@layerzerolabs/lz-sui-oft-sdk-v2 3.0.127-sui.1
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/README.md +95 -0
- package/dist/index.cjs +980 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +506 -0
- package/dist/index.d.ts +506 -0
- package/dist/index.mjs +967 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
- package/src/bcs/oft.ts +55 -0
- package/src/index.ts +8 -0
- package/src/modules/oft-composer-registry.ts +128 -0
- package/src/modules/oft-ptb-builder.ts +59 -0
- package/src/modules/oft.ts +978 -0
- package/src/types.ts +31 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var bcs = require('@mysten/sui/bcs');
|
|
4
|
+
var transactions = require('@mysten/sui/transactions');
|
|
5
|
+
var lzSuiSdkV2 = require('@layerzerolabs/lz-sui-sdk-v2');
|
|
6
|
+
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
11
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
12
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
13
|
+
var OFTLimitBcs = bcs.bcs.struct("OFTLimit", {
|
|
14
|
+
min_amount_ld: bcs.bcs.U64,
|
|
15
|
+
max_amount_ld: bcs.bcs.U64
|
|
16
|
+
});
|
|
17
|
+
var OFTFeeDetailBcs = bcs.bcs.struct("OFTFeeDetail", {
|
|
18
|
+
fee_amount_ld: bcs.bcs.U64,
|
|
19
|
+
is_reward: bcs.bcs.Bool,
|
|
20
|
+
description: bcs.bcs.String
|
|
21
|
+
});
|
|
22
|
+
var OFTReceiptBcs = bcs.bcs.struct("OFTReceipt", {
|
|
23
|
+
amount_sent_ld: bcs.bcs.U64,
|
|
24
|
+
amount_received_ld: bcs.bcs.U64
|
|
25
|
+
});
|
|
26
|
+
function parseOFTLimit(data) {
|
|
27
|
+
const parsed = OFTLimitBcs.parse(data);
|
|
28
|
+
return {
|
|
29
|
+
minAmountLd: BigInt(parsed.min_amount_ld),
|
|
30
|
+
maxAmountLd: BigInt(parsed.max_amount_ld)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function parseOFTFeeDetails(data) {
|
|
34
|
+
const vectorBcs = bcs.bcs.vector(OFTFeeDetailBcs);
|
|
35
|
+
const parsed = vectorBcs.parse(data);
|
|
36
|
+
return parsed.map(
|
|
37
|
+
(detail) => ({
|
|
38
|
+
feeAmountLd: BigInt(detail.fee_amount_ld),
|
|
39
|
+
isReward: detail.is_reward,
|
|
40
|
+
description: detail.description
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
function parseOFTReceipt(data) {
|
|
45
|
+
const parsed = OFTReceiptBcs.parse(data);
|
|
46
|
+
return {
|
|
47
|
+
amountSentLd: BigInt(parsed.amount_sent_ld),
|
|
48
|
+
amountReceivedLd: BigInt(parsed.amount_received_ld)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/modules/oft.ts
|
|
53
|
+
var MODULE_NAME = "oft";
|
|
54
|
+
var OFTErrorCode = {
|
|
55
|
+
// OFT related errors
|
|
56
|
+
OFT_EComposeMsgNotAllowed: 1,
|
|
57
|
+
OFT_EComposeMsgRequired: 2,
|
|
58
|
+
OFT_EInvalidComposeQueue: 3,
|
|
59
|
+
OFT_EInvalidLocalDecimals: 4,
|
|
60
|
+
OFT_EPaused: 5,
|
|
61
|
+
OFT_EPauseUnchanged: 6,
|
|
62
|
+
OFT_ESlippageExceeded: 7,
|
|
63
|
+
OFT_EInsufficientBalance: 8
|
|
64
|
+
};
|
|
65
|
+
var _OFT_instances, buildSendParam_fn, target_fn, adminCapId_fn;
|
|
66
|
+
var OFT = class {
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new OFT instance for interacting with an Omnichain Fungible Token
|
|
69
|
+
*
|
|
70
|
+
* @param protocolSDK - The LayerZero protocol SDK instance providing core cross-chain functionality
|
|
71
|
+
* @param corePackageId - The package ID of the core OFT framework (shared across all OFT implementations)
|
|
72
|
+
* @param packageId - The package ID of the specific OFT token implementation
|
|
73
|
+
* @param oftObjectId - The unique object ID of this OFT instance
|
|
74
|
+
* @param coinType - The Sui coin type string (e.g., "0x123::mycoin::MYCOIN")
|
|
75
|
+
* @param adminCapId - Optional admin capability object ID for privileged operations (required for admin functions)
|
|
76
|
+
*/
|
|
77
|
+
constructor(protocolSDK, corePackageId, packageId, oftObjectId, coinType, adminCapId) {
|
|
78
|
+
__privateAdd(this, _OFT_instances);
|
|
79
|
+
this.protocolSDK = protocolSDK;
|
|
80
|
+
this.packageId = packageId;
|
|
81
|
+
this.corePackageId = corePackageId;
|
|
82
|
+
this.client = protocolSDK.client;
|
|
83
|
+
this.objects = protocolSDK.objects;
|
|
84
|
+
this.oftObjectId = oftObjectId;
|
|
85
|
+
this.adminCapId = adminCapId;
|
|
86
|
+
this.coinType = coinType;
|
|
87
|
+
}
|
|
88
|
+
// ==========================================
|
|
89
|
+
// ADMIN FUNCTIONS
|
|
90
|
+
// ==========================================
|
|
91
|
+
// These functions require admin privileges and are used for OFT configuration
|
|
92
|
+
// and management. They require the adminCapId to be provided during construction.
|
|
93
|
+
/**
|
|
94
|
+
* Register OFT as an OApp with LayerZero endpoint
|
|
95
|
+
* @param tx - The transaction to add the move call to
|
|
96
|
+
* @param lzReceiveInfo - PTB Builder lzReceiveInfoMoveCall result, used for protocol SDK to dynamically build the PTB
|
|
97
|
+
* for OFT's lzReceive operation
|
|
98
|
+
*/
|
|
99
|
+
registerOAppMoveCall(tx, lzReceiveInfo) {
|
|
100
|
+
tx.moveCall({
|
|
101
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "register_oapp"),
|
|
102
|
+
typeArguments: [this.coinType],
|
|
103
|
+
arguments: [
|
|
104
|
+
tx.object(this.oftObjectId),
|
|
105
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
106
|
+
tx.object(this.objects.endpointV2),
|
|
107
|
+
lzSuiSdkV2.asBytes(tx, lzReceiveInfo)
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set enforced options for OFT messaging to a destination
|
|
113
|
+
* @param tx - The transaction to add the move call to
|
|
114
|
+
* @param eid - Endpoint ID
|
|
115
|
+
* @param msgType - Message type (SEND or SEND_AND_CALL)
|
|
116
|
+
* @param options - Enforced options as bytes
|
|
117
|
+
*/
|
|
118
|
+
setEnforcedOptionsMoveCall(tx, eid, msgType, options) {
|
|
119
|
+
tx.moveCall({
|
|
120
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_enforced_options"),
|
|
121
|
+
typeArguments: [this.coinType],
|
|
122
|
+
arguments: [
|
|
123
|
+
tx.object(this.oftObjectId),
|
|
124
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
125
|
+
lzSuiSdkV2.asU32(tx, eid),
|
|
126
|
+
lzSuiSdkV2.asU16(tx, msgType),
|
|
127
|
+
lzSuiSdkV2.asBytes(tx, options)
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Set peer OFT on another chain
|
|
133
|
+
* @param tx - The transaction to add the move call to
|
|
134
|
+
* @param messagingChannel - The messaging channel object ID
|
|
135
|
+
* @param eid - Peer endpoint ID
|
|
136
|
+
* @param peer - Peer OFT address as bytes
|
|
137
|
+
*/
|
|
138
|
+
setPeerMoveCall(tx, messagingChannel, eid, peer) {
|
|
139
|
+
tx.moveCall({
|
|
140
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_peer"),
|
|
141
|
+
typeArguments: [this.coinType],
|
|
142
|
+
arguments: [
|
|
143
|
+
tx.object(this.oftObjectId),
|
|
144
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
145
|
+
tx.object(this.objects.endpointV2),
|
|
146
|
+
lzSuiSdkV2.asObject(tx, messagingChannel),
|
|
147
|
+
lzSuiSdkV2.asU32(tx, eid),
|
|
148
|
+
lzSuiSdkV2.asBytes32(tx, peer, this.protocolSDK.getUtils())
|
|
149
|
+
]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Set delegate for OFT
|
|
154
|
+
* @param tx - The transaction to add the move call to
|
|
155
|
+
* @param newDelegate - The new delegate address
|
|
156
|
+
*/
|
|
157
|
+
setDelegateMoveCall(tx, newDelegate) {
|
|
158
|
+
tx.moveCall({
|
|
159
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_delegate"),
|
|
160
|
+
typeArguments: [this.coinType],
|
|
161
|
+
arguments: [
|
|
162
|
+
tx.object(this.oftObjectId),
|
|
163
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
164
|
+
tx.object(this.objects.endpointV2),
|
|
165
|
+
lzSuiSdkV2.asAddress(tx, newDelegate)
|
|
166
|
+
]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Set pause state for OFT operations
|
|
171
|
+
* @param tx - The transaction to add the move call to
|
|
172
|
+
* @param pause - Whether to pause or unpause operations
|
|
173
|
+
*/
|
|
174
|
+
setPauseMoveCall(tx, pause) {
|
|
175
|
+
tx.moveCall({
|
|
176
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_pause"),
|
|
177
|
+
typeArguments: [this.coinType],
|
|
178
|
+
arguments: [tx.object(this.oftObjectId), tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)), lzSuiSdkV2.asBool(tx, pause)]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// ==========================================
|
|
182
|
+
// FEE MANAGEMENT ADMIN FUNCTIONS
|
|
183
|
+
// ==========================================
|
|
184
|
+
// Configure fee collection and distribution for OFT transfers
|
|
185
|
+
/**
|
|
186
|
+
* Set fee deposit address for OFT fees
|
|
187
|
+
* @param tx - The transaction to add the move call to
|
|
188
|
+
* @param feeDepositAddress - The new fee deposit address
|
|
189
|
+
*/
|
|
190
|
+
setFeeDepositAddressMoveCall(tx, feeDepositAddress) {
|
|
191
|
+
tx.moveCall({
|
|
192
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_fee_deposit_address"),
|
|
193
|
+
typeArguments: [this.coinType],
|
|
194
|
+
arguments: [tx.object(this.oftObjectId), tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)), lzSuiSdkV2.asAddress(tx, feeDepositAddress)]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Set fee basis points for OFT transfers
|
|
199
|
+
* @param tx - The transaction to add the move call to
|
|
200
|
+
* @param feeBps - The fee in basis points
|
|
201
|
+
*/
|
|
202
|
+
setFeeBpsMoveCall(tx, feeBps) {
|
|
203
|
+
tx.moveCall({
|
|
204
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_fee_bps"),
|
|
205
|
+
typeArguments: [this.coinType],
|
|
206
|
+
arguments: [tx.object(this.oftObjectId), tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)), lzSuiSdkV2.asU64(tx, feeBps)]
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// ==========================================
|
|
210
|
+
// RATE LIMITER ADMIN FUNCTIONS
|
|
211
|
+
// ==========================================
|
|
212
|
+
// Configure transfer rate limits for security and compliance
|
|
213
|
+
/**
|
|
214
|
+
* Set rate limit for OFT transfers
|
|
215
|
+
* @param tx - The transaction to add the move call to
|
|
216
|
+
* @param eid - Endpoint ID
|
|
217
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
218
|
+
* @param rateLimit - Rate limit amount
|
|
219
|
+
* @param windowSeconds - Time window in seconds
|
|
220
|
+
*/
|
|
221
|
+
setRateLimitMoveCall(tx, eid, inbound, rateLimit, windowSeconds) {
|
|
222
|
+
tx.moveCall({
|
|
223
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "set_rate_limit"),
|
|
224
|
+
typeArguments: [this.coinType],
|
|
225
|
+
arguments: [
|
|
226
|
+
tx.object(this.oftObjectId),
|
|
227
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
228
|
+
lzSuiSdkV2.asU32(tx, eid),
|
|
229
|
+
lzSuiSdkV2.asBool(tx, inbound),
|
|
230
|
+
lzSuiSdkV2.asU64(tx, rateLimit),
|
|
231
|
+
lzSuiSdkV2.asU64(tx, windowSeconds),
|
|
232
|
+
tx.object.clock()
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Remove rate limit for OFT transfers
|
|
238
|
+
* @param tx - The transaction to add the move call to
|
|
239
|
+
* @param eid - Endpoint ID
|
|
240
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
241
|
+
*/
|
|
242
|
+
unsetRateLimitMoveCall(tx, eid, inbound) {
|
|
243
|
+
tx.moveCall({
|
|
244
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "unset_rate_limit"),
|
|
245
|
+
typeArguments: [this.coinType],
|
|
246
|
+
arguments: [
|
|
247
|
+
tx.object(this.oftObjectId),
|
|
248
|
+
tx.object(__privateMethod(this, _OFT_instances, adminCapId_fn).call(this)),
|
|
249
|
+
lzSuiSdkV2.asU32(tx, eid),
|
|
250
|
+
lzSuiSdkV2.asBool(tx, inbound)
|
|
251
|
+
]
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// ==========================================
|
|
255
|
+
// CORE FUNCTIONS
|
|
256
|
+
// ==========================================
|
|
257
|
+
// Primary OFT operations for token transfers and coin management
|
|
258
|
+
/**
|
|
259
|
+
* Splits specified amount of coins from user's wallet
|
|
260
|
+
* @param tx - The transaction to add the move call to
|
|
261
|
+
* @param owner - Address of the user whose coins to split
|
|
262
|
+
* @param amount - Amount of coins to split (in smallest units)
|
|
263
|
+
* @param limit - Maximum total number of coins to collect across all pages (default: 200)
|
|
264
|
+
* @param pageSize - Maximum number of coins to fetch per page (default: 50)
|
|
265
|
+
* @returns Promise resolving to split coin as TransactionResult
|
|
266
|
+
* @throws Error if insufficient coins balance or no coins found
|
|
267
|
+
*/
|
|
268
|
+
async splitCoinMoveCall(tx, owner, amount, limit = 200, pageSize = 50) {
|
|
269
|
+
return this.protocolSDK.getUtils().splitCoinMoveCall(tx, this.coinType, owner, amount, limit, pageSize);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Send OFT tokens to destination chain
|
|
273
|
+
* @param tx - The transaction to add the move call to
|
|
274
|
+
* @param sender - Sender address for ZRO token operations
|
|
275
|
+
* @param coinProvided - Coin object ID or transaction result to send
|
|
276
|
+
* @param messagingChannel - The messaging channel object ID
|
|
277
|
+
* @param sendParam - Send parameters including destination and amounts
|
|
278
|
+
* @param nativeFee - Native token fee amount
|
|
279
|
+
* @param zroFee - ZRO token fee amount
|
|
280
|
+
* @param refundAddress - Address for fee refunds
|
|
281
|
+
* @returns Promise<TransactionResult> - Transaction result containing send operation and receipt objects
|
|
282
|
+
*/
|
|
283
|
+
async sendMoveCall(tx, sender, coinProvided, sendParam, nativeFee, zroFee, refundAddress, messagingChannel) {
|
|
284
|
+
const sendParamArg = lzSuiSdkV2.isTransactionArgument(sendParam) ? sendParam : __privateMethod(this, _OFT_instances, buildSendParam_fn).call(this, tx, sendParam);
|
|
285
|
+
const messagingChannelArg = messagingChannel ?? await this.protocolSDK.getEndpoint().getMessagingChannel(this.packageId);
|
|
286
|
+
const transactionResult = tx.moveCall({
|
|
287
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "send"),
|
|
288
|
+
typeArguments: [this.coinType],
|
|
289
|
+
arguments: [
|
|
290
|
+
tx.object(this.oftObjectId),
|
|
291
|
+
lzSuiSdkV2.asObject(tx, coinProvided),
|
|
292
|
+
tx.object(this.objects.endpointV2),
|
|
293
|
+
tx.object(messagingChannelArg),
|
|
294
|
+
sendParamArg,
|
|
295
|
+
lzSuiSdkV2.asArgWithTx(tx, nativeFee, (tx2, val) => tx2.splitCoins(tx2.gas, [lzSuiSdkV2.asU64(tx2, val)])[0]),
|
|
296
|
+
await lzSuiSdkV2.asArgWithTxAsync(
|
|
297
|
+
tx,
|
|
298
|
+
zroFee,
|
|
299
|
+
async (tx2, val) => this.protocolSDK.getZro().splitOptionZroTokenMoveCall(tx2, sender, val)
|
|
300
|
+
),
|
|
301
|
+
lzSuiSdkV2.asAddress(tx, refundAddress),
|
|
302
|
+
tx.object.clock()
|
|
303
|
+
]
|
|
304
|
+
});
|
|
305
|
+
const endpointCall = transactionResult[0];
|
|
306
|
+
await this.protocolSDK.getEndpoint().populateSendTransaction(tx, endpointCall, sender);
|
|
307
|
+
tx.moveCall({
|
|
308
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "confirm_send"),
|
|
309
|
+
typeArguments: [this.coinType],
|
|
310
|
+
arguments: [tx.object(this.oftObjectId), endpointCall]
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
// ==========================================
|
|
314
|
+
// QUOTE FUNCTIONS
|
|
315
|
+
// ==========================================
|
|
316
|
+
// Calculate fees, limits, and receipts before executing operations
|
|
317
|
+
/**
|
|
318
|
+
* Quote OFT sending operation with detailed fee breakdown
|
|
319
|
+
* @param sendParam - Send parameters for the OFT operation
|
|
320
|
+
* @returns Promise with limit, fee details, and receipt information
|
|
321
|
+
*/
|
|
322
|
+
async quoteOft(sendParam) {
|
|
323
|
+
return lzSuiSdkV2.executeSimulate(
|
|
324
|
+
this.client,
|
|
325
|
+
(tx) => {
|
|
326
|
+
const sendParamArg = lzSuiSdkV2.isTransactionArgument(sendParam) ? sendParam : __privateMethod(this, _OFT_instances, buildSendParam_fn).call(this, tx, sendParam);
|
|
327
|
+
tx.moveCall({
|
|
328
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "quote_oft"),
|
|
329
|
+
typeArguments: [this.coinType],
|
|
330
|
+
arguments: [tx.object(this.oftObjectId), sendParamArg, tx.object.clock()]
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
(result) => {
|
|
334
|
+
return {
|
|
335
|
+
limit: parseOFTLimit(result[0].value),
|
|
336
|
+
feeDetails: parseOFTFeeDetails(result[1].value),
|
|
337
|
+
receipt: parseOFTReceipt(result[2].value)
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Quote messaging fees for OFT sending
|
|
344
|
+
* @param sender - Sender address
|
|
345
|
+
* @param sendParam - Send parameters for the OFT operation
|
|
346
|
+
* @param payInZro - Whether to pay in ZRO tokens
|
|
347
|
+
* @returns Promise<MessagingFee> - The calculated messaging fees
|
|
348
|
+
*/
|
|
349
|
+
async quoteSend(sender, sendParam, payInZro) {
|
|
350
|
+
const tx = new transactions.Transaction();
|
|
351
|
+
const sendParamArg = lzSuiSdkV2.isTransactionArgument(sendParam) ? sendParam : __privateMethod(this, _OFT_instances, buildSendParam_fn).call(this, tx, sendParam);
|
|
352
|
+
const quoteCall = tx.moveCall({
|
|
353
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "quote_send"),
|
|
354
|
+
typeArguments: [this.coinType],
|
|
355
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asAddress(tx, sender), sendParamArg, lzSuiSdkV2.asBool(tx, payInZro)]
|
|
356
|
+
});
|
|
357
|
+
return this.protocolSDK.getEndpoint().quote(tx, quoteCall);
|
|
358
|
+
}
|
|
359
|
+
// ==========================================
|
|
360
|
+
// VIEW FUNCTIONS
|
|
361
|
+
// ==========================================
|
|
362
|
+
// Read-only functions to query OFT state and configuration
|
|
363
|
+
/**
|
|
364
|
+
* Get OFT version information
|
|
365
|
+
* @param tx - The transaction to add the move call to
|
|
366
|
+
* @returns Transaction result containing version information
|
|
367
|
+
*/
|
|
368
|
+
oftVersionMoveCall(tx) {
|
|
369
|
+
return tx.moveCall({
|
|
370
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "oft_version"),
|
|
371
|
+
typeArguments: [this.coinType],
|
|
372
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Get OFT version information
|
|
377
|
+
* @returns Promise<{ major: number; minor: number }> - The OFT version
|
|
378
|
+
*/
|
|
379
|
+
async oftVersion() {
|
|
380
|
+
return lzSuiSdkV2.executeSimulate(
|
|
381
|
+
this.client,
|
|
382
|
+
(tx) => {
|
|
383
|
+
this.oftVersionMoveCall(tx);
|
|
384
|
+
},
|
|
385
|
+
(result) => {
|
|
386
|
+
const major = Number(bcs.bcs.U64.parse(result[0].value));
|
|
387
|
+
const minor = Number(bcs.bcs.U64.parse(result[1].value));
|
|
388
|
+
return { major, minor };
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Get coin metadata address
|
|
394
|
+
* @param tx - The transaction to add the move call to
|
|
395
|
+
* @returns Transaction result containing coin metadata address
|
|
396
|
+
*/
|
|
397
|
+
coinMetadataMoveCall(tx) {
|
|
398
|
+
return tx.moveCall({
|
|
399
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "coin_metadata"),
|
|
400
|
+
typeArguments: [this.coinType],
|
|
401
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get coin metadata address
|
|
406
|
+
* @returns Promise<string> - The coin metadata address
|
|
407
|
+
*/
|
|
408
|
+
async coinMetadata() {
|
|
409
|
+
return lzSuiSdkV2.executeSimulate(
|
|
410
|
+
this.client,
|
|
411
|
+
(tx) => {
|
|
412
|
+
this.coinMetadataMoveCall(tx);
|
|
413
|
+
},
|
|
414
|
+
(result) => bcs.bcs.Address.parse(result[0].value)
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Get OFT admin address
|
|
419
|
+
* @param tx - The transaction to add the move call to
|
|
420
|
+
* @returns Transaction result containing the admin address
|
|
421
|
+
*/
|
|
422
|
+
adminMoveCall(tx) {
|
|
423
|
+
return tx.moveCall({
|
|
424
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "admin"),
|
|
425
|
+
typeArguments: [this.coinType],
|
|
426
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Get OFT admin address
|
|
431
|
+
* @returns Promise<string> - The admin address
|
|
432
|
+
*/
|
|
433
|
+
async admin() {
|
|
434
|
+
return lzSuiSdkV2.executeSimulate(
|
|
435
|
+
this.client,
|
|
436
|
+
(tx) => {
|
|
437
|
+
this.adminMoveCall(tx);
|
|
438
|
+
},
|
|
439
|
+
(result) => bcs.bcs.Address.parse(result[0].value)
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Get shared decimals for cross-chain compatibility
|
|
444
|
+
* @param tx - The transaction to add the move call to
|
|
445
|
+
* @returns Transaction result containing shared decimals
|
|
446
|
+
*/
|
|
447
|
+
sharedDecimalsMoveCall(tx) {
|
|
448
|
+
return tx.moveCall({
|
|
449
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "shared_decimals"),
|
|
450
|
+
typeArguments: [this.coinType],
|
|
451
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get shared decimals for cross-chain compatibility
|
|
456
|
+
* @returns Promise<number> - The shared decimal precision
|
|
457
|
+
*/
|
|
458
|
+
async sharedDecimals() {
|
|
459
|
+
return lzSuiSdkV2.executeSimulate(
|
|
460
|
+
this.client,
|
|
461
|
+
(tx) => {
|
|
462
|
+
this.sharedDecimalsMoveCall(tx);
|
|
463
|
+
},
|
|
464
|
+
(result) => bcs.bcs.U8.parse(result[0].value)
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Check if OFT is paused
|
|
469
|
+
* @param tx - The transaction to add the move call to
|
|
470
|
+
* @returns Transaction result containing the paused status
|
|
471
|
+
*/
|
|
472
|
+
isPausedMoveCall(tx) {
|
|
473
|
+
return tx.moveCall({
|
|
474
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "is_paused"),
|
|
475
|
+
typeArguments: [this.coinType],
|
|
476
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Check if OFT is paused
|
|
481
|
+
* @returns Promise<boolean> - True if OFT is paused
|
|
482
|
+
*/
|
|
483
|
+
async isPaused() {
|
|
484
|
+
return lzSuiSdkV2.executeSimulate(
|
|
485
|
+
this.client,
|
|
486
|
+
(tx) => {
|
|
487
|
+
this.isPausedMoveCall(tx);
|
|
488
|
+
},
|
|
489
|
+
(result) => bcs.bcs.Bool.parse(result[0].value)
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Check if this OFT is an adapter (wraps existing token)
|
|
494
|
+
* @param tx - The transaction to add the move call to
|
|
495
|
+
* @returns Transaction result containing the adapter status
|
|
496
|
+
*/
|
|
497
|
+
isAdapterMoveCall(tx) {
|
|
498
|
+
return tx.moveCall({
|
|
499
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "is_adapter"),
|
|
500
|
+
typeArguments: [this.coinType],
|
|
501
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Check if this OFT is an adapter (wraps existing token)
|
|
506
|
+
* @returns Promise<boolean> - True if this is an OFT adapter
|
|
507
|
+
*/
|
|
508
|
+
async isAdapter() {
|
|
509
|
+
return lzSuiSdkV2.executeSimulate(
|
|
510
|
+
this.client,
|
|
511
|
+
(tx) => {
|
|
512
|
+
this.isAdapterMoveCall(tx);
|
|
513
|
+
},
|
|
514
|
+
(result) => bcs.bcs.Bool.parse(result[0].value)
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
// ==========================================
|
|
518
|
+
// FEE VIEW FUNCTIONS
|
|
519
|
+
// ==========================================
|
|
520
|
+
// Query current fee configuration and settings
|
|
521
|
+
/**
|
|
522
|
+
* Get fee basis points for OFT transfers
|
|
523
|
+
* @param tx - The transaction to add the move call to
|
|
524
|
+
* @returns Transaction result containing the fee basis points
|
|
525
|
+
*/
|
|
526
|
+
feeBpsMoveCall(tx) {
|
|
527
|
+
return tx.moveCall({
|
|
528
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "fee_bps"),
|
|
529
|
+
typeArguments: [this.coinType],
|
|
530
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Get fee basis points for OFT transfers
|
|
535
|
+
* @returns Promise<bigint> - The fee in basis points
|
|
536
|
+
*/
|
|
537
|
+
async feeBps() {
|
|
538
|
+
return lzSuiSdkV2.executeSimulate(
|
|
539
|
+
this.client,
|
|
540
|
+
(tx) => {
|
|
541
|
+
this.feeBpsMoveCall(tx);
|
|
542
|
+
},
|
|
543
|
+
(result) => BigInt(bcs.bcs.U64.parse(result[0].value))
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get fee deposit address for OFT
|
|
548
|
+
* @param tx - The transaction to add the move call to
|
|
549
|
+
* @returns Transaction result containing the fee deposit address
|
|
550
|
+
*/
|
|
551
|
+
feeDepositAddressMoveCall(tx) {
|
|
552
|
+
return tx.moveCall({
|
|
553
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "fee_deposit_address"),
|
|
554
|
+
typeArguments: [this.coinType],
|
|
555
|
+
arguments: [tx.object(this.oftObjectId)]
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Get fee deposit address for OFT
|
|
560
|
+
* @returns Promise<string> - The fee deposit address
|
|
561
|
+
*/
|
|
562
|
+
async feeDepositAddress() {
|
|
563
|
+
return lzSuiSdkV2.executeSimulate(
|
|
564
|
+
this.client,
|
|
565
|
+
(tx) => {
|
|
566
|
+
this.feeDepositAddressMoveCall(tx);
|
|
567
|
+
},
|
|
568
|
+
(result) => bcs.bcs.Address.parse(result[0].value)
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
// ==========================================
|
|
572
|
+
// RATE LIMITER VIEW FUNCTIONS
|
|
573
|
+
// ==========================================
|
|
574
|
+
// Query current rate limiting configuration and status
|
|
575
|
+
/**
|
|
576
|
+
* Get rate limit configuration for an endpoint
|
|
577
|
+
* @param tx - The transaction to add the move call to
|
|
578
|
+
* @param eid - Endpoint ID
|
|
579
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
580
|
+
* @returns Transaction result containing rate limit configuration
|
|
581
|
+
*/
|
|
582
|
+
rateLimitConfigMoveCall(tx, eid, inbound) {
|
|
583
|
+
return tx.moveCall({
|
|
584
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "rate_limit_config"),
|
|
585
|
+
typeArguments: [this.coinType],
|
|
586
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid), lzSuiSdkV2.asBool(tx, inbound)]
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Get rate limit configuration for an endpoint
|
|
591
|
+
* @param eid - Endpoint ID
|
|
592
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
593
|
+
* @returns Promise<{ limit: bigint; windowSeconds: bigint }> - Rate limit configuration
|
|
594
|
+
*/
|
|
595
|
+
async rateLimitConfig(eid, inbound) {
|
|
596
|
+
return lzSuiSdkV2.executeSimulate(
|
|
597
|
+
this.client,
|
|
598
|
+
(tx) => {
|
|
599
|
+
this.rateLimitConfigMoveCall(tx, eid, inbound);
|
|
600
|
+
},
|
|
601
|
+
(result) => {
|
|
602
|
+
const limit = BigInt(bcs.bcs.U64.parse(result[0].value));
|
|
603
|
+
const windowSeconds = BigInt(bcs.bcs.U64.parse(result[1].value));
|
|
604
|
+
return { limit, windowSeconds };
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Get current in-flight amount for rate limiting
|
|
610
|
+
* @param tx - The transaction to add the move call to
|
|
611
|
+
* @param eid - Endpoint ID
|
|
612
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
613
|
+
* @returns Transaction result containing in-flight amount
|
|
614
|
+
*/
|
|
615
|
+
rateLimitInFlightMoveCall(tx, eid, inbound) {
|
|
616
|
+
return tx.moveCall({
|
|
617
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "rate_limit_in_flight"),
|
|
618
|
+
typeArguments: [this.coinType],
|
|
619
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid), lzSuiSdkV2.asBool(tx, inbound), tx.object.clock()]
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Get current in-flight amount for rate limiting
|
|
624
|
+
* @param eid - Endpoint ID
|
|
625
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
626
|
+
* @returns Promise<bigint> - Current in-flight amount
|
|
627
|
+
*/
|
|
628
|
+
async rateLimitInFlight(eid, inbound) {
|
|
629
|
+
return lzSuiSdkV2.executeSimulate(
|
|
630
|
+
this.client,
|
|
631
|
+
(tx) => {
|
|
632
|
+
this.rateLimitInFlightMoveCall(tx, eid, inbound);
|
|
633
|
+
},
|
|
634
|
+
(result) => BigInt(bcs.bcs.U64.parse(result[0].value))
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Get rate limit capacity (remaining available amount)
|
|
639
|
+
* @param tx - The transaction to add the move call to
|
|
640
|
+
* @param eid - Endpoint ID
|
|
641
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
642
|
+
* @returns Transaction result containing rate limit capacity
|
|
643
|
+
*/
|
|
644
|
+
rateLimitCapacityMoveCall(tx, eid, inbound) {
|
|
645
|
+
return tx.moveCall({
|
|
646
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "rate_limit_capacity"),
|
|
647
|
+
typeArguments: [this.coinType],
|
|
648
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid), lzSuiSdkV2.asBool(tx, inbound), tx.object.clock()]
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Get rate limit capacity (remaining available amount)
|
|
653
|
+
* @param eid - Endpoint ID
|
|
654
|
+
* @param inbound - Whether this is for inbound or outbound transfers
|
|
655
|
+
* @returns Promise<bigint> - Remaining rate limit capacity
|
|
656
|
+
*/
|
|
657
|
+
async rateLimitCapacity(eid, inbound) {
|
|
658
|
+
return lzSuiSdkV2.executeSimulate(
|
|
659
|
+
this.client,
|
|
660
|
+
(tx) => {
|
|
661
|
+
this.rateLimitCapacityMoveCall(tx, eid, inbound);
|
|
662
|
+
},
|
|
663
|
+
(result) => BigInt(bcs.bcs.U64.parse(result[0].value))
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Combine enforced options with extra options
|
|
668
|
+
* @param tx - The transaction to add the move call to
|
|
669
|
+
* @param eid - Endpoint ID
|
|
670
|
+
* @param msgType - Message type
|
|
671
|
+
* @param extraOptions - Extra options to combine with enforced options
|
|
672
|
+
* @returns Transaction result containing the combined options
|
|
673
|
+
*/
|
|
674
|
+
combineOptionsMoveCall(tx, eid, msgType, extraOptions) {
|
|
675
|
+
return tx.moveCall({
|
|
676
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "combine_options"),
|
|
677
|
+
typeArguments: [this.coinType],
|
|
678
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid), lzSuiSdkV2.asU16(tx, msgType), lzSuiSdkV2.asBytes(tx, extraOptions)]
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Combine enforced options with extra options
|
|
683
|
+
* @param eid - Endpoint ID
|
|
684
|
+
* @param msgType - Message type
|
|
685
|
+
* @param extraOptions - Extra options to combine with enforced options
|
|
686
|
+
* @returns Promise<Uint8Array> - The combined options as bytes
|
|
687
|
+
*/
|
|
688
|
+
async combineOptions(eid, msgType, extraOptions) {
|
|
689
|
+
return lzSuiSdkV2.executeSimulate(
|
|
690
|
+
this.client,
|
|
691
|
+
(tx) => {
|
|
692
|
+
this.combineOptionsMoveCall(tx, eid, msgType, extraOptions);
|
|
693
|
+
},
|
|
694
|
+
(result) => new Uint8Array(bcs.bcs.vector(bcs.bcs.u8()).parse(result[0].value))
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Get enforced options for OFT messaging
|
|
699
|
+
* @param tx - The transaction to add the move call to
|
|
700
|
+
* @param eid - Endpoint ID
|
|
701
|
+
* @param msgType - Message type
|
|
702
|
+
* @returns Transaction result containing the enforced options
|
|
703
|
+
*/
|
|
704
|
+
getEnforcedOptionsMoveCall(tx, eid, msgType) {
|
|
705
|
+
return tx.moveCall({
|
|
706
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "get_enforced_options"),
|
|
707
|
+
typeArguments: [this.coinType],
|
|
708
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid), lzSuiSdkV2.asU16(tx, msgType)]
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Get enforced options for OFT messaging
|
|
713
|
+
* @param eid - Endpoint ID
|
|
714
|
+
* @param msgType - Message type
|
|
715
|
+
* @returns Promise<Uint8Array> - The enforced options as bytes
|
|
716
|
+
*/
|
|
717
|
+
async getEnforcedOptions(eid, msgType) {
|
|
718
|
+
return lzSuiSdkV2.executeSimulate(
|
|
719
|
+
this.client,
|
|
720
|
+
(tx) => {
|
|
721
|
+
this.getEnforcedOptionsMoveCall(tx, eid, msgType);
|
|
722
|
+
},
|
|
723
|
+
(result) => new Uint8Array(bcs.bcs.vector(bcs.bcs.u8()).parse(result[0].value))
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Check if OFT has a peer on specific endpoint
|
|
728
|
+
* @param tx - The transaction to add the move call to
|
|
729
|
+
* @param eid - Endpoint ID
|
|
730
|
+
* @returns Transaction result containing the peer existence status
|
|
731
|
+
*/
|
|
732
|
+
hasPeerMoveCall(tx, eid) {
|
|
733
|
+
return tx.moveCall({
|
|
734
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "has_peer"),
|
|
735
|
+
typeArguments: [this.coinType],
|
|
736
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid)]
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Check if OFT has a peer on specific endpoint
|
|
741
|
+
* @param eid - Endpoint ID
|
|
742
|
+
* @returns Promise<boolean> - True if peer exists on the endpoint
|
|
743
|
+
*/
|
|
744
|
+
async hasPeer(eid) {
|
|
745
|
+
return lzSuiSdkV2.executeSimulate(
|
|
746
|
+
this.client,
|
|
747
|
+
(tx) => {
|
|
748
|
+
this.hasPeerMoveCall(tx, eid);
|
|
749
|
+
},
|
|
750
|
+
(result) => bcs.bcs.Bool.parse(result[0].value)
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Get peer OFT address on specific endpoint
|
|
755
|
+
* @param tx - The transaction to add the move call to
|
|
756
|
+
* @param eid - Endpoint ID
|
|
757
|
+
* @returns Transaction result containing the peer address
|
|
758
|
+
*/
|
|
759
|
+
getPeerMoveCall(tx, eid) {
|
|
760
|
+
return tx.moveCall({
|
|
761
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "get_peer"),
|
|
762
|
+
typeArguments: [this.coinType],
|
|
763
|
+
arguments: [tx.object(this.oftObjectId), lzSuiSdkV2.asU32(tx, eid)]
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Get peer OFT address on specific endpoint
|
|
768
|
+
* @param eid - Endpoint ID
|
|
769
|
+
* @returns Promise<Uint8Array> - The peer address as bytes32
|
|
770
|
+
*/
|
|
771
|
+
async getPeer(eid) {
|
|
772
|
+
return lzSuiSdkV2.executeSimulate(
|
|
773
|
+
this.client,
|
|
774
|
+
(tx) => {
|
|
775
|
+
this.getPeerMoveCall(tx, eid);
|
|
776
|
+
},
|
|
777
|
+
(result) => {
|
|
778
|
+
return new Uint8Array(bcs.bcs.vector(bcs.bcs.u8()).parse(result[0].value));
|
|
779
|
+
}
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
_OFT_instances = new WeakSet();
|
|
784
|
+
// ==========================================
|
|
785
|
+
// PRIVATE HELPER FUNCTIONS
|
|
786
|
+
// ==========================================
|
|
787
|
+
// Internal utility functions for OFT operations
|
|
788
|
+
/**
|
|
789
|
+
* Build SendParam struct for OFT operations
|
|
790
|
+
* @param tx - The transaction to add the move call to
|
|
791
|
+
* @param param - Send parameters to build
|
|
792
|
+
* @returns Transaction result containing the SendParam struct
|
|
793
|
+
* @private
|
|
794
|
+
*/
|
|
795
|
+
buildSendParam_fn = function(tx, param) {
|
|
796
|
+
return tx.moveCall({
|
|
797
|
+
target: __privateMethod(this, _OFT_instances, target_fn).call(this, "create", "send_param"),
|
|
798
|
+
arguments: [
|
|
799
|
+
lzSuiSdkV2.asU32(tx, param.dstEid),
|
|
800
|
+
lzSuiSdkV2.asBytes32(tx, param.to, this.protocolSDK.getUtils()),
|
|
801
|
+
lzSuiSdkV2.asU64(tx, param.amountLd),
|
|
802
|
+
lzSuiSdkV2.asU64(tx, param.minAmountLd),
|
|
803
|
+
lzSuiSdkV2.asBytes(tx, param.extraOptions),
|
|
804
|
+
lzSuiSdkV2.asBytes(tx, param.composeMsg),
|
|
805
|
+
lzSuiSdkV2.asBytes(tx, param.oftCmd)
|
|
806
|
+
]
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Generate the full target path for move calls
|
|
811
|
+
* @param name - The function name to call
|
|
812
|
+
* @param module_name - The module name (defaults to 'oft')
|
|
813
|
+
* @returns The full module path for the move call
|
|
814
|
+
* @private
|
|
815
|
+
*/
|
|
816
|
+
target_fn = function(name, module_name = MODULE_NAME) {
|
|
817
|
+
return `${this.corePackageId}::${module_name}::${name}`;
|
|
818
|
+
};
|
|
819
|
+
/**
|
|
820
|
+
* Get the admin capability ID, throwing an error if not available
|
|
821
|
+
* @returns The admin capability ID
|
|
822
|
+
* @throws Error if admin capability ID was not provided during construction
|
|
823
|
+
* @private
|
|
824
|
+
*/
|
|
825
|
+
adminCapId_fn = function() {
|
|
826
|
+
if (this.adminCapId === void 0) {
|
|
827
|
+
throw new Error("Admin cap ID not found");
|
|
828
|
+
}
|
|
829
|
+
return this.adminCapId;
|
|
830
|
+
};
|
|
831
|
+
var OFTComposerRegistryErrorCode = {
|
|
832
|
+
// OFT Composer Registry related errors
|
|
833
|
+
EComposeTransferNotFound: 1,
|
|
834
|
+
EDepositAddressNotFound: 2
|
|
835
|
+
};
|
|
836
|
+
var _OFTComposerRegistry_instances, target_fn2;
|
|
837
|
+
var OFTComposerRegistry = class {
|
|
838
|
+
constructor(protocolSDK, packageId, registryObjectId) {
|
|
839
|
+
__privateAdd(this, _OFTComposerRegistry_instances);
|
|
840
|
+
this.client = protocolSDK.client;
|
|
841
|
+
this.protocolSDK = protocolSDK;
|
|
842
|
+
this.packageId = packageId;
|
|
843
|
+
this.registryObjectId = registryObjectId;
|
|
844
|
+
}
|
|
845
|
+
// === Set Functions ===
|
|
846
|
+
/**
|
|
847
|
+
* Set deposit address for OFT composer
|
|
848
|
+
* @param tx - The transaction to add the move call to
|
|
849
|
+
* @param composerCallCap - The composer call capability transaction result
|
|
850
|
+
* @param depositAddress - The new deposit address
|
|
851
|
+
* @returns Transaction result containing the set operation
|
|
852
|
+
*/
|
|
853
|
+
setDepositAddressMoveCall(tx, composerCallCap, depositAddress) {
|
|
854
|
+
return tx.moveCall({
|
|
855
|
+
target: __privateMethod(this, _OFTComposerRegistry_instances, target_fn2).call(this, "set_deposit_address"),
|
|
856
|
+
arguments: [tx.object(this.registryObjectId), lzSuiSdkV2.asObject(tx, composerCallCap), lzSuiSdkV2.asAddress(tx, depositAddress)]
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
// === View Functions ===
|
|
860
|
+
/**
|
|
861
|
+
* Get deposit address for a composer
|
|
862
|
+
* @param tx - The transaction to add the move call to
|
|
863
|
+
* @param composer - The composer address
|
|
864
|
+
* @returns Transaction result containing the deposit address
|
|
865
|
+
*/
|
|
866
|
+
getDepositAddressMoveCall(tx, composer) {
|
|
867
|
+
return tx.moveCall({
|
|
868
|
+
target: __privateMethod(this, _OFTComposerRegistry_instances, target_fn2).call(this, "get_deposit_address"),
|
|
869
|
+
arguments: [tx.object(this.registryObjectId), lzSuiSdkV2.asAddress(tx, composer)]
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Get compose transfer object for composition operations
|
|
874
|
+
* @param tx - The transaction to add the move call to
|
|
875
|
+
* @param from - The sender address
|
|
876
|
+
* @param guid - The GUID transaction result
|
|
877
|
+
* @param composer - The composer address
|
|
878
|
+
* @returns Transaction result containing the compose transfer object
|
|
879
|
+
*/
|
|
880
|
+
getComposeTransferMoveCall(tx, from, guid, composer) {
|
|
881
|
+
return tx.moveCall({
|
|
882
|
+
target: __privateMethod(this, _OFTComposerRegistry_instances, target_fn2).call(this, "get_compose_transfer"),
|
|
883
|
+
arguments: [
|
|
884
|
+
tx.object(this.registryObjectId),
|
|
885
|
+
lzSuiSdkV2.asAddress(tx, from),
|
|
886
|
+
lzSuiSdkV2.asBytes32(tx, guid, this.protocolSDK.getUtils()),
|
|
887
|
+
lzSuiSdkV2.asAddress(tx, composer)
|
|
888
|
+
]
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Get compose transfer object address
|
|
893
|
+
* @param from - The sender address
|
|
894
|
+
* @param guid - The GUID as number array
|
|
895
|
+
* @param composer - The composer address
|
|
896
|
+
* @returns Promise<string> - The compose transfer object address
|
|
897
|
+
*/
|
|
898
|
+
async getComposeTransfer(from, guid, composer) {
|
|
899
|
+
return lzSuiSdkV2.executeSimulate(
|
|
900
|
+
this.client,
|
|
901
|
+
(tx) => {
|
|
902
|
+
return this.getComposeTransferMoveCall(
|
|
903
|
+
tx,
|
|
904
|
+
from,
|
|
905
|
+
lzSuiSdkV2.asBytes32(tx, guid, this.protocolSDK.getUtils()),
|
|
906
|
+
composer
|
|
907
|
+
);
|
|
908
|
+
},
|
|
909
|
+
(result) => {
|
|
910
|
+
const parsed = bcs.bcs.Address.parse(result[0].value);
|
|
911
|
+
return parsed;
|
|
912
|
+
}
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
_OFTComposerRegistry_instances = new WeakSet();
|
|
917
|
+
// === Private Functions ===
|
|
918
|
+
/**
|
|
919
|
+
* Generate the full target path for move calls
|
|
920
|
+
* @param func - The function name to call
|
|
921
|
+
* @returns The full module path for the move call
|
|
922
|
+
* @private
|
|
923
|
+
*/
|
|
924
|
+
target_fn2 = function(func) {
|
|
925
|
+
return `${this.packageId}::oft_composer_registry::${func}`;
|
|
926
|
+
};
|
|
927
|
+
var OFTPtbBuilder = class {
|
|
928
|
+
constructor(protocolSDK, packageId, objectId, client, coinType, oftObjectId) {
|
|
929
|
+
this.objects = protocolSDK.objects;
|
|
930
|
+
this.packageId = packageId;
|
|
931
|
+
this.objectId = objectId;
|
|
932
|
+
this.client = client;
|
|
933
|
+
this.coinType = coinType;
|
|
934
|
+
this.oftObjectId = oftObjectId;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Get LayerZero receive information for OFT registration
|
|
938
|
+
*
|
|
939
|
+
* This function prepares the necessary metadata for registering an OFT
|
|
940
|
+
* with the LayerZero endpoint, enabling it to receive cross-chain messages.
|
|
941
|
+
*
|
|
942
|
+
* @param tx - The transaction to add the move call to
|
|
943
|
+
* @param composerRegistry - The composer registry object ID for routing compose transfers
|
|
944
|
+
* @returns TransactionResult containing serialized execution metadata for endpoint registration
|
|
945
|
+
*/
|
|
946
|
+
lzReceiveInfoMoveCall(tx, composerRegistry) {
|
|
947
|
+
return tx.moveCall({
|
|
948
|
+
target: `${this.packageId}::oft_ptb_builder::lz_receive_info`,
|
|
949
|
+
typeArguments: [this.coinType],
|
|
950
|
+
arguments: [
|
|
951
|
+
tx.object(this.objectId),
|
|
952
|
+
tx.object(this.oftObjectId),
|
|
953
|
+
tx.object(this.objects.endpointV2),
|
|
954
|
+
lzSuiSdkV2.asObject(tx, composerRegistry),
|
|
955
|
+
tx.object.clock()
|
|
956
|
+
]
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
// src/types.ts
|
|
962
|
+
var OFTMsgType = {
|
|
963
|
+
SEND: 1,
|
|
964
|
+
SEND_AND_CALL: 2
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
exports.OFT = OFT;
|
|
968
|
+
exports.OFTComposerRegistry = OFTComposerRegistry;
|
|
969
|
+
exports.OFTComposerRegistryErrorCode = OFTComposerRegistryErrorCode;
|
|
970
|
+
exports.OFTErrorCode = OFTErrorCode;
|
|
971
|
+
exports.OFTFeeDetailBcs = OFTFeeDetailBcs;
|
|
972
|
+
exports.OFTLimitBcs = OFTLimitBcs;
|
|
973
|
+
exports.OFTMsgType = OFTMsgType;
|
|
974
|
+
exports.OFTPtbBuilder = OFTPtbBuilder;
|
|
975
|
+
exports.OFTReceiptBcs = OFTReceiptBcs;
|
|
976
|
+
exports.parseOFTFeeDetails = parseOFTFeeDetails;
|
|
977
|
+
exports.parseOFTLimit = parseOFTLimit;
|
|
978
|
+
exports.parseOFTReceipt = parseOFTReceipt;
|
|
979
|
+
//# sourceMappingURL=index.cjs.map
|
|
980
|
+
//# sourceMappingURL=index.cjs.map
|