@layerzerolabs/lz-v2-stellar-sdk 0.2.121 → 0.2.123
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/.turbo/turbo-build.log +235 -1
- package/.turbo/turbo-lint.log +8 -0
- package/.turbo/turbo-test.log +41 -1361
- package/dist/generated/dvn.d.ts +2 -2
- package/dist/generated/dvn.js +2 -2
- package/dist/generated/endpoint.d.ts +2 -2
- package/dist/generated/endpoint.js +2 -2
- package/dist/generated/executor.d.ts +3 -3
- package/dist/generated/executor.d.ts.map +1 -1
- package/dist/generated/executor.js +3 -3
- package/dist/generated/executor.js.map +1 -1
- package/dist/generated/price_feed.d.ts +2 -2
- package/dist/generated/price_feed.js +2 -2
- package/dist/generated/sml.d.ts +2 -2
- package/dist/generated/sml.js +2 -2
- package/dist/generated/uln302.d.ts +2 -2
- package/dist/generated/uln302.js +2 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
- package/rust-toolchain.toml +4 -0
- package/src/index.ts +0 -5
- package/test/suites/constants.ts +30 -51
- package/test/suites/deploy.ts +13 -273
- package/test/suites/globalSetup.ts +3 -602
- package/test/upgrader.test.ts +1 -0
- package/test/utils.ts +11 -658
- package/ts-bindings-gen.toml +59 -0
- package/dist/generated/counter.d.ts +0 -1253
- package/dist/generated/counter.d.ts.map +0 -1
- package/dist/generated/counter.js +0 -391
- package/dist/generated/counter.js.map +0 -1
- package/dist/generated/oft.d.ts +0 -1638
- package/dist/generated/oft.d.ts.map +0 -1
- package/dist/generated/oft.js +0 -463
- package/dist/generated/oft.js.map +0 -1
- package/dist/generated/sac_manager.d.ts +0 -567
- package/dist/generated/sac_manager.d.ts.map +0 -1
- package/dist/generated/sac_manager.js +0 -198
- package/dist/generated/sac_manager.js.map +0 -1
- package/src/generated/bml.ts +0 -672
- package/src/generated/counter.ts +0 -1208
- package/src/generated/dvn.ts +0 -1508
- package/src/generated/dvn_fee_lib.ts +0 -595
- package/src/generated/endpoint.ts +0 -1181
- package/src/generated/executor.ts +0 -1521
- package/src/generated/executor_fee_lib.ts +0 -1027
- package/src/generated/executor_helper.ts +0 -833
- package/src/generated/layerzero_view.ts +0 -1119
- package/src/generated/oft.ts +0 -1609
- package/src/generated/price_feed.ts +0 -793
- package/src/generated/sac_manager.ts +0 -555
- package/src/generated/sml.ts +0 -921
- package/src/generated/treasury.ts +0 -887
- package/src/generated/uln302.ts +0 -1224
- package/src/generated/upgrader.ts +0 -276
- package/test/counter-sml.test.ts +0 -480
- package/test/counter-uln.test.ts +0 -584
- package/test/oft-sml.test.ts +0 -750
- package/test/sac-manager.test.ts +0 -464
- package/test/secp256k1.ts +0 -59
- package/test/suites/dummyContractClient.ts +0 -168
- package/test/suites/localnet.ts +0 -192
- package/test/suites/scan.ts +0 -202
- package/turbo.json +0 -15
package/test/suites/deploy.ts
CHANGED
|
@@ -1,142 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Asset,
|
|
3
|
-
BASE_FEE,
|
|
4
|
-
hash,
|
|
5
|
-
Keypair,
|
|
6
|
-
Operation,
|
|
7
|
-
rpc,
|
|
8
|
-
TransactionBuilder,
|
|
9
|
-
xdr,
|
|
10
|
-
} from '@stellar/stellar-sdk';
|
|
11
|
-
import { readFileSync } from 'fs';
|
|
1
|
+
import type { Asset, Keypair, rpc } from '@stellar/stellar-sdk';
|
|
12
2
|
|
|
13
3
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from '
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Query and display the TTL (Time To Live) of uploaded WASM code
|
|
23
|
-
*
|
|
24
|
-
* @param wasmHash - The hex-encoded SHA-256 hash of the WASM code
|
|
25
|
-
* @param server - The Stellar RPC server instance
|
|
26
|
-
* @param rpcUrl - Optional RPC URL (defaults to RPC_URL constant)
|
|
27
|
-
*/
|
|
28
|
-
async function queryWasmTtl(wasmHash: string, server: rpc.Server, rpcUrl?: string): Promise<void> {
|
|
29
|
-
try {
|
|
30
|
-
const latestLedger = await server.getLatestLedger();
|
|
31
|
-
const currentLedger = latestLedger.sequence;
|
|
32
|
-
|
|
33
|
-
// Create the LedgerKey for contract code using XDR encoding
|
|
34
|
-
const wasmHashBuffer = Buffer.from(wasmHash, 'hex');
|
|
35
|
-
// Ensure hash is exactly 32 bytes
|
|
36
|
-
const hashBytes =
|
|
37
|
-
wasmHashBuffer.length === 32 ? wasmHashBuffer : wasmHashBuffer.slice(0, 32);
|
|
38
|
-
// Create LedgerKeyContractCode with hash
|
|
39
|
-
const ledgerKeyContractCode = new xdr.LedgerKeyContractCode({
|
|
40
|
-
hash: hashBytes,
|
|
41
|
-
});
|
|
42
|
-
const ledgerKey = xdr.LedgerKey.contractCode(ledgerKeyContractCode);
|
|
43
|
-
const ledgerKeyXdr = ledgerKey.toXDR('base64');
|
|
4
|
+
deployAssetSac as deployAssetSacEnv,
|
|
5
|
+
deployContract as deployContractEnv,
|
|
6
|
+
deployNativeSac as deployNativeSacEnv,
|
|
7
|
+
deployZroToken as deployZroTokenEnv,
|
|
8
|
+
uploadWasm as uploadWasmEnv,
|
|
9
|
+
} from '@layerzerolabs/test-utils-stellar';
|
|
44
10
|
|
|
45
|
-
|
|
46
|
-
const rpcEndpoint = rpcUrl || (server as any).serverURL || RPC_URL;
|
|
47
|
-
const response = await fetch(rpcEndpoint, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
body: JSON.stringify({
|
|
51
|
-
jsonrpc: '2.0',
|
|
52
|
-
id: 1,
|
|
53
|
-
method: 'getLedgerEntries',
|
|
54
|
-
params: {
|
|
55
|
-
keys: [ledgerKeyXdr],
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const result = (await response.json()) as any;
|
|
61
|
-
if (result.error) {
|
|
62
|
-
console.warn(`Warning: Could not retrieve WASM TTL: ${result.error.message}`);
|
|
63
|
-
} else if (result.result?.entries?.[0]?.liveUntilLedgerSeq) {
|
|
64
|
-
const liveUntilLedgerSeq = result.result.entries[0].liveUntilLedgerSeq;
|
|
65
|
-
const ttlLedgers = liveUntilLedgerSeq - currentLedger;
|
|
66
|
-
const ttlDays = (ttlLedgers * 5) / (24 * 3600); // ~5 seconds per ledger
|
|
67
|
-
console.log(
|
|
68
|
-
`⏰ WASM TTL: live until ledger ${liveUntilLedgerSeq} (${ttlLedgers} ledgers remaining, ~${ttlDays.toFixed(2)} days)`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
// If querying TTL fails, it might be because the code isn't indexed yet
|
|
73
|
-
// This is non-fatal, so we just log a warning
|
|
74
|
-
console.warn(
|
|
75
|
-
`Warning: Could not retrieve WASM TTL: ${error instanceof Error ? error.message : String(error)}`,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
11
|
+
import { env } from './constants.js';
|
|
79
12
|
|
|
80
13
|
export async function uploadWasm(
|
|
81
14
|
wasmBuffer: Buffer,
|
|
82
15
|
keypair: Keypair,
|
|
83
16
|
server: rpc.Server,
|
|
84
17
|
): Promise<string> {
|
|
85
|
-
|
|
86
|
-
`📦 WASM buffer size: ${wasmBuffer.length} bytes (${(wasmBuffer.length / 1024).toFixed(2)} KB)`,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const account = await server.getAccount(keypair.publicKey());
|
|
90
|
-
|
|
91
|
-
const uploadTx = new TransactionBuilder(account, {
|
|
92
|
-
fee: BASE_FEE,
|
|
93
|
-
networkPassphrase: NETWORK_PASSPHRASE,
|
|
94
|
-
})
|
|
95
|
-
.addOperation(Operation.uploadContractWasm({ wasm: wasmBuffer }))
|
|
96
|
-
.setTimeout(30)
|
|
97
|
-
.build();
|
|
98
|
-
|
|
99
|
-
const simulated = await server.simulateTransaction(uploadTx);
|
|
100
|
-
const preparedTx = rpc.assembleTransaction(uploadTx, simulated).build();
|
|
101
|
-
|
|
102
|
-
console.log(
|
|
103
|
-
`💰 Upload transaction fee: ${preparedTx.fee} stroops (${(Number(preparedTx.fee) / 10000000).toFixed(7)} XLM)`,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
preparedTx.sign(keypair);
|
|
107
|
-
|
|
108
|
-
const sendResult = await server.sendTransaction(preparedTx);
|
|
109
|
-
|
|
110
|
-
if (sendResult.status !== 'PENDING') {
|
|
111
|
-
throw new Error(`Transaction failed: ${JSON.stringify(sendResult)}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Wait for transaction to be confirmed
|
|
115
|
-
const txResult = await server.pollTransaction(sendResult.hash);
|
|
116
|
-
|
|
117
|
-
if (txResult.status !== 'SUCCESS') {
|
|
118
|
-
throw new Error(`Transaction not successful: ${JSON.stringify(txResult)}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Compute the WASM hash (SHA-256 of the WASM bytes)
|
|
122
|
-
const wasmHash = hash(wasmBuffer).toString('hex');
|
|
123
|
-
|
|
124
|
-
// Query and display the WASM code TTL
|
|
125
|
-
await queryWasmTtl(wasmHash, server);
|
|
126
|
-
|
|
127
|
-
return wasmHash;
|
|
18
|
+
return uploadWasmEnv(env, wasmBuffer, keypair, server);
|
|
128
19
|
}
|
|
129
20
|
|
|
130
|
-
/**
|
|
131
|
-
* Generic contract deployment helper that works with any contract Client
|
|
132
|
-
*
|
|
133
|
-
* @param ClientClass - The contract Client class (e.g., EndpointClient, SMLClient)
|
|
134
|
-
* @param wasmFilePath - Path to the compiled WASM file
|
|
135
|
-
* @param constructorArgs - Arguments for the contract's constructor
|
|
136
|
-
* @param deployer - The keypair that will deploy the contract
|
|
137
|
-
* @param options - Optional deployment options (salt, fee, timeout, etc.)
|
|
138
|
-
* @returns The deployed contract's Client instance with the contractId
|
|
139
|
-
*/
|
|
140
21
|
export async function deployContract<T extends { options: { contractId: string } }>(
|
|
141
22
|
ClientClass: {
|
|
142
23
|
deploy: (
|
|
@@ -155,158 +36,17 @@ export async function deployContract<T extends { options: { contractId: string }
|
|
|
155
36
|
allowHttp?: boolean;
|
|
156
37
|
} = {},
|
|
157
38
|
): Promise<T> {
|
|
158
|
-
|
|
159
|
-
rpcUrl = RPC_URL,
|
|
160
|
-
networkPassphrase = NETWORK_PASSPHRASE,
|
|
161
|
-
allowHttp = true,
|
|
162
|
-
salt,
|
|
163
|
-
} = options;
|
|
164
|
-
|
|
165
|
-
const server = new rpc.Server(rpcUrl, {
|
|
166
|
-
allowHttp: allowHttp,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
let wasmHash = options.wasmHash;
|
|
170
|
-
if (wasmHash) {
|
|
171
|
-
console.log('📦 Using pre-uploaded WASM hash:', wasmHash);
|
|
172
|
-
} else {
|
|
173
|
-
// Step 1: Read WASM file
|
|
174
|
-
console.log('📖 Reading WASM file from:', wasmFilePath);
|
|
175
|
-
const wasmBuffer = readFileSync(wasmFilePath);
|
|
176
|
-
|
|
177
|
-
// Step 2: Upload WASM and get hash
|
|
178
|
-
console.log('📤 Uploading WASM...');
|
|
179
|
-
wasmHash = await uploadWasm(wasmBuffer, deployer, server);
|
|
180
|
-
console.log('✅ WASM uploaded, hash:', wasmHash);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Step 3: Deploy the contract
|
|
184
|
-
console.log('🚀 Deploying contract...');
|
|
185
|
-
const deployOptions = {
|
|
186
|
-
wasmHash: wasmHash,
|
|
187
|
-
publicKey: deployer.publicKey(),
|
|
188
|
-
signTransaction: async (tx: string) => {
|
|
189
|
-
const transaction = TransactionBuilder.fromXDR(tx, networkPassphrase);
|
|
190
|
-
transaction.sign(deployer);
|
|
191
|
-
return {
|
|
192
|
-
signedTxXdr: transaction.toXDR(),
|
|
193
|
-
signerAddress: deployer.publicKey(),
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
rpcUrl: rpcUrl,
|
|
197
|
-
networkPassphrase: networkPassphrase,
|
|
198
|
-
allowHttp: allowHttp,
|
|
199
|
-
salt: salt,
|
|
200
|
-
};
|
|
201
|
-
const deployTx =
|
|
202
|
-
constructorArgs == null
|
|
203
|
-
? await ClientClass.deploy(deployOptions)
|
|
204
|
-
: await ClientClass.deploy(constructorArgs, deployOptions);
|
|
205
|
-
|
|
206
|
-
// Step 4: Sign and send
|
|
207
|
-
const sentTx = await deployTx.signAndSend();
|
|
208
|
-
|
|
209
|
-
// Step 5: Extract contract ID from result
|
|
210
|
-
const contractClient = sentTx.result;
|
|
211
|
-
const contractId = contractClient.options.contractId;
|
|
212
|
-
console.log('✅ Contract deployed at:', contractId);
|
|
213
|
-
|
|
214
|
-
return contractClient;
|
|
39
|
+
return deployContractEnv(env, ClientClass, wasmFilePath, constructorArgs, deployer, options);
|
|
215
40
|
}
|
|
216
41
|
|
|
217
42
|
export async function deployNativeSac(): Promise<void> {
|
|
218
|
-
|
|
219
|
-
console.log('✅ Native SAC deployed');
|
|
43
|
+
return deployNativeSacEnv(env);
|
|
220
44
|
}
|
|
221
45
|
|
|
222
46
|
export async function deployZroToken(): Promise<void> {
|
|
223
|
-
|
|
224
|
-
allowHttp: true,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// First, issue the ZRO token.
|
|
228
|
-
// We can't changeTrust of Issuer account, because the Issuer can't hold the asset.
|
|
229
|
-
const account = await server.getAccount(DEFAULT_DEPLOYER.publicKey());
|
|
230
|
-
const transaction = new TransactionBuilder(account, {
|
|
231
|
-
fee: BASE_FEE,
|
|
232
|
-
networkPassphrase: NETWORK_PASSPHRASE,
|
|
233
|
-
})
|
|
234
|
-
.addOperation(
|
|
235
|
-
Operation.changeTrust({ asset: ZRO_ASSET, source: ZRO_DISTRIBUTOR.publicKey() }),
|
|
236
|
-
)
|
|
237
|
-
.addOperation(
|
|
238
|
-
Operation.payment({
|
|
239
|
-
asset: ZRO_ASSET,
|
|
240
|
-
amount: '10000',
|
|
241
|
-
destination: ZRO_DISTRIBUTOR.publicKey(),
|
|
242
|
-
}),
|
|
243
|
-
)
|
|
244
|
-
.setTimeout(10)
|
|
245
|
-
.build();
|
|
246
|
-
transaction.sign(DEFAULT_DEPLOYER, ZRO_DISTRIBUTOR);
|
|
247
|
-
|
|
248
|
-
const sendResult = await server.sendTransaction(transaction);
|
|
249
|
-
if (sendResult.status !== 'PENDING') {
|
|
250
|
-
throw new Error(`Failed to issue ZRO token: ${JSON.stringify(sendResult)}`);
|
|
251
|
-
}
|
|
252
|
-
const txResult = await server.pollTransaction(sendResult.hash);
|
|
253
|
-
if (txResult.status !== 'SUCCESS') {
|
|
254
|
-
throw new Error(`Failed to issue ZRO token: ${JSON.stringify(txResult)}`);
|
|
255
|
-
}
|
|
256
|
-
console.log('✅ ZRO asset issued');
|
|
257
|
-
|
|
258
|
-
// Deploy the Stellar Asset Contract (SAC)
|
|
259
|
-
await deployAssetSac(ZRO_ASSET);
|
|
260
|
-
console.log('✅ ZRO SAC deployed');
|
|
47
|
+
return deployZroTokenEnv(env);
|
|
261
48
|
}
|
|
262
49
|
|
|
263
|
-
/**
|
|
264
|
-
* Deploy SAC for a custom asset using TypeScript
|
|
265
|
-
*/
|
|
266
50
|
export async function deployAssetSac(asset: Asset): Promise<string> {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const server = new rpc.Server(RPC_URL, { allowHttp: true });
|
|
270
|
-
const account = await server.getAccount(DEFAULT_DEPLOYER.publicKey());
|
|
271
|
-
|
|
272
|
-
// Build transaction with createStellarAssetContract operation
|
|
273
|
-
const deployTx = new TransactionBuilder(account, {
|
|
274
|
-
fee: BASE_FEE,
|
|
275
|
-
networkPassphrase: NETWORK_PASSPHRASE,
|
|
276
|
-
})
|
|
277
|
-
.addOperation(
|
|
278
|
-
Operation.createStellarAssetContract({
|
|
279
|
-
asset: asset,
|
|
280
|
-
}),
|
|
281
|
-
)
|
|
282
|
-
.setTimeout(30)
|
|
283
|
-
.build();
|
|
284
|
-
|
|
285
|
-
// Simulate transaction first (required for contract operations)
|
|
286
|
-
const simulated = await server.simulateTransaction(deployTx);
|
|
287
|
-
|
|
288
|
-
// Check if simulation was successful
|
|
289
|
-
if (rpc.Api.isSimulationError(simulated)) {
|
|
290
|
-
// Soroban returns ExistingValue when the contract is already deployed.
|
|
291
|
-
// This is expected on container reuse (local dev reruns).
|
|
292
|
-
if (simulated.error?.includes('ExistingValue')) {
|
|
293
|
-
console.log(`SAC for ${asset.toString()} already deployed, skipping`);
|
|
294
|
-
return asset.contractId(NETWORK_PASSPHRASE);
|
|
295
|
-
}
|
|
296
|
-
throw new Error(`Transaction simulation failed: ${JSON.stringify(simulated)}`);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const preparedTx = rpc.assembleTransaction(deployTx, simulated).build();
|
|
300
|
-
|
|
301
|
-
// Sign and send
|
|
302
|
-
preparedTx.sign(DEFAULT_DEPLOYER);
|
|
303
|
-
const sendResult = await server.sendTransaction(preparedTx);
|
|
304
|
-
if (sendResult.status !== 'PENDING') {
|
|
305
|
-
throw new Error(`Failed to deploy SAC: ${JSON.stringify(sendResult)}`);
|
|
306
|
-
}
|
|
307
|
-
const txResult = await server.pollTransaction(sendResult.hash);
|
|
308
|
-
if (txResult.status !== 'SUCCESS') {
|
|
309
|
-
throw new Error(`SAC deployment not successful: ${JSON.stringify(txResult)}`);
|
|
310
|
-
}
|
|
311
|
-
return asset.contractId(NETWORK_PASSPHRASE);
|
|
51
|
+
return deployAssetSacEnv(env, asset);
|
|
312
52
|
}
|