@skip-go/client 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{chunk-IDEJORRT.cjs → chunk-23YF4LFI.cjs} +30 -0
- package/dist/cjs/chunk-4YTACAVP.cjs +185 -0
- package/dist/cjs/{chunk-46VB6RQK.cjs → chunk-CUDPMOR6.cjs} +10 -3
- package/dist/cjs/chunk-GCJO6DZD.cjs +55 -0
- package/dist/cjs/{chunk-ZKBSNSHQ.cjs → chunk-HHZGD62Y.cjs} +120 -116
- package/dist/cjs/{chunk-ZAATXQBG.cjs → chunk-K4YAPDUE.cjs} +2 -2
- package/dist/cjs/{chunk-7MC3BVQN.cjs → chunk-UIQML2XG.cjs} +113 -28
- package/dist/cjs/chunk-VF65UG3E.cjs +214 -0
- package/dist/cjs/{chunk-Q43XCBMX.cjs → chunk-W3KF3V57.cjs} +4 -4
- package/dist/cjs/{chunk-6LA66667.cjs → chunk-X22PL5T7.cjs} +3 -3
- package/dist/cjs/index.cjs +26 -20
- package/dist/cjs/public-functions/executeMultipleRoutes.cjs +29 -0
- package/dist/cjs/public-functions/executeRoute.cjs +8 -7
- package/dist/cjs/public-functions/getFeeInfoForChain.cjs +3 -3
- package/dist/cjs/public-functions/getRecommendedGasPrice.cjs +4 -4
- package/dist/cjs/public-functions/getSigningStargateClient.cjs +3 -3
- package/dist/cjs/public-functions/setClientOptions.cjs +2 -2
- package/dist/cjs/public-functions/subscribeToRouteStatus.cjs +5 -5
- package/dist/cjs/public-functions/validateCosmosGasBalance.cjs +5 -5
- package/dist/esm/{callbacks-B3kjKg0v.d.ts → callbacks-CvqAtBJq.d.ts} +19 -64
- package/dist/esm/chunk-7RS3YIVC.js +53 -0
- package/dist/esm/chunk-AZALP3WR.js +212 -0
- package/dist/esm/{chunk-CIAOTO3M.js → chunk-CX5N7ZLJ.js} +1 -1
- package/dist/esm/chunk-IUYOY23L.js +180 -0
- package/dist/esm/{chunk-GHNH5QC3.js → chunk-JKN4E5VN.js} +9 -2
- package/dist/esm/{chunk-4RLJWCQR.js → chunk-KLGGCB73.js} +1 -1
- package/dist/esm/{chunk-KYDY7QRT.js → chunk-MPSXXWKL.js} +1 -1
- package/dist/esm/{chunk-BAJFQZDT.js → chunk-MTAS5XMN.js} +99 -96
- package/dist/esm/{chunk-RQ7DXNSS.js → chunk-VUXLWWLF.js} +113 -28
- package/dist/esm/{chunk-REWUSU53.js → chunk-WBZVMPPV.js} +30 -0
- package/dist/esm/client-types-Dk6ypWdO.d.ts +114 -0
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +12 -10
- package/dist/esm/public-functions/executeMultipleRoutes.d.ts +60 -0
- package/dist/esm/public-functions/executeMultipleRoutes.js +20 -0
- package/dist/esm/public-functions/executeRoute.d.ts +3 -3
- package/dist/esm/public-functions/executeRoute.js +7 -6
- package/dist/esm/public-functions/getEvmGasAmountForMessage.d.ts +4 -1
- package/dist/esm/public-functions/getFeeInfoForChain.js +2 -2
- package/dist/esm/public-functions/getRecommendedGasPrice.js +3 -3
- package/dist/esm/public-functions/getSigningStargateClient.js +2 -2
- package/dist/esm/public-functions/setClientOptions.d.ts +4 -2
- package/dist/esm/public-functions/setClientOptions.js +1 -1
- package/dist/esm/public-functions/subscribeToRouteStatus.d.ts +3 -3
- package/dist/esm/public-functions/subscribeToRouteStatus.js +1 -1
- package/dist/esm/public-functions/validateCosmosGasBalance.d.ts +5 -4
- package/dist/esm/public-functions/validateCosmosGasBalance.js +4 -4
- package/dist/esm/public-functions/waitForTransaction.d.ts +3 -3
- package/dist/esm/{setClientOptions-BTRwCbmt.d.ts → setClientOptions-BD8e7m2x.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/cjs/chunk-VIG2BHYJ.cjs +0 -185
- package/dist/esm/chunk-3J6O2PVK.js +0 -180
- package/dist/esm/client-types-B7Fin0mq.d.ts +0 -61
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getCosmosGasAmountForMessage } from './chunk-KNXMSLOB.js';
|
|
2
2
|
import { BigNumber } from './chunk-VQ5SIQWU.js';
|
|
3
|
-
import { getSigningStargateClient } from './chunk-
|
|
3
|
+
import { getSigningStargateClient } from './chunk-MPSXXWKL.js';
|
|
4
4
|
import { ClientState, balances } from './chunk-ZOUYAZU6.js';
|
|
5
5
|
import { GasPrice, calculateFee } from '@cosmjs/stargate';
|
|
6
6
|
import { Decimal } from '@cosmjs/math';
|
|
@@ -13,7 +13,8 @@ var validateCosmosGasBalance = async ({
|
|
|
13
13
|
getOfflineSigner,
|
|
14
14
|
txIndex,
|
|
15
15
|
simulate,
|
|
16
|
-
getCosmosPriorityFeeDenom
|
|
16
|
+
getCosmosPriorityFeeDenom,
|
|
17
|
+
isMultiRoutes
|
|
17
18
|
}) => {
|
|
18
19
|
const skipAssets = (await ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
19
20
|
const skipChains = await ClientState.getSkipChains();
|
|
@@ -81,6 +82,12 @@ var validateCosmosGasBalance = async ({
|
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
83
84
|
if (chainId === "noble-1") {
|
|
85
|
+
if (isMultiRoutes && txIndex === 0) {
|
|
86
|
+
return calculateFee(
|
|
87
|
+
Math.ceil(parseFloat(estimatedGasAmount)),
|
|
88
|
+
gasPrice
|
|
89
|
+
);
|
|
90
|
+
}
|
|
84
91
|
if (asset.denom.toLowerCase() === "ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0".toLowerCase()) {
|
|
85
92
|
const fee2 = calculateFee(2e6, gasPrice);
|
|
86
93
|
return fee2;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_GAS_DENOM_OVERRIDES } from './chunk-SWYON2RG.js';
|
|
2
|
-
import { chains } from './chunk-
|
|
2
|
+
import { chains } from './chunk-IUYOY23L.js';
|
|
3
3
|
import { ClientState } from './chunk-ZOUYAZU6.js';
|
|
4
4
|
|
|
5
5
|
// src/private-functions/getDefaultGasTokenForChain.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { chains, findFirstWorkingEndpoint } from './chunk-3J6O2PVK.js';
|
|
2
1
|
import { BaseAccount as BaseAccount$1, isSet, bytesFromBase64, base64FromBytes } from './chunk-QO2CYYF5.js';
|
|
2
|
+
import { chains, findFirstWorkingEndpoint } from './chunk-IUYOY23L.js';
|
|
3
3
|
import { ClientState } from './chunk-ZOUYAZU6.js';
|
|
4
4
|
import { accountFromAny, SigningStargateClient } from '@cosmjs/stargate';
|
|
5
5
|
import { assertDefinedAndNotNull } from '@cosmjs/utils';
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { updateRouteDetails
|
|
2
|
-
import { validateCosmosGasBalance } from './chunk-
|
|
1
|
+
import { updateRouteDetails } from './chunk-VUXLWWLF.js';
|
|
2
|
+
import { validateCosmosGasBalance } from './chunk-JKN4E5VN.js';
|
|
3
3
|
import { getEncodeObjectFromCosmosMessage } from './chunk-KNXMSLOB.js';
|
|
4
4
|
import { getEVMGasAmountForMessage } from './chunk-GV2QOWB4.js';
|
|
5
5
|
import { BigNumber } from './chunk-VQ5SIQWU.js';
|
|
6
6
|
import { GAS_STATION_CHAIN_IDS } from './chunk-SWYON2RG.js';
|
|
7
|
-
import { getRpcEndpointForChain, accountParser, getSigningStargateClient } from './chunk-
|
|
8
|
-
import { chains, findFirstWorkingEndpoint, getIsEthermint, getIsInitia } from './chunk-
|
|
9
|
-
import { messages } from './chunk-AND7HVIU.js';
|
|
7
|
+
import { getRpcEndpointForChain, accountParser, getSigningStargateClient } from './chunk-MPSXXWKL.js';
|
|
8
|
+
import { chains, findFirstWorkingEndpoint, getIsEthermint, getIsInitia } from './chunk-IUYOY23L.js';
|
|
10
9
|
import { submitTransaction } from './chunk-JQ4F4WBG.js';
|
|
11
10
|
import { venues } from './chunk-52PEBJRQ.js';
|
|
12
11
|
import { ClientState, balances } from './chunk-ZOUYAZU6.js';
|
|
13
|
-
import {
|
|
14
|
-
import { PublicKey, Transaction, Connection, LAMPORTS_PER_SOL } from '@solana/web3.js';
|
|
15
|
-
import { bech32m, bech32 } from 'bech32';
|
|
12
|
+
import { toCamel, wait } from './chunk-A6KSECAH.js';
|
|
16
13
|
import { StargateClient } from '@cosmjs/stargate';
|
|
17
14
|
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
18
15
|
import { isOfflineDirectSigner, makeAuthInfoBytes, makeSignDoc, encodePubkey } from '@cosmjs/proto-signing';
|
|
@@ -23,6 +20,8 @@ import { Any } from 'cosmjs-types/google/protobuf/any.js';
|
|
|
23
20
|
import { Int53 } from '@cosmjs/math';
|
|
24
21
|
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing.js';
|
|
25
22
|
import { isAddress, publicActions, maxUint256, formatUnits } from 'viem';
|
|
23
|
+
import { Transaction, PublicKey, Connection, LAMPORTS_PER_SOL } from '@solana/web3.js';
|
|
24
|
+
import { bech32m, bech32 } from 'bech32';
|
|
26
25
|
|
|
27
26
|
// src/private-functions/getRestEndpointForChain.ts
|
|
28
27
|
var getRestEndpointForChain = async (chainId) => {
|
|
@@ -172,11 +171,11 @@ var signCosmosMessageDirect = async (options) => {
|
|
|
172
171
|
if (!accountFromSigner) {
|
|
173
172
|
throw new Error("signCosmosMessageDirect error: failed to retrieve account from signer");
|
|
174
173
|
}
|
|
175
|
-
const
|
|
174
|
+
const messages = cosmosMsgs.map((cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg));
|
|
176
175
|
const txBodyEncodeObject = {
|
|
177
176
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
178
177
|
value: {
|
|
179
|
-
messages
|
|
178
|
+
messages
|
|
180
179
|
}
|
|
181
180
|
};
|
|
182
181
|
const txBodyBytes = ClientState.registry.encode(txBodyEncodeObject);
|
|
@@ -207,26 +206,40 @@ var signCosmosMessageAmino = async (options) => {
|
|
|
207
206
|
signerData: { accountNumber, sequence, chainId: signerChainId }
|
|
208
207
|
} = options;
|
|
209
208
|
const accounts = await signer.getAccounts();
|
|
210
|
-
const accountFromSigner = accounts.find(
|
|
209
|
+
const accountFromSigner = accounts.find(
|
|
210
|
+
(account) => account.address === signerAddress
|
|
211
|
+
);
|
|
211
212
|
if (!accountFromSigner) {
|
|
212
|
-
throw new Error(
|
|
213
|
+
throw new Error(
|
|
214
|
+
"signCosmosMessageAmino: failed to retrieve account from signer"
|
|
215
|
+
);
|
|
213
216
|
}
|
|
214
|
-
const
|
|
217
|
+
const messages = cosmosMsgs.map(
|
|
218
|
+
(cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg)
|
|
219
|
+
);
|
|
215
220
|
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
216
|
-
const msgs =
|
|
217
|
-
|
|
218
|
-
|
|
221
|
+
const msgs = messages.map((msg) => ClientState.aminoTypes.toAmino(msg));
|
|
222
|
+
const signDoc = makeSignDoc$1(
|
|
223
|
+
msgs,
|
|
224
|
+
fee,
|
|
225
|
+
signerChainId,
|
|
226
|
+
"",
|
|
227
|
+
accountNumber,
|
|
228
|
+
sequence
|
|
229
|
+
);
|
|
219
230
|
const { signature, signed } = await signer.signAmino(signerAddress, signDoc);
|
|
220
231
|
const signedTxBody = {
|
|
221
232
|
messages: signed.msgs.map((msg) => ClientState.aminoTypes.fromAmino(msg)),
|
|
222
233
|
memo: signed.memo
|
|
223
234
|
};
|
|
224
|
-
signedTxBody.messages[0].value.memo =
|
|
235
|
+
signedTxBody.messages[0].value.memo = messages[0].value.memo;
|
|
225
236
|
const signedTxBodyEncodeObject = {
|
|
226
237
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
227
238
|
value: signedTxBody
|
|
228
239
|
};
|
|
229
|
-
const signedTxBodyBytes = ClientState.registry.encode(
|
|
240
|
+
const signedTxBodyBytes = ClientState.registry.encode(
|
|
241
|
+
signedTxBodyEncodeObject
|
|
242
|
+
);
|
|
230
243
|
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
|
|
231
244
|
const signedSequence = Int53.fromString(signed.sequence).toNumber();
|
|
232
245
|
const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
|
|
@@ -257,7 +270,7 @@ var signCosmosTransaction = async ({
|
|
|
257
270
|
throw new Error("executeCosmosTransaction error: tx is undefined");
|
|
258
271
|
}
|
|
259
272
|
const chainId = tx.cosmosTx?.chainId;
|
|
260
|
-
const
|
|
273
|
+
const messages = tx.cosmosTx?.msgs;
|
|
261
274
|
const currentUserAddress = userAddresses.find((x) => x.chainId === tx.cosmosTx?.chainId)?.address;
|
|
262
275
|
const gasArray = ClientState.validateGasResults;
|
|
263
276
|
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
@@ -271,7 +284,7 @@ var signCosmosTransaction = async ({
|
|
|
271
284
|
if (chainId === void 0) {
|
|
272
285
|
throw new Error("no chainId found for tx");
|
|
273
286
|
}
|
|
274
|
-
if (
|
|
287
|
+
if (messages === void 0) {
|
|
275
288
|
throw new Error("no messages found for tx");
|
|
276
289
|
}
|
|
277
290
|
const { signer } = await getSigningStargateClient({
|
|
@@ -300,7 +313,7 @@ var signCosmosTransaction = async ({
|
|
|
300
313
|
const commonRawTxBody = {
|
|
301
314
|
signerAddress: currentUserAddress,
|
|
302
315
|
chainId,
|
|
303
|
-
cosmosMsgs:
|
|
316
|
+
cosmosMsgs: messages,
|
|
304
317
|
fee,
|
|
305
318
|
signerData: {
|
|
306
319
|
accountNumber,
|
|
@@ -876,7 +889,8 @@ var validateEvmGasBalance = async ({
|
|
|
876
889
|
signer,
|
|
877
890
|
tx,
|
|
878
891
|
getFallbackGasAmount,
|
|
879
|
-
useUnlimitedApproval
|
|
892
|
+
useUnlimitedApproval,
|
|
893
|
+
bypassApprovalCheck
|
|
880
894
|
}) => {
|
|
881
895
|
const chainId = tx?.chainId ?? "";
|
|
882
896
|
const skipAssets = (await ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
@@ -901,7 +915,7 @@ var validateEvmGasBalance = async ({
|
|
|
901
915
|
)?.[1];
|
|
902
916
|
const gasBalance = nativeGasBalance || zeroAddressGasBalance;
|
|
903
917
|
const { requiredErc20Approvals } = tx;
|
|
904
|
-
if (requiredErc20Approvals) {
|
|
918
|
+
if (!bypassApprovalCheck && requiredErc20Approvals) {
|
|
905
919
|
try {
|
|
906
920
|
await validateEvmTokenApproval({
|
|
907
921
|
requiredErc20Approvals,
|
|
@@ -1038,10 +1052,10 @@ var validateGasBalances = async ({
|
|
|
1038
1052
|
simulate,
|
|
1039
1053
|
disabledChainIds,
|
|
1040
1054
|
enabledChainIds,
|
|
1041
|
-
useUnlimitedApproval,
|
|
1042
1055
|
getCosmosPriorityFeeDenom,
|
|
1043
1056
|
routeId,
|
|
1044
|
-
options
|
|
1057
|
+
options,
|
|
1058
|
+
isMultiRoutes
|
|
1045
1059
|
}) => {
|
|
1046
1060
|
const validateResult = await Promise.all(
|
|
1047
1061
|
txs.map(async (tx, i) => {
|
|
@@ -1069,7 +1083,8 @@ var validateGasBalances = async ({
|
|
|
1069
1083
|
getOfflineSigner: getCosmosSigner,
|
|
1070
1084
|
txIndex: i,
|
|
1071
1085
|
simulate,
|
|
1072
|
-
getCosmosPriorityFeeDenom
|
|
1086
|
+
getCosmosPriorityFeeDenom,
|
|
1087
|
+
isMultiRoutes
|
|
1073
1088
|
});
|
|
1074
1089
|
return res;
|
|
1075
1090
|
} catch (e) {
|
|
@@ -1101,7 +1116,8 @@ var validateGasBalances = async ({
|
|
|
1101
1116
|
tx: tx.evmTx,
|
|
1102
1117
|
signer,
|
|
1103
1118
|
getFallbackGasAmount,
|
|
1104
|
-
useUnlimitedApproval
|
|
1119
|
+
useUnlimitedApproval: options?.useUnlimitedApproval,
|
|
1120
|
+
bypassApprovalCheck: options?.bypassApprovalCheck
|
|
1105
1121
|
});
|
|
1106
1122
|
return res;
|
|
1107
1123
|
} catch (e) {
|
|
@@ -1193,7 +1209,8 @@ var executeTransactions = async (options) => {
|
|
|
1193
1209
|
onValidateGasBalance,
|
|
1194
1210
|
trackTxPollingOptions,
|
|
1195
1211
|
batchSignTxs = true,
|
|
1196
|
-
routeId
|
|
1212
|
+
routeId,
|
|
1213
|
+
isMultiRoutes
|
|
1197
1214
|
} = options;
|
|
1198
1215
|
if (txs === void 0) {
|
|
1199
1216
|
throw new Error(
|
|
@@ -1203,11 +1220,11 @@ var executeTransactions = async (options) => {
|
|
|
1203
1220
|
const chainIds = getChainIdsFromTxs(txs);
|
|
1204
1221
|
const transactionDetails = txs.map((tx) => {
|
|
1205
1222
|
if ("cosmosTx" in tx) {
|
|
1206
|
-
return { chainId: tx.cosmosTx?.chainId };
|
|
1223
|
+
return { chainId: tx.cosmosTx?.chainId, chainType: "cosmos" /* Cosmos */ };
|
|
1207
1224
|
} else if ("evmTx" in tx) {
|
|
1208
|
-
return { chainId: tx.evmTx?.chainId };
|
|
1225
|
+
return { chainId: tx.evmTx?.chainId, chainType: "evm" /* Evm */ };
|
|
1209
1226
|
} else if ("svmTx" in tx) {
|
|
1210
|
-
return { chainId: tx.svmTx?.chainId };
|
|
1227
|
+
return { chainId: tx.svmTx?.chainId, chainType: "svm" /* Svm */ };
|
|
1211
1228
|
} else {
|
|
1212
1229
|
throw new Error("executeRoute error: invalid message type");
|
|
1213
1230
|
}
|
|
@@ -1232,7 +1249,8 @@ var executeTransactions = async (options) => {
|
|
|
1232
1249
|
disabledChainIds: validateChainIds,
|
|
1233
1250
|
getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
|
|
1234
1251
|
options,
|
|
1235
|
-
routeId
|
|
1252
|
+
routeId,
|
|
1253
|
+
isMultiRoutes
|
|
1236
1254
|
});
|
|
1237
1255
|
const validateEnabledChainIds = async (chainId) => {
|
|
1238
1256
|
await validateGasBalances({
|
|
@@ -1245,7 +1263,8 @@ var executeTransactions = async (options) => {
|
|
|
1245
1263
|
enabledChainIds: !batchSimulate ? [chainId] : validateChainIds,
|
|
1246
1264
|
getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
|
|
1247
1265
|
options,
|
|
1248
|
-
routeId
|
|
1266
|
+
routeId,
|
|
1267
|
+
isMultiRoutes
|
|
1249
1268
|
});
|
|
1250
1269
|
};
|
|
1251
1270
|
let signedTxs = [];
|
|
@@ -1259,11 +1278,16 @@ var executeTransactions = async (options) => {
|
|
|
1259
1278
|
await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
|
|
1260
1279
|
const isAllowedToBatchSignTxsUpfront = await (async () => {
|
|
1261
1280
|
try {
|
|
1262
|
-
const currentUserAddress = options.userAddresses.find(
|
|
1281
|
+
const currentUserAddress = options.userAddresses.find(
|
|
1282
|
+
(x) => x.chainId === tx.cosmosTx?.chainId
|
|
1283
|
+
)?.address;
|
|
1263
1284
|
if (!currentUserAddress) {
|
|
1264
1285
|
return false;
|
|
1265
1286
|
}
|
|
1266
|
-
const { accountNumber } = await getAccountNumberAndSequence(
|
|
1287
|
+
const { accountNumber } = await getAccountNumberAndSequence(
|
|
1288
|
+
currentUserAddress,
|
|
1289
|
+
tx.cosmosTx?.chainId
|
|
1290
|
+
);
|
|
1267
1291
|
if (accountNumber) {
|
|
1268
1292
|
return true;
|
|
1269
1293
|
}
|
|
@@ -1290,7 +1314,12 @@ var executeTransactions = async (options) => {
|
|
|
1290
1314
|
}
|
|
1291
1315
|
if ("svmTx" in tx) {
|
|
1292
1316
|
await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
|
|
1293
|
-
const signedTx = await signSvmTransaction({
|
|
1317
|
+
const signedTx = await signSvmTransaction({
|
|
1318
|
+
tx,
|
|
1319
|
+
options,
|
|
1320
|
+
index: i,
|
|
1321
|
+
routeId
|
|
1322
|
+
});
|
|
1294
1323
|
if (!signedTx) {
|
|
1295
1324
|
throw new Error(`executeRoute error: signedTx is undefined`);
|
|
1296
1325
|
}
|
|
@@ -1331,7 +1360,12 @@ var executeTransactions = async (options) => {
|
|
|
1331
1360
|
});
|
|
1332
1361
|
} else if ("evmTx" in tx) {
|
|
1333
1362
|
await validateEnabledChainIds(tx.evmTx?.chainId ?? "");
|
|
1334
|
-
const txResponse = await executeEvmTransaction(
|
|
1363
|
+
const txResponse = await executeEvmTransaction(
|
|
1364
|
+
tx,
|
|
1365
|
+
options,
|
|
1366
|
+
index,
|
|
1367
|
+
routeId
|
|
1368
|
+
);
|
|
1335
1369
|
txResult = {
|
|
1336
1370
|
chainId: tx?.evmTx?.chainId ?? "",
|
|
1337
1371
|
txHash: txResponse.transactionHash
|
|
@@ -1346,12 +1380,10 @@ var executeTransactions = async (options) => {
|
|
|
1346
1380
|
await onTransactionBroadcast?.({ ...txResult });
|
|
1347
1381
|
return txResult;
|
|
1348
1382
|
};
|
|
1349
|
-
|
|
1383
|
+
return {
|
|
1350
1384
|
transactionDetails,
|
|
1351
|
-
executeTransaction
|
|
1352
|
-
|
|
1353
|
-
options
|
|
1354
|
-
});
|
|
1385
|
+
executeTransaction
|
|
1386
|
+
};
|
|
1355
1387
|
};
|
|
1356
1388
|
var EVM_GAS_AMOUNT = 15e4;
|
|
1357
1389
|
var COSMOS_GAS_AMOUNT = {
|
|
@@ -1376,59 +1408,6 @@ var getDefaultFallbackGasAmount = async (chainId, chainType) => {
|
|
|
1376
1408
|
}
|
|
1377
1409
|
return defaultGasAmount;
|
|
1378
1410
|
};
|
|
1379
|
-
var executeRoute = async (options) => {
|
|
1380
|
-
const { route, userAddresses, beforeMsg, afterMsg, timeoutSeconds } = options;
|
|
1381
|
-
const { id: routeId } = updateRouteDetails({
|
|
1382
|
-
status: "unconfirmed",
|
|
1383
|
-
options
|
|
1384
|
-
});
|
|
1385
|
-
let addressList = [];
|
|
1386
|
-
userAddresses.forEach((userAddress, index) => {
|
|
1387
|
-
const requiredChainAddress = route.requiredChainAddresses[index];
|
|
1388
|
-
if (requiredChainAddress === userAddress?.chainId) {
|
|
1389
|
-
addressList.push(userAddress.address);
|
|
1390
|
-
}
|
|
1391
|
-
});
|
|
1392
|
-
if (addressList.length !== route.requiredChainAddresses.length) {
|
|
1393
|
-
addressList = userAddresses.map((x) => x.address);
|
|
1394
|
-
}
|
|
1395
|
-
const validLength = addressList.length === route.requiredChainAddresses.length || addressList.length === route.chainIds?.length;
|
|
1396
|
-
if (!validLength) {
|
|
1397
|
-
throw new Error("executeRoute error: invalid address list");
|
|
1398
|
-
}
|
|
1399
|
-
const isUserAddressesValid = await validateUserAddresses(userAddresses);
|
|
1400
|
-
if (!isUserAddressesValid) {
|
|
1401
|
-
throw new Error("executeRoute error: invalid user addresses");
|
|
1402
|
-
}
|
|
1403
|
-
const response = await messages({
|
|
1404
|
-
timeoutSeconds,
|
|
1405
|
-
amountIn: route?.amountIn,
|
|
1406
|
-
amountOut: route.estimatedAmountOut || "0",
|
|
1407
|
-
sourceAssetChainId: route?.sourceAssetChainId,
|
|
1408
|
-
sourceAssetDenom: route?.sourceAssetDenom,
|
|
1409
|
-
destAssetChainId: route?.destAssetChainId,
|
|
1410
|
-
destAssetDenom: route?.destAssetDenom,
|
|
1411
|
-
operations: route?.operations,
|
|
1412
|
-
addressList,
|
|
1413
|
-
slippageTolerancePercent: options.slippageTolerancePercent || "1",
|
|
1414
|
-
chainIdsToAffiliates: ApiState.chainIdsToAffiliates,
|
|
1415
|
-
postRouteHandler: options.postRouteHandler,
|
|
1416
|
-
feePayerAddress: options.svmFeePayer?.address
|
|
1417
|
-
});
|
|
1418
|
-
if (beforeMsg && (response?.txs?.length ?? 0) > 0) {
|
|
1419
|
-
const firstTx = response?.txs?.[0];
|
|
1420
|
-
if (firstTx && "cosmosTx" in firstTx) {
|
|
1421
|
-
firstTx.cosmosTx?.msgs?.unshift(beforeMsg);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
if (afterMsg && (response?.txs?.length ?? 0) > 0) {
|
|
1425
|
-
const lastTx = response?.txs?.[response.txs.length - 1];
|
|
1426
|
-
if (lastTx && "cosmosTx" in lastTx) {
|
|
1427
|
-
lastTx.cosmosTx?.msgs?.push(afterMsg);
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
await executeTransactions({ ...options, routeId, txs: response?.txs });
|
|
1431
|
-
};
|
|
1432
1411
|
var validateUserAddresses = async (userAddresses) => {
|
|
1433
1412
|
const chains2 = await ClientState.getSkipChains();
|
|
1434
1413
|
const validations = userAddresses.map((userAddress) => {
|
|
@@ -1468,5 +1447,29 @@ var validateUserAddresses = async (userAddresses) => {
|
|
|
1468
1447
|
});
|
|
1469
1448
|
return validations.every((validation) => validation);
|
|
1470
1449
|
};
|
|
1450
|
+
var createValidAddressList = async ({
|
|
1451
|
+
userAddresses,
|
|
1452
|
+
route
|
|
1453
|
+
}) => {
|
|
1454
|
+
let addressList = [];
|
|
1455
|
+
userAddresses.forEach((userAddress, index) => {
|
|
1456
|
+
const requiredChainAddress = route.requiredChainAddresses[index];
|
|
1457
|
+
if (requiredChainAddress === userAddress?.chainId) {
|
|
1458
|
+
addressList.push(userAddress.address);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
if (addressList.length !== route.requiredChainAddresses.length) {
|
|
1462
|
+
addressList = userAddresses.map((x) => x.address);
|
|
1463
|
+
}
|
|
1464
|
+
const validLength = addressList.length === route.requiredChainAddresses.length || addressList.length === route.chainIds?.length;
|
|
1465
|
+
if (!validLength) {
|
|
1466
|
+
throw new Error("createValidAddressList error: invalid address list");
|
|
1467
|
+
}
|
|
1468
|
+
const isUserAddressesValid = await validateUserAddresses(userAddresses);
|
|
1469
|
+
if (!isUserAddressesValid) {
|
|
1470
|
+
throw new Error("createValidAddressList error: invalid user addresses");
|
|
1471
|
+
}
|
|
1472
|
+
return addressList;
|
|
1473
|
+
};
|
|
1471
1474
|
|
|
1472
|
-
export {
|
|
1475
|
+
export { createValidAddressList, executeTransactions };
|
|
@@ -140,12 +140,12 @@ var isFinalRouteStatus = (routeDetails) => {
|
|
|
140
140
|
return false;
|
|
141
141
|
};
|
|
142
142
|
var isFinalState = (transaction) => {
|
|
143
|
-
const transactionState = transaction?.statusResponse?.state;
|
|
143
|
+
const transactionState = transaction?.statusResponse?.transfers?.[0]?.state;
|
|
144
144
|
const transactionStatus2 = transaction?.status;
|
|
145
145
|
return transactionState === "STATE_COMPLETED_SUCCESS" || transactionState === "STATE_COMPLETED_ERROR" || transactionState === "STATE_ABANDONED" || transactionStatus2 === "failed" || transactionStatus2 === "success";
|
|
146
146
|
};
|
|
147
147
|
var isSuccessState = (transaction) => {
|
|
148
|
-
const transactionState = transaction?.statusResponse?.state;
|
|
148
|
+
const transactionState = transaction?.statusResponse?.transfers?.[0]?.state;
|
|
149
149
|
const transactionStatus2 = transaction?.status;
|
|
150
150
|
return transactionState === "STATE_COMPLETED_SUCCESS" || transactionStatus2 === "success";
|
|
151
151
|
};
|
|
@@ -161,22 +161,36 @@ var initializeNewRouteDetails = (options) => {
|
|
|
161
161
|
txsSigned: 0,
|
|
162
162
|
transactionDetails: [],
|
|
163
163
|
transferEvents: [],
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
relatedRoutes: [],
|
|
165
|
+
userAddresses: options?.userAddresses ?? []
|
|
166
166
|
};
|
|
167
167
|
routeDetailsMap.set(newRouteId, newRouteDetails);
|
|
168
168
|
return newRouteDetails;
|
|
169
169
|
};
|
|
170
170
|
var subscribeToRouteStatus = (props) => {
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
171
|
+
const { routeDetails, onRouteStatusUpdated } = props;
|
|
172
|
+
const routeList = Array.isArray(routeDetails) ? routeDetails : [routeDetails];
|
|
173
|
+
const cancelFlags = /* @__PURE__ */ new Map();
|
|
174
|
+
const unsubscribers = [];
|
|
175
|
+
for (const route of routeList) {
|
|
176
|
+
const cancelFlag = { cancelled: false };
|
|
177
|
+
cancelFlags.set(route?.id ?? v4(), cancelFlag);
|
|
178
|
+
const unsubscribe = () => {
|
|
179
|
+
cancelFlag.cancelled = true;
|
|
180
|
+
};
|
|
181
|
+
unsubscribers.push(unsubscribe);
|
|
182
|
+
void executeAndSubscribeToRouteStatus({
|
|
183
|
+
routeDetails: route,
|
|
184
|
+
onRouteStatusUpdated,
|
|
185
|
+
isCancelled: () => cancelFlag.cancelled
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const unsubscribeAll = () => {
|
|
189
|
+
for (const unsubscribe of unsubscribers) {
|
|
190
|
+
unsubscribe();
|
|
191
|
+
}
|
|
174
192
|
};
|
|
175
|
-
|
|
176
|
-
...props,
|
|
177
|
-
isCancelled: () => cancelled
|
|
178
|
-
});
|
|
179
|
-
return unsubscribe;
|
|
193
|
+
return unsubscribeAll;
|
|
180
194
|
};
|
|
181
195
|
var executeAndSubscribeToRouteStatus = async ({
|
|
182
196
|
transactionDetails,
|
|
@@ -194,7 +208,9 @@ var executeAndSubscribeToRouteStatus = async ({
|
|
|
194
208
|
routeId ??= routeDetails?.id;
|
|
195
209
|
const currentRouteDetails = routeDetailsMap.get(routeId ?? "");
|
|
196
210
|
transactionDetails ??= routeDetails?.transactionDetails ?? currentRouteDetails?.transactionDetails ?? [];
|
|
197
|
-
if (routeDetails && isFinalRouteStatus(routeDetails)
|
|
211
|
+
if (routeDetails && isFinalRouteStatus(routeDetails) && routeDetails?.relatedRoutes?.every(
|
|
212
|
+
(relatedRoute) => isFinalRouteStatus(relatedRoute)
|
|
213
|
+
)) {
|
|
198
214
|
return;
|
|
199
215
|
}
|
|
200
216
|
for (const [transactionIndex, transaction] of transactionDetails.entries()) {
|
|
@@ -210,7 +226,11 @@ var executeAndSubscribeToRouteStatus = async ({
|
|
|
210
226
|
explorerLink = trackResponse.explorerLink;
|
|
211
227
|
}
|
|
212
228
|
transaction.explorerLink = explorerLink;
|
|
213
|
-
await onTransactionTracked?.({
|
|
229
|
+
await onTransactionTracked?.({
|
|
230
|
+
txHash: transaction.txHash,
|
|
231
|
+
chainId: transaction.chainId,
|
|
232
|
+
explorerLink
|
|
233
|
+
});
|
|
214
234
|
}
|
|
215
235
|
if (transaction.txHash === void 0) {
|
|
216
236
|
updateRouteDetails({
|
|
@@ -224,10 +244,17 @@ var executeAndSubscribeToRouteStatus = async ({
|
|
|
224
244
|
});
|
|
225
245
|
return;
|
|
226
246
|
}
|
|
227
|
-
while (
|
|
247
|
+
while (true) {
|
|
248
|
+
const updatedRouteDetails = routeDetailsMap.get(routeId ?? "");
|
|
249
|
+
const allRelatedRoutesFinal = updatedRouteDetails?.relatedRoutes?.every(
|
|
250
|
+
(relatedRoute) => relatedRoute && isFinalRouteStatus(relatedRoute)
|
|
251
|
+
);
|
|
252
|
+
if (isFinalState(transaction) && allRelatedRoutesFinal) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
228
255
|
if (isCancelled?.()) {
|
|
229
256
|
console.info(`Polling cancelled for route ${routeId}`);
|
|
230
|
-
|
|
257
|
+
break;
|
|
231
258
|
}
|
|
232
259
|
try {
|
|
233
260
|
const statusResponse = await transactionStatus({
|
|
@@ -242,7 +269,8 @@ var executeAndSubscribeToRouteStatus = async ({
|
|
|
242
269
|
options: {
|
|
243
270
|
onRouteStatusUpdated,
|
|
244
271
|
...options
|
|
245
|
-
}
|
|
272
|
+
},
|
|
273
|
+
relatedRoutes: routeDetails?.relatedRoutes
|
|
246
274
|
});
|
|
247
275
|
if (isFinalState(transaction)) {
|
|
248
276
|
onTransactionCompleted?.({
|
|
@@ -250,7 +278,11 @@ var executeAndSubscribeToRouteStatus = async ({
|
|
|
250
278
|
txHash: transaction.txHash,
|
|
251
279
|
status: statusResponse
|
|
252
280
|
});
|
|
253
|
-
|
|
281
|
+
if (routeDetails?.relatedRoutes?.every(
|
|
282
|
+
(relatedRoute) => isFinalRouteStatus(relatedRoute)
|
|
283
|
+
)) {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
254
286
|
}
|
|
255
287
|
} catch (error) {
|
|
256
288
|
console.error(error);
|
|
@@ -265,7 +297,10 @@ var updateRouteDetails = ({
|
|
|
265
297
|
routeDetails,
|
|
266
298
|
options,
|
|
267
299
|
status,
|
|
268
|
-
routeId
|
|
300
|
+
routeId,
|
|
301
|
+
mainRouteId,
|
|
302
|
+
transferIndexToRouteKey,
|
|
303
|
+
relatedRoutes
|
|
269
304
|
}) => {
|
|
270
305
|
routeId ??= routeDetails?.id ?? "";
|
|
271
306
|
let currentRouteDetails = routeDetails ?? routeDetailsMap.get(routeId);
|
|
@@ -273,6 +308,7 @@ var updateRouteDetails = ({
|
|
|
273
308
|
currentRouteDetails = initializeNewRouteDetails(options);
|
|
274
309
|
routeId = currentRouteDetails?.id;
|
|
275
310
|
}
|
|
311
|
+
transferIndexToRouteKey ??= currentRouteDetails?.transferIndexToRouteKey;
|
|
276
312
|
if (currentRouteDetails === void 0) {
|
|
277
313
|
throw new Error("No route details found");
|
|
278
314
|
}
|
|
@@ -281,7 +317,9 @@ var updateRouteDetails = ({
|
|
|
281
317
|
if (currentRouteDetails?.status === "signing" && status === "pending") {
|
|
282
318
|
currentRouteDetails.txsSigned += 1;
|
|
283
319
|
}
|
|
284
|
-
const transferEvents = routeDetails?.transferEvents ?? getTransferEventsFromTxStatusResponse(
|
|
320
|
+
const transferEvents = routeDetails?.transferEvents ?? getTransferEventsFromTxStatusResponse(
|
|
321
|
+
transactionDetails.map((tx) => tx.statusResponse).filter((status2) => status2 !== void 0)
|
|
322
|
+
);
|
|
285
323
|
const allExpectedTxsStarted = transactionDetails.every(
|
|
286
324
|
(tx) => tx.txHash || tx.status === void 0
|
|
287
325
|
);
|
|
@@ -305,9 +343,14 @@ var updateRouteDetails = ({
|
|
|
305
343
|
}
|
|
306
344
|
return currentRouteDetails?.status;
|
|
307
345
|
};
|
|
308
|
-
const transferAssetRelease = transactionDetails?.findLast(
|
|
309
|
-
|
|
310
|
-
|
|
346
|
+
const transferAssetRelease = transactionDetails?.findLast(
|
|
347
|
+
(i) => i.statusResponse?.transferAssetRelease
|
|
348
|
+
)?.statusResponse?.transferAssetRelease;
|
|
349
|
+
const updatedRelatedRoutes = updateRelatedRoutes({
|
|
350
|
+
relatedRoutes: relatedRoutes ?? currentRouteDetails?.relatedRoutes ?? [],
|
|
351
|
+
transferIndexToRouteKey,
|
|
352
|
+
transactionDetails
|
|
353
|
+
});
|
|
311
354
|
const newRouteDetails = {
|
|
312
355
|
id: routeId,
|
|
313
356
|
timestamp: currentRouteDetails.timestamp,
|
|
@@ -317,9 +360,11 @@ var updateRouteDetails = ({
|
|
|
317
360
|
transactionDetails,
|
|
318
361
|
transferEvents,
|
|
319
362
|
transferAssetRelease,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
363
|
+
userAddresses: (currentRouteDetails?.userAddresses.length > 0 ? currentRouteDetails?.userAddresses : options?.userAddresses) ?? [],
|
|
364
|
+
txsSigned: currentRouteDetails?.txsSigned,
|
|
365
|
+
transferIndexToRouteKey,
|
|
366
|
+
mainRouteId: mainRouteId ?? currentRouteDetails?.mainRouteId,
|
|
367
|
+
relatedRoutes: updatedRelatedRoutes
|
|
323
368
|
};
|
|
324
369
|
const newRouteStatus = getRouteDetailsWithSimpleTransactionDetailsStatus(newRouteDetails);
|
|
325
370
|
const previousRouteStatus = getRouteDetailsWithSimpleTransactionDetailsStatus(currentRouteDetails);
|
|
@@ -333,6 +378,8 @@ var updateRouteDetails = ({
|
|
|
333
378
|
};
|
|
334
379
|
var getSimpleRoute = (route) => {
|
|
335
380
|
return {
|
|
381
|
+
usdAmountOut: route?.usdAmountOut,
|
|
382
|
+
usdAmountIn: route?.usdAmountIn,
|
|
336
383
|
amountIn: route?.amountIn,
|
|
337
384
|
amountOut: route?.amountOut,
|
|
338
385
|
sourceAssetDenom: route?.sourceAssetDenom,
|
|
@@ -347,10 +394,11 @@ var getRouteDetailsWithSimpleTransactionDetailsStatus = (routeDetails) => {
|
|
|
347
394
|
...routeDetails,
|
|
348
395
|
transactionDetails: routeDetails.transactionDetails.map((txDetails) => {
|
|
349
396
|
const { statusResponse, ...rest } = txDetails;
|
|
350
|
-
|
|
397
|
+
const newTxDetails = {
|
|
351
398
|
...rest,
|
|
352
|
-
status: txDetails?.status ?? getTransactionStatus(
|
|
399
|
+
status: txDetails?.status ?? getTransactionStatus(statusResponse?.transfers?.[0]?.state)
|
|
353
400
|
};
|
|
401
|
+
return newTxDetails;
|
|
354
402
|
})
|
|
355
403
|
};
|
|
356
404
|
};
|
|
@@ -361,5 +409,42 @@ var removeRoutesWithFinalStatus = () => {
|
|
|
361
409
|
}
|
|
362
410
|
});
|
|
363
411
|
};
|
|
412
|
+
var convertTransactionStatusToRouteStatus = (transactionStatus2) => {
|
|
413
|
+
if (!transactionStatus2) return;
|
|
414
|
+
if (transactionStatus2 === "success") {
|
|
415
|
+
return "completed";
|
|
416
|
+
}
|
|
417
|
+
return transactionStatus2;
|
|
418
|
+
};
|
|
419
|
+
var updateRelatedRoutes = ({
|
|
420
|
+
relatedRoutes,
|
|
421
|
+
transferIndexToRouteKey,
|
|
422
|
+
transactionDetails
|
|
423
|
+
}) => {
|
|
424
|
+
let updatedRelatedRoutes = [
|
|
425
|
+
...relatedRoutes.map((relatedRoute) => ({ ...relatedRoute }))
|
|
426
|
+
];
|
|
427
|
+
if (!transferIndexToRouteKey) return updatedRelatedRoutes;
|
|
428
|
+
transactionDetails?.forEach((transaction) => {
|
|
429
|
+
Object.entries(transferIndexToRouteKey).forEach(([indexStr, routeKey]) => {
|
|
430
|
+
const index = Number(indexStr);
|
|
431
|
+
const state = transaction?.statusResponse?.transfers?.[index]?.state;
|
|
432
|
+
const status = convertTransactionStatusToRouteStatus(
|
|
433
|
+
getTransactionStatus(state)
|
|
434
|
+
);
|
|
435
|
+
const transferAssetRelease = transaction?.statusResponse?.transfers?.[index]?.transferAssetRelease;
|
|
436
|
+
const targetRoute = updatedRelatedRoutes.find(
|
|
437
|
+
(r) => r.routeKey === routeKey
|
|
438
|
+
);
|
|
439
|
+
if (targetRoute && state) {
|
|
440
|
+
targetRoute.status = status ?? "failed";
|
|
441
|
+
}
|
|
442
|
+
if (targetRoute && transferAssetRelease) {
|
|
443
|
+
targetRoute.transferAssetRelease = transferAssetRelease;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
return updatedRelatedRoutes;
|
|
448
|
+
};
|
|
364
449
|
|
|
365
450
|
export { executeAndSubscribeToRouteStatus, getTransactionStatus, subscribeToRouteStatus, updateRouteDetails };
|