From d7a3675c9aea57ac5367862798d8115e298515b7 Mon Sep 17 00:00:00 2001 From: alexanderliteplo Date: Mon, 6 Jan 2025 17:19:55 -0800 Subject: [PATCH] adding quotesend test script --- .../oft-aptos/tasks/move/sendFromMoveVM.ts | 5 +- examples/oft-move/README.md | 46 +++++++++++--- examples/oft-move/package.json | 1 + packages/devtools-extensible-cli/README.md | 3 + .../devtools-extensible-cli/tsconfig.json | 2 +- packages/oft-move/cli/init.ts | 1 + .../oft-move/cli/operations/quoteSendOFTFA.ts | 55 +++++++++++++++++ packages/oft-move/package.json | 3 + packages/oft-move/tasks/quoteSendOFTFA.ts | 60 +++++++++++++++++++ pnpm-lock.yaml | 11 +++- 10 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 packages/oft-move/cli/operations/quoteSendOFTFA.ts create mode 100644 packages/oft-move/tasks/quoteSendOFTFA.ts diff --git a/examples/oft-aptos/tasks/move/sendFromMoveVM.ts b/examples/oft-aptos/tasks/move/sendFromMoveVM.ts index eba652b92..2a232fabc 100644 --- a/examples/oft-aptos/tasks/move/sendFromMoveVM.ts +++ b/examples/oft-aptos/tasks/move/sendFromMoveVM.ts @@ -64,8 +64,9 @@ async function main() { nativeFee, 0 ) - - await sendAllTxs(aptos, oft, account_address, [sendPayload]) + + const payloads = [{ payload: sendPayload, description: 'Send Aptos OFT', eid: dst_eid }] + await sendAllTxs(aptos, oft, account_address, payloads) // Check the balance again const balance = await aptos.view({ diff --git a/examples/oft-move/README.md b/examples/oft-move/README.md index fff0bed0c..7f5643377 100644 --- a/examples/oft-move/README.md +++ b/examples/oft-move/README.md @@ -1,34 +1,48 @@ ### connecting to aptos via cli + To install aptos cli, run the following command: + ``` brew install aptos ``` + If you need to generate a new key, run the following command: + ``` aptos key generate --output-file my_key.pub ``` + Then initialize the aptos cli and connect to the aptos network: + ``` aptos init --network=testnet --private-key= ``` + You can then verify that your initialization was successful by running the following command: + ``` -cat .aptos/config.yaml +cat .aptos/config.yaml ``` + If successful the config will be populated with the RPC links and your account private key, account address, and network. Note: Your private key is stored in the .aptos/config.yaml file and will be extracted from there. + ## Setup + Create a `.env` file with the following variables: ```bash ACCOUNT_ADDRESS= EVM_PRIVATE_KEY= ``` + Note: aptos account address can be found in .aptos/config.yaml + ## Build and deploy ### Builds the contracts + ```bash pnpm run lz:sdk:move:build --lz-config move.layerzero.config.ts --named-addresses oft=$ACCOUNT_ADDRESS,oft_admin=$ACCOUNT_ADDRESS --move-deploy-script deploy-move/MyMoveOFTFA.ts ``` @@ -40,17 +54,21 @@ pnpm run lz:sdk:move:deploy --lz-config move.layerzero.config.ts --named-address ``` ## Init - Not OFT Agnostic + First modify deploy/MyMoveOFTFA.ts and replace the oftMetadata with the following: + ```ts -const oftType = 'OFT_FA' +const oftType = "OFT_FA"; const oftMetadata = { - token_name: 'MyMoveOFT', - token_symbol: 'MMOFT', - icon_uri: '', - project_uri: '', -} + token_name: "MyMoveOFT", + token_symbol: "MMOFT", + icon_uri: "", + project_uri: "", +}; ``` + Before running the wire command, first inside of move.layerzero.config.ts, set the delegate address to your account address. + ```ts contracts: [ { @@ -69,30 +87,40 @@ Before running the wire command, first inside of move.layerzero.config.ts, set t }, ], ``` + Then run the following command: + ```bash pnpm run lz:sdk:move:init --lz-config move.layerzero.config.ts --move-deploy-script deploy/MyMoveOFTFA.ts ``` -## Wire +## Wire + Then run the wire command: For EVM: + ```bash pnpm run lz:sdk:evm:wire --lz-config move.layerzero.config.ts ``` + For Move-VM: + ```bash pnpm run lz:sdk:move:wire --lz-config move.layerzero.config.ts ``` ## Help + ```bash pnpm run lz:sdk:help ``` + ## EVM Deployment + ```bash npx hardhat lz:deploy ``` + Select only the evm networks (DO NOT SELECT APTOS) -For deploy script tags use: \ No newline at end of file +For deploy script tags use: diff --git a/examples/oft-move/package.json b/examples/oft-move/package.json index 27070a5a0..ca7714063 100644 --- a/examples/oft-move/package.json +++ b/examples/oft-move/package.json @@ -18,6 +18,7 @@ "lz:sdk:move:build": "ts-node scripts/cli.ts --vm move --op build", "lz:sdk:move:deploy": "ts-node scripts/cli.ts --vm move --op deploy", "lz:sdk:move:init": "ts-node scripts/cli.ts --vm move --op init", + "lz:sdk:move:quoteSend": "ts-node scripts/cli.ts --vm move --op quoteSend", "lz:sdk:move:set-delegate": "ts-node scripts/cli.ts --vm move --op set-delegate", "lz:sdk:move:wire": "ts-node scripts/cli.ts --vm move --op wire", "test": "$npm_execpath run test:forge && $npm_execpath run test:hardhat && $npm_execpath run test:aptos", diff --git a/packages/devtools-extensible-cli/README.md b/packages/devtools-extensible-cli/README.md index fbc446f37..130c348aa 100644 --- a/packages/devtools-extensible-cli/README.md +++ b/packages/devtools-extensible-cli/README.md @@ -4,6 +4,9 @@ This is a CLI for LayerZero Devtools - which is extensible by defining new opera Operations are of the class Type `INewOperation` and are defined in the `types/index.d.ts` file. +When you go to type your new operation, the args will have `-` instead of `_`. +For example, `lz_config` will be `--lz-config` on the command line. + ```ts import { build as buildMove } from '../../tasks/move/build' import { INewOperation } from './NewOperation' diff --git a/packages/devtools-extensible-cli/tsconfig.json b/packages/devtools-extensible-cli/tsconfig.json index fa385a5a5..cb2c99e80 100644 --- a/packages/devtools-extensible-cli/tsconfig.json +++ b/packages/devtools-extensible-cli/tsconfig.json @@ -14,4 +14,4 @@ "@/tasks/*": ["./tasks/*"] } } -} +} \ No newline at end of file diff --git a/packages/oft-move/cli/init.ts b/packages/oft-move/cli/init.ts index 70a94a4e6..edb54e0e6 100644 --- a/packages/oft-move/cli/init.ts +++ b/packages/oft-move/cli/init.ts @@ -3,4 +3,5 @@ import path from 'path' export async function attach_oft_move(sdk: AptosEVMCLI) { await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-fa')) + await sdk.extendOperationFromPath(path.join(__dirname, './operations/quoteSendOFTFA')) } diff --git a/packages/oft-move/cli/operations/quoteSendOFTFA.ts b/packages/oft-move/cli/operations/quoteSendOFTFA.ts new file mode 100644 index 000000000..9f90cfade --- /dev/null +++ b/packages/oft-move/cli/operations/quoteSendOFTFA.ts @@ -0,0 +1,55 @@ +import { INewOperation } from '@layerzerolabs/devtools-extensible-cli' + +import { quoteSendOFTFA } from '../../tasks/quoteSendOFTFA' + +class QuoteSendOFTFA implements INewOperation { + vm = 'move' + operation = 'quoteSend' + description = 'Quote send an OFT with FA' + reqArgs = ['amount_ld', 'min_amount_ld', 'to_address', 'gas_limit', 'dst_eid'] + + addArgs = [ + { + name: '--dst-eid', + arg: { + help: 'destination endpoint id', + required: true, + }, + }, + { + name: '--gas-limit', + arg: { + help: 'gas limit', + required: true, + }, + }, + { + name: '--min-amount-ld', + arg: { + help: 'minimum amount to receive', + required: true, + }, + }, + { + name: '--to-address', + arg: { + help: 'to address', + required: true, + }, + }, + { + name: '--amount-ld', + arg: { + help: 'amount to send', + required: true, + }, + }, + ] + + async impl(args: any): Promise { + await quoteSendOFTFA(args.amount_ld, args.min_amount_ld, args.to_address, args.gas_limit, args.dst_eid) + } +} + +const NewOperation = new QuoteSendOFTFA() +export { NewOperation } diff --git a/packages/oft-move/package.json b/packages/oft-move/package.json index c984c5417..6338a703e 100644 --- a/packages/oft-move/package.json +++ b/packages/oft-move/package.json @@ -17,8 +17,11 @@ "lint:fix": "eslint --fix '**/*.{js,ts,json}'" }, "devDependencies": { + "@aptos-labs/ts-sdk": "^1.33.1", "@layerzerolabs/devtools-extensible-cli": "^0.0.1", "@layerzerolabs/devtools-move": "^0.0.1", + "@layerzerolabs/lz-definitions": "^3.0.21", + "@layerzerolabs/lz-v2-utilities": "^3.0.12", "@layerzerolabs/prettier-config-next": "^2.3.39", "argparse": "^2.0.1", "depcheck": "^1.4.7", diff --git a/packages/oft-move/tasks/quoteSendOFTFA.ts b/packages/oft-move/tasks/quoteSendOFTFA.ts new file mode 100644 index 000000000..d4609c51c --- /dev/null +++ b/packages/oft-move/tasks/quoteSendOFTFA.ts @@ -0,0 +1,60 @@ +import { Aptos, AptosConfig } from '@aptos-labs/ts-sdk' + +import { EndpointId } from '@layerzerolabs/lz-definitions' +import { Options } from '@layerzerolabs/lz-v2-utilities' + +import { OFT } from '@layerzerolabs/devtools-move/sdk/oft' +import { hexAddrToAptosBytesAddr } from '@layerzerolabs/devtools-move/sdk/utils' + +import { getLzNetworkStage, parseYaml } from '@layerzerolabs/devtools-move/tasks/move/utils/aptosNetworkParser' +import { getMoveVMOftAddress } from '@layerzerolabs/devtools-move/tasks/move/utils/utils' + +async function quoteSendOFTFA( + amountLd: number, + minAmountLd: number, + toAddress: string, + gasLimit: number, + dstEid: EndpointId +) { + const { account_address, private_key, network } = await parseYaml() + console.log(`Using aptos network ${network}`) + + const aptosConfig = new AptosConfig({ network: network }) + const aptos = new Aptos(aptosConfig) + + const lzNetworkStage = getLzNetworkStage(network) + const aptosOftAddress = getMoveVMOftAddress(lzNetworkStage) + + const oft = new OFT(aptos, aptosOftAddress, account_address, private_key) + + const toAddressBytes = hexAddrToAptosBytesAddr(toAddress) + const options = Options.newOptions().addExecutorLzReceiveOption(BigInt(gasLimit)) + + console.log(`Attempting to quote send ${amountLd} units`) + console.log(`Using OFT at address: ${aptosOftAddress}`) + console.log(`From account: ${account_address}`) + console.log(`To account: ${toAddress}`) + + const extra_options = options.toBytes() + const compose_message = new Uint8Array([]) + const oft_cmd = new Uint8Array([]) + + const [nativeFee, zroFee] = await oft.quoteSend( + account_address, + dstEid, + toAddressBytes, + amountLd, + minAmountLd, + extra_options, + compose_message, + oft_cmd, + false // pay_in_zro: false to pay in native tokens + ) + + console.log('\nQuote received:') + console.log('- Native fee:', nativeFee) + console.log('- ZRO fee:', zroFee) + console.log('If the above fees are acceptable, the wiring is confirmed to be successful.') +} + +export { quoteSendOFTFA } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 618e58f30..ad6f4a4c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1373,7 +1373,7 @@ importers: '@layerzerolabs/oft-evm': specifier: ^3.0.0 version: link:../../packages/oft-evm - '@layerzerolabs/oft-move': + '@layerzerolabs/oft-move': specifier: ^0.0.1 version: link:../../packages/oft-move '@layerzerolabs/prettier-config-next': @@ -3225,12 +3225,21 @@ importers: packages/oft-move: devDependencies: + '@aptos-labs/ts-sdk': + specifier: ^1.33.1 + version: 1.33.1 '@layerzerolabs/devtools-extensible-cli': specifier: ^0.0.1 version: link:../devtools-extensible-cli '@layerzerolabs/devtools-move': specifier: ^0.0.1 version: link:../devtools-move + '@layerzerolabs/lz-definitions': + specifier: ^3.0.21 + version: 3.0.27 + '@layerzerolabs/lz-v2-utilities': + specifier: ^3.0.12 + version: 3.0.27 '@layerzerolabs/prettier-config-next': specifier: ^2.3.39 version: 2.3.44