@layerzerolabs/lz-sui-sdk-v2 3.0.73 → 3.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +1169 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +353 -24
- package/dist/index.d.ts +353 -24
- package/dist/index.mjs +1138 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
- package/src/bcs/index.ts +1 -0
- package/src/bcs/messaging-fee.ts +6 -0
- package/src/index.ts +5 -1
- package/src/modules/counter.ts +239 -0
- package/src/modules/endpoint.ts +303 -0
- package/src/modules/index.ts +5 -0
- package/src/modules/simple-message-lib.ts +240 -0
- package/src/modules/utils.ts +390 -0
- package/src/modules/zro.ts +38 -0
- package/src/sdk.ts +233 -0
- package/src/types.ts +89 -0
- package/src/utils.ts +69 -0
- package/src/endpoint.ts +0 -38
package/src/types.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Counter, Endpoint, SimpleMessageLib, Utils, Zro } from './modules'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type representing the options for packages.
|
|
5
|
+
*/
|
|
6
|
+
export type PackageOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The endpoint V2 address.
|
|
9
|
+
*/
|
|
10
|
+
endpoint_v2: string
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The counter V2 address.
|
|
14
|
+
*/
|
|
15
|
+
counter_v2: string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The simple message library address.
|
|
19
|
+
*/
|
|
20
|
+
simple_message_lib: string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The zro address.
|
|
24
|
+
*/
|
|
25
|
+
zro: string
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The utils address.
|
|
29
|
+
*/
|
|
30
|
+
utils: string
|
|
31
|
+
} & { [key: string]: string }
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Type representing the options for objects.
|
|
35
|
+
*/
|
|
36
|
+
export type ObjectOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* The endpoint V2 object address.
|
|
39
|
+
*/
|
|
40
|
+
endpoint_v2: string
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The simple message library object address.
|
|
44
|
+
*/
|
|
45
|
+
simple_message_lib: string
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The ULN-302 message library object address.
|
|
49
|
+
*/
|
|
50
|
+
uln_302: string
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The blocked message library object address.
|
|
54
|
+
*/
|
|
55
|
+
blocked_message_lib: string
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The discovery object address for OApp discovery.
|
|
59
|
+
*/
|
|
60
|
+
discovery: string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The counter OApp object address.
|
|
64
|
+
*/
|
|
65
|
+
counter: string
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The OApp core object address.
|
|
69
|
+
*/
|
|
70
|
+
oapp_core: string
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The endpoint admin cap object address.
|
|
74
|
+
*/
|
|
75
|
+
endpoint_admin_cap: string
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The counter admin cap object address.
|
|
79
|
+
*/
|
|
80
|
+
counter_admin_cap: string
|
|
81
|
+
} & { [key: string]: string }
|
|
82
|
+
|
|
83
|
+
export interface Context {
|
|
84
|
+
endpoint: Endpoint
|
|
85
|
+
counter: Counter
|
|
86
|
+
simpleMessageLib: SimpleMessageLib
|
|
87
|
+
utils: Utils
|
|
88
|
+
zro: Zro
|
|
89
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
|
|
4
|
+
import { SuiClient, SuiExecutionResult, SuiTransactionBlockResponse } from '@mysten/sui/client'
|
|
5
|
+
import { Keypair } from '@mysten/sui/cryptography'
|
|
6
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
|
|
7
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
8
|
+
|
|
9
|
+
export async function devInspectTransaction(
|
|
10
|
+
suiClient: SuiClient,
|
|
11
|
+
tx: Transaction,
|
|
12
|
+
sender: string
|
|
13
|
+
): Promise<SuiExecutionResult[] | null | undefined> {
|
|
14
|
+
const { results, error } = await suiClient.devInspectTransactionBlock({
|
|
15
|
+
transactionBlock: tx,
|
|
16
|
+
sender: sender,
|
|
17
|
+
})
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
19
|
+
if (error != undefined && error != null) {
|
|
20
|
+
throw new Error(error)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return results
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function moveView(
|
|
27
|
+
suiClient: SuiClient,
|
|
28
|
+
tx: Transaction,
|
|
29
|
+
sender?: string
|
|
30
|
+
): Promise<SuiExecutionResult | null | undefined> {
|
|
31
|
+
if (sender === undefined) {
|
|
32
|
+
sender = Ed25519Keypair.generate().toSuiAddress()
|
|
33
|
+
}
|
|
34
|
+
const result = await devInspectTransaction(suiClient, tx, sender)
|
|
35
|
+
return result ? result[result.length - 1] : null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readAddressFromDeployment(network: string, name: string): string | undefined {
|
|
39
|
+
const deploymentPath = path.join(__dirname, '..', 'deployments', network, `${name}.json`)
|
|
40
|
+
if (!fs.existsSync(deploymentPath)) {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
const deployment = JSON.parse(fs.readFileSync(deploymentPath, 'utf8')) as { address: string }
|
|
44
|
+
return deployment.address
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function validateTransaction(
|
|
48
|
+
client: SuiClient,
|
|
49
|
+
signer: Keypair,
|
|
50
|
+
tx: Transaction
|
|
51
|
+
): Promise<SuiTransactionBlockResponse> {
|
|
52
|
+
tx.setSenderIfNotSet(signer.getPublicKey().toSuiAddress())
|
|
53
|
+
const result = await client.signAndExecuteTransaction({
|
|
54
|
+
signer,
|
|
55
|
+
transaction: tx,
|
|
56
|
+
options: {
|
|
57
|
+
showEffects: true,
|
|
58
|
+
showObjectChanges: true,
|
|
59
|
+
showEvents: true,
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (result.effects?.status.status !== 'success') {
|
|
64
|
+
throw new Error(result.effects?.status.error)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await client.waitForTransaction({ digest: result.digest })
|
|
68
|
+
return result
|
|
69
|
+
}
|
package/src/endpoint.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Transaction } from '@mysten/sui/transactions'
|
|
2
|
-
|
|
3
|
-
export async function initEid(): Promise<Transaction> {
|
|
4
|
-
throw new Error('Not implemented')
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// TODO: add more mutate functions here
|
|
8
|
-
|
|
9
|
-
export async function eid(): Promise<number> {
|
|
10
|
-
// TODO: implement
|
|
11
|
-
return Promise.resolve(1)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getSendLibrary(sender: string, dst_eid: number): Promise<string> {
|
|
15
|
-
throw new Error('Not implemented')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function getConfig(): Promise<string> {
|
|
19
|
-
throw new Error('Not implemented')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// TODO: more view functions to be added here
|
|
23
|
-
|
|
24
|
-
export async function populateQuoteTransaction(tx: Transaction): Promise<void> {
|
|
25
|
-
// TODO: implement
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function populateSendTransaction(tx: Transaction): Promise<void> {
|
|
29
|
-
// TODO: implement
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function populateGetConfigTransaction(tx: Transaction): Promise<void> {
|
|
33
|
-
// TODO: implement
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function populateSetConfigTransaction(tx: Transaction): Promise<void> {
|
|
37
|
-
// TODO: implement
|
|
38
|
-
}
|