Skip to content

Commit

Permalink
adding quotesend test script
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLiteplo committed Jan 7, 2025
1 parent 26859cf commit d7a3675
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 13 deletions.
5 changes: 3 additions & 2 deletions examples/oft-aptos/tasks/move/sendFromMoveVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
46 changes: 37 additions & 9 deletions examples/oft-move/README.md
Original file line number Diff line number Diff line change
@@ -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=<your-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=<your-aptos-account-address>
EVM_PRIVATE_KEY=<your-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
```
Expand All @@ -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: [
{
Expand All @@ -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:
For deploy script tags use:
1 change: 1 addition & 0 deletions examples/oft-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools-extensible-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-extensible-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"@/tasks/*": ["./tasks/*"]
}
}
}
}
1 change: 1 addition & 0 deletions packages/oft-move/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
55 changes: 55 additions & 0 deletions packages/oft-move/cli/operations/quoteSendOFTFA.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await quoteSendOFTFA(args.amount_ld, args.min_amount_ld, args.to_address, args.gas_limit, args.dst_eid)
}
}

const NewOperation = new QuoteSendOFTFA()
export { NewOperation }
3 changes: 3 additions & 0 deletions packages/oft-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
60 changes: 60 additions & 0 deletions packages/oft-move/tasks/quoteSendOFTFA.ts
Original file line number Diff line number Diff line change
@@ -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 }
11 changes: 10 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7a3675

Please sign in to comment.