@sodax/sdk 0.0.1-rc.25 → 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 +225 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +224 -128
- 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
|
}
|
|
@@ -10241,6 +10241,58 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10241
10241
|
}
|
|
10242
10242
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
10243
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
|
+
}
|
|
10244
10296
|
/**
|
|
10245
10297
|
* Get the balance of the token in the spoke chain.
|
|
10246
10298
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -10971,19 +11023,19 @@ async function postRequest(payload, apiUrl) {
|
|
|
10971
11023
|
return response.json();
|
|
10972
11024
|
}
|
|
10973
11025
|
async function submitTransaction(payload, apiUrl) {
|
|
10974
|
-
|
|
10975
|
-
|
|
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");
|
|
10976
11028
|
return postRequest(payload, apiUrl);
|
|
10977
11029
|
}
|
|
10978
11030
|
async function getTransactionPackets(payload, apiUrl) {
|
|
10979
|
-
|
|
10980
|
-
|
|
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");
|
|
10981
11033
|
return postRequest(payload, apiUrl);
|
|
10982
11034
|
}
|
|
10983
11035
|
async function getPacket(payload, apiUrl) {
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
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");
|
|
10987
11039
|
return postRequest(payload, apiUrl);
|
|
10988
11040
|
}
|
|
10989
11041
|
async function waitUntilIntentExecuted(payload) {
|
|
@@ -11114,11 +11166,11 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11114
11166
|
inputToken = hubProvider.chainConfig.wrappedNativeToken;
|
|
11115
11167
|
}
|
|
11116
11168
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
11117
|
-
|
|
11169
|
+
invariant11(
|
|
11118
11170
|
inputToken,
|
|
11119
11171
|
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
11120
11172
|
);
|
|
11121
|
-
|
|
11173
|
+
invariant11(
|
|
11122
11174
|
outputToken,
|
|
11123
11175
|
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
11124
11176
|
);
|
|
@@ -11150,7 +11202,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11150
11202
|
* @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
|
|
11151
11203
|
*/
|
|
11152
11204
|
static createIntentFeeData(fee, inputAmount) {
|
|
11153
|
-
|
|
11205
|
+
invariant11(inputAmount > 0n, "Input amount must be greater than 0");
|
|
11154
11206
|
if (!fee) {
|
|
11155
11207
|
return ["0x", 0n];
|
|
11156
11208
|
}
|
|
@@ -11158,7 +11210,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11158
11210
|
if (isPartnerFeeAmount(fee)) {
|
|
11159
11211
|
feeAmount = fee.amount;
|
|
11160
11212
|
} else if (isPartnerFeePercentage(fee)) {
|
|
11161
|
-
|
|
11213
|
+
invariant11(
|
|
11162
11214
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
11163
11215
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
11164
11216
|
);
|
|
@@ -11285,23 +11337,23 @@ var SolverApiService = class {
|
|
|
11285
11337
|
* }
|
|
11286
11338
|
*/
|
|
11287
11339
|
static async getQuote(payload, config) {
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
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(
|
|
11294
11346
|
isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
|
|
11295
11347
|
"unsupported token_src for src chain"
|
|
11296
11348
|
);
|
|
11297
|
-
|
|
11349
|
+
invariant11(
|
|
11298
11350
|
isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
|
|
11299
11351
|
"unsupported token_dst for dst chain"
|
|
11300
11352
|
);
|
|
11301
11353
|
const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
|
|
11302
11354
|
const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
|
|
11303
|
-
|
|
11304
|
-
|
|
11355
|
+
invariant11(tokenSrc, "hub asset not found for token_src");
|
|
11356
|
+
invariant11(tokenDst, "hub asset not found for token_dst");
|
|
11305
11357
|
try {
|
|
11306
11358
|
const response = await fetch(`${config.solverApiEndpoint}/quote`, {
|
|
11307
11359
|
method: "POST",
|
|
@@ -11396,7 +11448,7 @@ var SolverApiService = class {
|
|
|
11396
11448
|
}
|
|
11397
11449
|
}
|
|
11398
11450
|
static async getStatus(request, config) {
|
|
11399
|
-
|
|
11451
|
+
invariant11(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
|
|
11400
11452
|
try {
|
|
11401
11453
|
const response = await fetch(`${config.solverApiEndpoint}/status`, {
|
|
11402
11454
|
method: "POST",
|
|
@@ -11857,13 +11909,23 @@ var SolverService = class {
|
|
|
11857
11909
|
spokeProvider
|
|
11858
11910
|
}) {
|
|
11859
11911
|
try {
|
|
11860
|
-
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) {
|
|
11861
11923
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11862
11924
|
return await Erc20Service.isAllowanceValid(
|
|
11863
11925
|
params.inputToken,
|
|
11864
11926
|
params.inputAmount,
|
|
11865
11927
|
walletAddress,
|
|
11866
|
-
|
|
11928
|
+
getSolverConfig(SONIC_MAINNET_CHAIN_ID).intentsContract,
|
|
11867
11929
|
spokeProvider
|
|
11868
11930
|
);
|
|
11869
11931
|
}
|
|
@@ -11922,7 +11984,7 @@ var SolverService = class {
|
|
|
11922
11984
|
raw
|
|
11923
11985
|
}) {
|
|
11924
11986
|
try {
|
|
11925
|
-
if (spokeProvider instanceof EvmSpokeProvider
|
|
11987
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
11926
11988
|
const result = await Erc20Service.approve(
|
|
11927
11989
|
params.inputToken,
|
|
11928
11990
|
params.inputAmount,
|
|
@@ -11935,6 +11997,19 @@ var SolverService = class {
|
|
|
11935
11997
|
value: result
|
|
11936
11998
|
};
|
|
11937
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
|
+
}
|
|
11938
12013
|
return {
|
|
11939
12014
|
ok: false,
|
|
11940
12015
|
error: new Error("Approve only supported for EVM spoke chains")
|
|
@@ -11994,49 +12069,70 @@ var SolverService = class {
|
|
|
11994
12069
|
fee = this.config.partnerFee,
|
|
11995
12070
|
raw
|
|
11996
12071
|
}) {
|
|
11997
|
-
|
|
12072
|
+
invariant11(
|
|
11998
12073
|
isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
11999
12074
|
`Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
|
|
12000
12075
|
);
|
|
12001
|
-
|
|
12076
|
+
invariant11(
|
|
12002
12077
|
isValidOriginalAssetAddress(params.dstChain, params.outputToken),
|
|
12003
12078
|
`Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
|
|
12004
12079
|
);
|
|
12005
|
-
|
|
12006
|
-
|
|
12080
|
+
invariant11(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
|
|
12081
|
+
invariant11(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
|
|
12007
12082
|
try {
|
|
12008
12083
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12009
|
-
|
|
12084
|
+
invariant11(
|
|
12010
12085
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
12011
12086
|
"srcAddress must be the same as wallet address"
|
|
12012
12087
|
);
|
|
12013
12088
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12014
|
-
|
|
12015
|
-
|
|
12016
|
-
|
|
12017
|
-
|
|
12018
|
-
|
|
12019
|
-
|
|
12020
|
-
|
|
12021
|
-
|
|
12022
|
-
|
|
12023
|
-
|
|
12024
|
-
|
|
12025
|
-
|
|
12026
|
-
|
|
12027
|
-
|
|
12028
|
-
|
|
12029
|
-
|
|
12030
|
-
|
|
12031
|
-
}
|
|
12032
|
-
|
|
12033
|
-
|
|
12034
|
-
|
|
12035
|
-
|
|
12036
|
-
|
|
12037
|
-
|
|
12038
|
-
|
|
12039
|
-
|
|
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
|
+
}
|
|
12040
12136
|
} catch (error) {
|
|
12041
12137
|
return {
|
|
12042
12138
|
ok: false,
|
|
@@ -12059,8 +12155,8 @@ var SolverService = class {
|
|
|
12059
12155
|
*/
|
|
12060
12156
|
async cancelIntent(intent, spokeProvider, raw) {
|
|
12061
12157
|
try {
|
|
12062
|
-
|
|
12063
|
-
|
|
12158
|
+
invariant11(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12159
|
+
invariant11(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
12064
12160
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12065
12161
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12066
12162
|
const calls = [];
|
|
@@ -12572,7 +12668,7 @@ var IcxMigrationService = class {
|
|
|
12572
12668
|
migrateData(params) {
|
|
12573
12669
|
const calls = [];
|
|
12574
12670
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.address);
|
|
12575
|
-
|
|
12671
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
|
|
12576
12672
|
calls.push(
|
|
12577
12673
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
12578
12674
|
);
|
|
@@ -12588,7 +12684,7 @@ var IcxMigrationService = class {
|
|
|
12588
12684
|
revertMigration(params) {
|
|
12589
12685
|
const calls = [];
|
|
12590
12686
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
12591
|
-
|
|
12687
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
12592
12688
|
calls.push(
|
|
12593
12689
|
Erc20Service.encodeApprove(
|
|
12594
12690
|
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
@@ -12684,9 +12780,9 @@ var MigrationService = class {
|
|
|
12684
12780
|
async isAllowanceValid(params, action, spokeProvider) {
|
|
12685
12781
|
try {
|
|
12686
12782
|
if (action === "migrate") {
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
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(
|
|
12690
12786
|
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
12691
12787
|
"Invalid params"
|
|
12692
12788
|
);
|
|
@@ -12712,9 +12808,9 @@ var MigrationService = class {
|
|
|
12712
12808
|
};
|
|
12713
12809
|
}
|
|
12714
12810
|
if (action === "revert") {
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
|
|
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");
|
|
12718
12814
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12719
12815
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12720
12816
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -12770,9 +12866,9 @@ var MigrationService = class {
|
|
|
12770
12866
|
async approve(params, action, spokeProvider, raw) {
|
|
12771
12867
|
try {
|
|
12772
12868
|
if (action === "migrate") {
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
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");
|
|
12776
12872
|
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
12777
12873
|
const evmSpokeProvider = spokeProvider;
|
|
12778
12874
|
const result = await Erc20Service.approve(
|
|
@@ -12793,9 +12889,9 @@ var MigrationService = class {
|
|
|
12793
12889
|
};
|
|
12794
12890
|
}
|
|
12795
12891
|
if (action === "revert") {
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
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");
|
|
12799
12895
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12800
12896
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12801
12897
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -13207,13 +13303,13 @@ var MigrationService = class {
|
|
|
13207
13303
|
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
13208
13304
|
try {
|
|
13209
13305
|
if (!unchecked) {
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13216
|
-
|
|
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(
|
|
13217
13313
|
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
13218
13314
|
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
13219
13315
|
);
|
|
@@ -13221,11 +13317,11 @@ var MigrationService = class {
|
|
|
13221
13317
|
let migrationData;
|
|
13222
13318
|
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
13223
13319
|
if (!unchecked) {
|
|
13224
|
-
|
|
13320
|
+
invariant11(
|
|
13225
13321
|
isLegacybnUSDChainId(params.srcChainId),
|
|
13226
13322
|
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
13227
13323
|
);
|
|
13228
|
-
|
|
13324
|
+
invariant11(
|
|
13229
13325
|
isNewbnUSDChainId(params.dstChainId),
|
|
13230
13326
|
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
13231
13327
|
);
|
|
@@ -13240,15 +13336,15 @@ var MigrationService = class {
|
|
|
13240
13336
|
});
|
|
13241
13337
|
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
13242
13338
|
if (!unchecked) {
|
|
13243
|
-
|
|
13339
|
+
invariant11(
|
|
13244
13340
|
isLegacybnUSDChainId(params.dstChainId),
|
|
13245
13341
|
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
13246
13342
|
);
|
|
13247
|
-
|
|
13343
|
+
invariant11(
|
|
13248
13344
|
isNewbnUSDToken(params.srcbnUSD),
|
|
13249
13345
|
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
13250
13346
|
);
|
|
13251
|
-
|
|
13347
|
+
invariant11(
|
|
13252
13348
|
isNewbnUSDChainId(params.srcChainId),
|
|
13253
13349
|
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
13254
13350
|
);
|
|
@@ -13321,13 +13417,13 @@ var MigrationService = class {
|
|
|
13321
13417
|
*/
|
|
13322
13418
|
async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
|
|
13323
13419
|
try {
|
|
13324
|
-
|
|
13325
|
-
|
|
13326
|
-
|
|
13420
|
+
invariant11(params.amount > 0, "Amount must be greater than 0");
|
|
13421
|
+
invariant11(isAddress(params.to), "Recipient address is required");
|
|
13422
|
+
invariant11(
|
|
13327
13423
|
params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
13328
13424
|
"Token must be wICX or native ICX token"
|
|
13329
13425
|
);
|
|
13330
|
-
|
|
13426
|
+
invariant11(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
13331
13427
|
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
13332
13428
|
if (availableAmount < params.amount) {
|
|
13333
13429
|
throw new Error(
|
|
@@ -13439,7 +13535,7 @@ var BnUSDMigrationService = class {
|
|
|
13439
13535
|
migrateData(params) {
|
|
13440
13536
|
const calls = [];
|
|
13441
13537
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
13442
|
-
|
|
13538
|
+
invariant11(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
13443
13539
|
const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
13444
13540
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
13445
13541
|
calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
|
|
@@ -13451,7 +13547,7 @@ var BnUSDMigrationService = class {
|
|
|
13451
13547
|
return encodeContractCalls(calls);
|
|
13452
13548
|
}
|
|
13453
13549
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
13454
|
-
|
|
13550
|
+
invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13455
13551
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
13456
13552
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
13457
13553
|
dstAssetConfig.decimal,
|
|
@@ -13484,14 +13580,14 @@ var BnUSDMigrationService = class {
|
|
|
13484
13580
|
let decimals = 18;
|
|
13485
13581
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
13486
13582
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
13487
|
-
|
|
13583
|
+
invariant11(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13488
13584
|
decimals = assetConfig.decimal;
|
|
13489
13585
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
13490
13586
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
13491
13587
|
}
|
|
13492
13588
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
13493
13589
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
13494
|
-
|
|
13590
|
+
invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
13495
13591
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
13496
13592
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
13497
13593
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -13574,7 +13670,7 @@ var BalnSwapService = class {
|
|
|
13574
13670
|
*/
|
|
13575
13671
|
async swapData(balnToken, params) {
|
|
13576
13672
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, balnToken);
|
|
13577
|
-
|
|
13673
|
+
invariant11(assetConfig, `hub asset not found for baln token: ${balnToken}`);
|
|
13578
13674
|
const calls = [];
|
|
13579
13675
|
calls.push(
|
|
13580
13676
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
|
|
@@ -15338,9 +15434,9 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15338
15434
|
*/
|
|
15339
15435
|
async isAllowanceValid(params, spokeProvider) {
|
|
15340
15436
|
try {
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
15437
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15438
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15439
|
+
invariant11(
|
|
15344
15440
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15345
15441
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15346
15442
|
);
|
|
@@ -15435,19 +15531,19 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15435
15531
|
*/
|
|
15436
15532
|
async approve(params, spokeProvider, raw) {
|
|
15437
15533
|
try {
|
|
15438
|
-
|
|
15439
|
-
|
|
15440
|
-
|
|
15534
|
+
invariant11(params.amount > 0n, "Amount must be greater than 0");
|
|
15535
|
+
invariant11(params.token.length > 0, "Token is required");
|
|
15536
|
+
invariant11(
|
|
15441
15537
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15442
15538
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15443
15539
|
);
|
|
15444
15540
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15445
15541
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
15446
|
-
|
|
15542
|
+
invariant11(
|
|
15447
15543
|
params.action === "supply" || params.action === "repay",
|
|
15448
15544
|
"Invalid action (only supply and repay are supported on evm)"
|
|
15449
15545
|
);
|
|
15450
|
-
|
|
15546
|
+
invariant11(isAddress(params.token), "Invalid token address");
|
|
15451
15547
|
const result = await Erc20Service.approve(
|
|
15452
15548
|
params.token,
|
|
15453
15549
|
params.amount,
|
|
@@ -15461,11 +15557,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15461
15557
|
};
|
|
15462
15558
|
}
|
|
15463
15559
|
if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
15464
|
-
|
|
15560
|
+
invariant11(
|
|
15465
15561
|
params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
|
|
15466
15562
|
"Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
|
|
15467
15563
|
);
|
|
15468
|
-
|
|
15564
|
+
invariant11(isAddress(params.token), "Invalid token address");
|
|
15469
15565
|
if (params.action === "withdraw") {
|
|
15470
15566
|
const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
|
|
15471
15567
|
params.token,
|
|
@@ -15637,10 +15733,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15637
15733
|
*/
|
|
15638
15734
|
async createSupplyIntent(params, spokeProvider, raw) {
|
|
15639
15735
|
try {
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
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(
|
|
15644
15740
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15645
15741
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15646
15742
|
);
|
|
@@ -15792,10 +15888,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15792
15888
|
* }
|
|
15793
15889
|
*/
|
|
15794
15890
|
async createBorrowIntent(params, spokeProvider, raw) {
|
|
15795
|
-
|
|
15796
|
-
|
|
15797
|
-
|
|
15798
|
-
|
|
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(
|
|
15799
15895
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15800
15896
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15801
15897
|
);
|
|
@@ -15927,10 +16023,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15927
16023
|
* }
|
|
15928
16024
|
*/
|
|
15929
16025
|
async createWithdrawIntent(params, spokeProvider, raw) {
|
|
15930
|
-
|
|
15931
|
-
|
|
15932
|
-
|
|
15933
|
-
|
|
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(
|
|
15934
16030
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15935
16031
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15936
16032
|
);
|
|
@@ -16082,10 +16178,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16082
16178
|
* }
|
|
16083
16179
|
*/
|
|
16084
16180
|
async createRepayIntent(params, spokeProvider, raw) {
|
|
16085
|
-
|
|
16086
|
-
|
|
16087
|
-
|
|
16088
|
-
|
|
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(
|
|
16089
16185
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
16090
16186
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
16091
16187
|
);
|
|
@@ -16128,7 +16224,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16128
16224
|
buildSupplyData(token, to, amount, spokeChainId) {
|
|
16129
16225
|
const calls = [];
|
|
16130
16226
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16131
|
-
|
|
16227
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16132
16228
|
let assetAddress = assetConfig.asset;
|
|
16133
16229
|
const vaultAddress = assetConfig.vault;
|
|
16134
16230
|
const lendingPool = this.config.lendingPool;
|
|
@@ -16159,13 +16255,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16159
16255
|
* @returns {Hex} The transaction data.
|
|
16160
16256
|
*/
|
|
16161
16257
|
buildBorrowData(from, to, token, amount, spokeChainId) {
|
|
16162
|
-
|
|
16163
|
-
|
|
16258
|
+
invariant11(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
|
|
16259
|
+
invariant11(
|
|
16164
16260
|
isValidOriginalAssetAddress(spokeChainId, token),
|
|
16165
16261
|
`Unsupported spoke chain (${spokeChainId}) token: ${token}`
|
|
16166
16262
|
);
|
|
16167
16263
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16168
|
-
|
|
16264
|
+
invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16169
16265
|
let assetAddress = assetConfig.asset;
|
|
16170
16266
|
const vaultAddress = assetConfig.vault;
|
|
16171
16267
|
const bnUSDVault = this.config.bnUSDVault;
|