@sodax/sdk 0.0.1-rc.24 → 0.0.1-rc.25
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 +342 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -6
- package/dist/index.d.ts +66 -6
- package/dist/index.mjs +342 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -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.
|
|
@@ -10446,9 +10602,7 @@ function isBalnMigrateParams(value) {
|
|
|
10446
10602
|
function isIcxCreateRevertMigrationParams(value) {
|
|
10447
10603
|
return typeof value === "object" && value !== null && "amount" in value && "to" in value;
|
|
10448
10604
|
}
|
|
10449
|
-
|
|
10450
|
-
// src/services/spoke/SpokeService.ts
|
|
10451
|
-
var SpokeService = class {
|
|
10605
|
+
var SpokeService = class _SpokeService {
|
|
10452
10606
|
constructor() {
|
|
10453
10607
|
}
|
|
10454
10608
|
/**
|
|
@@ -10502,14 +10656,99 @@ var SpokeService = class {
|
|
|
10502
10656
|
}
|
|
10503
10657
|
throw new Error("Invalid spoke provider");
|
|
10504
10658
|
}
|
|
10659
|
+
/**
|
|
10660
|
+
|
|
10661
|
+
* Encodes transfer data using RLP encoding to match Solidity Transfer struct.
|
|
10662
|
+
* @param {Hex} token - The token contract address.
|
|
10663
|
+
* @param {Hex} from - The sender address.
|
|
10664
|
+
* @param {Hex} to - The recipient address.
|
|
10665
|
+
* @param {bigint} amount - The transfer amount.
|
|
10666
|
+
* @param {Hex} data - The encoded data payload.
|
|
10667
|
+
* @returns {Promise<Hex>} A promise that resolves to the RLP encoded transfer data.
|
|
10668
|
+
*/
|
|
10669
|
+
static encodeTransfer(token, from, to, amount, data) {
|
|
10670
|
+
const rlpInput = [
|
|
10671
|
+
token,
|
|
10672
|
+
// token (bytes)
|
|
10673
|
+
from,
|
|
10674
|
+
// from (bytes)
|
|
10675
|
+
to,
|
|
10676
|
+
// to (bytes)
|
|
10677
|
+
amount,
|
|
10678
|
+
// amount (uint256)
|
|
10679
|
+
data
|
|
10680
|
+
// data (bytes)
|
|
10681
|
+
];
|
|
10682
|
+
const rlpEncodedData = rlp.encode(rlpInput);
|
|
10683
|
+
return `0x${Buffer.from(rlpEncodedData).toString("hex")}`;
|
|
10684
|
+
}
|
|
10685
|
+
static async simulateDeposit(params, hubProvider) {
|
|
10686
|
+
const chainId = getIntentRelayChainId(params.spokeChainID);
|
|
10687
|
+
const hubAssetManager = hubProvider.chainConfig.addresses.assetManager;
|
|
10688
|
+
const payload = _SpokeService.encodeTransfer(params.token, params.from, params.to, params.amount, params.data);
|
|
10689
|
+
return _SpokeService.simulateRecvMessage(
|
|
10690
|
+
{ target: hubAssetManager, srcChainId: chainId, srcAddress: params.srcAddress, payload },
|
|
10691
|
+
hubProvider
|
|
10692
|
+
);
|
|
10693
|
+
}
|
|
10694
|
+
/**
|
|
10695
|
+
* Simulates receiving a message without signature verification.
|
|
10696
|
+
* This function calls simulateRecvMessage which always reverts with 'Simulation completed'.
|
|
10697
|
+
* @param {bigint} srcChainId - The chain ID of the originating chain.
|
|
10698
|
+
* @param {Hex} srcAddress - The address of the sender on the originating chain.
|
|
10699
|
+
* @param {Hex} payload - The encoded payload containing call data (from encodeTransfer).
|
|
10700
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10701
|
+
* @returns {Promise<{ success: boolean; error?: string }>} Result of the simulation.
|
|
10702
|
+
*/
|
|
10703
|
+
static async simulateRecvMessage(params, hubProvider) {
|
|
10704
|
+
try {
|
|
10705
|
+
const result = await hubProvider.publicClient.call({
|
|
10706
|
+
to: params.target,
|
|
10707
|
+
data: encodeFunctionData({
|
|
10708
|
+
abi: [
|
|
10709
|
+
{
|
|
10710
|
+
name: "simulateRecvMessage",
|
|
10711
|
+
type: "function",
|
|
10712
|
+
stateMutability: "nonpayable",
|
|
10713
|
+
inputs: [
|
|
10714
|
+
{ name: "srcChainId", type: "uint256" },
|
|
10715
|
+
{ name: "srcAddress", type: "bytes" },
|
|
10716
|
+
{ name: "payload", type: "bytes" }
|
|
10717
|
+
],
|
|
10718
|
+
outputs: []
|
|
10719
|
+
}
|
|
10720
|
+
],
|
|
10721
|
+
functionName: "simulateRecvMessage",
|
|
10722
|
+
args: [params.srcChainId, params.srcAddress, params.payload]
|
|
10723
|
+
})
|
|
10724
|
+
});
|
|
10725
|
+
console.warn("simulateRecvMessage did not revert as expected", { result });
|
|
10726
|
+
return {
|
|
10727
|
+
success: false,
|
|
10728
|
+
error: 'Function should have reverted with "Simulation completed"'
|
|
10729
|
+
};
|
|
10730
|
+
} catch (error) {
|
|
10731
|
+
if (error instanceof Error && error.message?.includes("Simulation completed")) {
|
|
10732
|
+
console.warn("simulateRecvMessage completed successfully with expected revert");
|
|
10733
|
+
return { success: true };
|
|
10734
|
+
}
|
|
10735
|
+
console.error("simulateRecvMessage failed with unexpected error:", error);
|
|
10736
|
+
return {
|
|
10737
|
+
success: false,
|
|
10738
|
+
error: error instanceof Error ? error.message || "Unknown simulation error" : "Unknown simulation error"
|
|
10739
|
+
};
|
|
10740
|
+
}
|
|
10741
|
+
}
|
|
10505
10742
|
/**
|
|
10506
10743
|
* Deposit tokens to the spoke chain.
|
|
10507
10744
|
* @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
10508
10745
|
* @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10509
10746
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10747
|
+
* @param {boolean} raw - Whether to return raw transaction data.
|
|
10748
|
+
* @param {boolean} skipSimulation - Whether to skip deposit simulation (optional, defaults to false).
|
|
10510
10749
|
* @returns {Promise<Hash>} A promise that resolves to the transaction hash.
|
|
10511
10750
|
*/
|
|
10512
|
-
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
10751
|
+
static async deposit(params, spokeProvider, hubProvider, raw, skipSimulation = false) {
|
|
10513
10752
|
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
10514
10753
|
return SonicSpokeService.deposit(
|
|
10515
10754
|
params,
|
|
@@ -10518,6 +10757,7 @@ var SpokeService = class {
|
|
|
10518
10757
|
);
|
|
10519
10758
|
}
|
|
10520
10759
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10760
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10521
10761
|
return EvmSpokeService.deposit(
|
|
10522
10762
|
params,
|
|
10523
10763
|
spokeProvider,
|
|
@@ -10526,14 +10766,11 @@ var SpokeService = class {
|
|
|
10526
10766
|
);
|
|
10527
10767
|
}
|
|
10528
10768
|
if (spokeProvider instanceof InjectiveSpokeProvider) {
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
spokeProvider,
|
|
10532
|
-
hubProvider,
|
|
10533
|
-
raw
|
|
10534
|
-
);
|
|
10769
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10770
|
+
return InjectiveSpokeService.deposit(params, spokeProvider, hubProvider, raw);
|
|
10535
10771
|
}
|
|
10536
10772
|
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10773
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10537
10774
|
return IconSpokeService.deposit(
|
|
10538
10775
|
params,
|
|
10539
10776
|
spokeProvider,
|
|
@@ -10542,6 +10779,7 @@ var SpokeService = class {
|
|
|
10542
10779
|
);
|
|
10543
10780
|
}
|
|
10544
10781
|
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10782
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10545
10783
|
return SuiSpokeService.deposit(
|
|
10546
10784
|
params,
|
|
10547
10785
|
spokeProvider,
|
|
@@ -10550,6 +10788,7 @@ var SpokeService = class {
|
|
|
10550
10788
|
);
|
|
10551
10789
|
}
|
|
10552
10790
|
if (spokeProvider instanceof SolanaSpokeProvider) {
|
|
10791
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10553
10792
|
return SolanaSpokeService.deposit(
|
|
10554
10793
|
params,
|
|
10555
10794
|
spokeProvider,
|
|
@@ -10558,6 +10797,7 @@ var SpokeService = class {
|
|
|
10558
10797
|
);
|
|
10559
10798
|
}
|
|
10560
10799
|
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10800
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10561
10801
|
return StellarSpokeService.deposit(
|
|
10562
10802
|
params,
|
|
10563
10803
|
spokeProvider,
|
|
@@ -10567,6 +10807,60 @@ var SpokeService = class {
|
|
|
10567
10807
|
}
|
|
10568
10808
|
throw new Error("Invalid spoke provider");
|
|
10569
10809
|
}
|
|
10810
|
+
static getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
10811
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10812
|
+
return EvmSpokeService.getSimulateDepositParams(
|
|
10813
|
+
params,
|
|
10814
|
+
spokeProvider,
|
|
10815
|
+
hubProvider
|
|
10816
|
+
);
|
|
10817
|
+
}
|
|
10818
|
+
if (spokeProvider instanceof InjectiveSpokeProvider) {
|
|
10819
|
+
return InjectiveSpokeService.getSimulateDepositParams(
|
|
10820
|
+
params,
|
|
10821
|
+
spokeProvider,
|
|
10822
|
+
hubProvider
|
|
10823
|
+
);
|
|
10824
|
+
}
|
|
10825
|
+
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10826
|
+
return IconSpokeService.getSimulateDepositParams(
|
|
10827
|
+
params,
|
|
10828
|
+
spokeProvider,
|
|
10829
|
+
hubProvider
|
|
10830
|
+
);
|
|
10831
|
+
}
|
|
10832
|
+
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10833
|
+
return SuiSpokeService.getSimulateDepositParams(
|
|
10834
|
+
params,
|
|
10835
|
+
spokeProvider,
|
|
10836
|
+
hubProvider
|
|
10837
|
+
);
|
|
10838
|
+
}
|
|
10839
|
+
if (spokeProvider instanceof SolanaSpokeProvider) {
|
|
10840
|
+
return SolanaSpokeService.getSimulateDepositParams(
|
|
10841
|
+
params,
|
|
10842
|
+
spokeProvider,
|
|
10843
|
+
hubProvider
|
|
10844
|
+
);
|
|
10845
|
+
}
|
|
10846
|
+
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10847
|
+
return StellarSpokeService.getSimulateDepositParams(
|
|
10848
|
+
params,
|
|
10849
|
+
spokeProvider,
|
|
10850
|
+
hubProvider
|
|
10851
|
+
);
|
|
10852
|
+
}
|
|
10853
|
+
throw new Error("Invalid spoke provider");
|
|
10854
|
+
}
|
|
10855
|
+
static async verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation) {
|
|
10856
|
+
if (!skipSimulation) {
|
|
10857
|
+
const simulationParams = await _SpokeService.getSimulateDepositParams(params, spokeProvider, hubProvider);
|
|
10858
|
+
const result = await _SpokeService.simulateDeposit(simulationParams, hubProvider);
|
|
10859
|
+
if (!result.success) {
|
|
10860
|
+
throw new Error("Simulation failed", { cause: result });
|
|
10861
|
+
}
|
|
10862
|
+
}
|
|
10863
|
+
}
|
|
10570
10864
|
/**
|
|
10571
10865
|
* Get the balance of the token in the spoke chain.
|
|
10572
10866
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -10605,14 +10899,16 @@ var SpokeService = class {
|
|
|
10605
10899
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
10606
10900
|
* @returns {Promise<Hash>} A promise that resolves to the transaction hash.
|
|
10607
10901
|
*/
|
|
10608
|
-
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
10902
|
+
static async callWallet(from, payload, spokeProvider, hubProvider, raw, skipSimulation = false) {
|
|
10609
10903
|
if (isSonicSpokeProvider(spokeProvider)) {
|
|
10610
10904
|
return await SonicSpokeService.callWallet(payload, spokeProvider, raw);
|
|
10611
10905
|
}
|
|
10612
10906
|
if (isEvmSpokeProvider(spokeProvider)) {
|
|
10907
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10613
10908
|
return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
|
|
10614
10909
|
}
|
|
10615
10910
|
if (isInjectiveSpokeProvider(spokeProvider)) {
|
|
10911
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10616
10912
|
return await InjectiveSpokeService.callWallet(
|
|
10617
10913
|
from,
|
|
10618
10914
|
payload,
|
|
@@ -10622,12 +10918,15 @@ var SpokeService = class {
|
|
|
10622
10918
|
);
|
|
10623
10919
|
}
|
|
10624
10920
|
if (isIconSpokeProvider(spokeProvider)) {
|
|
10921
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10625
10922
|
return await IconSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
10626
10923
|
}
|
|
10627
10924
|
if (isSuiSpokeProvider(spokeProvider)) {
|
|
10925
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10628
10926
|
return await SuiSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
10629
10927
|
}
|
|
10630
10928
|
if (isSolanaSpokeProvider(spokeProvider)) {
|
|
10929
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10631
10930
|
return await SolanaSpokeService.callWallet(
|
|
10632
10931
|
from,
|
|
10633
10932
|
payload,
|
|
@@ -10637,10 +10936,27 @@ var SpokeService = class {
|
|
|
10637
10936
|
);
|
|
10638
10937
|
}
|
|
10639
10938
|
if (isStellarSpokeProvider(spokeProvider)) {
|
|
10939
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10640
10940
|
return await StellarSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
|
|
10641
10941
|
}
|
|
10642
10942
|
throw new Error("Invalid spoke provider");
|
|
10643
10943
|
}
|
|
10944
|
+
static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
|
|
10945
|
+
if (!skipSimulation) {
|
|
10946
|
+
const result = await _SpokeService.simulateRecvMessage(
|
|
10947
|
+
{
|
|
10948
|
+
target: from,
|
|
10949
|
+
srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
|
|
10950
|
+
srcAddress: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
10951
|
+
payload
|
|
10952
|
+
},
|
|
10953
|
+
hubProvider
|
|
10954
|
+
);
|
|
10955
|
+
if (!result.success) {
|
|
10956
|
+
throw new Error("Simulation failed", { cause: result });
|
|
10957
|
+
}
|
|
10958
|
+
}
|
|
10959
|
+
}
|
|
10644
10960
|
};
|
|
10645
10961
|
async function postRequest(payload, apiUrl) {
|
|
10646
10962
|
const response = await retry(
|
|
@@ -10792,8 +11108,11 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
10792
11108
|
* @param {PartnerFee} fee - The partner fee configuration
|
|
10793
11109
|
* @returns {Promise<[Hex, Intent, bigint]>} The encoded contract call, intent and fee amount
|
|
10794
11110
|
*/
|
|
10795
|
-
static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee) {
|
|
10796
|
-
|
|
11111
|
+
static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, hubProvider) {
|
|
11112
|
+
let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
|
|
11113
|
+
if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
11114
|
+
inputToken = hubProvider.chainConfig.wrappedNativeToken;
|
|
11115
|
+
}
|
|
10797
11116
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
10798
11117
|
invariant10(
|
|
10799
11118
|
inputToken,
|
|
@@ -11345,13 +11664,15 @@ var SolverService = class {
|
|
|
11345
11664
|
intentParams: params,
|
|
11346
11665
|
spokeProvider,
|
|
11347
11666
|
fee = this.config.partnerFee,
|
|
11348
|
-
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
11667
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT,
|
|
11668
|
+
skipSimulation = false
|
|
11349
11669
|
}) {
|
|
11350
11670
|
return this.createAndSubmitIntent({
|
|
11351
11671
|
intentParams: params,
|
|
11352
11672
|
spokeProvider,
|
|
11353
11673
|
fee,
|
|
11354
|
-
timeout
|
|
11674
|
+
timeout,
|
|
11675
|
+
skipSimulation
|
|
11355
11676
|
});
|
|
11356
11677
|
}
|
|
11357
11678
|
/**
|
|
@@ -11400,14 +11721,16 @@ var SolverService = class {
|
|
|
11400
11721
|
intentParams: params,
|
|
11401
11722
|
spokeProvider,
|
|
11402
11723
|
fee = this.config.partnerFee,
|
|
11403
|
-
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
11724
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT,
|
|
11725
|
+
skipSimulation = false
|
|
11404
11726
|
}) {
|
|
11405
11727
|
try {
|
|
11406
11728
|
const createIntentResult = await this.createIntent({
|
|
11407
11729
|
intentParams: params,
|
|
11408
11730
|
spokeProvider,
|
|
11409
11731
|
fee,
|
|
11410
|
-
raw: false
|
|
11732
|
+
raw: false,
|
|
11733
|
+
skipSimulation
|
|
11411
11734
|
});
|
|
11412
11735
|
if (!createIntentResult.ok) {
|
|
11413
11736
|
return createIntentResult;
|
|
@@ -11695,7 +12018,8 @@ var SolverService = class {
|
|
|
11695
12018
|
},
|
|
11696
12019
|
creatorHubWalletAddress,
|
|
11697
12020
|
this.config,
|
|
11698
|
-
fee
|
|
12021
|
+
fee,
|
|
12022
|
+
this.hubProvider
|
|
11699
12023
|
);
|
|
11700
12024
|
const txResult = await SpokeService.deposit(
|
|
11701
12025
|
{
|