-
Notifications
You must be signed in to change notification settings - Fork 58
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
Runtianz/new script composer #587
Conversation
Please test and validate it
|
I have tested a React + Vite client-side render app and a Next.js server-side render app. However, it's worth noting that in the current version, the initialization is done when the SDK loads, so the bundled JavaScript is a bit large—about 5 MB for the client-side. |
The bundle size is a concern. I'd like to get consensus from the sdk team before approving it. @gregnazario @GhostWalker562 |
@GhostWalker562 I dont think the SDK officially supports react-native, but I assume you want it tested for Petra? |
I think that would be amazing. |
Cool. Then we dont need to merge it to |
Let's release it first and get feedbacks from the community. I'm getting multiple asks for this feature so would be great to let them try it out first. In the meantime, we can optimize on the packaging situation. |
eagerly waiting to use this feature in our app |
One workaround for the size is lazy load. wdyt? |
659a19c
to
7018ff6
Compare
This feature has been available for some time under a different version https://www.npmjs.com/package/@aptos-labs/ts-sdk/v/1.33.0-sc.1 and @runtian-zhou mentioned receiving positive feedback from users, along with excitement about integrating it officially into the @WGB5445 validated that the feature works in both web and Node.js environments. @0xmaayan confirmed there is no increase in the bundle size current
script compose branch
I’m okay with moving forward and merging it, thoughts @gregnazario @GhostWalker562 ? @runtian-zhou One thing we’re missing, which could be beneficial, is adding a complete example in the examples folder, not a blocker tho |
@0xmaayan would like to see it tested in a react-native environment too but otherwise sounds good to me |
|
This is the GitHub Pages deployment page for the Next.js and React versions, where you can view the corresponding source code: |
We've been using it in testnet and mainnet for some time, and there's a feature request which could really optimize the script composer - the ability to provide ABIs manually. Currently it fetches for ABIs every time which slows down the process. @itsmnthn can provide more details on this. |
Yes passing ABIs to the addBatchedCall for the given call and for standard module's ABIs as part of the script composer to avoid fetching it over the network multiple times to speed up execution time especially when connection is slow. Things add up when the script is complex and has more steps even when the network speed is gud. I've written custom AptosScriptComposer class to use in our FE which add abi as a parameter to addBatchedCall to avoid fetching ABI. So it does not fetch for a module which being called but still fetches standard abis required for argument types etc (which is not efficient right now especially to use on frontend) |
fa0ecbd
to
4fe12d4
Compare
This reverts commit bf8afa1.
4fe12d4
to
7f61c14
Compare
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.
Looks good, few small comments
Also make sure to add to README.md
about the wasm dependency in script-composer-pack
package.json
Outdated
@@ -56,6 +56,7 @@ | |||
"@noble/hashes": "^1.4.0", | |||
"@scure/bip32": "^1.4.0", | |||
"@scure/bip39": "^1.3.0", | |||
"@aptos-labs/script-composer-pack": "^0.0.4", |
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.
Update to latest when possible
aptosConfig: aptos.config, | ||
sender: singleSignerED25519SenderAccount.accountAddress, | ||
payload: TransactionPayloadScript.load(new Deserializer(bytes)), | ||
}); |
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.
Could you try to use the aptos.transaction.build.scriptComposer()
to build the script here?
So that it can be more consistent with the next test case
for (const typeTag of input.typeArguments) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.builder.load_type_tag(nodeUrl, typeTag.toString()); | ||
} |
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.
Change to await Promise.all(input.typeArguments.map((typeTag) => this.builder.load_type_tag(nodeUrl, typeTag.toString())));
to await the promises in parellel
await builder.init(); | ||
await builder.addBatchedCalls({ | ||
function: `${contractPublisherAccount.accountAddress}::transfer::transfer`, | ||
functionArguments: [CallArgument.new_signer(0), 1, receiverAccounts[0].accountAddress], |
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.
If there's a way to update the dependency to not use snake case, that would be great.
Even better, we can have a SignerArgument
instance instead using static functions from CallArgument
.
@@ -0,0 +1,85 @@ | |||
// Copyright © Aptos Foundation |
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.
Rename directory from script-composer to scriptComposer
9674c3f
to
df5cef1
Compare
CHANGELOG.md
Outdated
@@ -3,6 +3,7 @@ | |||
All notable changes to the Aptos TypeScript SDK will be captured in this file. This changelog is written by hand for now. It adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | |||
|
|||
# Unreleased | |||
- [`Breaking`] Add new new `scriptComposer` api in transactionSubmission api to allow SDK callers to invoke multiple Move functions inside a same transaction and compose the calls dynamically. |
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.
Should be "Add new"
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export class callArgument { |
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.
What happened to CallArgument
here?
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.
Sry should have removed this file...
725ea9a
to
61d0ac5
Compare
630ef2a
to
25d2de4
Compare
builder: (builder: AptosScriptComposer) => Promise<AptosScriptComposer>; | ||
options?: InputGenerateTransactionOptions; | ||
withFeePayer?: boolean; | ||
}): Promise<SimpleTransaction> { |
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.
any reason we are not following the other transactions build flow format?
return generateTransaction({ aptosConfig: this.config, ...args });
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.
This is because the generateTransaction
cannot take the serialized blob of move script as input (input contains both bytecode and type arguments/inputs).
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.
Ideally, we would have generateBatchTransaction
payload: TransactionPayloadScript.load(new Deserializer(bytes)), | ||
...args, | ||
}); | ||
return new SimpleTransaction(rawTxn, args.withFeePayer === true ? AccountAddress.ZERO : undefined); |
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.
If well follow the same format, this will be taken care with https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/internal/transactionSubmission.ts#L165
// before using the composer. | ||
async init() { | ||
if (!AptosScriptComposer.transactionComposer) { | ||
const module = await import("@aptos-labs/script-composer-pack"); |
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.
was this tested in node/web (react+next)/react native envs?
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.
Yes.
initSync({ module: ScriptComposerWasm.wasm }); | ||
AptosScriptComposer.transactionComposer = TransactionComposer; | ||
} | ||
this.builder = AptosScriptComposer.transactionComposer.single_signer(); |
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.
lets keep the same format
this.builder = AptosScriptComposer.transactionComposer.single_signer(); | |
this.builder = AptosScriptComposer.transactionComposer.singleSigner(); |
|
||
private builder?: any; | ||
|
||
private static transactionComposer?: 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.
why 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.
This is to allow for a lazy initialization of the composer so we don't need to pull the types in rightaway.
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.
then ideally the sdk would hold an internal type for that
// | ||
// The function would also return a list of `CallArgument` that can be passed on to future calls. | ||
async addBatchedCalls(input: InputBatchedFunctionData): Promise<CallArgument[]> { | ||
const { moduleAddress, moduleName, functionName } = getFunctionParts(input.function); |
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.
why we rewrite the same flow?
https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/transactions/transactionBuilder/transactionBuilder.ts#L180
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.
This is because we have some extra bookkeeping logics to maintain in the composer? Was wondering if you have some suggestions for how to refactor the codes here.
} | ||
|
||
build(): Uint8Array { | ||
return this.builder.generate_batched_calls(true); |
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.
return this.builder.generate_batched_calls(true); | |
return this.builder.generateBatchedCalls(true); |
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.
It's a bit unfortunate the camel cases are in the packed wasm so we can't just change the calls here. Tho these apis aren't called by users directly so it should be safe?
Overall LGTM, most important thing is that the change is marked as |
Oh this shouldn't be a breaking cause we didn't remove existing apis, just a new feature. Lemme remove that. |
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.
🚀 ship it!
b92ed09
to
e81b8d7
Compare
e81b8d7
to
d091088
Compare
Description
Reopen the script composer feature with updated dependency built into aptos-labs.
Test Plan
CI
Tested that the package can work in web, nodejs and nextjs environment.
Related Links
#565
Checklist
pnpm fmt
?CHANGELOG.md
?