@across-protocol/sdk 4.2.9-alpha.0 → 4.2.9-alpha.2
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/cjs/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +1 -0
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.d.ts +16 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +128 -27
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +4 -0
- package/dist/cjs/arch/svm/utils.js +13 -1
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +3 -3
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +5 -5
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +1 -1
- package/dist/cjs/clients/HubPoolClient.js +9 -6
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +28 -28
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +3 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/interfaces/HubPool.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +4 -4
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +7 -8
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +70 -62
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +2 -2
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +3 -3
- package/dist/cjs/utils/AddressUtils.js +24 -9
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.js +3 -3
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/esm/arch/evm/SpokeUtils.js +1 -0
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +46 -6
- package/dist/esm/arch/svm/SpokeUtils.js +157 -36
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +10 -0
- package/dist/esm/arch/svm/utils.js +18 -1
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +3 -3
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +5 -5
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +1 -1
- package/dist/esm/clients/HubPoolClient.js +9 -6
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +28 -28
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +3 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/interfaces/HubPool.d.ts +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +4 -4
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +8 -9
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +74 -64
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +3 -3
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +4 -3
- package/dist/esm/utils/AddressUtils.js +30 -12
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +14 -0
- package/dist/esm/utils/TokenUtils.js +3 -3
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +46 -6
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +10 -0
- package/dist/types/arch/svm/utils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +1 -1
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/interfaces/HubPool.d.ts +1 -1
- package/dist/types/interfaces/HubPool.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +8 -9
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +4 -3
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +14 -0
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/arch/evm/SpokeUtils.ts +9 -1
- package/src/arch/svm/SpokeUtils.ts +149 -42
- package/src/arch/svm/utils.ts +19 -0
- package/src/clients/BundleDataClient/BundleDataClient.ts +5 -5
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +5 -5
- package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
- package/src/clients/HubPoolClient.ts +13 -7
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +5 -5
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +32 -29
- package/src/clients/mocks/MockSpokePoolClient.ts +3 -1
- package/src/interfaces/HubPool.ts +1 -1
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +4 -4
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +85 -89
- package/src/relayFeeCalculator/relayFeeCalculator.ts +10 -4
- package/src/utils/AddressUtils.ts +31 -14
- package/src/utils/TokenUtils.ts +3 -3
|
@@ -4,17 +4,21 @@ import { hashNonEmptyMessage } from "@across-protocol/contracts/dist/src/svm/web
|
|
|
4
4
|
import {
|
|
5
5
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
6
6
|
TOKEN_PROGRAM_ADDRESS,
|
|
7
|
+
fetchMint,
|
|
7
8
|
getApproveCheckedInstruction,
|
|
9
|
+
getCreateAssociatedTokenIdempotentInstruction,
|
|
8
10
|
} from "@solana-program/token";
|
|
9
11
|
import {
|
|
10
12
|
Address,
|
|
11
13
|
address,
|
|
14
|
+
appendTransactionMessageInstruction,
|
|
12
15
|
fetchEncodedAccount,
|
|
13
16
|
fetchEncodedAccounts,
|
|
14
17
|
getAddressEncoder,
|
|
15
18
|
getProgramDerivedAddress,
|
|
16
19
|
getU32Encoder,
|
|
17
20
|
getU64Encoder,
|
|
21
|
+
pipe,
|
|
18
22
|
some,
|
|
19
23
|
type TransactionSigner,
|
|
20
24
|
} from "@solana/kit";
|
|
@@ -22,19 +26,17 @@ import assert from "assert";
|
|
|
22
26
|
import { arrayify, hexZeroPad, hexlify } from "ethers/lib/utils";
|
|
23
27
|
import { Logger } from "winston";
|
|
24
28
|
|
|
25
|
-
import {
|
|
29
|
+
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
26
30
|
import { Deposit, DepositWithBlock, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
|
|
31
|
+
import { BigNumber, SvmAddress, chainIsSvm, chunk, isUnsafeDepositId, keccak256 } from "../../utils";
|
|
27
32
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
keccak256,
|
|
36
|
-
} from "../../utils";
|
|
37
|
-
import { SvmCpiEventsClient, getEventAuthority, getFillStatusPda, getStatePda, unwrapEventData } from "./";
|
|
33
|
+
SvmCpiEventsClient,
|
|
34
|
+
createDefaultTransaction,
|
|
35
|
+
getEventAuthority,
|
|
36
|
+
getFillStatusPda,
|
|
37
|
+
getStatePda,
|
|
38
|
+
unwrapEventData,
|
|
39
|
+
} from "./";
|
|
38
40
|
import { SVMEventNames, SVMProvider } from "./types";
|
|
39
41
|
|
|
40
42
|
/**
|
|
@@ -425,41 +427,146 @@ export function createTokenAccountsInstruction(
|
|
|
425
427
|
}
|
|
426
428
|
|
|
427
429
|
/**
|
|
428
|
-
*
|
|
429
|
-
* @param
|
|
430
|
-
* @param
|
|
431
|
-
* @param
|
|
432
|
-
* @
|
|
430
|
+
* Creates a fill instruction.
|
|
431
|
+
* @param signer - The signer of the transaction.
|
|
432
|
+
* @param solanaClient - The Solana client.
|
|
433
|
+
* @param fillInput - The fill input.
|
|
434
|
+
* @param tokenDecimals - The token decimals.
|
|
435
|
+
* @param createRecipientAtaIfNeeded - Whether to create a recipient token account.
|
|
436
|
+
* @returns The fill instruction.
|
|
433
437
|
*/
|
|
434
|
-
export async
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
) {
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
438
|
+
export const createFillInstruction = async (
|
|
439
|
+
signer: TransactionSigner,
|
|
440
|
+
solanaClient: SVMProvider,
|
|
441
|
+
fillInput: SvmSpokeClient.FillRelayInput,
|
|
442
|
+
tokenDecimals: number,
|
|
443
|
+
createRecipientAtaIfNeeded: boolean = true
|
|
444
|
+
) => {
|
|
445
|
+
const mintInfo = await fetchMint(solanaClient, fillInput.mint);
|
|
446
|
+
const approveIx = getApproveCheckedInstruction(
|
|
447
|
+
{
|
|
448
|
+
source: fillInput.relayerTokenAccount,
|
|
449
|
+
mint: fillInput.mint,
|
|
450
|
+
delegate: fillInput.delegate,
|
|
451
|
+
owner: fillInput.signer,
|
|
452
|
+
amount: (fillInput.relayData as SvmSpokeClient.RelayDataArgs).outputAmount,
|
|
453
|
+
decimals: tokenDecimals,
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
programAddress: mintInfo.programAddress,
|
|
457
|
+
}
|
|
458
|
+
);
|
|
445
459
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
460
|
+
const getCreateAssociatedTokenIdempotentIx = () =>
|
|
461
|
+
getCreateAssociatedTokenIdempotentInstruction({
|
|
462
|
+
payer: signer,
|
|
463
|
+
owner: (fillInput.relayData as SvmSpokeClient.RelayDataArgs).recipient,
|
|
464
|
+
mint: fillInput.mint,
|
|
465
|
+
ata: fillInput.recipientTokenAccount,
|
|
466
|
+
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
467
|
+
tokenProgram: fillInput.tokenProgram,
|
|
468
|
+
});
|
|
452
469
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
470
|
+
const createFillIx = await SvmSpokeClient.getFillRelayInstruction(fillInput);
|
|
471
|
+
|
|
472
|
+
return pipe(
|
|
473
|
+
await createDefaultTransaction(solanaClient, signer),
|
|
474
|
+
(tx) =>
|
|
475
|
+
createRecipientAtaIfNeeded ? appendTransactionMessageInstruction(getCreateAssociatedTokenIdempotentIx(), tx) : tx,
|
|
476
|
+
(tx) => appendTransactionMessageInstruction(approveIx, tx),
|
|
477
|
+
(tx) => appendTransactionMessageInstruction(createFillIx, tx)
|
|
478
|
+
);
|
|
479
|
+
};
|
|
462
480
|
|
|
481
|
+
/**
|
|
482
|
+
* Creates a deposit instruction.
|
|
483
|
+
* @param signer - The signer of the transaction.
|
|
484
|
+
* @param solanaClient - The Solana client.
|
|
485
|
+
* @param depositInput - The deposit input.
|
|
486
|
+
* @param tokenDecimals - The token decimals.
|
|
487
|
+
* @param createVaultAtaIfNeeded - Whether to create a vault token account.
|
|
488
|
+
* @returns The deposit instruction.
|
|
489
|
+
*/
|
|
490
|
+
export const createDepositInstruction = async (
|
|
491
|
+
signer: TransactionSigner,
|
|
492
|
+
solanaClient: SVMProvider,
|
|
493
|
+
depositInput: SvmSpokeClient.DepositInput,
|
|
494
|
+
tokenDecimals: number,
|
|
495
|
+
createVaultAtaIfNeeded: boolean = true
|
|
496
|
+
) => {
|
|
497
|
+
const getCreateAssociatedTokenIdempotentIx = () =>
|
|
498
|
+
getCreateAssociatedTokenIdempotentInstruction({
|
|
499
|
+
payer: signer,
|
|
500
|
+
owner: depositInput.state,
|
|
501
|
+
mint: depositInput.mint,
|
|
502
|
+
ata: depositInput.vault,
|
|
503
|
+
systemProgram: depositInput.systemProgram,
|
|
504
|
+
tokenProgram: depositInput.tokenProgram,
|
|
505
|
+
});
|
|
506
|
+
const mintInfo = await fetchMint(solanaClient, depositInput.mint);
|
|
507
|
+
const approveIx = getApproveCheckedInstruction(
|
|
508
|
+
{
|
|
509
|
+
source: depositInput.depositorTokenAccount,
|
|
510
|
+
mint: depositInput.mint,
|
|
511
|
+
delegate: depositInput.delegate,
|
|
512
|
+
owner: depositInput.depositor,
|
|
513
|
+
amount: depositInput.inputAmount,
|
|
514
|
+
decimals: tokenDecimals,
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
programAddress: mintInfo.programAddress,
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
const depositIx = await SvmSpokeClient.getDepositInstruction(depositInput);
|
|
521
|
+
return pipe(
|
|
522
|
+
await createDefaultTransaction(solanaClient, signer),
|
|
523
|
+
(tx) =>
|
|
524
|
+
createVaultAtaIfNeeded ? appendTransactionMessageInstruction(getCreateAssociatedTokenIdempotentIx(), tx) : tx,
|
|
525
|
+
(tx) => appendTransactionMessageInstruction(approveIx, tx),
|
|
526
|
+
(tx) => appendTransactionMessageInstruction(depositIx, tx)
|
|
527
|
+
);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Creates a request slow fill instruction.
|
|
532
|
+
* @param signer - The signer of the transaction.
|
|
533
|
+
* @param solanaClient - The Solana client.
|
|
534
|
+
* @param depositInput - The deposit input.
|
|
535
|
+
* @returns The request slow fill instruction.
|
|
536
|
+
*/
|
|
537
|
+
export const createRequestSlowFillInstruction = async (
|
|
538
|
+
signer: TransactionSigner,
|
|
539
|
+
solanaClient: SVMProvider,
|
|
540
|
+
depositInput: SvmSpokeClient.RequestSlowFillInput
|
|
541
|
+
) => {
|
|
542
|
+
const requestSlowFillIx = await SvmSpokeClient.getRequestSlowFillInstruction(depositInput);
|
|
543
|
+
|
|
544
|
+
return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
|
|
545
|
+
appendTransactionMessageInstruction(requestSlowFillIx, tx)
|
|
546
|
+
);
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Creates a close fill PDA instruction.
|
|
551
|
+
* @param signer - The signer of the transaction.
|
|
552
|
+
* @param solanaClient - The Solana client.
|
|
553
|
+
* @param fillStatusPda - The fill status PDA.
|
|
554
|
+
* @returns The close fill PDA instruction.
|
|
555
|
+
*/
|
|
556
|
+
export const createCloseFillPdaInstruction = async (
|
|
557
|
+
signer: TransactionSigner,
|
|
558
|
+
solanaClient: SVMProvider,
|
|
559
|
+
fillStatusPda: Address
|
|
560
|
+
) => {
|
|
561
|
+
const closeFillPdaIx = await SvmSpokeClient.getCloseFillPdaInstruction({
|
|
562
|
+
signer,
|
|
563
|
+
state: await getStatePda(SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS),
|
|
564
|
+
fillStatus: fillStatusPda,
|
|
565
|
+
});
|
|
566
|
+
return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
|
|
567
|
+
appendTransactionMessageInstruction(closeFillPdaIx, tx)
|
|
568
|
+
);
|
|
569
|
+
};
|
|
463
570
|
export async function getAssociatedTokenAddress(
|
|
464
571
|
owner: SvmAddress,
|
|
465
572
|
mint: SvmAddress,
|
package/src/arch/svm/utils.ts
CHANGED
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
getU32Encoder,
|
|
11
11
|
isAddress,
|
|
12
12
|
type TransactionSigner,
|
|
13
|
+
pipe,
|
|
14
|
+
createTransactionMessage,
|
|
15
|
+
setTransactionMessageFeePayerSigner,
|
|
16
|
+
setTransactionMessageLifetimeUsingBlockhash,
|
|
13
17
|
} from "@solana/kit";
|
|
14
18
|
import { SvmSpokeClient } from "@across-protocol/contracts";
|
|
15
19
|
import { FillType, RelayData } from "../../interfaces";
|
|
@@ -280,3 +284,18 @@ export function getRandomSvmAddress() {
|
|
|
280
284
|
const base58Address = bs58.encode(bytes);
|
|
281
285
|
return address(base58Address);
|
|
282
286
|
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Creates a default v0 transaction skeleton.
|
|
290
|
+
* @param rpcClient - The Solana client.
|
|
291
|
+
* @param signer - The signer of the transaction.
|
|
292
|
+
* @returns The default transaction.
|
|
293
|
+
*/
|
|
294
|
+
export const createDefaultTransaction = async (rpcClient: SVMProvider, signer: TransactionSigner) => {
|
|
295
|
+
const { value: latestBlockhash } = await rpcClient.getLatestBlockhash().send();
|
|
296
|
+
return pipe(
|
|
297
|
+
createTransactionMessage({ version: 0 }),
|
|
298
|
+
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
|
|
299
|
+
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
|
|
300
|
+
);
|
|
301
|
+
};
|
|
@@ -676,15 +676,15 @@ export class BundleDataClient {
|
|
|
676
676
|
return allRefunds;
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
getRefundsFor(bundleRefunds: CombinedRefunds, relayer:
|
|
680
|
-
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
|
|
679
|
+
getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber {
|
|
680
|
+
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
|
|
681
681
|
return BigNumber.from(0);
|
|
682
682
|
}
|
|
683
|
-
const allRefunds = bundleRefunds[chainId][token];
|
|
684
|
-
return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : BigNumber.from(0);
|
|
683
|
+
const allRefunds = bundleRefunds[chainId][token.toBytes32()];
|
|
684
|
+
return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
|
|
685
685
|
}
|
|
686
686
|
|
|
687
|
-
getTotalRefund(refunds: CombinedRefunds[], relayer:
|
|
687
|
+
getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber {
|
|
688
688
|
return refunds.reduce((totalRefund, refunds) => {
|
|
689
689
|
return totalRefund.add(this.getRefundsFor(refunds, relayer, chainId, refundToken));
|
|
690
690
|
}, bnZero);
|
|
@@ -155,7 +155,7 @@ export function _buildPoolRebalanceRoot(
|
|
|
155
155
|
// there are no relevant L1 running balances.
|
|
156
156
|
if (
|
|
157
157
|
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
|
|
158
|
-
toAddressType(l2TokenAddress),
|
|
158
|
+
toAddressType(l2TokenAddress, repaymentChainId),
|
|
159
159
|
repaymentChainId,
|
|
160
160
|
mainnetBundleEndBlock
|
|
161
161
|
)
|
|
@@ -164,7 +164,7 @@ export function _buildPoolRebalanceRoot(
|
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
167
|
-
toAddressType(l2TokenAddress),
|
|
167
|
+
toAddressType(l2TokenAddress, repaymentChainId),
|
|
168
168
|
repaymentChainId,
|
|
169
169
|
mainnetBundleEndBlock
|
|
170
170
|
);
|
|
@@ -187,7 +187,7 @@ export function _buildPoolRebalanceRoot(
|
|
|
187
187
|
Object.entries(depositsForChain).forEach(([outputToken, deposits]) => {
|
|
188
188
|
deposits.forEach((deposit) => {
|
|
189
189
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
190
|
-
toAddressType(outputToken),
|
|
190
|
+
toAddressType(outputToken, destinationChainId),
|
|
191
191
|
destinationChainId,
|
|
192
192
|
mainnetBundleEndBlock
|
|
193
193
|
);
|
|
@@ -216,7 +216,7 @@ export function _buildPoolRebalanceRoot(
|
|
|
216
216
|
Object.entries(slowFilledDepositsForChain).forEach(([outputToken, slowFilledDeposits]) => {
|
|
217
217
|
slowFilledDeposits.forEach((deposit) => {
|
|
218
218
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
219
|
-
toAddressType(outputToken),
|
|
219
|
+
toAddressType(outputToken, destinationChainId),
|
|
220
220
|
destinationChainId,
|
|
221
221
|
mainnetBundleEndBlock
|
|
222
222
|
);
|
|
@@ -286,7 +286,7 @@ export function _buildPoolRebalanceRoot(
|
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
288
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
289
|
-
toAddressType(inputToken),
|
|
289
|
+
toAddressType(inputToken, originChainId),
|
|
290
290
|
originChainId,
|
|
291
291
|
mainnetBundleEndBlock
|
|
292
292
|
);
|
|
@@ -21,6 +21,12 @@ export function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLea
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const paramType = getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance");
|
|
24
|
-
const hashFn = (input: PoolRebalanceLeaf) =>
|
|
24
|
+
const hashFn = (input: PoolRebalanceLeaf) => {
|
|
25
|
+
const ethersLeaf = {
|
|
26
|
+
...input,
|
|
27
|
+
l1Tokens: input.l1Tokens.map((l1Token) => l1Token.toEvmAddress()),
|
|
28
|
+
};
|
|
29
|
+
return utils.keccak256(utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
|
|
30
|
+
};
|
|
25
31
|
return new MerkleTree<PoolRebalanceLeaf>(poolRebalanceLeaves, hashFn);
|
|
26
32
|
}
|
|
@@ -533,8 +533,8 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
533
533
|
return this.l1Tokens.find((token) => token.address.eq(l1Token));
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
-
getLpTokenInfoForL1Token(l1Token:
|
|
537
|
-
return this.lpTokens[l1Token];
|
|
536
|
+
getLpTokenInfoForL1Token(l1Token: EvmAddress): LpToken | undefined {
|
|
537
|
+
return this.lpTokens[l1Token.toEvmAddress()];
|
|
538
538
|
}
|
|
539
539
|
|
|
540
540
|
areTokensEquivalent(
|
|
@@ -920,7 +920,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
920
920
|
for (const event of events["CrossChainContractsSet"]) {
|
|
921
921
|
const args = spreadEventWithBlockNumber(event) as CrossChainContractsSet & { spokePool: string };
|
|
922
922
|
const dataToAdd: CrossChainContractsSet = {
|
|
923
|
-
spokePool: toAddressType(args.spokePool),
|
|
923
|
+
spokePool: toAddressType(args.spokePool, this.chainId),
|
|
924
924
|
blockNumber: args.blockNumber,
|
|
925
925
|
txnRef: args.txnRef,
|
|
926
926
|
logIndex: args.logIndex,
|
|
@@ -960,7 +960,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
960
960
|
// If the destination chain is SVM, then we need to convert the destination token to the Solana address.
|
|
961
961
|
// This is because the HubPool contract only holds a truncated address for the USDC token and currently
|
|
962
962
|
// only supports USDC as a destination token for Solana.
|
|
963
|
-
let destinationToken = toAddressType(args.destinationToken);
|
|
963
|
+
let destinationToken = toAddressType(args.destinationToken, this.chainId);
|
|
964
964
|
if (chainIsSvm(args.destinationChainId)) {
|
|
965
965
|
const usdcTokenSol = TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
|
|
966
966
|
const svmUsdc = SvmAddress.from(usdcTokenSol);
|
|
@@ -982,7 +982,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
982
982
|
[args.l1Token, args.destinationChainId],
|
|
983
983
|
[
|
|
984
984
|
{
|
|
985
|
-
l1Token: toAddressType(args.l1Token),
|
|
985
|
+
l1Token: toAddressType(args.l1Token, this.chainId),
|
|
986
986
|
l2Token: destinationToken,
|
|
987
987
|
blockNumber: args.blockNumber,
|
|
988
988
|
txnIndex: args.txnIndex,
|
|
@@ -1041,7 +1041,13 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1041
1041
|
this.proposedRootBundles.push(
|
|
1042
1042
|
...events["ProposeRootBundle"]
|
|
1043
1043
|
.filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
|
|
1044
|
-
.map((
|
|
1044
|
+
.map((_event) => {
|
|
1045
|
+
const args = spreadEventWithBlockNumber(_event) as ProposedRootBundle & { proposer: string };
|
|
1046
|
+
return {
|
|
1047
|
+
...args,
|
|
1048
|
+
proposer: toAddressType(args.proposer, this.chainId),
|
|
1049
|
+
};
|
|
1050
|
+
})
|
|
1045
1051
|
);
|
|
1046
1052
|
}
|
|
1047
1053
|
|
|
@@ -1078,7 +1084,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1078
1084
|
executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
|
|
1079
1085
|
const executedRootBundleWithL1Tokens = {
|
|
1080
1086
|
...executedRootBundle,
|
|
1081
|
-
l1Tokens: executedRootBundle.l1Tokens.map(toAddressType),
|
|
1087
|
+
l1Tokens: executedRootBundle.l1Tokens.map(toAddressType, this.chainId),
|
|
1082
1088
|
};
|
|
1083
1089
|
this.executedRootBundles.push(executedRootBundleWithL1Tokens);
|
|
1084
1090
|
}
|
|
@@ -195,11 +195,11 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
195
195
|
|
|
196
196
|
deposit = {
|
|
197
197
|
...spreadEventWithBlockNumber(event),
|
|
198
|
-
inputToken: toAddressType(event.args.inputToken),
|
|
199
|
-
outputToken: toAddressType(event.args.outputToken),
|
|
200
|
-
depositor: toAddressType(event.args.depositor),
|
|
201
|
-
recipient: toAddressType(event.args.recipient),
|
|
202
|
-
exclusiveRelayer: toAddressType(event.args.exclusiveRelayer),
|
|
198
|
+
inputToken: toAddressType(event.args.inputToken, this.chainId),
|
|
199
|
+
outputToken: toAddressType(event.args.outputToken, event.args.destinationChainId),
|
|
200
|
+
depositor: toAddressType(event.args.depositor, this.chainId),
|
|
201
|
+
recipient: toAddressType(event.args.recipient, event.args.destinationChainId),
|
|
202
|
+
exclusiveRelayer: toAddressType(event.args.exclusiveRelayer, event.args.destinationChainId),
|
|
203
203
|
originChainId: this.chainId,
|
|
204
204
|
quoteBlockNumber: await this.getBlockNumber(Number(event.args["quoteTimestamp"])),
|
|
205
205
|
fromLiteChain: true, // To be updated immediately afterwards.
|
|
@@ -508,8 +508,8 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
508
508
|
};
|
|
509
509
|
this.tokensBridged.push({
|
|
510
510
|
...event,
|
|
511
|
-
l2TokenAddress: toAddressType(event.l2TokenAddress),
|
|
512
|
-
}
|
|
511
|
+
l2TokenAddress: toAddressType(event.l2TokenAddress, this.chainId),
|
|
512
|
+
});
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
|
|
@@ -525,13 +525,13 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
525
525
|
};
|
|
526
526
|
return {
|
|
527
527
|
...event,
|
|
528
|
-
depositor: toAddressType(event.depositor),
|
|
529
|
-
recipient: toAddressType(event.recipient),
|
|
530
|
-
inputToken: toAddressType(event.inputToken),
|
|
531
|
-
outputToken: toAddressType(event.outputToken),
|
|
532
|
-
exclusiveRelayer: toAddressType(event.exclusiveRelayer),
|
|
528
|
+
depositor: toAddressType(event.depositor, this.chainId),
|
|
529
|
+
recipient: toAddressType(event.recipient, event.destinationChainId),
|
|
530
|
+
inputToken: toAddressType(event.inputToken, this.chainId),
|
|
531
|
+
outputToken: toAddressType(event.outputToken, event.destinationChainId),
|
|
532
|
+
exclusiveRelayer: toAddressType(event.exclusiveRelayer, event.destinationChainId),
|
|
533
533
|
} as DepositWithBlock;
|
|
534
|
-
})
|
|
534
|
+
});
|
|
535
535
|
if (depositEvents.length > 0) {
|
|
536
536
|
this.log(
|
|
537
537
|
"debug",
|
|
@@ -592,7 +592,7 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
592
592
|
const event = _event as SpeedUpWithBlock & { depositor: string; updatedRecipient: string };
|
|
593
593
|
return {
|
|
594
594
|
...event,
|
|
595
|
-
depositor: toAddressType(event.depositor),
|
|
595
|
+
depositor: toAddressType(event.depositor, this.chainId),
|
|
596
596
|
updatedRecipient: toAddressType(event.updatedRecipient),
|
|
597
597
|
} as SpeedUpWithBlock;
|
|
598
598
|
});
|
|
@@ -636,13 +636,13 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
636
636
|
};
|
|
637
637
|
return {
|
|
638
638
|
...event,
|
|
639
|
-
depositor: toAddressType(event.depositor),
|
|
640
|
-
recipient: toAddressType(event.recipient),
|
|
641
|
-
inputToken: toAddressType(event.inputToken),
|
|
642
|
-
outputToken: toAddressType(event.outputToken),
|
|
643
|
-
exclusiveRelayer: toAddressType(event.exclusiveRelayer),
|
|
639
|
+
depositor: toAddressType(event.depositor, event.originChainId),
|
|
640
|
+
recipient: toAddressType(event.recipient, this.chainId),
|
|
641
|
+
inputToken: toAddressType(event.inputToken, event.originChainId),
|
|
642
|
+
outputToken: toAddressType(event.outputToken, this.chainId),
|
|
643
|
+
exclusiveRelayer: toAddressType(event.exclusiveRelayer, this.chainId),
|
|
644
644
|
} as SlowFillRequestWithBlock;
|
|
645
|
-
})
|
|
645
|
+
});
|
|
646
646
|
for (const event of slowFillRequests) {
|
|
647
647
|
const slowFillRequest = {
|
|
648
648
|
...event,
|
|
@@ -681,18 +681,18 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
681
681
|
};
|
|
682
682
|
return {
|
|
683
683
|
...event,
|
|
684
|
-
depositor: toAddressType(event.depositor),
|
|
685
|
-
recipient: toAddressType(event.recipient),
|
|
686
|
-
inputToken: toAddressType(event.inputToken),
|
|
687
|
-
outputToken: toAddressType(event.outputToken),
|
|
688
|
-
exclusiveRelayer: toAddressType(event.exclusiveRelayer),
|
|
689
|
-
relayer: toAddressType(event.relayer),
|
|
684
|
+
depositor: toAddressType(event.depositor, event.originChainId),
|
|
685
|
+
recipient: toAddressType(event.recipient, this.chainId),
|
|
686
|
+
inputToken: toAddressType(event.inputToken, event.originChainId),
|
|
687
|
+
outputToken: toAddressType(event.outputToken, this.chainId),
|
|
688
|
+
exclusiveRelayer: toAddressType(event.exclusiveRelayer, this.chainId),
|
|
689
|
+
relayer: toAddressType(event.relayer, this.chainId),
|
|
690
690
|
relayExecutionInfo: {
|
|
691
691
|
...event.relayExecutionInfo,
|
|
692
|
-
updatedRecipient: toAddressType(event.relayExecutionInfo.updatedRecipient),
|
|
692
|
+
updatedRecipient: toAddressType(event.relayExecutionInfo.updatedRecipient, this.chainId),
|
|
693
693
|
},
|
|
694
694
|
} as FillWithBlock;
|
|
695
|
-
})
|
|
695
|
+
});
|
|
696
696
|
|
|
697
697
|
if (fillEvents.length > 0) {
|
|
698
698
|
this.log("debug", `Using ${fillEvents.length} newly queried ${eventName} events for chain ${this.chainId}`, {
|
|
@@ -728,8 +728,9 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
728
728
|
});
|
|
729
729
|
|
|
730
730
|
if (eventsToQuery.includes("EnabledDepositRoute")) {
|
|
731
|
-
const enableDepositsEvents =
|
|
732
|
-
|
|
731
|
+
const enableDepositsEvents = queryResults[
|
|
732
|
+
eventsToQuery.indexOf("EnabledDepositRoute")
|
|
733
|
+
] as EnabledDepositRouteWithBlock[];
|
|
733
734
|
|
|
734
735
|
for (const event of enableDepositsEvents) {
|
|
735
736
|
assign(this.depositRoutes, [event.originToken, event.destinationChainId], event.enabled);
|
|
@@ -737,16 +738,18 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
737
738
|
}
|
|
738
739
|
|
|
739
740
|
if (eventsToQuery.includes("RelayedRootBundle")) {
|
|
740
|
-
const relayedRootBundleEvents =
|
|
741
|
-
|
|
741
|
+
const relayedRootBundleEvents = queryResults[
|
|
742
|
+
eventsToQuery.indexOf("RelayedRootBundle")
|
|
743
|
+
] as RootBundleRelayWithBlock[];
|
|
742
744
|
for (const event of relayedRootBundleEvents) {
|
|
743
745
|
this.rootBundleRelays.push(event);
|
|
744
746
|
}
|
|
745
747
|
}
|
|
746
748
|
|
|
747
749
|
if (eventsToQuery.includes("ExecutedRelayerRefundRoot")) {
|
|
748
|
-
const refundEvents =
|
|
749
|
-
|
|
750
|
+
const refundEvents = queryResults[
|
|
751
|
+
eventsToQuery.indexOf("ExecutedRelayerRefundRoot")
|
|
752
|
+
] as RelayerRefundExecutionWithBlock[];
|
|
750
753
|
for (const event of refundEvents) {
|
|
751
754
|
this.relayerRefundExecutions.push(event);
|
|
752
755
|
}
|
|
@@ -67,7 +67,9 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
67
67
|
|
|
68
68
|
getDestinationTokenForDeposit(deposit: DepositWithBlock): Address {
|
|
69
69
|
const override = this.destinationTokenForChainOverride[deposit.originChainId];
|
|
70
|
-
return isDefined(override)
|
|
70
|
+
return isDefined(override)
|
|
71
|
+
? toAddressType(override, deposit.destinationChainId)
|
|
72
|
+
: super.getDestinationTokenForDeposit(deposit);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
setLatestBlockNumber(blockNumber: number): void {
|
|
@@ -74,7 +74,7 @@ export class QueryBase implements QueryInterface {
|
|
|
74
74
|
*/
|
|
75
75
|
async getGasCosts(
|
|
76
76
|
deposit: Omit<Deposit, "messageHash">,
|
|
77
|
-
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
|
|
77
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
|
|
78
78
|
options: Partial<{
|
|
79
79
|
gasPrice: BigNumberish;
|
|
80
80
|
gasUnits: BigNumberish;
|
|
@@ -124,7 +124,7 @@ export class QueryBase implements QueryInterface {
|
|
|
124
124
|
*/
|
|
125
125
|
getUnsignedTxFromDeposit(
|
|
126
126
|
deposit: Omit<Deposit, "messageHash">,
|
|
127
|
-
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
127
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
|
|
128
128
|
): Promise<PopulatedTransaction> {
|
|
129
129
|
return populateV3Relay(this.spokePool, deposit, relayer);
|
|
130
130
|
}
|
|
@@ -137,7 +137,7 @@ export class QueryBase implements QueryInterface {
|
|
|
137
137
|
*/
|
|
138
138
|
async getNativeGasCost(
|
|
139
139
|
deposit: Omit<Deposit, "messageHash">,
|
|
140
|
-
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
140
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
|
|
141
141
|
): Promise<BigNumber> {
|
|
142
142
|
const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
|
|
143
143
|
const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
|
|
@@ -154,7 +154,7 @@ export class QueryBase implements QueryInterface {
|
|
|
154
154
|
*/
|
|
155
155
|
async getOpStackL1DataFee(
|
|
156
156
|
unsignedTx: PopulatedTransaction,
|
|
157
|
-
relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId)),
|
|
157
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId), unsignedTx.chainId),
|
|
158
158
|
options: Partial<{
|
|
159
159
|
opStackL2GasUnits: BigNumberish;
|
|
160
160
|
opStackL1DataFeeMultiplier: BigNumber;
|