@across-protocol/contracts 3.0.18 → 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.js +2 -2
- package/dist/scripts/svm/bridgeLiabilityToHubPool.d.ts +1 -4
- package/dist/scripts/svm/bridgeLiabilityToHubPool.js +5 -15
- package/dist/scripts/svm/closeRelayerPdas.js +3 -3
- package/dist/scripts/svm/executeRebalanceToHubPool.d.ts +1 -4
- package/dist/scripts/svm/executeRebalanceToHubPool.js +6 -16
- package/dist/scripts/svm/executeRebalanceToSpokePool.js +14 -27
- package/dist/scripts/svm/fakeFillWithRandomDistribution.js +6 -7
- package/dist/scripts/svm/initialize.js +2 -2
- package/dist/scripts/svm/proposeRebalanceToSpokePool.js +11 -15
- package/dist/scripts/svm/publicKeyToAddress.js +2 -2
- package/dist/scripts/svm/queryDeposits.js +2 -2
- package/dist/scripts/svm/queryFills.js +10 -11
- package/dist/scripts/svm/remoteHubPoolPauseDeposits.js +10 -24
- package/dist/scripts/svm/remoteHubPoolSetDepositRoute.js +16 -29
- package/dist/scripts/svm/remotePauseDeposits.js +21 -27
- package/dist/scripts/svm/simpleFakeRelayerRepayment.js +3 -3
- package/dist/scripts/svm/simpleFill.js +3 -4
- package/dist/scripts/svm/utils/helpers.d.ts +3 -1
- package/dist/scripts/svm/utils/helpers.js +13 -3
- 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/test/svm/MulticallHandler.js +2 -2
- package/dist/test/svm/SvmSpoke.Bundle.js +48 -48
- package/dist/test/svm/SvmSpoke.Deposit.js +13 -13
- package/dist/test/svm/SvmSpoke.Fill.AcrossPlus.js +15 -17
- package/dist/test/svm/SvmSpoke.Fill.js +29 -30
- package/dist/test/svm/SvmSpoke.HandleReceiveMessage.js +2 -2
- package/dist/test/svm/SvmSpoke.Ownership.js +6 -6
- package/dist/test/svm/SvmSpoke.RefundClaims.js +5 -5
- package/dist/test/svm/SvmSpoke.Routes.js +3 -3
- package/dist/test/svm/SvmSpoke.SlowFill.AcrossPlus.js +19 -20
- package/dist/test/svm/SvmSpoke.SlowFill.js +18 -18
- package/dist/test/svm/SvmSpoke.TokenBridge.js +13 -13
- package/dist/test/svm/SvmSpoke.common.d.ts +1 -49
- package/dist/test/svm/SvmSpoke.common.js +4 -4
- package/dist/test/svm/cctpHelpers.js +2 -2
- package/dist/test/svm/utils.d.ts +5 -66
- package/dist/test/svm/utils.js +10 -226
- 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 -72
- package/dist/src/SvmUtils.js +0 -496
|
@@ -30,8 +30,8 @@ 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
|
-
const SvmUtils_1 = require("../../src/SvmUtils");
|
|
35
35
|
const { provider, connection, program, owner, chainId, seedBalance, initializeState } = SvmSpoke_common_1.common;
|
|
36
36
|
const { recipient, setCurrentTime, assertSE, assert } = SvmSpoke_common_1.common;
|
|
37
37
|
describe("svm_spoke.slow_fill", () => {
|
|
@@ -49,7 +49,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
49
49
|
const initialMintAmount = 10_000_000_000;
|
|
50
50
|
async function updateRelayData(newRelayData) {
|
|
51
51
|
relayData = newRelayData;
|
|
52
|
-
const relayHashUint8Array = (0,
|
|
52
|
+
const relayHashUint8Array = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
53
53
|
[fillStatus] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
|
|
54
54
|
// recipientTA could be different for each relayData if custom recipient was passed.
|
|
55
55
|
recipientTA = (await (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, payer, mint, relayData.recipient)).address;
|
|
@@ -89,7 +89,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
89
89
|
inputAmount: new anchor_1.BN(relayAmount),
|
|
90
90
|
outputAmount: new anchor_1.BN(relayAmount),
|
|
91
91
|
originChainId: new anchor_1.BN(1),
|
|
92
|
-
depositId: (0,
|
|
92
|
+
depositId: (0, svm_1.intToU8Array32)(Math.floor(Math.random() * 1000000)), // Unique ID for each test.
|
|
93
93
|
fillDeadline: Math.floor(Date.now() / 1000) + 60, // 1 minute from now
|
|
94
94
|
exclusivityDeadline: Math.floor(Date.now() / 1000) - 30, // Note we set time in past to avoid exclusivity deadline
|
|
95
95
|
message,
|
|
@@ -99,7 +99,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
99
99
|
};
|
|
100
100
|
await updateRelayData(slowRelayLeaf.relayData);
|
|
101
101
|
slowRelayLeafs.push(slowRelayLeaf);
|
|
102
|
-
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs,
|
|
102
|
+
const merkleTree = new MerkleTree_1.MerkleTree(slowRelayLeafs, svm_1.slowFillHashFn);
|
|
103
103
|
const slowRelayRoot = merkleTree.getRoot();
|
|
104
104
|
const proof = merkleTree.getProof(slowRelayLeafs[0]);
|
|
105
105
|
const leaf = slowRelayLeafs[0];
|
|
@@ -117,7 +117,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
117
117
|
.accounts(relayRootBundleAccounts)
|
|
118
118
|
.rpc();
|
|
119
119
|
const proofAsNumbers = proof.map((p) => Array.from(p));
|
|
120
|
-
const relayHash = (0,
|
|
120
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(slowRelayLeaf.relayData, chainId);
|
|
121
121
|
return { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle };
|
|
122
122
|
};
|
|
123
123
|
before("Creates token mint and associated token accounts", async () => {
|
|
@@ -145,7 +145,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
145
145
|
inputAmount: new anchor_1.BN(relayAmount),
|
|
146
146
|
outputAmount: new anchor_1.BN(relayAmount),
|
|
147
147
|
originChainId: new anchor_1.BN(1),
|
|
148
|
-
depositId: (0,
|
|
148
|
+
depositId: (0, svm_1.intToU8Array32)(1),
|
|
149
149
|
fillDeadline: Math.floor(Date.now() / 1000) + 60, // 1 minute from now
|
|
150
150
|
exclusivityDeadline: Math.floor(Date.now() / 1000) + 30, // 30 seconds from now
|
|
151
151
|
message: encodedMessage,
|
|
@@ -154,7 +154,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
154
154
|
});
|
|
155
155
|
it("Requests a V3 slow fill, verify the event & state change", async () => {
|
|
156
156
|
// Attempt to request a slow fill before the exclusivityDeadline
|
|
157
|
-
const relayHash = Array.from((0,
|
|
157
|
+
const relayHash = Array.from((0, svm_1.calculateRelayHashUint8Array)(relayData, chainId));
|
|
158
158
|
try {
|
|
159
159
|
await program.methods.requestV3SlowFill(relayHash, relayData).accounts(requestAccounts).signers([relayer]).rpc();
|
|
160
160
|
assert.fail("Request should have failed due to exclusivity deadline not passed");
|
|
@@ -170,20 +170,20 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
170
170
|
.signers([relayer])
|
|
171
171
|
.rpc();
|
|
172
172
|
// Fetch and verify the RequestedV3SlowFill event
|
|
173
|
-
const events = await (0,
|
|
173
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
174
174
|
const event = events.find((event) => event.name === "requestedV3SlowFill")?.data;
|
|
175
175
|
assert.isNotNull(event, "RequestedV3SlowFill event should be emitted");
|
|
176
176
|
// Verify that the event data matches the relay data.
|
|
177
177
|
Object.entries(relayData).forEach(([key, value]) => {
|
|
178
178
|
if (key === "message") {
|
|
179
|
-
assertSE(event.messageHash, (0,
|
|
179
|
+
assertSE(event.messageHash, (0, svm_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
180
180
|
}
|
|
181
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 V3 slow fill if the relay has already been filled", async () => {
|
|
186
|
-
const relayHash = Array.from((0,
|
|
186
|
+
const relayHash = Array.from((0, svm_1.calculateRelayHashUint8Array)(relayData, chainId));
|
|
187
187
|
// Fill the relay first
|
|
188
188
|
const approveIx = await (0, spl_token_1.createApproveCheckedInstruction)(fillAccounts.relayerTokenAccount, fillAccounts.mint, fillAccounts.state, fillAccounts.signer, BigInt(relayData.outputAmount.toString()), tokenDecimals);
|
|
189
189
|
const fillIx = await program.methods
|
|
@@ -212,7 +212,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
it("Fetches FillStatusAccount before and after requestV3SlowFill", async () => {
|
|
215
|
-
const relayHash = (0,
|
|
215
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
216
216
|
const [fillStatusPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHash], program.programId);
|
|
217
217
|
// Fetch FillStatusAccount before requestV3SlowFill
|
|
218
218
|
let fillStatusAccount = await program.account.fillStatusAccount.fetchNullable(fillStatusPDA);
|
|
@@ -232,7 +232,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
232
232
|
assert.equal(fillStatusAccount.relayer.toString(), relayer.publicKey.toString(), "Caller should be set as relayer");
|
|
233
233
|
});
|
|
234
234
|
it("Fails to request a V3 slow fill multiple times for the same fill", async () => {
|
|
235
|
-
const relayHash = (0,
|
|
235
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
236
236
|
// Set the contract time to be after the exclusivityDeadline
|
|
237
237
|
await setCurrentTime(program, state, relayer, new anchor_1.BN(relayData.exclusivityDeadline + 1));
|
|
238
238
|
// Request a slow fill
|
|
@@ -306,20 +306,20 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
306
306
|
assert.strictEqual(BigInt(iVaultBal) - BigInt(fVaultBal), BigInt(leaf.updatedOutputAmount.toNumber()), "Vault balance should be reduced by relay amount");
|
|
307
307
|
assert.strictEqual(BigInt(fRecipientBal) - BigInt(iRecipientBal), BigInt(leaf.updatedOutputAmount.toNumber()), "Recipient balance should be increased by relay amount");
|
|
308
308
|
// Fetch and verify the FilledV3Relay event
|
|
309
|
-
const events = await (0,
|
|
309
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
310
310
|
const event = events.find((event) => event.name === "filledV3Relay")?.data;
|
|
311
311
|
assert.isNotNull(event, "FilledV3Relay event should be emitted");
|
|
312
312
|
// Verify that the event data matches the relay data.
|
|
313
313
|
Object.entries(relayData).forEach(([key, value]) => {
|
|
314
314
|
if (key === "message") {
|
|
315
|
-
assertSE(event.messageHash, (0,
|
|
315
|
+
assertSE(event.messageHash, (0, svm_1.hashNonEmptyMessage)(value), `MessageHash should match`);
|
|
316
316
|
}
|
|
317
317
|
else
|
|
318
318
|
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
|
|
319
319
|
});
|
|
320
320
|
// RelayExecutionInfo should match.
|
|
321
321
|
assertSE(event.relayExecutionInfo.updatedRecipient, relayData.recipient, "UpdatedRecipient should match");
|
|
322
|
-
assertSE(event.relayExecutionInfo.updatedMessageHash, (0,
|
|
322
|
+
assertSE(event.relayExecutionInfo.updatedMessageHash, (0, svm_1.hashNonEmptyMessage)(relayData.message), "UpdatedMessageHash should match");
|
|
323
323
|
assertSE(event.relayExecutionInfo.updatedOutputAmount, relayData.outputAmount, "UpdatedOutputAmount should match");
|
|
324
324
|
assert.equal(JSON.stringify(event.relayExecutionInfo.fillType), `{"slowFill":{}}`, "FillType should be SlowFill");
|
|
325
325
|
// These props below are not part of relayData.
|
|
@@ -338,7 +338,7 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
338
338
|
assert.isTrue(stateAccountData.pausedFills, "Fills should be paused");
|
|
339
339
|
// Attempt to request a slow fill. This should fail because fills are paused.
|
|
340
340
|
try {
|
|
341
|
-
const relayHash = (0,
|
|
341
|
+
const relayHash = (0, svm_1.calculateRelayHashUint8Array)(relayData, chainId);
|
|
342
342
|
await program.methods
|
|
343
343
|
.requestV3SlowFill(Array.from(relayHash), relayData)
|
|
344
344
|
.accounts(requestAccounts)
|
|
@@ -560,11 +560,11 @@ describe("svm_spoke.slow_fill", () => {
|
|
|
560
560
|
.remainingAccounts(fillRemainingAccounts)
|
|
561
561
|
.rpc();
|
|
562
562
|
// Fetch and verify message hash in the RequestedV3SlowFill and FilledV3Relay events
|
|
563
|
-
const requestEvents = await (0,
|
|
563
|
+
const requestEvents = await (0, svm_1.readEventsUntilFound)(connection, tx1, [program]);
|
|
564
564
|
const requestEvent = requestEvents.find((event) => event.name === "requestedV3SlowFill")?.data;
|
|
565
565
|
assert.isNotNull(requestEvent, "RequestedV3SlowFill event should be emitted");
|
|
566
566
|
assertSE(requestEvent.messageHash, new Uint8Array(32), `MessageHash should be zeroed`);
|
|
567
|
-
const fillEvents = await (0,
|
|
567
|
+
const fillEvents = await (0, svm_1.readEventsUntilFound)(connection, tx2, [program]);
|
|
568
568
|
const fillEvent = fillEvents.find((event) => event.name === "filledV3Relay")?.data;
|
|
569
569
|
assert.isNotNull(fillEvent, "FilledV3Relay event should be emitted");
|
|
570
570
|
assertSE(fillEvent.messageHash, new Uint8Array(32), `MessageHash should be zeroed`);
|
|
@@ -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 () => {
|
|
@@ -265,7 +265,7 @@ describe("svm_spoke.token_bridge", () => {
|
|
|
265
265
|
.accounts({ ...bridgeTokensToHubPoolAccounts, messageSentEventData: simpleBridgeMessageSentEventData.publicKey })
|
|
266
266
|
.signers([simpleBridgeMessageSentEventData])
|
|
267
267
|
.rpc();
|
|
268
|
-
const events = await (0,
|
|
268
|
+
const events = await (0, svm_1.readEventsUntilFound)(connection, tx, [program]);
|
|
269
269
|
const event = events.find((event) => event.name === "bridgedToHubPool")?.data;
|
|
270
270
|
chai_1.assert.isNotNull(event, "BridgedToHubPool event should be emitted");
|
|
271
271
|
chai_1.assert.strictEqual(event.amount.toString(), simpleBridgeAmount.toString(), "Invalid amount");
|
|
@@ -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,19 +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");
|
|
34
32
|
const crypto_1 = require("crypto");
|
|
33
|
+
const ethers_1 = require("ethers");
|
|
34
|
+
const svm_1 = require("../../src/svm");
|
|
35
35
|
const provider = anchor.AnchorProvider.env();
|
|
36
36
|
const program = anchor.workspace.SvmSpoke;
|
|
37
37
|
const owner = provider.wallet.publicKey;
|
|
38
38
|
const chainId = new anchor_1.BN(420);
|
|
39
39
|
const remoteDomain = new anchor_1.BN(0); // Ethereum
|
|
40
40
|
const localDomain = 5; // Solana
|
|
41
|
-
const crossDomainAdmin = (0,
|
|
41
|
+
const crossDomainAdmin = (0, svm_1.evmAddressToPublicKey)(ethers_1.ethers.Wallet.createRandom().address);
|
|
42
42
|
const seedBalance = 20000000;
|
|
43
43
|
const destinationChainId = new anchor_1.BN(1);
|
|
44
44
|
const recipient = web3_js_1.Keypair.generate().publicKey;
|
|
@@ -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
|
};
|
package/dist/test/svm/utils.d.ts
CHANGED
|
@@ -1,42 +1,13 @@
|
|
|
1
|
-
import { BN
|
|
2
|
-
import { AccountMeta,
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { AccountMeta, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { BigNumber } from "ethers";
|
|
4
|
-
import {
|
|
5
|
-
import { readEvents, readProgramEvents, calculateRelayHashUint8Array, findProgramAddress, readEventsUntilFound } from "../../src/SvmUtils";
|
|
4
|
+
import { calculateRelayHashUint8Array, findProgramAddress, readEvents, readProgramEvents } from "../../src/svm";
|
|
6
5
|
import { MerkleTree } from "@uma/common";
|
|
7
|
-
import {
|
|
8
|
-
export {
|
|
6
|
+
import { RelayerRefundLeafType } from "../../src/types/svm";
|
|
7
|
+
export { calculateRelayHashUint8Array, findProgramAddress, readEvents, readProgramEvents };
|
|
9
8
|
export declare function printLogs(connection: any, program: any, tx: any): Promise<void>;
|
|
10
9
|
export declare function randomAddress(): string;
|
|
11
10
|
export declare function randomBigInt(bytes?: number, signed?: boolean): bigint;
|
|
12
|
-
export interface RelayerRefundLeaf {
|
|
13
|
-
isSolana: boolean;
|
|
14
|
-
amountToReturn: BigNumber;
|
|
15
|
-
chainId: BigNumber;
|
|
16
|
-
refundAmounts: BigNumber[];
|
|
17
|
-
leafId: BigNumber;
|
|
18
|
-
l2TokenAddress: string;
|
|
19
|
-
refundAddresses: string[];
|
|
20
|
-
}
|
|
21
|
-
export interface RelayerRefundLeafSolana {
|
|
22
|
-
isSolana: boolean;
|
|
23
|
-
amountToReturn: BN;
|
|
24
|
-
chainId: BN;
|
|
25
|
-
refundAmounts: BN[];
|
|
26
|
-
leafId: BN;
|
|
27
|
-
mintPublicKey: PublicKey;
|
|
28
|
-
refundAddresses: PublicKey[];
|
|
29
|
-
}
|
|
30
|
-
export type RelayerRefundLeafType = RelayerRefundLeaf | RelayerRefundLeafSolana;
|
|
31
|
-
export declare function convertLeafIdToNumber(leaf: RelayerRefundLeafSolana): {
|
|
32
|
-
leafId: number;
|
|
33
|
-
isSolana: boolean;
|
|
34
|
-
amountToReturn: BN;
|
|
35
|
-
chainId: BN;
|
|
36
|
-
refundAmounts: BN[];
|
|
37
|
-
mintPublicKey: PublicKey;
|
|
38
|
-
refundAddresses: PublicKey[];
|
|
39
|
-
};
|
|
40
11
|
export declare function buildRelayerRefundMerkleTree({ totalEvmDistributions, totalSolanaDistributions, mixLeaves, chainId, mint, svmRelayers, evmRelayers, evmTokenAddress, evmRefundAmounts, svmRefundAmounts, }: {
|
|
41
12
|
totalEvmDistributions: number;
|
|
42
13
|
totalSolanaDistributions: number;
|
|
@@ -52,38 +23,6 @@ export declare function buildRelayerRefundMerkleTree({ totalEvmDistributions, to
|
|
|
52
23
|
relayerRefundLeaves: RelayerRefundLeafType[];
|
|
53
24
|
merkleTree: MerkleTree<RelayerRefundLeafType>;
|
|
54
25
|
};
|
|
55
|
-
export declare function calculateRelayerRefundLeafHashUint8Array(relayData: RelayerRefundLeafSolana): string;
|
|
56
|
-
export declare const relayerRefundHashFn: (input: RelayerRefundLeaf | RelayerRefundLeafSolana) => string;
|
|
57
|
-
export interface SlowFillLeaf {
|
|
58
|
-
relayData: {
|
|
59
|
-
depositor: PublicKey;
|
|
60
|
-
recipient: PublicKey;
|
|
61
|
-
exclusiveRelayer: PublicKey;
|
|
62
|
-
inputToken: PublicKey;
|
|
63
|
-
outputToken: PublicKey;
|
|
64
|
-
inputAmount: BN;
|
|
65
|
-
outputAmount: BN;
|
|
66
|
-
originChainId: BN;
|
|
67
|
-
depositId: number[];
|
|
68
|
-
fillDeadline: number;
|
|
69
|
-
exclusivityDeadline: number;
|
|
70
|
-
message: Buffer;
|
|
71
|
-
};
|
|
72
|
-
chainId: BN;
|
|
73
|
-
updatedOutputAmount: BN;
|
|
74
|
-
}
|
|
75
|
-
export declare function slowFillHashFn(slowFillLeaf: SlowFillLeaf): string;
|
|
76
|
-
export declare function loadExecuteRelayerRefundLeafParams(program: Program<SvmSpoke>, caller: PublicKey, rootBundleId: number, relayerRefundLeaf: RelayerRefundLeafSolana, proof: number[][]): Promise<PublicKey>;
|
|
77
|
-
export declare function closeInstructionParams(program: Program<SvmSpoke>, signer: Keypair): Promise<void>;
|
|
78
|
-
export declare function createFillV3RelayParamsInstructions(program: Program<SvmSpoke>, signer: PublicKey, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<{
|
|
79
|
-
loadInstructions: TransactionInstruction[];
|
|
80
|
-
closeInstruction: TransactionInstruction;
|
|
81
|
-
}>;
|
|
82
|
-
export declare function loadFillV3RelayParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData, repaymentChainId: BN, repaymentAddress: PublicKey): Promise<void>;
|
|
83
|
-
export declare function loadRequestV3SlowFillParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData): Promise<TransactionInstruction[]>;
|
|
84
|
-
export declare function loadExecuteV3SlowRelayLeafParams(program: Program<SvmSpoke>, signer: Keypair, slowFillLeaf: SlowFillLeaf, rootBundleId: number, proof: number[][]): Promise<TransactionInstruction[]>;
|
|
85
|
-
export declare function intToU8Array32(num: number | BN): number[];
|
|
86
|
-
export declare function u8Array32ToInt(u8Array: Uint8Array | number[]): bigint;
|
|
87
26
|
export declare function testAcrossPlusMessage(): {
|
|
88
27
|
encodedMessage: Buffer;
|
|
89
28
|
fillRemainingAccounts: AccountMeta[];
|