-
Notifications
You must be signed in to change notification settings - Fork 758
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
Feat: Support estimate_fee_bulk API #461
Conversation
✅ Deploy Preview for starknetjs canceled.
|
tests fail because we need to update devnet from 0.4.0 to 0.4.2 |
Just to clarify, this means bumping |
__tests__/account.test.ts
Outdated
test('estimate fee bulk', async () => { | ||
const res = await account.estimateFeeBulk([ | ||
{ | ||
type: 'DECLARE', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 } & ( |
There was a problem hiding this comment.
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 } & ( |
There was a problem hiding this comment.
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
src/account/default.ts
Outdated
const version = toBN(feeTransactionVersion); | ||
const chainId = await this.getChainId(); | ||
|
||
const invocations: any = await Promise.all( |
There was a problem hiding this comment.
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
Let's fix these tests and include it in next v4 release please @irisdv |
Is this PR ready for review? |
Yes it's ready for review, I fixed the tests |
src/provider/sequencer.ts
Outdated
invocations: InvocationBulk, | ||
blockIdentifier: BlockIdentifier = this.blockIdentifier | ||
): Promise<EstimateFeeResponseBulk> { | ||
const params: any = [].concat(invocations as []).map((invocation: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const params: any = [].concat(invocations as []).map((invocation: any) => { | |
const params: Sequencer.EstimateFeeRequestBulk = invocations.map((invocation) => { |
There was a problem hiding this comment.
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
Thanks for your help @irisdv . Appreciate this! |
🎉 This PR is included in version 4.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 5.0.0-beta.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Motivation and Resolution
Feat #388
Adds support for
estimate_fee_bulk
API introduced in Cairo 0.10.2Usage related changes
estimateFeeBulk
in Account class, taking in arguments an array of transactions and returns an array ofEstimateFeeResponse
. Implemented only with sequencer, callingestimateFeeBulk
with RPC will throw an error.Checklist: