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

Feat: Support estimate_fee_bulk API #461

Merged
merged 14 commits into from
Jan 9, 2023

Conversation

irisdv
Copy link
Contributor

@irisdv irisdv commented Dec 16, 2022

Motivation and Resolution

Feat #388
Adds support for estimate_fee_bulk API introduced in Cairo 0.10.2

Usage related changes

  • Adds a new function estimateFeeBulk in Account class, taking in arguments an array of transactions and returns an array of EstimateFeeResponse. Implemented only with sequencer, calling estimateFeeBulk with RPC will throw an error.

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes
  • Updated the docs (www)
  • Updated the tests
  • All tests are passing

@netlify
Copy link

netlify bot commented Dec 16, 2022

Deploy Preview for starknetjs canceled.

Name Link
🔨 Latest commit 8e0f3da
🔍 Latest deploy log https://app.netlify.com/sites/starknetjs/deploys/63bc4e946a4df50008c25f4d

@irisdv irisdv changed the title [WIP] Feat: Support estimate_fee_bulk API Feat: Support estimate_fee_bulk API Dec 20, 2022
@ivpavici
Copy link
Collaborator

tests fail because we need to update devnet from 0.4.0 to 0.4.2

@penovicp
Copy link
Collaborator

tests fail because we need to update devnet from 0.4.0 to 0.4.2

Just to clarify, this means bumping shardlabs/starknet-devnet:0.4.0-seed0 in the .github/workflows files so it can be done as part of this PR.

test('estimate fee bulk', async () => {
const res = await account.estimateFeeBulk([
{
type: 'DECLARE',
Copy link
Contributor

@yoga-braavos yoga-braavos Dec 21, 2022

Choose a reason for hiding this comment

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

@irisdv I suggest that on top of this "generic" test, we add a test for the main scenario this bulk endpoint caters which is:
Txn 1: DEPLOY_ACCOUNT
Txn 2: Multi-call (of INVOKE-s) on the account deployed account from Txn 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When adding this test I realised I have an issue when estimating fees for DEPLOY_ACCOUNT. I have this error when I’m trying to use the function estimateAccountDeployFee on its own : Entry point 0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895 not found in contract with class hash 0x3fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854

Is there a specific way to make it work ? My understanding is that to deploy a new account I need to declare it, send eth to the address then deploy it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The 0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895 selector is __validate_deploy__ meaning that the contract you tried to deploy does not implement this endpoint and thus DEPLOY_ACCOUNT fails. In order for it to work, you need to implement/use a contract that have the __validate_deploy__ entry-point - See example in OpenZeppelin's account contract:
https://github.com/OpenZeppelin/cairo-contracts/blob/e0e07555b319d8131a35259b55269ba7b19e744e/src/openzeppelin/account/presets/Account.cairo#L112

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I updated the version of Account.json in the repo and added this testcase.

src/types/lib.ts Outdated
@@ -77,6 +77,19 @@ export type InvocationsDetails = {

export type InvocationsDetailsWithNonce = InvocationsDetails & { nonce: BigNumberish };

export type TransactionBulk = { type: TransactionType } & (
Copy link
Contributor

@yoga-braavos yoga-braavos Dec 21, 2022

Choose a reason for hiding this comment

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

@irisdv why are you calling it "Bulk" if it's a single object? I would move the wrapping in an Array to the type to justify its "bulk" naming and change function signature to accept TransactionBulk rather than Array<TransactionBulk>

src/types/lib.ts Outdated
| DeployAccountContractPayload
);

export type InvocationBulk = { type: TransactionType } & (
Copy link
Contributor

Choose a reason for hiding this comment

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

@irisdv same comment re "Bulk" semantics as above

const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();

const invocations: any = await Promise.all(
Copy link
Contributor

Choose a reason for hiding this comment

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

@irisdv this is a big code dup with the specialized estimate*Fee functions, please consider some refactoring so each flavor is managed in a single place in the code and the wrapping functions use that place instead of implementing it on their own

@dhruvkelawala
Copy link
Collaborator

Let's fix these tests and include it in next v4 release please @irisdv

@dhruvkelawala
Copy link
Collaborator

Is this PR ready for review?

@irisdv
Copy link
Contributor Author

irisdv commented Jan 6, 2023

Yes it's ready for review, I fixed the tests

src/account/default.ts Outdated Show resolved Hide resolved
src/account/default.ts Outdated Show resolved Hide resolved
src/account/default.ts Outdated Show resolved Hide resolved
src/account/default.ts Outdated Show resolved Hide resolved
src/account/interface.ts Outdated Show resolved Hide resolved
src/provider/rpc.ts Outdated Show resolved Hide resolved
src/provider/sequencer.ts Outdated Show resolved Hide resolved
src/types/api/sequencer.ts Outdated Show resolved Hide resolved
src/types/lib.ts Outdated Show resolved Hide resolved
src/types/lib.ts Outdated Show resolved Hide resolved
invocations: InvocationBulk,
blockIdentifier: BlockIdentifier = this.blockIdentifier
): Promise<EstimateFeeResponseBulk> {
const params: any = [].concat(invocations as []).map((invocation: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const params: any = [].concat(invocations as []).map((invocation: any) => {
const params: Sequencer.EstimateFeeRequestBulk = invocations.map((invocation) => {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a small change, we can merge after this

@dhruvkelawala
Copy link
Collaborator

Thanks for your help @irisdv . Appreciate this!

@dhruvkelawala dhruvkelawala merged commit 1352e78 into starknet-io:develop Jan 9, 2023
@github-actions
Copy link

github-actions bot commented Jan 9, 2023

🎉 This PR is included in version 4.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 5.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants