@sodax/sdk 0.0.1-rc.24 → 0.0.1-rc.26
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/index.cjs +565 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -6
- package/dist/index.d.ts +67 -6
- package/dist/index.mjs +564 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getAbiItem, encodeAbiParameters, parseAbiParameters, toHex, erc20Abi as erc20Abi$1, encodeFunctionData, fromHex, createPublicClient, http, decodeAbiParameters, encodePacked, parseEventLogs, keccak256, isAddress } from 'viem';
|
|
2
|
-
import
|
|
2
|
+
import invariant11 from 'tiny-invariant';
|
|
3
3
|
import { bcs } from '@mysten/sui/bcs';
|
|
4
4
|
import { PublicKey, Connection, VersionedTransaction, SystemProgram, ComputeBudgetProgram } from '@solana/web3.js';
|
|
5
5
|
import { SorobanRpc, Address, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Operation, Account, FeeBumpTransaction } from '@stellar/stellar-sdk';
|
|
@@ -6141,16 +6141,16 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
6141
6141
|
if (!fee) {
|
|
6142
6142
|
return 0n;
|
|
6143
6143
|
}
|
|
6144
|
-
|
|
6144
|
+
invariant11(inputAmount > 0n, "Input amount must be greater than 0");
|
|
6145
6145
|
let feeAmount = 0n;
|
|
6146
6146
|
if (isPartnerFeeAmount(fee)) {
|
|
6147
|
-
|
|
6147
|
+
invariant11(
|
|
6148
6148
|
fee.amount >= 0 && fee.amount <= inputAmount,
|
|
6149
6149
|
`Fee amount must be greater than 0 and less than or equal to the input amount: ${fee.amount}`
|
|
6150
6150
|
);
|
|
6151
6151
|
feeAmount = fee.amount;
|
|
6152
6152
|
} else if (isPartnerFeePercentage(fee)) {
|
|
6153
|
-
|
|
6153
|
+
invariant11(
|
|
6154
6154
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
6155
6155
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
6156
6156
|
);
|
|
@@ -6159,8 +6159,8 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
6159
6159
|
return feeAmount;
|
|
6160
6160
|
}
|
|
6161
6161
|
function adjustAmountByFee(amount, fee, quoteType) {
|
|
6162
|
-
|
|
6163
|
-
|
|
6162
|
+
invariant11(amount > 0n, "Amount must be greater than 0");
|
|
6163
|
+
invariant11(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
|
|
6164
6164
|
if (quoteType === "exact_input") {
|
|
6165
6165
|
return amount - calculateFeeAmount(amount, fee);
|
|
6166
6166
|
}
|
|
@@ -6303,6 +6303,7 @@ var hubChainConfig = {
|
|
|
6303
6303
|
sodaToken: "0x7c7d53eecda37a87ce0d5bf8e0b24512a48dc963"
|
|
6304
6304
|
},
|
|
6305
6305
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
6306
|
+
wrappedNativeToken: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38",
|
|
6306
6307
|
supportedTokens: []
|
|
6307
6308
|
}
|
|
6308
6309
|
};
|
|
@@ -6799,6 +6800,7 @@ var spokeChainConfig = {
|
|
|
6799
6800
|
[SUI_MAINNET_CHAIN_ID]: {
|
|
6800
6801
|
addresses: {
|
|
6801
6802
|
connection: "0xf3b1e696a66d02cb776dc15aae73c68bc8f03adcb6ba0ec7f6332d9d90a6a3d2::connectionv3::0x3ee76d13909ac58ae13baab4c9be5a5142818d9a387aed641825e5d4356969bf",
|
|
6803
|
+
assetManagerId: "0xa17a409164d1676db71b411ab50813ba2c7dd547d2df538c699049566f1ff922::asset_manager::0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
|
|
6802
6804
|
assetManager: "0x897f911a4b7691870a1a2513af7e85fdee8de275615c77068fd8b90b8e78c678::asset_manager::0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
|
|
6803
6805
|
xTokenManager: "",
|
|
6804
6806
|
rateLimit: "",
|
|
@@ -9222,6 +9224,32 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
9222
9224
|
args: [token]
|
|
9223
9225
|
});
|
|
9224
9226
|
}
|
|
9227
|
+
/**
|
|
9228
|
+
* Generate simulation parameters for deposit from EvmSpokeDepositParams.
|
|
9229
|
+
* @param {EvmSpokeDepositParams} params - The deposit parameters.
|
|
9230
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9231
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9232
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9233
|
+
*/
|
|
9234
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9235
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9236
|
+
spokeProvider.chainConfig.chain.id,
|
|
9237
|
+
params.from,
|
|
9238
|
+
hubProvider
|
|
9239
|
+
);
|
|
9240
|
+
return {
|
|
9241
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9242
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9243
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9244
|
+
to,
|
|
9245
|
+
amount: params.amount,
|
|
9246
|
+
data: params.data,
|
|
9247
|
+
srcAddress: encodeAddress(
|
|
9248
|
+
spokeProvider.chainConfig.chain.id,
|
|
9249
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9250
|
+
)
|
|
9251
|
+
};
|
|
9252
|
+
}
|
|
9225
9253
|
/**
|
|
9226
9254
|
* Calls a contract on the spoke chain using the user's wallet.
|
|
9227
9255
|
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
@@ -9344,6 +9372,32 @@ var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
|
9344
9372
|
raw
|
|
9345
9373
|
);
|
|
9346
9374
|
}
|
|
9375
|
+
/**
|
|
9376
|
+
* Generate simulation parameters for deposit from InjectiveSpokeDepositParams.
|
|
9377
|
+
* @param {InjectiveSpokeDepositParams} params - The deposit parameters.
|
|
9378
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9379
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9380
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9381
|
+
*/
|
|
9382
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9383
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9384
|
+
spokeProvider.chainConfig.chain.id,
|
|
9385
|
+
toHex(Buffer.from(params.from, "utf-8")),
|
|
9386
|
+
hubProvider
|
|
9387
|
+
);
|
|
9388
|
+
return {
|
|
9389
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9390
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9391
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9392
|
+
to,
|
|
9393
|
+
amount: params.amount,
|
|
9394
|
+
data: params.data,
|
|
9395
|
+
srcAddress: encodeAddress(
|
|
9396
|
+
spokeProvider.chainConfig.chain.id,
|
|
9397
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9398
|
+
)
|
|
9399
|
+
};
|
|
9400
|
+
}
|
|
9347
9401
|
/**
|
|
9348
9402
|
* Get the balance of the token that deposited in the spoke chain Asset Manager.
|
|
9349
9403
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -9481,6 +9535,32 @@ var IconSpokeService = class _IconSpokeService {
|
|
|
9481
9535
|
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9482
9536
|
return _IconSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
9483
9537
|
}
|
|
9538
|
+
/**
|
|
9539
|
+
* Generate simulation parameters for deposit from IconSpokeDepositParams.
|
|
9540
|
+
* @param {IconSpokeDepositParams} params - The deposit parameters.
|
|
9541
|
+
* @param {IconSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9542
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9543
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9544
|
+
*/
|
|
9545
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9546
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9547
|
+
spokeProvider.chainConfig.chain.id,
|
|
9548
|
+
getIconAddressBytes(params.from),
|
|
9549
|
+
hubProvider
|
|
9550
|
+
);
|
|
9551
|
+
return {
|
|
9552
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9553
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9554
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9555
|
+
to,
|
|
9556
|
+
amount: params.amount,
|
|
9557
|
+
data: params.data,
|
|
9558
|
+
srcAddress: encodeAddress(
|
|
9559
|
+
spokeProvider.chainConfig.chain.id,
|
|
9560
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9561
|
+
)
|
|
9562
|
+
};
|
|
9563
|
+
}
|
|
9484
9564
|
/**
|
|
9485
9565
|
* Transfers tokens to the hub chain.
|
|
9486
9566
|
*/
|
|
@@ -9681,6 +9761,32 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
9681
9761
|
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9682
9762
|
return _SolanaSpokeService.call(BigInt(relayId), from, keccak256(payload), spokeProvider, raw);
|
|
9683
9763
|
}
|
|
9764
|
+
/**
|
|
9765
|
+
* Generate simulation parameters for deposit from SolanaSpokeDepositParams.
|
|
9766
|
+
* @param {SolanaSpokeDepositParams} params - The deposit parameters.
|
|
9767
|
+
* @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9768
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9769
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9770
|
+
*/
|
|
9771
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9772
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9773
|
+
spokeProvider.chainConfig.chain.id,
|
|
9774
|
+
encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9775
|
+
hubProvider
|
|
9776
|
+
);
|
|
9777
|
+
return {
|
|
9778
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9779
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9780
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9781
|
+
to,
|
|
9782
|
+
amount: params.amount,
|
|
9783
|
+
data: params.data,
|
|
9784
|
+
srcAddress: encodeAddress(
|
|
9785
|
+
spokeProvider.chainConfig.chain.id,
|
|
9786
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9787
|
+
)
|
|
9788
|
+
};
|
|
9789
|
+
}
|
|
9684
9790
|
static async transfer({ token, recipient, amount, data }, spokeProvider, raw) {
|
|
9685
9791
|
let depositInstruction;
|
|
9686
9792
|
const amountBN = new BN(amount);
|
|
@@ -9849,6 +9955,32 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
9849
9955
|
static async getDeposit(token, spokeProvider) {
|
|
9850
9956
|
return BigInt(await spokeProvider.getBalance(token));
|
|
9851
9957
|
}
|
|
9958
|
+
/**
|
|
9959
|
+
* Generate simulation parameters for deposit from StellarSpokeDepositParams.
|
|
9960
|
+
* @param {StellarSpokeDepositParams} params - The deposit parameters.
|
|
9961
|
+
* @param {StellarSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9962
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9963
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9964
|
+
*/
|
|
9965
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9966
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9967
|
+
spokeProvider.chainConfig.chain.id,
|
|
9968
|
+
params.from,
|
|
9969
|
+
hubProvider
|
|
9970
|
+
);
|
|
9971
|
+
return {
|
|
9972
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9973
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9974
|
+
from: params.from,
|
|
9975
|
+
to,
|
|
9976
|
+
amount: params.amount,
|
|
9977
|
+
data: params.data,
|
|
9978
|
+
srcAddress: encodeAddress(
|
|
9979
|
+
spokeProvider.chainConfig.chain.id,
|
|
9980
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9981
|
+
)
|
|
9982
|
+
};
|
|
9983
|
+
}
|
|
9852
9984
|
/**
|
|
9853
9985
|
* Calls a contract on the spoke chain using the user's wallet.
|
|
9854
9986
|
* @param from - The address of the user on the hub chain.
|
|
@@ -9931,6 +10063,30 @@ var SuiSpokeService = class _SuiSpokeService {
|
|
|
9931
10063
|
static async getDeposit(token, spokeProvider) {
|
|
9932
10064
|
return spokeProvider.getBalance(token);
|
|
9933
10065
|
}
|
|
10066
|
+
/**
|
|
10067
|
+
* Generate simulation parameters for deposit from SuiSpokeDepositParams.
|
|
10068
|
+
* @param {SuiSpokeDepositParams} params - The deposit parameters.
|
|
10069
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10070
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10071
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
10072
|
+
*/
|
|
10073
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
10074
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
10075
|
+
spokeProvider.chainConfig.chain.id,
|
|
10076
|
+
params.from,
|
|
10077
|
+
hubProvider
|
|
10078
|
+
);
|
|
10079
|
+
const encoder = new TextEncoder();
|
|
10080
|
+
return {
|
|
10081
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
10082
|
+
token: toHex(encoder.encode(params.token)),
|
|
10083
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
10084
|
+
to,
|
|
10085
|
+
amount: params.amount,
|
|
10086
|
+
data: params.data,
|
|
10087
|
+
srcAddress: toHex(encoder.encode(spokeProvider.chainConfig.addresses.assetManagerId))
|
|
10088
|
+
};
|
|
10089
|
+
}
|
|
9934
10090
|
/**
|
|
9935
10091
|
* Calls a contract on the spoke chain using the user's wallet.
|
|
9936
10092
|
* @param {HubAddress} from - The address of the user on the spoke chain.
|
|
@@ -10085,6 +10241,58 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10085
10241
|
}
|
|
10086
10242
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
10087
10243
|
}
|
|
10244
|
+
static async createSwapIntent(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, spokeProvider, hubProvider, raw) {
|
|
10245
|
+
let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
|
|
10246
|
+
if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
10247
|
+
inputToken = hubProvider.chainConfig.nativeToken;
|
|
10248
|
+
}
|
|
10249
|
+
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
10250
|
+
invariant11(
|
|
10251
|
+
inputToken,
|
|
10252
|
+
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
10253
|
+
);
|
|
10254
|
+
invariant11(
|
|
10255
|
+
outputToken,
|
|
10256
|
+
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
10257
|
+
);
|
|
10258
|
+
const [feeData, feeAmount] = EvmSolverService.createIntentFeeData(fee, createIntentParams.inputAmount);
|
|
10259
|
+
const intentsContract = solverConfig2.intentsContract;
|
|
10260
|
+
const intent = {
|
|
10261
|
+
...createIntentParams,
|
|
10262
|
+
inputToken,
|
|
10263
|
+
outputToken,
|
|
10264
|
+
inputAmount: createIntentParams.inputAmount - feeAmount,
|
|
10265
|
+
srcChain: getIntentRelayChainId(createIntentParams.srcChain),
|
|
10266
|
+
dstChain: getIntentRelayChainId(createIntentParams.dstChain),
|
|
10267
|
+
srcAddress: encodeAddress(createIntentParams.srcChain, createIntentParams.srcAddress),
|
|
10268
|
+
dstAddress: encodeAddress(createIntentParams.dstChain, createIntentParams.dstAddress),
|
|
10269
|
+
intentId: randomUint256(),
|
|
10270
|
+
creator: creatorHubWalletAddress,
|
|
10271
|
+
data: feeData
|
|
10272
|
+
// fee amount will be deducted from the input amount
|
|
10273
|
+
};
|
|
10274
|
+
const txData = EvmSolverService.encodeCreateIntent(intent, intentsContract);
|
|
10275
|
+
const rawTx = {
|
|
10276
|
+
from: await spokeProvider.walletProvider.getWalletAddress(),
|
|
10277
|
+
to: txData.address,
|
|
10278
|
+
data: txData.data,
|
|
10279
|
+
value: createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase() ? createIntentParams.inputAmount : 0n
|
|
10280
|
+
};
|
|
10281
|
+
if (raw) {
|
|
10282
|
+
return [
|
|
10283
|
+
rawTx,
|
|
10284
|
+
intent,
|
|
10285
|
+
feeAmount,
|
|
10286
|
+
txData.data
|
|
10287
|
+
];
|
|
10288
|
+
}
|
|
10289
|
+
return [
|
|
10290
|
+
await spokeProvider.walletProvider.sendTransaction(rawTx),
|
|
10291
|
+
intent,
|
|
10292
|
+
feeAmount,
|
|
10293
|
+
txData.data
|
|
10294
|
+
];
|
|
10295
|
+
}
|
|
10088
10296
|
/**
|
|
10089
10297
|
* Get the balance of the token in the spoke chain.
|
|
10090
10298
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -10446,9 +10654,7 @@ function isBalnMigrateParams(value) {
|
|
|
10446
10654
|
function isIcxCreateRevertMigrationParams(value) {
|
|
10447
10655
|
return typeof value === "object" && value !== null && "amount" in value && "to" in value;
|
|
10448
10656
|
}
|
|
10449
|
-
|
|
10450
|
-
// src/services/spoke/SpokeService.ts
|
|
10451
|
-
var SpokeService = class {
|
|
10657
|
+
var SpokeService = class _SpokeService {
|
|
10452
10658
|
constructor() {
|
|
10453
10659
|
}
|
|
10454
10660
|
/**
|
|
@@ -10502,14 +10708,99 @@ var SpokeService = class {
|
|
|
10502
10708
|
}
|
|
10503
10709
|
throw new Error("Invalid spoke provider");
|
|
10504
10710
|
}
|
|
10711
|
+
/**
|
|
10712
|
+
|
|
10713
|
+
* Encodes transfer data using RLP encoding to match Solidity Transfer struct.
|
|
10714
|
+
* @param {Hex} token - The token contract address.
|
|
10715
|
+
* @param {Hex} from - The sender address.
|
|
10716
|
+
* @param {Hex} to - The recipient address.
|
|
10717
|
+
* @param {bigint} amount - The transfer amount.
|
|
10718
|
+
* @param {Hex} data - The encoded data payload.
|
|
10719
|
+
* @returns {Promise<Hex>} A promise that resolves to the RLP encoded transfer data.
|
|
10720
|
+
*/
|
|
10721
|
+
static encodeTransfer(token, from, to, amount, data) {
|
|
10722
|
+
const rlpInput = [
|
|
10723
|
+
token,
|
|
10724
|
+
// token (bytes)
|
|
10725
|
+
from,
|
|
10726
|
+
// from (bytes)
|
|
10727
|
+
to,
|
|
10728
|
+
// to (bytes)
|
|
10729
|
+
amount,
|
|
10730
|
+
// amount (uint256)
|
|
10731
|
+
data
|
|
10732
|
+
// data (bytes)
|
|
10733
|
+
];
|
|
10734
|
+
const rlpEncodedData = rlp.encode(rlpInput);
|
|
10735
|
+
return `0x${Buffer.from(rlpEncodedData).toString("hex")}`;
|
|
10736
|
+
}
|
|
10737
|
+
static async simulateDeposit(params, hubProvider) {
|
|
10738
|
+
const chainId = getIntentRelayChainId(params.spokeChainID);
|
|
10739
|
+
const hubAssetManager = hubProvider.chainConfig.addresses.assetManager;
|
|
10740
|
+
const payload = _SpokeService.encodeTransfer(params.token, params.from, params.to, params.amount, params.data);
|
|
10741
|
+
return _SpokeService.simulateRecvMessage(
|
|
10742
|
+
{ target: hubAssetManager, srcChainId: chainId, srcAddress: params.srcAddress, payload },
|
|
10743
|
+
hubProvider
|
|
10744
|
+
);
|
|
10745
|
+
}
|
|
10746
|
+
/**
|
|
10747
|
+
* Simulates receiving a message without signature verification.
|
|
10748
|
+
* This function calls simulateRecvMessage which always reverts with 'Simulation completed'.
|
|
10749
|
+
* @param {bigint} srcChainId - The chain ID of the originating chain.
|
|
10750
|
+
* @param {Hex} srcAddress - The address of the sender on the originating chain.
|
|
10751
|
+
* @param {Hex} payload - The encoded payload containing call data (from encodeTransfer).
|
|
10752
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10753
|
+
* @returns {Promise<{ success: boolean; error?: string }>} Result of the simulation.
|
|
10754
|
+
*/
|
|
10755
|
+
static async simulateRecvMessage(params, hubProvider) {
|
|
10756
|
+
try {
|
|
10757
|
+
const result = await hubProvider.publicClient.call({
|
|
10758
|
+
to: params.target,
|
|
10759
|
+
data: encodeFunctionData({
|
|
10760
|
+
abi: [
|
|
10761
|
+
{
|
|
10762
|
+
name: "simulateRecvMessage",
|
|
10763
|
+
type: "function",
|
|
10764
|
+
stateMutability: "nonpayable",
|
|
10765
|
+
inputs: [
|
|
10766
|
+
{ name: "srcChainId", type: "uint256" },
|
|
10767
|
+
{ name: "srcAddress", type: "bytes" },
|
|
10768
|
+
{ name: "payload", type: "bytes" }
|
|
10769
|
+
],
|
|
10770
|
+
outputs: []
|
|
10771
|
+
}
|
|
10772
|
+
],
|
|
10773
|
+
functionName: "simulateRecvMessage",
|
|
10774
|
+
args: [params.srcChainId, params.srcAddress, params.payload]
|
|
10775
|
+
})
|
|
10776
|
+
});
|
|
10777
|
+
console.warn("simulateRecvMessage did not revert as expected", { result });
|
|
10778
|
+
return {
|
|
10779
|
+
success: false,
|
|
10780
|
+
error: 'Function should have reverted with "Simulation completed"'
|
|
10781
|
+
};
|
|
10782
|
+
} catch (error) {
|
|
10783
|
+
if (error instanceof Error && error.message?.includes("Simulation completed")) {
|
|
10784
|
+
console.warn("simulateRecvMessage completed successfully with expected revert");
|
|
10785
|
+
return { success: true };
|
|
10786
|
+
}
|
|
10787
|
+
console.error("simulateRecvMessage failed with unexpected error:", error);
|
|
10788
|
+
return {
|
|
10789
|
+
success: false,
|
|
10790
|
+
error: error instanceof Error ? error.message || "Unknown simulation error" : "Unknown simulation error"
|
|
10791
|
+
};
|
|
10792
|
+
}
|
|
10793
|
+
}
|
|
10505
10794
|
/**
|
|
10506
10795
|
* Deposit tokens to the spoke chain.
|
|
10507
10796
|
* @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
10508
10797
|
* @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10509
10798
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10799
|
+
* @param {boolean} raw - Whether to return raw transaction data.
|
|
10800
|
+
* @param {boolean} skipSimulation - Whether to skip deposit simulation (optional, defaults to false).
|
|
10510
10801
|
* @returns {Promise<Hash>} A promise that resolves to the transaction hash.
|
|
10511
10802
|
*/
|
|
10512
|
-
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
10803
|
+
static async deposit(params, spokeProvider, hubProvider, raw, skipSimulation = false) {
|
|
10513
10804
|
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
10514
10805
|
return SonicSpokeService.deposit(
|
|
10515
10806
|
params,
|
|
@@ -10518,6 +10809,7 @@ var SpokeService = class {
|
|
|
10518
10809
|
);
|
|
10519
10810
|
}
|
|
10520
10811
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10812
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10521
10813
|
return EvmSpokeService.deposit(
|
|
10522
10814
|
params,
|
|
10523
10815
|
spokeProvider,
|
|
@@ -10526,14 +10818,11 @@ var SpokeService = class {
|
|
|
10526
10818
|
);
|
|
10527
10819
|
}
|
|
10528
10820
|
if (spokeProvider instanceof InjectiveSpokeProvider) {
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
spokeProvider,
|
|
10532
|
-
hubProvider,
|
|
10533
|
-
raw
|
|
10534
|
-
);
|
|
10821
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10822
|
+
return InjectiveSpokeService.deposit(params, spokeProvider, hubProvider, raw);
|
|
10535
10823
|
}
|
|
10536
10824
|
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10825
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10537
10826
|
return IconSpokeService.deposit(
|
|
10538
10827
|
params,
|
|
10539
10828
|
spokeProvider,
|
|
@@ -10542,6 +10831,7 @@ var SpokeService = class {
|
|
|
10542
10831
|
);
|
|
10543
10832
|
}
|
|
10544
10833
|
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10834
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10545
10835
|
return SuiSpokeService.deposit(
|
|
10546
10836
|
params,
|
|
10547
10837
|
spokeProvider,
|
|
@@ -10550,6 +10840,7 @@ var SpokeService = class {
|
|
|
10550
10840
|
);
|
|
10551
10841
|
}
|
|
10552
10842
|
if (spokeProvider instanceof SolanaSpokeProvider) {
|
|
10843
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10553
10844
|
return SolanaSpokeService.deposit(
|
|
10554
10845
|
params,
|
|
10555
10846
|
spokeProvider,
|
|
@@ -10558,6 +10849,7 @@ var SpokeService = class {
|
|
|
10558
10849
|
);
|
|
10559
10850
|
}
|
|
10560
10851
|
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10852
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10561
10853
|
return StellarSpokeService.deposit(
|
|
10562
10854
|
params,
|
|
10563
10855
|
spokeProvider,
|
|
@@ -10567,6 +10859,60 @@ var SpokeService = class {
|
|
|
10567
10859
|
}
|
|
10568
10860
|
throw new Error("Invalid spoke provider");
|
|
10569
10861
|
}
|
|
10862
|
+
static getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
10863
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10864
|
+
return EvmSpokeService.getSimulateDepositParams(
|
|
10865
|
+
params,
|
|
10866
|
+
spokeProvider,
|
|
10867
|
+
hubProvider
|
|
10868
|
+
);
|
|
10869
|
+
}
|
|
10870
|
+
if (spokeProvider instanceof InjectiveSpokeProvider) {
|
|
10871
|
+
return InjectiveSpokeService.getSimulateDepositParams(
|
|
10872
|
+
params,
|
|
10873
|
+
spokeProvider,
|
|
10874
|
+
hubProvider
|
|
10875
|
+
);
|
|
10876
|
+
}
|
|
10877
|
+
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10878
|
+
return IconSpokeService.getSimulateDepositParams(
|
|
10879
|
+
params,
|
|
10880
|
+
spokeProvider,
|
|
10881
|
+
hubProvider
|
|
10882
|
+
);
|
|
10883
|
+
}
|
|
10884
|
+
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10885
|
+
return SuiSpokeService.getSimulateDepositParams(
|
|
10886
|
+
params,
|
|
10887
|
+
spokeProvider,
|
|
10888
|
+
hubProvider
|
|
10889
|
+
);
|
|
10890
|
+
}
|
|
10891
|
+
if (spokeProvider instanceof SolanaSpokeProvider) {
|
|
10892
|
+
return SolanaSpokeService.getSimulateDepositParams(
|
|
10893
|
+
params,
|
|
10894
|
+
spokeProvider,
|
|
10895
|
+
hubProvider
|
|
10896
|
+
);
|
|
10897
|
+
}
|
|
10898
|
+
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10899
|
+
return StellarSpokeService.getSimulateDepositParams(
|
|
10900
|
+
params,
|
|
10901
|
+
spokeProvider,
|
|
10902
|
+
hubProvider
|
|
10903
|
+
);
|
|
10904
|
+
}
|
|
10905
|
+
throw new Error("Invalid spoke provider");
|
|
10906
|
+
}
|
|
10907
|
+
static async verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation) {
|
|
10908
|
+
if (!skipSimulation) {
|
|
10909
|
+
const simulationParams = await _SpokeService.getSimulateDepositParams(params, spokeProvider, hubProvider);
|
|
10910
|
+
const result = await _SpokeService.simulateDeposit(simulationParams, hubProvider);
|
|
10911
|
+
if (!result.success) {
|
|
10912
|
+
throw new Error("Simulation failed", { cause: result });
|
|
10913
|
+
}
|
|
10914
|
+
}
|
|
10915
|
+
}
|
|
10570
10916
|
/**
|
|
10571
10917
|
* Get the balance of the token in the spoke chain.
|
|
10572
10918
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -10605,14 +10951,16 @@ var SpokeService = class {
|
|
|
10605
10951
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10606
10952
|
* @returns {Promise<Hash>} A promise that resolves to the transaction hash.
|
|
10607
10953
|
*/
|
|
10608
|
-
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
10954
|
+
static async callWallet(from, payload, spokeProvider, hubProvider, raw, skipSimulation = false) {
|
|
10609
10955
|
if (isSonicSpokeProvider(spokeProvider)) {
|
|
10610
10956
|
return await SonicSpokeService.callWallet(payload, spokeProvider, raw);
|
|
10611
10957
|
}
|
|
10612
10958
|
if (isEvmSpokeProvider(spokeProvider)) {
|
|
10959
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10613
10960
|
return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
|
|
10614
10961
|
}
|
|
10615
10962
|
if (isInjectiveSpokeProvider(spokeProvider)) {
|
|
10963
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10616
10964
|
return await InjectiveSpokeService.callWallet(
|
|
10617
10965
|
from,
|
|
10618
10966
|
payload,
|
|
@@ -10622,12 +10970,15 @@ var SpokeService = class {
|
|
|
10622
10970
|
);
|
|
10623
10971
|
}
|
|
10624
10972
|
if (isIconSpokeProvider(spokeProvider)) {
|
|
10973
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10625
10974
|
return await IconSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
10626
10975
|
}
|
|
10627
10976
|
if (isSuiSpokeProvider(spokeProvider)) {
|
|
10977
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10628
10978
|
return await SuiSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
10629
10979
|
}
|
|
10630
10980
|
if (isSolanaSpokeProvider(spokeProvider)) {
|
|
10981
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10631
10982
|
return await SolanaSpokeService.callWallet(
|
|
10632
10983
|
from,
|
|
10633
10984
|
payload,
|
|
@@ -10637,10 +10988,27 @@ var SpokeService = class {
|
|
|
10637
10988
|
);
|
|
10638
10989
|
}
|
|
10639
10990
|
if (isStellarSpokeProvider(spokeProvider)) {
|
|
10991
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10640
10992
|
return await StellarSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
|
|
10641
10993
|
}
|
|
10642
10994
|
throw new Error("Invalid spoke provider");
|
|
10643
10995
|
}
|
|
10996
|
+
static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
|
|
10997
|
+
if (!skipSimulation) {
|
|
10998
|
+
const result = await _SpokeService.simulateRecvMessage(
|
|
10999
|
+
{
|
|
11000
|
+
target: from,
|
|
11001
|
+
srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
|
|
11002
|
+
srcAddress: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
11003
|
+
payload
|
|
11004
|
+
},
|
|
11005
|
+
hubProvider
|
|
11006
|
+
);
|
|
11007
|
+
if (!result.success) {
|
|
11008
|
+
throw new Error("Simulation failed", { cause: result });
|
|
11009
|
+
}
|
|
11010
|
+
}
|
|
11011
|
+
}
|
|
10644
11012
|
};
|
|
10645
11013
|
async function postRequest(payload, apiUrl) {
|
|
10646
11014
|
const response = await retry(
|
|
@@ -10655,19 +11023,19 @@ async function postRequest(payload, apiUrl) {
|
|
|
10655
11023
|
return response.json();
|
|
10656
11024
|
}
|
|
10657
11025
|
async function submitTransaction(payload, apiUrl) {
|
|
10658
|
-
|
|
10659
|
-
|
|
11026
|
+
invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11027
|
+
invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
10660
11028
|
return postRequest(payload, apiUrl);
|
|
10661
11029
|
}
|
|
10662
11030
|
async function getTransactionPackets(payload, apiUrl) {
|
|
10663
|
-
|
|
10664
|
-
|
|
11031
|
+
invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11032
|
+
invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
10665
11033
|
return postRequest(payload, apiUrl);
|
|
10666
11034
|
}
|
|
10667
11035
|
async function getPacket(payload, apiUrl) {
|
|
10668
|
-
|
|
10669
|
-
|
|
10670
|
-
|
|
11036
|
+
invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11037
|
+
invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
11038
|
+
invariant11(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
|
|
10671
11039
|
return postRequest(payload, apiUrl);
|
|
10672
11040
|
}
|
|
10673
11041
|
async function waitUntilIntentExecuted(payload) {
|
|
@@ -10792,14 +11160,17 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
10792
11160
|
* @param {PartnerFee} fee - The partner fee configuration
|
|
10793
11161
|
* @returns {Promise<[Hex, Intent, bigint]>} The encoded contract call, intent and fee amount
|
|
10794
11162
|
*/
|
|
10795
|
-
static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee) {
|
|
10796
|
-
|
|
11163
|
+
static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, hubProvider) {
|
|
11164
|
+
let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
|
|
11165
|
+
if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
11166
|
+
inputToken = hubProvider.chainConfig.wrappedNativeToken;
|
|
11167
|
+
}
|
|
10797
11168
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
10798
|
-
|
|
11169
|
+
invariant11(
|
|
10799
11170
|
inputToken,
|
|
10800
11171
|
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
10801
11172
|
);
|
|
10802
|
-
|
|
11173
|
+
invariant11(
|
|
10803
11174
|
outputToken,
|
|
10804
11175
|
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
10805
11176
|
);
|
|
@@ -10831,7 +11202,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
10831
11202
|
* @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
|
|
10832
11203
|
*/
|
|
10833
11204
|
static createIntentFeeData(fee, inputAmount) {
|
|
10834
|
-
|
|
11205
|
+
invariant11(inputAmount > 0n, "Input amount must be greater than 0");
|
|
10835
11206
|
if (!fee) {
|
|
10836
11207
|
return ["0x", 0n];
|
|
10837
11208
|
}
|
|
@@ -10839,7 +11210,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
10839
11210
|
if (isPartnerFeeAmount(fee)) {
|
|
10840
11211
|
feeAmount = fee.amount;
|
|
10841
11212
|
} else if (isPartnerFeePercentage(fee)) {
|
|
10842
|
-
|
|
11213
|
+
invariant11(
|
|
10843
11214
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
10844
11215
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
10845
11216
|
);
|
|
@@ -10966,23 +11337,23 @@ var SolverApiService = class {
|
|
|
10966
11337
|
* }
|
|
10967
11338
|
*/
|
|
10968
11339
|
static async getQuote(payload, config) {
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
11340
|
+
invariant11(payload.token_src.length > 0, "Empty token_src");
|
|
11341
|
+
invariant11(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
|
|
11342
|
+
invariant11(payload.token_dst.length > 0, "Empty token_dst");
|
|
11343
|
+
invariant11(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
|
|
11344
|
+
invariant11(payload.amount > 0n, "amount must be greater than 0");
|
|
11345
|
+
invariant11(
|
|
10975
11346
|
isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
|
|
10976
11347
|
"unsupported token_src for src chain"
|
|
10977
11348
|
);
|
|
10978
|
-
|
|
11349
|
+
invariant11(
|
|
10979
11350
|
isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
|
|
10980
11351
|
"unsupported token_dst for dst chain"
|
|
10981
11352
|
);
|
|
10982
11353
|
const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
|
|
10983
11354
|
const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
|
|
10984
|
-
|
|
10985
|
-
|
|
11355
|
+
invariant11(tokenSrc, "hub asset not found for token_src");
|
|
11356
|
+
invariant11(tokenDst, "hub asset not found for token_dst");
|
|
10986
11357
|
try {
|
|
10987
11358
|
const response = await fetch(`${config.solverApiEndpoint}/quote`, {
|
|
10988
11359
|
method: "POST",
|
|
@@ -11077,7 +11448,7 @@ var SolverApiService = class {
|
|
|
11077
11448
|
}
|
|
11078
11449
|
}
|
|
11079
11450
|
static async getStatus(request, config) {
|
|
11080
|
-
|
|
11451
|
+
invariant11(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
|
|
11081
11452
|
try {
|
|
11082
11453
|
const response = await fetch(`${config.solverApiEndpoint}/status`, {
|
|
11083
11454
|
method: "POST",
|
|
@@ -11345,13 +11716,15 @@ var SolverService = class {
|
|
|
11345
11716
|
intentParams: params,
|
|
11346
11717
|
spokeProvider,
|
|
11347
11718
|
fee = this.config.partnerFee,
|
|
11348
|
-
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
11719
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT,
|
|
11720
|
+
skipSimulation = false
|
|
11349
11721
|
}) {
|
|
11350
11722
|
return this.createAndSubmitIntent({
|
|
11351
11723
|
intentParams: params,
|
|
11352
11724
|
spokeProvider,
|
|
11353
11725
|
fee,
|
|
11354
|
-
timeout
|
|
11726
|
+
timeout,
|
|
11727
|
+
skipSimulation
|
|
11355
11728
|
});
|
|
11356
11729
|
}
|
|
11357
11730
|
/**
|
|
@@ -11400,14 +11773,16 @@ var SolverService = class {
|
|
|
11400
11773
|
intentParams: params,
|
|
11401
11774
|
spokeProvider,
|
|
11402
11775
|
fee = this.config.partnerFee,
|
|
11403
|
-
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
11776
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT,
|
|
11777
|
+
skipSimulation = false
|
|
11404
11778
|
}) {
|
|
11405
11779
|
try {
|
|
11406
11780
|
const createIntentResult = await this.createIntent({
|
|
11407
11781
|
intentParams: params,
|
|
11408
11782
|
spokeProvider,
|
|
11409
11783
|
fee,
|
|
11410
|
-
raw: false
|
|
11784
|
+
raw: false,
|
|
11785
|
+
skipSimulation
|
|
11411
11786
|
});
|
|
11412
11787
|
if (!createIntentResult.ok) {
|
|
11413
11788
|
return createIntentResult;
|
|
@@ -11534,13 +11909,23 @@ var SolverService = class {
|
|
|
11534
11909
|
spokeProvider
|
|
11535
11910
|
}) {
|
|
11536
11911
|
try {
|
|
11537
|
-
if (spokeProvider instanceof EvmSpokeProvider
|
|
11912
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
11913
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11914
|
+
return await Erc20Service.isAllowanceValid(
|
|
11915
|
+
params.inputToken,
|
|
11916
|
+
params.inputAmount,
|
|
11917
|
+
walletAddress,
|
|
11918
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
11919
|
+
spokeProvider
|
|
11920
|
+
);
|
|
11921
|
+
}
|
|
11922
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
11538
11923
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11539
11924
|
return await Erc20Service.isAllowanceValid(
|
|
11540
11925
|
params.inputToken,
|
|
11541
11926
|
params.inputAmount,
|
|
11542
11927
|
walletAddress,
|
|
11543
|
-
|
|
11928
|
+
getSolverConfig(SONIC_MAINNET_CHAIN_ID).intentsContract,
|
|
11544
11929
|
spokeProvider
|
|
11545
11930
|
);
|
|
11546
11931
|
}
|
|
@@ -11599,7 +11984,7 @@ var SolverService = class {
|
|
|
11599
11984
|
raw
|
|
11600
11985
|
}) {
|
|
11601
11986
|
try {
|
|
11602
|
-
if (spokeProvider instanceof EvmSpokeProvider
|
|
11987
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
11603
11988
|
const result = await Erc20Service.approve(
|
|
11604
11989
|
params.inputToken,
|
|
11605
11990
|
params.inputAmount,
|
|
@@ -11612,6 +11997,19 @@ var SolverService = class {
|
|
|
11612
11997
|
value: result
|
|
11613
11998
|
};
|
|
11614
11999
|
}
|
|
12000
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
12001
|
+
const result = await Erc20Service.approve(
|
|
12002
|
+
params.inputToken,
|
|
12003
|
+
params.inputAmount,
|
|
12004
|
+
getSolverConfig(SONIC_MAINNET_CHAIN_ID).intentsContract,
|
|
12005
|
+
spokeProvider,
|
|
12006
|
+
raw
|
|
12007
|
+
);
|
|
12008
|
+
return {
|
|
12009
|
+
ok: true,
|
|
12010
|
+
value: result
|
|
12011
|
+
};
|
|
12012
|
+
}
|
|
11615
12013
|
return {
|
|
11616
12014
|
ok: false,
|
|
11617
12015
|
error: new Error("Approve only supported for EVM spoke chains")
|
|
@@ -11671,48 +12069,70 @@ var SolverService = class {
|
|
|
11671
12069
|
fee = this.config.partnerFee,
|
|
11672
12070
|
raw
|
|
11673
12071
|
}) {
|
|
11674
|
-
|
|
12072
|
+
invariant11(
|
|
11675
12073
|
isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
11676
12074
|
`Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
|
|
11677
12075
|
);
|
|
11678
|
-
|
|
12076
|
+
invariant11(
|
|
11679
12077
|
isValidOriginalAssetAddress(params.dstChain, params.outputToken),
|
|
11680
12078
|
`Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
|
|
11681
12079
|
);
|
|
11682
|
-
|
|
11683
|
-
|
|
12080
|
+
invariant11(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
|
|
12081
|
+
invariant11(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
|
|
11684
12082
|
try {
|
|
11685
12083
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11686
|
-
|
|
12084
|
+
invariant11(
|
|
11687
12085
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
11688
12086
|
"srcAddress must be the same as wallet address"
|
|
11689
12087
|
);
|
|
11690
12088
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
{
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
12089
|
+
if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
12090
|
+
const [txResult, intent, feeAmount, data] = await SonicSpokeService.createSwapIntent(
|
|
12091
|
+
params,
|
|
12092
|
+
creatorHubWalletAddress,
|
|
12093
|
+
this.config,
|
|
12094
|
+
fee,
|
|
12095
|
+
spokeProvider,
|
|
12096
|
+
this.hubProvider,
|
|
12097
|
+
raw
|
|
12098
|
+
);
|
|
12099
|
+
return {
|
|
12100
|
+
ok: true,
|
|
12101
|
+
value: [
|
|
12102
|
+
txResult,
|
|
12103
|
+
{ ...intent, feeAmount },
|
|
12104
|
+
data
|
|
12105
|
+
]
|
|
12106
|
+
};
|
|
12107
|
+
}
|
|
12108
|
+
{
|
|
12109
|
+
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
|
|
12110
|
+
{
|
|
12111
|
+
...params,
|
|
12112
|
+
srcAddress: walletAddress
|
|
12113
|
+
},
|
|
12114
|
+
creatorHubWalletAddress,
|
|
12115
|
+
this.config,
|
|
12116
|
+
fee,
|
|
12117
|
+
this.hubProvider
|
|
12118
|
+
);
|
|
12119
|
+
const txResult = await SpokeService.deposit(
|
|
12120
|
+
{
|
|
12121
|
+
from: walletAddress,
|
|
12122
|
+
to: creatorHubWalletAddress,
|
|
12123
|
+
token: params.inputToken,
|
|
12124
|
+
amount: params.inputAmount,
|
|
12125
|
+
data
|
|
12126
|
+
},
|
|
12127
|
+
spokeProvider,
|
|
12128
|
+
this.hubProvider,
|
|
12129
|
+
raw
|
|
12130
|
+
);
|
|
12131
|
+
return {
|
|
12132
|
+
ok: true,
|
|
12133
|
+
value: [txResult, { ...intent, feeAmount }, data]
|
|
12134
|
+
};
|
|
12135
|
+
}
|
|
11716
12136
|
} catch (error) {
|
|
11717
12137
|
return {
|
|
11718
12138
|
ok: false,
|
|
@@ -11735,8 +12155,8 @@ var SolverService = class {
|
|
|
11735
12155
|
*/
|
|
11736
12156
|
async cancelIntent(intent, spokeProvider, raw) {
|
|
11737
12157
|
try {
|
|
11738
|
-
|
|
11739
|
-
|
|
12158
|
+
invariant11(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12159
|
+
invariant11(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
11740
12160
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11741
12161
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11742
12162
|
const calls = [];
|
|
@@ -12248,7 +12668,7 @@ var IcxMigrationService = class {
|
|
|
12248
12668
|
migrateData(params) {
|
|
12249
12669
|
const calls = [];
|
|
12250
12670
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.address);
|
|
12251
|
-
|
|
12671
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
|
|
12252
12672
|
calls.push(
|
|
12253
12673
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
12254
12674
|
);
|
|
@@ -12264,7 +12684,7 @@ var IcxMigrationService = class {
|
|
|
12264
12684
|
revertMigration(params) {
|
|
12265
12685
|
const calls = [];
|
|
12266
12686
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
12267
|
-
|
|
12687
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
12268
12688
|
calls.push(
|
|
12269
12689
|
Erc20Service.encodeApprove(
|
|
12270
12690
|
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
@@ -12360,9 +12780,9 @@ var MigrationService = class {
|
|
|
12360
12780
|
async isAllowanceValid(params, action, spokeProvider) {
|
|
12361
12781
|
try {
|
|
12362
12782
|
if (action === "migrate") {
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
|
|
12783
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
12784
|
+
invariant11(isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
12785
|
+
invariant11(
|
|
12366
12786
|
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
12367
12787
|
"Invalid params"
|
|
12368
12788
|
);
|
|
@@ -12388,9 +12808,9 @@ var MigrationService = class {
|
|
|
12388
12808
|
};
|
|
12389
12809
|
}
|
|
12390
12810
|
if (action === "revert") {
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
|
|
12811
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
12812
|
+
invariant11(params.to.length > 0, "To address is required");
|
|
12813
|
+
invariant11(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12394
12814
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12395
12815
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12396
12816
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -12446,9 +12866,9 @@ var MigrationService = class {
|
|
|
12446
12866
|
async approve(params, action, spokeProvider, raw) {
|
|
12447
12867
|
try {
|
|
12448
12868
|
if (action === "migrate") {
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12869
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
12870
|
+
invariant11(params.to.length > 0, "To address is required");
|
|
12871
|
+
invariant11(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12452
12872
|
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
12453
12873
|
const evmSpokeProvider = spokeProvider;
|
|
12454
12874
|
const result = await Erc20Service.approve(
|
|
@@ -12469,9 +12889,9 @@ var MigrationService = class {
|
|
|
12469
12889
|
};
|
|
12470
12890
|
}
|
|
12471
12891
|
if (action === "revert") {
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12892
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
12893
|
+
invariant11(params.to.length > 0, "To address is required");
|
|
12894
|
+
invariant11(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12475
12895
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12476
12896
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12477
12897
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -12883,13 +13303,13 @@ var MigrationService = class {
|
|
|
12883
13303
|
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
12884
13304
|
try {
|
|
12885
13305
|
if (!unchecked) {
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
13306
|
+
invariant11(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
13307
|
+
invariant11(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
13308
|
+
invariant11(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
13309
|
+
invariant11(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
13310
|
+
invariant11(params.amount > 0, "Amount must be greater than 0");
|
|
13311
|
+
invariant11(params.to.length > 0, "Recipient address is required");
|
|
13312
|
+
invariant11(
|
|
12893
13313
|
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
12894
13314
|
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
12895
13315
|
);
|
|
@@ -12897,11 +13317,11 @@ var MigrationService = class {
|
|
|
12897
13317
|
let migrationData;
|
|
12898
13318
|
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
12899
13319
|
if (!unchecked) {
|
|
12900
|
-
|
|
13320
|
+
invariant11(
|
|
12901
13321
|
isLegacybnUSDChainId(params.srcChainId),
|
|
12902
13322
|
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
12903
13323
|
);
|
|
12904
|
-
|
|
13324
|
+
invariant11(
|
|
12905
13325
|
isNewbnUSDChainId(params.dstChainId),
|
|
12906
13326
|
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
12907
13327
|
);
|
|
@@ -12916,15 +13336,15 @@ var MigrationService = class {
|
|
|
12916
13336
|
});
|
|
12917
13337
|
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
12918
13338
|
if (!unchecked) {
|
|
12919
|
-
|
|
13339
|
+
invariant11(
|
|
12920
13340
|
isLegacybnUSDChainId(params.dstChainId),
|
|
12921
13341
|
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
12922
13342
|
);
|
|
12923
|
-
|
|
13343
|
+
invariant11(
|
|
12924
13344
|
isNewbnUSDToken(params.srcbnUSD),
|
|
12925
13345
|
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
12926
13346
|
);
|
|
12927
|
-
|
|
13347
|
+
invariant11(
|
|
12928
13348
|
isNewbnUSDChainId(params.srcChainId),
|
|
12929
13349
|
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
12930
13350
|
);
|
|
@@ -12997,13 +13417,13 @@ var MigrationService = class {
|
|
|
12997
13417
|
*/
|
|
12998
13418
|
async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
|
|
12999
13419
|
try {
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13420
|
+
invariant11(params.amount > 0, "Amount must be greater than 0");
|
|
13421
|
+
invariant11(isAddress(params.to), "Recipient address is required");
|
|
13422
|
+
invariant11(
|
|
13003
13423
|
params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
13004
13424
|
"Token must be wICX or native ICX token"
|
|
13005
13425
|
);
|
|
13006
|
-
|
|
13426
|
+
invariant11(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
13007
13427
|
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
13008
13428
|
if (availableAmount < params.amount) {
|
|
13009
13429
|
throw new Error(
|
|
@@ -13115,7 +13535,7 @@ var BnUSDMigrationService = class {
|
|
|
13115
13535
|
migrateData(params) {
|
|
13116
13536
|
const calls = [];
|
|
13117
13537
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
13118
|
-
|
|
13538
|
+
invariant11(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
13119
13539
|
const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
13120
13540
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
13121
13541
|
calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
|
|
@@ -13127,7 +13547,7 @@ var BnUSDMigrationService = class {
|
|
|
13127
13547
|
return encodeContractCalls(calls);
|
|
13128
13548
|
}
|
|
13129
13549
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
13130
|
-
|
|
13550
|
+
invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13131
13551
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
13132
13552
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
13133
13553
|
dstAssetConfig.decimal,
|
|
@@ -13160,14 +13580,14 @@ var BnUSDMigrationService = class {
|
|
|
13160
13580
|
let decimals = 18;
|
|
13161
13581
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
13162
13582
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
13163
|
-
|
|
13583
|
+
invariant11(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13164
13584
|
decimals = assetConfig.decimal;
|
|
13165
13585
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
13166
13586
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
13167
13587
|
}
|
|
13168
13588
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
13169
13589
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
13170
|
-
|
|
13590
|
+
invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
13171
13591
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
13172
13592
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
13173
13593
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -13250,7 +13670,7 @@ var BalnSwapService = class {
|
|
|
13250
13670
|
*/
|
|
13251
13671
|
async swapData(balnToken, params) {
|
|
13252
13672
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, balnToken);
|
|
13253
|
-
|
|
13673
|
+
invariant11(assetConfig, `hub asset not found for baln token: ${balnToken}`);
|
|
13254
13674
|
const calls = [];
|
|
13255
13675
|
calls.push(
|
|
13256
13676
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
|
|
@@ -15014,9 +15434,9 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15014
15434
|
*/
|
|
15015
15435
|
async isAllowanceValid(params, spokeProvider) {
|
|
15016
15436
|
try {
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15437
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15438
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15439
|
+
invariant11(
|
|
15020
15440
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15021
15441
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15022
15442
|
);
|
|
@@ -15111,19 +15531,19 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15111
15531
|
*/
|
|
15112
15532
|
async approve(params, spokeProvider, raw) {
|
|
15113
15533
|
try {
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15534
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15535
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15536
|
+
invariant11(
|
|
15117
15537
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15118
15538
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15119
15539
|
);
|
|
15120
15540
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15121
15541
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
15122
|
-
|
|
15542
|
+
invariant11(
|
|
15123
15543
|
params.action === "supply" || params.action === "repay",
|
|
15124
15544
|
"Invalid action (only supply and repay are supported on evm)"
|
|
15125
15545
|
);
|
|
15126
|
-
|
|
15546
|
+
invariant11(isAddress(params.token), "Invalid token address");
|
|
15127
15547
|
const result = await Erc20Service.approve(
|
|
15128
15548
|
params.token,
|
|
15129
15549
|
params.amount,
|
|
@@ -15137,11 +15557,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15137
15557
|
};
|
|
15138
15558
|
}
|
|
15139
15559
|
if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
15140
|
-
|
|
15560
|
+
invariant11(
|
|
15141
15561
|
params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
|
|
15142
15562
|
"Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
|
|
15143
15563
|
);
|
|
15144
|
-
|
|
15564
|
+
invariant11(isAddress(params.token), "Invalid token address");
|
|
15145
15565
|
if (params.action === "withdraw") {
|
|
15146
15566
|
const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
|
|
15147
15567
|
params.token,
|
|
@@ -15313,10 +15733,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15313
15733
|
*/
|
|
15314
15734
|
async createSupplyIntent(params, spokeProvider, raw) {
|
|
15315
15735
|
try {
|
|
15316
|
-
|
|
15317
|
-
|
|
15318
|
-
|
|
15319
|
-
|
|
15736
|
+
invariant11(params.action === "supply", "Invalid action");
|
|
15737
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15738
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15739
|
+
invariant11(
|
|
15320
15740
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15321
15741
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15322
15742
|
);
|
|
@@ -15468,10 +15888,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15468
15888
|
* }
|
|
15469
15889
|
*/
|
|
15470
15890
|
async createBorrowIntent(params, spokeProvider, raw) {
|
|
15471
|
-
|
|
15472
|
-
|
|
15473
|
-
|
|
15474
|
-
|
|
15891
|
+
invariant11(params.action === "borrow", "Invalid action");
|
|
15892
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15893
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15894
|
+
invariant11(
|
|
15475
15895
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15476
15896
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15477
15897
|
);
|
|
@@ -15603,10 +16023,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15603
16023
|
* }
|
|
15604
16024
|
*/
|
|
15605
16025
|
async createWithdrawIntent(params, spokeProvider, raw) {
|
|
15606
|
-
|
|
15607
|
-
|
|
15608
|
-
|
|
15609
|
-
|
|
16026
|
+
invariant11(params.action === "withdraw", "Invalid action");
|
|
16027
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
16028
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
16029
|
+
invariant11(
|
|
15610
16030
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15611
16031
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15612
16032
|
);
|
|
@@ -15758,10 +16178,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15758
16178
|
* }
|
|
15759
16179
|
*/
|
|
15760
16180
|
async createRepayIntent(params, spokeProvider, raw) {
|
|
15761
|
-
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
|
|
16181
|
+
invariant11(params.action === "repay", "Invalid action");
|
|
16182
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
16183
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
16184
|
+
invariant11(
|
|
15765
16185
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15766
16186
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15767
16187
|
);
|
|
@@ -15804,7 +16224,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15804
16224
|
buildSupplyData(token, to, amount, spokeChainId) {
|
|
15805
16225
|
const calls = [];
|
|
15806
16226
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
15807
|
-
|
|
16227
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
15808
16228
|
let assetAddress = assetConfig.asset;
|
|
15809
16229
|
const vaultAddress = assetConfig.vault;
|
|
15810
16230
|
const lendingPool = this.config.lendingPool;
|
|
@@ -15835,13 +16255,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15835
16255
|
* @returns {Hex} The transaction data.
|
|
15836
16256
|
*/
|
|
15837
16257
|
buildBorrowData(from, to, token, amount, spokeChainId) {
|
|
15838
|
-
|
|
15839
|
-
|
|
16258
|
+
invariant11(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
|
|
16259
|
+
invariant11(
|
|
15840
16260
|
isValidOriginalAssetAddress(spokeChainId, token),
|
|
15841
16261
|
`Unsupported spoke chain (${spokeChainId}) token: ${token}`
|
|
15842
16262
|
);
|
|
15843
16263
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
15844
|
-
|
|
16264
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
15845
16265
|
let assetAddress = assetConfig.asset;
|
|
15846
16266
|
const vaultAddress = assetConfig.vault;
|
|
15847
16267
|
const bnUSDVault = this.config.bnUSDVault;
|