-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shankar <[email protected]>
- Loading branch information
1 parent
504c40d
commit 1c487c1
Showing
40 changed files
with
4,852 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
artifacts | ||
cache | ||
dist | ||
node_modules | ||
out | ||
*.log | ||
*.sol | ||
*.yaml | ||
*.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Devtools-Movement README | ||
|
||
1. Supports movement and evm chain side of the layerzero-sdk | ||
2. Uses existing `hardhat.config.ts` and `layerzero.config.ts` | ||
3. Extensible for OFTs and OApps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@layerzerolabs/devtools-movement", | ||
"version": "0.0.1", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"prebuild": "tsc -noEmit", | ||
"build": "$npm_execpath tsup --clean", | ||
"clean": "rm -rf dist", | ||
"dev": "$npm_execpath tsup --watch", | ||
"lint": "$npm_execpath eslint '**/*.{js,ts,json}'", | ||
"lint:fix": "eslint --fix '**/*.{js,ts,json}'" | ||
}, | ||
"devDependencies": { | ||
"@aptos-labs/ts-sdk": "^1.33.1", | ||
"@layerzerolabs/lz-definitions": "^3.0.21", | ||
"@layerzerolabs/lz-evm-sdk-v2": "^3.0.27", | ||
"@layerzerolabs/lz-serdes": "^3.0.19", | ||
"@layerzerolabs/lz-v2-utilities": "^3.0.12", | ||
"@layerzerolabs/toolbox-hardhat": "~0.6.1", | ||
"@types/argparse": "^2.0.17", | ||
"@types/node": "~18.18.14", | ||
"argparse": "^2.0.1", | ||
"ethers": "^5.7.2", | ||
"hardhat": "^2.22.10", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.4.4", | ||
"yaml": "^2.6.1" | ||
}, | ||
"engines": { | ||
"node": ">=18.16.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Aptos } from '@aptos-labs/ts-sdk' | ||
|
||
import { EndpointId, getNetworkForChainId } from '@layerzerolabs/lz-definitions' | ||
|
||
interface LibraryTimeoutResponse { | ||
expiry: bigint | ||
lib: string | ||
} | ||
|
||
export class Endpoint { | ||
private aptos: Aptos | ||
private endpoint_address: string | ||
constructor(aptos: Aptos, endpoint_address: string) { | ||
this.aptos = aptos | ||
this.endpoint_address = endpoint_address | ||
} | ||
|
||
async getDefaultSendLibrary(eid: EndpointId): Promise<string> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_default_send_lib`, | ||
functionArguments: [eid], | ||
}, | ||
}) | ||
return result[0] as string | ||
} | ||
|
||
async getSendLibrary(oftAddress: string, dstEid: number): Promise<[string, boolean]> { | ||
try { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_effective_send_library`, | ||
functionArguments: [oftAddress, dstEid], | ||
}, | ||
}) | ||
return [result[0] as string, result[1] as boolean] | ||
} catch (error) { | ||
const toNetwork = getNetworkForChainId(dstEid) | ||
throw new Error( | ||
`Failed to get send library. Network: ${toNetwork.chainName}-${toNetwork.env} might not be supported.` | ||
) | ||
} | ||
} | ||
|
||
async getReceiveLibrary(oftAddress: string, dstEid: number): Promise<[string, boolean]> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_effective_receive_library`, | ||
functionArguments: [oftAddress, dstEid], | ||
}, | ||
}) | ||
return [result[0] as string, result[1] as boolean] | ||
} | ||
|
||
async getDefaultReceiveLibraryTimeout(eid: EndpointId): Promise<LibraryTimeoutResponse> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_default_receive_library_timeout`, | ||
functionArguments: [eid], | ||
}, | ||
}) | ||
return result[0] as LibraryTimeoutResponse | ||
} | ||
|
||
async getReceiveLibraryTimeout(oftAddress: string, dstEid: number): Promise<LibraryTimeoutResponse> { | ||
try { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_receive_library_timeout`, | ||
functionArguments: [oftAddress, dstEid], | ||
}, | ||
}) | ||
const rawResponse = result[0] as { expiry: string; lib: string } | ||
return { | ||
expiry: BigInt(rawResponse.expiry), | ||
lib: rawResponse.lib, | ||
} | ||
} catch (error) { | ||
// if the timeout is not set, it will throw a VM error, so we should return a value that will always produce a diff | ||
return { expiry: BigInt(-1), lib: '' } | ||
} | ||
} | ||
|
||
async getDefaultReceiveLibrary(eid: EndpointId): Promise<string> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_default_receive_lib`, | ||
functionArguments: [eid], | ||
}, | ||
}) | ||
return result[0] as string | ||
} | ||
|
||
async getConfig( | ||
oAppAddress: string, | ||
msgLibAddress: string, | ||
eid: EndpointId, | ||
configType: number | ||
): Promise<Uint8Array> { | ||
try { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.endpoint_address}::endpoint::get_config`, | ||
functionArguments: [oAppAddress, msgLibAddress, eid, configType], | ||
}, | ||
}) | ||
return result[0] as Uint8Array | ||
} catch (error) { | ||
throw new Error( | ||
`Failed to get config for Message Library: ${msgLibAddress} on ${getNetworkForChainId(eid).chainName}. Please ensure that the Message Library exists.` | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// todo: implement connection builder that reads form yaml and fills in config with movement stuff if needed | ||
// todo replace all mentions of aptos with move-vm instead | ||
|
||
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk' | ||
|
||
const CHAIN_MOVEMENT = 'movement' | ||
const CHAIN_APTOS = 'aptos' | ||
|
||
const MOVEMENT_INDEXER_URLS = { | ||
[Network.TESTNET]: 'https://indexer.testnet.porto.movementnetwork.xyz/v1/graphql', | ||
[Network.MAINNET]: 'N/A', | ||
[Network.DEVNET]: 'N/A', | ||
[Network.LOCAL]: 'N/A', | ||
[Network.CUSTOM]: 'N/A', | ||
} | ||
|
||
export function getConnection(chain: string, network: Network, fullnode: string, faucet: string): Aptos { | ||
if (chain === CHAIN_MOVEMENT) { | ||
const indexer = getMovementIndexerUrl(network) | ||
return new Aptos( | ||
new AptosConfig({ | ||
network: Network.CUSTOM, | ||
fullnode: fullnode, | ||
faucet: faucet, | ||
indexer: indexer, | ||
}) | ||
) | ||
} else { | ||
return new Aptos(new AptosConfig({ network: network })) | ||
} | ||
} | ||
|
||
export function getChain(fullnode: string): string { | ||
if (fullnode.toLowerCase().includes(CHAIN_MOVEMENT)) { | ||
return CHAIN_MOVEMENT | ||
} else { | ||
return CHAIN_APTOS | ||
} | ||
} | ||
|
||
function getMovementIndexerUrl(network: Network): string { | ||
const indexerUrl = MOVEMENT_INDEXER_URLS[network] | ||
if (indexerUrl !== 'N/A') { | ||
return indexerUrl | ||
} | ||
throw new Error('Invalid network') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Aptos } from '@aptos-labs/ts-sdk' | ||
|
||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
|
||
interface MoveVectorResponse { | ||
vec: UlnConfig[] | ||
} | ||
|
||
interface UlnConfig { | ||
confirmations: bigint | ||
optional_dvn_threshold: number | ||
optional_dvns: string[] | ||
required_dvns: string[] | ||
use_default_for_confirmations: boolean | ||
use_default_for_optional_dvns: boolean | ||
use_default_for_required_dvns: boolean | ||
} | ||
|
||
export class MsgLib { | ||
private aptos: Aptos | ||
private msgLibAddress: string | ||
constructor(aptos: Aptos, msgLibAddress: string) { | ||
this.aptos = aptos | ||
this.msgLibAddress = msgLibAddress | ||
} | ||
|
||
async get_default_uln_send_config(eid: EndpointId): Promise<UlnConfig> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.msgLibAddress}::msglib::get_default_uln_send_config`, | ||
functionArguments: [eid], | ||
}, | ||
}) | ||
return (result[0] as MoveVectorResponse).vec[0] | ||
} | ||
|
||
async get_default_uln_receive_config(eid: EndpointId): Promise<UlnConfig> { | ||
const result = await this.aptos.view({ | ||
payload: { | ||
function: `${this.msgLibAddress}::msglib::get_default_uln_receive_config`, | ||
functionArguments: [eid], | ||
}, | ||
}) | ||
return (result[0] as MoveVectorResponse).vec[0] | ||
} | ||
} |
Oops, something went wrong.