@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,203 @@
1
+ // src/utils/timer.ts
2
+ var wait = (ms) => {
3
+ return new Promise((resolve) => setTimeout(resolve, ms));
4
+ };
5
+
6
+ // src/utils/convert.ts
7
+ function toSnake(obj) {
8
+ return convertKeys(obj, (key) => key.replace(/([A-Z])/g, "_$1").toLowerCase());
9
+ }
10
+ function toCamel(obj) {
11
+ return convertKeys(obj, (key) => key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()));
12
+ }
13
+ function convertKeys(obj, convertKey) {
14
+ if (Array.isArray(obj)) {
15
+ return obj.map((item) => convertKeys(item, convertKey));
16
+ } else if (obj !== null && typeof obj === "object") {
17
+ return Object.keys(obj).reduce((acc, key) => {
18
+ acc[convertKey(key)] = convertKeys(obj[key], convertKey);
19
+ return acc;
20
+ }, {});
21
+ } else {
22
+ return obj;
23
+ }
24
+ }
25
+
26
+ // src/utils/generateApi.ts
27
+ var createRequestClient = ({ apiUrl, apiKey, apiHeaders }) => {
28
+ if (!apiUrl?.endsWith("/")) {
29
+ apiUrl += "/";
30
+ }
31
+ const headers = new Headers({
32
+ "content-type": "application/json"
33
+ });
34
+ if (apiKey) {
35
+ headers.set("authorization", apiKey);
36
+ }
37
+ if (apiHeaders) {
38
+ new Headers(apiHeaders).forEach((value, key) => {
39
+ headers.set(key, value);
40
+ });
41
+ }
42
+ const handleResponse = async (response) => {
43
+ const contentType = response.headers.get("content-type");
44
+ const isJson = contentType?.includes("application/json");
45
+ const body = isJson ? await response.json() : await response.text();
46
+ if (!response.ok) {
47
+ const message = typeof body === "object" && body?.message ? body.message : response.statusText;
48
+ const error = new Error(message);
49
+ if (body?.code) {
50
+ error.code = body.code;
51
+ }
52
+ if (body?.details) {
53
+ error.details = body.details;
54
+ }
55
+ throw error;
56
+ }
57
+ return body;
58
+ };
59
+ const get = async (path, params, signal) => {
60
+ if (path?.startsWith("/")) {
61
+ console.warn("paths that start with / are treated as absolute paths, please remove the leading / if this path is intended to be a relative path");
62
+ }
63
+ const url = new URL(path ?? "", apiUrl);
64
+ if (params && typeof params === "object") {
65
+ Object.entries(params).forEach(([key, value]) => {
66
+ if (value !== void 0 && value !== null) {
67
+ if (Array.isArray(value)) {
68
+ value.forEach((item) => {
69
+ url.searchParams.append(key, String(item));
70
+ });
71
+ } else {
72
+ url.searchParams.append(key, String(value));
73
+ }
74
+ }
75
+ });
76
+ }
77
+ const response = await fetch(url.toString(), {
78
+ method: "GET",
79
+ headers,
80
+ signal
81
+ });
82
+ return handleResponse(response);
83
+ };
84
+ const post = async (path, data = {}, signal) => {
85
+ if (path?.startsWith("/")) {
86
+ console.warn("paths that start with / are treated as absolute paths, please remove the leading / if this path is intended to be a relative path");
87
+ }
88
+ const response = await fetch(new URL(path, apiUrl).toString(), {
89
+ method: "POST",
90
+ headers,
91
+ body: JSON.stringify(data),
92
+ signal
93
+ });
94
+ return handleResponse(response);
95
+ };
96
+ return { get, post };
97
+ };
98
+ function createRequest({
99
+ path,
100
+ method = "get",
101
+ onSuccess,
102
+ transformResponse
103
+ }) {
104
+ let controller = null;
105
+ const request = async (options) => {
106
+ const { apiKey, apiUrl, apiHeaders, abortDuplicateRequests, ...requestParams } = options ?? {};
107
+ let fetchClient = ApiState.client;
108
+ if (apiKey || apiUrl || apiHeaders || fetchClient === void 0) {
109
+ fetchClient = createRequestClient({
110
+ apiUrl: apiUrl || "https://api.skip.build",
111
+ apiKey,
112
+ apiHeaders
113
+ });
114
+ }
115
+ ApiState.apiCalled = true;
116
+ if (abortDuplicateRequests && controller && !controller?.signal?.aborted) {
117
+ controller?.abort();
118
+ }
119
+ controller = new AbortController();
120
+ try {
121
+ const response = await fetchClient[method](
122
+ path,
123
+ requestParams ? toSnake(requestParams) : void 0,
124
+ controller.signal
125
+ );
126
+ const camelCased = toCamel(response ?? {});
127
+ const finalResponse = transformResponse ? transformResponse(camelCased) : camelCased;
128
+ onSuccess?.(finalResponse, requestParams);
129
+ return finalResponse;
130
+ } catch (error) {
131
+ if (error.name === "AbortError") {
132
+ console.log("Request was cancelled");
133
+ } else {
134
+ console.error("Error:", error);
135
+ throw error;
136
+ }
137
+ }
138
+ };
139
+ return request;
140
+ }
141
+ function api({
142
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
+ methodName,
144
+ path,
145
+ onSuccess,
146
+ method = "get",
147
+ transformResponse
148
+ }) {
149
+ return createRequest({
150
+ path,
151
+ method,
152
+ onSuccess,
153
+ transformResponse
154
+ });
155
+ }
156
+ function pollingApi({
157
+ methodName,
158
+ path,
159
+ method = "get",
160
+ onSuccess,
161
+ onError,
162
+ isSuccess = () => true,
163
+ maxRetries = 10,
164
+ retryInterval = 1e3,
165
+ backoffMultiplier = 2,
166
+ throwOnError = false
167
+ }) {
168
+ const request = async (requestParams) => {
169
+ let attempt = 0;
170
+ let lastError;
171
+ while (attempt < maxRetries) {
172
+ try {
173
+ const result = await api({ methodName, path, method })(requestParams);
174
+ if (result && isSuccess(result)) {
175
+ onSuccess?.(result, attempt);
176
+ return result;
177
+ }
178
+ } catch (err) {
179
+ lastError = err;
180
+ onError?.(err, attempt);
181
+ if (throwOnError) {
182
+ throw err;
183
+ }
184
+ }
185
+ const delay = retryInterval * Math.pow(backoffMultiplier, attempt);
186
+ await wait(delay);
187
+ attempt++;
188
+ }
189
+ throw lastError ?? new Error("pollingApi: max retries exceeded");
190
+ };
191
+ return (params) => request(params);
192
+ }
193
+
194
+ // src/state/apiState.ts
195
+ var ApiState = class {
196
+ static client;
197
+ static chainIdsToAffiliates;
198
+ static cumulativeAffiliateFeeBPS = "0";
199
+ static initialized = false;
200
+ static apiCalled = false;
201
+ };
202
+
203
+ export { ApiState, api, createRequestClient, pollingApi, toCamel, wait };
@@ -0,0 +1,212 @@
1
+ import { createValidAddressList, executeTransactions } from './chunk-XIVAEU6S.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 };
@@ -0,0 +1,272 @@
1
+ import { MsgDepositForBurn, MsgDepositForBurnWithCaller, MsgExecute, MsgInitiateTokenDeposit, BaseVestingAccount, Timestamp, Period } from './chunk-F2LQB2DP.js';
2
+ import { toTimestamp, fromTimestamp, fromJsonTimestamp, isSet } from './chunk-RTDD7HZ3.js';
3
+ import '@cosmjs/stargate';
4
+ import { toUtf8 } from '@cosmjs/encoding';
5
+ import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx.js';
6
+ import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx.js';
7
+ import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx.js';
8
+ import _m0 from 'protobufjs/minimal.js';
9
+
10
+ function createBaseClawbackVestingAccount() {
11
+ return {
12
+ baseVestingAccount: void 0,
13
+ funderAddress: "",
14
+ startTime: /* @__PURE__ */ new Date(),
15
+ lockupPeriods: [],
16
+ vestingPeriods: []
17
+ };
18
+ }
19
+ var ClawbackVestingAccount = {
20
+ typeUrl: "/evmos.vesting.v2.ClawbackVestingAccount",
21
+ encode(message, writer = _m0.Writer.create()) {
22
+ if (message.baseVestingAccount !== void 0) {
23
+ BaseVestingAccount.encode(message.baseVestingAccount, writer.uint32(10).fork()).ldelim();
24
+ }
25
+ if (message.funderAddress !== "") {
26
+ writer.uint32(18).string(message.funderAddress);
27
+ }
28
+ if (message.startTime !== void 0) {
29
+ Timestamp.encode(toTimestamp(message.startTime), writer.uint32(26).fork()).ldelim();
30
+ }
31
+ for (const v of message.lockupPeriods) {
32
+ Period.encode(v, writer.uint32(34).fork()).ldelim();
33
+ }
34
+ for (const v of message.vestingPeriods) {
35
+ Period.encode(v, writer.uint32(42).fork()).ldelim();
36
+ }
37
+ return writer;
38
+ },
39
+ decode(input, length) {
40
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
41
+ let end = length === void 0 ? reader.len : reader.pos + length;
42
+ const message = createBaseClawbackVestingAccount();
43
+ while (reader.pos < end) {
44
+ const tag = reader.uint32();
45
+ switch (tag >>> 3) {
46
+ case 1:
47
+ message.baseVestingAccount = BaseVestingAccount.decode(reader, reader.uint32());
48
+ break;
49
+ case 2:
50
+ message.funderAddress = reader.string();
51
+ break;
52
+ case 3:
53
+ message.startTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
54
+ break;
55
+ case 4:
56
+ message.lockupPeriods.push(Period.decode(reader, reader.uint32()));
57
+ break;
58
+ case 5:
59
+ message.vestingPeriods.push(Period.decode(reader, reader.uint32()));
60
+ break;
61
+ default:
62
+ reader.skipType(tag & 7);
63
+ break;
64
+ }
65
+ }
66
+ return message;
67
+ },
68
+ fromJSON(object) {
69
+ return {
70
+ baseVestingAccount: isSet(object.baseVestingAccount) ? BaseVestingAccount.fromJSON(object.baseVestingAccount) : void 0,
71
+ funderAddress: isSet(object.funderAddress) ? String(object.funderAddress) : "",
72
+ startTime: isSet(object.startTime) ? fromJsonTimestamp(object.startTime) : void 0,
73
+ lockupPeriods: Array.isArray(object?.lockupPeriods) ? object.lockupPeriods.map((e) => Period.fromJSON(e)) : [],
74
+ vestingPeriods: Array.isArray(object?.vestingPeriods) ? object.vestingPeriods.map((e) => Period.fromJSON(e)) : []
75
+ };
76
+ },
77
+ toJSON(message) {
78
+ const obj = {};
79
+ message.baseVestingAccount !== void 0 && (obj.baseVestingAccount = message.baseVestingAccount ? BaseVestingAccount.toJSON(message.baseVestingAccount) : void 0);
80
+ message.funderAddress !== void 0 && (obj.funderAddress = message.funderAddress);
81
+ message.startTime !== void 0 && (obj.startTime = message.startTime.toISOString());
82
+ if (message.lockupPeriods) {
83
+ obj.lockupPeriods = message.lockupPeriods.map((e) => e ? Period.toJSON(e) : void 0);
84
+ } else {
85
+ obj.lockupPeriods = [];
86
+ }
87
+ if (message.vestingPeriods) {
88
+ obj.vestingPeriods = message.vestingPeriods.map((e) => e ? Period.toJSON(e) : void 0);
89
+ } else {
90
+ obj.vestingPeriods = [];
91
+ }
92
+ return obj;
93
+ },
94
+ fromPartial(object) {
95
+ const message = createBaseClawbackVestingAccount();
96
+ message.baseVestingAccount = object.baseVestingAccount !== void 0 && object.baseVestingAccount !== null ? BaseVestingAccount.fromPartial(object.baseVestingAccount) : void 0;
97
+ message.funderAddress = object.funderAddress ?? "";
98
+ message.startTime = object.startTime ?? void 0;
99
+ message.lockupPeriods = object.lockupPeriods?.map((e) => Period.fromPartial(e)) || [];
100
+ message.vestingPeriods = object.vestingPeriods?.map((e) => Period.fromPartial(e)) || [];
101
+ return message;
102
+ },
103
+ fromAmino(object) {
104
+ const message = createBaseClawbackVestingAccount();
105
+ if (object.base_vesting_account !== void 0 && object.base_vesting_account !== null) {
106
+ message.baseVestingAccount = BaseVestingAccount.fromAmino(object.base_vesting_account);
107
+ }
108
+ if (object.funder_address !== void 0 && object.funder_address !== null) {
109
+ message.funderAddress = object.funder_address;
110
+ }
111
+ if (object.start_time !== void 0 && object.start_time !== null) {
112
+ message.startTime = fromTimestamp(Timestamp.fromAmino(object.start_time));
113
+ }
114
+ message.lockupPeriods = object.lockup_periods?.map((e) => Period.fromAmino(e)) || [];
115
+ message.vestingPeriods = object.vesting_periods?.map((e) => Period.fromAmino(e)) || [];
116
+ return message;
117
+ },
118
+ toAmino(message) {
119
+ const obj = {};
120
+ obj.base_vesting_account = message.baseVestingAccount ? BaseVestingAccount.toAmino(message.baseVestingAccount) : void 0;
121
+ obj.funder_address = message.funderAddress === "" ? void 0 : message.funderAddress;
122
+ obj.start_time = message.startTime ? Timestamp.toAmino(toTimestamp(message.startTime)) : void 0;
123
+ if (message.lockupPeriods) {
124
+ obj.lockup_periods = message.lockupPeriods.map((e) => e ? Period.toAmino(e) : void 0);
125
+ } else {
126
+ obj.lockup_periods = message.lockupPeriods;
127
+ }
128
+ if (message.vestingPeriods) {
129
+ obj.vesting_periods = message.vestingPeriods.map((e) => e ? Period.toAmino(e) : void 0);
130
+ } else {
131
+ obj.vesting_periods = message.vestingPeriods;
132
+ }
133
+ return obj;
134
+ },
135
+ fromAminoMsg(object) {
136
+ return ClawbackVestingAccount.fromAmino(object.value);
137
+ },
138
+ toAminoMsg(message) {
139
+ return {
140
+ type: "vesting/ClawbackVestingAccount",
141
+ value: ClawbackVestingAccount.toAmino(message)
142
+ };
143
+ },
144
+ fromProtoMsg(message) {
145
+ return ClawbackVestingAccount.decode(message.value);
146
+ },
147
+ toProto(message) {
148
+ return ClawbackVestingAccount.encode(message).finish();
149
+ },
150
+ toProtoMsg(message) {
151
+ return {
152
+ typeUrl: "/evmos.vesting.v2.ClawbackVestingAccount",
153
+ value: ClawbackVestingAccount.encode(message).finish()
154
+ };
155
+ }
156
+ };
157
+
158
+ // src/private-functions/cosmos/getEncodeObjectFromCosmosMessage.ts
159
+ function getEncodeObjectFromCosmosMessage(message) {
160
+ const msgJson = JSON.parse(message.msg ?? "");
161
+ if (message.msgTypeUrl === "/ibc.applications.transfer.v1.MsgTransfer") {
162
+ return {
163
+ typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
164
+ value: MsgTransfer.fromJSON({
165
+ sourcePort: msgJson.source_port,
166
+ sourceChannel: msgJson.source_channel,
167
+ token: msgJson.token,
168
+ sender: msgJson.sender,
169
+ receiver: msgJson.receiver,
170
+ timeoutHeight: msgJson.timeout_height,
171
+ timeoutTimestamp: msgJson.timeout_timestamp,
172
+ memo: msgJson.memo
173
+ })
174
+ };
175
+ }
176
+ if (message.msgTypeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract") {
177
+ return {
178
+ typeUrl: message.msgTypeUrl,
179
+ value: MsgExecuteContract.fromPartial({
180
+ sender: msgJson.sender,
181
+ contract: msgJson.contract,
182
+ msg: toUtf8(JSON.stringify(msgJson.msg)),
183
+ funds: msgJson.funds
184
+ })
185
+ };
186
+ }
187
+ if (message.msgTypeUrl === "/cosmos.bank.v1beta1.MsgSend") {
188
+ return {
189
+ typeUrl: message.msgTypeUrl,
190
+ value: MsgSend.fromPartial({
191
+ fromAddress: msgJson.from_address,
192
+ toAddress: msgJson.to_address,
193
+ amount: msgJson.amount
194
+ })
195
+ };
196
+ }
197
+ if (message.msgTypeUrl === "/circle.cctp.v1.MsgDepositForBurn") {
198
+ return {
199
+ typeUrl: message.msgTypeUrl,
200
+ value: MsgDepositForBurn.fromAmino(msgJson)
201
+ };
202
+ }
203
+ if (message.msgTypeUrl === "/circle.cctp.v1.MsgDepositForBurnWithCaller") {
204
+ return {
205
+ typeUrl: message.msgTypeUrl,
206
+ value: MsgDepositForBurnWithCaller.fromAmino(msgJson)
207
+ };
208
+ }
209
+ if (message.msgTypeUrl === "/initia.move.v1.MsgExecute") {
210
+ return {
211
+ typeUrl: message.msgTypeUrl,
212
+ value: MsgExecute.fromPartial({
213
+ sender: msgJson.sender,
214
+ moduleAddress: msgJson.module_address,
215
+ moduleName: msgJson.module_name,
216
+ functionName: msgJson.function_name,
217
+ args: msgJson.args
218
+ })
219
+ };
220
+ }
221
+ if (message.msgTypeUrl === "/opinit.ophost.v1.MsgInitiateTokenDeposit") {
222
+ return {
223
+ typeUrl: message.msgTypeUrl,
224
+ value: MsgInitiateTokenDeposit.fromPartial({
225
+ sender: msgJson.sender,
226
+ to: msgJson.to,
227
+ amount: msgJson.amount,
228
+ bridgeId: msgJson.bridge_id
229
+ })
230
+ };
231
+ }
232
+ if (message.msgTypeUrl === "/evmos.vesting.v2.ClawbackVestingAccount") {
233
+ return {
234
+ typeUrl: message.msgTypeUrl,
235
+ value: ClawbackVestingAccount.fromPartial({
236
+ baseVestingAccount: msgJson.base_vesting_account,
237
+ funderAddress: msgJson.funder_address,
238
+ lockupPeriods: msgJson.lockup_periods,
239
+ startTime: msgJson.start_time,
240
+ vestingPeriods: msgJson.vesting_periods
241
+ })
242
+ };
243
+ }
244
+ return {
245
+ typeUrl: message.msgTypeUrl ?? "",
246
+ value: msgJson
247
+ };
248
+ }
249
+
250
+ // src/public-functions/getCosmosGasAmountForMessage.ts
251
+ var DEFAULT_GAS_MULTIPLIER = 1.5;
252
+ async function getCosmosGasAmountForMessage(client, signerAddress, chainId, messages, encodedMsgs, multiplier = DEFAULT_GAS_MULTIPLIER) {
253
+ if (!messages && !encodedMsgs) {
254
+ throw new Error("Either message or encodedMsg must be provided");
255
+ }
256
+ const _encodedMsgs = messages?.map((message) => getEncodeObjectFromCosmosMessage(message));
257
+ encodedMsgs = encodedMsgs || _encodedMsgs;
258
+ if (!encodedMsgs) {
259
+ throw new Error("Either message or encodedMsg must be provided");
260
+ }
261
+ if (chainId.includes("evmos") || chainId.includes("injective") || chainId.includes("dymension") || chainId.includes("sunrise-1") || process?.env.NODE_ENV === "test") {
262
+ if (messages?.find((i) => i.msgTypeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract")) {
263
+ return "2400000";
264
+ }
265
+ return "300000";
266
+ }
267
+ const estimatedGas = await client.simulate(signerAddress, encodedMsgs, "");
268
+ const estimatedGasWithBuffer = estimatedGas * multiplier;
269
+ return Math.ceil(estimatedGasWithBuffer).toFixed(0);
270
+ }
271
+
272
+ export { DEFAULT_GAS_MULTIPLIER, getCosmosGasAmountForMessage, getEncodeObjectFromCosmosMessage };