@skip-go/client 1.6.0-alpha.1 → 1.6.0-alpha.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.
Files changed (158) hide show
  1. package/package.json +1 -1
  2. package/dist/cjs/api/getAssets.cjs +0 -16
  3. package/dist/cjs/api/getAssetsBetweenChains.cjs +0 -12
  4. package/dist/cjs/api/getBridges.cjs +0 -12
  5. package/dist/cjs/api/getChains.cjs +0 -12
  6. package/dist/cjs/api/getVenues.cjs +0 -12
  7. package/dist/cjs/api/postAssetsFromSource.cjs +0 -13
  8. package/dist/cjs/api/postBalances.cjs +0 -12
  9. package/dist/cjs/api/postIbcOriginAssets.cjs +0 -12
  10. package/dist/cjs/api/postMessages.cjs +0 -12
  11. package/dist/cjs/api/postMessagesDirect.cjs +0 -12
  12. package/dist/cjs/api/postRecommendAssets.cjs +0 -12
  13. package/dist/cjs/api/postRoute.cjs +0 -12
  14. package/dist/cjs/api/postSubmitTransaction.cjs +0 -12
  15. package/dist/cjs/api/postTrackTransaction.cjs +0 -12
  16. package/dist/cjs/api/postTransactionStatus.cjs +0 -12
  17. package/dist/cjs/chunk-2QPPD3BB.cjs +0 -210
  18. package/dist/cjs/chunk-2SA3OAIJ.cjs +0 -18
  19. package/dist/cjs/chunk-4BWE7SOV.cjs +0 -68
  20. package/dist/cjs/chunk-4GHUZDDP.cjs +0 -16
  21. package/dist/cjs/chunk-4ZIVDKQN.cjs +0 -387
  22. package/dist/cjs/chunk-A3UNNRKD.cjs +0 -574
  23. package/dist/cjs/chunk-A5S6SIYN.cjs +0 -12
  24. package/dist/cjs/chunk-AQTXZWLA.cjs +0 -55
  25. package/dist/cjs/chunk-ASDMDYTC.cjs +0 -11
  26. package/dist/cjs/chunk-ATW6UNT5.cjs +0 -136
  27. package/dist/cjs/chunk-AUTOIM57.cjs +0 -22
  28. package/dist/cjs/chunk-AVWWCQ5P.cjs +0 -2264
  29. package/dist/cjs/chunk-CIZTNJ3K.cjs +0 -24
  30. package/dist/cjs/chunk-CK6CQWQU.cjs +0 -49
  31. package/dist/cjs/chunk-EAZQ2ECA.cjs +0 -185
  32. package/dist/cjs/chunk-F3EB2AQG.cjs +0 -28
  33. package/dist/cjs/chunk-FCTBCHOT.cjs +0 -12
  34. package/dist/cjs/chunk-GDDD6R2X.cjs +0 -459
  35. package/dist/cjs/chunk-IJIBMN2F.cjs +0 -12
  36. package/dist/cjs/chunk-JRXPJ45U.cjs +0 -12
  37. package/dist/cjs/chunk-LJF74VNZ.cjs +0 -214
  38. package/dist/cjs/chunk-LJV45UGL.cjs +0 -582
  39. package/dist/cjs/chunk-MUJBB64F.cjs +0 -291
  40. package/dist/cjs/chunk-NCFH5MGF.cjs +0 -39
  41. package/dist/cjs/chunk-NM4PISTQ.cjs +0 -3359
  42. package/dist/cjs/chunk-OJISEAMX.cjs +0 -13
  43. package/dist/cjs/chunk-OVKHTOBP.cjs +0 -99
  44. package/dist/cjs/chunk-PDNKS5R2.cjs +0 -13
  45. package/dist/cjs/chunk-TEH6UMUR.cjs +0 -280
  46. package/dist/cjs/chunk-UXW4XVHF.cjs +0 -15
  47. package/dist/cjs/chunk-WVMDZODS.cjs +0 -1495
  48. package/dist/cjs/chunk-YX56UXDX.cjs +0 -189
  49. package/dist/cjs/index.cjs +0 -349
  50. package/dist/cjs/public-functions/executeMultipleRoutes.cjs +0 -27
  51. package/dist/cjs/public-functions/executeRoute.cjs +0 -27
  52. package/dist/cjs/public-functions/getCosmosGasAmountForMessage.cjs +0 -16
  53. package/dist/cjs/public-functions/getEvmGasAmountForMessage.cjs +0 -11
  54. package/dist/cjs/public-functions/getFeeInfoForChain.cjs +0 -14
  55. package/dist/cjs/public-functions/getRecommendedGasPrice.cjs +0 -15
  56. package/dist/cjs/public-functions/getRouteWithGasOnReceive.cjs +0 -41
  57. package/dist/cjs/public-functions/getSigningStargateClient.cjs +0 -15
  58. package/dist/cjs/public-functions/setApiOptions.cjs +0 -12
  59. package/dist/cjs/public-functions/setClientOptions.cjs +0 -16
  60. package/dist/cjs/public-functions/subscribeToRouteStatus.cjs +0 -26
  61. package/dist/cjs/public-functions/validateCosmosGasBalance.cjs +0 -18
  62. package/dist/cjs/public-functions/waitForTransaction.cjs +0 -18
  63. package/dist/esm/api/getAssets.d.ts +0 -19
  64. package/dist/esm/api/getAssets.js +0 -3
  65. package/dist/esm/api/getAssetsBetweenChains.d.ts +0 -56
  66. package/dist/esm/api/getAssetsBetweenChains.js +0 -3
  67. package/dist/esm/api/getBridges.d.ts +0 -55
  68. package/dist/esm/api/getBridges.js +0 -3
  69. package/dist/esm/api/getChains.d.ts +0 -41
  70. package/dist/esm/api/getChains.js +0 -3
  71. package/dist/esm/api/getVenues.d.ts +0 -13
  72. package/dist/esm/api/getVenues.js +0 -3
  73. package/dist/esm/api/postAssetsFromSource.d.ts +0 -22
  74. package/dist/esm/api/postAssetsFromSource.js +0 -4
  75. package/dist/esm/api/postBalances.d.ts +0 -35
  76. package/dist/esm/api/postBalances.js +0 -3
  77. package/dist/esm/api/postIbcOriginAssets.d.ts +0 -32
  78. package/dist/esm/api/postIbcOriginAssets.js +0 -3
  79. package/dist/esm/api/postMessages.d.ts +0 -101
  80. package/dist/esm/api/postMessages.js +0 -3
  81. package/dist/esm/api/postMessagesDirect.d.ts +0 -617
  82. package/dist/esm/api/postMessagesDirect.js +0 -3
  83. package/dist/esm/api/postRecommendAssets.d.ts +0 -40
  84. package/dist/esm/api/postRecommendAssets.js +0 -3
  85. package/dist/esm/api/postRoute.d.ts +0 -507
  86. package/dist/esm/api/postRoute.js +0 -3
  87. package/dist/esm/api/postSubmitTransaction.d.ts +0 -17
  88. package/dist/esm/api/postSubmitTransaction.js +0 -3
  89. package/dist/esm/api/postTrackTransaction.d.ts +0 -12
  90. package/dist/esm/api/postTrackTransaction.js +0 -3
  91. package/dist/esm/api/postTransactionStatus.d.ts +0 -639
  92. package/dist/esm/api/postTransactionStatus.js +0 -3
  93. package/dist/esm/apiState-1VvikVK-.d.ts +0 -8
  94. package/dist/esm/callbacks-1e6BnDot.d.ts +0 -158
  95. package/dist/esm/chunk-3DIX6KRJ.js +0 -566
  96. package/dist/esm/chunk-3JHLVPRG.js +0 -10
  97. package/dist/esm/chunk-5WYMRZIO.js +0 -97
  98. package/dist/esm/chunk-6QW6MRVQ.js +0 -53
  99. package/dist/esm/chunk-A4HQEGYV.js +0 -432
  100. package/dist/esm/chunk-A5NZMSTI.js +0 -10
  101. package/dist/esm/chunk-CGJRRAFS.js +0 -22
  102. package/dist/esm/chunk-DMJMN4J3.js +0 -379
  103. package/dist/esm/chunk-E4NRDAVO.js +0 -65
  104. package/dist/esm/chunk-ETBJVFQP.js +0 -10
  105. package/dist/esm/chunk-F2LQB2DP.js +0 -3323
  106. package/dist/esm/chunk-F66EKL3W.js +0 -203
  107. package/dist/esm/chunk-GV2QOWB4.js +0 -26
  108. package/dist/esm/chunk-GZJLX2CP.js +0 -2258
  109. package/dist/esm/chunk-HNU2Y3JI.js +0 -13
  110. package/dist/esm/chunk-J24LYWJE.js +0 -130
  111. package/dist/esm/chunk-KZKAL5ZN.js +0 -16
  112. package/dist/esm/chunk-N4PTRCNT.js +0 -11
  113. package/dist/esm/chunk-NUHMTWHP.js +0 -180
  114. package/dist/esm/chunk-OMOVHXSC.js +0 -212
  115. package/dist/esm/chunk-P36PE4CR.js +0 -37
  116. package/dist/esm/chunk-PZ2624FK.js +0 -187
  117. package/dist/esm/chunk-QYXGDTUU.js +0 -47
  118. package/dist/esm/chunk-R2GHDOWX.js +0 -272
  119. package/dist/esm/chunk-RTDD7HZ3.js +0 -275
  120. package/dist/esm/chunk-SXBG57J3.js +0 -20
  121. package/dist/esm/chunk-TGTOO2ZQ.js +0 -14
  122. package/dist/esm/chunk-UHCKOKBM.js +0 -9
  123. package/dist/esm/chunk-ULUX2CVU.js +0 -557
  124. package/dist/esm/chunk-UN46DUOV.js +0 -11
  125. package/dist/esm/chunk-XNU3TKKM.js +0 -10
  126. package/dist/esm/chunk-ZVFYCNA5.js +0 -1492
  127. package/dist/esm/client-types-Bz-WqtM3.d.ts +0 -114
  128. package/dist/esm/generateApi-Bi3W_Sti.d.ts +0 -56
  129. package/dist/esm/index.d.ts +0 -1859
  130. package/dist/esm/index.js +0 -32
  131. package/dist/esm/public-functions/executeMultipleRoutes.d.ts +0 -80
  132. package/dist/esm/public-functions/executeMultipleRoutes.js +0 -18
  133. package/dist/esm/public-functions/executeRoute.d.ts +0 -12
  134. package/dist/esm/public-functions/executeRoute.js +0 -18
  135. package/dist/esm/public-functions/getCosmosGasAmountForMessage.d.ts +0 -8
  136. package/dist/esm/public-functions/getCosmosGasAmountForMessage.js +0 -3
  137. package/dist/esm/public-functions/getEvmGasAmountForMessage.d.ts +0 -14
  138. package/dist/esm/public-functions/getEvmGasAmountForMessage.js +0 -2
  139. package/dist/esm/public-functions/getFeeInfoForChain.d.ts +0 -9
  140. package/dist/esm/public-functions/getFeeInfoForChain.js +0 -5
  141. package/dist/esm/public-functions/getRecommendedGasPrice.d.ts +0 -9
  142. package/dist/esm/public-functions/getRecommendedGasPrice.js +0 -6
  143. package/dist/esm/public-functions/getRouteWithGasOnReceive.d.ts +0 -20
  144. package/dist/esm/public-functions/getRouteWithGasOnReceive.js +0 -32
  145. package/dist/esm/public-functions/getSigningStargateClient.d.ts +0 -13
  146. package/dist/esm/public-functions/getSigningStargateClient.js +0 -6
  147. package/dist/esm/public-functions/setApiOptions.d.ts +0 -9
  148. package/dist/esm/public-functions/setApiOptions.js +0 -3
  149. package/dist/esm/public-functions/setClientOptions.d.ts +0 -11
  150. package/dist/esm/public-functions/setClientOptions.js +0 -7
  151. package/dist/esm/public-functions/subscribeToRouteStatus.d.ts +0 -12
  152. package/dist/esm/public-functions/subscribeToRouteStatus.js +0 -5
  153. package/dist/esm/public-functions/validateCosmosGasBalance.d.ts +0 -44
  154. package/dist/esm/public-functions/validateCosmosGasBalance.js +0 -9
  155. package/dist/esm/public-functions/waitForTransaction.d.ts +0 -1279
  156. package/dist/esm/public-functions/waitForTransaction.js +0 -5
  157. package/dist/esm/setClientOptions-QO8p3yRr.d.ts +0 -76
  158. package/dist/esm/swaggerTypes-Cvh0GDv-.d.ts +0 -2050
