@layerzerolabs/lz-sui-sdk-v2 3.0.133 → 3.0.134-sui.0
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 +8 -0
- package/deployments/sui-sandbox-local/blocked_message_lib.json +24 -24
- package/deployments/sui-sandbox-local/blocked_msglib_ptb_builder.json +26 -26
- package/deployments/sui-sandbox-local/counter.json +69 -34
- package/deployments/sui-sandbox-local/dvn.json +15 -14
- package/deployments/sui-sandbox-local/dvn_call_type.json +28 -28
- package/deployments/sui-sandbox-local/dvn_fee_lib.json +27 -27
- package/deployments/sui-sandbox-local/dvn_layerzero.json +24 -24
- package/deployments/sui-sandbox-local/dvn_ptb_builder.json +21 -21
- package/deployments/sui-sandbox-local/endpoint_ptb_builder.json +30 -30
- package/deployments/sui-sandbox-local/executor.json +21 -20
- package/deployments/sui-sandbox-local/executor_call_type.json +21 -21
- package/deployments/sui-sandbox-local/executor_fee_lib.json +32 -32
- package/deployments/sui-sandbox-local/executor_layerzero.json +20 -20
- package/deployments/sui-sandbox-local/executor_ptb_builder.json +21 -21
- package/deployments/sui-sandbox-local/layerzero_views.json +13 -13
- package/deployments/sui-sandbox-local/message_lib_common.json +20 -20
- package/deployments/sui-sandbox-local/msglib_ptb_builder_call_types.json +20 -20
- package/deployments/sui-sandbox-local/oapp.json +23 -21
- package/deployments/sui-sandbox-local/object-BlockedMessageLib.json +5 -5
- package/deployments/sui-sandbox-local/object-BlockedMsglibPtbBuilder.json +5 -5
- package/deployments/sui-sandbox-local/object-Counter.json +5 -5
- package/deployments/sui-sandbox-local/object-CounterAdminCap.json +5 -5
- package/deployments/sui-sandbox-local/object-CounterOApp.json +5 -5
- package/deployments/sui-sandbox-local/object-DVN.json +2 -2
- package/deployments/sui-sandbox-local/object-DVNCap.json +4 -4
- package/deployments/sui-sandbox-local/object-DVNFeeLib.json +5 -5
- package/deployments/sui-sandbox-local/object-EndpointPtbBuilder.json +5 -5
- package/deployments/sui-sandbox-local/object-EndpointPtbBuilderAdminCap.json +5 -5
- package/deployments/sui-sandbox-local/object-Executor.json +2 -2
- package/deployments/sui-sandbox-local/object-ExecutorCap.json +3 -3
- package/deployments/sui-sandbox-local/object-ExecutorFeeLib.json +5 -5
- package/deployments/sui-sandbox-local/object-ExecutorOwnerCap.json +2 -2
- package/deployments/sui-sandbox-local/object-PackageWhitelistValidator.json +5 -5
- package/deployments/sui-sandbox-local/object-PriceFeed.json +5 -5
- package/deployments/sui-sandbox-local/object-PriceFeedOwnerCap.json +5 -5
- package/deployments/sui-sandbox-local/object-SimpleMessageLib.json +5 -5
- package/deployments/sui-sandbox-local/object-SimpleMessageLibAdminCap.json +5 -5
- package/deployments/sui-sandbox-local/object-SmlPtbBuilder.json +5 -5
- package/deployments/sui-sandbox-local/object-Treasury.json +5 -5
- package/deployments/sui-sandbox-local/object-TreasuryAdminCap.json +5 -5
- package/deployments/sui-sandbox-local/object-ULN302.json +5 -5
- package/deployments/sui-sandbox-local/object-ULN302AdminCap.json +5 -5
- package/deployments/sui-sandbox-local/object-Uln302PtbBuilder.json +5 -5
- package/deployments/sui-sandbox-local/object-Uln302Verification.json +5 -5
- package/deployments/sui-sandbox-local/object-WorkerRegistry.json +9 -0
- package/deployments/sui-sandbox-local/package_whitelist_validator.json +48 -48
- package/deployments/sui-sandbox-local/price_feed.json +40 -40
- package/deployments/sui-sandbox-local/price_feed_call_types.json +12 -12
- package/deployments/sui-sandbox-local/ptb_move_call.json +12 -12
- package/deployments/sui-sandbox-local/simple_message_lib.json +29 -29
- package/deployments/sui-sandbox-local/simple_msglib_ptb_builder.json +18 -18
- package/deployments/sui-sandbox-local/treasury.json +40 -40
- package/deployments/sui-sandbox-local/uln_302.json +50 -50
- package/deployments/sui-sandbox-local/uln_302_ptb_builder.json +22 -22
- package/deployments/sui-sandbox-local/worker_common.json +15 -14
- package/deployments/sui-sandbox-local/worker_registry.json +58 -0
- package/dist/index.cjs +834 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +541 -316
- package/dist/index.d.ts +541 -316
- package/dist/index.mjs +828 -295
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/bcs/index.ts +2 -1
- package/src/bcs/oapp.ts +14 -0
- package/src/generated/addresses.ts +66 -48
- package/src/module-manager.ts +15 -3
- package/src/modules/endpoint.ts +2 -3
- package/src/modules/oapps/counter.ts +30 -47
- package/src/modules/oapps/oapp.ts +468 -62
- package/src/modules/ptb-builders/ptb-builder.ts +10 -4
- package/src/modules/workers/dvn-layerzero.ts +1 -0
- package/src/modules/workers/dvn.ts +59 -0
- package/src/modules/workers/executor-layerzero.ts +1 -0
- package/src/modules/workers/executor.ts +59 -0
- package/src/modules/workers/index.ts +1 -0
- package/src/modules/workers/worker-registry.ts +109 -0
- package/src/resource.ts +3 -0
- package/src/sdk.ts +7 -2
- package/src/types/endpoint.ts +2 -1
- package/src/types/modules.ts +1 -0
- package/src/types/oapp.ts +6 -0
- package/src/types/options.ts +15 -0
- package/src/utils/transaction.ts +3 -3
|
@@ -2,9 +2,21 @@ import { bcs } from '@mysten/sui/bcs'
|
|
|
2
2
|
import { SuiClient } from '@mysten/sui/client'
|
|
3
3
|
import { Transaction, TransactionArgument, TransactionResult } from '@mysten/sui/transactions'
|
|
4
4
|
|
|
5
|
+
import { OAppInfoV1Bcs } from '../../bcs'
|
|
5
6
|
import { ModuleManager } from '../../module-manager'
|
|
6
7
|
import { ObjectOptions } from '../../types'
|
|
7
|
-
import {
|
|
8
|
+
import { OAppInfoV1 } from '../../types/oapp'
|
|
9
|
+
import {
|
|
10
|
+
asAddress,
|
|
11
|
+
asBytes,
|
|
12
|
+
asBytes32,
|
|
13
|
+
asObject,
|
|
14
|
+
asU16,
|
|
15
|
+
asU32,
|
|
16
|
+
asU64,
|
|
17
|
+
executeSimulate,
|
|
18
|
+
isTransactionArgument,
|
|
19
|
+
} from '../../utils'
|
|
8
20
|
|
|
9
21
|
const MODULE_NAME = 'oapp'
|
|
10
22
|
|
|
@@ -25,20 +37,28 @@ export const OAppErrorCode = {
|
|
|
25
37
|
|
|
26
38
|
export class OApp {
|
|
27
39
|
public packageId: string
|
|
40
|
+
public oappCallCapId: string
|
|
28
41
|
public readonly client: SuiClient
|
|
42
|
+
public oappInfo: OAppInfoV1 | null = null
|
|
29
43
|
private readonly objects: ObjectOptions
|
|
30
44
|
|
|
31
45
|
constructor(
|
|
32
46
|
packageId: string,
|
|
47
|
+
oappCallCapId: string,
|
|
33
48
|
client: SuiClient,
|
|
34
49
|
objects: ObjectOptions,
|
|
35
50
|
private readonly moduleManager: ModuleManager
|
|
36
51
|
) {
|
|
37
52
|
this.packageId = packageId
|
|
53
|
+
this.oappCallCapId = oappCallCapId
|
|
38
54
|
this.client = client
|
|
39
55
|
this.objects = objects
|
|
40
56
|
}
|
|
41
57
|
|
|
58
|
+
// setOAppInfo(oappInfo: OAppInfoV1): void {
|
|
59
|
+
// this.oappInfo = oappInfo
|
|
60
|
+
// }
|
|
61
|
+
|
|
42
62
|
// === Set Functions ===
|
|
43
63
|
|
|
44
64
|
/**
|
|
@@ -50,18 +70,18 @@ export class OApp {
|
|
|
50
70
|
* @param msgType - Message type or transaction argument
|
|
51
71
|
* @param options - Enforced options as bytes or transaction argument
|
|
52
72
|
*/
|
|
53
|
-
setEnforcedOptionsMoveCall(
|
|
73
|
+
async setEnforcedOptionsMoveCall(
|
|
54
74
|
tx: Transaction,
|
|
55
|
-
oapp: string | TransactionArgument,
|
|
56
|
-
adminCap: string | TransactionArgument,
|
|
57
75
|
eid: number | TransactionArgument,
|
|
58
76
|
msgType: number | TransactionArgument,
|
|
59
77
|
options: Uint8Array | TransactionArgument
|
|
60
|
-
): void {
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
const oappInfo = await this.#oappInfo()
|
|
80
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
61
81
|
tx.moveCall({
|
|
62
82
|
target: this.#target('set_enforced_options'),
|
|
63
83
|
arguments: [
|
|
64
|
-
asObject(tx,
|
|
84
|
+
asObject(tx, oappInfo.oapp_object),
|
|
65
85
|
asObject(tx, adminCap),
|
|
66
86
|
asU32(tx, eid),
|
|
67
87
|
asU16(tx, msgType),
|
|
@@ -78,18 +98,21 @@ export class OApp {
|
|
|
78
98
|
* @param eid - Peer endpoint ID or transaction argument
|
|
79
99
|
* @param peer - Peer OApp address as bytes or transaction argument
|
|
80
100
|
*/
|
|
81
|
-
setPeerMoveCall(
|
|
101
|
+
async setPeerMoveCall(
|
|
82
102
|
tx: Transaction,
|
|
83
|
-
oapp: string | TransactionArgument,
|
|
84
|
-
adminCap: string | TransactionArgument,
|
|
85
103
|
eid: number | TransactionArgument,
|
|
86
104
|
peer: Uint8Array | TransactionArgument
|
|
87
|
-
): void {
|
|
105
|
+
): Promise<void> {
|
|
106
|
+
const oappInfo = await this.#oappInfo()
|
|
107
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
108
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
88
109
|
tx.moveCall({
|
|
89
110
|
target: this.#target('set_peer'),
|
|
90
111
|
arguments: [
|
|
91
|
-
asObject(tx,
|
|
112
|
+
asObject(tx, oappInfo.oapp_object),
|
|
92
113
|
asObject(tx, adminCap),
|
|
114
|
+
asObject(tx, this.objects.endpointV2),
|
|
115
|
+
asObject(tx, messagingChannel),
|
|
93
116
|
asU32(tx, eid),
|
|
94
117
|
asBytes32(tx, peer, this.moduleManager.getUtils()),
|
|
95
118
|
],
|
|
@@ -99,56 +122,57 @@ export class OApp {
|
|
|
99
122
|
// === View Functions ===
|
|
100
123
|
|
|
101
124
|
/**
|
|
102
|
-
* Get admin address for OApp
|
|
125
|
+
* Get admin capability address for OApp
|
|
103
126
|
* @param tx - The transaction to add the move call to
|
|
104
127
|
* @param oapp - The OApp object ID or transaction argument
|
|
105
|
-
* @returns Transaction result containing the admin address
|
|
128
|
+
* @returns Transaction result containing the admin capability address
|
|
106
129
|
*/
|
|
107
|
-
|
|
130
|
+
getAdminCapMoveCall(tx: Transaction, oapp: string | TransactionArgument): TransactionResult {
|
|
108
131
|
return tx.moveCall({
|
|
109
|
-
target: this.#target('
|
|
132
|
+
target: this.#target('admin_cap'),
|
|
110
133
|
arguments: [asObject(tx, oapp)],
|
|
111
134
|
})
|
|
112
135
|
}
|
|
113
136
|
|
|
114
137
|
/**
|
|
115
|
-
* Get admin address for OApp
|
|
138
|
+
* Get admin capability address for OApp
|
|
116
139
|
* @param oapp - The OApp object ID
|
|
117
|
-
* @returns Promise<string> - The admin address
|
|
140
|
+
* @returns Promise<string> - The admin capability address
|
|
118
141
|
*/
|
|
119
|
-
async
|
|
142
|
+
async getAdminCap(oapp: string): Promise<string> {
|
|
120
143
|
return executeSimulate(
|
|
121
144
|
this.client,
|
|
122
145
|
(tx) => {
|
|
123
|
-
this.
|
|
146
|
+
this.getAdminCapMoveCall(tx, oapp)
|
|
124
147
|
},
|
|
125
148
|
(result) => bcs.Address.parse(result[0].value)
|
|
126
149
|
)
|
|
127
150
|
}
|
|
128
151
|
|
|
129
152
|
/**
|
|
130
|
-
* Get OApp
|
|
153
|
+
* Get OApp CallCap identifier
|
|
131
154
|
* @param tx - The transaction to add the move call to
|
|
132
155
|
* @param oapp - The OApp object ID or transaction argument
|
|
133
|
-
* @returns Transaction result containing the OApp
|
|
156
|
+
* @returns Transaction result containing the OApp CallCap identifier
|
|
134
157
|
*/
|
|
135
|
-
|
|
158
|
+
async getOAppCapIdMoveCall(tx: Transaction): Promise<TransactionResult> {
|
|
159
|
+
const oappInfo = await this.#oappInfo()
|
|
136
160
|
return tx.moveCall({
|
|
137
|
-
target: this.#target('
|
|
138
|
-
arguments: [asObject(tx,
|
|
161
|
+
target: this.#target('oapp_cap_id'),
|
|
162
|
+
arguments: [asObject(tx, oappInfo.oapp_object)],
|
|
139
163
|
})
|
|
140
164
|
}
|
|
141
165
|
|
|
142
166
|
/**
|
|
143
|
-
* Get OApp
|
|
144
|
-
* @param oapp - The OApp object ID
|
|
145
|
-
* @returns Promise<string> - The OApp
|
|
167
|
+
* Get OApp CallCap identifier
|
|
168
|
+
* @param oapp - The OApp object ID (optional, uses configured oapp if not provided)
|
|
169
|
+
* @returns Promise<string> - The OApp CallCap identifier
|
|
146
170
|
*/
|
|
147
|
-
async
|
|
171
|
+
async getOAppCapId(): Promise<string> {
|
|
148
172
|
return executeSimulate(
|
|
149
173
|
this.client,
|
|
150
|
-
(tx) => {
|
|
151
|
-
this.
|
|
174
|
+
async (tx) => {
|
|
175
|
+
await this.getOAppCapIdMoveCall(tx)
|
|
152
176
|
},
|
|
153
177
|
(result) => bcs.Address.parse(result[0].value)
|
|
154
178
|
)
|
|
@@ -163,16 +187,21 @@ export class OApp {
|
|
|
163
187
|
* @param extraOptions - Extra options to combine with enforced options or transaction argument
|
|
164
188
|
* @returns Transaction result containing combined options
|
|
165
189
|
*/
|
|
166
|
-
combineOptionsMoveCall(
|
|
190
|
+
async combineOptionsMoveCall(
|
|
167
191
|
tx: Transaction,
|
|
168
|
-
oapp: string | TransactionArgument,
|
|
169
192
|
eid: number | TransactionArgument,
|
|
170
193
|
msgType: number | TransactionArgument,
|
|
171
194
|
extraOptions: Uint8Array | TransactionArgument
|
|
172
|
-
): TransactionResult {
|
|
195
|
+
): Promise<TransactionResult> {
|
|
196
|
+
const oappInfo = await this.#oappInfo()
|
|
173
197
|
return tx.moveCall({
|
|
174
198
|
target: this.#target('combine_options'),
|
|
175
|
-
arguments: [
|
|
199
|
+
arguments: [
|
|
200
|
+
asObject(tx, oappInfo.oapp_object),
|
|
201
|
+
asU32(tx, eid),
|
|
202
|
+
asU16(tx, msgType),
|
|
203
|
+
asBytes(tx, extraOptions),
|
|
204
|
+
],
|
|
176
205
|
})
|
|
177
206
|
}
|
|
178
207
|
|
|
@@ -184,11 +213,11 @@ export class OApp {
|
|
|
184
213
|
* @param extraOptions - Extra options to combine with enforced options
|
|
185
214
|
* @returns Promise<Uint8Array> - Combined options as bytes
|
|
186
215
|
*/
|
|
187
|
-
async combineOptions(
|
|
216
|
+
async combineOptions(eid: number, msgType: number, extraOptions: Uint8Array): Promise<Uint8Array> {
|
|
188
217
|
return executeSimulate(
|
|
189
218
|
this.client,
|
|
190
|
-
(tx) => {
|
|
191
|
-
this.combineOptionsMoveCall(tx,
|
|
219
|
+
async (tx) => {
|
|
220
|
+
await this.combineOptionsMoveCall(tx, eid, msgType, extraOptions)
|
|
192
221
|
},
|
|
193
222
|
(result) => new Uint8Array(bcs.vector(bcs.u8()).parse(result[0].value))
|
|
194
223
|
)
|
|
@@ -202,15 +231,15 @@ export class OApp {
|
|
|
202
231
|
* @param msgType - Message type or transaction argument
|
|
203
232
|
* @returns Transaction result containing enforced options
|
|
204
233
|
*/
|
|
205
|
-
getEnforcedOptionsMoveCall(
|
|
234
|
+
async getEnforcedOptionsMoveCall(
|
|
206
235
|
tx: Transaction,
|
|
207
|
-
oapp: string | TransactionArgument,
|
|
208
236
|
eid: number | TransactionArgument,
|
|
209
237
|
msgType: number | TransactionArgument
|
|
210
|
-
): TransactionResult {
|
|
238
|
+
): Promise<TransactionResult> {
|
|
239
|
+
const oappInfo = await this.#oappInfo()
|
|
211
240
|
return tx.moveCall({
|
|
212
241
|
target: this.#target('get_enforced_options'),
|
|
213
|
-
arguments: [asObject(tx,
|
|
242
|
+
arguments: [asObject(tx, oappInfo.oapp_object), asU32(tx, eid), asU16(tx, msgType)],
|
|
214
243
|
})
|
|
215
244
|
}
|
|
216
245
|
|
|
@@ -221,11 +250,11 @@ export class OApp {
|
|
|
221
250
|
* @param msgType - Message type
|
|
222
251
|
* @returns Promise<Uint8Array> - Enforced options as bytes
|
|
223
252
|
*/
|
|
224
|
-
async getEnforcedOptions(
|
|
253
|
+
async getEnforcedOptions(eid: number, msgType: number): Promise<Uint8Array> {
|
|
225
254
|
return executeSimulate(
|
|
226
255
|
this.client,
|
|
227
|
-
(tx) => {
|
|
228
|
-
this.getEnforcedOptionsMoveCall(tx,
|
|
256
|
+
async (tx) => {
|
|
257
|
+
await this.getEnforcedOptionsMoveCall(tx, eid, msgType)
|
|
229
258
|
},
|
|
230
259
|
(result) => new Uint8Array(bcs.vector(bcs.u8()).parse(result[0].value))
|
|
231
260
|
)
|
|
@@ -238,14 +267,11 @@ export class OApp {
|
|
|
238
267
|
* @param dstEid - Destination endpoint ID or transaction argument
|
|
239
268
|
* @returns Transaction result containing boolean result
|
|
240
269
|
*/
|
|
241
|
-
hasPeerMoveCall(
|
|
242
|
-
|
|
243
|
-
oapp: string | TransactionArgument,
|
|
244
|
-
dstEid: number | TransactionArgument
|
|
245
|
-
): TransactionResult {
|
|
270
|
+
async hasPeerMoveCall(tx: Transaction, dstEid: number | TransactionArgument): Promise<TransactionResult> {
|
|
271
|
+
const oappInfo = await this.#oappInfo()
|
|
246
272
|
return tx.moveCall({
|
|
247
273
|
target: this.#target('has_peer'),
|
|
248
|
-
arguments: [asObject(tx,
|
|
274
|
+
arguments: [asObject(tx, oappInfo.oapp_object), asU32(tx, dstEid)],
|
|
249
275
|
})
|
|
250
276
|
}
|
|
251
277
|
|
|
@@ -255,11 +281,11 @@ export class OApp {
|
|
|
255
281
|
* @param dstEid - Destination endpoint ID
|
|
256
282
|
* @returns Promise<boolean> - True if peer is configured, false otherwise
|
|
257
283
|
*/
|
|
258
|
-
async hasPeer(
|
|
284
|
+
async hasPeer(dstEid: number): Promise<boolean> {
|
|
259
285
|
return executeSimulate(
|
|
260
286
|
this.client,
|
|
261
|
-
(tx) => {
|
|
262
|
-
this.hasPeerMoveCall(tx,
|
|
287
|
+
async (tx) => {
|
|
288
|
+
await this.hasPeerMoveCall(tx, dstEid)
|
|
263
289
|
},
|
|
264
290
|
(result) => bcs.Bool.parse(result[0].value)
|
|
265
291
|
)
|
|
@@ -272,14 +298,11 @@ export class OApp {
|
|
|
272
298
|
* @param dstEid - Destination endpoint ID or transaction argument
|
|
273
299
|
* @returns Transaction result containing peer address
|
|
274
300
|
*/
|
|
275
|
-
getPeerMoveCall(
|
|
276
|
-
|
|
277
|
-
oapp: string | TransactionArgument,
|
|
278
|
-
dstEid: number | TransactionArgument
|
|
279
|
-
): TransactionResult {
|
|
301
|
+
async getPeerMoveCall(tx: Transaction, dstEid: number | TransactionArgument): Promise<TransactionResult> {
|
|
302
|
+
const oappInfo = await this.#oappInfo()
|
|
280
303
|
return tx.moveCall({
|
|
281
304
|
target: this.#target('get_peer'),
|
|
282
|
-
arguments: [asObject(tx,
|
|
305
|
+
arguments: [asObject(tx, oappInfo.oapp_object), asU32(tx, dstEid)],
|
|
283
306
|
})
|
|
284
307
|
}
|
|
285
308
|
|
|
@@ -289,11 +312,11 @@ export class OApp {
|
|
|
289
312
|
* @param dstEid - Destination endpoint ID
|
|
290
313
|
* @returns Promise<Uint8Array> - Peer address as bytes32
|
|
291
314
|
*/
|
|
292
|
-
async getPeer(
|
|
315
|
+
async getPeer(dstEid: number): Promise<Uint8Array> {
|
|
293
316
|
return executeSimulate(
|
|
294
317
|
this.client,
|
|
295
|
-
(tx) => {
|
|
296
|
-
this.getPeerMoveCall(tx,
|
|
318
|
+
async (tx) => {
|
|
319
|
+
await this.getPeerMoveCall(tx, dstEid)
|
|
297
320
|
},
|
|
298
321
|
(result) => {
|
|
299
322
|
return new Uint8Array(bcs.vector(bcs.u8()).parse(result[0].value))
|
|
@@ -301,8 +324,391 @@ export class OApp {
|
|
|
301
324
|
)
|
|
302
325
|
}
|
|
303
326
|
|
|
327
|
+
getOAppInfoV1MoveCall(tx: Transaction): TransactionResult {
|
|
328
|
+
const endpoint = this.moduleManager.getEndpoint()
|
|
329
|
+
const oappInfoRaw = endpoint.getLzReceiveInfoMoveCall(tx, this.oappCallCapId) // the new OAppInfo used to be named as lz_receive_info
|
|
330
|
+
return tx.moveCall({
|
|
331
|
+
target: `${this.packageId}::oapp_info_v1::decode`,
|
|
332
|
+
arguments: [oappInfoRaw],
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async getOAppInfoV1(): Promise<OAppInfoV1> {
|
|
337
|
+
return executeSimulate(
|
|
338
|
+
this.client,
|
|
339
|
+
(tx) => {
|
|
340
|
+
this.getOAppInfoV1MoveCall(tx)
|
|
341
|
+
},
|
|
342
|
+
(result) => {
|
|
343
|
+
return OAppInfoV1Bcs.parse(result[0].value)
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// === Endpoint Call Functions ===
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Register OApp with the endpoint
|
|
352
|
+
* @param tx - The transaction to add the move call to
|
|
353
|
+
* @param oappInfo - OApp information as bytes (optional)
|
|
354
|
+
* @returns Transaction result containing the messaging channel address
|
|
355
|
+
*/
|
|
356
|
+
async registerOAppMoveCall(
|
|
357
|
+
tx: Transaction,
|
|
358
|
+
oappInfo?: Uint8Array | TransactionArgument
|
|
359
|
+
): Promise<TransactionResult> {
|
|
360
|
+
let oappInfoArg: TransactionArgument
|
|
361
|
+
if (isTransactionArgument(oappInfo)) {
|
|
362
|
+
oappInfoArg = oappInfo
|
|
363
|
+
} else if (oappInfo) {
|
|
364
|
+
// For Some(vector<u8>), convert Uint8Array to number[] and wrap in Option
|
|
365
|
+
oappInfoArg = tx.pure.option('vector<u8>', Array.from(oappInfo))
|
|
366
|
+
} else {
|
|
367
|
+
// For None
|
|
368
|
+
oappInfoArg = tx.pure.option('vector<u8>', null)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const oappInfoObj = await this.#oappInfo()
|
|
372
|
+
const adminCap = await this.getAdminCap(oappInfoObj.oapp_object)
|
|
373
|
+
return tx.moveCall({
|
|
374
|
+
target: this.#target('register_oapp', 'endpoint_calls'),
|
|
375
|
+
arguments: [
|
|
376
|
+
asObject(tx, oappInfoObj.oapp_object),
|
|
377
|
+
asObject(tx, adminCap),
|
|
378
|
+
asObject(tx, this.objects.endpointV2),
|
|
379
|
+
oappInfoArg,
|
|
380
|
+
],
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Set delegate for OApp
|
|
386
|
+
* @param tx - The transaction to add the move call to
|
|
387
|
+
* @param newDelegate - New delegate address
|
|
388
|
+
*/
|
|
389
|
+
async setDelegateMoveCall(tx: Transaction, newDelegate: string | TransactionArgument): Promise<void> {
|
|
390
|
+
const oappInfo = await this.#oappInfo()
|
|
391
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
392
|
+
tx.moveCall({
|
|
393
|
+
target: this.#target('set_delegate', 'endpoint_calls'),
|
|
394
|
+
arguments: [
|
|
395
|
+
asObject(tx, oappInfo.oapp_object),
|
|
396
|
+
asObject(tx, adminCap),
|
|
397
|
+
asObject(tx, this.objects.endpointV2),
|
|
398
|
+
asAddress(tx, newDelegate),
|
|
399
|
+
],
|
|
400
|
+
})
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Set OApp information in the endpoint
|
|
405
|
+
* @param tx - The transaction to add the move call to
|
|
406
|
+
* @param oappInfo - OApp information as bytes
|
|
407
|
+
*/
|
|
408
|
+
async setOAppInfoMoveCall(tx: Transaction, oappInfo: Uint8Array | TransactionArgument): Promise<void> {
|
|
409
|
+
const oappInfoObj = await this.#oappInfo()
|
|
410
|
+
const adminCap = await this.getAdminCap(oappInfoObj.oapp_object)
|
|
411
|
+
tx.moveCall({
|
|
412
|
+
target: this.#target('set_oapp_info', 'endpoint_calls'),
|
|
413
|
+
arguments: [
|
|
414
|
+
asObject(tx, oappInfoObj.oapp_object),
|
|
415
|
+
asObject(tx, adminCap),
|
|
416
|
+
asObject(tx, this.objects.endpointV2),
|
|
417
|
+
asBytes(tx, oappInfo),
|
|
418
|
+
],
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Initialize channel with remote OApp
|
|
424
|
+
* @param tx - The transaction to add the move call to
|
|
425
|
+
* @param remoteEid - Remote endpoint ID
|
|
426
|
+
* @param remoteOApp - Remote OApp address as bytes32
|
|
427
|
+
*/
|
|
428
|
+
async initChannelMoveCall(
|
|
429
|
+
tx: Transaction,
|
|
430
|
+
remoteEid: number | TransactionArgument,
|
|
431
|
+
remoteOApp: Uint8Array | TransactionArgument
|
|
432
|
+
): Promise<void> {
|
|
433
|
+
const oappInfo = await this.#oappInfo()
|
|
434
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
435
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
436
|
+
tx.moveCall({
|
|
437
|
+
target: this.#target('init_channel', 'endpoint_calls'),
|
|
438
|
+
arguments: [
|
|
439
|
+
asObject(tx, oappInfo.oapp_object),
|
|
440
|
+
asObject(tx, adminCap),
|
|
441
|
+
asObject(tx, this.objects.endpointV2),
|
|
442
|
+
asObject(tx, messagingChannel),
|
|
443
|
+
asU32(tx, remoteEid),
|
|
444
|
+
asBytes32(tx, remoteOApp, this.moduleManager.getUtils()),
|
|
445
|
+
],
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Clear a message from the messaging channel
|
|
451
|
+
* @param tx - The transaction to add the move call to
|
|
452
|
+
* @param srcEid - Source endpoint ID
|
|
453
|
+
* @param sender - Sender address as bytes32
|
|
454
|
+
* @param nonce - Message nonce
|
|
455
|
+
* @param guid - Message GUID as bytes32
|
|
456
|
+
* @param message - Message payload
|
|
457
|
+
*/
|
|
458
|
+
async clearMoveCall(
|
|
459
|
+
tx: Transaction,
|
|
460
|
+
srcEid: number | TransactionArgument,
|
|
461
|
+
sender: Uint8Array | TransactionArgument,
|
|
462
|
+
nonce: number | bigint | TransactionArgument,
|
|
463
|
+
guid: Uint8Array | TransactionArgument,
|
|
464
|
+
message: Uint8Array | TransactionArgument
|
|
465
|
+
): Promise<void> {
|
|
466
|
+
const oappInfo = await this.#oappInfo()
|
|
467
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
468
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
469
|
+
tx.moveCall({
|
|
470
|
+
target: this.#target('clear', 'endpoint_calls'),
|
|
471
|
+
arguments: [
|
|
472
|
+
asObject(tx, oappInfo.oapp_object),
|
|
473
|
+
asObject(tx, adminCap),
|
|
474
|
+
asObject(tx, this.objects.endpointV2),
|
|
475
|
+
asObject(tx, messagingChannel),
|
|
476
|
+
asU32(tx, srcEid),
|
|
477
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
478
|
+
asU64(tx, nonce),
|
|
479
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
480
|
+
asBytes(tx, message),
|
|
481
|
+
],
|
|
482
|
+
})
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Skip a message in the messaging channel
|
|
487
|
+
* @param tx - The transaction to add the move call to
|
|
488
|
+
* @param srcEid - Source endpoint ID
|
|
489
|
+
* @param sender - Sender address as bytes32
|
|
490
|
+
* @param nonce - Message nonce
|
|
491
|
+
*/
|
|
492
|
+
async skipMoveCall(
|
|
493
|
+
tx: Transaction,
|
|
494
|
+
srcEid: number | TransactionArgument,
|
|
495
|
+
sender: Uint8Array | TransactionArgument,
|
|
496
|
+
nonce: number | bigint | TransactionArgument
|
|
497
|
+
): Promise<void> {
|
|
498
|
+
const oappInfo = await this.#oappInfo()
|
|
499
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
500
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
501
|
+
tx.moveCall({
|
|
502
|
+
target: this.#target('skip', 'endpoint_calls'),
|
|
503
|
+
arguments: [
|
|
504
|
+
asObject(tx, oappInfo.oapp_object),
|
|
505
|
+
asObject(tx, adminCap),
|
|
506
|
+
asObject(tx, this.objects.endpointV2),
|
|
507
|
+
asObject(tx, messagingChannel),
|
|
508
|
+
asU32(tx, srcEid),
|
|
509
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
510
|
+
asU64(tx, nonce),
|
|
511
|
+
],
|
|
512
|
+
})
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Nilify a message in the messaging channel
|
|
517
|
+
* @param tx - The transaction to add the move call to
|
|
518
|
+
* @param srcEid - Source endpoint ID
|
|
519
|
+
* @param sender - Sender address as bytes32
|
|
520
|
+
* @param nonce - Message nonce
|
|
521
|
+
* @param payloadHash - Payload hash as bytes32
|
|
522
|
+
*/
|
|
523
|
+
async nilifyMoveCall(
|
|
524
|
+
tx: Transaction,
|
|
525
|
+
srcEid: number | TransactionArgument,
|
|
526
|
+
sender: Uint8Array | TransactionArgument,
|
|
527
|
+
nonce: number | bigint | TransactionArgument,
|
|
528
|
+
payloadHash: Uint8Array | TransactionArgument
|
|
529
|
+
): Promise<void> {
|
|
530
|
+
const oappInfo = await this.#oappInfo()
|
|
531
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
532
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
533
|
+
tx.moveCall({
|
|
534
|
+
target: this.#target('nilify', 'endpoint_calls'),
|
|
535
|
+
arguments: [
|
|
536
|
+
asObject(tx, oappInfo.oapp_object),
|
|
537
|
+
asObject(tx, adminCap),
|
|
538
|
+
asObject(tx, this.objects.endpointV2),
|
|
539
|
+
asObject(tx, messagingChannel),
|
|
540
|
+
asU32(tx, srcEid),
|
|
541
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
542
|
+
asU64(tx, nonce),
|
|
543
|
+
asBytes32(tx, payloadHash, this.moduleManager.getUtils()),
|
|
544
|
+
],
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Burn a message in the messaging channel
|
|
550
|
+
* @param tx - The transaction to add the move call to
|
|
551
|
+
* @param srcEid - Source endpoint ID
|
|
552
|
+
* @param sender - Sender address as bytes32
|
|
553
|
+
* @param nonce - Message nonce
|
|
554
|
+
* @param payloadHash - Payload hash as bytes32
|
|
555
|
+
*/
|
|
556
|
+
async burnMoveCall(
|
|
557
|
+
tx: Transaction,
|
|
558
|
+
srcEid: number | TransactionArgument,
|
|
559
|
+
sender: Uint8Array | TransactionArgument,
|
|
560
|
+
nonce: number | bigint | TransactionArgument,
|
|
561
|
+
payloadHash: Uint8Array | TransactionArgument
|
|
562
|
+
): Promise<void> {
|
|
563
|
+
const oappInfo = await this.#oappInfo()
|
|
564
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
565
|
+
const messagingChannel = await this.moduleManager.getEndpoint().getMessagingChannel(this.oappCallCapId)
|
|
566
|
+
tx.moveCall({
|
|
567
|
+
target: this.#target('burn', 'endpoint_calls'),
|
|
568
|
+
arguments: [
|
|
569
|
+
asObject(tx, oappInfo.oapp_object),
|
|
570
|
+
asObject(tx, adminCap),
|
|
571
|
+
asObject(tx, this.objects.endpointV2),
|
|
572
|
+
asObject(tx, messagingChannel),
|
|
573
|
+
asU32(tx, srcEid),
|
|
574
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
575
|
+
asU64(tx, nonce),
|
|
576
|
+
asBytes32(tx, payloadHash, this.moduleManager.getUtils()),
|
|
577
|
+
],
|
|
578
|
+
})
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Set send library for a destination chain
|
|
583
|
+
* @param tx - The transaction to add the move call to
|
|
584
|
+
* @param dstEid - Destination endpoint ID
|
|
585
|
+
* @param sendLibrary - Send library address
|
|
586
|
+
*/
|
|
587
|
+
async setSendLibraryMoveCall(
|
|
588
|
+
tx: Transaction,
|
|
589
|
+
dstEid: number | TransactionArgument,
|
|
590
|
+
sendLibrary: string | TransactionArgument
|
|
591
|
+
): Promise<void> {
|
|
592
|
+
const oappInfo = await this.#oappInfo()
|
|
593
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
594
|
+
tx.moveCall({
|
|
595
|
+
target: this.#target('set_send_library', 'endpoint_calls'),
|
|
596
|
+
arguments: [
|
|
597
|
+
asObject(tx, oappInfo.oapp_object),
|
|
598
|
+
asObject(tx, adminCap),
|
|
599
|
+
asObject(tx, this.objects.endpointV2),
|
|
600
|
+
asU32(tx, dstEid),
|
|
601
|
+
asAddress(tx, sendLibrary),
|
|
602
|
+
],
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Set receive library for a source chain
|
|
608
|
+
* @param tx - The transaction to add the move call to
|
|
609
|
+
* @param srcEid - Source endpoint ID
|
|
610
|
+
* @param receiveLibrary - Receive library address
|
|
611
|
+
* @param gracePeriod - Grace period in seconds
|
|
612
|
+
*/
|
|
613
|
+
async setReceiveLibraryMoveCall(
|
|
614
|
+
tx: Transaction,
|
|
615
|
+
srcEid: number | TransactionArgument,
|
|
616
|
+
receiveLibrary: string | TransactionArgument,
|
|
617
|
+
gracePeriod: number | bigint | TransactionArgument
|
|
618
|
+
): Promise<void> {
|
|
619
|
+
const oappInfo = await this.#oappInfo()
|
|
620
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
621
|
+
tx.moveCall({
|
|
622
|
+
target: this.#target('set_receive_library', 'endpoint_calls'),
|
|
623
|
+
arguments: [
|
|
624
|
+
asObject(tx, oappInfo.oapp_object),
|
|
625
|
+
asObject(tx, adminCap),
|
|
626
|
+
asObject(tx, this.objects.endpointV2),
|
|
627
|
+
asU32(tx, srcEid),
|
|
628
|
+
asAddress(tx, receiveLibrary),
|
|
629
|
+
asU64(tx, gracePeriod),
|
|
630
|
+
tx.object.clock(),
|
|
631
|
+
],
|
|
632
|
+
})
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Set receive library timeout for a source chain
|
|
637
|
+
* @param tx - The transaction to add the move call to
|
|
638
|
+
* @param srcEid - Source endpoint ID
|
|
639
|
+
* @param receiveLibrary - Receive library address
|
|
640
|
+
* @param expiry - Expiry timestamp in seconds
|
|
641
|
+
*/
|
|
642
|
+
async setReceiveLibraryTimeoutMoveCall(
|
|
643
|
+
tx: Transaction,
|
|
644
|
+
srcEid: number | TransactionArgument,
|
|
645
|
+
receiveLibrary: string | TransactionArgument,
|
|
646
|
+
expiry: number | bigint | TransactionArgument
|
|
647
|
+
): Promise<void> {
|
|
648
|
+
const oappInfo = await this.#oappInfo()
|
|
649
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
650
|
+
tx.moveCall({
|
|
651
|
+
target: this.#target('set_receive_library_timeout', 'endpoint_calls'),
|
|
652
|
+
arguments: [
|
|
653
|
+
asObject(tx, oappInfo.oapp_object),
|
|
654
|
+
asObject(tx, adminCap),
|
|
655
|
+
asObject(tx, this.objects.endpointV2),
|
|
656
|
+
asU32(tx, srcEid),
|
|
657
|
+
asAddress(tx, receiveLibrary),
|
|
658
|
+
asU64(tx, expiry),
|
|
659
|
+
tx.object.clock(),
|
|
660
|
+
],
|
|
661
|
+
})
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Set configuration for a message library
|
|
666
|
+
* @param tx - The transaction to add the move call to
|
|
667
|
+
* @param lib - Library address
|
|
668
|
+
* @param eid - Endpoint ID
|
|
669
|
+
* @param configType - Configuration type
|
|
670
|
+
* @param config - Configuration data as bytes
|
|
671
|
+
* @returns Transaction result containing Call<MessageLibSetConfigParam, Void>
|
|
672
|
+
*/
|
|
673
|
+
async setConfigMoveCall(
|
|
674
|
+
tx: Transaction,
|
|
675
|
+
lib: string | TransactionArgument,
|
|
676
|
+
eid: number | TransactionArgument,
|
|
677
|
+
configType: number | TransactionArgument,
|
|
678
|
+
config: Uint8Array | TransactionArgument
|
|
679
|
+
): Promise<TransactionResult> {
|
|
680
|
+
const oappInfo = await this.#oappInfo()
|
|
681
|
+
const adminCap = await this.getAdminCap(oappInfo.oapp_object)
|
|
682
|
+
return tx.moveCall({
|
|
683
|
+
target: this.#target('set_config', 'endpoint_calls'),
|
|
684
|
+
typeArguments: [],
|
|
685
|
+
arguments: [
|
|
686
|
+
asObject(tx, oappInfo.oapp_object),
|
|
687
|
+
asObject(tx, adminCap),
|
|
688
|
+
asObject(tx, this.objects.endpointV2),
|
|
689
|
+
asAddress(tx, lib),
|
|
690
|
+
asU32(tx, eid),
|
|
691
|
+
asU32(tx, configType),
|
|
692
|
+
asBytes(tx, config),
|
|
693
|
+
],
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
|
|
304
697
|
// === Private Functions ===
|
|
305
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Get OApp info, throwing if not set
|
|
701
|
+
* @returns The OApp info
|
|
702
|
+
* @throws Error if OApp info is not set
|
|
703
|
+
* @private
|
|
704
|
+
*/
|
|
705
|
+
async #oappInfo(): Promise<OAppInfoV1> {
|
|
706
|
+
if (!this.oappInfo) {
|
|
707
|
+
this.oappInfo = await this.getOAppInfoV1()
|
|
708
|
+
}
|
|
709
|
+
return this.oappInfo
|
|
710
|
+
}
|
|
711
|
+
|
|
306
712
|
/**
|
|
307
713
|
* Generate the full target path for move calls
|
|
308
714
|
* @param name - The function name to call
|