@across-protocol/sdk 4.3.3 → 4.3.5
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/svm/SpokeUtils.d.ts +13 -5
- package/dist/cjs/arch/svm/SpokeUtils.js +74 -5
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +6 -1
- package/dist/cjs/arch/svm/utils.js +67 -1
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +22 -16
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +45 -19
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +4 -3
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +1 -1
- package/dist/cjs/interfaces/SpokePool.d.ts +18 -0
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +2 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +7 -68
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +2 -0
- package/dist/cjs/utils/AddressUtils.js +4 -0
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.d.ts +3 -1
- package/dist/cjs/utils/DepositUtils.js +9 -1
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +23 -5
- package/dist/esm/arch/svm/SpokeUtils.js +86 -5
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +20 -1
- package/dist/esm/arch/svm/utils.js +76 -1
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +24 -18
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +55 -32
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +5 -4
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +1 -1
- package/dist/esm/interfaces/SpokePool.d.ts +18 -0
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +2 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +9 -73
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +2 -0
- package/dist/esm/utils/AddressUtils.js +4 -0
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.d.ts +15 -1
- package/dist/esm/utils/DepositUtils.js +19 -1
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +23 -5
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +20 -1
- package/dist/types/arch/svm/utils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +18 -0
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +2 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +2 -0
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/DepositUtils.d.ts +15 -1
- package/dist/types/utils/DepositUtils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/arch/svm/SpokeUtils.ts +97 -6
- package/src/arch/svm/utils.ts +61 -1
- package/src/clients/BundleDataClient/BundleDataClient.ts +12 -6
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +52 -29
- package/src/clients/mocks/MockSvmCpiEventsClient.ts +5 -3
- package/src/interfaces/SpokePool.ts +23 -0
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +7 -93
- package/src/utils/AddressUtils.ts +5 -0
- package/src/utils/DepositUtils.ts +49 -1
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
5
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, fetchMint } from "@solana-program/token";
|
|
6
|
-
import { getComputeUnitEstimateForTransactionMessageFactory } from "@solana/kit";
|
|
7
|
-
import {
|
|
8
|
-
SVMProvider,
|
|
9
|
-
SolanaVoidSigner,
|
|
10
|
-
createFillInstruction,
|
|
11
|
-
getAssociatedTokenAddress,
|
|
12
|
-
getEventAuthority,
|
|
13
|
-
getFillRelayDelegatePda,
|
|
14
|
-
getFillStatusPda,
|
|
15
|
-
getStatePda,
|
|
16
|
-
toAddress,
|
|
17
|
-
} from "../../arch/svm";
|
|
2
|
+
import { getComputeUnitEstimateForTransactionMessageFactory, TransactionSigner } from "@solana/kit";
|
|
3
|
+
import { SVMProvider, SolanaVoidSigner, getFillRelayTx } from "../../arch/svm";
|
|
18
4
|
import { Coingecko } from "../../coingecko";
|
|
19
5
|
import { CHAIN_IDs } from "../../constants";
|
|
20
6
|
import { getGasPriceEstimate } from "../../gasPriceOracle";
|
|
21
7
|
import { RelayData } from "../../interfaces";
|
|
22
|
-
import {
|
|
23
|
-
Address,
|
|
24
|
-
BigNumber,
|
|
25
|
-
BigNumberish,
|
|
26
|
-
SvmAddress,
|
|
27
|
-
TransactionCostEstimate,
|
|
28
|
-
getRelayDataHash,
|
|
29
|
-
toBN,
|
|
30
|
-
} from "../../utils";
|
|
8
|
+
import { Address, BigNumber, BigNumberish, SvmAddress, TransactionCostEstimate, toBN } from "../../utils";
|
|
31
9
|
import { Logger, QueryInterface, getDefaultRelayer } from "../relayFeeCalculator";
|
|
32
10
|
import { SymbolMappingType } from "./";
|
|
33
11
|
|
|
@@ -93,7 +71,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
93
71
|
const [repaymentChainId, repaymentAddress] = [destinationChainId, relayer]; // These are not important for gas cost simulation.
|
|
94
72
|
const fillRelayTx = await this.getFillRelayTx(
|
|
95
73
|
{ ...relayData, recipient, outputToken, exclusiveRelayer },
|
|
96
|
-
relayer,
|
|
74
|
+
SolanaVoidSigner(relayer.toBase58()),
|
|
97
75
|
repaymentChainId,
|
|
98
76
|
repaymentAddress
|
|
99
77
|
);
|
|
@@ -139,7 +117,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
139
117
|
const [repaymentChainId, repaymentAddress] = [destinationChainId, relayer]; // These are not important for gas cost simulation.
|
|
140
118
|
const fillRelayTx = await this.getFillRelayTx(
|
|
141
119
|
{ ...deposit, recipient, outputToken, exclusiveRelayer },
|
|
142
|
-
relayer,
|
|
120
|
+
SolanaVoidSigner(relayer.toBase58()),
|
|
143
121
|
repaymentChainId,
|
|
144
122
|
repaymentAddress
|
|
145
123
|
);
|
|
@@ -158,75 +136,11 @@ export class SvmQuery implements QueryInterface {
|
|
|
158
136
|
recipient: SvmAddress;
|
|
159
137
|
outputToken: SvmAddress;
|
|
160
138
|
},
|
|
161
|
-
|
|
139
|
+
signer: TransactionSigner,
|
|
162
140
|
repaymentChainId: number,
|
|
163
141
|
repaymentAddress: Address
|
|
164
142
|
) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// tsc appeasement...should be unnecessary, but isn't. @todo Identify why.
|
|
168
|
-
assert(recipient.isSVM(), `getFillRelayTx: recipient not an SVM address (${recipient})`);
|
|
169
|
-
assert(
|
|
170
|
-
repaymentAddress.isValidOn(repaymentChainId),
|
|
171
|
-
`getFillRelayTx: repayment address ${repaymentAddress} not valid on chain ${repaymentChainId})`
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const program = toAddress(this.spokePool);
|
|
175
|
-
const _relayDataHash = getRelayDataHash(relayData, destinationChainId);
|
|
176
|
-
const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
|
|
177
|
-
|
|
178
|
-
const [state, delegate] = await Promise.all([
|
|
179
|
-
getStatePda(program),
|
|
180
|
-
getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), toAddress(repaymentAddress), program),
|
|
181
|
-
]);
|
|
182
|
-
|
|
183
|
-
const mint = toAddress(outputToken);
|
|
184
|
-
const mintInfo = await fetchMint(this.provider, mint);
|
|
185
|
-
|
|
186
|
-
const [recipientAta, relayerAta, fillStatus, eventAuthority] = await Promise.all([
|
|
187
|
-
getAssociatedTokenAddress(recipient, outputToken, mintInfo.programAddress),
|
|
188
|
-
getAssociatedTokenAddress(SvmAddress.from(relayer.toBase58()), outputToken, mintInfo.programAddress),
|
|
189
|
-
getFillStatusPda(program, relayData, destinationChainId),
|
|
190
|
-
getEventAuthority(program),
|
|
191
|
-
]);
|
|
192
|
-
|
|
193
|
-
const svmRelayData: SvmSpokeClient.FillRelayInput["relayData"] = {
|
|
194
|
-
depositor: toAddress(depositor),
|
|
195
|
-
recipient: toAddress(recipient),
|
|
196
|
-
exclusiveRelayer: toAddress(exclusiveRelayer),
|
|
197
|
-
inputToken: toAddress(inputToken),
|
|
198
|
-
outputToken: mint,
|
|
199
|
-
inputAmount: relayData.inputAmount.toBigInt(),
|
|
200
|
-
outputAmount: relayData.outputAmount.toBigInt(),
|
|
201
|
-
originChainId: relayData.originChainId,
|
|
202
|
-
depositId: new Uint8Array(intToU8Array32(relayData.depositId.toNumber())),
|
|
203
|
-
fillDeadline: relayData.fillDeadline,
|
|
204
|
-
exclusivityDeadline: relayData.exclusivityDeadline,
|
|
205
|
-
message: new Uint8Array(Buffer.from(relayData.message, "hex")),
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const simulatedSigner = SolanaVoidSigner(relayer.toBase58());
|
|
209
|
-
const fillInput: SvmSpokeClient.FillRelayInput = {
|
|
210
|
-
signer: simulatedSigner,
|
|
211
|
-
state,
|
|
212
|
-
delegate,
|
|
213
|
-
mint,
|
|
214
|
-
relayerTokenAccount: relayerAta,
|
|
215
|
-
recipientTokenAccount: recipientAta,
|
|
216
|
-
fillStatus,
|
|
217
|
-
tokenProgram: mintInfo.programAddress,
|
|
218
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
219
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
220
|
-
eventAuthority,
|
|
221
|
-
program,
|
|
222
|
-
relayHash: relayDataHash,
|
|
223
|
-
relayData: svmRelayData,
|
|
224
|
-
repaymentChainId: BigInt(repaymentChainId),
|
|
225
|
-
repaymentAddress: toAddress(repaymentAddress),
|
|
226
|
-
};
|
|
227
|
-
// Pass createRecipientAtaIfNeeded =true to the createFillInstruction function to create the recipient token account
|
|
228
|
-
// if it doesn't exist.
|
|
229
|
-
return createFillInstruction(simulatedSigner, this.provider, fillInput, mintInfo.data.decimals, true);
|
|
143
|
+
return await getFillRelayTx(this.spokePool, this.provider, relayData, signer, repaymentChainId, repaymentAddress);
|
|
230
144
|
}
|
|
231
145
|
|
|
232
146
|
/**
|
|
@@ -90,6 +90,7 @@ export function toAddressType(address: string, chainId: number): Address {
|
|
|
90
90
|
// The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
|
|
91
91
|
// which for this class, is a bytes32 hex string.
|
|
92
92
|
export abstract class Address {
|
|
93
|
+
readonly __address_type_brand = true;
|
|
93
94
|
readonly rawAddress: Uint8Array;
|
|
94
95
|
|
|
95
96
|
// Keep all address types in cache so that we may lazily evaluate them when necessary.
|
|
@@ -109,6 +110,10 @@ export abstract class Address {
|
|
|
109
110
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
static isAddress(obj: unknown): obj is Address {
|
|
114
|
+
return "__address_type_brand" in (obj as { __address_type_brand: boolean });
|
|
115
|
+
}
|
|
116
|
+
|
|
112
117
|
// Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
|
|
113
118
|
// throw since address length validation was done at construction time.
|
|
114
119
|
toBytes32(): string {
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import { SpokePoolClient } from "../clients";
|
|
3
3
|
import { DEFAULT_CACHING_TTL, EMPTY_MESSAGE, UNDEFINED_MESSAGE_HASH, ZERO_BYTES } from "../constants";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CachingMechanismInterface,
|
|
6
|
+
Deposit,
|
|
7
|
+
DepositWithBlock,
|
|
8
|
+
Fill,
|
|
9
|
+
RelayData,
|
|
10
|
+
SlowFillRequest,
|
|
11
|
+
ConvertedRelayData,
|
|
12
|
+
ConvertedFill,
|
|
13
|
+
} from "../interfaces";
|
|
5
14
|
import { getMessageHash, isUnsafeDepositId } from "./SpokeUtils";
|
|
6
15
|
import { getNetworkName } from "./NetworkUtils";
|
|
7
16
|
import { bnZero } from "./BigNumberUtils";
|
|
@@ -251,3 +260,42 @@ export function resolveDepositMessage(deposit: Deposit): string {
|
|
|
251
260
|
assert(isDefined(message)); // Appease tsc about the updatedMessage being possibly undefined.
|
|
252
261
|
return message;
|
|
253
262
|
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Converts a RelayData object with `Address` types as address fields to a `RelayData`-like object with
|
|
266
|
+
* strings as address fields.
|
|
267
|
+
* @param relayData RelayData type.
|
|
268
|
+
* @returns a RelayData-like type which has strings as fields.
|
|
269
|
+
*/
|
|
270
|
+
export function convertRelayDataParamsToBytes32(relayData: RelayData): ConvertedRelayData {
|
|
271
|
+
return {
|
|
272
|
+
...relayData,
|
|
273
|
+
depositor: relayData.depositor.toBytes32(),
|
|
274
|
+
recipient: relayData.recipient.toBytes32(),
|
|
275
|
+
inputToken: relayData.inputToken.toBytes32(),
|
|
276
|
+
outputToken: relayData.outputToken.toBytes32(),
|
|
277
|
+
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Converts a Fill object with `Address` types as address fields to a `RelayData`-like object with
|
|
283
|
+
* strings as address fields.
|
|
284
|
+
* @param relayData RelayData type.
|
|
285
|
+
* @returns a RelayData-like type which has strings as fields.
|
|
286
|
+
*/
|
|
287
|
+
export function convertFillParamsToBytes32(fill: Fill): ConvertedFill {
|
|
288
|
+
return {
|
|
289
|
+
...fill,
|
|
290
|
+
depositor: fill.depositor.toBytes32(),
|
|
291
|
+
recipient: fill.recipient.toBytes32(),
|
|
292
|
+
inputToken: fill.inputToken.toBytes32(),
|
|
293
|
+
outputToken: fill.outputToken.toBytes32(),
|
|
294
|
+
exclusiveRelayer: fill.exclusiveRelayer.toBytes32(),
|
|
295
|
+
relayer: fill.relayer.toBytes32(),
|
|
296
|
+
relayExecutionInfo: {
|
|
297
|
+
...fill.relayExecutionInfo,
|
|
298
|
+
updatedRecipient: fill.relayExecutionInfo.updatedRecipient.toBytes32(),
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
}
|