@across-protocol/contracts 3.0.17 → 3.0.19
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 +2 -0
- package/artifacts/build-info/9cb910e5bb5dd730cd01af84a0fb0466.json +1 -0
- package/artifacts/contracts/Ink_SpokePool.sol/Ink_SpokePool.dbg.json +4 -0
- package/artifacts/contracts/Ink_SpokePool.sol/Ink_SpokePool.json +2316 -0
- package/contracts/Ink_SpokePool.sol +72 -0
- package/dist/deploy/consts.js +8 -2
- package/dist/deployments/deployments.json +7 -1
- package/dist/hardhat.config.js +17 -0
- package/dist/scripts/svm/addressToPublicKey.d.ts +1 -0
- package/dist/scripts/svm/addressToPublicKey.js +20 -0
- package/dist/scripts/svm/bridgeLiabilityToHubPool.d.ts +25 -0
- package/dist/scripts/svm/bridgeLiabilityToHubPool.js +221 -0
- package/dist/scripts/svm/closeRelayerPdas.js +8 -9
- package/dist/scripts/svm/enableRoute.js +7 -1
- package/dist/scripts/svm/executeRebalanceToHubPool.d.ts +29 -0
- package/dist/scripts/svm/executeRebalanceToHubPool.js +345 -0
- package/dist/scripts/svm/executeRebalanceToSpokePool.d.ts +1 -0
- package/dist/scripts/svm/executeRebalanceToSpokePool.js +240 -0
- package/dist/scripts/svm/fakeFillWithRandomDistribution.js +6 -7
- package/dist/scripts/svm/initialize.js +2 -2
- package/dist/scripts/svm/proposeRebalanceToHubPool.d.ts +27 -0
- package/dist/scripts/svm/proposeRebalanceToHubPool.js +117 -0
- package/dist/scripts/svm/proposeRebalanceToSpokePool.d.ts +1 -0
- package/dist/scripts/svm/proposeRebalanceToSpokePool.js +97 -0
- package/dist/scripts/svm/publicKeyToAddress.d.ts +1 -0
- package/dist/scripts/svm/publicKeyToAddress.js +20 -0
- package/dist/scripts/svm/queryDeposits.js +3 -2
- package/dist/scripts/svm/queryFills.js +12 -14
- package/dist/scripts/svm/queryRoute.js +7 -1
- package/dist/scripts/svm/queryState.js +1 -0
- package/dist/scripts/svm/remoteHubPoolPauseDeposits.d.ts +1 -0
- package/dist/scripts/svm/remoteHubPoolPauseDeposits.js +191 -0
- package/dist/scripts/svm/remoteHubPoolSetDepositRoute.js +16 -29
- package/dist/scripts/svm/remotePauseDeposits.js +21 -27
- package/dist/scripts/svm/simpleDeposit.js +7 -1
- package/dist/scripts/svm/simpleFakeRelayerRepayment.js +3 -3
- package/dist/scripts/svm/simpleFill.js +6 -6
- package/dist/scripts/svm/utils/constants.d.ts +4 -0
- package/dist/scripts/svm/utils/constants.js +8 -1
- package/dist/scripts/svm/utils/helpers.d.ts +33 -0
- package/dist/scripts/svm/utils/helpers.js +60 -1
- package/dist/scripts/svm/utils/poolRebalanceTree.d.ts +22 -0
- package/dist/scripts/svm/utils/poolRebalanceTree.js +20 -0
- package/dist/src/svm/coders.d.ts +37 -0
- package/dist/src/svm/coders.js +250 -0
- package/dist/src/svm/conversionUtils.d.ts +22 -0
- package/dist/src/svm/conversionUtils.js +73 -0
- package/dist/src/svm/index.d.ts +6 -0
- package/dist/src/svm/index.js +22 -0
- package/dist/src/svm/instructionParamsUtils.d.ts +31 -0
- package/dist/src/svm/instructionParamsUtils.js +128 -0
- package/dist/src/svm/relayHashUtils.d.ts +30 -0
- package/dist/src/svm/relayHashUtils.js +209 -0
- package/dist/src/svm/solanaProgramUtils.d.ts +38 -0
- package/dist/src/svm/solanaProgramUtils.js +147 -0
- package/dist/src/svm/transactionUtils.d.ts +8 -0
- package/dist/src/svm/transactionUtils.js +55 -0
- package/dist/src/types/svm.d.ts +118 -0
- package/dist/src/types/svm.js +2 -0
- package/dist/target/types/svm_spoke.d.ts +47 -42
- package/dist/tasks/enableL1TokenAcrossEcosystem.js +3 -33
- package/dist/tasks/types.d.ts +2 -0
- package/dist/tasks/types.js +2 -0
- package/dist/tasks/utils.d.ts +12 -0
- package/dist/tasks/utils.js +34 -0
- package/dist/test/svm/MulticallHandler.js +2 -2
- package/dist/test/svm/SvmSpoke.Bundle.js +59 -60
- package/dist/test/svm/SvmSpoke.Deposit.js +23 -31
- package/dist/test/svm/SvmSpoke.Fill.AcrossPlus.js +16 -18
- package/dist/test/svm/SvmSpoke.Fill.js +38 -40
- package/dist/test/svm/SvmSpoke.HandleReceiveMessage.js +2 -2
- package/dist/test/svm/SvmSpoke.Ownership.js +11 -17
- package/dist/test/svm/SvmSpoke.RefundClaims.js +12 -11
- package/dist/test/svm/SvmSpoke.Routes.js +11 -7
- package/dist/test/svm/SvmSpoke.SlowFill.AcrossPlus.js +72 -16
- package/dist/test/svm/SvmSpoke.SlowFill.js +33 -28
- package/dist/test/svm/SvmSpoke.TokenBridge.js +15 -17
- package/dist/test/svm/SvmSpoke.common.d.ts +1 -49
- package/dist/test/svm/SvmSpoke.common.js +6 -5
- package/dist/test/svm/cctpHelpers.js +2 -2
- package/dist/test/svm/utils.d.ts +5 -67
- package/dist/test/svm/utils.js +10 -220
- package/dist/typechain/contracts/Ink_SpokePool.d.ts +1251 -0
- package/dist/typechain/contracts/Ink_SpokePool.js +2 -0
- package/dist/typechain/contracts/index.d.ts +1 -0
- package/dist/typechain/factories/contracts/Ink_SpokePool__factory.d.ts +1833 -0
- package/dist/typechain/factories/contracts/Ink_SpokePool__factory.js +2347 -0
- package/dist/typechain/factories/contracts/index.d.ts +1 -0
- package/dist/typechain/factories/contracts/index.js +3 -1
- package/dist/typechain/hardhat.d.ts +9 -0
- package/dist/typechain/index.d.ts +2 -0
- package/dist/typechain/index.js +5 -3
- package/package.json +2 -2
- package/dist/src/SvmUtils.d.ts +0 -50
- package/dist/src/SvmUtils.js +0 -415
|
@@ -29,11 +29,10 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
29
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
30
30
|
const web3_js_1 = require("@solana/web3.js");
|
|
31
31
|
const MerkleTree_1 = require("@uma/common/dist/MerkleTree");
|
|
32
|
-
const
|
|
32
|
+
const svm_1 = require("../../src/svm");
|
|
33
33
|
const SvmSpoke_common_1 = require("./SvmSpoke.common");
|
|
34
|
-
const
|
|
35
|
-
const {
|
|
36
|
-
const { initializeState, assertSE } = SvmSpoke_common_1.common;
|
|
34
|
+
const { provider, connection, program, owner, chainId, setCurrentTime } = SvmSpoke_common_1.common;
|
|
35
|
+
const { initializeState, assertSE, assert } = SvmSpoke_common_1.common;
|
|
37
36
|
describe("svm_spoke.slow_fill.across_plus", () => {
|
|
38
37
|
anchor.setProvider(provider);
|
|
39
38
|
const payer = anchor.AnchorProvider.env().wallet.payer;
|
|
@@ -48,7 +47,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
48
47
|
const seedBalance = 10_000_000_000;
|
|
49
48
|
async function updateRelayData(newRelayData) {
|
|
50
49
|
relayData = newRelayData;
|
|
51
|
-
const relayHashUint8Array = (0,
|
|
50
|
+
const relayHashUint8Array = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
52
51
|
const [fillStatusPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
|
|
53
52
|
// Accounts for requestingSlowFill.
|
|
54
53
|
requestAccounts = {
|
|
@@ -75,7 +74,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
75
74
|
updatedOutputAmount: relayData.outputAmount,
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
|
-
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs,
|
|
77
|
+
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs, svm_1.slowFillHashFn);
|
|
79
78
|
const slowRelayRoot = merkleTree.getRoot();
|
|
80
79
|
const proof = merkleTree.getProof(slowRelayLeafs[0]);
|
|
81
80
|
const leaf = slowRelayLeafs[0];
|
|
@@ -93,7 +92,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
93
92
|
.accounts(relayRootBundleAccounts)
|
|
94
93
|
.rpc();
|
|
95
94
|
const proofAsNumbers = proof.map((p) => Array.from(p));
|
|
96
|
-
const relayHash = (0,
|
|
95
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(slowRelayLeaf.relayData, chainId);
|
|
97
96
|
return { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle };
|
|
98
97
|
};
|
|
99
98
|
const createSlowFillIx = async (multicallHandlerCoder, bufferParams = false) => {
|
|
@@ -102,7 +101,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
102
101
|
const requestV3SlowFillValues = [Array.from(relayHash), leaf.relayData];
|
|
103
102
|
let loadRequestParamsInstructions = [];
|
|
104
103
|
if (bufferParams) {
|
|
105
|
-
loadRequestParamsInstructions = await (0,
|
|
104
|
+
loadRequestParamsInstructions = await (0, svm_1.loadRequestV3SlowFillParams)(program, relayer, requestV3SlowFillValues[1]);
|
|
106
105
|
[requestAccounts.instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), relayer.publicKey.toBuffer()], program.programId);
|
|
107
106
|
}
|
|
108
107
|
const requestV3SlowFillParams = bufferParams
|
|
@@ -136,7 +135,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
136
135
|
];
|
|
137
136
|
let loadExecuteParamsInstructions = [];
|
|
138
137
|
if (bufferParams) {
|
|
139
|
-
loadExecuteParamsInstructions = await (0,
|
|
138
|
+
loadExecuteParamsInstructions = await (0, svm_1.loadExecuteV3SlowRelayLeafParams)(program, relayer, executeV3SlowRelayLeafValues[1], executeV3SlowRelayLeafValues[2], executeV3SlowRelayLeafValues[3]);
|
|
140
139
|
[requestAccounts.instructionParams] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("instruction_params"), relayer.publicKey.toBuffer()], program.programId);
|
|
141
140
|
}
|
|
142
141
|
const executeV3SlowRelayLeafParams = bufferParams
|
|
@@ -171,7 +170,7 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
171
170
|
inputAmount: new anchor_1.BN(relayAmount),
|
|
172
171
|
outputAmount: new anchor_1.BN(relayAmount),
|
|
173
172
|
originChainId: new anchor_1.BN(1),
|
|
174
|
-
depositId: (0,
|
|
173
|
+
depositId: (0, svm_1.intToU8Array32)(Math.floor(Math.random() * 1000000)), // Unique ID for each test.
|
|
175
174
|
fillDeadline: Math.floor(Date.now() / 1000) + 60, // 1 minute from now
|
|
176
175
|
exclusivityDeadline: Math.floor(Date.now() / 1000) - 30, // Note we set time in past to avoid exclusivity deadline
|
|
177
176
|
message: Buffer.from(""), // Will be populated in the tests below.
|
|
@@ -182,9 +181,9 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
182
181
|
const iVaultBal = (await (0, spl_token_1.getAccount)(connection, vault)).amount;
|
|
183
182
|
// Construct ix to transfer all tokens from handler to the final recipient.
|
|
184
183
|
const transferIx = (0, spl_token_1.createTransferCheckedInstruction)(handlerATA, mint, finalRecipientATA, handlerSigner, relayData.outputAmount.toNumber(), tokenDecimals);
|
|
185
|
-
const multicallHandlerCoder = new
|
|
184
|
+
const multicallHandlerCoder = new svm_1.MulticallHandlerCoder([transferIx]);
|
|
186
185
|
const handlerMessage = multicallHandlerCoder.encode();
|
|
187
|
-
const message = new
|
|
186
|
+
const message = new svm_1.AcrossPlusMessageCoder({
|
|
188
187
|
handler: handlerProgram.programId,
|
|
189
188
|
readOnlyLen: multicallHandlerCoder.readOnlyLen,
|
|
190
189
|
valueAmount: new anchor_1.BN(0),
|
|
@@ -220,9 +219,9 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
220
219
|
const transferInstruction = (0, spl_token_1.createTransferCheckedInstruction)(handlerATA, mint, recipientATA, handlerSigner, distributionAmount, tokenDecimals);
|
|
221
220
|
transferInstructions.push(transferInstruction);
|
|
222
221
|
}
|
|
223
|
-
const multicallHandlerCoder = new
|
|
222
|
+
const multicallHandlerCoder = new svm_1.MulticallHandlerCoder(transferInstructions);
|
|
224
223
|
const handlerMessage = multicallHandlerCoder.encode();
|
|
225
|
-
const message = new
|
|
224
|
+
const message = new svm_1.AcrossPlusMessageCoder({
|
|
226
225
|
handler: handlerProgram.programId,
|
|
227
226
|
readOnlyLen: multicallHandlerCoder.readOnlyLen,
|
|
228
227
|
valueAmount: new anchor_1.BN(0),
|
|
@@ -247,14 +246,14 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
247
246
|
await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadRequestParamsInstructions[i]), [relayer]);
|
|
248
247
|
}
|
|
249
248
|
}
|
|
250
|
-
await (0,
|
|
249
|
+
await (0, svm_1.sendTransactionWithLookupTable)(connection, [computeBudgetIx, requestIx], relayer);
|
|
251
250
|
await new Promise((resolve) => setTimeout(resolve, 1000)); // Make sure request tx gets processed.
|
|
252
251
|
if (bufferParams) {
|
|
253
252
|
for (let i = 0; i < loadExecuteParamsInstructions.length; i += 1) {
|
|
254
253
|
await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadExecuteParamsInstructions[i]), [relayer]);
|
|
255
254
|
}
|
|
256
255
|
}
|
|
257
|
-
await (0,
|
|
256
|
+
await (0, svm_1.sendTransactionWithLookupTable)(connection, [computeBudgetIx, executeIx], relayer);
|
|
258
257
|
// Verify vault's balance after the fill
|
|
259
258
|
await new Promise((resolve) => setTimeout(resolve, 1000)); // Make sure token transfers get processed.
|
|
260
259
|
const fVaultBal = (await (0, spl_token_1.getAccount)(connection, vault)).amount;
|
|
@@ -277,4 +276,61 @@ describe("svm_spoke.slow_fill.across_plus", () => {
|
|
|
277
276
|
await fillTokenDistributions(numberOfDistributions, true);
|
|
278
277
|
});
|
|
279
278
|
});
|
|
279
|
+
it("Can recover and close fill status PDA from event data", async () => {
|
|
280
|
+
// Construct ix to transfer all tokens from handler to the final recipient.
|
|
281
|
+
const transferIx = (0, spl_token_1.createTransferCheckedInstruction)(handlerATA, mint, finalRecipientATA, handlerSigner, relayData.outputAmount.toNumber(), tokenDecimals);
|
|
282
|
+
const multicallHandlerCoder = new svm_1.MulticallHandlerCoder([transferIx]);
|
|
283
|
+
const handlerMessage = multicallHandlerCoder.encode();
|
|
284
|
+
const message = new svm_1.AcrossPlusMessageCoder({
|
|
285
|
+
handler: handlerProgram.programId,
|
|
286
|
+
readOnlyLen: multicallHandlerCoder.readOnlyLen,
|
|
287
|
+
valueAmount: new anchor_1.BN(0),
|
|
288
|
+
accounts: multicallHandlerCoder.compiledMessage.accountKeys,
|
|
289
|
+
handlerMessage,
|
|
290
|
+
});
|
|
291
|
+
const encodedMessage = message.encode();
|
|
292
|
+
// Update relay data with the encoded message.
|
|
293
|
+
const newRelayData = { ...relayData, message: encodedMessage };
|
|
294
|
+
updateRelayData(newRelayData);
|
|
295
|
+
// Prepare request and execute slow fill instructions as we will need to use Address Lookup Table (ALT).
|
|
296
|
+
// Request and execute slow fill.
|
|
297
|
+
const { loadRequestParamsInstructions, requestIx, loadExecuteParamsInstructions, executeIx } = await createSlowFillIx(multicallHandlerCoder, true);
|
|
298
|
+
// Fill using the ALT and submit load params transactions.
|
|
299
|
+
for (let i = 0; i < loadRequestParamsInstructions.length; i += 1) {
|
|
300
|
+
await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadRequestParamsInstructions[i]), [relayer]);
|
|
301
|
+
}
|
|
302
|
+
await (0, svm_1.sendTransactionWithLookupTable)(connection, [requestIx], relayer);
|
|
303
|
+
await new Promise((resolve) => setTimeout(resolve, 1000)); // Make sure request tx gets processed.
|
|
304
|
+
for (let i = 0; i < loadExecuteParamsInstructions.length; i += 1) {
|
|
305
|
+
await (0, web3_js_1.sendAndConfirmTransaction)(program.provider.connection, new web3_js_1.Transaction().add(loadExecuteParamsInstructions[i]), [relayer]);
|
|
306
|
+
}
|
|
307
|
+
const { txSignature } = await (0, svm_1.sendTransactionWithLookupTable)(connection, [executeIx], relayer);
|
|
308
|
+
await connection.confirmTransaction(txSignature, "confirmed");
|
|
309
|
+
await connection.getTransaction(txSignature, {
|
|
310
|
+
commitment: "confirmed",
|
|
311
|
+
maxSupportedTransactionVersion: 0,
|
|
312
|
+
});
|
|
313
|
+
// We don't close ALT here as that would require ~4 minutes between deactivation and closing, but we demonstrate
|
|
314
|
+
// being able to close the fill status PDA using only event data.
|
|
315
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, txSignature, [program]);
|
|
316
|
+
const eventData = events.find((event) => event.name === "filledV3Relay")?.data;
|
|
317
|
+
assert.isNotNull(eventData, "FilledV3Relay event should be emitted");
|
|
318
|
+
// Recover relay hash and derived fill status from event data.
|
|
319
|
+
const relayHashUint8Array = (0, svm_1.calculateRelayEventHashUint8Array)(eventData, chainId);
|
|
320
|
+
const [fillStatusPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
|
|
321
|
+
const fillStatusAccount = await program.account.fillStatusAccount.fetch(fillStatusPDA);
|
|
322
|
+
assert.isTrue("filled" in fillStatusAccount.status, "Fill status account should be marked as filled");
|
|
323
|
+
assertSE(fillStatusAccount.relayer, relayer.publicKey, "Relayer should match in the fill status");
|
|
324
|
+
// Set the current time to past the fill deadline
|
|
325
|
+
await setCurrentTime(program, state, relayer, new anchor_1.BN(fillStatusAccount.fillDeadline + 1));
|
|
326
|
+
const closeFillPdaAccounts = {
|
|
327
|
+
signer: relayer.publicKey,
|
|
328
|
+
state,
|
|
329
|
+
fillStatus: fillStatusPDA,
|
|
330
|
+
};
|
|
331
|
+
await program.methods.closeFillPda().accounts(closeFillPdaAccounts).signers([relayer]).rpc();
|
|
332
|
+
// Verify the fill PDA is closed
|
|
333
|
+
const fillStatusAccountAfter = await connection.getAccountInfo(fillStatusPDA);
|
|
334
|
+
assert.isNull(fillStatusAccountAfter, "Fill PDA should be closed after closing");
|
|
335
|
+
});
|
|
280
336
|
});
|
|
@@ -30,6 +30,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
|
30
30
|
const web3_js_1 = require("@solana/web3.js");
|
|
31
31
|
const SvmSpoke_common_1 = require("./SvmSpoke.common");
|
|
32
32
|
const MerkleTree_1 = require("@uma/common/dist/MerkleTree");
|
|
33
|
+
const svm_1 = require("../../src/svm");
|
|
33
34
|
const utils_1 = require("./utils");
|
|
34
35
|
const { provider, connection, program, owner, chainId, seedBalance, initializeState } = SvmSpoke_common_1.common;
|
|
35
36
|
const { recipient, setCurrentTime, assertSE, assert } = SvmSpoke_common_1.common;
|
|
@@ -48,7 +49,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
48
49
|
const initialMintAmount = 10_000_000_000;
|
|
49
50
|
async function updateRelayData(newRelayData) {
|
|
50
51
|
relayData = newRelayData;
|
|
51
|
-
const relayHashUint8Array = (0,
|
|
52
|
+
const relayHashUint8Array = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
52
53
|
[fillStatus] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
|
|
53
54
|
// recipientTA could be different for each relayData if custom recipient was passed.
|
|
54
55
|
recipientTA = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, mint, relayData.recipient)).address;
|
|
@@ -88,7 +89,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
88
89
|
inputAmount: new anchor_1.BN(relayAmount),
|
|
89
90
|
outputAmount: new anchor_1.BN(relayAmount),
|
|
90
91
|
originChainId: new anchor_1.BN(1),
|
|
91
|
-
depositId: (0,
|
|
92
|
+
depositId: (0, svm_1.intToU8Array32)(Math.floor(Math.random() * 1000000)), // Unique ID for each test.
|
|
92
93
|
fillDeadline: Math.floor(Date.now() / 1000) + 60, // 1 minute from now
|
|
93
94
|
exclusivityDeadline: Math.floor(Date.now() / 1000) - 30, // Note we set time in past to avoid exclusivity deadline
|
|
94
95
|
message,
|
|
@@ -98,7 +99,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
98
99
|
};
|
|
99
100
|
await updateRelayData(slowRelayLeaf.relayData);
|
|
100
101
|
slowRelayLeafs.push(slowRelayLeaf);
|
|
101
|
-
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs,
|
|
102
|
+
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs, svm_1.slowFillHashFn);
|
|
102
103
|
const slowRelayRoot = merkleTree.getRoot();
|
|
103
104
|
const proof = merkleTree.getProof(slowRelayLeafs[0]);
|
|
104
105
|
const leaf = slowRelayLeafs[0];
|
|
@@ -116,7 +117,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
116
117
|
.accounts(relayRootBundleAccounts)
|
|
117
118
|
.rpc();
|
|
118
119
|
const proofAsNumbers = proof.map((p) => Array.from(p));
|
|
119
|
-
const relayHash = (0,
|
|
120
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(slowRelayLeaf.relayData, chainId);
|
|
120
121
|
return { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle };
|
|
121
122
|
};
|
|
122
123
|
before("Creates token mint and associated token accounts", async () => {
|
|
@@ -144,7 +145,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
144
145
|
inputAmount: new anchor_1.BN(relayAmount),
|
|
145
146
|
outputAmount: new anchor_1.BN(relayAmount),
|
|
146
147
|
originChainId: new anchor_1.BN(1),
|
|
147
|
-
depositId: (0,
|
|
148
|
+
depositId: (0, svm_1.intToU8Array32)(1),
|
|
148
149
|
fillDeadline: Math.floor(Date.now() / 1000) + 60, // 1 minute from now
|
|
149
150
|
exclusivityDeadline: Math.floor(Date.now() / 1000) + 30, // 30 seconds from now
|
|
150
151
|
message: encodedMessage,
|
|
@@ -153,7 +154,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
153
154
|
});
|
|
154
155
|
it("Requests a V3 slow fill, verify the event & state change", async () => {
|
|
155
156
|
// Attempt to request a slow fill before the exclusivityDeadline
|
|
156
|
-
const relayHash = Array.from((0,
|
|
157
|
+
const relayHash = Array.from((0, svm_1.calculateRelayHashUint8Array)(relayData, chainId));
|
|
157
158
|
try {
|
|
158
159
|
await program.methods.requestV3SlowFill(relayHash, relayData).accounts(requestAccounts).signers([relayer]).rpc();
|
|
159
160
|
assert.fail("Request should have failed due to exclusivity deadline not passed");
|
|
@@ -163,23 +164,26 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
163
164
|
}
|
|
164
165
|
// Set the contract time to be after the exclusivityDeadline
|
|
165
166
|
await setCurrentTime(program, state, relayer, new anchor_1.BN(relayData.exclusivityDeadline + 1));
|
|
166
|
-
await program.methods
|
|
167
|
+
const tx = await program.methods
|
|
168
|
+
.requestV3SlowFill(relayHash, relayData)
|
|
169
|
+
.accounts(requestAccounts)
|
|
170
|
+
.signers([relayer])
|
|
171
|
+
.rpc();
|
|
167
172
|
// Fetch and verify the RequestedV3SlowFill event
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
const event = events.find((event) => event.name === "requestedV3SlowFill").data;
|
|
173
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
174
|
+
const event = events.find((event) => event.name === "requestedV3SlowFill")?.data;
|
|
171
175
|
assert.isNotNull(event, "RequestedV3SlowFill event should be emitted");
|
|
172
176
|
// Verify that the event data matches the relay data.
|
|
173
177
|
Object.entries(relayData).forEach(([key, value]) => {
|
|
174
178
|
if (key === "message") {
|
|
175
|
-
assertSE(event.messageHash, (0,
|
|
179
|
+
assertSE(event.messageHash, (0, svm_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
176
180
|
}
|
|
177
181
|
else
|
|
178
182
|
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
|
|
179
183
|
});
|
|
180
184
|
});
|
|
181
185
|
it("Fails to request a V3 slow fill if the relay has already been filled", async () => {
|
|
182
|
-
const relayHash = Array.from((0,
|
|
186
|
+
const relayHash = Array.from((0, svm_1.calculateRelayHashUint8Array)(relayData, chainId));
|
|
183
187
|
// Fill the relay first
|
|
184
188
|
const approveIx = await (0, spl_token_1.createApproveCheckedInstruction)(fillAccounts.relayerTokenAccount, fillAccounts.mint, fillAccounts.state, fillAccounts.signer, BigInt(relayData.outputAmount.toString()), tokenDecimals);
|
|
185
189
|
const fillIx = await program.methods
|
|
@@ -208,7 +212,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
208
212
|
}
|
|
209
213
|
});
|
|
210
214
|
it("Fetches FillStatusAccount before and after requestV3SlowFill", async () => {
|
|
211
|
-
const relayHash = (0,
|
|
215
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
212
216
|
const [fillStatusPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHash], program.programId);
|
|
213
217
|
// Fetch FillStatusAccount before requestV3SlowFill
|
|
214
218
|
let fillStatusAccount = await program.account.fillStatusAccount.fetchNullable(fillStatusPDA);
|
|
@@ -228,7 +232,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
228
232
|
assert.equal(fillStatusAccount.relayer.toString(), relayer.publicKey.toString(), "Caller should be set as relayer");
|
|
229
233
|
});
|
|
230
234
|
it("Fails to request a V3 slow fill multiple times for the same fill", async () => {
|
|
231
|
-
const relayHash = (0,
|
|
235
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
232
236
|
// Set the contract time to be after the exclusivityDeadline
|
|
233
237
|
await setCurrentTime(program, state, relayer, new anchor_1.BN(relayData.exclusivityDeadline + 1));
|
|
234
238
|
// Request a slow fill
|
|
@@ -293,28 +297,29 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
293
297
|
.remainingAccounts(fillRemainingAccounts)
|
|
294
298
|
.instruction();
|
|
295
299
|
const computeBudgetInstruction = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 });
|
|
296
|
-
await (0, web3_js_1.sendAndConfirmTransaction)(connection, new web3_js_1.Transaction().add(computeBudgetInstruction, ix), [
|
|
300
|
+
const tx = await (0, web3_js_1.sendAndConfirmTransaction)(connection, new web3_js_1.Transaction().add(computeBudgetInstruction, ix), [
|
|
301
|
+
payer,
|
|
302
|
+
]);
|
|
297
303
|
// Verify the results
|
|
298
304
|
const fVaultBal = (await connection.getTokenAccountBalance(vault)).value.amount;
|
|
299
305
|
const fRecipientBal = (await connection.getTokenAccountBalance(recipientTA)).value.amount;
|
|
300
306
|
assert.strictEqual(BigInt(iVaultBal) - BigInt(fVaultBal), BigInt(leaf.updatedOutputAmount.toNumber()), "Vault balance should be reduced by relay amount");
|
|
301
307
|
assert.strictEqual(BigInt(fRecipientBal) - BigInt(iRecipientBal), BigInt(leaf.updatedOutputAmount.toNumber()), "Recipient balance should be increased by relay amount");
|
|
302
308
|
// Fetch and verify the FilledV3Relay event
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
const event = events.find((event) => event.name === "filledV3Relay").data;
|
|
309
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
310
|
+
const event = events.find((event) => event.name === "filledV3Relay")?.data;
|
|
306
311
|
assert.isNotNull(event, "FilledV3Relay event should be emitted");
|
|
307
312
|
// Verify that the event data matches the relay data.
|
|
308
313
|
Object.entries(relayData).forEach(([key, value]) => {
|
|
309
314
|
if (key === "message") {
|
|
310
|
-
assertSE(event.messageHash, (0,
|
|
315
|
+
assertSE(event.messageHash, (0, svm_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
311
316
|
}
|
|
312
317
|
else
|
|
313
318
|
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
|
|
314
319
|
});
|
|
315
320
|
// RelayExecutionInfo should match.
|
|
316
321
|
assertSE(event.relayExecutionInfo.updatedRecipient, relayData.recipient, "UpdatedRecipient should match");
|
|
317
|
-
assertSE(event.relayExecutionInfo.updatedMessageHash, (0,
|
|
322
|
+
assertSE(event.relayExecutionInfo.updatedMessageHash, (0, svm_1.hashNonEmptyMessage)(relayData.message), "UpdatedMessageHash should match");
|
|
318
323
|
assertSE(event.relayExecutionInfo.updatedOutputAmount, relayData.outputAmount, "UpdatedOutputAmount should match");
|
|
319
324
|
assert.equal(JSON.stringify(event.relayExecutionInfo.fillType), `{"slowFill":{}}`, "FillType should be SlowFill");
|
|
320
325
|
// These props below are not part of relayData.
|
|
@@ -333,7 +338,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
333
338
|
assert.isTrue(stateAccountData.pausedFills, "Fills should be paused");
|
|
334
339
|
// Attempt to request a slow fill. This should fail because fills are paused.
|
|
335
340
|
try {
|
|
336
|
-
const relayHash = (0,
|
|
341
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
337
342
|
await program.methods
|
|
338
343
|
.requestV3SlowFill(Array.from(relayHash), relayData)
|
|
339
344
|
.accounts(requestAccounts)
|
|
@@ -531,7 +536,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
531
536
|
// Relay root bundle of slow fill leaf with empty message.
|
|
532
537
|
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle(undefined, undefined, Buffer.alloc(0));
|
|
533
538
|
// Request V3 slow fill
|
|
534
|
-
await program.methods
|
|
539
|
+
const tx1 = await program.methods
|
|
535
540
|
.requestV3SlowFill(Array.from(relayHash), leaf.relayData)
|
|
536
541
|
.accounts(requestAccounts)
|
|
537
542
|
.signers([relayer])
|
|
@@ -549,19 +554,19 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
549
554
|
recipientTokenAccount: recipientTA,
|
|
550
555
|
program: program.programId,
|
|
551
556
|
};
|
|
552
|
-
await program.methods
|
|
557
|
+
const tx2 = await program.methods
|
|
553
558
|
.executeV3SlowRelayLeaf(Array.from(relayHash), leaf, rootBundleId, proofAsNumbers)
|
|
554
559
|
.accounts(executeSlowRelayLeafAccounts)
|
|
555
560
|
.remainingAccounts(fillRemainingAccounts)
|
|
556
561
|
.rpc();
|
|
557
562
|
// Fetch and verify message hash in the RequestedV3SlowFill and FilledV3Relay events
|
|
558
|
-
|
|
559
|
-
const
|
|
560
|
-
const requestEvent = events.find((event) => event.name === "requestedV3SlowFill").data;
|
|
561
|
-
const fillEvent = events.find((event) => event.name === "filledV3Relay").data;
|
|
563
|
+
const requestEvents = await (0, svm_1.readEventsUntilFound)(connection, tx1, [program]);
|
|
564
|
+
const requestEvent = requestEvents.find((event) => event.name === "requestedV3SlowFill")?.data;
|
|
562
565
|
assert.isNotNull(requestEvent, "RequestedV3SlowFill event should be emitted");
|
|
563
|
-
assert.isNotNull(fillEvent, "FilledV3Relay event should be emitted");
|
|
564
566
|
assertSE(requestEvent.messageHash, new Uint8Array(32), `MessageHash should be zeroed`);
|
|
567
|
+
const fillEvents = await (0, svm_1.readEventsUntilFound)(connection, tx2, [program]);
|
|
568
|
+
const fillEvent = fillEvents.find((event) => event.name === "filledV3Relay")?.data;
|
|
569
|
+
assert.isNotNull(fillEvent, "FilledV3Relay event should be emitted");
|
|
565
570
|
assertSE(fillEvent.messageHash, new Uint8Array(32), `MessageHash should be zeroed`);
|
|
566
571
|
assertSE(fillEvent.relayExecutionInfo.updatedMessageHash, new Uint8Array(32), `UpdatedMessageHash should be zeroed`);
|
|
567
572
|
});
|
|
@@ -29,9 +29,9 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
29
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
30
30
|
const MerkleTree_1 = require("@uma/common/dist/MerkleTree");
|
|
31
31
|
const SvmSpoke_common_1 = require("./SvmSpoke.common");
|
|
32
|
-
const utils_1 = require("./utils");
|
|
33
32
|
const chai_1 = require("chai");
|
|
34
33
|
const cctpHelpers_1 = require("./cctpHelpers");
|
|
34
|
+
const svm_1 = require("../../src/svm");
|
|
35
35
|
const { provider, program, owner, initializeState, connection, remoteDomain, chainId, crossDomainAdmin } = SvmSpoke_common_1.common;
|
|
36
36
|
describe("svm_spoke.token_bridge", () => {
|
|
37
37
|
anchor.setProvider(provider);
|
|
@@ -45,19 +45,19 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
45
45
|
before(async () => {
|
|
46
46
|
// token_minter state is pulled from devnet (DBD8hAwLDRQkTsu6EqviaYNGKPnsAMmQonxf7AH8ZcFY) with its
|
|
47
47
|
// token_controller field overridden to test wallet.
|
|
48
|
-
tokenMinter = (0,
|
|
48
|
+
tokenMinter = (0, svm_1.findProgramAddress)("token_minter", tokenMessengerMinterProgram.programId).publicKey;
|
|
49
49
|
// message_transmitter state is forked from devnet (BWrwSWjbikT3H7qHAkUEbLmwDQoB4ZDJ4wcSEhSPTZCu).
|
|
50
|
-
messageTransmitter = (0,
|
|
50
|
+
messageTransmitter = (0, svm_1.findProgramAddress)("message_transmitter", messageTransmitterProgram.programId).publicKey;
|
|
51
51
|
// token_messenger state is forked from devnet (Afgq3BHEfCE7d78D2XE9Bfyu2ieDqvE24xX8KDwreBms).
|
|
52
|
-
tokenMessenger = (0,
|
|
52
|
+
tokenMessenger = (0, svm_1.findProgramAddress)("token_messenger", tokenMessengerMinterProgram.programId).publicKey;
|
|
53
53
|
// Ethereum remote_token_messenger state is forked from devnet (Hazwi3jFQtLKc2ughi7HFXPkpDeso7DQaMR9Ks4afh3j).
|
|
54
|
-
remoteTokenMessenger = (0,
|
|
54
|
+
remoteTokenMessenger = (0, svm_1.findProgramAddress)("remote_token_messenger", tokenMessengerMinterProgram.programId, [
|
|
55
55
|
remoteDomain.toString(),
|
|
56
56
|
]).publicKey;
|
|
57
57
|
// PDA for token_messenger_minter to emit DepositForBurn event via CPI.
|
|
58
|
-
eventAuthority = (0,
|
|
58
|
+
eventAuthority = (0, svm_1.findProgramAddress)("__event_authority", tokenMessengerMinterProgram.programId).publicKey;
|
|
59
59
|
// PDA, used to check that CCTP sendMessage was called by TokenMessenger
|
|
60
|
-
tokenMessengerMinterSenderAuthority = (0,
|
|
60
|
+
tokenMessengerMinterSenderAuthority = (0, svm_1.findProgramAddress)("sender_authority", tokenMessengerMinterProgram.programId).publicKey;
|
|
61
61
|
});
|
|
62
62
|
beforeEach(async () => {
|
|
63
63
|
// Each test will have different state and mint token.
|
|
@@ -65,10 +65,10 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
65
65
|
mint = await (0, spl_token_1.createMint)(connection, payer, owner, owner, 6);
|
|
66
66
|
vault = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, mint, state, true)).address;
|
|
67
67
|
await (0, spl_token_1.mintTo)(connection, payer, mint, vault, provider.publicKey, initialMintAmount);
|
|
68
|
-
transferLiability = (0,
|
|
69
|
-
localToken = (0,
|
|
68
|
+
transferLiability = (0, svm_1.findProgramAddress)("transfer_liability", program.programId, [mint]).publicKey;
|
|
69
|
+
localToken = (0, svm_1.findProgramAddress)("local_token", tokenMessengerMinterProgram.programId, [mint]).publicKey;
|
|
70
70
|
// add local cctp token
|
|
71
|
-
const custodyTokenAccount = (0,
|
|
71
|
+
const custodyTokenAccount = (0, svm_1.findProgramAddress)("custody", tokenMessengerMinterProgram.programId, [
|
|
72
72
|
mint,
|
|
73
73
|
]).publicKey;
|
|
74
74
|
const addLocalTokenAccounts = {
|
|
@@ -128,7 +128,7 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
128
128
|
refundAddresses: [],
|
|
129
129
|
refundAmounts: [],
|
|
130
130
|
});
|
|
131
|
-
const merkleTree = new MerkleTree_1.MerkleTree(relayerRefundLeaves,
|
|
131
|
+
const merkleTree = new MerkleTree_1.MerkleTree(relayerRefundLeaves, svm_1.relayerRefundHashFn);
|
|
132
132
|
const root = merkleTree.getRoot();
|
|
133
133
|
const proof = merkleTree.getProof(relayerRefundLeaves[0]);
|
|
134
134
|
const leaf = relayerRefundLeaves[0];
|
|
@@ -163,7 +163,7 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
163
163
|
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
164
164
|
program: program.programId,
|
|
165
165
|
};
|
|
166
|
-
await (0,
|
|
166
|
+
await (0, svm_1.loadExecuteRelayerRefundLeafParams)(program, owner, stateAccountData.rootBundleId, leaf, proofAsNumbers);
|
|
167
167
|
await program.methods.executeRelayerRefundLeaf().accounts(executeRelayerRefundLeafAccounts).rpc();
|
|
168
168
|
};
|
|
169
169
|
it("Bridge all pending tokens to HubPool in single transaction", async () => {
|
|
@@ -260,15 +260,13 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
260
260
|
// Create a new Keypair for the message event data.
|
|
261
261
|
const simpleBridgeMessageSentEventData = anchor_1.web3.Keypair.generate();
|
|
262
262
|
// Perform the bridge operation.
|
|
263
|
-
await program.methods
|
|
263
|
+
const tx = await program.methods
|
|
264
264
|
.bridgeTokensToHubPool(new anchor_1.BN(simpleBridgeAmount))
|
|
265
265
|
.accounts({ ...bridgeTokensToHubPoolAccounts, messageSentEventData: simpleBridgeMessageSentEventData.publicKey })
|
|
266
266
|
.signers([simpleBridgeMessageSentEventData])
|
|
267
267
|
.rpc();
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const events = await (0, utils_1.readProgramEvents)(connection, program);
|
|
271
|
-
const event = events.find((event) => event.name === "bridgedToHubPool").data;
|
|
268
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
269
|
+
const event = events.find((event) => event.name === "bridgedToHubPool")?.data;
|
|
272
270
|
chai_1.assert.isNotNull(event, "BridgedToHubPool event should be emitted");
|
|
273
271
|
chai_1.assert.strictEqual(event.amount.toString(), simpleBridgeAmount.toString(), "Invalid amount");
|
|
274
272
|
chai_1.assert.strictEqual(event.mint.toString(), mint.toString(), "Invalid mint");
|
|
@@ -1,59 +1,11 @@
|
|
|
1
1
|
import * as anchor from "@coral-xyz/anchor";
|
|
2
2
|
import { BN, Program } from "@coral-xyz/anchor";
|
|
3
3
|
import { PublicKey } from "@solana/web3.js";
|
|
4
|
+
import { DepositData } from "../../src/types/svm";
|
|
4
5
|
import { SvmSpoke } from "../../target/types/svm_spoke";
|
|
5
|
-
import { SlowFillLeaf } from "./utils";
|
|
6
6
|
declare function setCurrentTime(program: Program<SvmSpoke>, state: any, signer: anchor.web3.Keypair, newTime: BN): Promise<void>;
|
|
7
7
|
declare function getCurrentTime(program: Program<SvmSpoke>, state: any): Promise<number>;
|
|
8
8
|
declare function assertSE(a: any, b: any, errorMessage: string): void;
|
|
9
|
-
interface DepositData {
|
|
10
|
-
depositor: PublicKey | null;
|
|
11
|
-
recipient: PublicKey;
|
|
12
|
-
inputToken: PublicKey | null;
|
|
13
|
-
outputToken: PublicKey;
|
|
14
|
-
inputAmount: BN;
|
|
15
|
-
outputAmount: BN;
|
|
16
|
-
destinationChainId: BN;
|
|
17
|
-
exclusiveRelayer: PublicKey;
|
|
18
|
-
quoteTimestamp: BN;
|
|
19
|
-
fillDeadline: BN;
|
|
20
|
-
exclusivityParameter: BN;
|
|
21
|
-
message: Buffer;
|
|
22
|
-
}
|
|
23
|
-
export type DepositDataValues = [
|
|
24
|
-
PublicKey,
|
|
25
|
-
PublicKey,
|
|
26
|
-
PublicKey,
|
|
27
|
-
PublicKey,
|
|
28
|
-
BN,
|
|
29
|
-
BN,
|
|
30
|
-
BN,
|
|
31
|
-
PublicKey,
|
|
32
|
-
number,
|
|
33
|
-
number,
|
|
34
|
-
number,
|
|
35
|
-
Buffer
|
|
36
|
-
];
|
|
37
|
-
export type RelayData = {
|
|
38
|
-
depositor: PublicKey;
|
|
39
|
-
recipient: PublicKey;
|
|
40
|
-
exclusiveRelayer: PublicKey;
|
|
41
|
-
inputToken: PublicKey;
|
|
42
|
-
outputToken: PublicKey;
|
|
43
|
-
inputAmount: BN;
|
|
44
|
-
outputAmount: BN;
|
|
45
|
-
originChainId: BN;
|
|
46
|
-
depositId: number[];
|
|
47
|
-
fillDeadline: number;
|
|
48
|
-
exclusivityDeadline: number;
|
|
49
|
-
message: Buffer;
|
|
50
|
-
};
|
|
51
|
-
export type FillDataValues = [number[], RelayData, BN, PublicKey];
|
|
52
|
-
export type FillDataParams = [number[], RelayData | null, BN | null, PublicKey | null];
|
|
53
|
-
export type RequestV3SlowFillDataValues = [number[], RelayData];
|
|
54
|
-
export type RequestV3SlowFillDataParams = [number[], RelayData | null];
|
|
55
|
-
export type ExecuteV3SlowRelayLeafDataValues = [number[], SlowFillLeaf, number, number[][]];
|
|
56
|
-
export type ExecuteV3SlowRelayLeafDataParams = [number[], SlowFillLeaf | null, number | null, number[][] | null];
|
|
57
9
|
export declare const common: {
|
|
58
10
|
provider: anchor.AnchorProvider;
|
|
59
11
|
connection: anchor.web3.Connection;
|
|
@@ -26,18 +26,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.common = void 0;
|
|
27
27
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
28
28
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
29
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
30
|
-
const ethers_1 = require("ethers");
|
|
31
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
32
|
-
const
|
|
30
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
33
31
|
const chai_1 = require("chai");
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
const ethers_1 = require("ethers");
|
|
34
|
+
const svm_1 = require("../../src/svm");
|
|
34
35
|
const provider = anchor.AnchorProvider.env();
|
|
35
36
|
const program = anchor.workspace.SvmSpoke;
|
|
36
37
|
const owner = provider.wallet.publicKey;
|
|
37
38
|
const chainId = new anchor_1.BN(420);
|
|
38
39
|
const remoteDomain = new anchor_1.BN(0); // Ethereum
|
|
39
40
|
const localDomain = 5; // Solana
|
|
40
|
-
const crossDomainAdmin = (0,
|
|
41
|
+
const crossDomainAdmin = (0, svm_1.evmAddressToPublicKey)(ethers_1.ethers.Wallet.createRandom().address);
|
|
41
42
|
const seedBalance = 20000000;
|
|
42
43
|
const destinationChainId = new anchor_1.BN(1);
|
|
43
44
|
const recipient = web3_js_1.Keypair.generate().publicKey;
|
|
@@ -52,7 +53,7 @@ const message = Buffer.from("Test message");
|
|
|
52
53
|
const depositQuoteTimeBuffer = new anchor_1.BN(3600); // 1 hour.
|
|
53
54
|
const fillDeadlineBuffer = new anchor_1.BN(3600 * 4); // 4 hours.
|
|
54
55
|
const initializeState = async (seed, initialState) => {
|
|
55
|
-
const actualSeed = seed || new anchor_1.BN(
|
|
56
|
+
const actualSeed = seed || new anchor_1.BN((0, crypto_1.randomBytes)(8).toString("hex"), 16); // Generate a random u64
|
|
56
57
|
const seeds = [Buffer.from("state"), actualSeed.toArrayLike(Buffer, "le", 8)];
|
|
57
58
|
const [state] = web3_js_1.PublicKey.findProgramAddressSync(seeds, program.programId);
|
|
58
59
|
if (!initialState) {
|
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getMessages = exports.encodeMessageHeader = exports.decodeTokenMessengerMessageBody = exports.decodeMessageHeader = exports.decodeMessageSentData = void 0;
|
|
27
27
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
28
|
-
const
|
|
28
|
+
const svm_1 = require("../../src/svm");
|
|
29
29
|
// Index positions to decode Message Header from
|
|
30
30
|
// https://developers.circle.com/stablecoins/docs/message-format#message-header
|
|
31
31
|
const HEADER_VERSION_INDEX = 0;
|
|
@@ -75,7 +75,7 @@ const decodeTokenMessengerMessageBody = (data) => {
|
|
|
75
75
|
const version = data.readUInt32BE(BODY_VERSION_INDEX);
|
|
76
76
|
const burnToken = new anchor.web3.PublicKey(data.slice(BURN_TOKEN_INDEX, BURN_TOKEN_INDEX + 32));
|
|
77
77
|
const mintRecipient = new anchor.web3.PublicKey(data.slice(MINT_RECIPIENT_INDEX, MINT_RECIPIENT_INDEX + 32));
|
|
78
|
-
const amount = (0,
|
|
78
|
+
const amount = (0, svm_1.readUInt256BE)(data.slice(AMOUNT_INDEX, AMOUNT_INDEX + 32));
|
|
79
79
|
const messageSender = new anchor.web3.PublicKey(data.slice(MESSAGE_SENDER_INDEX, MESSAGE_SENDER_INDEX + 32));
|
|
80
80
|
return { version, burnToken, mintRecipient, amount, messageSender };
|
|
81
81
|
};
|