@across-protocol/contracts 4.0.11 → 4.0.12
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/dist/scripts/svm/{enableRoute.js → createVault.js} +13 -35
- package/dist/scripts/svm/fakeFillWithRandomDistribution.js +9 -8
- package/dist/scripts/svm/nativeDeposit.js +138 -0
- package/dist/scripts/svm/queryEventsV2.js +3 -3
- package/dist/scripts/svm/{queryRoute.js → queryVault.js} +10 -25
- package/dist/scripts/svm/remoteHubPoolPauseDeposits.js +2 -2
- package/dist/scripts/svm/simpleDeposit.js +3 -12
- package/dist/scripts/svm/simpleFakeRelayerRepayment.js +2 -9
- package/dist/scripts/svm/simpleFill.js +3 -2
- package/dist/src/svm/assets/idl/svm_spoke.json +43 -369
- package/dist/src/svm/assets/svm_spoke.d.ts +40 -366
- package/dist/src/svm/clients/SvmSpoke/accounts/index.d.ts +0 -1
- package/dist/src/svm/clients/SvmSpoke/accounts/index.js +0 -1
- package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.d.ts +3 -1
- package/dist/src/svm/clients/SvmSpoke/errors/svmSpoke.js +4 -1
- package/dist/src/svm/clients/SvmSpoke/instructions/deposit.d.ts +21 -13
- package/dist/src/svm/clients/SvmSpoke/instructions/deposit.js +38 -6
- package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.d.ts +21 -13
- package/dist/src/svm/clients/SvmSpoke/instructions/depositNow.js +38 -6
- package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.d.ts +20 -16
- package/dist/src/svm/clients/SvmSpoke/instructions/fillRelay.js +6 -1
- package/dist/src/svm/clients/SvmSpoke/instructions/index.d.ts +0 -1
- package/dist/src/svm/clients/SvmSpoke/instructions/index.js +0 -1
- package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.d.ts +21 -13
- package/dist/src/svm/clients/SvmSpoke/instructions/unsafeDeposit.js +38 -6
- package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.d.ts +6 -10
- package/dist/src/svm/clients/SvmSpoke/programs/svmSpoke.js +5 -13
- package/dist/src/svm/clients/SvmSpoke/types/index.d.ts +0 -1
- package/dist/src/svm/clients/SvmSpoke/types/index.js +0 -1
- package/dist/src/svm/web3-v1/helpers.d.ts +114 -1
- package/dist/src/svm/web3-v1/helpers.js +179 -1
- package/dist/target/types/svm_spoke.d.ts +40 -366
- package/dist/test/svm/SvmSpoke.Deposit.js +143 -176
- package/dist/test/svm/SvmSpoke.Fill.AcrossPlus.js +20 -17
- package/dist/test/svm/SvmSpoke.Fill.js +52 -38
- package/dist/test/svm/SvmSpoke.HandleReceiveMessage.js +2 -114
- package/dist/test/svm/SvmSpoke.SlowFill.AcrossPlus.js +2 -2
- package/dist/test/svm/SvmSpoke.SlowFill.js +37 -34
- package/dist/test/svm/SvmSpoke.common.d.ts +2 -3
- package/dist/test/svm/SvmSpoke.common.js +3 -12
- package/package.json +1 -1
- package/dist/scripts/svm/remoteHubPoolSetDepositRoute.d.ts +0 -1
- package/dist/scripts/svm/remoteHubPoolSetDepositRoute.js +0 -252
- package/dist/src/svm/clients/SvmSpoke/accounts/route.d.ts +0 -27
- package/dist/src/svm/clients/SvmSpoke/accounts/route.js +0 -66
- package/dist/src/svm/clients/SvmSpoke/instructions/setEnableRoute.d.ts +0 -95
- package/dist/src/svm/clients/SvmSpoke/instructions/setEnableRoute.js +0 -213
- package/dist/src/svm/clients/SvmSpoke/types/enabledDepositRoute.d.ts +0 -21
- package/dist/src/svm/clients/SvmSpoke/types/enabledDepositRoute.js +0 -30
- package/dist/test/svm/SvmSpoke.Routes.js +0 -167
- /package/dist/scripts/svm/{enableRoute.d.ts → createVault.d.ts} +0 -0
- /package/dist/scripts/svm/{queryRoute.d.ts → nativeDeposit.d.ts} +0 -0
- /package/dist/{test/svm/SvmSpoke.Routes.d.ts → scripts/svm/queryVault.d.ts} +0 -0
|
@@ -32,11 +32,10 @@ const SvmSpoke_common_1 = require("./SvmSpoke.common");
|
|
|
32
32
|
const MerkleTree_1 = require("@uma/common/dist/MerkleTree");
|
|
33
33
|
const web3_v1_1 = require("../../src/svm/web3-v1");
|
|
34
34
|
const utils_1 = require("./utils");
|
|
35
|
-
const { provider, connection, program, owner, chainId, seedBalance, initializeState } = SvmSpoke_common_1.common;
|
|
36
|
-
const { recipient, setCurrentTime, assertSE, assert } = SvmSpoke_common_1.common;
|
|
35
|
+
const { provider, connection, program, owner, chainId, seedBalance, initializeState, recipient, setCurrentTime, assertSE, assert, } = SvmSpoke_common_1.common;
|
|
37
36
|
describe("svm_spoke.slow_fill", () => {
|
|
38
37
|
anchor.setProvider(provider);
|
|
39
|
-
const payer = anchor.AnchorProvider.env().wallet
|
|
38
|
+
const { payer } = anchor.AnchorProvider.env().wallet;
|
|
40
39
|
const relayer = web3_js_1.Keypair.generate();
|
|
41
40
|
const otherRelayer = web3_js_1.Keypair.generate();
|
|
42
41
|
const { encodedMessage, fillRemainingAccounts } = (0, utils_1.testAcrossPlusMessage)();
|
|
@@ -47,7 +46,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
47
46
|
let requestAccounts; // Store accounts to simplify program interactions.
|
|
48
47
|
let fillAccounts;
|
|
49
48
|
const initialMintAmount = 10_000_000_000;
|
|
50
|
-
async
|
|
49
|
+
const updateRelayData = async (newRelayData) => {
|
|
51
50
|
relayData = newRelayData;
|
|
52
51
|
const relayHashUint8Array = (0, web3_v1_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
53
52
|
[fillStatus] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
|
|
@@ -64,6 +63,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
64
63
|
};
|
|
65
64
|
fillAccounts = {
|
|
66
65
|
state,
|
|
66
|
+
delegate: (0, web3_v1_1.getFillRelayDelegatePda)(relayHashUint8Array, new anchor_1.BN(1), relayer.publicKey, program.programId).pda,
|
|
67
67
|
signer: relayer.publicKey,
|
|
68
68
|
instructionParams: program.programId,
|
|
69
69
|
mint: mint,
|
|
@@ -74,7 +74,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
74
74
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
75
75
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
76
76
|
};
|
|
77
|
-
}
|
|
77
|
+
};
|
|
78
78
|
const relaySlowFillRootBundle = async (slowRelayLeafRecipient = recipient, slowRelayLeafChainId = chainId, message = encodedMessage) => {
|
|
79
79
|
//TODO: verify that the leaf structure created here is equivalent to the one created by the EVM logic. I think
|
|
80
80
|
// I've gotten the concatenation, endianness, etc correct but want to be sure.
|
|
@@ -104,7 +104,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
104
104
|
const proof = merkleTree.getProof(slowRelayLeafs[0]);
|
|
105
105
|
const leaf = slowRelayLeafs[0];
|
|
106
106
|
let stateAccountData = await program.account.state.fetch(state);
|
|
107
|
-
const rootBundleId = stateAccountData
|
|
107
|
+
const { rootBundleId } = stateAccountData;
|
|
108
108
|
const rootBundleIdBuffer = Buffer.alloc(4);
|
|
109
109
|
rootBundleIdBuffer.writeUInt32LE(rootBundleId);
|
|
110
110
|
const seeds = [Buffer.from("root_bundle"), seed.toArrayLike(Buffer, "le", 8), rootBundleIdBuffer];
|
|
@@ -152,7 +152,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
152
152
|
};
|
|
153
153
|
await updateRelayData(initialRelayData);
|
|
154
154
|
});
|
|
155
|
-
it("Requests a
|
|
155
|
+
it("Requests a slow fill, verify the event & state change", async () => {
|
|
156
156
|
// Attempt to request a slow fill before the exclusivityDeadline
|
|
157
157
|
const relayHash = Array.from((0, web3_v1_1.calculateRelayHashUint8Array)(relayData, chainId));
|
|
158
158
|
try {
|
|
@@ -178,14 +178,16 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
178
178
|
if (key === "message") {
|
|
179
179
|
assertSE(event.messageHash, (0, web3_v1_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
180
180
|
}
|
|
181
|
-
else
|
|
181
|
+
else {
|
|
182
182
|
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
|
|
183
|
+
}
|
|
183
184
|
});
|
|
184
185
|
});
|
|
185
|
-
it("Fails to request a
|
|
186
|
-
const
|
|
186
|
+
it("Fails to request a slow fill if the relay has already been filled", async () => {
|
|
187
|
+
const relayHashUint8Array = (0, web3_v1_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
188
|
+
const relayHash = Array.from(relayHashUint8Array);
|
|
187
189
|
// Fill the relay first
|
|
188
|
-
const approveIx = await (0, spl_token_1.createApproveCheckedInstruction)(fillAccounts.relayerTokenAccount, fillAccounts.mint,
|
|
190
|
+
const approveIx = await (0, spl_token_1.createApproveCheckedInstruction)(fillAccounts.relayerTokenAccount, fillAccounts.mint, (0, web3_v1_1.getFillRelayDelegatePda)(relayHashUint8Array, new anchor_1.BN(1), relayer.publicKey, program.programId).pda, fillAccounts.signer, BigInt(relayData.outputAmount.toString()), tokenDecimals);
|
|
189
191
|
const fillIx = await program.methods
|
|
190
192
|
.fillRelay(relayHash, relayData, new anchor_1.BN(1), relayer.publicKey)
|
|
191
193
|
.accounts(fillAccounts)
|
|
@@ -231,7 +233,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
231
233
|
assert.equal(JSON.stringify(fillStatusAccount.status), `{\"requestedSlowFill\":{}}`, "FillStatus should be RequestedSlowFill");
|
|
232
234
|
assert.equal(fillStatusAccount.relayer.toString(), relayer.publicKey.toString(), "Caller should be set as relayer");
|
|
233
235
|
});
|
|
234
|
-
it("Fails to request a
|
|
236
|
+
it("Fails to request a slow fill multiple times for the same fill", async () => {
|
|
235
237
|
const relayHash = (0, web3_v1_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
236
238
|
// Set the contract time to be after the exclusivityDeadline
|
|
237
239
|
await setCurrentTime(program, state, relayer, new anchor_1.BN(relayData.exclusivityDeadline + 1));
|
|
@@ -254,12 +256,12 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
254
256
|
assert.include(err.toString(), "InvalidSlowFillRequest", "Expected InvalidSlowFillRequest error");
|
|
255
257
|
}
|
|
256
258
|
});
|
|
257
|
-
it("Executes
|
|
259
|
+
it("Executes slow relay leaf, verify the event & state change", async () => {
|
|
258
260
|
// Relay root bundle with slow fill leaf.
|
|
259
261
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle();
|
|
260
262
|
const iVaultBal = (await connection.getTokenAccountBalance(vault)).value.amount;
|
|
261
263
|
const iRecipientBal = (await connection.getTokenAccountBalance(recipientTA)).value.amount;
|
|
262
|
-
// Attempt to execute
|
|
264
|
+
// Attempt to execute slow relay leaf before requesting slow fill. This should fail before requested,
|
|
263
265
|
// even if there is a valid proof.
|
|
264
266
|
const executeSlowRelayLeafAccounts = {
|
|
265
267
|
state: state,
|
|
@@ -284,13 +286,13 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
284
286
|
catch (err) {
|
|
285
287
|
assert.include(err.toString(), "AccountNotInitialized", "Expected AccountNotInitialized error");
|
|
286
288
|
}
|
|
287
|
-
// Request
|
|
289
|
+
// Request slow fill
|
|
288
290
|
await program.methods
|
|
289
291
|
.requestSlowFill(Array.from(relayHash), leaf.relayData)
|
|
290
292
|
.accounts(requestAccounts)
|
|
291
293
|
.signers([relayer])
|
|
292
294
|
.rpc();
|
|
293
|
-
// Execute
|
|
295
|
+
// Execute slow relay leaf after requesting slow fill
|
|
294
296
|
const ix = await program.methods
|
|
295
297
|
.executeSlowRelayLeaf(Array.from(relayHash), leaf, rootBundleId, proofAsNumbers)
|
|
296
298
|
.accounts(executeSlowRelayLeafAccounts)
|
|
@@ -314,8 +316,9 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
314
316
|
if (key === "message") {
|
|
315
317
|
assertSE(event.messageHash, (0, web3_v1_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
316
318
|
}
|
|
317
|
-
else
|
|
319
|
+
else {
|
|
318
320
|
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
|
|
321
|
+
}
|
|
319
322
|
});
|
|
320
323
|
// RelayExecutionInfo should match.
|
|
321
324
|
assertSE(event.relayExecutionInfo.updatedRecipient, relayData.recipient, "UpdatedRecipient should match");
|
|
@@ -326,7 +329,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
326
329
|
assertSE(event.repaymentChainId, new anchor_1.BN(0), "Repayment chain id should be 0");
|
|
327
330
|
assertSE(event.relayer, web3_js_1.PublicKey.default, "Repayment address should be 0");
|
|
328
331
|
});
|
|
329
|
-
it("Fails to request a
|
|
332
|
+
it("Fails to request a slow fill when fills are paused", async () => {
|
|
330
333
|
// Pause fills
|
|
331
334
|
const pauseFillsAccounts = {
|
|
332
335
|
state: state,
|
|
@@ -351,15 +354,15 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
351
354
|
assert.strictEqual(err.error.errorCode.code, "FillsArePaused", "Expected error code FillsArePaused");
|
|
352
355
|
}
|
|
353
356
|
});
|
|
354
|
-
it("Fails to execute
|
|
355
|
-
// Request
|
|
357
|
+
it("Fails to execute slow relay leaf to wrong recipient", async () => {
|
|
358
|
+
// Request slow fill.
|
|
356
359
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle();
|
|
357
360
|
await program.methods
|
|
358
361
|
.requestSlowFill(Array.from(relayHash), leaf.relayData)
|
|
359
362
|
.accounts(requestAccounts)
|
|
360
363
|
.signers([relayer])
|
|
361
364
|
.rpc();
|
|
362
|
-
// Try to execute
|
|
365
|
+
// Try to execute slow relay leaf with wrong recipient token account should fail.
|
|
363
366
|
const wrongRecipient = web3_js_1.Keypair.generate().publicKey;
|
|
364
367
|
const wrongRecipientTA = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, mint, wrongRecipient)).address;
|
|
365
368
|
try {
|
|
@@ -387,8 +390,8 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
387
390
|
assert.strictEqual(err.error.errorCode.code, "ConstraintTokenOwner", "Expected error code ConstraintTokenOwner");
|
|
388
391
|
}
|
|
389
392
|
});
|
|
390
|
-
it("Cannot replay execute
|
|
391
|
-
// Request
|
|
393
|
+
it("Cannot replay execute slow relay leaf against wrong fill status account", async () => {
|
|
394
|
+
// Request slow fill for the first recipient.
|
|
392
395
|
const firstRecipient = web3_js_1.Keypair.generate().publicKey;
|
|
393
396
|
const { relayHash: firstRelayHash, leaf: firstLeaf, rootBundleId: firstRootBundleId, proofAsNumbers: firstProofAsNumbers, rootBundle: firstRootBundle, } = await relaySlowFillRootBundle(firstRecipient);
|
|
394
397
|
await program.methods
|
|
@@ -398,7 +401,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
398
401
|
.rpc();
|
|
399
402
|
const firstRecipientTA = recipientTA; // Global recipientTA will get updated when passing the second relayData.
|
|
400
403
|
const firstFillStatus = fillStatus; // Global fillStatus will get updated when passing the second relayData.
|
|
401
|
-
// Request
|
|
404
|
+
// Request slow fill for the second recipient.
|
|
402
405
|
// Note: we could also had generated single slow relay root for both recipients, but having them relayed in separate
|
|
403
406
|
// root bundles makes it easier to reuse existing test code.
|
|
404
407
|
const secondRecipient = web3_js_1.Keypair.generate().publicKey;
|
|
@@ -410,7 +413,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
410
413
|
.rpc();
|
|
411
414
|
const secondFillStatus = fillStatus; // Global fillStatus got updated with the second relayData.
|
|
412
415
|
const iFirstRecipientBal = (await connection.getTokenAccountBalance(firstRecipientTA)).value.amount;
|
|
413
|
-
// Execute
|
|
416
|
+
// Execute slow relay leaf for the first recipient.
|
|
414
417
|
const executeSlowRelayLeafAccounts = {
|
|
415
418
|
state,
|
|
416
419
|
rootBundle: firstRootBundle,
|
|
@@ -430,7 +433,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
430
433
|
.rpc();
|
|
431
434
|
const fFirstRecipientBal = (await connection.getTokenAccountBalance(firstRecipientTA)).value.amount;
|
|
432
435
|
assert.strictEqual(BigInt(fFirstRecipientBal) - BigInt(iFirstRecipientBal), BigInt(firstLeaf.updatedOutputAmount.toString()), "First recipient balance should be increased by its relay amount");
|
|
433
|
-
// Try to replay execute
|
|
436
|
+
// Try to replay execute slow relay leaf for the first recipient using the fill status account that is derived
|
|
434
437
|
// from the second relay hash. This should fail due to mismatching relay hash.
|
|
435
438
|
try {
|
|
436
439
|
const executeSlowRelayLeafAccounts = {
|
|
@@ -457,8 +460,8 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
457
460
|
assert.strictEqual(err.error.errorCode.code, "InvalidRelayHash", "Expected error code InvalidRelayHash");
|
|
458
461
|
}
|
|
459
462
|
});
|
|
460
|
-
it("Fails to execute
|
|
461
|
-
// Request
|
|
463
|
+
it("Fails to execute slow relay leaf for mint inconsistent output_token", async () => {
|
|
464
|
+
// Request slow fill.
|
|
462
465
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle();
|
|
463
466
|
await program.methods
|
|
464
467
|
.requestSlowFill(Array.from(relayHash), leaf.relayData)
|
|
@@ -470,7 +473,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
470
473
|
const wrongRecipientTA = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, wrongMint, recipient)).address;
|
|
471
474
|
const wrongVault = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, wrongMint, state, true)).address;
|
|
472
475
|
await (0, spl_token_1.mintTo)(connection, payer, wrongMint, wrongVault, provider.publicKey, initialMintAmount);
|
|
473
|
-
// Try to execute
|
|
476
|
+
// Try to execute slow relay leaf with inconsistent mint should fail.
|
|
474
477
|
try {
|
|
475
478
|
const executeSlowRelayLeafAccounts = {
|
|
476
479
|
state,
|
|
@@ -496,8 +499,8 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
496
499
|
assert.strictEqual(err.error.errorCode.code, "InvalidMint", "Expected error code InvalidMint");
|
|
497
500
|
}
|
|
498
501
|
});
|
|
499
|
-
it("Cannot execute
|
|
500
|
-
// Request
|
|
502
|
+
it("Cannot execute slow relay leaf targeted at another chain", async () => {
|
|
503
|
+
// Request slow fill for another chain.
|
|
501
504
|
const anotherChainId = new anchor_1.BN(Math.floor(Math.random() * 1000000));
|
|
502
505
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle(undefined, anotherChainId);
|
|
503
506
|
await program.methods
|
|
@@ -505,7 +508,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
505
508
|
.accounts(requestAccounts)
|
|
506
509
|
.signers([relayer])
|
|
507
510
|
.rpc();
|
|
508
|
-
// Trying to execute
|
|
511
|
+
// Trying to execute slow relay leaf for another chain should fail as the program overrides chain_id that should
|
|
509
512
|
// invalidate the proofs.
|
|
510
513
|
try {
|
|
511
514
|
const executeSlowRelayLeafAccounts = {
|
|
@@ -535,13 +538,13 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
535
538
|
it("Emits zeroed hash for empty message", async () => {
|
|
536
539
|
// Relay root bundle of slow fill leaf with empty message.
|
|
537
540
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle(undefined, undefined, Buffer.alloc(0));
|
|
538
|
-
// Request
|
|
541
|
+
// Request slow fill
|
|
539
542
|
const tx1 = await program.methods
|
|
540
543
|
.requestSlowFill(Array.from(relayHash), leaf.relayData)
|
|
541
544
|
.accounts(requestAccounts)
|
|
542
545
|
.signers([relayer])
|
|
543
546
|
.rpc();
|
|
544
|
-
// Execute
|
|
547
|
+
// Execute slow relay leaf after requesting slow fill
|
|
545
548
|
const executeSlowRelayLeafAccounts = {
|
|
546
549
|
state,
|
|
547
550
|
rootBundle,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as anchor from "@coral-xyz/anchor";
|
|
2
2
|
import { BN, Program } from "@coral-xyz/anchor";
|
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { PublicKey, Signer } from "@solana/web3.js";
|
|
4
4
|
import { DepositData } from "../../src/types/svm";
|
|
5
5
|
import { SvmSpoke } from "../../target/types/svm_spoke";
|
|
6
6
|
declare function setCurrentTime(program: Program<SvmSpoke>, state: any, signer: anchor.web3.Keypair, newTime: BN): Promise<void>;
|
|
@@ -39,8 +39,7 @@ export declare const common: {
|
|
|
39
39
|
state: anchor.web3.PublicKey;
|
|
40
40
|
seed: anchor.BN;
|
|
41
41
|
}>;
|
|
42
|
-
|
|
43
|
-
getVaultAta: (tokenMint: PublicKey, state: PublicKey) => Promise<anchor.web3.PublicKey>;
|
|
42
|
+
getOrCreateVaultAta: (payer: Signer, tokenMint: PublicKey, state: PublicKey) => Promise<anchor.web3.PublicKey>;
|
|
44
43
|
setCurrentTime: typeof setCurrentTime;
|
|
45
44
|
getCurrentTime: typeof getCurrentTime;
|
|
46
45
|
assert: Chai.AssertStatic;
|
|
@@ -73,19 +73,11 @@ const initializeState = async (seed, initialState) => {
|
|
|
73
73
|
.rpc();
|
|
74
74
|
return { state, seed: actualSeed };
|
|
75
75
|
};
|
|
76
|
-
const
|
|
77
|
-
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
78
|
-
Buffer.from("route"),
|
|
79
|
-
originToken.toBytes(),
|
|
80
|
-
seed.toArrayLike(Buffer, "le", 8),
|
|
81
|
-
routeChainId.toArrayLike(Buffer, "le", 8),
|
|
82
|
-
], program.programId)[0];
|
|
83
|
-
};
|
|
84
|
-
const getVaultAta = async (tokenMint, state) => {
|
|
76
|
+
const getOrCreateVaultAta = async (payer, tokenMint, state) => {
|
|
85
77
|
const tokenMintAccount = await provider.connection.getAccountInfo(tokenMint);
|
|
86
78
|
if (tokenMintAccount === null)
|
|
87
79
|
throw new Error("Token Mint account not found");
|
|
88
|
-
return (0, spl_token_1.
|
|
80
|
+
return (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, tokenMint, state, true, undefined, undefined, tokenMintAccount.owner, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID)).address;
|
|
89
81
|
};
|
|
90
82
|
async function setCurrentTime(program, state, signer, newTime) {
|
|
91
83
|
let setCurrentTimeAccounts = { state, signer: signer.publicKey };
|
|
@@ -125,8 +117,7 @@ exports.common = {
|
|
|
125
117
|
depositQuoteTimeBuffer,
|
|
126
118
|
fillDeadlineBuffer,
|
|
127
119
|
initializeState,
|
|
128
|
-
|
|
129
|
-
getVaultAta,
|
|
120
|
+
getOrCreateVaultAta,
|
|
130
121
|
setCurrentTime,
|
|
131
122
|
getCurrentTime,
|
|
132
123
|
assert: chai_1.assert,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This script bridges remote call to pause deposits on Solana Spoke Pool. Required environment:
|
|
3
|
-
// - NODE_URL_${CHAIN_ID}: Ethereum RPC URL (must point to the Mainnet or Sepolia depending on Solana cluster).
|
|
4
|
-
// - MNEMONIC: Mnemonic of the wallet that will sign the sending transaction on Ethereum
|
|
5
|
-
// - HUB_POOL_ADDRESS: Hub Pool address
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
-
if (mod && mod.__esModule) return mod;
|
|
24
|
-
var result = {};
|
|
25
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
-
__setModuleDefault(result, mod);
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
-
};
|
|
32
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
34
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
35
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
36
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
37
|
-
const common_1 = require("@uma/common");
|
|
38
|
-
require("dotenv/config");
|
|
39
|
-
const ethers_1 = require("ethers");
|
|
40
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
41
|
-
const helpers_1 = require("yargs/helpers");
|
|
42
|
-
const web3_v1_1 = require("../../src/svm/web3-v1");
|
|
43
|
-
const typechain_1 = require("../../typechain");
|
|
44
|
-
const constants_1 = require("../../utils/constants");
|
|
45
|
-
const helpers_2 = require("./utils/helpers");
|
|
46
|
-
// Set up Solana provider.
|
|
47
|
-
const provider = anchor_1.AnchorProvider.env();
|
|
48
|
-
anchor.setProvider(provider);
|
|
49
|
-
// Parse arguments
|
|
50
|
-
const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
51
|
-
.option("originChainId", { type: "string", demandOption: true, describe: "Origin chain ID" })
|
|
52
|
-
.option("destinationChainId", { type: "string", demandOption: true, describe: "Destination chain ID" })
|
|
53
|
-
.option("depositsEnabled", { type: "boolean", demandOption: true, describe: "Deposits enabled" })
|
|
54
|
-
.option("resumeRemoteTx", { type: "string", demandOption: false, describe: "Resume receiving remote tx" }).argv;
|
|
55
|
-
async function remoteHubPoolSetDepositRoute() {
|
|
56
|
-
const resolvedArgv = await argv;
|
|
57
|
-
const originChainId = resolvedArgv.originChainId;
|
|
58
|
-
const destinationChainId = resolvedArgv.destinationChainId;
|
|
59
|
-
const depositsEnabled = resolvedArgv.depositsEnabled;
|
|
60
|
-
const seed = new anchor_1.BN(0);
|
|
61
|
-
const resumeRemoteTx = resolvedArgv.resumeRemoteTx;
|
|
62
|
-
// Set up Ethereum provider and signer.
|
|
63
|
-
const isDevnet = (0, web3_v1_1.isSolanaDevnet)(provider);
|
|
64
|
-
const nodeURL = isDevnet ? (0, common_1.getNodeUrl)("sepolia", true) : (0, common_1.getNodeUrl)("mainnet", true);
|
|
65
|
-
const ethersProvider = new ethers_1.ethers.providers.JsonRpcProvider(nodeURL);
|
|
66
|
-
const ethersSigner = ethers_1.ethers.Wallet.fromMnemonic((0, helpers_2.requireEnv)("MNEMONIC")).connect(ethersProvider);
|
|
67
|
-
const hubPoolAddress = (0, helpers_2.requireEnv)("HUB_POOL_ADDRESS");
|
|
68
|
-
const usdcProgramId = isDevnet ? web3_v1_1.SOLANA_USDC_DEVNET : web3_v1_1.SOLANA_USDC_MAINNET;
|
|
69
|
-
const originToken = new web3_js_1.PublicKey(usdcProgramId);
|
|
70
|
-
const originTokenAddress = (0, web3_v1_1.fromBytes32ToAddress)((0, web3_v1_1.fromBase58ToBytes32)(originToken.toBase58()));
|
|
71
|
-
// CCTP domains.
|
|
72
|
-
const remoteDomain = 0; // Ethereum
|
|
73
|
-
// Get Solana programs and accounts.
|
|
74
|
-
const svmSpokeProgram = (0, web3_v1_1.getSpokePoolProgram)(provider);
|
|
75
|
-
const [statePda, _] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("state"), seed.toArrayLike(Buffer, "le", 8)], svmSpokeProgram.programId);
|
|
76
|
-
const [routePda] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
77
|
-
Buffer.from("route"),
|
|
78
|
-
originToken.toBytes(),
|
|
79
|
-
seed.toArrayLike(Buffer, "le", 8),
|
|
80
|
-
new anchor_1.BN(destinationChainId).toArrayLike(Buffer, "le", 8),
|
|
81
|
-
], svmSpokeProgram.programId);
|
|
82
|
-
const vault = (0, spl_token_1.getAssociatedTokenAddressSync)(originToken, statePda, true, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
83
|
-
const messageTransmitterProgram = (0, web3_v1_1.getMessageTransmitterProgram)(provider);
|
|
84
|
-
const [messageTransmitterState] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("message_transmitter")], messageTransmitterProgram.programId);
|
|
85
|
-
const [authorityPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("message_transmitter_authority"), svmSpokeProgram.programId.toBuffer()], messageTransmitterProgram.programId);
|
|
86
|
-
const [selfAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("self_authority")], svmSpokeProgram.programId);
|
|
87
|
-
const [eventAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("__event_authority")], svmSpokeProgram.programId);
|
|
88
|
-
const irisApiUrl = isDevnet ? web3_v1_1.CIRCLE_IRIS_API_URL_DEVNET : web3_v1_1.CIRCLE_IRIS_API_URL_MAINNET;
|
|
89
|
-
const solanaCluster = isDevnet ? "devnet" : "mainnet";
|
|
90
|
-
const supportedEvmChainId = isDevnet ? constants_1.CHAIN_IDs.SEPOLIA : constants_1.CHAIN_IDs.MAINNET; // Sepolia is bridged to devnet, Ethereum to mainnet in CCTP.
|
|
91
|
-
const evmChainId = (await ethersProvider.getNetwork()).chainId;
|
|
92
|
-
if (evmChainId !== supportedEvmChainId) {
|
|
93
|
-
throw new Error(`Chain ID ${evmChainId} does not match expected Solana cluster ${solanaCluster}`);
|
|
94
|
-
}
|
|
95
|
-
const hubPool = typechain_1.HubPool__factory.connect(hubPoolAddress, ethersProvider);
|
|
96
|
-
console.log("Remotely configuring deposit route...");
|
|
97
|
-
console.table([
|
|
98
|
-
{ Property: "seed", Value: seed.toString() },
|
|
99
|
-
{ Property: "evmChainId", Value: evmChainId.toString() },
|
|
100
|
-
{ Property: "originChainId", Value: originChainId },
|
|
101
|
-
{ Property: "destinationChainId", Value: destinationChainId },
|
|
102
|
-
{ Property: "depositsEnabled", Value: depositsEnabled },
|
|
103
|
-
{ Property: "svmSpokeProgramProgramId", Value: svmSpokeProgram.programId.toString() },
|
|
104
|
-
{ Property: "providerPublicKey", Value: provider.wallet.publicKey.toString() },
|
|
105
|
-
{ Property: "statePda", Value: statePda.toString() },
|
|
106
|
-
{ Property: "messageTransmitterProgramId", Value: messageTransmitterProgram.programId.toString() },
|
|
107
|
-
{ Property: "messageTransmitterState", Value: messageTransmitterState.toString() },
|
|
108
|
-
{ Property: "authorityPda", Value: authorityPda.toString() },
|
|
109
|
-
{ Property: "selfAuthority", Value: selfAuthority.toString() },
|
|
110
|
-
{ Property: "eventAuthority", Value: eventAuthority.toString() },
|
|
111
|
-
{ Property: "remoteSender", Value: ethersSigner.address },
|
|
112
|
-
]);
|
|
113
|
-
// Send setDepositRoute call from Ethereum, unless resuming a remote transaction.
|
|
114
|
-
let remoteTxHash;
|
|
115
|
-
if (!resumeRemoteTx) {
|
|
116
|
-
console.log("Sending setDepositRoute message from HubPool...");
|
|
117
|
-
const tx = await hubPool
|
|
118
|
-
.connect(ethersSigner)
|
|
119
|
-
.setDepositRoute(originChainId, destinationChainId, originTokenAddress, depositsEnabled);
|
|
120
|
-
await tx.wait();
|
|
121
|
-
remoteTxHash = tx.hash;
|
|
122
|
-
console.log("Message sent on remote chain, tx", remoteTxHash);
|
|
123
|
-
}
|
|
124
|
-
else
|
|
125
|
-
remoteTxHash = resumeRemoteTx;
|
|
126
|
-
// Fetch attestation from CCTP attestation service.
|
|
127
|
-
const attestationResponse = await (0, web3_v1_1.getMessages)(remoteTxHash, remoteDomain, irisApiUrl);
|
|
128
|
-
const { attestation, message } = attestationResponse.messages[0];
|
|
129
|
-
console.log("CCTP attestation response:", attestationResponse.messages[0]);
|
|
130
|
-
// Accounts in CCTP message_transmitter receive_message instruction.
|
|
131
|
-
const nonce = (0, web3_v1_1.decodeMessageHeader)(Buffer.from(message.replace("0x", ""), "hex")).nonce;
|
|
132
|
-
const usedNonces = (await messageTransmitterProgram.methods
|
|
133
|
-
.getNoncePda({
|
|
134
|
-
nonce: new anchor_1.BN(nonce.toString()),
|
|
135
|
-
sourceDomain: remoteDomain,
|
|
136
|
-
})
|
|
137
|
-
.accounts({
|
|
138
|
-
messageTransmitter: messageTransmitterState,
|
|
139
|
-
})
|
|
140
|
-
.view());
|
|
141
|
-
const receiveMessageAccounts = {
|
|
142
|
-
payer: provider.wallet.publicKey,
|
|
143
|
-
caller: provider.wallet.publicKey,
|
|
144
|
-
authorityPda,
|
|
145
|
-
messageTransmitter: messageTransmitterState,
|
|
146
|
-
usedNonces,
|
|
147
|
-
receiver: svmSpokeProgram.programId,
|
|
148
|
-
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
149
|
-
};
|
|
150
|
-
// accountMetas list to pass to remaining accounts when receiving message via CCTP.
|
|
151
|
-
const remainingAccounts = [];
|
|
152
|
-
// state in HandleReceiveMessage accounts (used for remote domain and sender authentication).
|
|
153
|
-
remainingAccounts.push({
|
|
154
|
-
isSigner: false,
|
|
155
|
-
isWritable: false,
|
|
156
|
-
pubkey: statePda,
|
|
157
|
-
});
|
|
158
|
-
// self_authority in HandleReceiveMessage accounts, also signer in self-invoked CPIs.
|
|
159
|
-
remainingAccounts.push({
|
|
160
|
-
isSigner: false,
|
|
161
|
-
isWritable: false,
|
|
162
|
-
pubkey: selfAuthority,
|
|
163
|
-
});
|
|
164
|
-
// program in HandleReceiveMessage accounts.
|
|
165
|
-
remainingAccounts.push({
|
|
166
|
-
isSigner: false,
|
|
167
|
-
isWritable: false,
|
|
168
|
-
pubkey: svmSpokeProgram.programId,
|
|
169
|
-
});
|
|
170
|
-
// payer
|
|
171
|
-
remainingAccounts.push({
|
|
172
|
-
isSigner: true,
|
|
173
|
-
isWritable: true,
|
|
174
|
-
pubkey: provider.wallet.publicKey,
|
|
175
|
-
});
|
|
176
|
-
// state in self-invoked CPIs (state can change as a result of remote call).
|
|
177
|
-
remainingAccounts.push({
|
|
178
|
-
isSigner: false,
|
|
179
|
-
isWritable: true,
|
|
180
|
-
pubkey: statePda,
|
|
181
|
-
});
|
|
182
|
-
// route
|
|
183
|
-
remainingAccounts.push({
|
|
184
|
-
isSigner: false,
|
|
185
|
-
isWritable: true,
|
|
186
|
-
pubkey: routePda,
|
|
187
|
-
});
|
|
188
|
-
// vault
|
|
189
|
-
remainingAccounts.push({
|
|
190
|
-
isSigner: false,
|
|
191
|
-
isWritable: true,
|
|
192
|
-
pubkey: vault,
|
|
193
|
-
});
|
|
194
|
-
// origin token mint
|
|
195
|
-
remainingAccounts.push({
|
|
196
|
-
isSigner: false,
|
|
197
|
-
isWritable: true,
|
|
198
|
-
pubkey: originToken,
|
|
199
|
-
});
|
|
200
|
-
// token_program
|
|
201
|
-
remainingAccounts.push({
|
|
202
|
-
isSigner: false,
|
|
203
|
-
isWritable: true,
|
|
204
|
-
pubkey: spl_token_1.TOKEN_PROGRAM_ID,
|
|
205
|
-
});
|
|
206
|
-
// associated_token_program
|
|
207
|
-
remainingAccounts.push({
|
|
208
|
-
isSigner: false,
|
|
209
|
-
isWritable: true,
|
|
210
|
-
pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
211
|
-
});
|
|
212
|
-
// system_program
|
|
213
|
-
remainingAccounts.push({
|
|
214
|
-
isSigner: false,
|
|
215
|
-
isWritable: true,
|
|
216
|
-
pubkey: web3_js_1.SystemProgram.programId,
|
|
217
|
-
});
|
|
218
|
-
// event_authority in self-invoked CPIs (appended by Anchor with event_cpi macro).
|
|
219
|
-
remainingAccounts.push({
|
|
220
|
-
isSigner: false,
|
|
221
|
-
isWritable: true,
|
|
222
|
-
pubkey: eventAuthority,
|
|
223
|
-
});
|
|
224
|
-
// program
|
|
225
|
-
remainingAccounts.push({
|
|
226
|
-
isSigner: false,
|
|
227
|
-
isWritable: true,
|
|
228
|
-
pubkey: svmSpokeProgram.programId,
|
|
229
|
-
});
|
|
230
|
-
// Receive remote message on Solana.
|
|
231
|
-
console.log("Receiving message on Solana...");
|
|
232
|
-
const receiveMessageTx = await messageTransmitterProgram.methods
|
|
233
|
-
.receiveMessage({
|
|
234
|
-
message: Buffer.from(message.replace("0x", ""), "hex"),
|
|
235
|
-
attestation: Buffer.from(attestation.replace("0x", ""), "hex"),
|
|
236
|
-
})
|
|
237
|
-
.accounts(receiveMessageAccounts)
|
|
238
|
-
.remainingAccounts(remainingAccounts)
|
|
239
|
-
.rpc();
|
|
240
|
-
console.log("\nReceived remote message");
|
|
241
|
-
console.log("Your transaction signature", receiveMessageTx);
|
|
242
|
-
let routeAccount = await svmSpokeProgram.account.route.fetch(routePda);
|
|
243
|
-
console.log("Updated deposit route state to: enabled =", routeAccount.enabled);
|
|
244
|
-
}
|
|
245
|
-
remoteHubPoolSetDepositRoute()
|
|
246
|
-
.then(() => {
|
|
247
|
-
process.exit(0);
|
|
248
|
-
})
|
|
249
|
-
.catch((err) => {
|
|
250
|
-
console.error(err);
|
|
251
|
-
process.exit(1);
|
|
252
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was AUTOGENERATED using the codama library.
|
|
3
|
-
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
-
* to add features, then rerun codama to update it.
|
|
5
|
-
*
|
|
6
|
-
* @see https://github.com/codama-idl/codama
|
|
7
|
-
*/
|
|
8
|
-
import { fetchEncodedAccount, fetchEncodedAccounts, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
|
|
9
|
-
export declare const ROUTE_DISCRIMINATOR: Uint8Array;
|
|
10
|
-
export declare function getRouteDiscriminatorBytes(): ReadonlyUint8Array;
|
|
11
|
-
export type Route = {
|
|
12
|
-
discriminator: ReadonlyUint8Array;
|
|
13
|
-
enabled: boolean;
|
|
14
|
-
};
|
|
15
|
-
export type RouteArgs = {
|
|
16
|
-
enabled: boolean;
|
|
17
|
-
};
|
|
18
|
-
export declare function getRouteEncoder(): Encoder<RouteArgs>;
|
|
19
|
-
export declare function getRouteDecoder(): Decoder<Route>;
|
|
20
|
-
export declare function getRouteCodec(): Codec<RouteArgs, Route>;
|
|
21
|
-
export declare function decodeRoute<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<Route, TAddress>;
|
|
22
|
-
export declare function decodeRoute<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<Route, TAddress>;
|
|
23
|
-
export declare function fetchRoute<TAddress extends string = string>(rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig): Promise<Account<Route, TAddress>>;
|
|
24
|
-
export declare function fetchMaybeRoute<TAddress extends string = string>(rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig): Promise<MaybeAccount<Route, TAddress>>;
|
|
25
|
-
export declare function fetchAllRoute(rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig): Promise<Account<Route>[]>;
|
|
26
|
-
export declare function fetchAllMaybeRoute(rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig): Promise<MaybeAccount<Route>[]>;
|
|
27
|
-
export declare function getRouteSize(): number;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This code was AUTOGENERATED using the codama library.
|
|
4
|
-
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
5
|
-
* to add features, then rerun codama to update it.
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/codama-idl/codama
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ROUTE_DISCRIMINATOR = void 0;
|
|
11
|
-
exports.getRouteDiscriminatorBytes = getRouteDiscriminatorBytes;
|
|
12
|
-
exports.getRouteEncoder = getRouteEncoder;
|
|
13
|
-
exports.getRouteDecoder = getRouteDecoder;
|
|
14
|
-
exports.getRouteCodec = getRouteCodec;
|
|
15
|
-
exports.decodeRoute = decodeRoute;
|
|
16
|
-
exports.fetchRoute = fetchRoute;
|
|
17
|
-
exports.fetchMaybeRoute = fetchMaybeRoute;
|
|
18
|
-
exports.fetchAllRoute = fetchAllRoute;
|
|
19
|
-
exports.fetchAllMaybeRoute = fetchAllMaybeRoute;
|
|
20
|
-
exports.getRouteSize = getRouteSize;
|
|
21
|
-
const kit_1 = require("@solana/kit");
|
|
22
|
-
exports.ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
23
|
-
80, 179, 58, 115, 52, 19, 146, 134,
|
|
24
|
-
]);
|
|
25
|
-
function getRouteDiscriminatorBytes() {
|
|
26
|
-
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ROUTE_DISCRIMINATOR);
|
|
27
|
-
}
|
|
28
|
-
function getRouteEncoder() {
|
|
29
|
-
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
|
|
30
|
-
['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
|
|
31
|
-
['enabled', (0, kit_1.getBooleanEncoder)()],
|
|
32
|
-
]), (value) => ({ ...value, discriminator: exports.ROUTE_DISCRIMINATOR }));
|
|
33
|
-
}
|
|
34
|
-
function getRouteDecoder() {
|
|
35
|
-
return (0, kit_1.getStructDecoder)([
|
|
36
|
-
['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
|
|
37
|
-
['enabled', (0, kit_1.getBooleanDecoder)()],
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
|
-
function getRouteCodec() {
|
|
41
|
-
return (0, kit_1.combineCodec)(getRouteEncoder(), getRouteDecoder());
|
|
42
|
-
}
|
|
43
|
-
function decodeRoute(encodedAccount) {
|
|
44
|
-
return (0, kit_1.decodeAccount)(encodedAccount, getRouteDecoder());
|
|
45
|
-
}
|
|
46
|
-
async function fetchRoute(rpc, address, config) {
|
|
47
|
-
const maybeAccount = await fetchMaybeRoute(rpc, address, config);
|
|
48
|
-
(0, kit_1.assertAccountExists)(maybeAccount);
|
|
49
|
-
return maybeAccount;
|
|
50
|
-
}
|
|
51
|
-
async function fetchMaybeRoute(rpc, address, config) {
|
|
52
|
-
const maybeAccount = await (0, kit_1.fetchEncodedAccount)(rpc, address, config);
|
|
53
|
-
return decodeRoute(maybeAccount);
|
|
54
|
-
}
|
|
55
|
-
async function fetchAllRoute(rpc, addresses, config) {
|
|
56
|
-
const maybeAccounts = await fetchAllMaybeRoute(rpc, addresses, config);
|
|
57
|
-
(0, kit_1.assertAccountsExist)(maybeAccounts);
|
|
58
|
-
return maybeAccounts;
|
|
59
|
-
}
|
|
60
|
-
async function fetchAllMaybeRoute(rpc, addresses, config) {
|
|
61
|
-
const maybeAccounts = await (0, kit_1.fetchEncodedAccounts)(rpc, addresses, config);
|
|
62
|
-
return maybeAccounts.map((maybeAccount) => decodeRoute(maybeAccount));
|
|
63
|
-
}
|
|
64
|
-
function getRouteSize() {
|
|
65
|
-
return 9;
|
|
66
|
-
}
|