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

Add simulation support #931

Merged
merged 11 commits into from
Nov 22, 2021
Merged

Add simulation support #931

merged 11 commits into from
Nov 22, 2021

Conversation

webmaster128
Copy link
Member

Closes #828

@webmaster128 webmaster128 force-pushed the add-simulate branch 2 times, most recently from 4ded93f to 4d61793 Compare November 18, 2021 18:12
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful helper.

I like to not auto-set gas inside the signer, but let a caller easily get simulation estimates and set gas in the app

}),
};
const memo = "Go go go";
const gasUsed = await client.simulate(alice.address0, [executeContractMsg], memo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool!

@webmaster128
Copy link
Member Author

I like to not auto-set gas inside the signer, but let a caller easily get simulation estimates and set gas in the app

Yeah, this is the next question. I think the flow is very inconvenient. I'm thinking about an "auto" option that does the simulation internally and use a constant multiplier but still allow a custom gas limit. I'll write an example that shows how the current diff can be used.

@webmaster128
Copy link
Member Author

@ethanfrey could you have a look at packages/cli/examples/simulate.ts? There you see how manul gas is easy if you create the messages manually anyways (like e.g. ts-relayer), but annoying if you use higher level methods like "sendTokens" or CosmWasm "execute" that create the messages internally. The API we have now allows both. The only limitation is that the "auto" multiplier is fixed to 1.3.

Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice stuff

const memo = "With simulate";
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
const fee = calculateFee(Math.round(gasEstimation * 1.3), gasPrice);
const result = await client.sendTokens(account.address, recipient, amount, fee, memo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this next to last argument can be:

  • "auto"
  • number -> multiplier after simulation
  • StdFee -> caller fixed gas/fee

The top two using a gas price set in the constructor.

Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

@@ -367,7 +391,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
senderAddress: string,
recipientAddress: string,
amount: readonly Coin[],
fee: StdFee,
fee: StdFee | "auto" | number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, nice arg here... very flexible and I hope the caller uses TS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore simulation for help in choosing gas limits
2 participants