@@ -1,212 +0,0 @@
1
- import { createValidAddressList, executeTransactions } from './chunk-ZVFYCNA5.js';
2
- import { updateRouteDetails, executeAndSubscribeToRouteStatus } from './chunk-3DIX6KRJ.js';
3
- import { messages } from './chunk-P36PE4CR.js';
4
- import { trackTransaction } from './chunk-SXBG57J3.js';
5
- import { ApiState } from './chunk-F66EKL3W.js';
6
-
7
- // src/public-functions/executeMultipleRoutes.ts
8
- var executeMultipleRoutes = async (options) => {
9
- const {
10
- route,
11
- userAddresses,
12
- appendCosmosMsgs,
13
- postRouteHandler,
14
- slippageTolerancePercent,
15
- ...restOptions
16
- } = options;
17
- const addressList = {};
18
- for (const [routeKey, routeValue] of Object.entries(route)) {
19
- const _userAddresses = userAddresses[routeKey];
20
- if (_userAddresses === void 0) {
21
- throw new Error(
22
- `executeMultipleRoutes error: no user addresses found for route: ${routeKey}`
23
- );
24
- }
25
- const routeAddressList = await createValidAddressList({
26
- userAddresses: _userAddresses,
27
- route: routeValue
28
- });
29
- addressList[routeKey] = routeAddressList;
30
- }
31
- const msgsResponses = await Promise.all(
32
- Object.entries(route).map(async ([routeKey, routeValue]) => {
33
- const routeAddressList = addressList[routeKey];
34
- if (routeAddressList === void 0) {
35
- throw new Error(
36
- `executeMultipleRoutes error: address list not found for route ${routeKey}`
37
- );
38
- }
39
- return await messages({
40
- timeoutSeconds: options.timeoutSeconds,
41
- amountIn: routeValue?.amountIn,
42
- amountOut: routeValue.estimatedAmountOut || "0",
43
- sourceAssetChainId: routeValue?.sourceAssetChainId,
44
- sourceAssetDenom: routeValue?.sourceAssetDenom,
45
- destAssetChainId: routeValue?.destAssetChainId,
46
- destAssetDenom: routeValue?.destAssetDenom,
47
- operations: routeValue?.operations,
48
- addressList: routeAddressList,
49
- slippageTolerancePercent: slippageTolerancePercent?.[routeKey] || "1",
50
- chainIdsToAffiliates: ApiState.chainIdsToAffiliates,
51
- postRouteHandler: postRouteHandler?.[routeKey],
52
- feePayerAddress: options.svmFeePayer?.address
53
- });
54
- })
55
- );
56
- let msgsRecord = {};
57
- msgsResponses.forEach((msg, index2) => {
58
- const routeKey = Object.keys(route)[index2];
59
- if (!routeKey) {
60
- throw new Error(
61
- `executeMultipleRoutes error: route key not found for index ${index2}`
62
- );
63
- }
64
- const addedCosmosMsgs = appendCosmosMsgs?.[routeKey];
65
- if (addedCosmosMsgs) {
66
- Object.entries(addedCosmosMsgs).forEach(([chainId, msgs]) => {
67
- const txIndex = msg?.txs?.findIndex(
68
- (tx2) => "cosmosTx" in tx2 && tx2.cosmosTx.chainId === chainId
69
- );
70
- if (txIndex === void 0 || txIndex === -1) return;
71
- const tx = msg?.txs?.[txIndex];
72
- if (tx && "cosmosTx" in tx) {
73
- tx.cosmosTx.msgs?.unshift(...msgs);
74
- }
75
- });
76
- }
77
- msgsRecord[routeKey] = msg;
78
- });
79
- let transferIndexToRouteKey = void 0;
80
- const cosmosTxIndex0Map = /* @__PURE__ */ new Map();
81
- let transferIndex = 0;
82
- for (const [routeKey, msgs] of Object.entries(msgsRecord)) {
83
- const firstTx = msgs?.txs?.[0];
84
- if (firstTx && "cosmosTx" in firstTx) {
85
- const { chainId, msgs: firstTxMsgs } = firstTx.cosmosTx;
86
- if (!transferIndexToRouteKey) {
87
- transferIndexToRouteKey = {};
88
- }
89
- transferIndexToRouteKey[transferIndex] = routeKey;
90
- transferIndex++;
91
- if (!cosmosTxIndex0Map.has(chainId)) {
92
- cosmosTxIndex0Map.set(chainId, {
93
- routeKey,
94
- firstCosmosTx: firstTx.cosmosTx
95
- });
96
- } else {
97
- const existing = cosmosTxIndex0Map.get(chainId);
98
- if (existing && firstTxMsgs) {
99
- const modifyTarget = msgsRecord[existing.routeKey]?.txs?.[0];
100
- if (modifyTarget && "cosmosTx" in modifyTarget) {
101
- modifyTarget.cosmosTx.msgs?.push(...firstTxMsgs);
102
- msgsRecord[routeKey]?.txs?.shift();
103
- }
104
- }
105
- }
106
- }
107
- }
108
- Object.entries(msgsRecord).forEach(([routeKey, msgs]) => {
109
- if (msgs?.txs?.length === 0) {
110
- delete msgsRecord[routeKey];
111
- }
112
- });
113
- let mainRouteId = void 0;
114
- let msgsRecordIndexToRouteId = {};
115
- let index = 0;
116
- const transactionDetailsList = {};
117
- const executeTransactionList = {};
118
- const mergedMainAndSecondaryRoutes = Object.entries(msgsRecord).length !== Object.entries(route).length;
119
- for (const [routeKey, msgsResponse] of Object.entries(msgsRecord)) {
120
- const { id: routeId } = updateRouteDetails({
121
- status: "unconfirmed",
122
- options: {
123
- route: route[routeKey],
124
- ...restOptions
125
- },
126
- mainRouteId,
127
- transferIndexToRouteKey
128
- });
129
- msgsRecordIndexToRouteId[index] = routeId;
130
- if (routeKey === "mainRoute") {
131
- mainRouteId = routeId;
132
- }
133
- const { transactionDetails, executeTransaction: _executeTransaction } = await executeTransactions({
134
- ...restOptions,
135
- routeId,
136
- txs: msgsResponse?.txs,
137
- route: route[routeKey],
138
- userAddresses: userAddresses[routeKey],
139
- isMultiRoutes: true
140
- });
141
- const executeTransaction = async (index2) => {
142
- const txResult = await _executeTransaction(index2);
143
- if (routeKey !== "mainRoute" || mergedMainAndSecondaryRoutes) {
144
- const relatedRoutes = Object.entries(route).filter(([key]) => key !== "mainRoute").map(([key, route2]) => ({ route: route2, routeKey: key, status: "pending" }));
145
- updateRouteDetails({
146
- options: {
147
- route: route[routeKey],
148
- ...restOptions
149
- },
150
- routeId: mainRouteId,
151
- transferIndexToRouteKey,
152
- relatedRoutes
153
- });
154
- }
155
- return txResult;
156
- };
157
- if (transactionDetails[0]?.chainType === "evm" /* Evm */) {
158
- for (const [index2, transactionDetail] of transactionDetails.entries()) {
159
- const txResult = await executeTransaction(index2);
160
- if (txResult.txHash) {
161
- const trackResponse = await trackTransaction({
162
- chainId: transactionDetail.chainId,
163
- txHash: txResult.txHash,
164
- ...options.trackTxPollingOptions
165
- });
166
- await options?.onTransactionTracked?.({
167
- txHash: txResult.txHash,
168
- chainId: transactionDetail.chainId,
169
- explorerLink: trackResponse.explorerLink
170
- });
171
- transactionDetail.txHash = txResult.txHash;
172
- transactionDetail.explorerLink = trackResponse.explorerLink;
173
- }
174
- }
175
- } else {
176
- executeTransactionList[index] = executeTransaction;
177
- }
178
- transactionDetailsList[index] = transactionDetails;
179
- index++;
180
- }
181
- await Promise.all(
182
- Object.entries(msgsRecord).map(([routeKey, msgsResponse], index2) => {
183
- return executeAndSubscribeToRouteStatus({
184
- transactionDetails: transactionDetailsList[index2],
185
- executeTransaction: executeTransactionList[index2],
186
- routeId: msgsRecordIndexToRouteId[index2],
187
- options: {
188
- route: route[routeKey],
189
- userAddresses: userAddresses[routeKey],
190
- ...restOptions,
191
- onRouteStatusUpdated: (routeStatus) => {
192
- const relatedRoutes = Object.entries(route).filter(([key]) => key !== "mainRoute").map(([key, route2]) => ({ route: route2, routeKey: key, status: routeStatus.status }));
193
- if (routeKey !== "mainRoute") {
194
- updateRouteDetails({
195
- options: {
196
- route: route[routeKey],
197
- ...restOptions
198
- },
199
- routeId: mainRouteId,
200
- transferIndexToRouteKey,
201
- relatedRoutes
202
- });
203
- }
204
- options.onRouteStatusUpdated?.(routeStatus);
205
- }
206
- }
207
- });
208
- })
209
- );
210
- };
211
-
212
- export { executeMultipleRoutes };
@@ -1,37 +0,0 @@
1
- import { api } from './chunk-F66EKL3W.js';
2
-
3
- // src/utils/filterMessagesRequest.ts
4
- var filterMessagesRequest = (request) => {
5
- const messagesRequest = {
6
- sourceAssetDenom: request.sourceAssetDenom,
7
- sourceAssetChainId: request.sourceAssetChainId,
8
- destAssetDenom: request.destAssetDenom,
9
- destAssetChainId: request.destAssetChainId,
10
- amountIn: request.amountIn,
11
- amountOut: request.amountOut,
12
- addressList: request.addressList,
13
- operations: request.operations,
14
- estimatedAmountOut: request.estimatedAmountOut,
15
- slippageTolerancePercent: request.slippageTolerancePercent,
16
- feePayerAddress: request.feePayerAddress,
17
- timeoutSeconds: request.timeoutSeconds,
18
- postRouteHandler: request.postRouteHandler,
19
- chainIdsToAffiliates: request.chainIdsToAffiliates,
20
- enableGasWarnings: request.enableGasWarnings,
21
- apiUrl: request.apiUrl,
22
- apiKey: request.apiKey,
23
- abortDuplicateRequests: request.abortDuplicateRequests
24
- };
25
- return messagesRequest;
26
- };
27
-
28
- // src/api/postMessages.ts
29
- var messages = async (request) => {
30
- return api({
31
- methodName: "msgs",
32
- method: "post",
33
- path: "v2/fungible/msgs"
34
- })(filterMessagesRequest(request));
35
- };
36
-
37
- export { messages };
@@ -1,187 +0,0 @@
1
- import { getCosmosGasAmountForMessage } from './chunk-R2GHDOWX.js';
2
- import { getSigningStargateClient } from './chunk-DMJMN4J3.js';
3
- import { ClientState, balances } from './chunk-J24LYWJE.js';
4
- import { BigNumber } from 'bignumber.js';
5
- import { GasPrice, calculateFee } from '@cosmjs/stargate';
6
- import { Decimal } from '@cosmjs/math';
7
-
8
- var validateCosmosGasBalance = async ({
9
- chainId,
10
- signerAddress,
11
- messages,
12
- getFallbackGasAmount,
13
- getOfflineSigner,
14
- txIndex,
15
- simulate,
16
- getCosmosPriorityFeeDenom,
17
- isMultiRoutes
18
- }) => {
19
- const skipAssets = (await ClientState.getSkipAssets({ chainId }))?.[chainId];
20
- const skipChains = await ClientState.getSkipChains();
21
- const prioFeeDenom = await getCosmosPriorityFeeDenom?.(chainId);
22
- const chain = skipChains?.find((c) => c.chainId === chainId);
23
- if (!chain) {
24
- throw new Error(`failed to find chain id '${chainId}'`);
25
- }
26
- const { feeAssets } = chain;
27
- if (!feeAssets) {
28
- throw new Error(`failed to find fee assets for chain id '${chainId}'`);
29
- }
30
- const estimatedGasAmount = await (async () => {
31
- try {
32
- if (simulate === false) throw new Error("simulate");
33
- if (txIndex !== 0 && chainId === "noble-1") {
34
- return "0";
35
- }
36
- const { stargateClient } = await getSigningStargateClient({
37
- chainId,
38
- getOfflineSigner
39
- });
40
- const estimatedGas = await getCosmosGasAmountForMessage(
41
- stargateClient,
42
- signerAddress,
43
- chainId,
44
- messages
45
- );
46
- return estimatedGas;
47
- } catch (e) {
48
- const error = e;
49
- if (error.message === "simulate" && !getFallbackGasAmount) {
50
- throw new Error(`unable to get gas amount for ${chainId}'s message(s)`);
51
- }
52
- if (getFallbackGasAmount) {
53
- const fallbackGasAmount = await getFallbackGasAmount(
54
- chainId,
55
- "cosmos" /* Cosmos */
56
- );
57
- if (!fallbackGasAmount) {
58
- throw new Error(`unable to estimate gas for message(s) ${messages}`);
59
- }
60
- return String(fallbackGasAmount);
61
- }
62
- throw error;
63
- }
64
- })();
65
- const fees = feeAssets.map((asset) => {
66
- const gasPrice = (() => {
67
- if (!asset?.gasPrice) return void 0;
68
- let price = asset.gasPrice.average;
69
- if (price === "") {
70
- price = asset.gasPrice.high;
71
- }
72
- if (price === "") {
73
- price = asset.gasPrice.low;
74
- }
75
- if (!price) return;
76
- return new GasPrice(
77
- Decimal.fromUserInput(BigNumber(price).toFixed(), 18),
78
- asset?.denom ?? ""
79
- );
80
- })();
81
- if (!gasPrice) {
82
- return null;
83
- }
84
- if (chainId === "noble-1") {
85
- if (isMultiRoutes && txIndex === 0) {
86
- return calculateFee(
87
- Math.ceil(parseFloat(estimatedGasAmount)),
88
- gasPrice
89
- );
90
- }
91
- if (asset.denom.toLowerCase() === "ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0".toLowerCase()) {
92
- const fee2 = calculateFee(2e6, gasPrice);
93
- return fee2;
94
- }
95
- const fee = calculateFee(2e5, gasPrice);
96
- return fee;
97
- }
98
- return calculateFee(Math.ceil(parseFloat(estimatedGasAmount)), gasPrice);
99
- });
100
- const feeBalance = await balances({
101
- chains: {
102
- [chainId]: {
103
- address: signerAddress,
104
- denoms: feeAssets.map((asset) => asset.denom ?? "")
105
- }
106
- }
107
- });
108
- const validatedAssets = feeAssets.map((asset, index) => {
109
- const chainAsset = skipAssets?.find((x) => x.denom === asset.denom);
110
- const symbol = chainAsset?.recommendedSymbol?.toUpperCase();
111
- const decimal = Number(chainAsset?.decimals);
112
- if (!chainAsset) {
113
- return {
114
- error: `(${chain?.prettyName}) Unable to find asset for ${asset.denom}`
115
- };
116
- }
117
- if (isNaN(decimal))
118
- return {
119
- error: `(${chain?.prettyName}) Unable to find decimal for ${symbol}`
120
- };
121
- const fee = fees[index];
122
- if (!fee) {
123
- return {
124
- error: `(${chain?.prettyName}) Unable to calculate fee for ${symbol}`,
125
- asset
126
- };
127
- }
128
- if (txIndex !== 0 && chainId === "noble-1") {
129
- return {
130
- error: null,
131
- asset,
132
- fee
133
- };
134
- }
135
- let balance = feeBalance?.chains?.[chainId]?.denoms?.[asset?.denom ?? ""];
136
- if (!balance) {
137
- balance = {
138
- amount: "0",
139
- formattedAmount: "0"
140
- };
141
- }
142
- if (!fee.amount[0]?.amount) {
143
- return {
144
- error: `(${chain?.prettyName}) Unable to get fee for ${symbol}`,
145
- asset
146
- };
147
- }
148
- if (parseInt(balance?.amount ?? "") < parseInt(fee.amount[0]?.amount)) {
149
- const userAmount = new BigNumber(parseFloat(balance?.amount ?? "")).shiftedBy(-decimal).toFixed(decimal);
150
- const feeAmount = new BigNumber(parseFloat(fee.amount[0]?.amount)).shiftedBy(-decimal).toFixed(decimal);
151
- return {
152
- error: `Insufficient balance for gas on ${chain?.prettyName}. Need ${feeAmount} ${symbol} but only have ${userAmount} ${symbol}.`,
153
- asset
154
- };
155
- }
156
- return {
157
- error: null,
158
- asset,
159
- fee
160
- };
161
- });
162
- if (prioFeeDenom) {
163
- const availableAssets = validatedAssets.filter(
164
- (res) => res?.error === null
165
- );
166
- const prioFeeAsset = availableAssets.find(
167
- (res) => res?.asset?.denom === prioFeeDenom
168
- );
169
- if (prioFeeAsset) {
170
- return prioFeeAsset;
171
- }
172
- }
173
- const feeUsed = validatedAssets.find((res) => res?.error === null);
174
- if (!feeUsed) {
175
- if (validatedAssets.length > 1) {
176
- throw new Error(
177
- validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chain.prettyName}.`
178
- );
179
- }
180
- throw new Error(
181
- validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chain.prettyName}.`
182
- );
183
- }
184
- return feeUsed;
185
- };
186
-
187
- export { validateCosmosGasBalance };
@@ -1,47 +0,0 @@
1
- import { createRequestClient, ApiState } from './chunk-F66EKL3W.js';
2
-
3
- // src/public-functions/setApiOptions.ts
4
- var setApiOptions = (options = {}) => {
5
- ApiState.client = createRequestClient({
6
- apiUrl: options.apiUrl || "https://api.skip.build",
7
- apiKey: options.apiKey,
8
- apiHeaders: options.apiHeaders
9
- });
10
- if (options.chainIdsToAffiliates) {
11
- ApiState.cumulativeAffiliateFeeBPS = validateChainIdsToAffiliates(options.chainIdsToAffiliates);
12
- ApiState.chainIdsToAffiliates = options.chainIdsToAffiliates;
13
- }
14
- if (!options.allowOptionsUpdateAfterApiCall && ApiState.apiCalled && !ApiState.initialized) {
15
- throw new Error("setApiOptions must be called before an api request is made");
16
- }
17
- ApiState.initialized = true;
18
- };
19
- function validateChainIdsToAffiliates(chainIdsToAffiliates) {
20
- const affiliatesArray = Object.values(chainIdsToAffiliates).map((chain) => chain.affiliates).filter((a) => a !== void 0);
21
- const firstAffiliateBasisPointsFee = affiliatesArray[0]?.reduce((acc, affiliate) => {
22
- if (!affiliate.basisPointsFee) {
23
- throw new Error("basisPointFee must exist in each affiliate");
24
- }
25
- return acc + parseInt(affiliate.basisPointsFee, 10);
26
- }, 0);
27
- const allBasisPointsAreEqual = affiliatesArray.every((affiliate) => {
28
- const totalBasisPointsFee = affiliate.reduce((acc, affiliate2) => {
29
- if (!affiliate2.basisPointsFee) {
30
- throw new Error("basisPointFee must exist in each affiliate");
31
- }
32
- if (!affiliate2.address) {
33
- throw new Error("address to receive fee must exist in each affiliate");
34
- }
35
- return acc + parseInt(affiliate2?.basisPointsFee, 10);
36
- }, 0);
37
- return totalBasisPointsFee === firstAffiliateBasisPointsFee;
38
- });
39
- if (!allBasisPointsAreEqual) {
40
- throw new Error(
41
- "basisPointFee does not add up to the same number for each chain in chainIdsToAffiliates"
42
- );
43
- }
44
- return firstAffiliateBasisPointsFee?.toFixed(0);
45
- }
46
-
47
- export { setApiOptions };