@skip-go/client 1.5.3-alpha.0 → 1.5.3
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/api/getAssets.cjs +1 -1
- package/dist/cjs/api/getAssetsBetweenChains.cjs +1 -1
- package/dist/cjs/api/getBridges.cjs +1 -1
- package/dist/cjs/api/getChains.cjs +1 -1
- package/dist/cjs/api/getVenues.cjs +1 -1
- package/dist/cjs/api/postAssetsFromSource.cjs +1 -1
- package/dist/cjs/api/postBalances.cjs +1 -1
- package/dist/cjs/api/postIbcOriginAssets.cjs +1 -1
- package/dist/cjs/api/postMessages.cjs +1 -1
- package/dist/cjs/api/postMessagesDirect.cjs +1 -1
- package/dist/cjs/api/postRecommendAssets.cjs +1 -1
- package/dist/cjs/api/postRoute.cjs +1 -1
- package/dist/cjs/api/postSubmitTransaction.cjs +1 -1
- package/dist/cjs/api/postTrackTransaction.cjs +1 -1
- package/dist/cjs/api/postTransactionStatus.cjs +1 -1
- package/dist/cjs/{chunk-I6VYDEUV.cjs → chunk-3UPZIINE.cjs} +137 -137
- package/dist/cjs/{chunk-H2T4LMS2.cjs → chunk-4RLEZ5DV.cjs} +3 -3
- package/dist/cjs/{chunk-KM2D7PJL.cjs → chunk-4TBONPD6.cjs} +33 -33
- package/dist/cjs/{chunk-WKYP2NMS.cjs → chunk-6W2OIU3O.cjs} +15 -15
- package/dist/cjs/{chunk-ARCCHERF.cjs → chunk-BFA7XKVT.cjs} +19 -19
- package/dist/cjs/{chunk-BQDOKZFX.cjs → chunk-BT6HQNBF.cjs} +3 -3
- package/dist/cjs/{chunk-CZKIE576.cjs → chunk-DAPPFYGA.cjs} +8 -8
- package/dist/cjs/{chunk-MOWOIPUG.cjs → chunk-GOQK63JP.cjs} +4 -4
- package/dist/cjs/{chunk-3M7YYWGL.cjs → chunk-MUJBB64F.cjs} +3 -7
- package/dist/cjs/{chunk-UY5LWG5D.cjs → chunk-ND7SYSAP.cjs} +4 -4
- package/dist/cjs/{chunk-DWOE6N5S.cjs → chunk-NM4PISTQ.cjs} +189 -188
- package/dist/cjs/{chunk-J7HZ6VJE.cjs → chunk-QWQVTCKP.cjs} +15 -15
- package/dist/cjs/{chunk-XCFPRLX3.cjs → chunk-U2NZCNKX.cjs} +153 -153
- package/dist/cjs/chunk-UMBMSRZZ.cjs +185 -0
- package/dist/cjs/{chunk-DLT6Q6RB.cjs → chunk-WOSAJSJB.cjs} +163 -149
- package/dist/cjs/index.cjs +84 -80
- package/dist/cjs/public-functions/executeMultipleRoutes.cjs +12 -22
- package/dist/cjs/public-functions/executeRoute.cjs +12 -22
- package/dist/cjs/public-functions/getCosmosGasAmountForMessage.cjs +5 -5
- package/dist/cjs/public-functions/getEvmGasAmountForMessage.cjs +1 -1
- package/dist/cjs/public-functions/getFeeInfoForChain.cjs +5 -4
- package/dist/cjs/public-functions/getRecommendedGasPrice.cjs +7 -6
- package/dist/cjs/public-functions/getRouteWithGasOnReceive.cjs +18 -14
- package/dist/cjs/public-functions/getSigningStargateClient.cjs +5 -5
- package/dist/cjs/public-functions/setApiOptions.cjs +1 -1
- package/dist/cjs/public-functions/setClientOptions.cjs +5 -5
- package/dist/cjs/public-functions/subscribeToRouteStatus.cjs +1 -1
- package/dist/cjs/public-functions/validateCosmosGasBalance.cjs +9 -9
- package/dist/cjs/public-functions/waitForTransaction.cjs +1 -1
- package/dist/esm/api/getAssets.d.ts +1 -1
- package/dist/esm/api/getAssets.js +1 -1
- package/dist/esm/api/getAssetsBetweenChains.d.ts +1 -1
- package/dist/esm/api/getAssetsBetweenChains.js +1 -1
- package/dist/esm/api/getBridges.d.ts +1 -1
- package/dist/esm/api/getBridges.js +1 -1
- package/dist/esm/api/getChains.d.ts +1 -1
- package/dist/esm/api/getChains.js +1 -1
- package/dist/esm/api/getVenues.js +1 -1
- package/dist/esm/api/postAssetsFromSource.d.ts +1 -1
- package/dist/esm/api/postAssetsFromSource.js +1 -1
- package/dist/esm/api/postBalances.d.ts +2 -2
- package/dist/esm/api/postBalances.js +1 -1
- package/dist/esm/api/postIbcOriginAssets.js +1 -1
- package/dist/esm/api/postMessages.d.ts +2 -2
- package/dist/esm/api/postMessages.js +1 -1
- package/dist/esm/api/postMessagesDirect.d.ts +1 -1
- package/dist/esm/api/postMessagesDirect.js +1 -1
- package/dist/esm/api/postRecommendAssets.d.ts +1 -1
- package/dist/esm/api/postRecommendAssets.js +1 -1
- package/dist/esm/api/postRoute.d.ts +2 -2
- package/dist/esm/api/postRoute.js +1 -1
- package/dist/esm/api/postSubmitTransaction.d.ts +2 -2
- package/dist/esm/api/postSubmitTransaction.js +1 -1
- package/dist/esm/api/postTrackTransaction.d.ts +2 -2
- package/dist/esm/api/postTrackTransaction.js +1 -1
- package/dist/esm/api/postTransactionStatus.d.ts +2 -2
- package/dist/esm/api/postTransactionStatus.js +1 -1
- package/dist/esm/{callbacks-C-KUJnDv.d.ts → callbacks-CJ_p70xa.d.ts} +3 -3
- package/dist/esm/{chunk-FDRLM2JD.js → chunk-426BGQ4K.js} +131 -131
- package/dist/esm/{chunk-DL374PFE.js → chunk-BBEFB277.js} +1 -1
- package/dist/esm/{chunk-UIDIKXMB.js → chunk-F2LQB2DP.js} +6 -5
- package/dist/esm/{chunk-KNXMSLOB.js → chunk-GLH7IRLX.js} +2 -2
- package/dist/esm/{chunk-SOVU5NCL.js → chunk-GLM7QWYT.js} +2 -2
- package/dist/esm/{chunk-47HN6VKU.js → chunk-H2TTIB5K.js} +3 -3
- package/dist/esm/{chunk-QL423UEF.js → chunk-HP5EMWC6.js} +163 -149
- package/dist/esm/{chunk-JNVGNIOE.js → chunk-HZVXNDMH.js} +2 -2
- package/dist/esm/{chunk-JYYCFKB4.js → chunk-KS764SOZ.js} +15 -15
- package/dist/esm/{chunk-IGK7LJCM.js → chunk-L233BZ4I.js} +5 -5
- package/dist/esm/{chunk-6M7N6EAO.js → chunk-LBS7KX5I.js} +12 -12
- package/dist/esm/chunk-O4J7DHZA.js +180 -0
- package/dist/esm/{chunk-H3MY23AH.js → chunk-QYIZGNWZ.js} +1 -1
- package/dist/esm/{chunk-QO2CYYF5.js → chunk-RTDD7HZ3.js} +4 -7
- package/dist/esm/{chunk-RHLE3EW7.js → chunk-SA4GETWP.js} +1 -1
- package/dist/esm/{client-types-CGMuZ3zo.d.ts → client-types-uXKJQRqe.d.ts} +1 -1
- package/dist/esm/{generateApi-D_-Gso-x.d.ts → generateApi-BMFrG4FZ.d.ts} +1 -1
- package/dist/esm/index.d.ts +260 -259
- package/dist/esm/index.js +17 -13
- package/dist/esm/public-functions/executeMultipleRoutes.d.ts +4 -4
- package/dist/esm/public-functions/executeMultipleRoutes.js +11 -21
- package/dist/esm/public-functions/executeRoute.d.ts +4 -4
- package/dist/esm/public-functions/executeRoute.js +11 -21
- package/dist/esm/public-functions/getCosmosGasAmountForMessage.d.ts +1 -1
- package/dist/esm/public-functions/getCosmosGasAmountForMessage.js +3 -3
- package/dist/esm/public-functions/getEvmGasAmountForMessage.d.ts +3 -3
- package/dist/esm/public-functions/getEvmGasAmountForMessage.js +1 -1
- package/dist/esm/public-functions/getFeeInfoForChain.d.ts +1 -1
- package/dist/esm/public-functions/getFeeInfoForChain.js +4 -3
- package/dist/esm/public-functions/getRecommendedGasPrice.js +6 -5
- package/dist/esm/public-functions/getRouteWithGasOnReceive.d.ts +1 -1
- package/dist/esm/public-functions/getRouteWithGasOnReceive.js +17 -13
- package/dist/esm/public-functions/getSigningStargateClient.js +4 -4
- package/dist/esm/public-functions/setApiOptions.d.ts +1 -1
- package/dist/esm/public-functions/setApiOptions.js +1 -1
- package/dist/esm/public-functions/setClientOptions.d.ts +4 -4
- package/dist/esm/public-functions/setClientOptions.js +4 -4
- package/dist/esm/public-functions/subscribeToRouteStatus.d.ts +4 -4
- package/dist/esm/public-functions/subscribeToRouteStatus.js +1 -1
- package/dist/esm/public-functions/validateCosmosGasBalance.d.ts +4 -4
- package/dist/esm/public-functions/validateCosmosGasBalance.js +8 -8
- package/dist/esm/public-functions/waitForTransaction.d.ts +4 -4
- package/dist/esm/public-functions/waitForTransaction.js +1 -1
- package/dist/esm/{setClientOptions-C8g92xTm.d.ts → setClientOptions-D1qgaOqC.d.ts} +3 -3
- package/dist/esm/{swaggerTypes-B_jKfpvz.d.ts → swaggerTypes-Cop47I0X.d.ts} +257 -255
- package/package.json +5 -5
- package/dist/cjs/chunk-EVEVOW2U.cjs +0 -2179
- package/dist/cjs/chunk-GGSF5JZH.cjs +0 -101
- package/dist/cjs/chunk-GWRZ6MPC.cjs +0 -2179
- package/dist/cjs/chunk-KSJ5QYMR.cjs +0 -185
- package/dist/cjs/chunk-W6ID22B6.cjs +0 -24
- package/dist/esm/chunk-RHGDUD76.js +0 -180
- package/dist/esm/chunk-RJ35JBT4.js +0 -2154
- package/dist/esm/chunk-X2IBEHMZ.js +0 -2154
- package/dist/esm/chunk-XHLXJGVB.js +0 -22
- package/dist/esm/chunk-YWG4XR5A.js +0 -98
|
@@ -1,2154 +0,0 @@
|
|
|
1
|
-
import { updateRouteDetails, executeAndSubscribeToRouteStatus } from './chunk-5IXH2QPF.js';
|
|
2
|
-
import { validateCosmosGasBalance } from './chunk-47HN6VKU.js';
|
|
3
|
-
import { getEncodeObjectFromCosmosMessage } from './chunk-KNXMSLOB.js';
|
|
4
|
-
import { getEVMGasAmountForMessage } from './chunk-GV2QOWB4.js';
|
|
5
|
-
import { bignumber_default, BigNumber } from './chunk-JYYCFKB4.js';
|
|
6
|
-
import { GAS_STATION_CHAIN_IDS } from './chunk-YWG4XR5A.js';
|
|
7
|
-
import { getRpcEndpointForChain, accountParser, getSigningStargateClient } from './chunk-SOVU5NCL.js';
|
|
8
|
-
import { chains as chains$1, findFirstWorkingEndpoint, getIsEthermint, getIsInitia } from './chunk-RHGDUD76.js';
|
|
9
|
-
import { messages } from './chunk-IHSSWY3M.js';
|
|
10
|
-
import { route } from './chunk-VWOMKMH2.js';
|
|
11
|
-
import { submitTransaction } from './chunk-HDW6XFWX.js';
|
|
12
|
-
import { trackTransaction } from './chunk-AUNRER4I.js';
|
|
13
|
-
import { venues } from './chunk-FNTPI2AV.js';
|
|
14
|
-
import { ClientState, chains, assets, balances } from './chunk-MYGJGC62.js';
|
|
15
|
-
import { ApiState, toCamel, wait } from './chunk-VGCTTJO7.js';
|
|
16
|
-
import { StargateClient } from '@cosmjs/stargate';
|
|
17
|
-
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
18
|
-
import { isOfflineDirectSigner, makeAuthInfoBytes, makeSignDoc, encodePubkey } from '@cosmjs/proto-signing';
|
|
19
|
-
import { pubkeyType as pubkeyType$1, makeSignDoc as makeSignDoc$1, encodeSecp256k1Pubkey } from '@cosmjs/amino';
|
|
20
|
-
import { fromBase64, toBase64 } from '@cosmjs/encoding';
|
|
21
|
-
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys.js';
|
|
22
|
-
import { Any } from 'cosmjs-types/google/protobuf/any.js';
|
|
23
|
-
import { Int53 } from '@cosmjs/math';
|
|
24
|
-
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing.js';
|
|
25
|
-
import { defineChain, createPublicClient, fallback, http, isAddress, formatUnits, publicActions, maxUint256 } from 'viem';
|
|
26
|
-
import { PublicKey, Transaction, Connection, LAMPORTS_PER_SOL } from '@solana/web3.js';
|
|
27
|
-
import { bech32m, bech32 } from 'bech32';
|
|
28
|
-
import { arbitrum, avalanche, base, bsc, celo, fantom, filecoin, kava, linea, mainnet, manta, moonbeam, optimism, polygon, polygonMumbai, sepolia, avalancheFuji, baseSepolia, optimismSepolia, arbitrumSepolia, blast, blastSepolia, forma, sei, bscTestnet, fantomTestnet, kavaTestnet, lineaSepolia, mantaSepoliaTestnet } from 'viem/chains';
|
|
29
|
-
|
|
30
|
-
// src/types/swaggerTypesJson.ts
|
|
31
|
-
var AutopilotActionJson = /* @__PURE__ */ ((AutopilotActionJson2) => {
|
|
32
|
-
AutopilotActionJson2["LIQUID_STAKE"] = "LIQUID_STAKE";
|
|
33
|
-
AutopilotActionJson2["CLAIM"] = "CLAIM";
|
|
34
|
-
return AutopilotActionJson2;
|
|
35
|
-
})(AutopilotActionJson || {});
|
|
36
|
-
var AxelarTransferStateJson = /* @__PURE__ */ ((AxelarTransferStateJson2) => {
|
|
37
|
-
AxelarTransferStateJson2["AXELAR_TRANSFER_UNKNOWN"] = "AXELAR_TRANSFER_UNKNOWN";
|
|
38
|
-
AxelarTransferStateJson2["AXELAR_TRANSFER_PENDING_CONFIRMATION"] = "AXELAR_TRANSFER_PENDING_CONFIRMATION";
|
|
39
|
-
AxelarTransferStateJson2["AXELAR_TRANSFER_PENDING_RECEIPT"] = "AXELAR_TRANSFER_PENDING_RECEIPT";
|
|
40
|
-
AxelarTransferStateJson2["AXELAR_TRANSFER_SUCCESS"] = "AXELAR_TRANSFER_SUCCESS";
|
|
41
|
-
AxelarTransferStateJson2["AXELAR_TRANSFER_FAILURE"] = "AXELAR_TRANSFER_FAILURE";
|
|
42
|
-
return AxelarTransferStateJson2;
|
|
43
|
-
})(AxelarTransferStateJson || {});
|
|
44
|
-
var AxelarTransferTypeJson = /* @__PURE__ */ ((AxelarTransferTypeJson2) => {
|
|
45
|
-
AxelarTransferTypeJson2["AXELAR_TRANSFER_CONTRACT_CALL_WITH_TOKEN"] = "AXELAR_TRANSFER_CONTRACT_CALL_WITH_TOKEN";
|
|
46
|
-
AxelarTransferTypeJson2["AXELAR_TRANSFER_SEND_TOKEN"] = "AXELAR_TRANSFER_SEND_TOKEN";
|
|
47
|
-
return AxelarTransferTypeJson2;
|
|
48
|
-
})(AxelarTransferTypeJson || {});
|
|
49
|
-
var CCTPTransferStateJson = /* @__PURE__ */ ((CCTPTransferStateJson2) => {
|
|
50
|
-
CCTPTransferStateJson2["CCTP_TRANSFER_UNKNOWN"] = "CCTP_TRANSFER_UNKNOWN";
|
|
51
|
-
CCTPTransferStateJson2["CCTP_TRANSFER_SENT"] = "CCTP_TRANSFER_SENT";
|
|
52
|
-
CCTPTransferStateJson2["CCTP_TRANSFER_PENDING_CONFIRMATION"] = "CCTP_TRANSFER_PENDING_CONFIRMATION";
|
|
53
|
-
CCTPTransferStateJson2["CCTP_TRANSFER_CONFIRMED"] = "CCTP_TRANSFER_CONFIRMED";
|
|
54
|
-
CCTPTransferStateJson2["CCTP_TRANSFER_RECEIVED"] = "CCTP_TRANSFER_RECEIVED";
|
|
55
|
-
return CCTPTransferStateJson2;
|
|
56
|
-
})(CCTPTransferStateJson || {});
|
|
57
|
-
var StargateTransferStateJson = /* @__PURE__ */ ((StargateTransferStateJson2) => {
|
|
58
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_UNKNOWN"] = "STARGATE_TRANSFER_UNKNOWN";
|
|
59
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_SENT"] = "STARGATE_TRANSFER_SENT";
|
|
60
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_PENDING_CONFIRMATION"] = "STARGATE_TRANSFER_PENDING_CONFIRMATION";
|
|
61
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_CONFIRMED"] = "STARGATE_TRANSFER_CONFIRMED";
|
|
62
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_RECEIVED"] = "STARGATE_TRANSFER_RECEIVED";
|
|
63
|
-
StargateTransferStateJson2["STARGATE_TRANSFER_FAILED"] = "STARGATE_TRANSFER_FAILED";
|
|
64
|
-
return StargateTransferStateJson2;
|
|
65
|
-
})(StargateTransferStateJson || {});
|
|
66
|
-
var GoFastTransferStateJson = /* @__PURE__ */ ((GoFastTransferStateJson2) => {
|
|
67
|
-
GoFastTransferStateJson2["GO_FAST_TRANSFER_UNKNOWN"] = "GO_FAST_TRANSFER_UNKNOWN";
|
|
68
|
-
GoFastTransferStateJson2["GO_FAST_TRANSFER_SENT"] = "GO_FAST_TRANSFER_SENT";
|
|
69
|
-
GoFastTransferStateJson2["GO_FAST_POST_ACTION_FAILED"] = "GO_FAST_POST_ACTION_FAILED";
|
|
70
|
-
GoFastTransferStateJson2["GO_FAST_TRANSFER_TIMEOUT"] = "GO_FAST_TRANSFER_TIMEOUT";
|
|
71
|
-
GoFastTransferStateJson2["GO_FAST_TRANSFER_FILLED"] = "GO_FAST_TRANSFER_FILLED";
|
|
72
|
-
GoFastTransferStateJson2["GO_FAST_TRANSFER_REFUNDED"] = "GO_FAST_TRANSFER_REFUNDED";
|
|
73
|
-
return GoFastTransferStateJson2;
|
|
74
|
-
})(GoFastTransferStateJson || {});
|
|
75
|
-
var BridgeTypeJson = /* @__PURE__ */ ((BridgeTypeJson2) => {
|
|
76
|
-
BridgeTypeJson2["IBC"] = "IBC";
|
|
77
|
-
BridgeTypeJson2["AXELAR"] = "AXELAR";
|
|
78
|
-
BridgeTypeJson2["CCTP"] = "CCTP";
|
|
79
|
-
BridgeTypeJson2["HYPERLANE"] = "HYPERLANE";
|
|
80
|
-
BridgeTypeJson2["OPINIT"] = "OPINIT";
|
|
81
|
-
BridgeTypeJson2["GO_FAST"] = "GO_FAST";
|
|
82
|
-
BridgeTypeJson2["STARGATE"] = "STARGATE";
|
|
83
|
-
BridgeTypeJson2["LAYER_ZERO"] = "LAYER_ZERO";
|
|
84
|
-
BridgeTypeJson2["EUREKA"] = "EUREKA";
|
|
85
|
-
return BridgeTypeJson2;
|
|
86
|
-
})(BridgeTypeJson || {});
|
|
87
|
-
var ChainTypeJson = /* @__PURE__ */ ((ChainTypeJson2) => {
|
|
88
|
-
ChainTypeJson2["Cosmos"] = "cosmos";
|
|
89
|
-
ChainTypeJson2["Evm"] = "evm";
|
|
90
|
-
ChainTypeJson2["Svm"] = "svm";
|
|
91
|
-
return ChainTypeJson2;
|
|
92
|
-
})(ChainTypeJson || {});
|
|
93
|
-
var ContractCallWithTokenErrorTypeJson = /* @__PURE__ */ ((ContractCallWithTokenErrorTypeJson2) => {
|
|
94
|
-
ContractCallWithTokenErrorTypeJson2["CONTRACT_CALL_WITH_TOKEN_EXECUTION_ERROR"] = "CONTRACT_CALL_WITH_TOKEN_EXECUTION_ERROR";
|
|
95
|
-
return ContractCallWithTokenErrorTypeJson2;
|
|
96
|
-
})(ContractCallWithTokenErrorTypeJson || {});
|
|
97
|
-
var HyperlaneTransferStateJson = /* @__PURE__ */ ((HyperlaneTransferStateJson2) => {
|
|
98
|
-
HyperlaneTransferStateJson2["HYPERLANE_TRANSFER_UNKNOWN"] = "HYPERLANE_TRANSFER_UNKNOWN";
|
|
99
|
-
HyperlaneTransferStateJson2["HYPERLANE_TRANSFER_SENT"] = "HYPERLANE_TRANSFER_SENT";
|
|
100
|
-
HyperlaneTransferStateJson2["HYPERLANE_TRANSFER_FAILED"] = "HYPERLANE_TRANSFER_FAILED";
|
|
101
|
-
HyperlaneTransferStateJson2["HYPERLANE_TRANSFER_RECEIVED"] = "HYPERLANE_TRANSFER_RECEIVED";
|
|
102
|
-
return HyperlaneTransferStateJson2;
|
|
103
|
-
})(HyperlaneTransferStateJson || {});
|
|
104
|
-
var PacketErrorTypeJson = /* @__PURE__ */ ((PacketErrorTypeJson2) => {
|
|
105
|
-
PacketErrorTypeJson2["PACKET_ERROR_UNKNOWN"] = "PACKET_ERROR_UNKNOWN";
|
|
106
|
-
PacketErrorTypeJson2["PACKET_ERROR_ACKNOWLEDGEMENT"] = "PACKET_ERROR_ACKNOWLEDGEMENT";
|
|
107
|
-
PacketErrorTypeJson2["PACKET_ERROR_TIMEOUT"] = "PACKET_ERROR_TIMEOUT";
|
|
108
|
-
return PacketErrorTypeJson2;
|
|
109
|
-
})(PacketErrorTypeJson || {});
|
|
110
|
-
var ReasonJson = /* @__PURE__ */ ((ReasonJson2) => {
|
|
111
|
-
ReasonJson2["UNKNOWN"] = "UNKNOWN";
|
|
112
|
-
ReasonJson2["MOST_LIQUID"] = "MOST_LIQUID";
|
|
113
|
-
ReasonJson2["BASE_TOKEN"] = "BASE_TOKEN";
|
|
114
|
-
ReasonJson2["DIRECT"] = "DIRECT";
|
|
115
|
-
return ReasonJson2;
|
|
116
|
-
})(ReasonJson || {});
|
|
117
|
-
var RoutePriceWarningTypeJson = /* @__PURE__ */ ((RoutePriceWarningTypeJson2) => {
|
|
118
|
-
RoutePriceWarningTypeJson2["LOW_INFO_WARNING"] = "LOW_INFO_WARNING";
|
|
119
|
-
RoutePriceWarningTypeJson2["BAD_PRICE_WARNING"] = "BAD_PRICE_WARNING";
|
|
120
|
-
return RoutePriceWarningTypeJson2;
|
|
121
|
-
})(RoutePriceWarningTypeJson || {});
|
|
122
|
-
var SendTokenErrorTypeJson = /* @__PURE__ */ ((SendTokenErrorTypeJson2) => {
|
|
123
|
-
SendTokenErrorTypeJson2["SEND_TOKEN_EXECUTION_ERROR"] = "SEND_TOKEN_EXECUTION_ERROR";
|
|
124
|
-
return SendTokenErrorTypeJson2;
|
|
125
|
-
})(SendTokenErrorTypeJson || {});
|
|
126
|
-
var StatusErrorTypeJson = /* @__PURE__ */ ((StatusErrorTypeJson2) => {
|
|
127
|
-
StatusErrorTypeJson2["STATUS_ERROR_UNKNOWN"] = "STATUS_ERROR_UNKNOWN";
|
|
128
|
-
StatusErrorTypeJson2["STATUS_ERROR_TRANSACTION_EXECUTION"] = "STATUS_ERROR_TRANSACTION_EXECUTION";
|
|
129
|
-
StatusErrorTypeJson2["STATUS_ERROR_INDEXING"] = "STATUS_ERROR_INDEXING";
|
|
130
|
-
StatusErrorTypeJson2["STATUS_ERROR_TRANSFER"] = "STATUS_ERROR_TRANSFER";
|
|
131
|
-
return StatusErrorTypeJson2;
|
|
132
|
-
})(StatusErrorTypeJson || {});
|
|
133
|
-
var TransactionStateJson = /* @__PURE__ */ ((TransactionStateJson2) => {
|
|
134
|
-
TransactionStateJson2["STATE_SUBMITTED"] = "STATE_SUBMITTED";
|
|
135
|
-
TransactionStateJson2["STATE_PENDING"] = "STATE_PENDING";
|
|
136
|
-
TransactionStateJson2["STATE_ABANDONED"] = "STATE_ABANDONED";
|
|
137
|
-
TransactionStateJson2["STATE_COMPLETED_SUCCESS"] = "STATE_COMPLETED_SUCCESS";
|
|
138
|
-
TransactionStateJson2["STATE_COMPLETED_ERROR"] = "STATE_COMPLETED_ERROR";
|
|
139
|
-
TransactionStateJson2["STATE_PENDING_ERROR"] = "STATE_PENDING_ERROR";
|
|
140
|
-
return TransactionStateJson2;
|
|
141
|
-
})(TransactionStateJson || {});
|
|
142
|
-
var OPInitTransferStateJson = /* @__PURE__ */ ((OPInitTransferStateJson2) => {
|
|
143
|
-
OPInitTransferStateJson2["OPINIT_TRANSFER_UNKNOWN"] = "OPINIT_TRANSFER_UNKNOWN";
|
|
144
|
-
OPInitTransferStateJson2["OPINIT_TRANSFER_SENT"] = "OPINIT_TRANSFER_SENT";
|
|
145
|
-
OPInitTransferStateJson2["OPINIT_TRANSFER_RECEIVED"] = "OPINIT_TRANSFER_RECEIVED";
|
|
146
|
-
return OPInitTransferStateJson2;
|
|
147
|
-
})(OPInitTransferStateJson || {});
|
|
148
|
-
var LayerZeroTransferStateJson = /* @__PURE__ */ ((LayerZeroTransferStateJson2) => {
|
|
149
|
-
LayerZeroTransferStateJson2["LAYER_ZERO_TRANSFER_UNKNOWN"] = "LAYER_ZERO_TRANSFER_UNKNOWN";
|
|
150
|
-
LayerZeroTransferStateJson2["LAYER_ZERO_TRANSFER_SENT"] = "LAYER_ZERO_TRANSFER_SENT";
|
|
151
|
-
LayerZeroTransferStateJson2["LAYER_ZERO_TRANSFER_WAITING_FOR_COMPOSE"] = "LAYER_ZERO_TRANSFER_WAITING_FOR_COMPOSE";
|
|
152
|
-
LayerZeroTransferStateJson2["LAYER_ZERO_TRANSFER_RECEIVED"] = "LAYER_ZERO_TRANSFER_RECEIVED";
|
|
153
|
-
LayerZeroTransferStateJson2["LAYER_ZERO_TRANSFER_FAILED"] = "LAYER_ZERO_TRANSFER_FAILED";
|
|
154
|
-
return LayerZeroTransferStateJson2;
|
|
155
|
-
})(LayerZeroTransferStateJson || {});
|
|
156
|
-
var TransferStateJson = /* @__PURE__ */ ((TransferStateJson2) => {
|
|
157
|
-
TransferStateJson2["TRANSFER_UNKNOWN"] = "TRANSFER_UNKNOWN";
|
|
158
|
-
TransferStateJson2["TRANSFER_PENDING"] = "TRANSFER_PENDING";
|
|
159
|
-
TransferStateJson2["TRANSFER_RECEIVED"] = "TRANSFER_RECEIVED";
|
|
160
|
-
TransferStateJson2["TRANSFER_SUCCESS"] = "TRANSFER_SUCCESS";
|
|
161
|
-
TransferStateJson2["TRANSFER_FAILURE"] = "TRANSFER_FAILURE";
|
|
162
|
-
return TransferStateJson2;
|
|
163
|
-
})(TransferStateJson || {});
|
|
164
|
-
var FeeTypeJson = /* @__PURE__ */ ((FeeTypeJson2) => {
|
|
165
|
-
FeeTypeJson2["SMART_RELAY"] = "SMART_RELAY";
|
|
166
|
-
return FeeTypeJson2;
|
|
167
|
-
})(FeeTypeJson || {});
|
|
168
|
-
var FeeBehaviorJson = /* @__PURE__ */ ((FeeBehaviorJson2) => {
|
|
169
|
-
FeeBehaviorJson2["FEE_BEHAVIOR_DEDUCTED"] = "FEE_BEHAVIOR_DEDUCTED";
|
|
170
|
-
FeeBehaviorJson2["FEE_BEHAVIOR_ADDITIONAL"] = "FEE_BEHAVIOR_ADDITIONAL";
|
|
171
|
-
return FeeBehaviorJson2;
|
|
172
|
-
})(FeeBehaviorJson || {});
|
|
173
|
-
|
|
174
|
-
// src/private-functions/getRestEndpointForChain.ts
|
|
175
|
-
var getRestEndpointForChain = async (chainId) => {
|
|
176
|
-
if (ClientState.endpointOptions.getRestEndpointForChain) {
|
|
177
|
-
return ClientState.endpointOptions.getRestEndpointForChain(chainId);
|
|
178
|
-
}
|
|
179
|
-
if (ClientState.endpointOptions.endpoints && ClientState.endpointOptions.endpoints[chainId]) {
|
|
180
|
-
const endpointOptions = ClientState.endpointOptions.endpoints[chainId];
|
|
181
|
-
if (endpointOptions?.rest) {
|
|
182
|
-
return endpointOptions.rest;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const chain = chains$1().find((chain2) => chain2.chainId === chainId);
|
|
186
|
-
if (!chain) {
|
|
187
|
-
throw new Error(
|
|
188
|
-
`getRestEndpointForChain error: failed to find chain id '${chainId}' in registry`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
if (chain.apis?.rest?.length === 0 || !chain.apis?.rest) {
|
|
192
|
-
throw new Error(
|
|
193
|
-
`getRestEndpointForChain error: failed to find REST endpoint for chain id '${chainId}'`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
const endpoints = chain.apis?.rest?.map((api) => api.address);
|
|
197
|
-
const endpoint = await findFirstWorkingEndpoint(endpoints, "rest");
|
|
198
|
-
if (!endpoint) {
|
|
199
|
-
throw new Error(
|
|
200
|
-
`getRestEndpointForChain error: failed to find REST endpoint for chain id '${chainId}'`
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
return endpoint;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// src/private-functions/getAccountNumberAndSequence.ts
|
|
207
|
-
var getAccountNumberAndSequence = async (address, chainId) => {
|
|
208
|
-
if (chainId.includes("dymension")) {
|
|
209
|
-
return getAccountNumberAndSequenceFromDymension(address, chainId);
|
|
210
|
-
}
|
|
211
|
-
const endpoint = await getRpcEndpointForChain(chainId);
|
|
212
|
-
const client = ClientState.signingStargateClientByChainId[chainId] ?? await StargateClient.connect(endpoint, {
|
|
213
|
-
accountParser
|
|
214
|
-
});
|
|
215
|
-
const account = await client.getAccount(address);
|
|
216
|
-
if (!account) {
|
|
217
|
-
throw new Error("getAccountNumberAndSequence: failed to retrieve account");
|
|
218
|
-
}
|
|
219
|
-
client.disconnect();
|
|
220
|
-
return {
|
|
221
|
-
accountNumber: account.accountNumber,
|
|
222
|
-
sequence: account.sequence
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
var getAccountNumberAndSequenceFromDymension = async (address, chainId) => {
|
|
226
|
-
const endpoint = await getRestEndpointForChain(chainId);
|
|
227
|
-
const res = await fetch(
|
|
228
|
-
`${endpoint}/cosmos/auth/v1beta1/accounts/${address}`,
|
|
229
|
-
{
|
|
230
|
-
headers: {
|
|
231
|
-
"Content-Type": "application/json"
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
);
|
|
235
|
-
if (!res.ok) {
|
|
236
|
-
throw new Error(`Failed to fetch account data: ${res.statusText}`);
|
|
237
|
-
}
|
|
238
|
-
const jsonResponse = await res.json();
|
|
239
|
-
const response = toCamel(jsonResponse);
|
|
240
|
-
let sequence = 0;
|
|
241
|
-
let accountNumber = 0;
|
|
242
|
-
if (response.account.baseAccount) {
|
|
243
|
-
sequence = response.account.baseAccount.sequence;
|
|
244
|
-
accountNumber = response.account.baseAccount.accountNumber;
|
|
245
|
-
} else {
|
|
246
|
-
sequence = response.account.sequence;
|
|
247
|
-
accountNumber = response.account.accountNumber;
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
accountNumber,
|
|
251
|
-
sequence
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
var pubkeyType = {
|
|
255
|
-
ethsecp256k1: "ethermint/PubKeyEthSecp256k1",
|
|
256
|
-
...pubkeyType$1
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// src/amino/encoding.ts
|
|
260
|
-
function encodeEthSecp256k1Pubkey(pubkey) {
|
|
261
|
-
if (pubkey.length !== 33 || pubkey[0] !== 2 && pubkey[0] !== 3) {
|
|
262
|
-
throw new Error(
|
|
263
|
-
"Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03"
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
type: pubkeyType.ethsecp256k1,
|
|
268
|
-
value: toBase64(pubkey)
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/proto-signing/pubkey.ts
|
|
273
|
-
function makePubkeyAnyFromAccount(account, chainId) {
|
|
274
|
-
const isEthermint = getIsEthermint(chainId);
|
|
275
|
-
const pubkey = isEthermint ? encodeEthSecp256k1Pubkey(account.pubkey) : encodeSecp256k1Pubkey(account.pubkey);
|
|
276
|
-
const pubkeyAny = encodePubkeyToAny(pubkey, chainId, isEthermint);
|
|
277
|
-
return pubkeyAny;
|
|
278
|
-
}
|
|
279
|
-
function encodePubkeyToAny(pubkey, chainId, isEthermint) {
|
|
280
|
-
if (isEthermint) {
|
|
281
|
-
const pubkeyProto = PubKey.fromPartial({
|
|
282
|
-
key: fromBase64(pubkey.value)
|
|
283
|
-
});
|
|
284
|
-
let typeUrl = "";
|
|
285
|
-
if (chainId?.includes("injective")) {
|
|
286
|
-
typeUrl = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
|
|
287
|
-
} else {
|
|
288
|
-
typeUrl = "/ethermint.crypto.v1.ethsecp256k1.PubKey";
|
|
289
|
-
}
|
|
290
|
-
return Any.fromPartial({
|
|
291
|
-
typeUrl,
|
|
292
|
-
value: Uint8Array.from(PubKey.encode(pubkeyProto).finish())
|
|
293
|
-
});
|
|
294
|
-
} else {
|
|
295
|
-
const isInitia = getIsInitia(chainId);
|
|
296
|
-
const pubkeyProto = PubKey.fromPartial({
|
|
297
|
-
key: fromBase64(pubkey.value)
|
|
298
|
-
});
|
|
299
|
-
if (isInitia) {
|
|
300
|
-
return Any.fromPartial({
|
|
301
|
-
typeUrl: "/initia.crypto.v1beta1.ethsecp256k1.PubKey",
|
|
302
|
-
value: Uint8Array.from(PubKey.encode(pubkeyProto).finish())
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
return encodePubkey(pubkey);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
var signCosmosMessageDirect = async (options) => {
|
|
309
|
-
const {
|
|
310
|
-
signer,
|
|
311
|
-
signerAddress,
|
|
312
|
-
chainId,
|
|
313
|
-
cosmosMsgs,
|
|
314
|
-
fee,
|
|
315
|
-
signerData: { accountNumber, sequence, chainId: signerChainId }
|
|
316
|
-
} = options;
|
|
317
|
-
const accounts = await signer.getAccounts();
|
|
318
|
-
const accountFromSigner = accounts.find((account) => account.address === signerAddress);
|
|
319
|
-
if (!accountFromSigner) {
|
|
320
|
-
throw new Error("signCosmosMessageDirect error: failed to retrieve account from signer");
|
|
321
|
-
}
|
|
322
|
-
const messages2 = cosmosMsgs.map((cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg));
|
|
323
|
-
const txBodyEncodeObject = {
|
|
324
|
-
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
325
|
-
value: {
|
|
326
|
-
messages: messages2
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
const txBodyBytes = ClientState.registry.encode(txBodyEncodeObject);
|
|
330
|
-
const gasLimit = Int53.fromString(fee.gas).toNumber();
|
|
331
|
-
const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
|
|
332
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
333
|
-
[{ pubkey: pubkeyAny, sequence }],
|
|
334
|
-
fee.amount,
|
|
335
|
-
gasLimit,
|
|
336
|
-
fee.granter,
|
|
337
|
-
fee.payer
|
|
338
|
-
);
|
|
339
|
-
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
340
|
-
const { signature, signed } = await signer.signDirect(signerAddress, signDoc);
|
|
341
|
-
return TxRaw.fromPartial({
|
|
342
|
-
bodyBytes: signed.bodyBytes,
|
|
343
|
-
authInfoBytes: signed.authInfoBytes,
|
|
344
|
-
signatures: [fromBase64(signature.signature)]
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
|
-
var signCosmosMessageAmino = async (options) => {
|
|
348
|
-
const {
|
|
349
|
-
signer,
|
|
350
|
-
signerAddress,
|
|
351
|
-
chainId,
|
|
352
|
-
cosmosMsgs,
|
|
353
|
-
fee,
|
|
354
|
-
signerData: { accountNumber, sequence, chainId: signerChainId }
|
|
355
|
-
} = options;
|
|
356
|
-
const accounts = await signer.getAccounts();
|
|
357
|
-
const accountFromSigner = accounts.find(
|
|
358
|
-
(account) => account.address === signerAddress
|
|
359
|
-
);
|
|
360
|
-
if (!accountFromSigner) {
|
|
361
|
-
throw new Error(
|
|
362
|
-
"signCosmosMessageAmino: failed to retrieve account from signer"
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
const messages2 = cosmosMsgs.map(
|
|
366
|
-
(cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg)
|
|
367
|
-
);
|
|
368
|
-
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
369
|
-
const msgs = messages2.map((msg) => ClientState.aminoTypes.toAmino(msg));
|
|
370
|
-
const signDoc = makeSignDoc$1(
|
|
371
|
-
msgs,
|
|
372
|
-
fee,
|
|
373
|
-
signerChainId,
|
|
374
|
-
"",
|
|
375
|
-
accountNumber,
|
|
376
|
-
sequence
|
|
377
|
-
);
|
|
378
|
-
const { signature, signed } = await signer.signAmino(signerAddress, signDoc);
|
|
379
|
-
const signedTxBody = {
|
|
380
|
-
messages: signed.msgs.map((msg) => ClientState.aminoTypes.fromAmino(msg)),
|
|
381
|
-
memo: signed.memo
|
|
382
|
-
};
|
|
383
|
-
signedTxBody.messages[0].value.memo = messages2[0].value.memo;
|
|
384
|
-
const signedTxBodyEncodeObject = {
|
|
385
|
-
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
386
|
-
value: signedTxBody
|
|
387
|
-
};
|
|
388
|
-
const signedTxBodyBytes = ClientState.registry.encode(
|
|
389
|
-
signedTxBodyEncodeObject
|
|
390
|
-
);
|
|
391
|
-
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
|
|
392
|
-
const signedSequence = Int53.fromString(signed.sequence).toNumber();
|
|
393
|
-
const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
|
|
394
|
-
const signedAuthInfoBytes = makeAuthInfoBytes(
|
|
395
|
-
[{ pubkey: pubkeyAny, sequence: signedSequence }],
|
|
396
|
-
signed.fee.amount,
|
|
397
|
-
signedGasLimit,
|
|
398
|
-
signed.fee.granter,
|
|
399
|
-
signed.fee.payer,
|
|
400
|
-
signMode
|
|
401
|
-
);
|
|
402
|
-
return TxRaw.fromPartial({
|
|
403
|
-
bodyBytes: signedTxBodyBytes,
|
|
404
|
-
authInfoBytes: signedAuthInfoBytes,
|
|
405
|
-
signatures: [fromBase64(signature.signature)]
|
|
406
|
-
});
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/private-functions/cosmos/signCosmosTransaction.ts
|
|
410
|
-
var signCosmosTransaction = async ({
|
|
411
|
-
tx,
|
|
412
|
-
options,
|
|
413
|
-
index,
|
|
414
|
-
routeId
|
|
415
|
-
}) => {
|
|
416
|
-
const { userAddresses } = options;
|
|
417
|
-
if (tx === void 0) {
|
|
418
|
-
throw new Error("executeCosmosTransaction error: tx is undefined");
|
|
419
|
-
}
|
|
420
|
-
const chainId = tx.cosmosTx?.chainId;
|
|
421
|
-
const messages2 = tx.cosmosTx?.msgs;
|
|
422
|
-
const currentUserAddress = userAddresses.find((x) => x.chainId === tx.cosmosTx?.chainId)?.address;
|
|
423
|
-
const gasArray = ClientState.validateGasResults;
|
|
424
|
-
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
425
|
-
if (typeof gas?.error === "string") {
|
|
426
|
-
throw new Error(gas?.error);
|
|
427
|
-
}
|
|
428
|
-
const gasUsed = gasArray?.[index];
|
|
429
|
-
if (!gasUsed) {
|
|
430
|
-
throw new Error(`executeRoute error: invalid gas at index ${index}`);
|
|
431
|
-
}
|
|
432
|
-
if (chainId === void 0) {
|
|
433
|
-
throw new Error("no chainId found for tx");
|
|
434
|
-
}
|
|
435
|
-
if (messages2 === void 0) {
|
|
436
|
-
throw new Error("no messages found for tx");
|
|
437
|
-
}
|
|
438
|
-
const { signer } = await getSigningStargateClient({
|
|
439
|
-
chainId,
|
|
440
|
-
getOfflineSigner: options?.getCosmosSigner
|
|
441
|
-
});
|
|
442
|
-
if (!currentUserAddress) {
|
|
443
|
-
throw new Error(
|
|
444
|
-
`executeCosmosTransaction error: invalid address for chain '${tx.cosmosTx?.chainId}'`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
const accounts = await signer.getAccounts();
|
|
448
|
-
const accountFromSigner = accounts.find((account) => account.address === currentUserAddress);
|
|
449
|
-
if (!accountFromSigner) {
|
|
450
|
-
throw new Error("executeCosmosTransaction error: failed to retrieve account from signer");
|
|
451
|
-
}
|
|
452
|
-
const fee = gasUsed?.fee;
|
|
453
|
-
if (!fee) {
|
|
454
|
-
throw new Error("executeCosmosTransaction error: failed to retrieve fee from gas");
|
|
455
|
-
}
|
|
456
|
-
const { accountNumber, sequence } = await getAccountNumberAndSequence(
|
|
457
|
-
currentUserAddress,
|
|
458
|
-
chainId
|
|
459
|
-
);
|
|
460
|
-
let rawTx;
|
|
461
|
-
const commonRawTxBody = {
|
|
462
|
-
signerAddress: currentUserAddress,
|
|
463
|
-
chainId,
|
|
464
|
-
cosmosMsgs: messages2,
|
|
465
|
-
fee,
|
|
466
|
-
signerData: {
|
|
467
|
-
accountNumber,
|
|
468
|
-
sequence,
|
|
469
|
-
chainId
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
options.onTransactionSignRequested?.({
|
|
473
|
-
chainId,
|
|
474
|
-
txIndex: index,
|
|
475
|
-
signerAddress: currentUserAddress
|
|
476
|
-
});
|
|
477
|
-
updateRouteDetails({
|
|
478
|
-
status: "signing",
|
|
479
|
-
routeId,
|
|
480
|
-
options
|
|
481
|
-
});
|
|
482
|
-
if (isOfflineDirectSigner(signer)) {
|
|
483
|
-
rawTx = await signCosmosMessageDirect({
|
|
484
|
-
...commonRawTxBody,
|
|
485
|
-
signer
|
|
486
|
-
});
|
|
487
|
-
} else {
|
|
488
|
-
rawTx = await signCosmosMessageAmino({ ...commonRawTxBody, signer });
|
|
489
|
-
}
|
|
490
|
-
options?.onTransactionSigned?.({
|
|
491
|
-
chainId
|
|
492
|
-
});
|
|
493
|
-
updateRouteDetails({
|
|
494
|
-
status: "pending",
|
|
495
|
-
routeId,
|
|
496
|
-
options
|
|
497
|
-
});
|
|
498
|
-
const txBytes = TxRaw.encode(rawTx).finish();
|
|
499
|
-
const rawTxBase64 = Buffer.from(txBytes).toString("base64");
|
|
500
|
-
return rawTxBase64;
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// src/private-functions/cosmos/executeCosmosTransaction.ts
|
|
504
|
-
var executeCosmosTransaction = async ({
|
|
505
|
-
tx,
|
|
506
|
-
options,
|
|
507
|
-
index,
|
|
508
|
-
routeId
|
|
509
|
-
}) => {
|
|
510
|
-
if (tx === void 0) {
|
|
511
|
-
throw new Error("executeCosmosTransaction error: tx is undefined");
|
|
512
|
-
}
|
|
513
|
-
const rawTxBase64 = await signCosmosTransaction({
|
|
514
|
-
tx,
|
|
515
|
-
options,
|
|
516
|
-
index,
|
|
517
|
-
routeId
|
|
518
|
-
});
|
|
519
|
-
const chainId = tx.cosmosTx?.chainId;
|
|
520
|
-
const txResponse = await submitTransaction({
|
|
521
|
-
chainId,
|
|
522
|
-
tx: rawTxBase64
|
|
523
|
-
});
|
|
524
|
-
return {
|
|
525
|
-
chainId: tx?.cosmosTx?.chainId ?? "",
|
|
526
|
-
txHash: txResponse?.txHash ?? "",
|
|
527
|
-
explorerLink: txResponse?.explorerLink ?? ""
|
|
528
|
-
};
|
|
529
|
-
};
|
|
530
|
-
function createAbi(abi) {
|
|
531
|
-
return abi;
|
|
532
|
-
}
|
|
533
|
-
var erc20ABI = /* @__PURE__ */ createAbi([
|
|
534
|
-
{
|
|
535
|
-
type: "event",
|
|
536
|
-
name: "Approval",
|
|
537
|
-
inputs: [
|
|
538
|
-
{
|
|
539
|
-
indexed: true,
|
|
540
|
-
name: "owner",
|
|
541
|
-
type: "address"
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
indexed: true,
|
|
545
|
-
name: "spender",
|
|
546
|
-
type: "address"
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
indexed: false,
|
|
550
|
-
name: "value",
|
|
551
|
-
type: "uint256"
|
|
552
|
-
}
|
|
553
|
-
]
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
type: "event",
|
|
557
|
-
name: "Transfer",
|
|
558
|
-
inputs: [
|
|
559
|
-
{
|
|
560
|
-
indexed: true,
|
|
561
|
-
name: "from",
|
|
562
|
-
type: "address"
|
|
563
|
-
},
|
|
564
|
-
{
|
|
565
|
-
indexed: true,
|
|
566
|
-
name: "to",
|
|
567
|
-
type: "address"
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
indexed: false,
|
|
571
|
-
name: "value",
|
|
572
|
-
type: "uint256"
|
|
573
|
-
}
|
|
574
|
-
]
|
|
575
|
-
},
|
|
576
|
-
{
|
|
577
|
-
type: "function",
|
|
578
|
-
name: "allowance",
|
|
579
|
-
stateMutability: "view",
|
|
580
|
-
inputs: [
|
|
581
|
-
{
|
|
582
|
-
name: "owner",
|
|
583
|
-
type: "address"
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
name: "spender",
|
|
587
|
-
type: "address"
|
|
588
|
-
}
|
|
589
|
-
],
|
|
590
|
-
outputs: [
|
|
591
|
-
{
|
|
592
|
-
name: "",
|
|
593
|
-
type: "uint256"
|
|
594
|
-
}
|
|
595
|
-
]
|
|
596
|
-
},
|
|
597
|
-
{
|
|
598
|
-
type: "function",
|
|
599
|
-
name: "approve",
|
|
600
|
-
stateMutability: "nonpayable",
|
|
601
|
-
inputs: [
|
|
602
|
-
{
|
|
603
|
-
name: "spender",
|
|
604
|
-
type: "address"
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
name: "amount",
|
|
608
|
-
type: "uint256"
|
|
609
|
-
}
|
|
610
|
-
],
|
|
611
|
-
outputs: [
|
|
612
|
-
{
|
|
613
|
-
name: "",
|
|
614
|
-
type: "bool"
|
|
615
|
-
}
|
|
616
|
-
]
|
|
617
|
-
},
|
|
618
|
-
{
|
|
619
|
-
type: "function",
|
|
620
|
-
name: "balanceOf",
|
|
621
|
-
stateMutability: "view",
|
|
622
|
-
inputs: [
|
|
623
|
-
{
|
|
624
|
-
name: "account",
|
|
625
|
-
type: "address"
|
|
626
|
-
}
|
|
627
|
-
],
|
|
628
|
-
outputs: [
|
|
629
|
-
{
|
|
630
|
-
name: "",
|
|
631
|
-
type: "uint256"
|
|
632
|
-
}
|
|
633
|
-
]
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
type: "function",
|
|
637
|
-
name: "decimals",
|
|
638
|
-
stateMutability: "view",
|
|
639
|
-
inputs: [],
|
|
640
|
-
outputs: [
|
|
641
|
-
{
|
|
642
|
-
name: "",
|
|
643
|
-
type: "uint8"
|
|
644
|
-
}
|
|
645
|
-
]
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
type: "function",
|
|
649
|
-
name: "name",
|
|
650
|
-
stateMutability: "view",
|
|
651
|
-
inputs: [],
|
|
652
|
-
outputs: [
|
|
653
|
-
{
|
|
654
|
-
name: "",
|
|
655
|
-
type: "string"
|
|
656
|
-
}
|
|
657
|
-
]
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
type: "function",
|
|
661
|
-
name: "symbol",
|
|
662
|
-
stateMutability: "view",
|
|
663
|
-
inputs: [],
|
|
664
|
-
outputs: [
|
|
665
|
-
{
|
|
666
|
-
name: "",
|
|
667
|
-
type: "string"
|
|
668
|
-
}
|
|
669
|
-
]
|
|
670
|
-
},
|
|
671
|
-
{
|
|
672
|
-
type: "function",
|
|
673
|
-
name: "totalSupply",
|
|
674
|
-
stateMutability: "view",
|
|
675
|
-
inputs: [],
|
|
676
|
-
outputs: [
|
|
677
|
-
{
|
|
678
|
-
name: "",
|
|
679
|
-
type: "uint256"
|
|
680
|
-
}
|
|
681
|
-
]
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
type: "function",
|
|
685
|
-
name: "transfer",
|
|
686
|
-
stateMutability: "nonpayable",
|
|
687
|
-
inputs: [
|
|
688
|
-
{
|
|
689
|
-
name: "recipient",
|
|
690
|
-
type: "address"
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
name: "amount",
|
|
694
|
-
type: "uint256"
|
|
695
|
-
}
|
|
696
|
-
],
|
|
697
|
-
outputs: [
|
|
698
|
-
{
|
|
699
|
-
name: "",
|
|
700
|
-
type: "bool"
|
|
701
|
-
}
|
|
702
|
-
]
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
type: "function",
|
|
706
|
-
name: "transferFrom",
|
|
707
|
-
stateMutability: "nonpayable",
|
|
708
|
-
inputs: [
|
|
709
|
-
{
|
|
710
|
-
name: "sender",
|
|
711
|
-
type: "address"
|
|
712
|
-
},
|
|
713
|
-
{
|
|
714
|
-
name: "recipient",
|
|
715
|
-
type: "address"
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
name: "amount",
|
|
719
|
-
type: "uint256"
|
|
720
|
-
}
|
|
721
|
-
],
|
|
722
|
-
outputs: [
|
|
723
|
-
{
|
|
724
|
-
name: "",
|
|
725
|
-
type: "bool"
|
|
726
|
-
}
|
|
727
|
-
]
|
|
728
|
-
}
|
|
729
|
-
]);
|
|
730
|
-
|
|
731
|
-
// src/private-functions/evm/executeEvmTransaction.ts
|
|
732
|
-
var executeEvmTransaction = async (message, options, index, routeId) => {
|
|
733
|
-
const gasArray = ClientState.validateGasResults;
|
|
734
|
-
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
735
|
-
if (typeof gas?.error === "string") {
|
|
736
|
-
throw new Error(gas?.error);
|
|
737
|
-
}
|
|
738
|
-
const { evmTx } = message;
|
|
739
|
-
const getEvmSigner = options.getEvmSigner;
|
|
740
|
-
if (!getEvmSigner) {
|
|
741
|
-
throw new Error("executeEVMTransaction error: getEvmSigner is not provided");
|
|
742
|
-
}
|
|
743
|
-
if (!evmTx?.chainId) {
|
|
744
|
-
throw new Error("chain id not found in evmTx");
|
|
745
|
-
}
|
|
746
|
-
const evmSigner = await getEvmSigner(evmTx.chainId);
|
|
747
|
-
if (!evmSigner.account) {
|
|
748
|
-
throw new Error("executeEVMTransaction error: failed to retrieve account from signer");
|
|
749
|
-
}
|
|
750
|
-
if (!evmTx.chainId) {
|
|
751
|
-
throw new Error("executeEVMTransaction error: chainId not found for evmTx");
|
|
752
|
-
}
|
|
753
|
-
if (!evmTx.value && evmTx.value !== "") {
|
|
754
|
-
throw new Error("executeEVMTransaction error: no value found in evmTx");
|
|
755
|
-
}
|
|
756
|
-
const { onApproveAllowance, onTransactionSigned, bypassApprovalCheck, useUnlimitedApproval } = options;
|
|
757
|
-
const extendedSigner = evmSigner.extend(publicActions);
|
|
758
|
-
if (!bypassApprovalCheck && evmTx.requiredErc20Approvals) {
|
|
759
|
-
for (const requiredApproval of evmTx.requiredErc20Approvals) {
|
|
760
|
-
const allowance = await extendedSigner.readContract({
|
|
761
|
-
address: requiredApproval.tokenContract,
|
|
762
|
-
abi: erc20ABI,
|
|
763
|
-
functionName: "allowance",
|
|
764
|
-
args: [
|
|
765
|
-
evmSigner.account.address,
|
|
766
|
-
requiredApproval.spender
|
|
767
|
-
]
|
|
768
|
-
});
|
|
769
|
-
if (!requiredApproval.amount) {
|
|
770
|
-
throw new Error("executeEVMTransaction error: no amount found in a requiredApproval");
|
|
771
|
-
}
|
|
772
|
-
if (allowance > BigInt(requiredApproval.amount)) {
|
|
773
|
-
continue;
|
|
774
|
-
}
|
|
775
|
-
onApproveAllowance?.({
|
|
776
|
-
status: "pending",
|
|
777
|
-
allowance: requiredApproval
|
|
778
|
-
});
|
|
779
|
-
updateRouteDetails({
|
|
780
|
-
status: "allowance",
|
|
781
|
-
routeId,
|
|
782
|
-
options
|
|
783
|
-
});
|
|
784
|
-
const txHash2 = await extendedSigner.writeContract({
|
|
785
|
-
account: evmSigner.account,
|
|
786
|
-
address: requiredApproval.tokenContract,
|
|
787
|
-
abi: erc20ABI,
|
|
788
|
-
functionName: "approve",
|
|
789
|
-
args: [
|
|
790
|
-
requiredApproval.spender,
|
|
791
|
-
useUnlimitedApproval ? maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
|
|
792
|
-
],
|
|
793
|
-
chain: evmSigner.chain
|
|
794
|
-
});
|
|
795
|
-
const receipt2 = await extendedSigner.waitForTransactionReceipt({
|
|
796
|
-
hash: txHash2
|
|
797
|
-
});
|
|
798
|
-
if (receipt2.status === "reverted") {
|
|
799
|
-
throw new Error(
|
|
800
|
-
`executeEVMTransaction error: evm tx reverted for hash ${receipt2.transactionHash}`
|
|
801
|
-
);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
onApproveAllowance?.({
|
|
805
|
-
status: "completed"
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
options?.onTransactionSignRequested?.({
|
|
809
|
-
chainId: evmTx.chainId,
|
|
810
|
-
signerAddress: evmSigner.account.address,
|
|
811
|
-
txIndex: index
|
|
812
|
-
});
|
|
813
|
-
updateRouteDetails({
|
|
814
|
-
status: "signing",
|
|
815
|
-
routeId,
|
|
816
|
-
options
|
|
817
|
-
});
|
|
818
|
-
const txHash = await extendedSigner.sendTransaction({
|
|
819
|
-
account: evmSigner.account,
|
|
820
|
-
to: evmTx.to,
|
|
821
|
-
data: `0x${evmTx.data}`,
|
|
822
|
-
chain: evmSigner.chain,
|
|
823
|
-
value: evmTx.value === "" ? void 0 : BigInt(evmTx.value)
|
|
824
|
-
});
|
|
825
|
-
updateRouteDetails({
|
|
826
|
-
status: "pending",
|
|
827
|
-
routeId,
|
|
828
|
-
options
|
|
829
|
-
});
|
|
830
|
-
onTransactionSigned?.({
|
|
831
|
-
chainId: evmTx.chainId
|
|
832
|
-
});
|
|
833
|
-
const receipt = await extendedSigner.waitForTransactionReceipt({
|
|
834
|
-
hash: txHash
|
|
835
|
-
});
|
|
836
|
-
return receipt;
|
|
837
|
-
};
|
|
838
|
-
var signSvmTransaction = async ({
|
|
839
|
-
tx,
|
|
840
|
-
options,
|
|
841
|
-
index,
|
|
842
|
-
routeId
|
|
843
|
-
}) => {
|
|
844
|
-
const gasArray = ClientState.validateGasResults;
|
|
845
|
-
if (tx === void 0) {
|
|
846
|
-
throw new Error("executeSvmTransaction error: tx is undefined");
|
|
847
|
-
}
|
|
848
|
-
const gas = gasArray?.find(
|
|
849
|
-
(gas2) => gas2?.error !== null && gas2?.error !== void 0
|
|
850
|
-
);
|
|
851
|
-
if (typeof gas?.error === "string") {
|
|
852
|
-
throw new Error(gas?.error);
|
|
853
|
-
}
|
|
854
|
-
const svmTx = tx?.svmTx;
|
|
855
|
-
const getSvmSigner = options?.getSvmSigner;
|
|
856
|
-
if (!getSvmSigner) {
|
|
857
|
-
throw new Error(
|
|
858
|
-
"executeSvmTransaction error: getSvmSigner is not provided"
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
const signer = await getSvmSigner();
|
|
862
|
-
if (!svmTx?.chainId) {
|
|
863
|
-
throw new Error("executeSvmTransaction error: chainId not found in svmTx");
|
|
864
|
-
}
|
|
865
|
-
const txBuffer = Buffer.from(svmTx.tx ?? "", "base64");
|
|
866
|
-
const transaction = Transaction.from(txBuffer);
|
|
867
|
-
if (options.svmFeePayer) {
|
|
868
|
-
const message = transaction.serializeMessage();
|
|
869
|
-
const resSignTx = await options.svmFeePayer.signTransaction(message);
|
|
870
|
-
transaction.addSignature(
|
|
871
|
-
new PublicKey(options.svmFeePayer.address),
|
|
872
|
-
Buffer.from(resSignTx)
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
if (!("signTransaction" in signer)) return;
|
|
876
|
-
options?.onTransactionSignRequested?.({
|
|
877
|
-
chainId: svmTx.chainId,
|
|
878
|
-
signerAddress: signer.publicKey?.toBase58(),
|
|
879
|
-
txIndex: index
|
|
880
|
-
});
|
|
881
|
-
updateRouteDetails({
|
|
882
|
-
status: "signing",
|
|
883
|
-
routeId,
|
|
884
|
-
options
|
|
885
|
-
});
|
|
886
|
-
const signedTx = await signer.signTransaction(transaction);
|
|
887
|
-
options?.onTransactionSigned?.({ chainId: svmTx.chainId });
|
|
888
|
-
updateRouteDetails({
|
|
889
|
-
status: "pending",
|
|
890
|
-
routeId,
|
|
891
|
-
options
|
|
892
|
-
});
|
|
893
|
-
const serializedTx = signedTx.serialize();
|
|
894
|
-
return serializedTx;
|
|
895
|
-
};
|
|
896
|
-
|
|
897
|
-
// src/private-functions/svm/executeSvmTransaction.ts
|
|
898
|
-
var executeSvmTransaction = async (tx, options, index, routeId) => {
|
|
899
|
-
const svmTx = tx?.svmTx;
|
|
900
|
-
if (!svmTx?.chainId) {
|
|
901
|
-
throw new Error("executeSvmTransaction error: chainId not found in svmTx");
|
|
902
|
-
}
|
|
903
|
-
const signedTx = await signSvmTransaction({ tx, options, index, routeId });
|
|
904
|
-
if (!signedTx) {
|
|
905
|
-
throw new Error("executeSvmTransaction error: signedTx is undefined");
|
|
906
|
-
}
|
|
907
|
-
const endpoint = await getRpcEndpointForChain(svmTx.chainId);
|
|
908
|
-
const connection = new Connection(endpoint);
|
|
909
|
-
let signature;
|
|
910
|
-
const submitTxResponse = await submitTransaction({
|
|
911
|
-
chainId: svmTx.chainId,
|
|
912
|
-
tx: signedTx.toString("base64")
|
|
913
|
-
});
|
|
914
|
-
signature = submitTxResponse?.txHash;
|
|
915
|
-
const rpcSig = await connection.sendRawTransaction(signedTx, {
|
|
916
|
-
preflightCommitment: "confirmed",
|
|
917
|
-
maxRetries: 5
|
|
918
|
-
});
|
|
919
|
-
signature = rpcSig;
|
|
920
|
-
if (!signature) {
|
|
921
|
-
throw new Error("executeSvmTransaction error: signature not found");
|
|
922
|
-
}
|
|
923
|
-
let getStatusCount = 0;
|
|
924
|
-
let errorCount = 0;
|
|
925
|
-
while (true) {
|
|
926
|
-
try {
|
|
927
|
-
const status = await connection.getSignatureStatus(signature, {
|
|
928
|
-
searchTransactionHistory: true
|
|
929
|
-
});
|
|
930
|
-
if (status?.value?.confirmationStatus === "confirmed") {
|
|
931
|
-
return {
|
|
932
|
-
chainId: svmTx.chainId,
|
|
933
|
-
txHash: signature,
|
|
934
|
-
explorerLink: submitTxResponse?.explorerLink ?? ""
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
if (getStatusCount > 12) {
|
|
938
|
-
await wait(3e3);
|
|
939
|
-
throw new Error(
|
|
940
|
-
`executeSvmTransaction error: waiting finalized status timed out for ${signature}`
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
getStatusCount++;
|
|
944
|
-
await wait(3e3);
|
|
945
|
-
} catch (error) {
|
|
946
|
-
errorCount++;
|
|
947
|
-
if (errorCount > 12) {
|
|
948
|
-
throw error;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
var validateEvmTokenApproval = async ({
|
|
954
|
-
requiredErc20Approvals,
|
|
955
|
-
signer,
|
|
956
|
-
chain,
|
|
957
|
-
gasBalance,
|
|
958
|
-
tx,
|
|
959
|
-
useUnlimitedApproval
|
|
960
|
-
}) => {
|
|
961
|
-
if (!signer.account?.address) {
|
|
962
|
-
throw new Error("validateEvmGasBalance: Signer address not found");
|
|
963
|
-
}
|
|
964
|
-
for (const requiredApproval of requiredErc20Approvals) {
|
|
965
|
-
const extendedSigner = signer.extend(publicActions);
|
|
966
|
-
const allowance = await extendedSigner.readContract({
|
|
967
|
-
address: requiredApproval.tokenContract,
|
|
968
|
-
abi: erc20ABI,
|
|
969
|
-
functionName: "allowance",
|
|
970
|
-
args: [signer.account?.address, requiredApproval.spender]
|
|
971
|
-
});
|
|
972
|
-
if (allowance > BigInt(requiredApproval.amount)) {
|
|
973
|
-
continue;
|
|
974
|
-
}
|
|
975
|
-
const fee = await extendedSigner.estimateFeesPerGas();
|
|
976
|
-
const allowanceGasFee = BigInt(fee.maxFeePerGas) * BigInt(1e5);
|
|
977
|
-
if (!gasBalance) {
|
|
978
|
-
const chainAssets = (await ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
|
|
979
|
-
const nativeAsset = chainAssets?.find((x) => x.denom.includes("-native"));
|
|
980
|
-
const zeroAddressAsset = chainAssets?.find(
|
|
981
|
-
(x) => x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
982
|
-
);
|
|
983
|
-
const asset = nativeAsset || zeroAddressAsset;
|
|
984
|
-
if (!asset?.decimals) {
|
|
985
|
-
throw new Error(
|
|
986
|
-
`Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei.`
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
const formattedGasAmount = formatUnits(allowanceGasFee, asset?.decimals);
|
|
990
|
-
throw new Error(
|
|
991
|
-
`Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`
|
|
992
|
-
);
|
|
993
|
-
}
|
|
994
|
-
if (BigNumber(gasBalance.amount).lt(Number(allowanceGasFee))) {
|
|
995
|
-
const chainAssets = (await ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
|
|
996
|
-
const asset = chainAssets?.find(
|
|
997
|
-
(x) => x.denom.includes("-native") || x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
998
|
-
);
|
|
999
|
-
if (!asset?.decimals) {
|
|
1000
|
-
return {
|
|
1001
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei but only have ${gasBalance.amount} gwei.`,
|
|
1002
|
-
asset: null,
|
|
1003
|
-
fee: null
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
const formattedGasAmount = formatUnits(allowanceGasFee, asset?.decimals);
|
|
1007
|
-
return {
|
|
1008
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
|
|
1009
|
-
asset: null,
|
|
1010
|
-
fee: null
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
const txHash = await extendedSigner.writeContract({
|
|
1014
|
-
account: signer.account,
|
|
1015
|
-
address: requiredApproval.tokenContract,
|
|
1016
|
-
abi: erc20ABI,
|
|
1017
|
-
functionName: "approve",
|
|
1018
|
-
args: [
|
|
1019
|
-
requiredApproval.spender,
|
|
1020
|
-
useUnlimitedApproval ? maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
|
|
1021
|
-
],
|
|
1022
|
-
chain: signer.chain
|
|
1023
|
-
});
|
|
1024
|
-
const receipt = await extendedSigner.waitForTransactionReceipt({
|
|
1025
|
-
hash: txHash
|
|
1026
|
-
});
|
|
1027
|
-
if (receipt.status === "reverted") {
|
|
1028
|
-
throw new Error(
|
|
1029
|
-
`executeEVMTransaction error: evm tx reverted for hash ${receipt.transactionHash}`
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
};
|
|
1034
|
-
|
|
1035
|
-
// src/private-functions/evm/validateEvmGasBalance.ts
|
|
1036
|
-
var validateEvmGasBalance = async ({
|
|
1037
|
-
signer,
|
|
1038
|
-
tx,
|
|
1039
|
-
getFallbackGasAmount,
|
|
1040
|
-
useUnlimitedApproval,
|
|
1041
|
-
bypassApprovalCheck
|
|
1042
|
-
}) => {
|
|
1043
|
-
const chainId = tx?.chainId ?? "";
|
|
1044
|
-
const skipAssets = (await ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
1045
|
-
const skipChains = await ClientState.getSkipChains();
|
|
1046
|
-
const chain = skipChains?.find?.((chain2) => chain2.chainId === chainId);
|
|
1047
|
-
if (!chain) {
|
|
1048
|
-
throw new Error(`failed to find chain for chainId: '${chainId}'`);
|
|
1049
|
-
}
|
|
1050
|
-
if (!signer.account?.address) {
|
|
1051
|
-
throw new Error("validateEvmGasBalance: Signer address not found");
|
|
1052
|
-
}
|
|
1053
|
-
const skipBalances = (await balances({
|
|
1054
|
-
chains: {
|
|
1055
|
-
[tx?.chainId ?? ""]: {
|
|
1056
|
-
address: signer.account?.address
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}))?.chains?.[tx?.chainId ?? ""]?.denoms;
|
|
1060
|
-
const nativeGasBalance = skipBalances && Object.entries(skipBalances).find(([denom]) => denom.includes("-native"))?.[1];
|
|
1061
|
-
const zeroAddressGasBalance = skipBalances && Object.entries(skipBalances).find(
|
|
1062
|
-
([denom]) => denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1063
|
-
)?.[1];
|
|
1064
|
-
const gasBalance = nativeGasBalance || zeroAddressGasBalance;
|
|
1065
|
-
const { requiredErc20Approvals } = tx;
|
|
1066
|
-
if (!bypassApprovalCheck && requiredErc20Approvals) {
|
|
1067
|
-
try {
|
|
1068
|
-
await validateEvmTokenApproval({
|
|
1069
|
-
requiredErc20Approvals,
|
|
1070
|
-
signer,
|
|
1071
|
-
chain,
|
|
1072
|
-
gasBalance,
|
|
1073
|
-
tx,
|
|
1074
|
-
useUnlimitedApproval
|
|
1075
|
-
});
|
|
1076
|
-
} catch (error) {
|
|
1077
|
-
const err = error;
|
|
1078
|
-
return {
|
|
1079
|
-
error: err.message,
|
|
1080
|
-
asset: null,
|
|
1081
|
-
fee: null
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
const gasAmount = await getEVMGasAmountForMessage(signer, tx, getFallbackGasAmount);
|
|
1086
|
-
if (!gasBalance) {
|
|
1087
|
-
const nativeAsset = skipAssets?.find((x) => x.denom?.includes("-native"));
|
|
1088
|
-
const zeroAddressAsset = skipAssets?.find(
|
|
1089
|
-
(x) => x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1090
|
-
);
|
|
1091
|
-
const asset = nativeAsset || zeroAddressAsset;
|
|
1092
|
-
if (!asset?.decimals) {
|
|
1093
|
-
return {
|
|
1094
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei.`,
|
|
1095
|
-
asset: null,
|
|
1096
|
-
fee: null
|
|
1097
|
-
};
|
|
1098
|
-
}
|
|
1099
|
-
const formattedGasAmount = formatUnits(gasAmount, asset?.decimals);
|
|
1100
|
-
return {
|
|
1101
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`,
|
|
1102
|
-
asset: null,
|
|
1103
|
-
fee: null
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
if (BigNumber(gasBalance.amount ?? "").lt(Number(gasAmount))) {
|
|
1107
|
-
const asset = skipAssets?.find(
|
|
1108
|
-
(x) => x.denom?.includes("-native") || x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1109
|
-
);
|
|
1110
|
-
if (!asset?.decimals) {
|
|
1111
|
-
return {
|
|
1112
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei but only have ${gasBalance.amount} gwei.`,
|
|
1113
|
-
asset: null,
|
|
1114
|
-
fee: null
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
const formattedGasAmount = formatUnits(gasAmount, asset?.decimals);
|
|
1118
|
-
return {
|
|
1119
|
-
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
|
|
1120
|
-
asset: null,
|
|
1121
|
-
fee: null
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
var validateSvmGasBalance = async ({
|
|
1126
|
-
tx,
|
|
1127
|
-
simulate,
|
|
1128
|
-
feePayerAddress
|
|
1129
|
-
}) => {
|
|
1130
|
-
if (!tx) throw new Error("Transaction is required");
|
|
1131
|
-
if (simulate === false) {
|
|
1132
|
-
return {
|
|
1133
|
-
success: true,
|
|
1134
|
-
logs: [],
|
|
1135
|
-
error: null,
|
|
1136
|
-
asset: null,
|
|
1137
|
-
fee: null
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
const endpoint = await getRpcEndpointForChain(tx.chainId ?? "");
|
|
1141
|
-
const connection = new Connection(endpoint);
|
|
1142
|
-
if (!connection) throw new Error(`Failed to connect to ${tx.chainId}`);
|
|
1143
|
-
const gasAmount = await getSVMGasAmountForMessage(connection, tx);
|
|
1144
|
-
const skipBalances = await balances({
|
|
1145
|
-
chains: {
|
|
1146
|
-
solana: {
|
|
1147
|
-
address: feePayerAddress ?? tx?.signerAddress,
|
|
1148
|
-
denoms: ["solana-native"]
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
});
|
|
1152
|
-
const gasBalance = skipBalances?.chains?.["solana"]?.denoms?.["solana-native"];
|
|
1153
|
-
if (!gasBalance) {
|
|
1154
|
-
return {
|
|
1155
|
-
success: false,
|
|
1156
|
-
error: `Insufficient balance for gas on Solana. Need ${gasAmount / LAMPORTS_PER_SOL} SOL.`,
|
|
1157
|
-
asset: null,
|
|
1158
|
-
fee: null
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
if (bignumber_default(gasBalance.amount ?? "").lt(gasAmount)) {
|
|
1162
|
-
return {
|
|
1163
|
-
success: false,
|
|
1164
|
-
error: `Insufficient balance for gas on Solana. Need ${gasAmount / LAMPORTS_PER_SOL} SOL but only have ${gasBalance.formattedAmount} SOL.`,
|
|
1165
|
-
asset: null,
|
|
1166
|
-
fee: null
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
success: true,
|
|
1171
|
-
error: null,
|
|
1172
|
-
asset: null,
|
|
1173
|
-
fee: null
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
async function getSVMGasAmountForMessage(connection, tx) {
|
|
1177
|
-
const _tx = Buffer.from(tx?.tx ?? "", "base64");
|
|
1178
|
-
const transaction = Transaction.from(_tx);
|
|
1179
|
-
const gas = await connection.getFeeForMessage(
|
|
1180
|
-
transaction.compileMessage(),
|
|
1181
|
-
"confirmed"
|
|
1182
|
-
);
|
|
1183
|
-
if (!gas.value) {
|
|
1184
|
-
throw new Error(
|
|
1185
|
-
`estimateGasForSVMTx error: unable to get gas for transaction on ${tx?.chainId}`
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1188
|
-
return gas.value;
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
// src/private-functions/validateGasBalances.ts
|
|
1192
|
-
var validateGasBalances = async ({
|
|
1193
|
-
txs,
|
|
1194
|
-
onValidateGasBalance,
|
|
1195
|
-
getFallbackGasAmount,
|
|
1196
|
-
getCosmosSigner,
|
|
1197
|
-
getEvmSigner,
|
|
1198
|
-
simulate,
|
|
1199
|
-
disabledChainIds,
|
|
1200
|
-
enabledChainIds,
|
|
1201
|
-
getCosmosPriorityFeeDenom,
|
|
1202
|
-
routeId,
|
|
1203
|
-
options,
|
|
1204
|
-
isMultiRoutes
|
|
1205
|
-
}) => {
|
|
1206
|
-
const validateResult = await Promise.all(
|
|
1207
|
-
txs.map(async (tx, i) => {
|
|
1208
|
-
if (!tx) {
|
|
1209
|
-
throw new Error(`invalid tx at index ${i}`);
|
|
1210
|
-
}
|
|
1211
|
-
if ("cosmosTx" in tx && !disabledChainIds?.includes(tx?.cosmosTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.cosmosTx?.chainId ?? ""))) {
|
|
1212
|
-
onValidateGasBalance?.({
|
|
1213
|
-
status: "pending"
|
|
1214
|
-
});
|
|
1215
|
-
updateRouteDetails({
|
|
1216
|
-
status: "validating",
|
|
1217
|
-
routeId,
|
|
1218
|
-
options
|
|
1219
|
-
});
|
|
1220
|
-
if (!tx?.cosmosTx?.msgs) {
|
|
1221
|
-
throw new Error(`invalid msgs ${tx?.cosmosTx?.msgs}`);
|
|
1222
|
-
}
|
|
1223
|
-
try {
|
|
1224
|
-
const res = await validateCosmosGasBalance({
|
|
1225
|
-
chainId: tx.cosmosTx.chainId ?? "",
|
|
1226
|
-
signerAddress: tx.cosmosTx.signerAddress ?? "",
|
|
1227
|
-
messages: tx.cosmosTx.msgs,
|
|
1228
|
-
getFallbackGasAmount,
|
|
1229
|
-
getOfflineSigner: getCosmosSigner,
|
|
1230
|
-
txIndex: i,
|
|
1231
|
-
simulate,
|
|
1232
|
-
getCosmosPriorityFeeDenom,
|
|
1233
|
-
isMultiRoutes
|
|
1234
|
-
});
|
|
1235
|
-
return res;
|
|
1236
|
-
} catch (e) {
|
|
1237
|
-
const error = e;
|
|
1238
|
-
return {
|
|
1239
|
-
error: error.message,
|
|
1240
|
-
asset: null,
|
|
1241
|
-
fee: null
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
if ("evmTx" in tx && !disabledChainIds?.includes(tx?.evmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.evmTx?.chainId ?? ""))) {
|
|
1246
|
-
onValidateGasBalance?.({
|
|
1247
|
-
status: "pending"
|
|
1248
|
-
});
|
|
1249
|
-
updateRouteDetails({
|
|
1250
|
-
status: "validating",
|
|
1251
|
-
routeId,
|
|
1252
|
-
options
|
|
1253
|
-
});
|
|
1254
|
-
const signer = await getEvmSigner?.(tx?.evmTx?.chainId ?? "");
|
|
1255
|
-
if (!signer) {
|
|
1256
|
-
throw new Error(
|
|
1257
|
-
`failed to get signer for chain ${tx?.evmTx?.chainId}`
|
|
1258
|
-
);
|
|
1259
|
-
}
|
|
1260
|
-
try {
|
|
1261
|
-
const res = await validateEvmGasBalance({
|
|
1262
|
-
tx: tx.evmTx,
|
|
1263
|
-
signer,
|
|
1264
|
-
getFallbackGasAmount,
|
|
1265
|
-
useUnlimitedApproval: options?.useUnlimitedApproval,
|
|
1266
|
-
bypassApprovalCheck: options?.bypassApprovalCheck
|
|
1267
|
-
});
|
|
1268
|
-
return res;
|
|
1269
|
-
} catch (e) {
|
|
1270
|
-
const error = e;
|
|
1271
|
-
return {
|
|
1272
|
-
error: error.message,
|
|
1273
|
-
asset: null,
|
|
1274
|
-
fee: null
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
if ("svmTx" in tx && !disabledChainIds?.includes(tx?.svmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.svmTx?.chainId ?? ""))) {
|
|
1279
|
-
onValidateGasBalance?.({
|
|
1280
|
-
status: "pending"
|
|
1281
|
-
});
|
|
1282
|
-
updateRouteDetails({
|
|
1283
|
-
status: "validating",
|
|
1284
|
-
routeId,
|
|
1285
|
-
options
|
|
1286
|
-
});
|
|
1287
|
-
try {
|
|
1288
|
-
const res = await validateSvmGasBalance({
|
|
1289
|
-
tx: tx.svmTx,
|
|
1290
|
-
simulate,
|
|
1291
|
-
feePayerAddress: options.svmFeePayer?.address
|
|
1292
|
-
});
|
|
1293
|
-
return res;
|
|
1294
|
-
} catch (e) {
|
|
1295
|
-
const error = e;
|
|
1296
|
-
return {
|
|
1297
|
-
error: error.message,
|
|
1298
|
-
asset: null,
|
|
1299
|
-
fee: null
|
|
1300
|
-
};
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
})
|
|
1304
|
-
);
|
|
1305
|
-
if (validateResult.filter(Boolean).length === 0) {
|
|
1306
|
-
return;
|
|
1307
|
-
}
|
|
1308
|
-
const txError = validateResult.find((res) => res && res?.error !== null);
|
|
1309
|
-
if (txError) {
|
|
1310
|
-
onValidateGasBalance?.({
|
|
1311
|
-
status: "error"
|
|
1312
|
-
});
|
|
1313
|
-
ClientState.validateGasResults = validateResult;
|
|
1314
|
-
throw new Error(`${txError.error}`);
|
|
1315
|
-
}
|
|
1316
|
-
onValidateGasBalance?.({
|
|
1317
|
-
status: "completed"
|
|
1318
|
-
});
|
|
1319
|
-
ClientState.validateGasResults = validateResult;
|
|
1320
|
-
};
|
|
1321
|
-
|
|
1322
|
-
// src/private-functions/getChainIdsFromTxs.ts
|
|
1323
|
-
var getChainIdsFromTxs = (txs) => {
|
|
1324
|
-
return txs.map((tx) => {
|
|
1325
|
-
if ("cosmosTx" in tx) {
|
|
1326
|
-
return {
|
|
1327
|
-
chainType: "cosmos" /* Cosmos */,
|
|
1328
|
-
chainId: tx.cosmosTx?.chainId
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
if ("svmTx" in tx) {
|
|
1332
|
-
return {
|
|
1333
|
-
chainType: "svm" /* Svm */,
|
|
1334
|
-
chainId: tx.svmTx?.chainId
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
if ("evmTx" in tx) {
|
|
1338
|
-
return {
|
|
1339
|
-
chainType: "evm" /* Evm */,
|
|
1340
|
-
chainId: tx.evmTx?.chainId
|
|
1341
|
-
};
|
|
1342
|
-
}
|
|
1343
|
-
});
|
|
1344
|
-
};
|
|
1345
|
-
|
|
1346
|
-
// src/private-functions/executeTransactions.ts
|
|
1347
|
-
var executeTransactions = async (options) => {
|
|
1348
|
-
const {
|
|
1349
|
-
txs,
|
|
1350
|
-
onTransactionBroadcast,
|
|
1351
|
-
simulate = true,
|
|
1352
|
-
batchSimulate = true,
|
|
1353
|
-
getFallbackGasAmount = getDefaultFallbackGasAmount,
|
|
1354
|
-
getCosmosSigner,
|
|
1355
|
-
getEvmSigner,
|
|
1356
|
-
onValidateGasBalance,
|
|
1357
|
-
trackTxPollingOptions,
|
|
1358
|
-
batchSignTxs = true,
|
|
1359
|
-
routeId,
|
|
1360
|
-
isMultiRoutes
|
|
1361
|
-
} = options;
|
|
1362
|
-
if (txs === void 0) {
|
|
1363
|
-
throw new Error(
|
|
1364
|
-
"executeTransactions error: txs is undefined in executeTransactions"
|
|
1365
|
-
);
|
|
1366
|
-
}
|
|
1367
|
-
const chainIds = getChainIdsFromTxs(txs);
|
|
1368
|
-
const transactionDetails = txs.map((tx) => {
|
|
1369
|
-
if ("cosmosTx" in tx) {
|
|
1370
|
-
return { chainId: tx.cosmosTx?.chainId, chainType: "cosmos" /* Cosmos */ };
|
|
1371
|
-
} else if ("evmTx" in tx) {
|
|
1372
|
-
return { chainId: tx.evmTx?.chainId, chainType: "evm" /* Evm */ };
|
|
1373
|
-
} else if ("svmTx" in tx) {
|
|
1374
|
-
return { chainId: tx.svmTx?.chainId, chainType: "svm" /* Svm */ };
|
|
1375
|
-
} else {
|
|
1376
|
-
throw new Error("executeRoute error: invalid message type");
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
updateRouteDetails({
|
|
1380
|
-
transactionDetails,
|
|
1381
|
-
routeId,
|
|
1382
|
-
options
|
|
1383
|
-
});
|
|
1384
|
-
const isGasStationSourceEVM = chainIds.find((item, i, array) => {
|
|
1385
|
-
return GAS_STATION_CHAIN_IDS.includes(item?.chainId ?? "") && array[i - 1]?.chainType === "evm" /* Evm */;
|
|
1386
|
-
});
|
|
1387
|
-
ClientState.validateGasResults = void 0;
|
|
1388
|
-
const validateChainIds = !batchSimulate ? chainIds.map((x) => x?.chainId ?? "") : isGasStationSourceEVM ? GAS_STATION_CHAIN_IDS : [];
|
|
1389
|
-
await validateGasBalances({
|
|
1390
|
-
txs,
|
|
1391
|
-
getFallbackGasAmount,
|
|
1392
|
-
getCosmosSigner,
|
|
1393
|
-
getEvmSigner,
|
|
1394
|
-
onValidateGasBalance,
|
|
1395
|
-
simulate,
|
|
1396
|
-
disabledChainIds: validateChainIds,
|
|
1397
|
-
getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
|
|
1398
|
-
options,
|
|
1399
|
-
routeId,
|
|
1400
|
-
isMultiRoutes
|
|
1401
|
-
});
|
|
1402
|
-
const validateEnabledChainIds = async (chainId) => {
|
|
1403
|
-
await validateGasBalances({
|
|
1404
|
-
txs,
|
|
1405
|
-
getFallbackGasAmount,
|
|
1406
|
-
getCosmosSigner,
|
|
1407
|
-
getEvmSigner,
|
|
1408
|
-
onValidateGasBalance,
|
|
1409
|
-
simulate,
|
|
1410
|
-
enabledChainIds: !batchSimulate ? [chainId] : validateChainIds,
|
|
1411
|
-
getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
|
|
1412
|
-
options,
|
|
1413
|
-
routeId,
|
|
1414
|
-
isMultiRoutes
|
|
1415
|
-
});
|
|
1416
|
-
};
|
|
1417
|
-
let signedTxs = [];
|
|
1418
|
-
if (batchSignTxs) {
|
|
1419
|
-
for (let i = 0; i < txs.length; i++) {
|
|
1420
|
-
const tx = txs[i];
|
|
1421
|
-
if (!tx) {
|
|
1422
|
-
throw new Error(`executeRoute error: invalid message at index ${i}`);
|
|
1423
|
-
}
|
|
1424
|
-
if ("cosmosTx" in tx) {
|
|
1425
|
-
await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
|
|
1426
|
-
const isAllowedToBatchSignTxsUpfront = await (async () => {
|
|
1427
|
-
try {
|
|
1428
|
-
const currentUserAddress = options.userAddresses.find(
|
|
1429
|
-
(x) => x.chainId === tx.cosmosTx?.chainId
|
|
1430
|
-
)?.address;
|
|
1431
|
-
if (!currentUserAddress) {
|
|
1432
|
-
return false;
|
|
1433
|
-
}
|
|
1434
|
-
const { accountNumber } = await getAccountNumberAndSequence(
|
|
1435
|
-
currentUserAddress,
|
|
1436
|
-
tx.cosmosTx?.chainId
|
|
1437
|
-
);
|
|
1438
|
-
if (accountNumber) {
|
|
1439
|
-
return true;
|
|
1440
|
-
}
|
|
1441
|
-
return false;
|
|
1442
|
-
} catch (_error) {
|
|
1443
|
-
return false;
|
|
1444
|
-
}
|
|
1445
|
-
})();
|
|
1446
|
-
if (!isAllowedToBatchSignTxsUpfront) {
|
|
1447
|
-
continue;
|
|
1448
|
-
}
|
|
1449
|
-
const signedTx = await signCosmosTransaction({
|
|
1450
|
-
tx,
|
|
1451
|
-
options,
|
|
1452
|
-
index: i,
|
|
1453
|
-
routeId
|
|
1454
|
-
});
|
|
1455
|
-
signedTxs.push({
|
|
1456
|
-
index: i,
|
|
1457
|
-
chainId: tx.cosmosTx?.chainId ?? "",
|
|
1458
|
-
tx: signedTx,
|
|
1459
|
-
chainType: "cosmos" /* Cosmos */
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
if ("svmTx" in tx) {
|
|
1463
|
-
await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
|
|
1464
|
-
const signedTx = await signSvmTransaction({
|
|
1465
|
-
tx,
|
|
1466
|
-
options,
|
|
1467
|
-
index: i,
|
|
1468
|
-
routeId
|
|
1469
|
-
});
|
|
1470
|
-
if (!signedTx) {
|
|
1471
|
-
throw new Error(`executeRoute error: signedTx is undefined`);
|
|
1472
|
-
}
|
|
1473
|
-
signedTxs.push({
|
|
1474
|
-
index: i,
|
|
1475
|
-
chainId: tx.svmTx?.chainId ?? "",
|
|
1476
|
-
tx: signedTx.toString("base64"),
|
|
1477
|
-
chainType: "svm" /* Svm */
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
const executeTransaction = async (index) => {
|
|
1483
|
-
const tx = txs[index];
|
|
1484
|
-
if (!tx) {
|
|
1485
|
-
throw new Error(`executeRoute error: invalid message at index ${index}`);
|
|
1486
|
-
}
|
|
1487
|
-
let txResult;
|
|
1488
|
-
const txSigned = signedTxs.find((item) => item.index === index);
|
|
1489
|
-
if (txSigned) {
|
|
1490
|
-
const txResponse = await submitTransaction({
|
|
1491
|
-
chainId: txSigned.chainId,
|
|
1492
|
-
tx: txSigned.tx
|
|
1493
|
-
});
|
|
1494
|
-
txResult = {
|
|
1495
|
-
chainId: txSigned.chainId,
|
|
1496
|
-
txHash: txResponse?.txHash ?? "",
|
|
1497
|
-
explorerLink: txResponse?.explorerLink ?? ""
|
|
1498
|
-
};
|
|
1499
|
-
} else {
|
|
1500
|
-
if ("cosmosTx" in tx) {
|
|
1501
|
-
await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
|
|
1502
|
-
txResult = await executeCosmosTransaction({
|
|
1503
|
-
tx,
|
|
1504
|
-
options,
|
|
1505
|
-
index,
|
|
1506
|
-
routeId
|
|
1507
|
-
});
|
|
1508
|
-
} else if ("evmTx" in tx) {
|
|
1509
|
-
await validateEnabledChainIds(tx.evmTx?.chainId ?? "");
|
|
1510
|
-
const txResponse = await executeEvmTransaction(
|
|
1511
|
-
tx,
|
|
1512
|
-
options,
|
|
1513
|
-
index,
|
|
1514
|
-
routeId
|
|
1515
|
-
);
|
|
1516
|
-
txResult = {
|
|
1517
|
-
chainId: tx?.evmTx?.chainId ?? "",
|
|
1518
|
-
txHash: txResponse.transactionHash
|
|
1519
|
-
};
|
|
1520
|
-
} else if ("svmTx" in tx) {
|
|
1521
|
-
await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
|
|
1522
|
-
txResult = await executeSvmTransaction(tx, options, index, routeId);
|
|
1523
|
-
} else {
|
|
1524
|
-
throw new Error("executeRoute error: invalid message type");
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
await onTransactionBroadcast?.({ ...txResult });
|
|
1528
|
-
return txResult;
|
|
1529
|
-
};
|
|
1530
|
-
return {
|
|
1531
|
-
transactionDetails,
|
|
1532
|
-
executeTransaction
|
|
1533
|
-
};
|
|
1534
|
-
};
|
|
1535
|
-
var EVM_GAS_AMOUNT = 15e4;
|
|
1536
|
-
var COSMOS_GAS_AMOUNT = {
|
|
1537
|
-
DEFAULT: 3e5,
|
|
1538
|
-
SWAP: 28e5,
|
|
1539
|
-
CARBON: 1e6
|
|
1540
|
-
};
|
|
1541
|
-
var getDefaultFallbackGasAmount = async (chainId, chainType) => {
|
|
1542
|
-
if (chainType === "evm" /* Evm */) {
|
|
1543
|
-
return EVM_GAS_AMOUNT;
|
|
1544
|
-
}
|
|
1545
|
-
if (chainType !== "cosmos" /* Cosmos */) return void 0;
|
|
1546
|
-
const venuesResult = await venues();
|
|
1547
|
-
const isSwapChain = venuesResult?.some(
|
|
1548
|
-
(venue) => venue.chainId === chainId
|
|
1549
|
-
) ?? false;
|
|
1550
|
-
const defaultGasAmount = Math.ceil(
|
|
1551
|
-
isSwapChain ? COSMOS_GAS_AMOUNT.SWAP : COSMOS_GAS_AMOUNT.DEFAULT
|
|
1552
|
-
);
|
|
1553
|
-
if (chainId === "carbon-1") {
|
|
1554
|
-
return COSMOS_GAS_AMOUNT.CARBON;
|
|
1555
|
-
}
|
|
1556
|
-
return defaultGasAmount;
|
|
1557
|
-
};
|
|
1558
|
-
var validateUserAddresses = async (userAddresses) => {
|
|
1559
|
-
const chains3 = await ClientState.getSkipChains();
|
|
1560
|
-
const validations = userAddresses.map((userAddress) => {
|
|
1561
|
-
const chain = chains3.find((chain2) => chain2.chainId === userAddress.chainId);
|
|
1562
|
-
switch (chain?.chainType) {
|
|
1563
|
-
case "cosmos" /* Cosmos */:
|
|
1564
|
-
try {
|
|
1565
|
-
if (chain.chainId?.includes("penumbra")) {
|
|
1566
|
-
try {
|
|
1567
|
-
return chain.bech32Prefix === bech32m.decode(userAddress.address, 143)?.prefix;
|
|
1568
|
-
} catch {
|
|
1569
|
-
return ["penumbracompat1", "tpenumbra"].includes(
|
|
1570
|
-
bech32.decode(userAddress.address, 1023).prefix
|
|
1571
|
-
);
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
return chain.bech32Prefix === bech32.decode(userAddress.address, 1023).prefix;
|
|
1575
|
-
} catch {
|
|
1576
|
-
return false;
|
|
1577
|
-
}
|
|
1578
|
-
case "evm" /* Evm */:
|
|
1579
|
-
try {
|
|
1580
|
-
return isAddress(userAddress.address);
|
|
1581
|
-
} catch (_error) {
|
|
1582
|
-
return false;
|
|
1583
|
-
}
|
|
1584
|
-
case "svm" /* Svm */:
|
|
1585
|
-
try {
|
|
1586
|
-
const publicKey = new PublicKey(userAddress.address);
|
|
1587
|
-
return PublicKey.isOnCurve(publicKey);
|
|
1588
|
-
} catch (_error) {
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
default:
|
|
1592
|
-
return false;
|
|
1593
|
-
}
|
|
1594
|
-
});
|
|
1595
|
-
return validations.every((validation) => validation);
|
|
1596
|
-
};
|
|
1597
|
-
var createValidAddressList = async ({
|
|
1598
|
-
userAddresses,
|
|
1599
|
-
route: route2
|
|
1600
|
-
}) => {
|
|
1601
|
-
let addressList = [];
|
|
1602
|
-
userAddresses.forEach((userAddress, index) => {
|
|
1603
|
-
const requiredChainAddress = route2.requiredChainAddresses[index];
|
|
1604
|
-
if (requiredChainAddress === userAddress?.chainId) {
|
|
1605
|
-
addressList.push(userAddress.address);
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
if (addressList.length !== route2.requiredChainAddresses.length) {
|
|
1609
|
-
addressList = userAddresses.map((x) => x.address);
|
|
1610
|
-
}
|
|
1611
|
-
const validLength = addressList.length === route2.requiredChainAddresses.length || addressList.length === route2.chainIds?.length;
|
|
1612
|
-
if (!validLength) {
|
|
1613
|
-
throw new Error("createValidAddressList error: invalid address list");
|
|
1614
|
-
}
|
|
1615
|
-
const isUserAddressesValid = await validateUserAddresses(userAddresses);
|
|
1616
|
-
if (!isUserAddressesValid) {
|
|
1617
|
-
throw new Error("createValidAddressList error: invalid user addresses");
|
|
1618
|
-
}
|
|
1619
|
-
return addressList;
|
|
1620
|
-
};
|
|
1621
|
-
|
|
1622
|
-
// src/public-functions/executeRoute.ts
|
|
1623
|
-
var executeRoute = async (options) => {
|
|
1624
|
-
const { route: route2, userAddresses, appendCosmosMsgs, timeoutSeconds } = options;
|
|
1625
|
-
const { id: routeId } = updateRouteDetails({
|
|
1626
|
-
status: "unconfirmed",
|
|
1627
|
-
options
|
|
1628
|
-
});
|
|
1629
|
-
const addressList = await createValidAddressList({
|
|
1630
|
-
userAddresses,
|
|
1631
|
-
route: route2
|
|
1632
|
-
});
|
|
1633
|
-
const response = await messages({
|
|
1634
|
-
timeoutSeconds,
|
|
1635
|
-
amountIn: route2?.amountIn,
|
|
1636
|
-
amountOut: route2.estimatedAmountOut || "0",
|
|
1637
|
-
sourceAssetChainId: route2?.sourceAssetChainId,
|
|
1638
|
-
sourceAssetDenom: route2?.sourceAssetDenom,
|
|
1639
|
-
destAssetChainId: route2?.destAssetChainId,
|
|
1640
|
-
destAssetDenom: route2?.destAssetDenom,
|
|
1641
|
-
operations: route2?.operations,
|
|
1642
|
-
addressList,
|
|
1643
|
-
slippageTolerancePercent: options.slippageTolerancePercent || "1",
|
|
1644
|
-
chainIdsToAffiliates: ApiState.chainIdsToAffiliates,
|
|
1645
|
-
postRouteHandler: options.postRouteHandler,
|
|
1646
|
-
feePayerAddress: options.svmFeePayer?.address
|
|
1647
|
-
});
|
|
1648
|
-
if (appendCosmosMsgs) {
|
|
1649
|
-
Object.entries(appendCosmosMsgs).forEach(([chainId, msgs]) => {
|
|
1650
|
-
const txIndex = response?.txs?.findIndex(
|
|
1651
|
-
(tx2) => "cosmosTx" in tx2 && tx2.cosmosTx.chainId === chainId
|
|
1652
|
-
);
|
|
1653
|
-
if (txIndex === void 0 || txIndex === -1) return;
|
|
1654
|
-
const tx = response?.txs?.[txIndex];
|
|
1655
|
-
if (tx && "cosmosTx" in tx) {
|
|
1656
|
-
tx.cosmosTx.msgs?.unshift(...msgs);
|
|
1657
|
-
}
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
const { transactionDetails, executeTransaction } = await executeTransactions({ ...options, routeId, txs: response?.txs });
|
|
1661
|
-
await executeAndSubscribeToRouteStatus({
|
|
1662
|
-
transactionDetails,
|
|
1663
|
-
executeTransaction,
|
|
1664
|
-
routeId,
|
|
1665
|
-
options
|
|
1666
|
-
});
|
|
1667
|
-
};
|
|
1668
|
-
|
|
1669
|
-
// src/public-functions/executeMultipleRoutes.ts
|
|
1670
|
-
var executeMultipleRoutes = async (options) => {
|
|
1671
|
-
const {
|
|
1672
|
-
route: route2,
|
|
1673
|
-
userAddresses,
|
|
1674
|
-
appendCosmosMsgs,
|
|
1675
|
-
postRouteHandler,
|
|
1676
|
-
slippageTolerancePercent,
|
|
1677
|
-
...restOptions
|
|
1678
|
-
} = options;
|
|
1679
|
-
const addressList = {};
|
|
1680
|
-
for (const [routeKey, routeValue] of Object.entries(route2)) {
|
|
1681
|
-
const _userAddresses = userAddresses[routeKey];
|
|
1682
|
-
if (_userAddresses === void 0) {
|
|
1683
|
-
throw new Error(
|
|
1684
|
-
`executeMultipleRoutes error: no user addresses found for route: ${routeKey}`
|
|
1685
|
-
);
|
|
1686
|
-
}
|
|
1687
|
-
const routeAddressList = await createValidAddressList({
|
|
1688
|
-
userAddresses: _userAddresses,
|
|
1689
|
-
route: routeValue
|
|
1690
|
-
});
|
|
1691
|
-
addressList[routeKey] = routeAddressList;
|
|
1692
|
-
}
|
|
1693
|
-
const msgsResponses = await Promise.all(
|
|
1694
|
-
Object.entries(route2).map(async ([routeKey, routeValue]) => {
|
|
1695
|
-
const routeAddressList = addressList[routeKey];
|
|
1696
|
-
if (routeAddressList === void 0) {
|
|
1697
|
-
throw new Error(
|
|
1698
|
-
`executeMultipleRoutes error: address list not found for route ${routeKey}`
|
|
1699
|
-
);
|
|
1700
|
-
}
|
|
1701
|
-
return await messages({
|
|
1702
|
-
timeoutSeconds: options.timeoutSeconds,
|
|
1703
|
-
amountIn: routeValue?.amountIn,
|
|
1704
|
-
amountOut: routeValue.estimatedAmountOut || "0",
|
|
1705
|
-
sourceAssetChainId: routeValue?.sourceAssetChainId,
|
|
1706
|
-
sourceAssetDenom: routeValue?.sourceAssetDenom,
|
|
1707
|
-
destAssetChainId: routeValue?.destAssetChainId,
|
|
1708
|
-
destAssetDenom: routeValue?.destAssetDenom,
|
|
1709
|
-
operations: routeValue?.operations,
|
|
1710
|
-
addressList: routeAddressList,
|
|
1711
|
-
slippageTolerancePercent: slippageTolerancePercent?.[routeKey] || "1",
|
|
1712
|
-
chainIdsToAffiliates: ApiState.chainIdsToAffiliates,
|
|
1713
|
-
postRouteHandler: postRouteHandler?.[routeKey],
|
|
1714
|
-
feePayerAddress: options.svmFeePayer?.address
|
|
1715
|
-
});
|
|
1716
|
-
})
|
|
1717
|
-
);
|
|
1718
|
-
let msgsRecord = {};
|
|
1719
|
-
msgsResponses.forEach((msg, index2) => {
|
|
1720
|
-
const routeKey = Object.keys(route2)[index2];
|
|
1721
|
-
if (!routeKey) {
|
|
1722
|
-
throw new Error(
|
|
1723
|
-
`executeMultipleRoutes error: route key not found for index ${index2}`
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
const addedCosmosMsgs = appendCosmosMsgs?.[routeKey];
|
|
1727
|
-
if (addedCosmosMsgs) {
|
|
1728
|
-
Object.entries(addedCosmosMsgs).forEach(([chainId, msgs]) => {
|
|
1729
|
-
const txIndex = msg?.txs?.findIndex(
|
|
1730
|
-
(tx2) => "cosmosTx" in tx2 && tx2.cosmosTx.chainId === chainId
|
|
1731
|
-
);
|
|
1732
|
-
if (txIndex === void 0 || txIndex === -1) return;
|
|
1733
|
-
const tx = msg?.txs?.[txIndex];
|
|
1734
|
-
if (tx && "cosmosTx" in tx) {
|
|
1735
|
-
tx.cosmosTx.msgs?.unshift(...msgs);
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
msgsRecord[routeKey] = msg;
|
|
1740
|
-
});
|
|
1741
|
-
let transferIndexToRouteKey = void 0;
|
|
1742
|
-
const cosmosTxIndex0Map = /* @__PURE__ */ new Map();
|
|
1743
|
-
let transferIndex = 0;
|
|
1744
|
-
for (const [routeKey, msgs] of Object.entries(msgsRecord)) {
|
|
1745
|
-
const firstTx = msgs?.txs?.[0];
|
|
1746
|
-
if (firstTx && "cosmosTx" in firstTx) {
|
|
1747
|
-
const { chainId, msgs: firstTxMsgs } = firstTx.cosmosTx;
|
|
1748
|
-
if (!transferIndexToRouteKey) {
|
|
1749
|
-
transferIndexToRouteKey = {};
|
|
1750
|
-
}
|
|
1751
|
-
transferIndexToRouteKey[transferIndex] = routeKey;
|
|
1752
|
-
transferIndex++;
|
|
1753
|
-
if (!cosmosTxIndex0Map.has(chainId)) {
|
|
1754
|
-
cosmosTxIndex0Map.set(chainId, {
|
|
1755
|
-
routeKey,
|
|
1756
|
-
firstCosmosTx: firstTx.cosmosTx
|
|
1757
|
-
});
|
|
1758
|
-
} else {
|
|
1759
|
-
const existing = cosmosTxIndex0Map.get(chainId);
|
|
1760
|
-
if (existing && firstTxMsgs) {
|
|
1761
|
-
const modifyTarget = msgsRecord[existing.routeKey]?.txs?.[0];
|
|
1762
|
-
if (modifyTarget && "cosmosTx" in modifyTarget) {
|
|
1763
|
-
modifyTarget.cosmosTx.msgs?.push(...firstTxMsgs);
|
|
1764
|
-
msgsRecord[routeKey]?.txs?.shift();
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
Object.entries(msgsRecord).forEach(([routeKey, msgs]) => {
|
|
1771
|
-
if (msgs?.txs?.length === 0) {
|
|
1772
|
-
delete msgsRecord[routeKey];
|
|
1773
|
-
}
|
|
1774
|
-
});
|
|
1775
|
-
let mainRouteId = void 0;
|
|
1776
|
-
let msgsRecordIndexToRouteId = {};
|
|
1777
|
-
let index = 0;
|
|
1778
|
-
const transactionDetailsList = {};
|
|
1779
|
-
const executeTransactionList = {};
|
|
1780
|
-
const mergedMainAndSecondaryRoutes = Object.entries(msgsRecord).length !== Object.entries(route2).length;
|
|
1781
|
-
for (const [routeKey, msgsResponse] of Object.entries(msgsRecord)) {
|
|
1782
|
-
const { id: routeId } = updateRouteDetails({
|
|
1783
|
-
status: "unconfirmed",
|
|
1784
|
-
options: {
|
|
1785
|
-
route: route2[routeKey],
|
|
1786
|
-
...restOptions
|
|
1787
|
-
},
|
|
1788
|
-
mainRouteId,
|
|
1789
|
-
transferIndexToRouteKey
|
|
1790
|
-
});
|
|
1791
|
-
msgsRecordIndexToRouteId[index] = routeId;
|
|
1792
|
-
if (routeKey === "mainRoute") {
|
|
1793
|
-
mainRouteId = routeId;
|
|
1794
|
-
}
|
|
1795
|
-
const { transactionDetails, executeTransaction: _executeTransaction } = await executeTransactions({
|
|
1796
|
-
...restOptions,
|
|
1797
|
-
routeId,
|
|
1798
|
-
txs: msgsResponse?.txs,
|
|
1799
|
-
route: route2[routeKey],
|
|
1800
|
-
userAddresses: userAddresses[routeKey],
|
|
1801
|
-
isMultiRoutes: true
|
|
1802
|
-
});
|
|
1803
|
-
const executeTransaction = async (index2) => {
|
|
1804
|
-
const txResult = await _executeTransaction(index2);
|
|
1805
|
-
if (routeKey !== "mainRoute" || mergedMainAndSecondaryRoutes) {
|
|
1806
|
-
const relatedRoutes = Object.entries(route2).filter(([key]) => key !== "mainRoute").map(([key, route3]) => ({ route: route3, routeKey: key, status: "pending" }));
|
|
1807
|
-
updateRouteDetails({
|
|
1808
|
-
options: {
|
|
1809
|
-
route: route2[routeKey],
|
|
1810
|
-
...restOptions
|
|
1811
|
-
},
|
|
1812
|
-
routeId: mainRouteId,
|
|
1813
|
-
transferIndexToRouteKey,
|
|
1814
|
-
relatedRoutes
|
|
1815
|
-
});
|
|
1816
|
-
}
|
|
1817
|
-
return txResult;
|
|
1818
|
-
};
|
|
1819
|
-
if (transactionDetails[0]?.chainType === "evm" /* Evm */) {
|
|
1820
|
-
for (const [index2, transactionDetail] of transactionDetails.entries()) {
|
|
1821
|
-
const txResult = await executeTransaction(index2);
|
|
1822
|
-
if (txResult.txHash) {
|
|
1823
|
-
const trackResponse = await trackTransaction({
|
|
1824
|
-
chainId: transactionDetail.chainId,
|
|
1825
|
-
txHash: txResult.txHash,
|
|
1826
|
-
...options.trackTxPollingOptions
|
|
1827
|
-
});
|
|
1828
|
-
await options?.onTransactionTracked?.({
|
|
1829
|
-
txHash: txResult.txHash,
|
|
1830
|
-
chainId: transactionDetail.chainId,
|
|
1831
|
-
explorerLink: trackResponse.explorerLink
|
|
1832
|
-
});
|
|
1833
|
-
transactionDetail.txHash = txResult.txHash;
|
|
1834
|
-
transactionDetail.explorerLink = trackResponse.explorerLink;
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
} else {
|
|
1838
|
-
executeTransactionList[index] = executeTransaction;
|
|
1839
|
-
}
|
|
1840
|
-
transactionDetailsList[index] = transactionDetails;
|
|
1841
|
-
index++;
|
|
1842
|
-
}
|
|
1843
|
-
await Promise.all(
|
|
1844
|
-
Object.entries(msgsRecord).map(([routeKey, msgsResponse], index2) => {
|
|
1845
|
-
return executeAndSubscribeToRouteStatus({
|
|
1846
|
-
transactionDetails: transactionDetailsList[index2],
|
|
1847
|
-
executeTransaction: executeTransactionList[index2],
|
|
1848
|
-
routeId: msgsRecordIndexToRouteId[index2],
|
|
1849
|
-
options: {
|
|
1850
|
-
route: route2[routeKey],
|
|
1851
|
-
userAddresses: userAddresses[routeKey],
|
|
1852
|
-
...restOptions,
|
|
1853
|
-
onRouteStatusUpdated: (routeStatus) => {
|
|
1854
|
-
const relatedRoutes = Object.entries(route2).filter(([key]) => key !== "mainRoute").map(([key, route3]) => ({ route: route3, routeKey: key, status: routeStatus.status }));
|
|
1855
|
-
if (routeKey !== "mainRoute") {
|
|
1856
|
-
updateRouteDetails({
|
|
1857
|
-
options: {
|
|
1858
|
-
route: route2[routeKey],
|
|
1859
|
-
...restOptions
|
|
1860
|
-
},
|
|
1861
|
-
routeId: mainRouteId,
|
|
1862
|
-
transferIndexToRouteKey,
|
|
1863
|
-
relatedRoutes
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
options.onRouteStatusUpdated?.(routeStatus);
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
});
|
|
1870
|
-
})
|
|
1871
|
-
);
|
|
1872
|
-
};
|
|
1873
|
-
|
|
1874
|
-
// src/utils/coingecko.ts
|
|
1875
|
-
var getUsdPrice = async (coingeckoId) => {
|
|
1876
|
-
try {
|
|
1877
|
-
const response = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${coingeckoId}&vs_currencies=usd`);
|
|
1878
|
-
const data = await response.json();
|
|
1879
|
-
return data?.[coingeckoId]?.usd;
|
|
1880
|
-
} catch (error) {
|
|
1881
|
-
return void 0;
|
|
1882
|
-
}
|
|
1883
|
-
};
|
|
1884
|
-
|
|
1885
|
-
// src/utils/numbers.ts
|
|
1886
|
-
var convertHumanReadableAmountToCryptoAmount = (humanReadableAmount, decimals) => {
|
|
1887
|
-
const cryptoAmount = new bignumber_default(humanReadableAmount).shiftedBy(decimals);
|
|
1888
|
-
return cryptoAmount.toFixed(0);
|
|
1889
|
-
};
|
|
1890
|
-
var formaTestnet = defineChain({
|
|
1891
|
-
id: 984123,
|
|
1892
|
-
name: "Forma Testnet",
|
|
1893
|
-
nativeCurrency: {
|
|
1894
|
-
name: "TIA",
|
|
1895
|
-
symbol: "TIA",
|
|
1896
|
-
decimals: 18
|
|
1897
|
-
},
|
|
1898
|
-
rpcUrls: {
|
|
1899
|
-
default: {
|
|
1900
|
-
http: ["https://rpc.sketchpad-1.forma.art"]
|
|
1901
|
-
}
|
|
1902
|
-
},
|
|
1903
|
-
blockExplorers: {
|
|
1904
|
-
default: {
|
|
1905
|
-
name: "Forma Explorer",
|
|
1906
|
-
url: "https://explorer.sketchpad-1.forma.art"
|
|
1907
|
-
}
|
|
1908
|
-
},
|
|
1909
|
-
testnet: true
|
|
1910
|
-
});
|
|
1911
|
-
var evmChains = [
|
|
1912
|
-
arbitrum,
|
|
1913
|
-
avalanche,
|
|
1914
|
-
base,
|
|
1915
|
-
bsc,
|
|
1916
|
-
celo,
|
|
1917
|
-
fantom,
|
|
1918
|
-
filecoin,
|
|
1919
|
-
kava,
|
|
1920
|
-
linea,
|
|
1921
|
-
mainnet,
|
|
1922
|
-
manta,
|
|
1923
|
-
moonbeam,
|
|
1924
|
-
optimism,
|
|
1925
|
-
polygon,
|
|
1926
|
-
polygonMumbai,
|
|
1927
|
-
sepolia,
|
|
1928
|
-
avalancheFuji,
|
|
1929
|
-
baseSepolia,
|
|
1930
|
-
optimismSepolia,
|
|
1931
|
-
arbitrumSepolia,
|
|
1932
|
-
blast,
|
|
1933
|
-
blastSepolia,
|
|
1934
|
-
forma,
|
|
1935
|
-
formaTestnet,
|
|
1936
|
-
sei,
|
|
1937
|
-
bscTestnet,
|
|
1938
|
-
fantomTestnet,
|
|
1939
|
-
kavaTestnet,
|
|
1940
|
-
lineaSepolia,
|
|
1941
|
-
mantaSepoliaTestnet
|
|
1942
|
-
];
|
|
1943
|
-
|
|
1944
|
-
// src/utils/array.ts
|
|
1945
|
-
function isSubset(arrayA, arrayB) {
|
|
1946
|
-
const setA = new Set(arrayA);
|
|
1947
|
-
return arrayB.every((item) => setA.has(item));
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
// src/public-functions/getRouteWithGasOnReceive.ts
|
|
1951
|
-
var GAS_ON_RECEIVE_AMOUNT_USD = {
|
|
1952
|
-
["cosmos" /* Cosmos */]: 0.1,
|
|
1953
|
-
evm_l2: 2
|
|
1954
|
-
};
|
|
1955
|
-
var DISABLED_SOURCE_CHAINIDS = ["1", "11155111"];
|
|
1956
|
-
var DISABLED_DESTINATION_CHAINIDS = ["solana", "solana-devnet"];
|
|
1957
|
-
var getRouteWithGasOnReceive = async (props) => {
|
|
1958
|
-
const originalRoute = props.routeResponse;
|
|
1959
|
-
try {
|
|
1960
|
-
if (DISABLED_SOURCE_CHAINIDS.includes(originalRoute.sourceAssetChainId)) {
|
|
1961
|
-
throw new Error(
|
|
1962
|
-
`Routes from ${originalRoute.sourceAssetChainId} are not supported`
|
|
1963
|
-
);
|
|
1964
|
-
}
|
|
1965
|
-
if (DISABLED_DESTINATION_CHAINIDS.includes(originalRoute.destAssetChainId)) {
|
|
1966
|
-
throw new Error(
|
|
1967
|
-
`Routes to ${originalRoute.destAssetChainId} are not supported`
|
|
1968
|
-
);
|
|
1969
|
-
}
|
|
1970
|
-
const skipChains = ClientState.skipChains ? ClientState.skipChains : await chains({
|
|
1971
|
-
includeEvm: true,
|
|
1972
|
-
includeSvm: true,
|
|
1973
|
-
chainIds: [
|
|
1974
|
-
originalRoute.sourceAssetChainId,
|
|
1975
|
-
originalRoute.destAssetChainId
|
|
1976
|
-
],
|
|
1977
|
-
onlyTestnets: props.onlyTestnets
|
|
1978
|
-
});
|
|
1979
|
-
const skipAssets = ClientState.skipAssets ? ClientState.skipAssets : await assets({
|
|
1980
|
-
chainIds: [
|
|
1981
|
-
originalRoute.sourceAssetChainId,
|
|
1982
|
-
originalRoute.destAssetChainId
|
|
1983
|
-
],
|
|
1984
|
-
includeEvmAssets: true,
|
|
1985
|
-
includeSvmAssets: true,
|
|
1986
|
-
onlyTestnets: props.onlyTestnets
|
|
1987
|
-
});
|
|
1988
|
-
const destinationChain = skipChains?.find(
|
|
1989
|
-
(chain) => chain.chainId === originalRoute.destAssetChainId
|
|
1990
|
-
);
|
|
1991
|
-
if (destinationChain?.feeAssets.map((i) => i.denom).includes(originalRoute.destAssetDenom)) {
|
|
1992
|
-
throw new Error(
|
|
1993
|
-
"Destination asset is already a fee asset on the destination chain"
|
|
1994
|
-
);
|
|
1995
|
-
}
|
|
1996
|
-
const gasOnReceiveAmount = await getGasOnReceiveAmount({
|
|
1997
|
-
destinationChain,
|
|
1998
|
-
skipAssets,
|
|
1999
|
-
sourceAsset: skipAssets?.[originalRoute.sourceAssetChainId]?.find(
|
|
2000
|
-
(i) => i.denom === originalRoute.sourceAssetDenom
|
|
2001
|
-
)
|
|
2002
|
-
});
|
|
2003
|
-
if (!gasOnReceiveAmount || gasOnReceiveAmount.length === 0) {
|
|
2004
|
-
throw new Error(
|
|
2005
|
-
"No gas on receive amount found for the destination chain"
|
|
2006
|
-
);
|
|
2007
|
-
}
|
|
2008
|
-
const splitDenoms = chunkArray(gasOnReceiveAmount, 3);
|
|
2009
|
-
let gasRoute;
|
|
2010
|
-
for (const chunk of splitDenoms) {
|
|
2011
|
-
const feeAssetRoutes = chunk.map(
|
|
2012
|
-
async ({ amountOut, denom, amountIn }) => {
|
|
2013
|
-
try {
|
|
2014
|
-
const res = await route({
|
|
2015
|
-
...props.routeRequest,
|
|
2016
|
-
destAssetDenom: denom,
|
|
2017
|
-
amountIn,
|
|
2018
|
-
amountOut,
|
|
2019
|
-
allowMultiTx: false
|
|
2020
|
-
});
|
|
2021
|
-
return res;
|
|
2022
|
-
} catch (_e) {
|
|
2023
|
-
return null;
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
);
|
|
2027
|
-
const result = await Promise.all(feeAssetRoutes);
|
|
2028
|
-
const _gasRoute = result.find((result2) => result2?.usdAmountOut);
|
|
2029
|
-
if (_gasRoute?.usdAmountOut) {
|
|
2030
|
-
gasRoute = _gasRoute;
|
|
2031
|
-
break;
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
if (!gasRoute) {
|
|
2035
|
-
throw new Error(
|
|
2036
|
-
"No gas route found for the destination chain with the provided assets"
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
const mainRouteAmountIn = bignumber_default(originalRoute?.amountIn ?? 0).minus(bignumber_default(gasRoute.amountIn ?? 0)).toString();
|
|
2040
|
-
const mainRoute = await route({
|
|
2041
|
-
...props.routeRequest,
|
|
2042
|
-
amountIn: mainRouteAmountIn,
|
|
2043
|
-
amountOut: void 0
|
|
2044
|
-
});
|
|
2045
|
-
if (!mainRoute) {
|
|
2046
|
-
throw new Error("No main route found with the provided assets");
|
|
2047
|
-
}
|
|
2048
|
-
if (originalRoute.txsRequired !== mainRoute.txsRequired || !isSubset(
|
|
2049
|
-
originalRoute?.requiredChainAddresses,
|
|
2050
|
-
mainRoute.requiredChainAddresses
|
|
2051
|
-
)) {
|
|
2052
|
-
throw new Error("Main route does not match the original route");
|
|
2053
|
-
}
|
|
2054
|
-
return {
|
|
2055
|
-
mainRoute,
|
|
2056
|
-
gasRoute
|
|
2057
|
-
};
|
|
2058
|
-
} catch (error) {
|
|
2059
|
-
return {
|
|
2060
|
-
mainRoute: originalRoute,
|
|
2061
|
-
gasRoute: void 0
|
|
2062
|
-
};
|
|
2063
|
-
}
|
|
2064
|
-
};
|
|
2065
|
-
var getGasOnReceiveAmount = async ({
|
|
2066
|
-
destinationChain,
|
|
2067
|
-
skipAssets,
|
|
2068
|
-
sourceAsset
|
|
2069
|
-
}) => {
|
|
2070
|
-
switch (destinationChain?.chainType) {
|
|
2071
|
-
case "cosmos" /* Cosmos */: {
|
|
2072
|
-
const usdPrice = sourceAsset?.coingeckoId ? await getUsdPrice(sourceAsset.coingeckoId) : void 0;
|
|
2073
|
-
return destinationChain.feeAssets.map((asset) => {
|
|
2074
|
-
const destinationAsset = skipAssets?.[destinationChain.chainId]?.find(
|
|
2075
|
-
(i) => i.denom === asset.denom
|
|
2076
|
-
);
|
|
2077
|
-
const gasPrice = asset.gasPrice?.average ?? asset.gasPrice?.high ?? asset.gasPrice?.low;
|
|
2078
|
-
if (!gasPrice || Number(gasPrice) === 0) {
|
|
2079
|
-
if (!usdPrice || !sourceAsset?.decimals) return;
|
|
2080
|
-
const gasOnReceiveAmountUsd = GAS_ON_RECEIVE_AMOUNT_USD["cosmos"];
|
|
2081
|
-
const amountIn = bignumber_default(gasOnReceiveAmountUsd).multipliedBy(usdPrice).toString();
|
|
2082
|
-
return {
|
|
2083
|
-
amountIn: convertHumanReadableAmountToCryptoAmount(
|
|
2084
|
-
amountIn,
|
|
2085
|
-
sourceAsset.decimals
|
|
2086
|
-
),
|
|
2087
|
-
amountOut: void 0,
|
|
2088
|
-
denom: asset.denom
|
|
2089
|
-
};
|
|
2090
|
-
}
|
|
2091
|
-
return {
|
|
2092
|
-
amountIn: void 0,
|
|
2093
|
-
amountOut: gasPrice && destinationAsset?.decimals ? convertHumanReadableAmountToCryptoAmount(
|
|
2094
|
-
bignumber_default(gasPrice).multipliedBy(3).toNumber(),
|
|
2095
|
-
destinationAsset.decimals
|
|
2096
|
-
) : void 0,
|
|
2097
|
-
denom: asset.denom
|
|
2098
|
-
};
|
|
2099
|
-
}).filter(Boolean);
|
|
2100
|
-
}
|
|
2101
|
-
case "evm" /* Evm */: {
|
|
2102
|
-
const sourceAssetPrice = sourceAsset?.coingeckoId ? await getUsdPrice(sourceAsset?.coingeckoId) : void 0;
|
|
2103
|
-
const destinationAsset = skipAssets?.[destinationChain.chainId]?.find(
|
|
2104
|
-
(i) => i.denom.includes("-native")
|
|
2105
|
-
);
|
|
2106
|
-
if (!sourceAssetPrice) {
|
|
2107
|
-
const chain = evmChains.find(
|
|
2108
|
-
(chain2) => chain2.id === Number(destinationChain?.chainId)
|
|
2109
|
-
);
|
|
2110
|
-
const client = createPublicClient({
|
|
2111
|
-
chain,
|
|
2112
|
-
transport: fallback([
|
|
2113
|
-
http("https://ethereum.publicnode.com"),
|
|
2114
|
-
http("https://rpc.ankr.com/eth"),
|
|
2115
|
-
http("https://cloudflare-eth.com")
|
|
2116
|
-
])
|
|
2117
|
-
});
|
|
2118
|
-
const fees = await client.estimateFeesPerGas();
|
|
2119
|
-
return [
|
|
2120
|
-
{
|
|
2121
|
-
amountIn: void 0,
|
|
2122
|
-
amountOut: bignumber_default(15e4).multipliedBy(fees.maxFeePerGas.toString()).multipliedBy(3).toString(),
|
|
2123
|
-
denom: destinationAsset?.denom
|
|
2124
|
-
}
|
|
2125
|
-
];
|
|
2126
|
-
}
|
|
2127
|
-
const gasPrice = bignumber_default(GAS_ON_RECEIVE_AMOUNT_USD["evm_l2"]).dividedBy(
|
|
2128
|
-
sourceAssetPrice
|
|
2129
|
-
).toString();
|
|
2130
|
-
return [
|
|
2131
|
-
{
|
|
2132
|
-
amountOut: void 0,
|
|
2133
|
-
amountIn: sourceAsset?.decimals ? convertHumanReadableAmountToCryptoAmount(
|
|
2134
|
-
gasPrice,
|
|
2135
|
-
sourceAsset.decimals
|
|
2136
|
-
) : void 0,
|
|
2137
|
-
denom: destinationAsset?.denom
|
|
2138
|
-
}
|
|
2139
|
-
];
|
|
2140
|
-
}
|
|
2141
|
-
default: {
|
|
2142
|
-
return;
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
};
|
|
2146
|
-
var chunkArray = (arr, size = 3) => {
|
|
2147
|
-
const result = [];
|
|
2148
|
-
for (let i = 0; i < arr.length; i += size) {
|
|
2149
|
-
result.push(arr.slice(i, i + size));
|
|
2150
|
-
}
|
|
2151
|
-
return result;
|
|
2152
|
-
};
|
|
2153
|
-
|
|
2154
|
-
export { AutopilotActionJson, AxelarTransferStateJson, AxelarTransferTypeJson, BridgeTypeJson, CCTPTransferStateJson, ChainTypeJson, ContractCallWithTokenErrorTypeJson, FeeBehaviorJson, FeeTypeJson, GoFastTransferStateJson, HyperlaneTransferStateJson, LayerZeroTransferStateJson, OPInitTransferStateJson, PacketErrorTypeJson, ReasonJson, RoutePriceWarningTypeJson, SendTokenErrorTypeJson, StargateTransferStateJson, StatusErrorTypeJson, TransactionStateJson, TransferStateJson, executeMultipleRoutes, executeRoute, getRouteWithGasOnReceive };
|