Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

286 type defs #291

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
}
],
"template-curly-spacing": ["error", "never"],
"@typescript-eslint/no-unused-vars": ["error"]
"@typescript-eslint/no-unused-vars": ["error"],
"@typescript-eslint/no-empty-interface": [
"error",
{
"allowSingleExtends": true
}
]
}
}
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
- [ ] Performed a self-review of the code
- [ ] Rebased to the last commit of the target branch (or merged it into my branch)
- [ ] Documented the changes
- [ ] If `src/type-extensions.ts` was changed, updated the line number referencing this file in the `## API` section of README.md
- [ ] Updated the `test` directory (with a test case consisting of `network.json`, `hardhat.config.ts`, `check.ts`)
- [ ] Linked issues which this PR resolves
- [ ] Created a PR to the `plugin` branch of [`starknet-hardhat-example`](https://github.com/Shard-Labs/starknet-hardhat-example):
Expand Down
193 changes: 9 additions & 184 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,13 @@
import "hardhat/types/config";
import "hardhat/types/runtime";
import {
BlockIdentifier,
NonceQueryOptions,
StarknetContract,
StarknetContractFactory,
StringMap
} from "./types";
import { StarknetContract, StarknetContractFactory, StringMap } from "./types";
import { StarknetWrapper } from "./starknet-wrappers";
import {
FlushResponse,
IncreaseTimeResponse,
LoadL1MessagingContractResponse,
SetTimeResponse,
PredeployedAccount
} from "./devnet-utils";
import { Account, ArgentAccount, OpenZeppelinAccount } from "./account";
import * as DevnetTypes from "./types/devnet";
import * as StarknetTypes from "./types/starknet";
import { Account } from "./account";
import { Transaction, TransactionReceipt, Block, TransactionTrace } from "./starknet-types";
import { HardhatNetworkConfig, NetworkConfig } from "hardhat/types/config";
import { StarknetChainId } from "./constants";

type StarknetConfig = {
dockerizedVersion?: string;
venv?: string;
wallets?: WalletUserConfig;
network?: string;
networkUrl?: string;
networkConfig?: NetworkConfig;
recompile?: boolean;
};

type WalletUserConfig = {
[walletName: string]: WalletConfig | undefined;
};

type WalletConfig = {
modulePath: string;
accountName?: string;
accountPath?: string;
};

declare module "hardhat/types/config" {
export interface ProjectPathsUserConfig {
starknetArtifacts?: string;
Expand All @@ -54,11 +22,11 @@ declare module "hardhat/types/config" {
}

export interface HardhatConfig {
starknet: StarknetConfig;
starknet: StarknetTypes.StarknetConfig;
}

export interface HardhatUserConfig {
starknet?: StarknetConfig;
starknet?: StarknetTypes.StarknetConfig;
}

export interface NetworksConfig {
Expand Down Expand Up @@ -108,160 +76,17 @@ type TransactionType = Transaction;
type BlockType = Block;

declare module "hardhat/types/runtime" {
interface Devnet {
/**
* Restarts the devnet.
* @returns void
* @throws {@link StarknetPluginError}
*/
restart(): Promise<void>;

/**
* Handles all pending L1 to L2 messages and sends them to the other layer
* @returns {Promise} - Metadata for the flushed messages
*/
flush: () => Promise<FlushResponse>;

/**
* Deploys or loads the L1 messaging contract.
* @param {string} networkUrl - L1 network url.
* @param {string} [address] - Address of the contract to be loaded.
* @param {string} [networkId] - Determines if the ganache or tesnet should be used/
* @returns
*/
loadL1MessagingContract: (
networkUrl: string,
address?: string,
networkId?: string
) => Promise<LoadL1MessagingContractResponse>;

/**
* Increases block time offset
* @param seconds the offset increase in seconds
* @returns an object containing the increased block time offset
*/
increaseTime: (seconds: number) => Promise<IncreaseTimeResponse>;

/**
* Sets the timestamp of next block
* @param seconds timestamp in seconds
* @returns an object containg next block timestamp
*/
setTime: (seconds: number) => Promise<SetTimeResponse>;

/**
* Fetch the predeployed accounts
* @returns an object containg array of account's metadata
*/
getPredeployedAccounts: () => Promise<PredeployedAccount[]>;

/**
* Preserves devnet instance to a file
* @param path path for the dumping
* @return void
*/
dump: (path: string) => Promise<void>;

/**
* Loads stored Starknet chain state
* @param path path for the dump file
* @returns void
*/
load: (path: string) => Promise<void>;

/**
* Creates an empty block
* @returns the empty block
*/
createBlock: () => Promise<Block>;
}

export interface Devnet extends DevnetTypes.Devnet {}
interface HardhatRuntimeEnvironment {
starknetWrapper: StarknetWrapper;

starknet: {
/**
* Fetches a compiled contract by name. E.g. if the contract is defined in MyContract.cairo,
* the provided string should be `MyContract`.
* @param name the case-sensitive contract name
* @returns a factory for generating instances of the desired contract
*/
getContractFactory: (name: string) => Promise<StarknetContractFactory>;

/**
* Cairo and Starknet source files may contain short string literals,
* which are interpreted as numbers (felts) during Starknet runtime.
* Use this utility function to provide short string arguments to your contract functions.
*
* This function converts such a short string (max 31 characters) to its felt representation (wrapped in a `BigInt`).
* Only accepts standard ASCII characters, i.e. characters with charcode between 0 and 127, inclusive.
* @param input the input short string
* @returns the numeric equivalent of the input short string, wrapped in a `BigInt`
*/
shortStringToBigInt: (convertableString: string) => BigInt;

/**
* Converts a BigInt to a string. The opposite of {@link shortStringToBigInt}.
* @param input the input BigInt
* @returns a string which is the result of converting a BigInt's hex value to its ASCII equivalent
*/
bigIntToShortString: (convertableBigInt: BigInt) => string;

/**
* The selected starknet-network name.
* Present if the called task relies on `--starknet-network` or `starknet["network"]` in the config object.
*/
network: string;

/**
* The configuration object of the selected starknet-network.
*/
networkConfig: HardhatNetworkConfig;

/**
* @param name the name of the wallet to get
* @returns a wallet
*/
getWallet: (name: string) => WalletConfig;

devnet: Devnet;

getTransaction: (txHash: string) => Promise<Transaction>;

getTransactionReceipt: (txHash: string) => Promise<TransactionReceipt>;

/**
* Returns execution information in a nested structure of calls.
* @param txHash the transaction hash
* @returns the transaction trace
*/
getTransactionTrace: (txHash: string) => Promise<TransactionTrace>;

/**
* Returns an entire block and the transactions contained within it.
* @param identifier optional block identifier (by block number or hash). To query the latest block, remove the identifier.
* @returns a block object
*/
getBlock: (identifier?: BlockIdentifier) => Promise<Block>;

/**
* Returns the nonce of the contract whose `address` is specified.
* @param address the contract address
* @param options optional arguments to specify the target
* @returns the nonce
*/
getNonce: (address: string, options?: NonceQueryOptions) => Promise<number>;

OpenZeppelinAccount: typeof OpenZeppelinAccount;

ArgentAccount: typeof ArgentAccount;
};
starknet: StarknetTypes.Starknet;
}

type StarknetContract = StarknetContractType;
type StarknetContractFactory = StarknetContractFactoryType;
type StringMap = StringMapType;
type Wallet = WalletConfig;
type Wallet = StarknetTypes.WalletConfig;
type Account = AccountType;
type Transaction = TransactionType;
type TransactionReceipt = TransactionReceiptType;
Expand Down
76 changes: 76 additions & 0 deletions src/types/devnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
FlushResponse,
IncreaseTimeResponse,
LoadL1MessagingContractResponse,
SetTimeResponse,
PredeployedAccount
} from "../devnet-utils";
import { Block } from "../starknet-types";

export interface Devnet {
/**
* Restarts the devnet.
* @returns void
* @throws {@link StarknetPluginError}
*/
restart(): Promise<void>;

/**
* Handles all pending L1 to L2 messages and sends them to the other layer
* @returns {Promise} - Metadata for the flushed messages
*/
flush: () => Promise<FlushResponse>;

/**
* Deploys or loads the L1 messaging contract.
* @param {string} networkUrl - L1 network url.
* @param {string} [address] - Address of the contract to be loaded.
* @param {string} [networkId] - Determines if the ganache or tesnet should be used/
* @returns
*/
loadL1MessagingContract: (
networkUrl: string,
address?: string,
networkId?: string
) => Promise<LoadL1MessagingContractResponse>;

/**
* Increases block time offset
* @param seconds the offset increase in seconds
* @returns an object containing the increased block time offset
*/
increaseTime: (seconds: number) => Promise<IncreaseTimeResponse>;

/**
* Sets the timestamp of next block
* @param seconds timestamp in seconds
* @returns an object containg next block timestamp
*/
setTime: (seconds: number) => Promise<SetTimeResponse>;

/**
* Fetch the predeployed accounts
* @returns an object containg array of account's metadata
*/
getPredeployedAccounts: () => Promise<PredeployedAccount[]>;

/**
* Preserves devnet instance to a file
* @param path path for the dumping
* @return void
*/
dump: (path: string) => Promise<void>;

/**
* Loads stored Starknet chain state
* @param path path for the dump file
* @returns void
*/
load: (path: string) => Promise<void>;

/**
* Creates an empty block
* @returns the empty block
*/
createBlock: () => Promise<Block>;
}
12 changes: 6 additions & 6 deletions src/types.ts → src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as fs from "fs";
import * as starknet from "./starknet-types";
import { StarknetPluginError } from "./starknet-plugin-error";
import * as starknet from "../starknet-types";
import { StarknetPluginError } from "../starknet-plugin-error";
import {
CHECK_STATUS_RECOVER_TIMEOUT,
QUERY_VERSION,
TRANSACTION_VERSION,
HEXADECIMAL_REGEX,
CHECK_STATUS_TIMEOUT
} from "./constants";
import { adaptLog, copyWithBigint, sleep, warn } from "./utils";
import { adaptInputUtil, adaptOutputUtil } from "./adapt";
} from "../constants";
import { adaptLog, copyWithBigint, sleep, warn } from "../utils";
import { adaptInputUtil, adaptOutputUtil } from "../adapt";
import { HardhatRuntimeEnvironment, Wallet } from "hardhat/types";
import { hash } from "starknet";
import { StarknetWrapper } from "./starknet-wrappers";
import { StarknetWrapper } from "../starknet-wrappers";

/**
* According to: https://starknet.io/docs/hello_starknet/intro.html#interact-with-the-contract
Expand Down
Loading