diff --git a/README.md b/README.md index 1020ee0b..3f8d7d95 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ You would typically use the input feature when deploying a single contract requi ### `starknet-verify` ``` -npx hardhat starknet-verify [--starknet-network ] [--path ] [ ...] [--address ] [--compiler-version ] [--license ] [--contract-name ] [--acount-contract ] +npx hardhat starknet-verify [--starknet-network ] [--path ] [ ...] [--address ] [--compiler-version ] [--license ] [--contract-name ] [--acount-contract] ``` Queries [Voyager](https://voyager.online/) to [verify the contract](https://voyager.online/verifyContract) deployed at `` using the source files at `` and any number of ``. @@ -343,8 +343,9 @@ More detailed documentation can be found [here](#account). const { res: currBalance } = await account.call(contract, "get_balance"); const amount = BigInt(10); - // Passing max_fee is currently optional - await account.invoke(contract, "increase_balance", { amount }, { maxFee: BigInt("123") }); + + // Read more about max fee specification under # Funds and fees + await account.invoke(contract, "increase_balance", { amount }, { maxFee: BigInt("1000000000") }); const { res: newBalance } = await account.call(contract, "get_balance"); expect(newBalance).to.deep.equal(currBalance + amount); @@ -610,7 +611,7 @@ npm install --save-dev influenceth__cairo_math_64x61@npm:@influenceth/cairo-math ```typescript paths: { - cairoPaths: ["./node_modules"] + cairoPaths: ["./node_modules"]; } ``` @@ -690,11 +691,11 @@ await contract.invoke("increase_balance", { amount: 1 }, { wallet }); Recompilation is performed when contracts are updated or when artifacts are missing. A file will be created with the name `cairo-files-cache.json` to handle caching. Recompilation is handled before the following [CLI commands](#cli-commands) are executed. -- `npx hardhat starknet-deploy` -- `npx hardhat starknet-invoke` -- `npx hardhat starknet-call` -- `npx hardhat run` -- `npx hardhat test` +- `npx hardhat starknet-deploy` +- `npx hardhat starknet-invoke` +- `npx hardhat starknet-call` +- `npx hardhat run` +- `npx hardhat test` This feature is turned off by default and is specified in the `hardhat.config.ts` file. @@ -784,6 +785,13 @@ Once your account has funds, you can specify a max fee greater than zero: await account.invoke(contract, "foo", { arg1: ... }, { maxFee: BigInt(...) }); ``` +If you don't specify a `maxFee`, one will be calculated for you by applying an overhead of 50% to the result of fee estimation. You can also customize the overhead by providing a value for `overhead`: + +```typescript +// maxFee will be 40% of estimated fee; if overhead not provided, a default value is used. +await account.invoke(contract, "foo", { arg1: ... }, { overhead: 0.4 ); +``` + ### Multicalls You can also use the Account object to perform multi{calls, invokes, fee estimations}. diff --git a/scripts/test.sh b/scripts/test.sh index 792e9da6..b5470bc8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,7 +9,7 @@ CONFIG_FILE_NAME="hardhat.config.ts" # setup example repo rm -rf starknet-hardhat-example -git clone -b plugin --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git +git clone -b release-0.7.0 --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git cd starknet-hardhat-example git log -n 1 npm install diff --git a/src/account.ts b/src/account.ts index eef5293d..6b967ab8 100644 --- a/src/account.ts +++ b/src/account.ts @@ -66,6 +66,23 @@ export abstract class Account { calldata?: StringMap, options?: InvokeOptions ): Promise { + if (options?.maxFee && options?.overhead) { + const msg = "Both maxFee and overhead cannot be specified"; + throw new StarknetPluginError(msg); + } + + if (options?.maxFee === undefined || options?.maxFee === null) { + let overhead = + options?.overhead === undefined || options?.overhead === null + ? 0.5 + : options?.overhead; + overhead = Math.round((1 + overhead) * 100); + const maxFee = await this.estimateFee(toContract, functionName, calldata, options); + options = { + ...options, + maxFee: (maxFee.amount * BigInt(overhead)) / BigInt(100) + }; + } return ( await this.interact(InteractChoice.INVOKE, toContract, functionName, calldata, options) ).toString(); diff --git a/src/external-server/create-devnet-wrapper.ts b/src/external-server/create-devnet-wrapper.ts index 5fb1dd56..1ba6da24 100644 --- a/src/external-server/create-devnet-wrapper.ts +++ b/src/external-server/create-devnet-wrapper.ts @@ -12,7 +12,9 @@ import { DockerDevnet } from "./docker-devnet"; import { VenvDevnet } from "./venv-devnet"; import { ExternalServer } from "./external-server"; -export function createIntegratedDevnet(hre: HardhatRuntimeEnvironment): ExternalServer { +export async function createIntegratedDevnet( + hre: HardhatRuntimeEnvironment +): Promise { const devnetNetwork = getNetwork( INTEGRATED_DEVNET, hre.config.networks, diff --git a/src/external-server/docker-devnet.ts b/src/external-server/docker-devnet.ts index d267aa52..d18c3276 100644 --- a/src/external-server/docker-devnet.ts +++ b/src/external-server/docker-devnet.ts @@ -18,6 +18,7 @@ export class DockerDevnet extends DockerServer { } protected async getContainerArgs(): Promise { - return this.devnetArgs || []; + const containerArgs = this.devnetArgs || []; + return [...containerArgs, "--port", this.port]; } } diff --git a/src/external-server/external-server.ts b/src/external-server/external-server.ts index ccdb16ae..2ff4f7f0 100644 --- a/src/external-server/external-server.ts +++ b/src/external-server/external-server.ts @@ -13,7 +13,7 @@ function sleep(amountMillis: number): Promise { }); } -function isFreePort(port: number): Promise { +export async function isFreePort(port: number): Promise { return new Promise((accept, reject) => { const sock = net.createConnection(port); sock.once("connect", () => { diff --git a/src/index.ts b/src/index.ts index d63a73f8..142dbca1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -293,10 +293,7 @@ task("starknet-verify", "Verifies a contract on a Starknet network.") .addParam("path", "The path of the main cairo contract (e.g. contracts/contract.cairo)") .addParam("address", "The address where the contract is deployed") .addParam("compilerVersion", "The compiler version used to compile the cairo contract") - .addOptionalParam( - "accountContract", - "The contract type which specifies whether it's an account contract. Omitting it sets false." - ) + .addFlag("accountContract", "The contract type which specifies it's an account contract.") .addOptionalParam("license", "The licence of the contract (e.g No License (None))") .addOptionalVariadicPositionalParam( "paths", diff --git a/src/task-actions.ts b/src/task-actions.ts index c8bba8f0..6bec0abc 100644 --- a/src/task-actions.ts +++ b/src/task-actions.ts @@ -26,6 +26,7 @@ import { getWalletUtil } from "./extend-utils"; import { createIntegratedDevnet } from "./external-server"; import { Recompiler } from "./recompiler"; import { version } from "../package.json"; +import { getFreePort, isFreePort } from "./external-server/external-server"; function checkSourceExists(sourcePath: string): void { if (!fs.existsSync(sourcePath)) { @@ -343,14 +344,7 @@ async function handleContractVerification( const bodyFormData = new FormData(); bodyFormData.append("compiler-version", args.compilerVersion); - let accountContract; - if (args.accountContract === "true") { - accountContract = "true"; - } else if (!args.accountContract || args.accountContract === "false") { - accountContract = "false"; - } else { - throw new StarknetPluginError("--account-contract must be true or false"); - } + const accountContract = args.accountContract ? "true" : "false"; bodyFormData.append("account-contract", accountContract); bodyFormData.append("license", args.license || "No License (None)"); @@ -560,7 +554,15 @@ async function runWithDevnet(hre: HardhatRuntimeEnvironment, fn: () => Promise&1 | - ../scripts/assert-contains.py "127.0.0.1:5050 already occupied." +npx hardhat test --no-compile test/integrated-devnet.test.ts diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.sh b/test/integrated-devnet-tests/with-venv-address-occupied/check.sh index 54e376dd..0e69d800 100755 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.sh +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.sh @@ -11,5 +11,4 @@ starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0 & npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "127.0.0.1:5050 already occupied." +npx hardhat test --no-compile test/integrated-devnet.test.ts