@skip-go/client 1.6.0-alpha.3 → 1.6.0-alpha.4

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.
Files changed (158) hide show
  1. package/dist/cjs/api/getAssets.cjs +16 -0
  2. package/dist/cjs/api/getAssetsBetweenChains.cjs +12 -0
  3. package/dist/cjs/api/getBridges.cjs +12 -0
  4. package/dist/cjs/api/getChains.cjs +12 -0
  5. package/dist/cjs/api/getVenues.cjs +12 -0
  6. package/dist/cjs/api/postAssetsFromSource.cjs +13 -0
  7. package/dist/cjs/api/postBalances.cjs +12 -0
  8. package/dist/cjs/api/postIbcOriginAssets.cjs +12 -0
  9. package/dist/cjs/api/postMessages.cjs +12 -0
  10. package/dist/cjs/api/postMessagesDirect.cjs +12 -0
  11. package/dist/cjs/api/postRecommendAssets.cjs +12 -0
  12. package/dist/cjs/api/postRoute.cjs +12 -0
  13. package/dist/cjs/api/postSubmitTransaction.cjs +12 -0
  14. package/dist/cjs/api/postTrackTransaction.cjs +12 -0
  15. package/dist/cjs/api/postTransactionStatus.cjs +12 -0
  16. package/dist/cjs/chunk-25TA7Z7R.cjs +460 -0
  17. package/dist/cjs/chunk-2QPPD3BB.cjs +210 -0
  18. package/dist/cjs/chunk-2SA3OAIJ.cjs +18 -0
  19. package/dist/cjs/chunk-3KO2DHFX.cjs +1495 -0
  20. package/dist/cjs/chunk-477CU2G2.cjs +280 -0
  21. package/dist/cjs/chunk-4BWE7SOV.cjs +68 -0
  22. package/dist/cjs/chunk-4GHUZDDP.cjs +16 -0
  23. package/dist/cjs/chunk-4ZIVDKQN.cjs +387 -0
  24. package/dist/cjs/chunk-6T4SBY5H.cjs +214 -0
  25. package/dist/cjs/chunk-A3UNNRKD.cjs +574 -0
  26. package/dist/cjs/chunk-A5S6SIYN.cjs +12 -0
  27. package/dist/cjs/chunk-ASDMDYTC.cjs +11 -0
  28. package/dist/cjs/chunk-ATW6UNT5.cjs +136 -0
  29. package/dist/cjs/chunk-AUTOIM57.cjs +22 -0
  30. package/dist/cjs/chunk-AVWWCQ5P.cjs +2264 -0
  31. package/dist/cjs/chunk-CIZTNJ3K.cjs +24 -0
  32. package/dist/cjs/chunk-CK6CQWQU.cjs +49 -0
  33. package/dist/cjs/chunk-EAZQ2ECA.cjs +185 -0
  34. package/dist/cjs/chunk-F3EB2AQG.cjs +28 -0
  35. package/dist/cjs/chunk-FCTBCHOT.cjs +12 -0
  36. package/dist/cjs/chunk-IJIBMN2F.cjs +12 -0
  37. package/dist/cjs/chunk-IUMMXFGP.cjs +189 -0
  38. package/dist/cjs/chunk-JRXPJ45U.cjs +12 -0
  39. package/dist/cjs/chunk-LJV45UGL.cjs +582 -0
  40. package/dist/cjs/chunk-MUJBB64F.cjs +291 -0
  41. package/dist/cjs/chunk-NCFH5MGF.cjs +39 -0
  42. package/dist/cjs/chunk-NM4PISTQ.cjs +3359 -0
  43. package/dist/cjs/chunk-OJISEAMX.cjs +13 -0
  44. package/dist/cjs/chunk-OVKHTOBP.cjs +99 -0
  45. package/dist/cjs/chunk-PDNKS5R2.cjs +13 -0
  46. package/dist/cjs/chunk-TELXDMYL.cjs +55 -0
  47. package/dist/cjs/chunk-UXW4XVHF.cjs +15 -0
  48. package/dist/cjs/index.cjs +349 -0
  49. package/dist/cjs/public-functions/executeMultipleRoutes.cjs +27 -0
  50. package/dist/cjs/public-functions/executeRoute.cjs +27 -0
  51. package/dist/cjs/public-functions/getCosmosGasAmountForMessage.cjs +16 -0
  52. package/dist/cjs/public-functions/getEvmGasAmountForMessage.cjs +11 -0
  53. package/dist/cjs/public-functions/getFeeInfoForChain.cjs +14 -0
  54. package/dist/cjs/public-functions/getRecommendedGasPrice.cjs +15 -0
  55. package/dist/cjs/public-functions/getRouteWithGasOnReceive.cjs +41 -0
  56. package/dist/cjs/public-functions/getSigningStargateClient.cjs +15 -0
  57. package/dist/cjs/public-functions/setApiOptions.cjs +12 -0
  58. package/dist/cjs/public-functions/setClientOptions.cjs +16 -0
  59. package/dist/cjs/public-functions/subscribeToRouteStatus.cjs +26 -0
  60. package/dist/cjs/public-functions/validateCosmosGasBalance.cjs +18 -0
  61. package/dist/cjs/public-functions/waitForTransaction.cjs +18 -0
  62. package/dist/esm/api/getAssets.d.ts +19 -0
  63. package/dist/esm/api/getAssets.js +3 -0
  64. package/dist/esm/api/getAssetsBetweenChains.d.ts +56 -0
  65. package/dist/esm/api/getAssetsBetweenChains.js +3 -0
  66. package/dist/esm/api/getBridges.d.ts +55 -0
  67. package/dist/esm/api/getBridges.js +3 -0
  68. package/dist/esm/api/getChains.d.ts +41 -0
  69. package/dist/esm/api/getChains.js +3 -0
  70. package/dist/esm/api/getVenues.d.ts +13 -0
  71. package/dist/esm/api/getVenues.js +3 -0
  72. package/dist/esm/api/postAssetsFromSource.d.ts +22 -0
  73. package/dist/esm/api/postAssetsFromSource.js +4 -0
  74. package/dist/esm/api/postBalances.d.ts +35 -0
  75. package/dist/esm/api/postBalances.js +3 -0
  76. package/dist/esm/api/postIbcOriginAssets.d.ts +32 -0
  77. package/dist/esm/api/postIbcOriginAssets.js +3 -0
  78. package/dist/esm/api/postMessages.d.ts +101 -0
  79. package/dist/esm/api/postMessages.js +3 -0
  80. package/dist/esm/api/postMessagesDirect.d.ts +640 -0
  81. package/dist/esm/api/postMessagesDirect.js +3 -0
  82. package/dist/esm/api/postRecommendAssets.d.ts +40 -0
  83. package/dist/esm/api/postRecommendAssets.js +3 -0
  84. package/dist/esm/api/postRoute.d.ts +530 -0
  85. package/dist/esm/api/postRoute.js +3 -0
  86. package/dist/esm/api/postSubmitTransaction.d.ts +17 -0
  87. package/dist/esm/api/postSubmitTransaction.js +3 -0
  88. package/dist/esm/api/postTrackTransaction.d.ts +12 -0
  89. package/dist/esm/api/postTrackTransaction.js +3 -0
  90. package/dist/esm/api/postTransactionStatus.d.ts +639 -0
  91. package/dist/esm/api/postTransactionStatus.js +3 -0
  92. package/dist/esm/apiState-1VvikVK-.d.ts +8 -0
  93. package/dist/esm/callbacks-DdC6QMlE.d.ts +158 -0
  94. package/dist/esm/chunk-3DIX6KRJ.js +566 -0
  95. package/dist/esm/chunk-3JHLVPRG.js +10 -0
  96. package/dist/esm/chunk-5WYMRZIO.js +97 -0
  97. package/dist/esm/chunk-A5NZMSTI.js +10 -0
  98. package/dist/esm/chunk-BU5RCZQH.js +187 -0
  99. package/dist/esm/chunk-CGJRRAFS.js +22 -0
  100. package/dist/esm/chunk-DMJMN4J3.js +379 -0
  101. package/dist/esm/chunk-E4NRDAVO.js +65 -0
  102. package/dist/esm/chunk-ETBJVFQP.js +10 -0
  103. package/dist/esm/chunk-F2LQB2DP.js +3323 -0
  104. package/dist/esm/chunk-F66EKL3W.js +203 -0
  105. package/dist/esm/chunk-G665WTT3.js +212 -0
  106. package/dist/esm/chunk-GPEO2I4P.js +272 -0
  107. package/dist/esm/chunk-GV2QOWB4.js +26 -0
  108. package/dist/esm/chunk-GZJLX2CP.js +2258 -0
  109. package/dist/esm/chunk-HNU2Y3JI.js +13 -0
  110. package/dist/esm/chunk-IZUHXTBP.js +53 -0
  111. package/dist/esm/chunk-J24LYWJE.js +130 -0
  112. package/dist/esm/chunk-KZKAL5ZN.js +16 -0
  113. package/dist/esm/chunk-N4PTRCNT.js +11 -0
  114. package/dist/esm/chunk-NUHMTWHP.js +180 -0
  115. package/dist/esm/chunk-P36PE4CR.js +37 -0
  116. package/dist/esm/chunk-QYXGDTUU.js +47 -0
  117. package/dist/esm/chunk-RH7PDDI5.js +433 -0
  118. package/dist/esm/chunk-RTDD7HZ3.js +275 -0
  119. package/dist/esm/chunk-SXBG57J3.js +20 -0
  120. package/dist/esm/chunk-TGTOO2ZQ.js +14 -0
  121. package/dist/esm/chunk-UHCKOKBM.js +9 -0
  122. package/dist/esm/chunk-ULUX2CVU.js +557 -0
  123. package/dist/esm/chunk-UN46DUOV.js +11 -0
  124. package/dist/esm/chunk-XIVAEU6S.js +1492 -0
  125. package/dist/esm/chunk-XNU3TKKM.js +10 -0
  126. package/dist/esm/client-types-D03Tellv.d.ts +114 -0
  127. package/dist/esm/generateApi-Bv02Xt5y.d.ts +56 -0
  128. package/dist/esm/index.d.ts +1859 -0
  129. package/dist/esm/index.js +32 -0
  130. package/dist/esm/public-functions/executeMultipleRoutes.d.ts +80 -0
  131. package/dist/esm/public-functions/executeMultipleRoutes.js +18 -0
  132. package/dist/esm/public-functions/executeRoute.d.ts +12 -0
  133. package/dist/esm/public-functions/executeRoute.js +18 -0
  134. package/dist/esm/public-functions/getCosmosGasAmountForMessage.d.ts +8 -0
  135. package/dist/esm/public-functions/getCosmosGasAmountForMessage.js +3 -0
  136. package/dist/esm/public-functions/getEvmGasAmountForMessage.d.ts +14 -0
  137. package/dist/esm/public-functions/getEvmGasAmountForMessage.js +2 -0
  138. package/dist/esm/public-functions/getFeeInfoForChain.d.ts +9 -0
  139. package/dist/esm/public-functions/getFeeInfoForChain.js +5 -0
  140. package/dist/esm/public-functions/getRecommendedGasPrice.d.ts +9 -0
  141. package/dist/esm/public-functions/getRecommendedGasPrice.js +6 -0
  142. package/dist/esm/public-functions/getRouteWithGasOnReceive.d.ts +20 -0
  143. package/dist/esm/public-functions/getRouteWithGasOnReceive.js +32 -0
  144. package/dist/esm/public-functions/getSigningStargateClient.d.ts +13 -0
  145. package/dist/esm/public-functions/getSigningStargateClient.js +6 -0
  146. package/dist/esm/public-functions/setApiOptions.d.ts +9 -0
  147. package/dist/esm/public-functions/setApiOptions.js +3 -0
  148. package/dist/esm/public-functions/setClientOptions.d.ts +11 -0
  149. package/dist/esm/public-functions/setClientOptions.js +7 -0
  150. package/dist/esm/public-functions/subscribeToRouteStatus.d.ts +12 -0
  151. package/dist/esm/public-functions/subscribeToRouteStatus.js +5 -0
  152. package/dist/esm/public-functions/validateCosmosGasBalance.d.ts +44 -0
  153. package/dist/esm/public-functions/validateCosmosGasBalance.js +9 -0
  154. package/dist/esm/public-functions/waitForTransaction.d.ts +1279 -0
  155. package/dist/esm/public-functions/waitForTransaction.js +5 -0
  156. package/dist/esm/setClientOptions-CTwe8YVX.d.ts +76 -0
  157. package/dist/esm/swaggerTypes-CzGbnX_b.d.ts +2067 -0
  158. package/package.json +1 -1
