@sodax/sdk 0.0.1-rc.10 → 0.0.1-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/index.cjs +969 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +267 -4
- package/dist/index.d.ts +267 -4
- package/dist/index.mjs +968 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -5160,7 +5160,9 @@ var hubChainConfig = {
|
|
|
5160
5160
|
addresses: {
|
|
5161
5161
|
assetManager: "0x60c5681bD1DB4e50735c4cA3386005A4BA4937C0",
|
|
5162
5162
|
hubWallet: "0xA0ed3047D358648F2C0583B415CffCA571FDB544",
|
|
5163
|
-
xTokenManager: "0x5bD2843de9D6b0e6A05d0FB742072274EA3C6CA3"
|
|
5163
|
+
xTokenManager: "0x5bD2843de9D6b0e6A05d0FB742072274EA3C6CA3",
|
|
5164
|
+
icxMigration: "0x8Af7cae2c8377BEDD8820A5ad096AaFA29D839cc",
|
|
5165
|
+
sodaToken: "0x8515352CB9832D1d379D52366D1E995ADd358420"
|
|
5164
5166
|
},
|
|
5165
5167
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
5166
5168
|
supportedTokens: []
|
|
@@ -5685,7 +5687,8 @@ var spokeChainConfig = {
|
|
|
5685
5687
|
addresses: {
|
|
5686
5688
|
assetManager: "cx1be33c283c7dc7617181d1b21a6a2309e71b1ee7",
|
|
5687
5689
|
connection: "cxe5cdf3b0f26967b0efc72d470d57bbf534268f94",
|
|
5688
|
-
rateLimit: "cxbbdcea9e6757023a046067ba8daa3c4c50304358"
|
|
5690
|
+
rateLimit: "cxbbdcea9e6757023a046067ba8daa3c4c50304358",
|
|
5691
|
+
wICX: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
5689
5692
|
},
|
|
5690
5693
|
chain: {
|
|
5691
5694
|
id: ICON_MAINNET_CHAIN_ID,
|
|
@@ -6073,15 +6076,15 @@ var hubAssets = {
|
|
|
6073
6076
|
decimal: 6,
|
|
6074
6077
|
symbol: "USDC",
|
|
6075
6078
|
name: "USD Coin",
|
|
6076
|
-
vault: "
|
|
6079
|
+
vault: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833"
|
|
6077
6080
|
}
|
|
6078
6081
|
},
|
|
6079
6082
|
[SOLANA_MAINNET_CHAIN_ID]: {
|
|
6080
6083
|
[spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].supportedTokens.SOL.address]: {
|
|
6081
6084
|
asset: "0x0c09e69a4528945de6d16c7e469dea6996fdf636",
|
|
6082
6085
|
decimal: 9,
|
|
6083
|
-
symbol: "
|
|
6084
|
-
name: "
|
|
6086
|
+
symbol: "SOL",
|
|
6087
|
+
name: "Solana",
|
|
6085
6088
|
vault: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87"
|
|
6086
6089
|
},
|
|
6087
6090
|
[spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].bnUSD]: {
|
|
@@ -6092,11 +6095,11 @@ var hubAssets = {
|
|
|
6092
6095
|
vault: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6093
6096
|
},
|
|
6094
6097
|
[spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].supportedTokens.USDC.address]: {
|
|
6095
|
-
asset: "
|
|
6098
|
+
asset: "0xC3f020057510ffE10Ceb882e1B48238b43d78a5e",
|
|
6096
6099
|
decimal: 6,
|
|
6097
6100
|
symbol: "USDC",
|
|
6098
6101
|
name: "USD Coin",
|
|
6099
|
-
vault: "
|
|
6102
|
+
vault: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833"
|
|
6100
6103
|
}
|
|
6101
6104
|
},
|
|
6102
6105
|
[ICON_MAINNET_CHAIN_ID]: {
|
|
@@ -6107,6 +6110,13 @@ var hubAssets = {
|
|
|
6107
6110
|
name: "ICON",
|
|
6108
6111
|
vault: "0x0000000000000000000000000000000000000000"
|
|
6109
6112
|
},
|
|
6113
|
+
[spokeChainConfig[ICON_MAINNET_CHAIN_ID].addresses.wICX]: {
|
|
6114
|
+
asset: "0xb66cB7D841272AF6BaA8b8119007EdEE35d2C24F",
|
|
6115
|
+
decimal: 18,
|
|
6116
|
+
symbol: "wICX",
|
|
6117
|
+
name: "ICON",
|
|
6118
|
+
vault: "0x0000000000000000000000000000000000000000"
|
|
6119
|
+
},
|
|
6110
6120
|
[spokeChainConfig[ICON_MAINNET_CHAIN_ID].bnUSD]: {
|
|
6111
6121
|
asset: "0x654dddf32a9a2ac53f5fb54bf1e93f66791f8047",
|
|
6112
6122
|
decimal: 18,
|
|
@@ -6120,8 +6130,7 @@ var DEFAULT_RELAYER_API_ENDPOINT = "https://xcall-relay.nw.iconblockchain.xyz";
|
|
|
6120
6130
|
var solverConfig = {
|
|
6121
6131
|
[SONIC_MAINNET_CHAIN_ID]: {
|
|
6122
6132
|
intentsContract: "0x6382D6ccD780758C5e8A6123c33ee8F4472F96ef",
|
|
6123
|
-
solverApiEndpoint: "https://
|
|
6124
|
-
// TODO replace with mainnet
|
|
6133
|
+
solverApiEndpoint: "https://sodax-solver.iconblockchain.xyz"
|
|
6125
6134
|
}
|
|
6126
6135
|
};
|
|
6127
6136
|
var getSolverConfig = (chainId) => solverConfig[chainId];
|
|
@@ -6264,11 +6273,13 @@ var moneyMarketSupportedTokens = {
|
|
|
6264
6273
|
],
|
|
6265
6274
|
[SUI_MAINNET_CHAIN_ID]: [
|
|
6266
6275
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.SUI,
|
|
6267
|
-
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
6276
|
+
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
6277
|
+
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
6268
6278
|
],
|
|
6269
6279
|
[INJECTIVE_MAINNET_CHAIN_ID]: [
|
|
6270
6280
|
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.INJ,
|
|
6271
|
-
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
6281
|
+
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
6282
|
+
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
6272
6283
|
],
|
|
6273
6284
|
[NIBIRU_MAINNET_CHAIN_ID]: [],
|
|
6274
6285
|
[SONIC_MAINNET_CHAIN_ID]: [
|
|
@@ -9037,10 +9048,7 @@ var IconSpokeService = class _IconSpokeService {
|
|
|
9037
9048
|
}
|
|
9038
9049
|
return spokeProvider.walletProvider.sendTransaction({
|
|
9039
9050
|
from: walletAddress,
|
|
9040
|
-
to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ?
|
|
9041
|
-
// wICX address
|
|
9042
|
-
"cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
9043
|
-
) : token,
|
|
9051
|
+
to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token,
|
|
9044
9052
|
value,
|
|
9045
9053
|
nid: spokeProvider.chainConfig.nid,
|
|
9046
9054
|
method: "transfer",
|
|
@@ -10533,12 +10541,13 @@ var SolverService = class {
|
|
|
10533
10541
|
}
|
|
10534
10542
|
/**
|
|
10535
10543
|
* Get the status of an intent from Solver API
|
|
10544
|
+
* NOTE: intentHash should be retrieved from relay packet dst_tx_hash property (see createAndSubmitIntent)
|
|
10536
10545
|
* @param {IntentStatusRequest} intentStatusRequest - The intent status request
|
|
10537
10546
|
* @returns {Promise<Result<IntentStatusResponse, IntentErrorResponse>>} The intent status response
|
|
10538
10547
|
*
|
|
10539
10548
|
* @example
|
|
10540
10549
|
* const intentStatusRequest = {
|
|
10541
|
-
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
10550
|
+
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b" // destination tx hash from relay packet
|
|
10542
10551
|
* } satisfies IntentStatusRequest
|
|
10543
10552
|
*
|
|
10544
10553
|
* const response = await solverService.getStatus(intentStatusRequest);
|
|
@@ -10762,10 +10771,16 @@ var SolverService = class {
|
|
|
10762
10771
|
*
|
|
10763
10772
|
* const txReceipt = approveResult.value;
|
|
10764
10773
|
*/
|
|
10765
|
-
async approve(token, amount,
|
|
10774
|
+
async approve(token, amount, spokeProvider, raw) {
|
|
10766
10775
|
try {
|
|
10767
10776
|
if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
|
|
10768
|
-
const result = await Erc20Service.approve(
|
|
10777
|
+
const result = await Erc20Service.approve(
|
|
10778
|
+
token,
|
|
10779
|
+
amount,
|
|
10780
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
10781
|
+
spokeProvider,
|
|
10782
|
+
raw
|
|
10783
|
+
);
|
|
10769
10784
|
return {
|
|
10770
10785
|
ok: true,
|
|
10771
10786
|
value: result
|
|
@@ -10910,6 +10925,937 @@ var SolverService = class {
|
|
|
10910
10925
|
}
|
|
10911
10926
|
};
|
|
10912
10927
|
|
|
10928
|
+
// src/abis/icxSwap.abi.ts
|
|
10929
|
+
var icxSwapAbi = [
|
|
10930
|
+
{
|
|
10931
|
+
type: "constructor",
|
|
10932
|
+
inputs: [],
|
|
10933
|
+
stateMutability: "nonpayable"
|
|
10934
|
+
},
|
|
10935
|
+
{
|
|
10936
|
+
type: "function",
|
|
10937
|
+
name: "ICX",
|
|
10938
|
+
inputs: [],
|
|
10939
|
+
outputs: [
|
|
10940
|
+
{
|
|
10941
|
+
name: "",
|
|
10942
|
+
type: "address",
|
|
10943
|
+
internalType: "contract IERC20"
|
|
10944
|
+
}
|
|
10945
|
+
],
|
|
10946
|
+
stateMutability: "view"
|
|
10947
|
+
},
|
|
10948
|
+
{
|
|
10949
|
+
type: "function",
|
|
10950
|
+
name: "UPGRADE_INTERFACE_VERSION",
|
|
10951
|
+
inputs: [],
|
|
10952
|
+
outputs: [
|
|
10953
|
+
{
|
|
10954
|
+
name: "",
|
|
10955
|
+
type: "string",
|
|
10956
|
+
internalType: "string"
|
|
10957
|
+
}
|
|
10958
|
+
],
|
|
10959
|
+
stateMutability: "view"
|
|
10960
|
+
},
|
|
10961
|
+
{
|
|
10962
|
+
type: "function",
|
|
10963
|
+
name: "getImplementation",
|
|
10964
|
+
inputs: [],
|
|
10965
|
+
outputs: [
|
|
10966
|
+
{
|
|
10967
|
+
name: "",
|
|
10968
|
+
type: "address",
|
|
10969
|
+
internalType: "address"
|
|
10970
|
+
}
|
|
10971
|
+
],
|
|
10972
|
+
stateMutability: "view"
|
|
10973
|
+
},
|
|
10974
|
+
{
|
|
10975
|
+
type: "function",
|
|
10976
|
+
name: "initialize",
|
|
10977
|
+
inputs: [],
|
|
10978
|
+
outputs: [],
|
|
10979
|
+
stateMutability: "nonpayable"
|
|
10980
|
+
},
|
|
10981
|
+
{
|
|
10982
|
+
type: "function",
|
|
10983
|
+
name: "owner",
|
|
10984
|
+
inputs: [],
|
|
10985
|
+
outputs: [
|
|
10986
|
+
{
|
|
10987
|
+
name: "",
|
|
10988
|
+
type: "address",
|
|
10989
|
+
internalType: "address"
|
|
10990
|
+
}
|
|
10991
|
+
],
|
|
10992
|
+
stateMutability: "view"
|
|
10993
|
+
},
|
|
10994
|
+
{
|
|
10995
|
+
type: "function",
|
|
10996
|
+
name: "pendingMigrations",
|
|
10997
|
+
inputs: [
|
|
10998
|
+
{
|
|
10999
|
+
name: "",
|
|
11000
|
+
type: "uint256",
|
|
11001
|
+
internalType: "uint256"
|
|
11002
|
+
}
|
|
11003
|
+
],
|
|
11004
|
+
outputs: [
|
|
11005
|
+
{
|
|
11006
|
+
name: "user",
|
|
11007
|
+
type: "address",
|
|
11008
|
+
internalType: "address"
|
|
11009
|
+
},
|
|
11010
|
+
{
|
|
11011
|
+
name: "to",
|
|
11012
|
+
type: "address",
|
|
11013
|
+
internalType: "address"
|
|
11014
|
+
},
|
|
11015
|
+
{
|
|
11016
|
+
name: "amount",
|
|
11017
|
+
type: "uint256",
|
|
11018
|
+
internalType: "uint256"
|
|
11019
|
+
},
|
|
11020
|
+
{
|
|
11021
|
+
name: "timestamp",
|
|
11022
|
+
type: "uint256",
|
|
11023
|
+
internalType: "uint256"
|
|
11024
|
+
}
|
|
11025
|
+
],
|
|
11026
|
+
stateMutability: "view"
|
|
11027
|
+
},
|
|
11028
|
+
{
|
|
11029
|
+
type: "function",
|
|
11030
|
+
name: "reverseSwap",
|
|
11031
|
+
inputs: [
|
|
11032
|
+
{
|
|
11033
|
+
name: "amount",
|
|
11034
|
+
type: "uint256",
|
|
11035
|
+
internalType: "uint256"
|
|
11036
|
+
},
|
|
11037
|
+
{
|
|
11038
|
+
name: "to",
|
|
11039
|
+
type: "address",
|
|
11040
|
+
internalType: "address"
|
|
11041
|
+
}
|
|
11042
|
+
],
|
|
11043
|
+
outputs: [],
|
|
11044
|
+
stateMutability: "nonpayable"
|
|
11045
|
+
},
|
|
11046
|
+
{
|
|
11047
|
+
type: "function",
|
|
11048
|
+
name: "reverseSwapEnabled",
|
|
11049
|
+
inputs: [],
|
|
11050
|
+
outputs: [
|
|
11051
|
+
{
|
|
11052
|
+
name: "",
|
|
11053
|
+
type: "bool",
|
|
11054
|
+
internalType: "bool"
|
|
11055
|
+
}
|
|
11056
|
+
],
|
|
11057
|
+
stateMutability: "view"
|
|
11058
|
+
},
|
|
11059
|
+
{
|
|
11060
|
+
type: "function",
|
|
11061
|
+
name: "sodax",
|
|
11062
|
+
inputs: [],
|
|
11063
|
+
outputs: [
|
|
11064
|
+
{
|
|
11065
|
+
name: "",
|
|
11066
|
+
type: "address",
|
|
11067
|
+
internalType: "contract IERC20"
|
|
11068
|
+
}
|
|
11069
|
+
],
|
|
11070
|
+
stateMutability: "view"
|
|
11071
|
+
},
|
|
11072
|
+
{
|
|
11073
|
+
type: "function",
|
|
11074
|
+
name: "swap",
|
|
11075
|
+
inputs: [
|
|
11076
|
+
{
|
|
11077
|
+
name: "amount",
|
|
11078
|
+
type: "uint256",
|
|
11079
|
+
internalType: "uint256"
|
|
11080
|
+
},
|
|
11081
|
+
{
|
|
11082
|
+
name: "to",
|
|
11083
|
+
type: "address",
|
|
11084
|
+
internalType: "address"
|
|
11085
|
+
}
|
|
11086
|
+
],
|
|
11087
|
+
outputs: [],
|
|
11088
|
+
stateMutability: "nonpayable"
|
|
11089
|
+
},
|
|
11090
|
+
{
|
|
11091
|
+
type: "event",
|
|
11092
|
+
name: "Initialized",
|
|
11093
|
+
inputs: [
|
|
11094
|
+
{
|
|
11095
|
+
name: "version",
|
|
11096
|
+
type: "uint64",
|
|
11097
|
+
indexed: false,
|
|
11098
|
+
internalType: "uint64"
|
|
11099
|
+
}
|
|
11100
|
+
],
|
|
11101
|
+
anonymous: false
|
|
11102
|
+
},
|
|
11103
|
+
{
|
|
11104
|
+
type: "event",
|
|
11105
|
+
name: "OwnershipTransferStarted",
|
|
11106
|
+
inputs: [
|
|
11107
|
+
{
|
|
11108
|
+
name: "previousOwner",
|
|
11109
|
+
type: "address",
|
|
11110
|
+
indexed: true,
|
|
11111
|
+
internalType: "address"
|
|
11112
|
+
},
|
|
11113
|
+
{
|
|
11114
|
+
name: "newOwner",
|
|
11115
|
+
type: "address",
|
|
11116
|
+
indexed: true,
|
|
11117
|
+
internalType: "address"
|
|
11118
|
+
}
|
|
11119
|
+
],
|
|
11120
|
+
anonymous: false
|
|
11121
|
+
},
|
|
11122
|
+
{
|
|
11123
|
+
type: "event",
|
|
11124
|
+
name: "OwnershipTransferred",
|
|
11125
|
+
inputs: [
|
|
11126
|
+
{
|
|
11127
|
+
name: "previousOwner",
|
|
11128
|
+
type: "address",
|
|
11129
|
+
indexed: true,
|
|
11130
|
+
internalType: "address"
|
|
11131
|
+
},
|
|
11132
|
+
{
|
|
11133
|
+
name: "newOwner",
|
|
11134
|
+
type: "address",
|
|
11135
|
+
indexed: true,
|
|
11136
|
+
internalType: "address"
|
|
11137
|
+
}
|
|
11138
|
+
],
|
|
11139
|
+
anonymous: false
|
|
11140
|
+
},
|
|
11141
|
+
{
|
|
11142
|
+
type: "event",
|
|
11143
|
+
name: "PendingMigrationApproved",
|
|
11144
|
+
inputs: [
|
|
11145
|
+
{
|
|
11146
|
+
name: "index",
|
|
11147
|
+
type: "uint256",
|
|
11148
|
+
indexed: false,
|
|
11149
|
+
internalType: "uint256"
|
|
11150
|
+
},
|
|
11151
|
+
{
|
|
11152
|
+
name: "user",
|
|
11153
|
+
type: "address",
|
|
11154
|
+
indexed: true,
|
|
11155
|
+
internalType: "address"
|
|
11156
|
+
},
|
|
11157
|
+
{
|
|
11158
|
+
name: "amount",
|
|
11159
|
+
type: "uint256",
|
|
11160
|
+
indexed: false,
|
|
11161
|
+
internalType: "uint256"
|
|
11162
|
+
}
|
|
11163
|
+
],
|
|
11164
|
+
anonymous: false
|
|
11165
|
+
},
|
|
11166
|
+
{
|
|
11167
|
+
type: "event",
|
|
11168
|
+
name: "PendingMigrationCreated",
|
|
11169
|
+
inputs: [
|
|
11170
|
+
{
|
|
11171
|
+
name: "user",
|
|
11172
|
+
type: "address",
|
|
11173
|
+
indexed: true,
|
|
11174
|
+
internalType: "address"
|
|
11175
|
+
},
|
|
11176
|
+
{
|
|
11177
|
+
name: "amount",
|
|
11178
|
+
type: "uint256",
|
|
11179
|
+
indexed: false,
|
|
11180
|
+
internalType: "uint256"
|
|
11181
|
+
},
|
|
11182
|
+
{
|
|
11183
|
+
name: "index",
|
|
11184
|
+
type: "uint256",
|
|
11185
|
+
indexed: false,
|
|
11186
|
+
internalType: "uint256"
|
|
11187
|
+
}
|
|
11188
|
+
],
|
|
11189
|
+
anonymous: false
|
|
11190
|
+
},
|
|
11191
|
+
{
|
|
11192
|
+
type: "event",
|
|
11193
|
+
name: "ReverseSwap",
|
|
11194
|
+
inputs: [
|
|
11195
|
+
{
|
|
11196
|
+
name: "user",
|
|
11197
|
+
type: "address",
|
|
11198
|
+
indexed: true,
|
|
11199
|
+
internalType: "address"
|
|
11200
|
+
},
|
|
11201
|
+
{
|
|
11202
|
+
name: "sodaxAmount",
|
|
11203
|
+
type: "uint256",
|
|
11204
|
+
indexed: false,
|
|
11205
|
+
internalType: "uint256"
|
|
11206
|
+
},
|
|
11207
|
+
{
|
|
11208
|
+
name: "ICXAmount",
|
|
11209
|
+
type: "uint256",
|
|
11210
|
+
indexed: false,
|
|
11211
|
+
internalType: "uint256"
|
|
11212
|
+
}
|
|
11213
|
+
],
|
|
11214
|
+
anonymous: false
|
|
11215
|
+
},
|
|
11216
|
+
{
|
|
11217
|
+
type: "event",
|
|
11218
|
+
name: "ReverseSwapToggled",
|
|
11219
|
+
inputs: [
|
|
11220
|
+
{
|
|
11221
|
+
name: "enabled",
|
|
11222
|
+
type: "bool",
|
|
11223
|
+
indexed: false,
|
|
11224
|
+
internalType: "bool"
|
|
11225
|
+
}
|
|
11226
|
+
],
|
|
11227
|
+
anonymous: false
|
|
11228
|
+
},
|
|
11229
|
+
{
|
|
11230
|
+
type: "event",
|
|
11231
|
+
name: "Swap",
|
|
11232
|
+
inputs: [
|
|
11233
|
+
{
|
|
11234
|
+
name: "user",
|
|
11235
|
+
type: "address",
|
|
11236
|
+
indexed: true,
|
|
11237
|
+
internalType: "address"
|
|
11238
|
+
},
|
|
11239
|
+
{
|
|
11240
|
+
name: "ICXAmount",
|
|
11241
|
+
type: "uint256",
|
|
11242
|
+
indexed: false,
|
|
11243
|
+
internalType: "uint256"
|
|
11244
|
+
},
|
|
11245
|
+
{
|
|
11246
|
+
name: "sodaxAmount",
|
|
11247
|
+
type: "uint256",
|
|
11248
|
+
indexed: false,
|
|
11249
|
+
internalType: "uint256"
|
|
11250
|
+
}
|
|
11251
|
+
],
|
|
11252
|
+
anonymous: false
|
|
11253
|
+
},
|
|
11254
|
+
{
|
|
11255
|
+
type: "event",
|
|
11256
|
+
name: "Upgraded",
|
|
11257
|
+
inputs: [
|
|
11258
|
+
{
|
|
11259
|
+
name: "implementation",
|
|
11260
|
+
type: "address",
|
|
11261
|
+
indexed: true,
|
|
11262
|
+
internalType: "address"
|
|
11263
|
+
}
|
|
11264
|
+
],
|
|
11265
|
+
anonymous: false
|
|
11266
|
+
},
|
|
11267
|
+
{
|
|
11268
|
+
type: "error",
|
|
11269
|
+
name: "AddressEmptyCode",
|
|
11270
|
+
inputs: [
|
|
11271
|
+
{
|
|
11272
|
+
name: "target",
|
|
11273
|
+
type: "address",
|
|
11274
|
+
internalType: "address"
|
|
11275
|
+
}
|
|
11276
|
+
]
|
|
11277
|
+
},
|
|
11278
|
+
{
|
|
11279
|
+
type: "error",
|
|
11280
|
+
name: "ERC1967InvalidImplementation",
|
|
11281
|
+
inputs: [
|
|
11282
|
+
{
|
|
11283
|
+
name: "implementation",
|
|
11284
|
+
type: "address",
|
|
11285
|
+
internalType: "address"
|
|
11286
|
+
}
|
|
11287
|
+
]
|
|
11288
|
+
},
|
|
11289
|
+
{
|
|
11290
|
+
type: "error",
|
|
11291
|
+
name: "ERC1967NonPayable",
|
|
11292
|
+
inputs: []
|
|
11293
|
+
},
|
|
11294
|
+
{
|
|
11295
|
+
type: "error",
|
|
11296
|
+
name: "FailedCall",
|
|
11297
|
+
inputs: []
|
|
11298
|
+
},
|
|
11299
|
+
{
|
|
11300
|
+
type: "error",
|
|
11301
|
+
name: "InvalidInitialization",
|
|
11302
|
+
inputs: []
|
|
11303
|
+
},
|
|
11304
|
+
{
|
|
11305
|
+
type: "error",
|
|
11306
|
+
name: "NotInitializing",
|
|
11307
|
+
inputs: []
|
|
11308
|
+
},
|
|
11309
|
+
{
|
|
11310
|
+
type: "error",
|
|
11311
|
+
name: "OwnableInvalidOwner",
|
|
11312
|
+
inputs: [
|
|
11313
|
+
{
|
|
11314
|
+
name: "owner",
|
|
11315
|
+
type: "address",
|
|
11316
|
+
internalType: "address"
|
|
11317
|
+
}
|
|
11318
|
+
]
|
|
11319
|
+
},
|
|
11320
|
+
{
|
|
11321
|
+
type: "error",
|
|
11322
|
+
name: "OwnableUnauthorizedAccount",
|
|
11323
|
+
inputs: [
|
|
11324
|
+
{
|
|
11325
|
+
name: "account",
|
|
11326
|
+
type: "address",
|
|
11327
|
+
internalType: "address"
|
|
11328
|
+
}
|
|
11329
|
+
]
|
|
11330
|
+
},
|
|
11331
|
+
{
|
|
11332
|
+
type: "error",
|
|
11333
|
+
name: "ReentrancyGuardReentrantCall",
|
|
11334
|
+
inputs: []
|
|
11335
|
+
},
|
|
11336
|
+
{
|
|
11337
|
+
type: "error",
|
|
11338
|
+
name: "SafeERC20FailedOperation",
|
|
11339
|
+
inputs: [
|
|
11340
|
+
{
|
|
11341
|
+
name: "token",
|
|
11342
|
+
type: "address",
|
|
11343
|
+
internalType: "address"
|
|
11344
|
+
}
|
|
11345
|
+
]
|
|
11346
|
+
},
|
|
11347
|
+
{
|
|
11348
|
+
type: "error",
|
|
11349
|
+
name: "UUPSUnauthorizedCallContext",
|
|
11350
|
+
inputs: []
|
|
11351
|
+
},
|
|
11352
|
+
{
|
|
11353
|
+
type: "error",
|
|
11354
|
+
name: "UUPSUnsupportedProxiableUUID",
|
|
11355
|
+
inputs: [
|
|
11356
|
+
{
|
|
11357
|
+
name: "slot",
|
|
11358
|
+
type: "bytes32",
|
|
11359
|
+
internalType: "bytes32"
|
|
11360
|
+
}
|
|
11361
|
+
]
|
|
11362
|
+
}
|
|
11363
|
+
];
|
|
11364
|
+
var IcxMigrationService = class {
|
|
11365
|
+
hubProvider;
|
|
11366
|
+
constructor(hubProvider) {
|
|
11367
|
+
this.hubProvider = hubProvider;
|
|
11368
|
+
}
|
|
11369
|
+
/**
|
|
11370
|
+
* Retrieves the available amount of SODA tokens in the ICX migration contract.
|
|
11371
|
+
* This represents the amount of tokens available for migration.
|
|
11372
|
+
*
|
|
11373
|
+
* @returns The available balance of SODA tokens in the migration contract
|
|
11374
|
+
*/
|
|
11375
|
+
async getAvailableAmount() {
|
|
11376
|
+
const balance = await this.hubProvider.publicClient.readContract({
|
|
11377
|
+
address: this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11378
|
+
abi: erc20Abi,
|
|
11379
|
+
functionName: "balanceOf",
|
|
11380
|
+
args: [this.hubProvider.chainConfig.addresses.icxMigration]
|
|
11381
|
+
});
|
|
11382
|
+
return balance;
|
|
11383
|
+
}
|
|
11384
|
+
/**
|
|
11385
|
+
* Generates transaction data for migrating wICX tokens from ICON to the hub chain.
|
|
11386
|
+
* This method creates the necessary contract calls to:
|
|
11387
|
+
* 1. Approve the migration contract to spend the wICX tokens
|
|
11388
|
+
* 2. Execute the migration swap
|
|
11389
|
+
*
|
|
11390
|
+
* @param params - The migration parameters including token address, amount, and recipient
|
|
11391
|
+
* @returns Encoded transaction data for the migration operation
|
|
11392
|
+
* @throws Will throw an error if the hub asset configuration is not found
|
|
11393
|
+
*/
|
|
11394
|
+
migrateData(params) {
|
|
11395
|
+
const calls = [];
|
|
11396
|
+
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.icx);
|
|
11397
|
+
invariant2(assetConfig, `hub asset not found for spoke chain token (token): ${params.icx}`);
|
|
11398
|
+
calls.push(
|
|
11399
|
+
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
11400
|
+
);
|
|
11401
|
+
calls.push(this.encodeMigrate(params.amount, params.to));
|
|
11402
|
+
return encodeContractCalls(calls);
|
|
11403
|
+
}
|
|
11404
|
+
/**
|
|
11405
|
+
* Generates transaction data for migrating back tokens to the ICON chain.
|
|
11406
|
+
* @param params - The migration parameters including token address, amount, and recipient
|
|
11407
|
+
* @returns Encoded transaction data for the migration operation
|
|
11408
|
+
* @throws Will throw an error if the hub asset configuration is not found
|
|
11409
|
+
*/
|
|
11410
|
+
revertMigration(params) {
|
|
11411
|
+
const calls = [];
|
|
11412
|
+
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
11413
|
+
invariant2(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
11414
|
+
calls.push(
|
|
11415
|
+
Erc20Service.encodeApprove(
|
|
11416
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11417
|
+
this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11418
|
+
params.amount
|
|
11419
|
+
)
|
|
11420
|
+
);
|
|
11421
|
+
calls.push(this.encodeRevertMigration(params.amount, params.userWallet));
|
|
11422
|
+
calls.push(
|
|
11423
|
+
EvmAssetManagerService.encodeTransfer(
|
|
11424
|
+
assetConfig.asset,
|
|
11425
|
+
params.to,
|
|
11426
|
+
params.amount,
|
|
11427
|
+
this.hubProvider.chainConfig.addresses.assetManager
|
|
11428
|
+
)
|
|
11429
|
+
);
|
|
11430
|
+
return encodeContractCalls(calls);
|
|
11431
|
+
}
|
|
11432
|
+
/**
|
|
11433
|
+
* Encodes a migration transaction for the ICX swap contract.
|
|
11434
|
+
* This creates the contract call data for swapping wICX tokens to SODA tokens.
|
|
11435
|
+
*
|
|
11436
|
+
* @param amount - The amount of wICX tokens to migrate
|
|
11437
|
+
* @param to - The address that will receive the migrated SODA tokens
|
|
11438
|
+
* @returns The encoded contract call for the migration operation
|
|
11439
|
+
*/
|
|
11440
|
+
encodeMigrate(amount, to) {
|
|
11441
|
+
return {
|
|
11442
|
+
address: this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11443
|
+
value: 0n,
|
|
11444
|
+
data: encodeFunctionData({
|
|
11445
|
+
abi: icxSwapAbi,
|
|
11446
|
+
functionName: "swap",
|
|
11447
|
+
args: [amount, to]
|
|
11448
|
+
})
|
|
11449
|
+
};
|
|
11450
|
+
}
|
|
11451
|
+
/**
|
|
11452
|
+
* Encodes a revert migration transaction for the ICX swap contract.
|
|
11453
|
+
* This creates the contract call data for swapping SODA tokens to wICX tokens.
|
|
11454
|
+
*
|
|
11455
|
+
* @param amount - The amount of wICX tokens to migrate
|
|
11456
|
+
* @param to - The address that will receive the migrated SODA tokens
|
|
11457
|
+
* @returns The encoded contract call for the migration operation
|
|
11458
|
+
*/
|
|
11459
|
+
encodeRevertMigration(amount, to) {
|
|
11460
|
+
return {
|
|
11461
|
+
address: this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11462
|
+
value: 0n,
|
|
11463
|
+
data: encodeFunctionData({
|
|
11464
|
+
abi: icxSwapAbi,
|
|
11465
|
+
functionName: "reverseSwap",
|
|
11466
|
+
args: [amount, to]
|
|
11467
|
+
})
|
|
11468
|
+
};
|
|
11469
|
+
}
|
|
11470
|
+
};
|
|
11471
|
+
var MigrationService = class {
|
|
11472
|
+
icxMigration;
|
|
11473
|
+
hubProvider;
|
|
11474
|
+
config;
|
|
11475
|
+
constructor(hubProvider, config) {
|
|
11476
|
+
this.hubProvider = hubProvider;
|
|
11477
|
+
this.icxMigration = new IcxMigrationService(hubProvider);
|
|
11478
|
+
this.config = config ?? {
|
|
11479
|
+
relayerApiEndpoint: DEFAULT_RELAYER_API_ENDPOINT
|
|
11480
|
+
};
|
|
11481
|
+
}
|
|
11482
|
+
async migrateData(params) {
|
|
11483
|
+
return this.icxMigration.migrateData(params);
|
|
11484
|
+
}
|
|
11485
|
+
/**
|
|
11486
|
+
* Checks if the allowance is valid for the migration transaction.
|
|
11487
|
+
* @param params - The parameters for the migration transaction.
|
|
11488
|
+
* @param spokeProvider - The spoke provider.
|
|
11489
|
+
* @returns {Promise<Result<boolean>>} - Returns the result of the allowance check or error
|
|
11490
|
+
*
|
|
11491
|
+
* @example
|
|
11492
|
+
* const result = await migrationService.isAllowanceValid(
|
|
11493
|
+
* {
|
|
11494
|
+
* token: 'ICX', // Token to migrate
|
|
11495
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11496
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11497
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11498
|
+
* action: 'migrate', // Action to perform (migrate or revert)
|
|
11499
|
+
* },
|
|
11500
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11501
|
+
* );
|
|
11502
|
+
*
|
|
11503
|
+
*/
|
|
11504
|
+
async isAllowanceValid(params, spokeProvider) {
|
|
11505
|
+
try {
|
|
11506
|
+
if (params.action === "migrate") {
|
|
11507
|
+
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
11508
|
+
invariant2(isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
11509
|
+
invariant2(
|
|
11510
|
+
spokeProvider instanceof IconSpokeProvider,
|
|
11511
|
+
"Spoke provider must be an instance of IconSpokeProvider"
|
|
11512
|
+
);
|
|
11513
|
+
invariant2(
|
|
11514
|
+
params.icx.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.icx.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
11515
|
+
"Token must be wICX or native ICX token"
|
|
11516
|
+
);
|
|
11517
|
+
invariant2(params.token === "ICX", "Token must be ICX");
|
|
11518
|
+
return {
|
|
11519
|
+
ok: true,
|
|
11520
|
+
value: true
|
|
11521
|
+
};
|
|
11522
|
+
}
|
|
11523
|
+
if (params.action === "revert") {
|
|
11524
|
+
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
11525
|
+
invariant2(isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
11526
|
+
invariant2(
|
|
11527
|
+
spokeProvider instanceof SonicSpokeProvider,
|
|
11528
|
+
"Spoke provider must be an instance of SonicSpokeProvider"
|
|
11529
|
+
);
|
|
11530
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11531
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11532
|
+
return await Erc20Service.isAllowanceValid(
|
|
11533
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11534
|
+
params.amount,
|
|
11535
|
+
wallet,
|
|
11536
|
+
userRouter,
|
|
11537
|
+
spokeProvider
|
|
11538
|
+
);
|
|
11539
|
+
}
|
|
11540
|
+
return {
|
|
11541
|
+
ok: false,
|
|
11542
|
+
error: new Error("Invalid action")
|
|
11543
|
+
};
|
|
11544
|
+
} catch (error) {
|
|
11545
|
+
return {
|
|
11546
|
+
ok: false,
|
|
11547
|
+
error
|
|
11548
|
+
};
|
|
11549
|
+
}
|
|
11550
|
+
}
|
|
11551
|
+
/**
|
|
11552
|
+
* Approves the amount spending for the revert migration transaction.
|
|
11553
|
+
* @param params - The parameters for the revert migration transaction.
|
|
11554
|
+
* @param spokeProvider - The spoke provider.
|
|
11555
|
+
* @param raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11556
|
+
* @returns {Promise<Result<TxReturnType<S, R>>>} - Returns the raw transaction payload or transaction hash
|
|
11557
|
+
*
|
|
11558
|
+
* @example
|
|
11559
|
+
* const result = await migrationService.approve(
|
|
11560
|
+
* {
|
|
11561
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11562
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11563
|
+
* action: 'revert',
|
|
11564
|
+
* },
|
|
11565
|
+
* spokeProvider, // SonicSpokeProvider instance
|
|
11566
|
+
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
11567
|
+
* );
|
|
11568
|
+
*
|
|
11569
|
+
*/
|
|
11570
|
+
async approve(params, spokeProvider, raw) {
|
|
11571
|
+
try {
|
|
11572
|
+
if (params.action === "revert") {
|
|
11573
|
+
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
11574
|
+
invariant2(params.to.length > 0, "To address is required");
|
|
11575
|
+
invariant2(
|
|
11576
|
+
spokeProvider instanceof SonicSpokeProvider,
|
|
11577
|
+
"Spoke provider must be an instance of SonicSpokeProvider"
|
|
11578
|
+
);
|
|
11579
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11580
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11581
|
+
const result = await Erc20Service.approve(
|
|
11582
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11583
|
+
params.amount,
|
|
11584
|
+
userRouter,
|
|
11585
|
+
spokeProvider,
|
|
11586
|
+
raw
|
|
11587
|
+
);
|
|
11588
|
+
return {
|
|
11589
|
+
ok: true,
|
|
11590
|
+
value: result
|
|
11591
|
+
};
|
|
11592
|
+
}
|
|
11593
|
+
return {
|
|
11594
|
+
ok: false,
|
|
11595
|
+
error: new Error("Invalid action")
|
|
11596
|
+
};
|
|
11597
|
+
} catch (error) {
|
|
11598
|
+
return {
|
|
11599
|
+
ok: false,
|
|
11600
|
+
error
|
|
11601
|
+
};
|
|
11602
|
+
}
|
|
11603
|
+
}
|
|
11604
|
+
/**
|
|
11605
|
+
* Creates a migration intent and submits (relays) it to the hub chain.
|
|
11606
|
+
* @param params - The parameters for the migration transaction.
|
|
11607
|
+
* @param spokeProvider - The spoke provider.
|
|
11608
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
11609
|
+
* @returns {Promise<Result<[Hex, Hex], MigrationError<'MIGRATION_FAILED'> | MigrationError<'CREATE_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
11610
|
+
* Returns a Result containing a tuple of [spokeTxHash, hubTxHash] if successful,
|
|
11611
|
+
* or an error describing why the migration or relay failed.
|
|
11612
|
+
*
|
|
11613
|
+
* @example
|
|
11614
|
+
* const result = await migrationService.createAndSubmitMigrateIntent(
|
|
11615
|
+
* {
|
|
11616
|
+
* token: 'ICX', // Token to migrate
|
|
11617
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11618
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11619
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11620
|
+
* action: 'migrate',
|
|
11621
|
+
* },
|
|
11622
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11623
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
11624
|
+
* );
|
|
11625
|
+
*
|
|
11626
|
+
* if (!result.ok) {
|
|
11627
|
+
* // Handle error
|
|
11628
|
+
* }
|
|
11629
|
+
*
|
|
11630
|
+
* const [
|
|
11631
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
11632
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
11633
|
+
* ] = result.value;
|
|
11634
|
+
* console.log('Migration transaction hashes:', { spokeTxHash, hubTxHash });
|
|
11635
|
+
*/
|
|
11636
|
+
async createAndSubmitMigrateIntent(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
11637
|
+
try {
|
|
11638
|
+
const txResult = await this.createMigrateIntent(params, spokeProvider);
|
|
11639
|
+
if (!txResult.ok) {
|
|
11640
|
+
return {
|
|
11641
|
+
ok: false,
|
|
11642
|
+
error: txResult.error
|
|
11643
|
+
};
|
|
11644
|
+
}
|
|
11645
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
11646
|
+
txResult.value,
|
|
11647
|
+
spokeProvider,
|
|
11648
|
+
this.config.relayerApiEndpoint,
|
|
11649
|
+
timeout
|
|
11650
|
+
);
|
|
11651
|
+
if (!packetResult.ok) {
|
|
11652
|
+
return packetResult;
|
|
11653
|
+
}
|
|
11654
|
+
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
11655
|
+
} catch (error) {
|
|
11656
|
+
return {
|
|
11657
|
+
ok: false,
|
|
11658
|
+
error: {
|
|
11659
|
+
code: "MIGRATION_FAILED",
|
|
11660
|
+
data: {
|
|
11661
|
+
payload: params,
|
|
11662
|
+
error
|
|
11663
|
+
}
|
|
11664
|
+
}
|
|
11665
|
+
};
|
|
11666
|
+
}
|
|
11667
|
+
}
|
|
11668
|
+
/**
|
|
11669
|
+
* Creates a revert migration (SODA to ICX) intent and submits (relays) it to the spoke chain.
|
|
11670
|
+
* @param params - The parameters for the revert migration transaction.
|
|
11671
|
+
* @param spokeProvider - The SonicSpokeProvider instance.
|
|
11672
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
11673
|
+
*
|
|
11674
|
+
* @returns {Promise<Result<[Hex, Hex], MigrationError<'REVERT_MIGRATION_FAILED'> | MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
11675
|
+
* Returns a Result containing a tuple of [hubTxHash, spokeTxHash] if successful,
|
|
11676
|
+
* or an error describing why the revert migration or relay failed.
|
|
11677
|
+
*
|
|
11678
|
+
*
|
|
11679
|
+
* @example
|
|
11680
|
+
* const result = await migrationService.createAndSubmitRevertMigrationIntent(
|
|
11681
|
+
* {
|
|
11682
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11683
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11684
|
+
* action: 'revert',
|
|
11685
|
+
* },
|
|
11686
|
+
* spokeProvider, // SonicSpokeProvider instance
|
|
11687
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
11688
|
+
* );
|
|
11689
|
+
*
|
|
11690
|
+
* if (!result.ok) {
|
|
11691
|
+
* // Handle error
|
|
11692
|
+
* }
|
|
11693
|
+
*
|
|
11694
|
+
* const [
|
|
11695
|
+
* hubTxHash, // transaction hash on the hub chain
|
|
11696
|
+
* spokeTxHash, // transaction hash on the spoke chain (i.e. the transaction that was relayed to the spoke)
|
|
11697
|
+
* ] = result.value;
|
|
11698
|
+
* console.log('Revert migration transaction hashes:', { hubTxHash, spokeTxHash });
|
|
11699
|
+
*/
|
|
11700
|
+
async createAndSubmitRevertMigrationIntent(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
11701
|
+
try {
|
|
11702
|
+
const txResult = await this.createRevertMigrationIntent(params, spokeProvider);
|
|
11703
|
+
if (!txResult.ok) {
|
|
11704
|
+
return txResult;
|
|
11705
|
+
}
|
|
11706
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
11707
|
+
txResult.value,
|
|
11708
|
+
spokeProvider,
|
|
11709
|
+
this.config.relayerApiEndpoint,
|
|
11710
|
+
timeout
|
|
11711
|
+
);
|
|
11712
|
+
if (!packetResult.ok) {
|
|
11713
|
+
return packetResult;
|
|
11714
|
+
}
|
|
11715
|
+
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
11716
|
+
} catch (error) {
|
|
11717
|
+
return {
|
|
11718
|
+
ok: false,
|
|
11719
|
+
error: {
|
|
11720
|
+
code: "REVERT_MIGRATION_FAILED",
|
|
11721
|
+
data: {
|
|
11722
|
+
payload: params,
|
|
11723
|
+
error
|
|
11724
|
+
}
|
|
11725
|
+
}
|
|
11726
|
+
};
|
|
11727
|
+
}
|
|
11728
|
+
}
|
|
11729
|
+
/**
|
|
11730
|
+
* Migrates ICX or wICX tokens from ICON to the hub chain.
|
|
11731
|
+
* This function handles the migration of ICX or wICX tokens to SODA tokens on the hub chain.
|
|
11732
|
+
* Note: This function does not relay the transaction to the spoke chain.
|
|
11733
|
+
* You should call the `isAllowanceValid` function before calling this function to check if the allowance is valid.
|
|
11734
|
+
* You should call the `relayTxAndWaitPacket` function after calling this function to relay the transaction to the spoke chain.
|
|
11735
|
+
*
|
|
11736
|
+
* @param {MigrationParams} params - The parameters for the migration transaction.
|
|
11737
|
+
* @param {IconSpokeProvider} spokeProvider - The spoke provider.
|
|
11738
|
+
* @param {boolean} raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11739
|
+
* @returns {Promise<Result<TxReturnType<IconSpokeProvider, R>, MigrationError<'CREATE_MIGRATION_INTENT_FAILED'>>>} - Returns the raw transaction payload or transaction hash
|
|
11740
|
+
*
|
|
11741
|
+
* @example
|
|
11742
|
+
* const result = await migrationService.createMigrateIntent(
|
|
11743
|
+
* {
|
|
11744
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11745
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11746
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11747
|
+
* },
|
|
11748
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11749
|
+
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
11750
|
+
* );
|
|
11751
|
+
*
|
|
11752
|
+
* if (!result.ok) {
|
|
11753
|
+
* // Handle error
|
|
11754
|
+
* }
|
|
11755
|
+
*/
|
|
11756
|
+
async createMigrateIntent(params, spokeProvider, raw) {
|
|
11757
|
+
try {
|
|
11758
|
+
invariant2(params.amount > 0, "Amount must be greater than 0");
|
|
11759
|
+
invariant2(isAddress(params.to), "Recipient address is required");
|
|
11760
|
+
invariant2(
|
|
11761
|
+
params.icx.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.icx.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
11762
|
+
"Token must be wICX or native ICX token"
|
|
11763
|
+
);
|
|
11764
|
+
invariant2(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
11765
|
+
invariant2(params.token === "ICX", "Token must be ICX");
|
|
11766
|
+
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
11767
|
+
if (availableAmount < params.amount) {
|
|
11768
|
+
throw new Error(
|
|
11769
|
+
`Insufficient liquidity. Available: ${availableAmount.toString()}, Requested: ${params.amount.toString()}`
|
|
11770
|
+
);
|
|
11771
|
+
}
|
|
11772
|
+
const migrationData = this.icxMigration.migrateData(params);
|
|
11773
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11774
|
+
const txResult = await SpokeService.deposit(
|
|
11775
|
+
{
|
|
11776
|
+
from: walletAddress,
|
|
11777
|
+
token: params.icx,
|
|
11778
|
+
amount: params.amount,
|
|
11779
|
+
data: migrationData
|
|
11780
|
+
},
|
|
11781
|
+
spokeProvider,
|
|
11782
|
+
this.hubProvider,
|
|
11783
|
+
raw
|
|
11784
|
+
);
|
|
11785
|
+
return {
|
|
11786
|
+
ok: true,
|
|
11787
|
+
value: txResult
|
|
11788
|
+
};
|
|
11789
|
+
} catch (error) {
|
|
11790
|
+
return {
|
|
11791
|
+
ok: false,
|
|
11792
|
+
error: {
|
|
11793
|
+
code: "CREATE_MIGRATION_INTENT_FAILED",
|
|
11794
|
+
data: {
|
|
11795
|
+
payload: params,
|
|
11796
|
+
error
|
|
11797
|
+
}
|
|
11798
|
+
}
|
|
11799
|
+
};
|
|
11800
|
+
}
|
|
11801
|
+
}
|
|
11802
|
+
/**
|
|
11803
|
+
* Creates a revert migration intent transaction on the hub chain.
|
|
11804
|
+
* Note: This function does not relay the transaction to the spoke chain.
|
|
11805
|
+
* You should call the `isAllowanceValid` function before calling this function to check if the allowance is valid.
|
|
11806
|
+
* You should call the `relayTxAndWaitPacket` function after calling this function to relay the transaction to the spoke chain.
|
|
11807
|
+
* @param {IcxCreateRevertMigrationParams} - The parameters for the revert migration transaction.
|
|
11808
|
+
* @param {SonicSpokeProvider} spokeProvider - The spoke provider.
|
|
11809
|
+
* @param {boolean} raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11810
|
+
* @returns {Promise<Result<TxReturnType<SonicSpokeProvider, R>, MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'>>>} - Returns the transaction hash or error
|
|
11811
|
+
*
|
|
11812
|
+
* @example
|
|
11813
|
+
* const result = await migrationService.createRevertMigrationIntent(
|
|
11814
|
+
* {
|
|
11815
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11816
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11817
|
+
* action: 'revert',
|
|
11818
|
+
* },
|
|
11819
|
+
*/
|
|
11820
|
+
async createRevertMigrationIntent(params, spokeProvider, raw) {
|
|
11821
|
+
try {
|
|
11822
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11823
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11824
|
+
const data = this.icxMigration.revertMigration({
|
|
11825
|
+
wICX: spokeChainConfig[ICON_MAINNET_CHAIN_ID].addresses.wICX,
|
|
11826
|
+
amount: params.amount,
|
|
11827
|
+
to: encodeAddress(ICON_MAINNET_CHAIN_ID, params.to),
|
|
11828
|
+
userWallet: userRouter
|
|
11829
|
+
});
|
|
11830
|
+
const txResult = await SonicSpokeService.deposit(
|
|
11831
|
+
{
|
|
11832
|
+
from: wallet,
|
|
11833
|
+
token: this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11834
|
+
amount: params.amount,
|
|
11835
|
+
data
|
|
11836
|
+
},
|
|
11837
|
+
spokeProvider,
|
|
11838
|
+
raw
|
|
11839
|
+
);
|
|
11840
|
+
return {
|
|
11841
|
+
ok: true,
|
|
11842
|
+
value: txResult
|
|
11843
|
+
};
|
|
11844
|
+
} catch (error) {
|
|
11845
|
+
return {
|
|
11846
|
+
ok: false,
|
|
11847
|
+
error: {
|
|
11848
|
+
code: "CREATE_REVERT_MIGRATION_INTENT_FAILED",
|
|
11849
|
+
data: {
|
|
11850
|
+
payload: params,
|
|
11851
|
+
error
|
|
11852
|
+
}
|
|
11853
|
+
}
|
|
11854
|
+
};
|
|
11855
|
+
}
|
|
11856
|
+
}
|
|
11857
|
+
};
|
|
11858
|
+
|
|
10913
11859
|
// src/entities/Sodax.ts
|
|
10914
11860
|
var Sodax = class {
|
|
10915
11861
|
config;
|
|
@@ -10917,6 +11863,8 @@ var Sodax = class {
|
|
|
10917
11863
|
// Solver service enabling intent based swaps
|
|
10918
11864
|
moneyMarket;
|
|
10919
11865
|
// Money Market service enabling cross-chain lending and borrowing
|
|
11866
|
+
migration;
|
|
11867
|
+
// ICX migration service enabling ICX migration to SODA
|
|
10920
11868
|
hubProvider;
|
|
10921
11869
|
// hub provider for the hub chain (e.g. Sonic mainnet)
|
|
10922
11870
|
relayerApiEndpoint;
|
|
@@ -10927,6 +11875,7 @@ var Sodax = class {
|
|
|
10927
11875
|
this.hubProvider = new EvmHubProvider(config?.hubProviderConfig);
|
|
10928
11876
|
this.solver = config && config.solver ? new SolverService(config.solver, this.hubProvider, this.relayerApiEndpoint) : new SolverService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
10929
11877
|
this.moneyMarket = config && config.moneyMarket ? new MoneyMarketService(config.moneyMarket, this.hubProvider, this.relayerApiEndpoint) : new MoneyMarketService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
11878
|
+
this.migration = config && config.migration ? new MigrationService(this.hubProvider, config.migration) : new MigrationService(this.hubProvider);
|
|
10930
11879
|
}
|
|
10931
11880
|
};
|
|
10932
11881
|
|
|
@@ -10961,6 +11910,6 @@ var IntentErrorCode = /* @__PURE__ */ ((IntentErrorCode2) => {
|
|
|
10961
11910
|
return IntentErrorCode2;
|
|
10962
11911
|
})(IntentErrorCode || {});
|
|
10963
11912
|
|
|
10964
|
-
export { BigIntToHex, CWSpokeProvider, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentErrorCode, IntentStatusCode, IntentsAbi, MAX_UINT256, MoneyMarketService, Sodax, SolanaSpokeProvider, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isCWSpokeProvider, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIntentRelayChainId, isJsonRpcPayloadResponse, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSupportedToken, isNativeToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, originalAssetTohubAssetMap, poolAbi, randomUint256, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, variableDebtTokenAbi, vaultTokenAbi, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
11913
|
+
export { BigIntToHex, CWSpokeProvider, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, IntentCreatedEventAbi, IntentDataType, IntentErrorCode, IntentStatusCode, IntentsAbi, MAX_UINT256, MigrationService, MoneyMarketService, Sodax, SolanaSpokeProvider, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isCWSpokeProvider, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIntentRelayChainId, isJsonRpcPayloadResponse, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSupportedToken, isNativeToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, originalAssetTohubAssetMap, poolAbi, randomUint256, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, variableDebtTokenAbi, vaultTokenAbi, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
10965
11914
|
//# sourceMappingURL=index.mjs.map
|
|
10966
11915
|
//# sourceMappingURL=index.mjs.map
|