@@ -0,0 +1,1495 @@
1
+ 'use strict';
2
+
3
+ var chunkA3UNNRKD_cjs = require('./chunk-A3UNNRKD.cjs');
4
+ var chunkIUMMXFGP_cjs = require('./chunk-IUMMXFGP.cjs');
5
+ var chunk477CU2G2_cjs = require('./chunk-477CU2G2.cjs');
6
+ var chunkF3EB2AQG_cjs = require('./chunk-F3EB2AQG.cjs');
7
+ var chunk4ZIVDKQN_cjs = require('./chunk-4ZIVDKQN.cjs');
8
+ var chunkEAZQ2ECA_cjs = require('./chunk-EAZQ2ECA.cjs');
9
+ var chunkJRXPJ45U_cjs = require('./chunk-JRXPJ45U.cjs');
10
+ var chunkFCTBCHOT_cjs = require('./chunk-FCTBCHOT.cjs');
11
+ var chunkATW6UNT5_cjs = require('./chunk-ATW6UNT5.cjs');
12
+ var chunk2QPPD3BB_cjs = require('./chunk-2QPPD3BB.cjs');
13
+ var stargate = require('@cosmjs/stargate');
14
+ var tx_js = require('cosmjs-types/cosmos/tx/v1beta1/tx.js');
15
+ var protoSigning = require('@cosmjs/proto-signing');
16
+ var amino = require('@cosmjs/amino');
17
+ var encoding = require('@cosmjs/encoding');
18
+ var keys_js = require('cosmjs-types/cosmos/crypto/secp256k1/keys.js');
19
+ var any_js = require('cosmjs-types/google/protobuf/any.js');
20
+ var math = require('@cosmjs/math');
21
+ var signing_js = require('cosmjs-types/cosmos/tx/signing/v1beta1/signing.js');
22
+ var viem = require('viem');
23
+ var web3_js = require('@solana/web3.js');
24
+ var bignumber_js = require('bignumber.js');
25
+ var bech32 = require('bech32');
26
+
27
+ // src/private-functions/getRestEndpointForChain.ts
28
+ var getRestEndpointForChain = async (chainId) => {
29
+ if (chunkATW6UNT5_cjs.ClientState.endpointOptions.getRestEndpointForChain) {
30
+ return chunkATW6UNT5_cjs.ClientState.endpointOptions.getRestEndpointForChain(chainId);
31
+ }
32
+ if (chunkATW6UNT5_cjs.ClientState.endpointOptions.endpoints && chunkATW6UNT5_cjs.ClientState.endpointOptions.endpoints[chainId]) {
33
+ const endpointOptions = chunkATW6UNT5_cjs.ClientState.endpointOptions.endpoints[chainId];
34
+ if (endpointOptions?.rest) {
35
+ return endpointOptions.rest;
36
+ }
37
+ }
38
+ const chain = chunkEAZQ2ECA_cjs.chains().find((chain2) => chain2.chainId === chainId);
39
+ if (!chain) {
40
+ throw new Error(
41
+ `getRestEndpointForChain error: failed to find chain id '${chainId}' in registry`
42
+ );
43
+ }
44
+ if (chain.apis?.rest?.length === 0 || !chain.apis?.rest) {
45
+ throw new Error(
46
+ `getRestEndpointForChain error: failed to find REST endpoint for chain id '${chainId}'`
47
+ );
48
+ }
49
+ const endpoints = chain.apis?.rest?.map((api) => api.address);
50
+ const endpoint = await chunkEAZQ2ECA_cjs.findFirstWorkingEndpoint(endpoints, "rest");
51
+ if (!endpoint) {
52
+ throw new Error(
53
+ `getRestEndpointForChain error: failed to find REST endpoint for chain id '${chainId}'`
54
+ );
55
+ }
56
+ return endpoint;
57
+ };
58
+
59
+ // src/private-functions/getAccountNumberAndSequence.ts
60
+ var getAccountNumberAndSequence = async (address, chainId) => {
61
+ if (chainId.includes("dymension")) {
62
+ return getAccountNumberAndSequenceFromDymension(address, chainId);
63
+ }
64
+ const endpoint = await chunk4ZIVDKQN_cjs.getRpcEndpointForChain(chainId);
65
+ const client = chunkATW6UNT5_cjs.ClientState.signingStargateClientByChainId[chainId] ?? await stargate.StargateClient.connect(endpoint, {
66
+ accountParser: chunk4ZIVDKQN_cjs.accountParser
67
+ });
68
+ const account = await client.getAccount(address);
69
+ if (!account) {
70
+ throw new Error("getAccountNumberAndSequence: failed to retrieve account");
71
+ }
72
+ client.disconnect();
73
+ return {
74
+ accountNumber: account.accountNumber,
75
+ sequence: account.sequence
76
+ };
77
+ };
78
+ var getAccountNumberAndSequenceFromDymension = async (address, chainId) => {
79
+ const endpoint = await getRestEndpointForChain(chainId);
80
+ const res = await fetch(
81
+ `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`,
82
+ {
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ }
86
+ }
87
+ );
88
+ if (!res.ok) {
89
+ throw new Error(`Failed to fetch account data: ${res.statusText}`);
90
+ }
91
+ const jsonResponse = await res.json();
92
+ const response = chunk2QPPD3BB_cjs.toCamel(jsonResponse);
93
+ let sequence = 0;
94
+ let accountNumber = 0;
95
+ if (response.account.baseAccount) {
96
+ sequence = response.account.baseAccount.sequence;
97
+ accountNumber = response.account.baseAccount.accountNumber;
98
+ } else {
99
+ sequence = response.account.sequence;
100
+ accountNumber = response.account.accountNumber;
101
+ }
102
+ return {
103
+ accountNumber,
104
+ sequence
105
+ };
106
+ };
107
+ var pubkeyType = {
108
+ ethsecp256k1: "ethermint/PubKeyEthSecp256k1",
109
+ ...amino.pubkeyType
110
+ };
111
+
112
+ // src/amino/encoding.ts
113
+ function encodeEthSecp256k1Pubkey(pubkey) {
114
+ if (pubkey.length !== 33 || pubkey[0] !== 2 && pubkey[0] !== 3) {
115
+ throw new Error(
116
+ "Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03"
117
+ );
118
+ }
119
+ return {
120
+ type: pubkeyType.ethsecp256k1,
121
+ value: encoding.toBase64(pubkey)
122
+ };
123
+ }
124
+
125
+ // src/proto-signing/pubkey.ts
126
+ function makePubkeyAnyFromAccount(account, chainId) {
127
+ const isEthermint = chunkEAZQ2ECA_cjs.getIsEthermint(chainId);
128
+ const pubkey = isEthermint ? encodeEthSecp256k1Pubkey(account.pubkey) : amino.encodeSecp256k1Pubkey(account.pubkey);
129
+ const pubkeyAny = encodePubkeyToAny(pubkey, chainId, isEthermint);
130
+ return pubkeyAny;
131
+ }
132
+ function encodePubkeyToAny(pubkey, chainId, isEthermint) {
133
+ if (isEthermint) {
134
+ const pubkeyProto = keys_js.PubKey.fromPartial({
135
+ key: encoding.fromBase64(pubkey.value)
136
+ });
137
+ let typeUrl = "";
138
+ if (chainId?.includes("injective")) {
139
+ typeUrl = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
140
+ } else {
141
+ typeUrl = "/ethermint.crypto.v1.ethsecp256k1.PubKey";
142
+ }
143
+ return any_js.Any.fromPartial({
144
+ typeUrl,
145
+ value: Uint8Array.from(keys_js.PubKey.encode(pubkeyProto).finish())
146
+ });
147
+ } else {
148
+ const isInitia = chunkEAZQ2ECA_cjs.getIsInitia(chainId);
149
+ const pubkeyProto = keys_js.PubKey.fromPartial({
150
+ key: encoding.fromBase64(pubkey.value)
151
+ });
152
+ if (isInitia) {
153
+ return any_js.Any.fromPartial({
154
+ typeUrl: "/initia.crypto.v1beta1.ethsecp256k1.PubKey",
155
+ value: Uint8Array.from(keys_js.PubKey.encode(pubkeyProto).finish())
156
+ });
157
+ }
158
+ return protoSigning.encodePubkey(pubkey);
159
+ }
160
+ }
161
+ var signCosmosMessageDirect = async (options) => {
162
+ const {
163
+ signer,
164
+ signerAddress,
165
+ chainId,
166
+ cosmosMsgs,
167
+ fee,
168
+ signerData: { accountNumber, sequence, chainId: signerChainId }
169
+ } = options;
170
+ const accounts = await signer.getAccounts();
171
+ const accountFromSigner = accounts.find((account) => account.address === signerAddress);
172
+ if (!accountFromSigner) {
173
+ throw new Error("signCosmosMessageDirect error: failed to retrieve account from signer");
174
+ }
175
+ const messages = cosmosMsgs.map((cosmosMsg) => chunk477CU2G2_cjs.getEncodeObjectFromCosmosMessage(cosmosMsg));
176
+ const txBodyEncodeObject = {
177
+ typeUrl: "/cosmos.tx.v1beta1.TxBody",
178
+ value: {
179
+ messages
180
+ }
181
+ };
182
+ const txBodyBytes = chunkATW6UNT5_cjs.ClientState.registry.encode(txBodyEncodeObject);
183
+ const gasLimit = math.Int53.fromString(fee.gas).toNumber();
184
+ const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
185
+ const authInfoBytes = protoSigning.makeAuthInfoBytes(
186
+ [{ pubkey: pubkeyAny, sequence }],
187
+ fee.amount,
188
+ gasLimit,
189
+ fee.granter,
190
+ fee.payer
191
+ );
192
+ const signDoc = protoSigning.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
193
+ const { signature, signed } = await signer.signDirect(signerAddress, signDoc);
194
+ return tx_js.TxRaw.fromPartial({
195
+ bodyBytes: signed.bodyBytes,
196
+ authInfoBytes: signed.authInfoBytes,
197
+ signatures: [encoding.fromBase64(signature.signature)]
198
+ });
199
+ };
200
+ var signCosmosMessageAmino = async (options) => {
201
+ const {
202
+ signer,
203
+ signerAddress,
204
+ chainId,
205
+ cosmosMsgs,
206
+ fee,
207
+ signerData: { accountNumber, sequence, chainId: signerChainId }
208
+ } = options;
209
+ const accounts = await signer.getAccounts();
210
+ const accountFromSigner = accounts.find(
211
+ (account) => account.address === signerAddress
212
+ );
213
+ if (!accountFromSigner) {
214
+ throw new Error(
215
+ "signCosmosMessageAmino: failed to retrieve account from signer"
216
+ );
217
+ }
218
+ const messages = cosmosMsgs.map(
219
+ (cosmosMsg) => chunk477CU2G2_cjs.getEncodeObjectFromCosmosMessage(cosmosMsg)
220
+ );
221
+ const signMode = signing_js.SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
222
+ const msgs = messages.map((msg) => chunkATW6UNT5_cjs.ClientState.aminoTypes.toAmino(msg));
223
+ const signDoc = amino.makeSignDoc(
224
+ msgs,
225
+ fee,
226
+ signerChainId,
227
+ "",
228
+ accountNumber,
229
+ sequence
230
+ );
231
+ const { signature, signed } = await signer.signAmino(signerAddress, signDoc);
232
+ const signedTxBody = {
233
+ messages: signed.msgs.map((msg) => chunkATW6UNT5_cjs.ClientState.aminoTypes.fromAmino(msg)),
234
+ memo: signed.memo
235
+ };
236
+ signedTxBody.messages[0].value.memo = messages[0].value.memo;
237
+ const signedTxBodyEncodeObject = {
238
+ typeUrl: "/cosmos.tx.v1beta1.TxBody",
239
+ value: signedTxBody
240
+ };
241
+ const signedTxBodyBytes = chunkATW6UNT5_cjs.ClientState.registry.encode(
242
+ signedTxBodyEncodeObject
243
+ );
244
+ const signedGasLimit = math.Int53.fromString(signed.fee.gas).toNumber();
245
+ const signedSequence = math.Int53.fromString(signed.sequence).toNumber();
246
+ const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
247
+ const signedAuthInfoBytes = protoSigning.makeAuthInfoBytes(
248
+ [{ pubkey: pubkeyAny, sequence: signedSequence }],
249
+ signed.fee.amount,
250
+ signedGasLimit,
251
+ signed.fee.granter,
252
+ signed.fee.payer,
253
+ signMode
254
+ );
255
+ return tx_js.TxRaw.fromPartial({
256
+ bodyBytes: signedTxBodyBytes,
257
+ authInfoBytes: signedAuthInfoBytes,
258
+ signatures: [encoding.fromBase64(signature.signature)]
259
+ });
260
+ };
261
+
262
+ // src/private-functions/cosmos/signCosmosTransaction.ts
263
+ var signCosmosTransaction = async ({
264
+ tx,
265
+ options,
266
+ index,
267
+ routeId
268
+ }) => {
269
+ const { userAddresses } = options;
270
+ if (tx === void 0) {
271
+ throw new Error("executeCosmosTransaction error: tx is undefined");
272
+ }
273
+ const chainId = tx.cosmosTx?.chainId;
274
+ const messages = tx.cosmosTx?.msgs;
275
+ const currentUserAddress = userAddresses.find((x) => x.chainId === tx.cosmosTx?.chainId)?.address;
276
+ const gasArray = chunkATW6UNT5_cjs.ClientState.validateGasResults;
277
+ const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
278
+ if (typeof gas?.error === "string") {
279
+ throw new Error(gas?.error);
280
+ }
281
+ const gasUsed = gasArray?.[index];
282
+ if (!gasUsed) {
283
+ throw new Error(`executeRoute error: invalid gas at index ${index}`);
284
+ }
285
+ if (chainId === void 0) {
286
+ throw new Error("no chainId found for tx");
287
+ }
288
+ if (messages === void 0) {
289
+ throw new Error("no messages found for tx");
290
+ }
291
+ const { signer } = await chunk4ZIVDKQN_cjs.getSigningStargateClient({
292
+ chainId,
293
+ getOfflineSigner: options?.getCosmosSigner
294
+ });
295
+ if (!currentUserAddress) {
296
+ throw new Error(
297
+ `executeCosmosTransaction error: invalid address for chain '${tx.cosmosTx?.chainId}'`
298
+ );
299
+ }
300
+ const accounts = await signer.getAccounts();
301
+ const accountFromSigner = accounts.find((account) => account.address === currentUserAddress);
302
+ if (!accountFromSigner) {
303
+ throw new Error("executeCosmosTransaction error: failed to retrieve account from signer");
304
+ }
305
+ const fee = gasUsed?.fee;
306
+ if (!fee) {
307
+ throw new Error("executeCosmosTransaction error: failed to retrieve fee from gas");
308
+ }
309
+ const { accountNumber, sequence } = await getAccountNumberAndSequence(
310
+ currentUserAddress,
311
+ chainId
312
+ );
313
+ let rawTx;
314
+ const commonRawTxBody = {
315
+ signerAddress: currentUserAddress,
316
+ chainId,
317
+ cosmosMsgs: messages,
318
+ fee,
319
+ signerData: {
320
+ accountNumber,
321
+ sequence,
322
+ chainId
323
+ }
324
+ };
325
+ options.onTransactionSignRequested?.({
326
+ chainId,
327
+ txIndex: index,
328
+ signerAddress: currentUserAddress
329
+ });
330
+ chunkA3UNNRKD_cjs.updateRouteDetails({
331
+ status: "signing",
332
+ routeId,
333
+ options
334
+ });
335
+ if (protoSigning.isOfflineDirectSigner(signer)) {
336
+ rawTx = await signCosmosMessageDirect({
337
+ ...commonRawTxBody,
338
+ signer
339
+ });
340
+ } else {
341
+ rawTx = await signCosmosMessageAmino({ ...commonRawTxBody, signer });
342
+ }
343
+ options?.onTransactionSigned?.({
344
+ chainId
345
+ });
346
+ chunkA3UNNRKD_cjs.updateRouteDetails({
347
+ status: "pending",
348
+ routeId,
349
+ options
350
+ });
351
+ const txBytes = tx_js.TxRaw.encode(rawTx).finish();
352
+ const rawTxBase64 = Buffer.from(txBytes).toString("base64");
353
+ return rawTxBase64;
354
+ };
355
+
356
+ // src/private-functions/cosmos/executeCosmosTransaction.ts
357
+ var executeCosmosTransaction = async ({
358
+ tx,
359
+ options,
360
+ index,
361
+ routeId
362
+ }) => {
363
+ if (tx === void 0) {
364
+ throw new Error("executeCosmosTransaction error: tx is undefined");
365
+ }
366
+ const rawTxBase64 = await signCosmosTransaction({
367
+ tx,
368
+ options,
369
+ index,
370
+ routeId
371
+ });
372
+ const chainId = tx.cosmosTx?.chainId;
373
+ const txResponse = await chunkJRXPJ45U_cjs.submitTransaction({
374
+ chainId,
375
+ tx: rawTxBase64
376
+ });
377
+ return {
378
+ chainId: tx?.cosmosTx?.chainId ?? "",
379
+ txHash: txResponse?.txHash ?? "",
380
+ explorerLink: txResponse?.explorerLink ?? ""
381
+ };
382
+ };
383
+ function createAbi(abi) {
384
+ return abi;
385
+ }
386
+ var erc20ABI = /* @__PURE__ */ createAbi([
387
+ {
388
+ type: "event",
389
+ name: "Approval",
390
+ inputs: [
391
+ {
392
+ indexed: true,
393
+ name: "owner",
394
+ type: "address"
395
+ },
396
+ {
397
+ indexed: true,
398
+ name: "spender",
399
+ type: "address"
400
+ },
401
+ {
402
+ indexed: false,
403
+ name: "value",
404
+ type: "uint256"
405
+ }
406
+ ]
407
+ },
408
+ {
409
+ type: "event",
410
+ name: "Transfer",
411
+ inputs: [
412
+ {
413
+ indexed: true,
414
+ name: "from",
415
+ type: "address"
416
+ },
417
+ {
418
+ indexed: true,
419
+ name: "to",
420
+ type: "address"
421
+ },
422
+ {
423
+ indexed: false,
424
+ name: "value",
425
+ type: "uint256"
426
+ }
427
+ ]
428
+ },
429
+ {
430
+ type: "function",
431
+ name: "allowance",
432
+ stateMutability: "view",
433
+ inputs: [
434
+ {
435
+ name: "owner",
436
+ type: "address"
437
+ },
438
+ {
439
+ name: "spender",
440
+ type: "address"
441
+ }
442
+ ],
443
+ outputs: [
444
+ {
445
+ name: "",
446
+ type: "uint256"
447
+ }
448
+ ]
449
+ },
450
+ {
451
+ type: "function",
452
+ name: "approve",
453
+ stateMutability: "nonpayable",
454
+ inputs: [
455
+ {
456
+ name: "spender",
457
+ type: "address"
458
+ },
459
+ {
460
+ name: "amount",
461
+ type: "uint256"
462
+ }
463
+ ],
464
+ outputs: [
465
+ {
466
+ name: "",
467
+ type: "bool"
468
+ }
469
+ ]
470
+ },
471
+ {
472
+ type: "function",
473
+ name: "balanceOf",
474
+ stateMutability: "view",
475
+ inputs: [
476
+ {
477
+ name: "account",
478
+ type: "address"
479
+ }
480
+ ],
481
+ outputs: [
482
+ {
483
+ name: "",
484
+ type: "uint256"
485
+ }
486
+ ]
487
+ },
488
+ {
489
+ type: "function",
490
+ name: "decimals",
491
+ stateMutability: "view",
492
+ inputs: [],
493
+ outputs: [
494
+ {
495
+ name: "",
496
+ type: "uint8"
497
+ }
498
+ ]
499
+ },
500
+ {
501
+ type: "function",
502
+ name: "name",
503
+ stateMutability: "view",
504
+ inputs: [],
505
+ outputs: [
506
+ {
507
+ name: "",
508
+ type: "string"
509
+ }
510
+ ]
511
+ },
512
+ {
513
+ type: "function",
514
+ name: "symbol",
515
+ stateMutability: "view",
516
+ inputs: [],
517
+ outputs: [
518
+ {
519
+ name: "",
520
+ type: "string"
521
+ }
522
+ ]
523
+ },
524
+ {
525
+ type: "function",
526
+ name: "totalSupply",
527
+ stateMutability: "view",
528
+ inputs: [],
529
+ outputs: [
530
+ {
531
+ name: "",
532
+ type: "uint256"
533
+ }
534
+ ]
535
+ },
536
+ {
537
+ type: "function",
538
+ name: "transfer",
539
+ stateMutability: "nonpayable",
540
+ inputs: [
541
+ {
542
+ name: "recipient",
543
+ type: "address"
544
+ },
545
+ {
546
+ name: "amount",
547
+ type: "uint256"
548
+ }
549
+ ],
550
+ outputs: [
551
+ {
552
+ name: "",
553
+ type: "bool"
554
+ }
555
+ ]
556
+ },
557
+ {
558
+ type: "function",
559
+ name: "transferFrom",
560
+ stateMutability: "nonpayable",
561
+ inputs: [
562
+ {
563
+ name: "sender",
564
+ type: "address"
565
+ },
566
+ {
567
+ name: "recipient",
568
+ type: "address"
569
+ },
570
+ {
571
+ name: "amount",
572
+ type: "uint256"
573
+ }
574
+ ],
575
+ outputs: [
576
+ {
577
+ name: "",
578
+ type: "bool"
579
+ }
580
+ ]
581
+ }
582
+ ]);
583
+
584
+ // src/private-functions/evm/executeEvmTransaction.ts
585
+ var executeEvmTransaction = async (message, options, index, routeId) => {
586
+ const gasArray = chunkATW6UNT5_cjs.ClientState.validateGasResults;
587
+ const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
588
+ if (typeof gas?.error === "string") {
589
+ throw new Error(gas?.error);
590
+ }
591
+ const { evmTx } = message;
592
+ const getEvmSigner = options.getEvmSigner;
593
+ if (!getEvmSigner) {
594
+ throw new Error("executeEVMTransaction error: getEvmSigner is not provided");
595
+ }
596
+ if (!evmTx?.chainId) {
597
+ throw new Error("chain id not found in evmTx");
598
+ }
599
+ const evmSigner = await getEvmSigner(evmTx.chainId);
600
+ if (!evmSigner.account) {
601
+ throw new Error("executeEVMTransaction error: failed to retrieve account from signer");
602
+ }
603
+ if (!evmTx.chainId) {
604
+ throw new Error("executeEVMTransaction error: chainId not found for evmTx");
605
+ }
606
+ if (!evmTx.value && evmTx.value !== "") {
607
+ throw new Error("executeEVMTransaction error: no value found in evmTx");
608
+ }
609
+ const { onApproveAllowance, onTransactionSigned, bypassApprovalCheck, useUnlimitedApproval } = options;
610
+ const extendedSigner = evmSigner.extend(viem.publicActions);
611
+ if (!bypassApprovalCheck && evmTx.requiredErc20Approvals) {
612
+ for (const requiredApproval of evmTx.requiredErc20Approvals) {
613
+ const allowance = await extendedSigner.readContract({
614
+ address: requiredApproval.tokenContract,
615
+ abi: erc20ABI,
616
+ functionName: "allowance",
617
+ args: [
618
+ evmSigner.account.address,
619
+ requiredApproval.spender
620
+ ]
621
+ });
622
+ if (!requiredApproval.amount) {
623
+ throw new Error("executeEVMTransaction error: no amount found in a requiredApproval");
624
+ }
625
+ if (allowance > BigInt(requiredApproval.amount)) {
626
+ continue;
627
+ }
628
+ onApproveAllowance?.({
629
+ status: "pending",
630
+ allowance: requiredApproval
631
+ });
632
+ chunkA3UNNRKD_cjs.updateRouteDetails({
633
+ status: "allowance",
634
+ routeId,
635
+ options
636
+ });
637
+ const txHash2 = await extendedSigner.writeContract({
638
+ account: evmSigner.account,
639
+ address: requiredApproval.tokenContract,
640
+ abi: erc20ABI,
641
+ functionName: "approve",
642
+ args: [
643
+ requiredApproval.spender,
644
+ useUnlimitedApproval ? viem.maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
645
+ ],
646
+ chain: evmSigner.chain
647
+ });
648
+ const receipt2 = await extendedSigner.waitForTransactionReceipt({
649
+ hash: txHash2
650
+ });
651
+ if (receipt2.status === "reverted") {
652
+ throw new Error(
653
+ `executeEVMTransaction error: evm tx reverted for hash ${receipt2.transactionHash}`
654
+ );
655
+ }
656
+ }
657
+ onApproveAllowance?.({
658
+ status: "completed"
659
+ });
660
+ }
661
+ options?.onTransactionSignRequested?.({
662
+ chainId: evmTx.chainId,
663
+ signerAddress: evmSigner.account.address,
664
+ txIndex: index
665
+ });
666
+ chunkA3UNNRKD_cjs.updateRouteDetails({
667
+ status: "signing",
668
+ routeId,
669
+ options
670
+ });
671
+ const txHash = await extendedSigner.sendTransaction({
672
+ account: evmSigner.account,
673
+ to: evmTx.to,
674
+ data: `0x${evmTx.data}`,
675
+ chain: evmSigner.chain,
676
+ value: evmTx.value === "" ? void 0 : BigInt(evmTx.value)
677
+ });
678
+ chunkA3UNNRKD_cjs.updateRouteDetails({
679
+ status: "pending",
680
+ routeId,
681
+ options
682
+ });
683
+ onTransactionSigned?.({
684
+ chainId: evmTx.chainId
685
+ });
686
+ const receipt = await extendedSigner.waitForTransactionReceipt({
687
+ hash: txHash
688
+ });
689
+ return receipt;
690
+ };
691
+ var signSvmTransaction = async ({
692
+ tx,
693
+ options,
694
+ index,
695
+ routeId
696
+ }) => {
697
+ const gasArray = chunkATW6UNT5_cjs.ClientState.validateGasResults;
698
+ if (tx === void 0) {
699
+ throw new Error("executeSvmTransaction error: tx is undefined");
700
+ }
701
+ const gas = gasArray?.find(
702
+ (gas2) => gas2?.error !== null && gas2?.error !== void 0
703
+ );
704
+ if (typeof gas?.error === "string") {
705
+ throw new Error(gas?.error);
706
+ }
707
+ const svmTx = tx?.svmTx;
708
+ const getSvmSigner = options?.getSvmSigner;
709
+ if (!getSvmSigner) {
710
+ throw new Error(
711
+ "executeSvmTransaction error: getSvmSigner is not provided"
712
+ );
713
+ }
714
+ const signer = await getSvmSigner();
715
+ if (!svmTx?.chainId) {
716
+ throw new Error("executeSvmTransaction error: chainId not found in svmTx");
717
+ }
718
+ const txBuffer = Buffer.from(svmTx.tx ?? "", "base64");
719
+ const transaction = web3_js.Transaction.from(txBuffer);
720
+ if (options.svmFeePayer) {
721
+ const message = transaction.serializeMessage();
722
+ const resSignTx = await options.svmFeePayer.signTransaction(message);
723
+ transaction.addSignature(
724
+ new web3_js.PublicKey(options.svmFeePayer.address),
725
+ Buffer.from(resSignTx)
726
+ );
727
+ }
728
+ if (!("signTransaction" in signer)) return;
729
+ options?.onTransactionSignRequested?.({
730
+ chainId: svmTx.chainId,
731
+ signerAddress: signer.publicKey?.toBase58(),
732
+ txIndex: index
733
+ });
734
+ chunkA3UNNRKD_cjs.updateRouteDetails({
735
+ status: "signing",
736
+ routeId,
737
+ options
738
+ });
739
+ const signedTx = await signer.signTransaction(transaction);
740
+ options?.onTransactionSigned?.({ chainId: svmTx.chainId });
741
+ chunkA3UNNRKD_cjs.updateRouteDetails({
742
+ status: "pending",
743
+ routeId,
744
+ options
745
+ });
746
+ const serializedTx = signedTx.serialize();
747
+ return serializedTx;
748
+ };
749
+
750
+ // src/private-functions/svm/executeSvmTransaction.ts
751
+ var executeSvmTransaction = async (tx, options, index, routeId) => {
752
+ const svmTx = tx?.svmTx;
753
+ if (!svmTx?.chainId) {
754
+ throw new Error("executeSvmTransaction error: chainId not found in svmTx");
755
+ }
756
+ const signedTx = await signSvmTransaction({ tx, options, index, routeId });
757
+ if (!signedTx) {
758
+ throw new Error("executeSvmTransaction error: signedTx is undefined");
759
+ }
760
+ const endpoint = await chunk4ZIVDKQN_cjs.getRpcEndpointForChain(svmTx.chainId);
761
+ const connection = new web3_js.Connection(endpoint);
762
+ let signature;
763
+ const submitTxResponse = await chunkJRXPJ45U_cjs.submitTransaction({
764
+ chainId: svmTx.chainId,
765
+ tx: signedTx.toString("base64")
766
+ });
767
+ signature = submitTxResponse?.txHash;
768
+ const rpcSig = await connection.sendRawTransaction(signedTx, {
769
+ preflightCommitment: "confirmed",
770
+ maxRetries: 5
771
+ });
772
+ signature = rpcSig;
773
+ if (!signature) {
774
+ throw new Error("executeSvmTransaction error: signature not found");
775
+ }
776
+ let getStatusCount = 0;
777
+ let errorCount = 0;
778
+ while (true) {
779
+ try {
780
+ const status = await connection.getSignatureStatus(signature, {
781
+ searchTransactionHistory: true
782
+ });
783
+ if (status?.value?.confirmationStatus === "confirmed") {
784
+ return {
785
+ chainId: svmTx.chainId,
786
+ txHash: signature,
787
+ explorerLink: submitTxResponse?.explorerLink ?? ""
788
+ };
789
+ }
790
+ if (getStatusCount > 12) {
791
+ await chunk2QPPD3BB_cjs.wait(3e3);
792
+ throw new Error(
793
+ `executeSvmTransaction error: waiting finalized status timed out for ${signature}`
794
+ );
795
+ }
796
+ getStatusCount++;
797
+ await chunk2QPPD3BB_cjs.wait(3e3);
798
+ } catch (error) {
799
+ errorCount++;
800
+ if (errorCount > 12) {
801
+ throw error;
802
+ }
803
+ }
804
+ }
805
+ };
806
+ var validateEvmTokenApproval = async ({
807
+ requiredErc20Approvals,
808
+ signer,
809
+ chain,
810
+ gasBalance,
811
+ tx,
812
+ routeId,
813
+ options
814
+ }) => {
815
+ if (!signer.account?.address) {
816
+ throw new Error("validateEvmGasBalance: Signer address not found");
817
+ }
818
+ for (const requiredApproval of requiredErc20Approvals) {
819
+ const extendedSigner = signer.extend(viem.publicActions);
820
+ const allowance = await extendedSigner.readContract({
821
+ address: requiredApproval.tokenContract,
822
+ abi: erc20ABI,
823
+ functionName: "allowance",
824
+ args: [signer.account?.address, requiredApproval.spender]
825
+ });
826
+ if (allowance > BigInt(requiredApproval.amount)) {
827
+ continue;
828
+ }
829
+ const fee = await extendedSigner.estimateFeesPerGas();
830
+ const allowanceGasFee = BigInt(fee.maxFeePerGas) * BigInt(1e5);
831
+ if (!gasBalance) {
832
+ const chainAssets = (await chunkATW6UNT5_cjs.ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
833
+ const nativeAsset = chainAssets?.find((x) => x.denom.includes("-native"));
834
+ const zeroAddressAsset = chainAssets?.find(
835
+ (x) => x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
836
+ );
837
+ const asset = nativeAsset || zeroAddressAsset;
838
+ if (!asset?.decimals) {
839
+ throw new Error(
840
+ `Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei.`
841
+ );
842
+ }
843
+ const formattedGasAmount = viem.formatUnits(allowanceGasFee, asset?.decimals);
844
+ throw new Error(
845
+ `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`
846
+ );
847
+ }
848
+ if (bignumber_js.BigNumber(gasBalance.amount).lt(Number(allowanceGasFee))) {
849
+ const chainAssets = (await chunkATW6UNT5_cjs.ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
850
+ const asset = chainAssets?.find(
851
+ (x) => x.denom.includes("-native") || x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
852
+ );
853
+ if (!asset?.decimals) {
854
+ return {
855
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei but only have ${gasBalance.amount} gwei.`,
856
+ asset: null,
857
+ fee: null
858
+ };
859
+ }
860
+ const formattedGasAmount = viem.formatUnits(allowanceGasFee, asset?.decimals);
861
+ return {
862
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
863
+ asset: null,
864
+ fee: null
865
+ };
866
+ }
867
+ const { onApproveAllowance, useUnlimitedApproval } = options;
868
+ onApproveAllowance?.({
869
+ status: "pending",
870
+ allowance: requiredApproval
871
+ });
872
+ chunkA3UNNRKD_cjs.updateRouteDetails({
873
+ status: "allowance",
874
+ routeId,
875
+ options
876
+ });
877
+ const txHash = await extendedSigner.writeContract({
878
+ account: signer.account,
879
+ address: requiredApproval.tokenContract,
880
+ abi: erc20ABI,
881
+ functionName: "approve",
882
+ args: [
883
+ requiredApproval.spender,
884
+ useUnlimitedApproval ? viem.maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
885
+ ],
886
+ chain: signer.chain
887
+ });
888
+ const receipt = await extendedSigner.waitForTransactionReceipt({
889
+ hash: txHash
890
+ });
891
+ if (receipt.status === "reverted") {
892
+ throw new Error(
893
+ `executeEVMTransaction error: evm tx reverted for hash ${receipt.transactionHash}`
894
+ );
895
+ }
896
+ onApproveAllowance?.({
897
+ status: "completed"
898
+ });
899
+ chunkA3UNNRKD_cjs.updateRouteDetails({
900
+ status: "signing",
901
+ routeId,
902
+ options
903
+ });
904
+ }
905
+ };
906
+
907
+ // src/private-functions/evm/validateEvmGasBalance.ts
908
+ var validateEvmGasBalance = async ({
909
+ signer,
910
+ tx,
911
+ getFallbackGasAmount,
912
+ options,
913
+ routeId
914
+ }) => {
915
+ const chainId = tx?.chainId ?? "";
916
+ const skipAssets = (await chunkATW6UNT5_cjs.ClientState.getSkipAssets({ chainId }))?.[chainId];
917
+ const skipChains = await chunkATW6UNT5_cjs.ClientState.getSkipChains();
918
+ const chain = skipChains?.find?.((chain2) => chain2.chainId === chainId);
919
+ if (!chain) {
920
+ throw new Error(`failed to find chain for chainId: '${chainId}'`);
921
+ }
922
+ if (!signer.account?.address) {
923
+ throw new Error("validateEvmGasBalance: Signer address not found");
924
+ }
925
+ const skipBalances = (await chunkATW6UNT5_cjs.balances({
926
+ chains: {
927
+ [tx?.chainId ?? ""]: {
928
+ address: signer.account?.address
929
+ }
930
+ }
931
+ }))?.chains?.[tx?.chainId ?? ""]?.denoms;
932
+ const nativeGasBalance = skipBalances && Object.entries(skipBalances).find(([denom]) => denom.includes("-native"))?.[1];
933
+ const zeroAddressGasBalance = skipBalances && Object.entries(skipBalances).find(
934
+ ([denom]) => denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
935
+ )?.[1];
936
+ const gasBalance = nativeGasBalance || zeroAddressGasBalance;
937
+ const { requiredErc20Approvals } = tx;
938
+ const { bypassApprovalCheck } = options;
939
+ if (!bypassApprovalCheck && requiredErc20Approvals) {
940
+ try {
941
+ await validateEvmTokenApproval({
942
+ requiredErc20Approvals,
943
+ signer,
944
+ chain,
945
+ gasBalance,
946
+ tx,
947
+ routeId,
948
+ options
949
+ });
950
+ } catch (error) {
951
+ const err = error;
952
+ return {
953
+ error: err.message,
954
+ asset: null,
955
+ fee: null
956
+ };
957
+ }
958
+ }
959
+ const gasAmount = await chunkF3EB2AQG_cjs.getEVMGasAmountForMessage(signer, tx, getFallbackGasAmount);
960
+ if (!gasBalance) {
961
+ const nativeAsset = skipAssets?.find((x) => x.denom?.includes("-native"));
962
+ const zeroAddressAsset = skipAssets?.find(
963
+ (x) => x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
964
+ );
965
+ const asset = nativeAsset || zeroAddressAsset;
966
+ if (!asset?.decimals) {
967
+ return {
968
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei.`,
969
+ asset: null,
970
+ fee: null
971
+ };
972
+ }
973
+ const formattedGasAmount = viem.formatUnits(gasAmount, asset?.decimals);
974
+ return {
975
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`,
976
+ asset: null,
977
+ fee: null
978
+ };
979
+ }
980
+ if (bignumber_js.BigNumber(gasBalance.amount ?? "").lt(Number(gasAmount))) {
981
+ const asset = skipAssets?.find(
982
+ (x) => x.denom?.includes("-native") || x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
983
+ );
984
+ if (!asset?.decimals) {
985
+ return {
986
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei but only have ${gasBalance.amount} gwei.`,
987
+ asset: null,
988
+ fee: null
989
+ };
990
+ }
991
+ const formattedGasAmount = viem.formatUnits(gasAmount, asset?.decimals);
992
+ return {
993
+ error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
994
+ asset: null,
995
+ fee: null
996
+ };
997
+ }
998
+ };
999
+ var validateSvmGasBalance = async ({
1000
+ tx,
1001
+ simulate
1002
+ }) => {
1003
+ if (!tx) throw new Error("Transaction is required");
1004
+ if (simulate === false) {
1005
+ return {
1006
+ success: true,
1007
+ logs: [],
1008
+ error: null,
1009
+ asset: null,
1010
+ fee: null
1011
+ };
1012
+ }
1013
+ const endpoint = await chunk4ZIVDKQN_cjs.getRpcEndpointForChain(tx.chainId ?? "");
1014
+ const connection = new web3_js.Connection(endpoint);
1015
+ if (!connection) throw new Error(`Failed to connect to ${tx.chainId}`);
1016
+ if (!tx.tx) {
1017
+ throw new Error("Transaction is required");
1018
+ }
1019
+ const txBuffer = Buffer.from(tx.tx, "base64");
1020
+ let transaction;
1021
+ try {
1022
+ transaction = web3_js.Transaction.from(txBuffer);
1023
+ } catch (decodeError) {
1024
+ return {
1025
+ success: false,
1026
+ error: { decodeError: decodeError.message },
1027
+ asset: null,
1028
+ fee: null
1029
+ };
1030
+ }
1031
+ const simulation = await connection.simulateTransaction(transaction);
1032
+ if (simulation.value.err) {
1033
+ const logs = simulation.value.logs ?? [];
1034
+ const shortfall = getSolShortfall(logs);
1035
+ const insufficientLamports = logs.some((log) => log.includes("insufficient lamports")) && shortfall !== null;
1036
+ const insufficientFundsForRent = Object.keys(simulation.value.err).includes(
1037
+ "InsufficientFundsForRent"
1038
+ );
1039
+ const errMsg = insufficientLamports ? `Insufficient balance for gas on Solana. You need ${shortfall.toFixed(6)} SOL to proceed.` : insufficientFundsForRent ? "Insufficient funds for rent on Solana. You need to fund your account." : "Simulation failed";
1040
+ return {
1041
+ success: false,
1042
+ logs,
1043
+ error: errMsg,
1044
+ asset: null,
1045
+ fee: null
1046
+ };
1047
+ }
1048
+ return {
1049
+ success: true,
1050
+ logs: simulation.value.logs ?? [],
1051
+ error: null,
1052
+ asset: null,
1053
+ fee: null
1054
+ };
1055
+ };
1056
+ function getSolShortfall(logs) {
1057
+ const line = logs.find((l) => l.includes("insufficient lamports"));
1058
+ if (!line) return null;
1059
+ const m = line.match(/insufficient lamports (\d+), need (\d+)/);
1060
+ if (!m) return null;
1061
+ const have = parseInt(m[1] ?? "0", 10);
1062
+ const need = parseInt(m[2] ?? "0", 10);
1063
+ const shortfallLamports = need - have;
1064
+ return shortfallLamports / web3_js.LAMPORTS_PER_SOL;
1065
+ }
1066
+
1067
+ // src/private-functions/validateGasBalances.ts
1068
+ var validateGasBalances = async ({
1069
+ txs,
1070
+ onValidateGasBalance,
1071
+ getFallbackGasAmount,
1072
+ getCosmosSigner,
1073
+ getEvmSigner,
1074
+ simulate,
1075
+ disabledChainIds,
1076
+ enabledChainIds,
1077
+ getCosmosPriorityFeeDenom,
1078
+ routeId,
1079
+ options,
1080
+ isMultiRoutes
1081
+ }) => {
1082
+ const validateResult = await Promise.all(
1083
+ txs.map(async (tx, i) => {
1084
+ if (!tx) {
1085
+ throw new Error(`invalid tx at index ${i}`);
1086
+ }
1087
+ if ("cosmosTx" in tx && !disabledChainIds?.includes(tx?.cosmosTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.cosmosTx?.chainId ?? ""))) {
1088
+ onValidateGasBalance?.({
1089
+ status: "pending"
1090
+ });
1091
+ chunkA3UNNRKD_cjs.updateRouteDetails({
1092
+ status: "validating",
1093
+ routeId,
1094
+ options
1095
+ });
1096
+ if (!tx?.cosmosTx?.msgs) {
1097
+ throw new Error(`invalid msgs ${tx?.cosmosTx?.msgs}`);
1098
+ }
1099
+ try {
1100
+ const res = await chunkIUMMXFGP_cjs.validateCosmosGasBalance({
1101
+ chainId: tx.cosmosTx.chainId ?? "",
1102
+ signerAddress: tx.cosmosTx.signerAddress ?? "",
1103
+ messages: tx.cosmosTx.msgs,
1104
+ getFallbackGasAmount,
1105
+ getOfflineSigner: getCosmosSigner,
1106
+ txIndex: i,
1107
+ simulate,
1108
+ getCosmosPriorityFeeDenom,
1109
+ isMultiRoutes
1110
+ });
1111
+ return res;
1112
+ } catch (e) {
1113
+ const error = e;
1114
+ return {
1115
+ error: error.message,
1116
+ asset: null,
1117
+ fee: null
1118
+ };
1119
+ }
1120
+ }
1121
+ if ("evmTx" in tx && !disabledChainIds?.includes(tx?.evmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.evmTx?.chainId ?? ""))) {
1122
+ onValidateGasBalance?.({
1123
+ status: "pending"
1124
+ });
1125
+ chunkA3UNNRKD_cjs.updateRouteDetails({
1126
+ status: "validating",
1127
+ routeId,
1128
+ options
1129
+ });
1130
+ const signer = await getEvmSigner?.(tx?.evmTx?.chainId ?? "");
1131
+ if (!signer) {
1132
+ throw new Error(
1133
+ `failed to get signer for chain ${tx?.evmTx?.chainId}`
1134
+ );
1135
+ }
1136
+ try {
1137
+ const res = await validateEvmGasBalance({
1138
+ tx: tx.evmTx,
1139
+ signer,
1140
+ getFallbackGasAmount,
1141
+ routeId,
1142
+ options
1143
+ });
1144
+ return res;
1145
+ } catch (e) {
1146
+ const error = e;
1147
+ return {
1148
+ error: error.message,
1149
+ asset: null,
1150
+ fee: null
1151
+ };
1152
+ }
1153
+ }
1154
+ if ("svmTx" in tx && !disabledChainIds?.includes(tx?.svmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.svmTx?.chainId ?? ""))) {
1155
+ onValidateGasBalance?.({
1156
+ status: "pending"
1157
+ });
1158
+ chunkA3UNNRKD_cjs.updateRouteDetails({
1159
+ status: "validating",
1160
+ routeId,
1161
+ options
1162
+ });
1163
+ try {
1164
+ const res = await validateSvmGasBalance({
1165
+ tx: tx.svmTx,
1166
+ simulate
1167
+ });
1168
+ return res;
1169
+ } catch (e) {
1170
+ const error = e;
1171
+ return {
1172
+ error: error.message,
1173
+ asset: null,
1174
+ fee: null
1175
+ };
1176
+ }
1177
+ }
1178
+ })
1179
+ );
1180
+ if (validateResult.filter(Boolean).length === 0) {
1181
+ return;
1182
+ }
1183
+ const txError = validateResult.find((res) => res && res?.error !== null);
1184
+ if (txError) {
1185
+ onValidateGasBalance?.({
1186
+ status: "error"
1187
+ });
1188
+ chunkATW6UNT5_cjs.ClientState.validateGasResults = validateResult;
1189
+ throw new Error(`${txError.error}`);
1190
+ }
1191
+ onValidateGasBalance?.({
1192
+ status: "completed"
1193
+ });
1194
+ chunkATW6UNT5_cjs.ClientState.validateGasResults = validateResult;
1195
+ };
1196
+
1197
+ // src/private-functions/getChainIdsFromTxs.ts
1198
+ var getChainIdsFromTxs = (txs) => {
1199
+ return txs.map((tx) => {
1200
+ if ("cosmosTx" in tx) {
1201
+ return {
1202
+ chainType: "cosmos" /* Cosmos */,
1203
+ chainId: tx.cosmosTx?.chainId
1204
+ };
1205
+ }
1206
+ if ("svmTx" in tx) {
1207
+ return {
1208
+ chainType: "svm" /* Svm */,
1209
+ chainId: tx.svmTx?.chainId
1210
+ };
1211
+ }
1212
+ if ("evmTx" in tx) {
1213
+ return {
1214
+ chainType: "evm" /* Evm */,
1215
+ chainId: tx.evmTx?.chainId
1216
+ };
1217
+ }
1218
+ });
1219
+ };
1220
+
1221
+ // src/private-functions/executeTransactions.ts
1222
+ var executeTransactions = async (options) => {
1223
+ const {
1224
+ txs,
1225
+ onTransactionBroadcast,
1226
+ simulate = true,
1227
+ batchSimulate = true,
1228
+ getFallbackGasAmount = getDefaultFallbackGasAmount,
1229
+ getCosmosSigner,
1230
+ getEvmSigner,
1231
+ onValidateGasBalance,
1232
+ trackTxPollingOptions,
1233
+ batchSignTxs = true,
1234
+ routeId,
1235
+ isMultiRoutes
1236
+ } = options;
1237
+ if (txs === void 0) {
1238
+ throw new Error(
1239
+ "executeTransactions error: txs is undefined in executeTransactions"
1240
+ );
1241
+ }
1242
+ const chainIds = getChainIdsFromTxs(txs);
1243
+ const transactionDetails = txs.map((tx) => {
1244
+ if ("cosmosTx" in tx) {
1245
+ return { chainId: tx.cosmosTx?.chainId, chainType: "cosmos" /* Cosmos */ };
1246
+ } else if ("evmTx" in tx) {
1247
+ return { chainId: tx.evmTx?.chainId, chainType: "evm" /* Evm */ };
1248
+ } else if ("svmTx" in tx) {
1249
+ return { chainId: tx.svmTx?.chainId, chainType: "svm" /* Svm */ };
1250
+ } else {
1251
+ throw new Error("executeRoute error: invalid message type");
1252
+ }
1253
+ });
1254
+ chunkA3UNNRKD_cjs.updateRouteDetails({
1255
+ transactionDetails,
1256
+ routeId,
1257
+ options
1258
+ });
1259
+ chunkATW6UNT5_cjs.ClientState.validateGasResults = void 0;
1260
+ const validateChainIds = !batchSimulate ? chainIds.map((x) => x?.chainId ?? "") : [];
1261
+ await validateGasBalances({
1262
+ txs,
1263
+ getFallbackGasAmount,
1264
+ getCosmosSigner,
1265
+ getEvmSigner,
1266
+ onValidateGasBalance,
1267
+ simulate,
1268
+ disabledChainIds: validateChainIds,
1269
+ getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
1270
+ options,
1271
+ routeId,
1272
+ isMultiRoutes
1273
+ });
1274
+ const validateEnabledChainIds = async (chainId) => {
1275
+ await validateGasBalances({
1276
+ txs,
1277
+ getFallbackGasAmount,
1278
+ getCosmosSigner,
1279
+ getEvmSigner,
1280
+ onValidateGasBalance,
1281
+ simulate,
1282
+ enabledChainIds: !batchSimulate ? [chainId] : validateChainIds,
1283
+ getCosmosPriorityFeeDenom: options.getCosmosPriorityFeeDenom,
1284
+ options,
1285
+ routeId,
1286
+ isMultiRoutes
1287
+ });
1288
+ };
1289
+ let signedTxs = [];
1290
+ if (batchSignTxs) {
1291
+ for (let i = 0; i < txs.length; i++) {
1292
+ const tx = txs[i];
1293
+ if (!tx) {
1294
+ throw new Error(`executeRoute error: invalid message at index ${i}`);
1295
+ }
1296
+ if ("cosmosTx" in tx) {
1297
+ await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
1298
+ const isAllowedToBatchSignTxsUpfront = await (async () => {
1299
+ try {
1300
+ const currentUserAddress = options.userAddresses.find(
1301
+ (x) => x.chainId === tx.cosmosTx?.chainId
1302
+ )?.address;
1303
+ if (!currentUserAddress) {
1304
+ return false;
1305
+ }
1306
+ const { accountNumber } = await getAccountNumberAndSequence(
1307
+ currentUserAddress,
1308
+ tx.cosmosTx?.chainId
1309
+ );
1310
+ if (accountNumber) {
1311
+ return true;
1312
+ }
1313
+ return false;
1314
+ } catch (_error) {
1315
+ return false;
1316
+ }
1317
+ })();
1318
+ if (!isAllowedToBatchSignTxsUpfront) {
1319
+ continue;
1320
+ }
1321
+ const signedTx = await signCosmosTransaction({
1322
+ tx,
1323
+ options,
1324
+ index: i,
1325
+ routeId
1326
+ });
1327
+ signedTxs.push({
1328
+ index: i,
1329
+ chainId: tx.cosmosTx?.chainId ?? "",
1330
+ tx: signedTx,
1331
+ chainType: "cosmos" /* Cosmos */
1332
+ });
1333
+ }
1334
+ if ("svmTx" in tx) {
1335
+ await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
1336
+ const signedTx = await signSvmTransaction({
1337
+ tx,
1338
+ options,
1339
+ index: i,
1340
+ routeId
1341
+ });
1342
+ if (!signedTx) {
1343
+ throw new Error(`executeRoute error: signedTx is undefined`);
1344
+ }
1345
+ signedTxs.push({
1346
+ index: i,
1347
+ chainId: tx.svmTx?.chainId ?? "",
1348
+ tx: signedTx.toString("base64"),
1349
+ chainType: "svm" /* Svm */
1350
+ });
1351
+ }
1352
+ }
1353
+ }
1354
+ const executeTransaction = async (index) => {
1355
+ const tx = txs[index];
1356
+ if (!tx) {
1357
+ throw new Error(`executeRoute error: invalid message at index ${index}`);
1358
+ }
1359
+ let txResult;
1360
+ const txSigned = signedTxs.find((item) => item.index === index);
1361
+ if (txSigned) {
1362
+ const txResponse = await chunkJRXPJ45U_cjs.submitTransaction({
1363
+ chainId: txSigned.chainId,
1364
+ tx: txSigned.tx
1365
+ });
1366
+ txResult = {
1367
+ chainId: txSigned.chainId,
1368
+ txHash: txResponse?.txHash ?? "",
1369
+ explorerLink: txResponse?.explorerLink ?? ""
1370
+ };
1371
+ } else {
1372
+ if ("cosmosTx" in tx) {
1373
+ await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
1374
+ txResult = await executeCosmosTransaction({
1375
+ tx,
1376
+ options,
1377
+ index,
1378
+ routeId
1379
+ });
1380
+ } else if ("evmTx" in tx) {
1381
+ await validateEnabledChainIds(tx.evmTx?.chainId ?? "");
1382
+ const txResponse = await executeEvmTransaction(
1383
+ tx,
1384
+ options,
1385
+ index,
1386
+ routeId
1387
+ );
1388
+ txResult = {
1389
+ chainId: tx?.evmTx?.chainId ?? "",
1390
+ txHash: txResponse.transactionHash
1391
+ };
1392
+ } else if ("svmTx" in tx) {
1393
+ await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
1394
+ txResult = await executeSvmTransaction(tx, options, index, routeId);
1395
+ } else {
1396
+ throw new Error("executeRoute error: invalid message type");
1397
+ }
1398
+ }
1399
+ await onTransactionBroadcast?.({ ...txResult });
1400
+ return txResult;
1401
+ };
1402
+ return {
1403
+ transactionDetails,
1404
+ executeTransaction
1405
+ };
1406
+ };
1407
+ var EVM_GAS_AMOUNT = 15e4;
1408
+ var COSMOS_GAS_AMOUNT = {
1409
+ DEFAULT: 3e5,
1410
+ SWAP: 28e5,
1411
+ CARBON: 1e6
1412
+ };
1413
+ var getDefaultFallbackGasAmount = async (chainId, chainType) => {
1414
+ if (chainType === "evm" /* Evm */) {
1415
+ return EVM_GAS_AMOUNT;
1416
+ }
1417
+ if (chainType !== "cosmos" /* Cosmos */) return void 0;
1418
+ const venuesResult = await chunkFCTBCHOT_cjs.venues();
1419
+ const isSwapChain = venuesResult?.some(
1420
+ (venue) => venue.chainId === chainId
1421
+ ) ?? false;
1422
+ const defaultGasAmount = Math.ceil(
1423
+ isSwapChain ? COSMOS_GAS_AMOUNT.SWAP : COSMOS_GAS_AMOUNT.DEFAULT
1424
+ );
1425
+ if (chainId === "carbon-1") {
1426
+ return COSMOS_GAS_AMOUNT.CARBON;
1427
+ }
1428
+ return defaultGasAmount;
1429
+ };
1430
+ var validateUserAddresses = async (userAddresses) => {
1431
+ const chains2 = await chunkATW6UNT5_cjs.ClientState.getSkipChains();
1432
+ const validations = userAddresses.map((userAddress) => {
1433
+ const chain = chains2.find((chain2) => chain2.chainId === userAddress.chainId);
1434
+ switch (chain?.chainType) {
1435
+ case "cosmos" /* Cosmos */:
1436
+ try {
1437
+ if (chain.chainId?.includes("penumbra")) {
1438
+ try {
1439
+ return chain.bech32Prefix === bech32.bech32m.decode(userAddress.address, 143)?.prefix;
1440
+ } catch {
1441
+ return ["penumbracompat1", "tpenumbra"].includes(
1442
+ bech32.bech32.decode(userAddress.address, 1023).prefix
1443
+ );
1444
+ }
1445
+ }
1446
+ return chain.bech32Prefix === bech32.bech32.decode(userAddress.address, 1023).prefix;
1447
+ } catch {
1448
+ return false;
1449
+ }
1450
+ case "evm" /* Evm */:
1451
+ try {
1452
+ return viem.isAddress(userAddress.address);
1453
+ } catch (_error) {
1454
+ return false;
1455
+ }
1456
+ case "svm" /* Svm */:
1457
+ try {
1458
+ const publicKey = new web3_js.PublicKey(userAddress.address);
1459
+ return web3_js.PublicKey.isOnCurve(publicKey);
1460
+ } catch (_error) {
1461
+ return false;
1462
+ }
1463
+ default:
1464
+ return false;
1465
+ }
1466
+ });
1467
+ return validations.every((validation) => validation);
1468
+ };
1469
+ var createValidAddressList = async ({
1470
+ userAddresses,
1471
+ route
1472
+ }) => {
1473
+ let addressList = [];
1474
+ userAddresses.forEach((userAddress, index) => {
1475
+ const requiredChainAddress = route.requiredChainAddresses[index];
1476
+ if (requiredChainAddress === userAddress?.chainId) {
1477
+ addressList.push(userAddress.address);
1478
+ }
1479
+ });
1480
+ if (addressList.length !== route.requiredChainAddresses.length) {
1481
+ addressList = userAddresses.map((x) => x.address);
1482
+ }
1483
+ const validLength = addressList.length === route.requiredChainAddresses.length || addressList.length === route.chainIds?.length;
1484
+ if (!validLength) {
1485
+ throw new Error("createValidAddressList error: invalid address list");
1486
+ }
1487
+ const isUserAddressesValid = await validateUserAddresses(userAddresses);
1488
+ if (!isUserAddressesValid) {
1489
+ throw new Error("createValidAddressList error: invalid user addresses");
1490
+ }
1491
+ return addressList;
1492
+ };
1493
+
1494
+ exports.createValidAddressList = createValidAddressList;
1495
+ exports.executeTransactions = executeTransactions;