@skip-go/client 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/getAssets.cjs +15 -0
- package/dist/api/{getAssets.d.ts → getAssets.d.cts} +2 -2
- package/dist/api/getAssetsBetweenChains.cjs +11 -0
- package/dist/api/{getAssetsBetweenChains.d.ts → getAssetsBetweenChains.d.cts} +2 -2
- package/dist/api/getBridges.cjs +11 -0
- package/dist/api/{getBridges.d.ts → getBridges.d.cts} +2 -2
- package/dist/api/getChains.cjs +11 -0
- package/dist/api/{getChains.d.ts → getChains.d.cts} +2 -2
- package/dist/api/getVenues.cjs +11 -0
- package/dist/api/{getVenues.d.ts → getVenues.d.cts} +1 -1
- package/dist/api/postAssetsFromSource.cjs +12 -0
- package/dist/api/{postAssetsFromSource.d.ts → postAssetsFromSource.d.cts} +2 -2
- package/dist/api/postBalances.cjs +11 -0
- package/dist/api/{postBalances.d.ts → postBalances.d.cts} +3 -3
- package/dist/api/postIbcOriginAssets.cjs +11 -0
- package/dist/api/{postIbcOriginAssets.d.ts → postIbcOriginAssets.d.cts} +1 -1
- package/dist/api/postMessages.cjs +11 -0
- package/dist/api/{postMessages.d.ts → postMessages.d.cts} +186 -186
- package/dist/api/postMessagesDirect.cjs +11 -0
- package/dist/api/{postMessagesDirect.d.ts → postMessagesDirect.d.cts} +185 -185
- package/dist/api/postRecommendAssets.cjs +11 -0
- package/dist/api/{postRecommendAssets.d.ts → postRecommendAssets.d.cts} +2 -2
- package/dist/api/postRoute.cjs +11 -0
- package/dist/api/{postRoute.d.ts → postRoute.d.cts} +163 -163
- package/dist/api/postSubmitTransaction.cjs +11 -0
- package/dist/api/{postSubmitTransaction.d.ts → postSubmitTransaction.d.cts} +1 -1
- package/dist/api/postTrackTransaction.cjs +11 -0
- package/dist/api/{postTrackTransaction.d.ts → postTrackTransaction.d.cts} +1 -1
- package/dist/api/postTransactionStatus.cjs +11 -0
- package/dist/api/{postTransactionStatus.d.ts → postTransactionStatus.d.cts} +3 -3
- package/dist/{chunk-FVSSCQ6C.js → chunk-32MRDO7V.cjs} +2 -2
- package/dist/chunk-44PBLFB5.cjs +24 -0
- package/dist/{chunk-GFRPLEJR.js → chunk-5IAEEEOQ.cjs} +217 -227
- package/dist/{chunk-Z4ZKOUGH.js → chunk-77ITCT75.cjs} +2 -2
- package/dist/{chunk-RT5TZAMU.js → chunk-7OIZPQJB.cjs} +101 -138
- package/dist/{chunk-CG5CQQBW.js → chunk-7SK3IFXJ.cjs} +32 -36
- package/dist/{chunk-2WHYWV4Y.js → chunk-DAMZSSOH.cjs} +2 -2
- package/dist/chunk-ED2OY55G.cjs +136 -0
- package/dist/chunk-G7BBDZ7C.cjs +1812 -0
- package/dist/chunk-HAR3IXDE.cjs +705 -0
- package/dist/{chunk-6BTWKTNM.js → chunk-ISHM4QWP.cjs} +4 -4
- package/dist/{chunk-4XWIXR2P.js → chunk-J4LI33TK.cjs} +18 -24
- package/dist/{chunk-YYNIFO2A.js → chunk-KDN7RCGP.cjs} +2 -2
- package/dist/{chunk-KYFTM3PI.js → chunk-L5V5PASH.cjs} +2 -2
- package/dist/{chunk-X2E2TKVR.js → chunk-LXYLWTNZ.cjs} +2 -2
- package/dist/{chunk-ZG23Z3WY.js → chunk-PNWIJSMA.cjs} +2 -2
- package/dist/{chunk-RE2QZJWE.js → chunk-RDOSNDAQ.cjs} +2 -2
- package/dist/chunk-SFMBRLUS.cjs +18 -0
- package/dist/{chunk-X2YPYBVN.js → chunk-SW3SEQMJ.cjs} +25 -30
- package/dist/{chunk-LRIPQQ4M.js → chunk-URLFWBSC.cjs} +2 -2
- package/dist/{chunk-5ZJBR5AQ.js → chunk-VI7UMBQ7.cjs} +2 -2
- package/dist/{chunk-PKPZTO4H.js → chunk-ZNXE6PUV.cjs} +9 -10
- package/dist/{client-types-CxjtffyG.d.ts → client-types-qvyKvyFh.d.cts} +1 -1
- package/dist/{executeRoute-BKvMVd1I.d.ts → executeRoute-BKRpODCc.d.cts} +3 -3
- package/dist/{generateApi-DqCp36fX.d.ts → generateApi-C0amiydg.d.cts} +1 -1
- package/dist/index.cjs +209 -0
- package/dist/{index.d.ts → index.d.cts} +25 -27
- package/dist/public-functions/executeRoute.cjs +21 -0
- package/dist/public-functions/{executeRoute.d.ts → executeRoute.d.cts} +4 -4
- package/dist/public-functions/getFeeInfoForChain.cjs +14 -0
- package/dist/public-functions/{getFeeInfoForChain.d.ts → getFeeInfoForChain.d.cts} +2 -2
- package/dist/public-functions/getRecommendedGasPrice.cjs +16 -0
- package/dist/public-functions/{getRecommendedGasPrice.d.ts → getRecommendedGasPrice.d.cts} +2 -2
- package/dist/public-functions/getSigningStargateClient.cjs +13 -0
- package/dist/public-functions/{getSigningStargateClient.d.ts → getSigningStargateClient.d.cts} +1 -1
- package/dist/public-functions/setApiOptions.cjs +11 -0
- package/dist/public-functions/{setApiOptions.d.ts → setApiOptions.d.cts} +2 -2
- package/dist/public-functions/setClientOptions.cjs +13 -0
- package/dist/public-functions/setClientOptions.d.cts +9 -0
- package/dist/{setClientOptions-DbanEIwL.d.ts → setClientOptions-CT6CHI9I.d.cts} +2 -2
- package/package.json +12 -3
- package/dist/api/getAssets.js +0 -15
- package/dist/api/getAssetsBetweenChains.js +0 -11
- package/dist/api/getBridges.js +0 -11
- package/dist/api/getChains.js +0 -11
- package/dist/api/getVenues.js +0 -11
- package/dist/api/postAssetsFromSource.js +0 -12
- package/dist/api/postBalances.js +0 -11
- package/dist/api/postIbcOriginAssets.js +0 -11
- package/dist/api/postMessages.js +0 -11
- package/dist/api/postMessagesDirect.js +0 -11
- package/dist/api/postRecommendAssets.js +0 -11
- package/dist/api/postRoute.js +0 -11
- package/dist/api/postSubmitTransaction.js +0 -11
- package/dist/api/postTrackTransaction.js +0 -11
- package/dist/api/postTransactionStatus.js +0 -11
- package/dist/chunk-5KVRQLI5.js +0 -17
- package/dist/chunk-6GJEXV5J.js +0 -130
- package/dist/chunk-ASPVKNJ7.js +0 -242
- package/dist/chunk-EQLA2SEZ.js +0 -2361
- package/dist/chunk-L2Q5RP6O.js +0 -25
- package/dist/index.js +0 -209
- package/dist/public-functions/executeRoute.js +0 -21
- package/dist/public-functions/getFeeInfoForChain.js +0 -14
- package/dist/public-functions/getRecommendedGasPrice.js +0 -16
- package/dist/public-functions/getSigningStargateClient.js +0 -13
- package/dist/public-functions/setApiOptions.js +0 -11
- package/dist/public-functions/setClientOptions.d.ts +0 -9
- package/dist/public-functions/setClientOptions.js +0 -13
- /package/dist/{apiState-CdzxTxYd.d.ts → apiState-CdzxTxYd.d.cts} +0 -0
- /package/dist/{chunk-VQ5SIQWU.js → chunk-4R6OCWRR.cjs} +0 -0
- /package/dist/{chunk-SWYON2RG.js → chunk-KZOSEIWH.cjs} +0 -0
- /package/dist/{swaggerTypes-O9-gvCT1.d.ts → swaggerTypes-O9-gvCT1.d.cts} +0 -0
|
@@ -0,0 +1,1812 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4R6OCWRR_cjs = require('./chunk-4R6OCWRR.cjs');
|
|
4
|
+
var chunkKZOSEIWH_cjs = require('./chunk-KZOSEIWH.cjs');
|
|
5
|
+
var chunkSW3SEQMJ_cjs = require('./chunk-SW3SEQMJ.cjs');
|
|
6
|
+
var chunk7SK3IFXJ_cjs = require('./chunk-7SK3IFXJ.cjs');
|
|
7
|
+
var chunk7OIZPQJB_cjs = require('./chunk-7OIZPQJB.cjs');
|
|
8
|
+
var chunk32MRDO7V_cjs = require('./chunk-32MRDO7V.cjs');
|
|
9
|
+
var chunkL5V5PASH_cjs = require('./chunk-L5V5PASH.cjs');
|
|
10
|
+
var chunkKDN7RCGP_cjs = require('./chunk-KDN7RCGP.cjs');
|
|
11
|
+
var chunkDAMZSSOH_cjs = require('./chunk-DAMZSSOH.cjs');
|
|
12
|
+
var chunkED2OY55G_cjs = require('./chunk-ED2OY55G.cjs');
|
|
13
|
+
var chunkHAR3IXDE_cjs = require('./chunk-HAR3IXDE.cjs');
|
|
14
|
+
var web3_js = require('@solana/web3.js');
|
|
15
|
+
var bech32 = require('bech32');
|
|
16
|
+
var stargate = require('@cosmjs/stargate');
|
|
17
|
+
var tx_js = require('cosmjs-types/cosmos/tx/v1beta1/tx.js');
|
|
18
|
+
var signer = require('@cosmjs/proto-signing/build/signer');
|
|
19
|
+
var base64 = require('@cosmjs/encoding/build/base64');
|
|
20
|
+
var encoding = require('@cosmjs/encoding');
|
|
21
|
+
var sdkTs = require('@injectivelabs/sdk-ts');
|
|
22
|
+
var tx$2 = require('cosmjs-types/cosmos/bank/v1beta1/tx');
|
|
23
|
+
var tx$1 = require('cosmjs-types/cosmwasm/wasm/v1/tx');
|
|
24
|
+
var tx = require('cosmjs-types/ibc/applications/transfer/v1/tx');
|
|
25
|
+
var _m0 = require('protobufjs/minimal');
|
|
26
|
+
var utils = require('@injectivelabs/utils');
|
|
27
|
+
var signing = require('@cosmjs/proto-signing/build/signing');
|
|
28
|
+
var amino = require('@cosmjs/amino');
|
|
29
|
+
var protoSigning = require('@cosmjs/proto-signing');
|
|
30
|
+
var keys = require('cosmjs-types/cosmos/crypto/secp256k1/keys');
|
|
31
|
+
var any = require('cosmjs-types/google/protobuf/any');
|
|
32
|
+
var integers = require('@cosmjs/math/build/integers');
|
|
33
|
+
var signing$1 = require('cosmjs-types/cosmos/tx/signing/v1beta1/signing');
|
|
34
|
+
var viem = require('viem');
|
|
35
|
+
var decimal = require('@cosmjs/math/build/decimal');
|
|
36
|
+
|
|
37
|
+
function _interopNamespace(e) {
|
|
38
|
+
if (e && e.__esModule) return e;
|
|
39
|
+
var n = Object.create(null);
|
|
40
|
+
if (e) {
|
|
41
|
+
Object.keys(e).forEach(function (k) {
|
|
42
|
+
if (k !== 'default') {
|
|
43
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
44
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return e[k]; }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
n.default = e;
|
|
52
|
+
return Object.freeze(n);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var _m0__namespace = /*#__PURE__*/_interopNamespace(_m0);
|
|
56
|
+
|
|
57
|
+
// src/private-functions/getRestEndpointForChain.ts
|
|
58
|
+
var getRestEndpointForChain = async (chainId) => {
|
|
59
|
+
if (chunkED2OY55G_cjs.ClientState.endpointOptions.getRestEndpointForChain) {
|
|
60
|
+
return chunkED2OY55G_cjs.ClientState.endpointOptions.getRestEndpointForChain(chainId);
|
|
61
|
+
}
|
|
62
|
+
if (chunkED2OY55G_cjs.ClientState.endpointOptions.endpoints && chunkED2OY55G_cjs.ClientState.endpointOptions.endpoints[chainId]) {
|
|
63
|
+
const endpointOptions = chunkED2OY55G_cjs.ClientState.endpointOptions.endpoints[chainId];
|
|
64
|
+
if (endpointOptions?.rest) {
|
|
65
|
+
return endpointOptions.rest;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const chain = chunk7SK3IFXJ_cjs.chains().find((chain2) => chain2.chain_id === chainId);
|
|
69
|
+
if (!chain) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`getRestEndpointForChain error: failed to find chain id '${chainId}' in registry`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (chain.apis?.rest?.length === 0 || !chain.apis?.rest) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`getRpcEndpointForChain error: failed to find RPC endpoint for chain '${chainId}'`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const endpoints = chain.apis?.rest?.map((api) => api.address);
|
|
80
|
+
const endpoint = await chunk7SK3IFXJ_cjs.findFirstWorkingEndpoint(endpoints, "rest");
|
|
81
|
+
if (!endpoint) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`getRestEndpointForChain error: failed to find REST endpoint for chain '${chainId}'`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return endpoint;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/private-functions/getAccountNumberAndSequence.ts
|
|
90
|
+
var getAccountNumberAndSequence = async (address, chainId) => {
|
|
91
|
+
if (chainId.includes("dymension")) {
|
|
92
|
+
return getAccountNumberAndSequenceFromDymension(address, chainId);
|
|
93
|
+
}
|
|
94
|
+
const endpoint = await chunkSW3SEQMJ_cjs.getRpcEndpointForChain(chainId);
|
|
95
|
+
const client = chunkED2OY55G_cjs.ClientState.signingStargateClientByChainId[chainId] ?? await stargate.StargateClient.connect(endpoint, {
|
|
96
|
+
accountParser: chunkSW3SEQMJ_cjs.accountParser
|
|
97
|
+
});
|
|
98
|
+
const account = await client.getAccount(address);
|
|
99
|
+
if (!account) {
|
|
100
|
+
throw new Error("getAccountNumberAndSequence: failed to retrieve account");
|
|
101
|
+
}
|
|
102
|
+
client.disconnect();
|
|
103
|
+
return {
|
|
104
|
+
accountNumber: account.accountNumber,
|
|
105
|
+
sequence: account.sequence
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
var getAccountNumberAndSequenceFromDymension = async (address, chainId) => {
|
|
109
|
+
const endpoint = await getRestEndpointForChain(chainId);
|
|
110
|
+
const jsonResponse = await chunkHAR3IXDE_cjs.createRequestClient({
|
|
111
|
+
baseUrl: `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
|
|
112
|
+
}).get();
|
|
113
|
+
const response = chunkHAR3IXDE_cjs.toCamel(jsonResponse);
|
|
114
|
+
let sequence = 0;
|
|
115
|
+
let accountNumber = 0;
|
|
116
|
+
if (response.account.baseAccount) {
|
|
117
|
+
sequence = response.account.baseAccount.sequence;
|
|
118
|
+
accountNumber = response.account.baseAccount.accountNumber;
|
|
119
|
+
} else {
|
|
120
|
+
sequence = response.account.sequence;
|
|
121
|
+
accountNumber = response.account.accountNumber;
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
accountNumber,
|
|
125
|
+
sequence
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
function createBaseClawbackVestingAccount() {
|
|
129
|
+
return {
|
|
130
|
+
baseVestingAccount: void 0,
|
|
131
|
+
funderAddress: "",
|
|
132
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
133
|
+
lockupPeriods: [],
|
|
134
|
+
vestingPeriods: []
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
var ClawbackVestingAccount = {
|
|
138
|
+
typeUrl: "/evmos.vesting.v2.ClawbackVestingAccount",
|
|
139
|
+
encode(message, writer = _m0__namespace.Writer.create()) {
|
|
140
|
+
if (message.baseVestingAccount !== void 0) {
|
|
141
|
+
chunk7OIZPQJB_cjs.BaseVestingAccount.encode(message.baseVestingAccount, writer.uint32(10).fork()).ldelim();
|
|
142
|
+
}
|
|
143
|
+
if (message.funderAddress !== "") {
|
|
144
|
+
writer.uint32(18).string(message.funderAddress);
|
|
145
|
+
}
|
|
146
|
+
if (message.startTime !== void 0) {
|
|
147
|
+
chunk7OIZPQJB_cjs.Timestamp.encode(chunk7OIZPQJB_cjs.toTimestamp(message.startTime), writer.uint32(26).fork()).ldelim();
|
|
148
|
+
}
|
|
149
|
+
for (const v of message.lockupPeriods) {
|
|
150
|
+
chunk7OIZPQJB_cjs.Period.encode(v, writer.uint32(34).fork()).ldelim();
|
|
151
|
+
}
|
|
152
|
+
for (const v of message.vestingPeriods) {
|
|
153
|
+
chunk7OIZPQJB_cjs.Period.encode(v, writer.uint32(42).fork()).ldelim();
|
|
154
|
+
}
|
|
155
|
+
return writer;
|
|
156
|
+
},
|
|
157
|
+
decode(input, length) {
|
|
158
|
+
const reader = input instanceof _m0__namespace.Reader ? input : new _m0__namespace.Reader(input);
|
|
159
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
160
|
+
const message = createBaseClawbackVestingAccount();
|
|
161
|
+
while (reader.pos < end) {
|
|
162
|
+
const tag = reader.uint32();
|
|
163
|
+
switch (tag >>> 3) {
|
|
164
|
+
case 1:
|
|
165
|
+
message.baseVestingAccount = chunk7OIZPQJB_cjs.BaseVestingAccount.decode(reader, reader.uint32());
|
|
166
|
+
break;
|
|
167
|
+
case 2:
|
|
168
|
+
message.funderAddress = reader.string();
|
|
169
|
+
break;
|
|
170
|
+
case 3:
|
|
171
|
+
message.startTime = chunk7OIZPQJB_cjs.fromTimestamp(chunk7OIZPQJB_cjs.Timestamp.decode(reader, reader.uint32()));
|
|
172
|
+
break;
|
|
173
|
+
case 4:
|
|
174
|
+
message.lockupPeriods.push(chunk7OIZPQJB_cjs.Period.decode(reader, reader.uint32()));
|
|
175
|
+
break;
|
|
176
|
+
case 5:
|
|
177
|
+
message.vestingPeriods.push(chunk7OIZPQJB_cjs.Period.decode(reader, reader.uint32()));
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
reader.skipType(tag & 7);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return message;
|
|
185
|
+
},
|
|
186
|
+
fromJSON(object) {
|
|
187
|
+
return {
|
|
188
|
+
baseVestingAccount: chunk7OIZPQJB_cjs.isSet(object.baseVestingAccount) ? chunk7OIZPQJB_cjs.BaseVestingAccount.fromJSON(object.baseVestingAccount) : void 0,
|
|
189
|
+
funderAddress: chunk7OIZPQJB_cjs.isSet(object.funderAddress) ? String(object.funderAddress) : "",
|
|
190
|
+
startTime: chunk7OIZPQJB_cjs.isSet(object.startTime) ? chunk7OIZPQJB_cjs.fromJsonTimestamp(object.startTime) : void 0,
|
|
191
|
+
lockupPeriods: Array.isArray(object?.lockupPeriods) ? object.lockupPeriods.map((e) => chunk7OIZPQJB_cjs.Period.fromJSON(e)) : [],
|
|
192
|
+
vestingPeriods: Array.isArray(object?.vestingPeriods) ? object.vestingPeriods.map((e) => chunk7OIZPQJB_cjs.Period.fromJSON(e)) : []
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
toJSON(message) {
|
|
196
|
+
const obj = {};
|
|
197
|
+
message.baseVestingAccount !== void 0 && (obj.baseVestingAccount = message.baseVestingAccount ? chunk7OIZPQJB_cjs.BaseVestingAccount.toJSON(message.baseVestingAccount) : void 0);
|
|
198
|
+
message.funderAddress !== void 0 && (obj.funderAddress = message.funderAddress);
|
|
199
|
+
message.startTime !== void 0 && (obj.startTime = message.startTime.toISOString());
|
|
200
|
+
if (message.lockupPeriods) {
|
|
201
|
+
obj.lockupPeriods = message.lockupPeriods.map((e) => e ? chunk7OIZPQJB_cjs.Period.toJSON(e) : void 0);
|
|
202
|
+
} else {
|
|
203
|
+
obj.lockupPeriods = [];
|
|
204
|
+
}
|
|
205
|
+
if (message.vestingPeriods) {
|
|
206
|
+
obj.vestingPeriods = message.vestingPeriods.map((e) => e ? chunk7OIZPQJB_cjs.Period.toJSON(e) : void 0);
|
|
207
|
+
} else {
|
|
208
|
+
obj.vestingPeriods = [];
|
|
209
|
+
}
|
|
210
|
+
return obj;
|
|
211
|
+
},
|
|
212
|
+
fromPartial(object) {
|
|
213
|
+
const message = createBaseClawbackVestingAccount();
|
|
214
|
+
message.baseVestingAccount = object.baseVestingAccount !== void 0 && object.baseVestingAccount !== null ? chunk7OIZPQJB_cjs.BaseVestingAccount.fromPartial(object.baseVestingAccount) : void 0;
|
|
215
|
+
message.funderAddress = object.funderAddress ?? "";
|
|
216
|
+
message.startTime = object.startTime ?? void 0;
|
|
217
|
+
message.lockupPeriods = object.lockupPeriods?.map((e) => chunk7OIZPQJB_cjs.Period.fromPartial(e)) || [];
|
|
218
|
+
message.vestingPeriods = object.vestingPeriods?.map((e) => chunk7OIZPQJB_cjs.Period.fromPartial(e)) || [];
|
|
219
|
+
return message;
|
|
220
|
+
},
|
|
221
|
+
fromAmino(object) {
|
|
222
|
+
const message = createBaseClawbackVestingAccount();
|
|
223
|
+
if (object.base_vesting_account !== void 0 && object.base_vesting_account !== null) {
|
|
224
|
+
message.baseVestingAccount = chunk7OIZPQJB_cjs.BaseVestingAccount.fromAmino(object.base_vesting_account);
|
|
225
|
+
}
|
|
226
|
+
if (object.funder_address !== void 0 && object.funder_address !== null) {
|
|
227
|
+
message.funderAddress = object.funder_address;
|
|
228
|
+
}
|
|
229
|
+
if (object.start_time !== void 0 && object.start_time !== null) {
|
|
230
|
+
message.startTime = chunk7OIZPQJB_cjs.fromTimestamp(chunk7OIZPQJB_cjs.Timestamp.fromAmino(object.start_time));
|
|
231
|
+
}
|
|
232
|
+
message.lockupPeriods = object.lockup_periods?.map((e) => chunk7OIZPQJB_cjs.Period.fromAmino(e)) || [];
|
|
233
|
+
message.vestingPeriods = object.vesting_periods?.map((e) => chunk7OIZPQJB_cjs.Period.fromAmino(e)) || [];
|
|
234
|
+
return message;
|
|
235
|
+
},
|
|
236
|
+
toAmino(message) {
|
|
237
|
+
const obj = {};
|
|
238
|
+
obj.base_vesting_account = message.baseVestingAccount ? chunk7OIZPQJB_cjs.BaseVestingAccount.toAmino(message.baseVestingAccount) : void 0;
|
|
239
|
+
obj.funder_address = message.funderAddress === "" ? void 0 : message.funderAddress;
|
|
240
|
+
obj.start_time = message.startTime ? chunk7OIZPQJB_cjs.Timestamp.toAmino(chunk7OIZPQJB_cjs.toTimestamp(message.startTime)) : void 0;
|
|
241
|
+
if (message.lockupPeriods) {
|
|
242
|
+
obj.lockup_periods = message.lockupPeriods.map((e) => e ? chunk7OIZPQJB_cjs.Period.toAmino(e) : void 0);
|
|
243
|
+
} else {
|
|
244
|
+
obj.lockup_periods = message.lockupPeriods;
|
|
245
|
+
}
|
|
246
|
+
if (message.vestingPeriods) {
|
|
247
|
+
obj.vesting_periods = message.vestingPeriods.map((e) => e ? chunk7OIZPQJB_cjs.Period.toAmino(e) : void 0);
|
|
248
|
+
} else {
|
|
249
|
+
obj.vesting_periods = message.vestingPeriods;
|
|
250
|
+
}
|
|
251
|
+
return obj;
|
|
252
|
+
},
|
|
253
|
+
fromAminoMsg(object) {
|
|
254
|
+
return ClawbackVestingAccount.fromAmino(object.value);
|
|
255
|
+
},
|
|
256
|
+
toAminoMsg(message) {
|
|
257
|
+
return {
|
|
258
|
+
type: "vesting/ClawbackVestingAccount",
|
|
259
|
+
value: ClawbackVestingAccount.toAmino(message)
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
fromProtoMsg(message) {
|
|
263
|
+
return ClawbackVestingAccount.decode(message.value);
|
|
264
|
+
},
|
|
265
|
+
toProto(message) {
|
|
266
|
+
return ClawbackVestingAccount.encode(message).finish();
|
|
267
|
+
},
|
|
268
|
+
toProtoMsg(message) {
|
|
269
|
+
return {
|
|
270
|
+
typeUrl: "/evmos.vesting.v2.ClawbackVestingAccount",
|
|
271
|
+
value: ClawbackVestingAccount.encode(message).finish()
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/private-functions/cosmos/getEncodeObjectFromCosmosMessage.ts
|
|
277
|
+
function getEncodeObjectFromCosmosMessage(message) {
|
|
278
|
+
const msgJson = JSON.parse(message.msg ?? "");
|
|
279
|
+
if (message.msgTypeUrl === "/ibc.applications.transfer.v1.MsgTransfer") {
|
|
280
|
+
return {
|
|
281
|
+
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
|
282
|
+
value: tx.MsgTransfer.fromJSON({
|
|
283
|
+
sourcePort: msgJson.source_port,
|
|
284
|
+
sourceChannel: msgJson.source_channel,
|
|
285
|
+
token: msgJson.token,
|
|
286
|
+
sender: msgJson.sender,
|
|
287
|
+
receiver: msgJson.receiver,
|
|
288
|
+
timeoutHeight: msgJson.timeout_height,
|
|
289
|
+
timeoutTimestamp: msgJson.timeout_timestamp,
|
|
290
|
+
memo: msgJson.memo
|
|
291
|
+
})
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (message.msgTypeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract") {
|
|
295
|
+
return {
|
|
296
|
+
typeUrl: message.msgTypeUrl,
|
|
297
|
+
value: tx$1.MsgExecuteContract.fromPartial({
|
|
298
|
+
sender: msgJson.sender,
|
|
299
|
+
contract: msgJson.contract,
|
|
300
|
+
msg: encoding.toUtf8(JSON.stringify(msgJson.msg)),
|
|
301
|
+
funds: msgJson.funds
|
|
302
|
+
})
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (message.msgTypeUrl === "/cosmos.bank.v1beta1.MsgSend") {
|
|
306
|
+
return {
|
|
307
|
+
typeUrl: message.msgTypeUrl,
|
|
308
|
+
value: tx$2.MsgSend.fromPartial({
|
|
309
|
+
fromAddress: msgJson.from_address,
|
|
310
|
+
toAddress: msgJson.to_address,
|
|
311
|
+
amount: msgJson.amount
|
|
312
|
+
})
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (message.msgTypeUrl === "/circle.cctp.v1.MsgDepositForBurn") {
|
|
316
|
+
return {
|
|
317
|
+
typeUrl: message.msgTypeUrl,
|
|
318
|
+
value: chunk7OIZPQJB_cjs.MsgDepositForBurn.fromAmino(msgJson)
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (message.msgTypeUrl === "/circle.cctp.v1.MsgDepositForBurnWithCaller") {
|
|
322
|
+
return {
|
|
323
|
+
typeUrl: message.msgTypeUrl,
|
|
324
|
+
value: chunk7OIZPQJB_cjs.MsgDepositForBurnWithCaller.fromAmino(msgJson)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if (message.msgTypeUrl === "/initia.move.v1.MsgExecute") {
|
|
328
|
+
return {
|
|
329
|
+
typeUrl: message.msgTypeUrl,
|
|
330
|
+
value: chunk7OIZPQJB_cjs.MsgExecute.fromPartial({
|
|
331
|
+
sender: msgJson.sender,
|
|
332
|
+
moduleAddress: msgJson.module_address,
|
|
333
|
+
moduleName: msgJson.module_name,
|
|
334
|
+
functionName: msgJson.function_name,
|
|
335
|
+
args: msgJson.args
|
|
336
|
+
})
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (message.msgTypeUrl === "/opinit.ophost.v1.MsgInitiateTokenDeposit") {
|
|
340
|
+
return {
|
|
341
|
+
typeUrl: message.msgTypeUrl,
|
|
342
|
+
value: chunk7OIZPQJB_cjs.MsgInitiateTokenDeposit.fromPartial({
|
|
343
|
+
sender: msgJson.sender,
|
|
344
|
+
to: msgJson.to,
|
|
345
|
+
amount: msgJson.amount,
|
|
346
|
+
bridgeId: msgJson.bridge_id
|
|
347
|
+
})
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
if (message.msgTypeUrl === "/evmos.vesting.v2.ClawbackVestingAccount") {
|
|
351
|
+
return {
|
|
352
|
+
typeUrl: message.msgTypeUrl,
|
|
353
|
+
value: ClawbackVestingAccount.fromPartial({
|
|
354
|
+
baseVestingAccount: msgJson.base_vesting_account,
|
|
355
|
+
funderAddress: msgJson.funder_address,
|
|
356
|
+
lockupPeriods: msgJson.lockup_periods,
|
|
357
|
+
startTime: msgJson.start_time,
|
|
358
|
+
vestingPeriods: msgJson.vesting_periods
|
|
359
|
+
})
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
typeUrl: message.msgTypeUrl ?? "",
|
|
364
|
+
value: msgJson
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function getEncodeObjectFromCosmosMessageInjective(message) {
|
|
368
|
+
const msgJson = JSON.parse(message.msg ?? "");
|
|
369
|
+
if (message.msgTypeUrl === "/ibc.applications.transfer.v1.MsgTransfer") {
|
|
370
|
+
return sdkTs.MsgTransfer.fromJSON({
|
|
371
|
+
port: msgJson.source_port,
|
|
372
|
+
channelId: msgJson.source_channel,
|
|
373
|
+
amount: msgJson.token,
|
|
374
|
+
sender: msgJson.sender,
|
|
375
|
+
receiver: msgJson.receiver,
|
|
376
|
+
timeout: msgJson.timeout_timestamp,
|
|
377
|
+
memo: msgJson.memo
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (message.msgTypeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract") {
|
|
381
|
+
return sdkTs.MsgExecuteContractCompat.fromJSON({
|
|
382
|
+
sender: msgJson.sender,
|
|
383
|
+
contractAddress: msgJson.contract,
|
|
384
|
+
msg: msgJson.msg,
|
|
385
|
+
funds: msgJson.funds
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
throw new Error("Unsupported message type");
|
|
389
|
+
}
|
|
390
|
+
function createTransaction({
|
|
391
|
+
chainId,
|
|
392
|
+
message,
|
|
393
|
+
timeoutHeight,
|
|
394
|
+
memo = "",
|
|
395
|
+
fee = utils.DEFAULT_STD_FEE,
|
|
396
|
+
signMode = 1,
|
|
397
|
+
pubKey,
|
|
398
|
+
accountNumber,
|
|
399
|
+
sequence
|
|
400
|
+
}) {
|
|
401
|
+
const signers = {
|
|
402
|
+
pubKey,
|
|
403
|
+
accountNumber,
|
|
404
|
+
sequence
|
|
405
|
+
};
|
|
406
|
+
return sdkTs.createTransactionWithSigners({
|
|
407
|
+
fee,
|
|
408
|
+
memo,
|
|
409
|
+
message,
|
|
410
|
+
signers,
|
|
411
|
+
chainId,
|
|
412
|
+
signMode,
|
|
413
|
+
timeoutHeight
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// src/private-functions/cosmos/signCosmosMessageDirectEvmos.ts
|
|
418
|
+
var signCosmosMessageDirectEvmos = async (signerAddress, signer, cosmosMsgs, fee, { accountNumber, sequence, chainId }) => {
|
|
419
|
+
const accounts = await signer.getAccounts();
|
|
420
|
+
const accountFromSigner = accounts.find((account) => account.address === signerAddress);
|
|
421
|
+
if (!accountFromSigner) {
|
|
422
|
+
throw new Error("signCosmosMessageDirectEvmos: failed to retrieve account from signer");
|
|
423
|
+
}
|
|
424
|
+
const messages2 = cosmosMsgs.map(
|
|
425
|
+
(cosmosMsg) => getEncodeObjectFromCosmosMessageInjective(cosmosMsg)
|
|
426
|
+
);
|
|
427
|
+
const pk = Buffer.from(accountFromSigner.pubkey).toString("base64");
|
|
428
|
+
const { signDoc } = createTransaction({
|
|
429
|
+
pubKey: pk,
|
|
430
|
+
chainId,
|
|
431
|
+
message: messages2,
|
|
432
|
+
sequence,
|
|
433
|
+
accountNumber,
|
|
434
|
+
timeoutHeight: 0,
|
|
435
|
+
fee
|
|
436
|
+
});
|
|
437
|
+
const directSignResponse = await signer.signDirect(signerAddress, signDoc);
|
|
438
|
+
return tx_js.TxRaw.fromPartial({
|
|
439
|
+
bodyBytes: directSignResponse.signed.bodyBytes,
|
|
440
|
+
authInfoBytes: directSignResponse.signed.authInfoBytes,
|
|
441
|
+
signatures: [base64.fromBase64(directSignResponse.signature.signature)]
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
var signCosmosMessageDirectInjective = async (signerAddress, signer, cosmosMsgs, fee, { accountNumber, sequence, chainId }) => {
|
|
445
|
+
const accounts = await signer.getAccounts();
|
|
446
|
+
const accountFromSigner = accounts.find((account) => account.address === signerAddress);
|
|
447
|
+
if (!accountFromSigner) {
|
|
448
|
+
throw new Error("signCosmosMessageDirectInjective: failed to retrieve account from signer");
|
|
449
|
+
}
|
|
450
|
+
const restEndpoint = await getRestEndpointForChain(chainId);
|
|
451
|
+
const chainRestTendermintApi = new sdkTs.ChainRestTendermintApi(restEndpoint);
|
|
452
|
+
const latestBlock = await chainRestTendermintApi.fetchLatestBlock();
|
|
453
|
+
const latestHeight = latestBlock.header.height;
|
|
454
|
+
const timeoutHeight = new utils.BigNumberInBase(latestHeight).plus(utils.DEFAULT_BLOCK_TIMEOUT_HEIGHT);
|
|
455
|
+
const pk = Buffer.from(accountFromSigner.pubkey).toString("base64");
|
|
456
|
+
const messages2 = cosmosMsgs.map(
|
|
457
|
+
(cosmosMsg) => getEncodeObjectFromCosmosMessageInjective(cosmosMsg)
|
|
458
|
+
);
|
|
459
|
+
const { signDoc } = createTransaction({
|
|
460
|
+
pubKey: pk,
|
|
461
|
+
chainId,
|
|
462
|
+
message: messages2,
|
|
463
|
+
sequence,
|
|
464
|
+
accountNumber,
|
|
465
|
+
timeoutHeight: timeoutHeight.toNumber(),
|
|
466
|
+
fee
|
|
467
|
+
});
|
|
468
|
+
const directSignResponse = await signer.signDirect(
|
|
469
|
+
signerAddress,
|
|
470
|
+
// @ts-expect-error TODO: Fix this
|
|
471
|
+
signDoc
|
|
472
|
+
);
|
|
473
|
+
return tx_js.TxRaw.fromPartial({
|
|
474
|
+
bodyBytes: directSignResponse.signed.bodyBytes,
|
|
475
|
+
authInfoBytes: directSignResponse.signed.authInfoBytes,
|
|
476
|
+
signatures: [base64.fromBase64(directSignResponse.signature.signature)]
|
|
477
|
+
});
|
|
478
|
+
};
|
|
479
|
+
var pubkeyType = {
|
|
480
|
+
ethsecp256k1: "ethermint/PubKeyEthSecp256k1",
|
|
481
|
+
...amino.pubkeyType
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// src/amino/encoding.ts
|
|
485
|
+
function encodeEthSecp256k1Pubkey(pubkey) {
|
|
486
|
+
if (pubkey.length !== 33 || pubkey[0] !== 2 && pubkey[0] !== 3) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
"Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03"
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
type: pubkeyType.ethsecp256k1,
|
|
493
|
+
value: encoding.toBase64(pubkey)
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/proto-signing/pubkey.ts
|
|
498
|
+
function makePubkeyAnyFromAccount(account, chainId) {
|
|
499
|
+
const isEthermint = chunk7SK3IFXJ_cjs.getIsEthermint(chainId);
|
|
500
|
+
const pubkey = isEthermint ? encodeEthSecp256k1Pubkey(account.pubkey) : amino.encodeSecp256k1Pubkey(account.pubkey);
|
|
501
|
+
const pubkeyAny = encodePubkeyToAny(pubkey, chainId, isEthermint);
|
|
502
|
+
return pubkeyAny;
|
|
503
|
+
}
|
|
504
|
+
function encodePubkeyToAny(pubkey, chainId, isEthermint) {
|
|
505
|
+
if (isEthermint) {
|
|
506
|
+
const pubkeyProto = keys.PubKey.fromPartial({
|
|
507
|
+
key: encoding.fromBase64(pubkey.value)
|
|
508
|
+
});
|
|
509
|
+
let typeUrl = "";
|
|
510
|
+
if (chainId?.includes("injective")) {
|
|
511
|
+
typeUrl = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
|
|
512
|
+
} else {
|
|
513
|
+
typeUrl = "/ethermint.crypto.v1.ethsecp256k1.PubKey";
|
|
514
|
+
}
|
|
515
|
+
return any.Any.fromPartial({
|
|
516
|
+
typeUrl,
|
|
517
|
+
value: Uint8Array.from(keys.PubKey.encode(pubkeyProto).finish())
|
|
518
|
+
});
|
|
519
|
+
} else {
|
|
520
|
+
const isInitia = chunk7SK3IFXJ_cjs.getIsInitia(chainId);
|
|
521
|
+
const pubkeyProto = keys.PubKey.fromPartial({
|
|
522
|
+
key: encoding.fromBase64(pubkey.value)
|
|
523
|
+
});
|
|
524
|
+
if (isInitia) {
|
|
525
|
+
return any.Any.fromPartial({
|
|
526
|
+
typeUrl: "/initia.crypto.v1beta1.ethsecp256k1.PubKey",
|
|
527
|
+
value: Uint8Array.from(keys.PubKey.encode(pubkeyProto).finish())
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return protoSigning.encodePubkey(pubkey);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
var signCosmosMessageDirect = async (options) => {
|
|
534
|
+
const {
|
|
535
|
+
signer,
|
|
536
|
+
signerAddress,
|
|
537
|
+
chainId,
|
|
538
|
+
cosmosMsgs,
|
|
539
|
+
fee,
|
|
540
|
+
signerData: { accountNumber, sequence, chainId: signerChainId }
|
|
541
|
+
} = options;
|
|
542
|
+
if (chainId.includes("evmos")) {
|
|
543
|
+
return signCosmosMessageDirectEvmos(signerAddress, signer, cosmosMsgs, fee, {
|
|
544
|
+
accountNumber,
|
|
545
|
+
sequence,
|
|
546
|
+
chainId: signerChainId
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (chainId.includes("injective")) {
|
|
550
|
+
return signCosmosMessageDirectInjective(signerAddress, signer, cosmosMsgs, fee, {
|
|
551
|
+
accountNumber,
|
|
552
|
+
sequence,
|
|
553
|
+
chainId: signerChainId
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
const accounts = await signer.getAccounts();
|
|
557
|
+
const accountFromSigner = accounts.find((account) => account.address === signerAddress);
|
|
558
|
+
if (!accountFromSigner) {
|
|
559
|
+
throw new Error("signCosmosMessageDirect error: failed to retrieve account from signer");
|
|
560
|
+
}
|
|
561
|
+
const messages2 = cosmosMsgs.map((cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg));
|
|
562
|
+
const txBodyEncodeObject = {
|
|
563
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
564
|
+
value: {
|
|
565
|
+
messages: messages2
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const txBodyBytes = chunkED2OY55G_cjs.ClientState.registry.encode(txBodyEncodeObject);
|
|
569
|
+
const gasLimit = integers.Int53.fromString(fee.gas).toNumber();
|
|
570
|
+
const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
|
|
571
|
+
const authInfoBytes = signing.makeAuthInfoBytes(
|
|
572
|
+
[{ pubkey: pubkeyAny, sequence }],
|
|
573
|
+
fee.amount,
|
|
574
|
+
gasLimit,
|
|
575
|
+
fee.granter,
|
|
576
|
+
fee.payer
|
|
577
|
+
);
|
|
578
|
+
const signDoc = signing.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
579
|
+
const { signature, signed } = await signer.signDirect(signerAddress, signDoc);
|
|
580
|
+
return tx_js.TxRaw.fromPartial({
|
|
581
|
+
bodyBytes: signed.bodyBytes,
|
|
582
|
+
authInfoBytes: signed.authInfoBytes,
|
|
583
|
+
signatures: [base64.fromBase64(signature.signature)]
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
var signCosmosMessageAmino = async (options) => {
|
|
587
|
+
const {
|
|
588
|
+
signer,
|
|
589
|
+
signerAddress,
|
|
590
|
+
chainId,
|
|
591
|
+
cosmosMsgs,
|
|
592
|
+
fee,
|
|
593
|
+
signerData: { accountNumber, sequence, chainId: signerChainId }
|
|
594
|
+
} = options;
|
|
595
|
+
const accounts = await signer.getAccounts();
|
|
596
|
+
const accountFromSigner = accounts.find((account) => account.address === signerAddress);
|
|
597
|
+
if (!accountFromSigner) {
|
|
598
|
+
throw new Error("signCosmosMessageAmino: failed to retrieve account from signer");
|
|
599
|
+
}
|
|
600
|
+
const messages2 = cosmosMsgs.map((cosmosMsg) => getEncodeObjectFromCosmosMessage(cosmosMsg));
|
|
601
|
+
const signMode = signing$1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
602
|
+
const msgs = messages2.map((msg) => chunkED2OY55G_cjs.ClientState.aminoTypes.toAmino(msg));
|
|
603
|
+
console.log("sign cosmos message amino", msgs, fee, signerChainId, "", accountNumber, sequence);
|
|
604
|
+
const signDoc = amino.makeSignDoc(msgs, fee, signerChainId, "", accountNumber, sequence);
|
|
605
|
+
const { signature, signed } = await signer.signAmino(signerAddress, signDoc);
|
|
606
|
+
const signedTxBody = {
|
|
607
|
+
messages: signed.msgs.map((msg) => chunkED2OY55G_cjs.ClientState.aminoTypes.fromAmino(msg)),
|
|
608
|
+
memo: signed.memo
|
|
609
|
+
};
|
|
610
|
+
signedTxBody.messages[0].value.memo = messages2[0].value.memo;
|
|
611
|
+
const signedTxBodyEncodeObject = {
|
|
612
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
613
|
+
value: signedTxBody
|
|
614
|
+
};
|
|
615
|
+
const signedTxBodyBytes = chunkED2OY55G_cjs.ClientState.registry.encode(signedTxBodyEncodeObject);
|
|
616
|
+
const signedGasLimit = integers.Int53.fromString(signed.fee.gas).toNumber();
|
|
617
|
+
const signedSequence = integers.Int53.fromString(signed.sequence).toNumber();
|
|
618
|
+
const pubkeyAny = makePubkeyAnyFromAccount(accountFromSigner, chainId);
|
|
619
|
+
const signedAuthInfoBytes = signing.makeAuthInfoBytes(
|
|
620
|
+
[{ pubkey: pubkeyAny, sequence: signedSequence }],
|
|
621
|
+
signed.fee.amount,
|
|
622
|
+
signedGasLimit,
|
|
623
|
+
signed.fee.granter,
|
|
624
|
+
signed.fee.payer,
|
|
625
|
+
signMode
|
|
626
|
+
);
|
|
627
|
+
return tx_js.TxRaw.fromPartial({
|
|
628
|
+
bodyBytes: signedTxBodyBytes,
|
|
629
|
+
authInfoBytes: signedAuthInfoBytes,
|
|
630
|
+
signatures: [base64.fromBase64(signature.signature)]
|
|
631
|
+
});
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/private-functions/cosmos/executeCosmosTransaction.ts
|
|
635
|
+
var executeCosmosTransaction = async ({
|
|
636
|
+
tx,
|
|
637
|
+
options,
|
|
638
|
+
index
|
|
639
|
+
}) => {
|
|
640
|
+
const { userAddresses } = options;
|
|
641
|
+
if (tx === void 0) {
|
|
642
|
+
throw new Error("executeCosmosTransaction error: tx is undefined");
|
|
643
|
+
}
|
|
644
|
+
const chainId = tx.cosmosTx?.chainId;
|
|
645
|
+
const messages2 = tx.cosmosTx?.msgs;
|
|
646
|
+
const currentUserAddress = userAddresses.find((x) => x.chainId === tx.cosmosTx?.chainId)?.address;
|
|
647
|
+
const gasArray = chunkED2OY55G_cjs.ClientState.validateGasResults;
|
|
648
|
+
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
649
|
+
if (typeof gas?.error === "string") {
|
|
650
|
+
throw new Error(gas?.error);
|
|
651
|
+
}
|
|
652
|
+
const gasUsed = gasArray?.[index];
|
|
653
|
+
if (!gasUsed) {
|
|
654
|
+
throw new Error(`executeRoute error: invalid gas at index ${index}`);
|
|
655
|
+
}
|
|
656
|
+
if (chainId === void 0) {
|
|
657
|
+
throw new Error("no chainId found for tx");
|
|
658
|
+
}
|
|
659
|
+
if (messages2 === void 0) {
|
|
660
|
+
throw new Error("no messages found for tx");
|
|
661
|
+
}
|
|
662
|
+
const { stargateClient, signer: signer$1 } = await chunkSW3SEQMJ_cjs.getSigningStargateClient({
|
|
663
|
+
chainId,
|
|
664
|
+
getOfflineSigner: options?.getCosmosSigner
|
|
665
|
+
});
|
|
666
|
+
if (!currentUserAddress) {
|
|
667
|
+
throw new Error(
|
|
668
|
+
`executeCosmosTransaction error: invalid address for chain '${tx.cosmosTx?.chainId}'`
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
const accounts = await signer$1.getAccounts();
|
|
672
|
+
const accountFromSigner = accounts.find((account) => account.address === currentUserAddress);
|
|
673
|
+
if (!accountFromSigner) {
|
|
674
|
+
throw new Error("executeCosmosTransaction error: failed to retrieve account from signer");
|
|
675
|
+
}
|
|
676
|
+
const fee = gasUsed?.fee;
|
|
677
|
+
if (!fee) {
|
|
678
|
+
throw new Error("executeCosmosTransaction error: failed to retrieve fee from gas");
|
|
679
|
+
}
|
|
680
|
+
const { accountNumber, sequence } = await getAccountNumberAndSequence(
|
|
681
|
+
currentUserAddress,
|
|
682
|
+
chainId
|
|
683
|
+
);
|
|
684
|
+
let rawTx;
|
|
685
|
+
const commonRawTxBody = {
|
|
686
|
+
signerAddress: currentUserAddress,
|
|
687
|
+
chainId,
|
|
688
|
+
cosmosMsgs: messages2,
|
|
689
|
+
fee,
|
|
690
|
+
signerData: {
|
|
691
|
+
accountNumber,
|
|
692
|
+
sequence,
|
|
693
|
+
chainId
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
if (signer.isOfflineDirectSigner(signer$1)) {
|
|
697
|
+
rawTx = await signCosmosMessageDirect({
|
|
698
|
+
...commonRawTxBody,
|
|
699
|
+
signer: signer$1
|
|
700
|
+
});
|
|
701
|
+
} else {
|
|
702
|
+
rawTx = await signCosmosMessageAmino({ ...commonRawTxBody, signer: signer$1 });
|
|
703
|
+
}
|
|
704
|
+
options?.onTransactionSigned?.({
|
|
705
|
+
chainId
|
|
706
|
+
});
|
|
707
|
+
const txBytes = tx_js.TxRaw.encode(rawTx).finish();
|
|
708
|
+
const txResponse = await stargateClient.broadcastTx(txBytes);
|
|
709
|
+
return {
|
|
710
|
+
chainId: tx?.cosmosTx?.chainId ?? "",
|
|
711
|
+
txHash: txResponse.transactionHash
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
function createAbi(abi) {
|
|
715
|
+
return abi;
|
|
716
|
+
}
|
|
717
|
+
var erc20ABI = /* @__PURE__ */ createAbi([
|
|
718
|
+
{
|
|
719
|
+
type: "event",
|
|
720
|
+
name: "Approval",
|
|
721
|
+
inputs: [
|
|
722
|
+
{
|
|
723
|
+
indexed: true,
|
|
724
|
+
name: "owner",
|
|
725
|
+
type: "address"
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
indexed: true,
|
|
729
|
+
name: "spender",
|
|
730
|
+
type: "address"
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
indexed: false,
|
|
734
|
+
name: "value",
|
|
735
|
+
type: "uint256"
|
|
736
|
+
}
|
|
737
|
+
]
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
type: "event",
|
|
741
|
+
name: "Transfer",
|
|
742
|
+
inputs: [
|
|
743
|
+
{
|
|
744
|
+
indexed: true,
|
|
745
|
+
name: "from",
|
|
746
|
+
type: "address"
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
indexed: true,
|
|
750
|
+
name: "to",
|
|
751
|
+
type: "address"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
indexed: false,
|
|
755
|
+
name: "value",
|
|
756
|
+
type: "uint256"
|
|
757
|
+
}
|
|
758
|
+
]
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
type: "function",
|
|
762
|
+
name: "allowance",
|
|
763
|
+
stateMutability: "view",
|
|
764
|
+
inputs: [
|
|
765
|
+
{
|
|
766
|
+
name: "owner",
|
|
767
|
+
type: "address"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
name: "spender",
|
|
771
|
+
type: "address"
|
|
772
|
+
}
|
|
773
|
+
],
|
|
774
|
+
outputs: [
|
|
775
|
+
{
|
|
776
|
+
name: "",
|
|
777
|
+
type: "uint256"
|
|
778
|
+
}
|
|
779
|
+
]
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
type: "function",
|
|
783
|
+
name: "approve",
|
|
784
|
+
stateMutability: "nonpayable",
|
|
785
|
+
inputs: [
|
|
786
|
+
{
|
|
787
|
+
name: "spender",
|
|
788
|
+
type: "address"
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
name: "amount",
|
|
792
|
+
type: "uint256"
|
|
793
|
+
}
|
|
794
|
+
],
|
|
795
|
+
outputs: [
|
|
796
|
+
{
|
|
797
|
+
name: "",
|
|
798
|
+
type: "bool"
|
|
799
|
+
}
|
|
800
|
+
]
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
type: "function",
|
|
804
|
+
name: "balanceOf",
|
|
805
|
+
stateMutability: "view",
|
|
806
|
+
inputs: [
|
|
807
|
+
{
|
|
808
|
+
name: "account",
|
|
809
|
+
type: "address"
|
|
810
|
+
}
|
|
811
|
+
],
|
|
812
|
+
outputs: [
|
|
813
|
+
{
|
|
814
|
+
name: "",
|
|
815
|
+
type: "uint256"
|
|
816
|
+
}
|
|
817
|
+
]
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
type: "function",
|
|
821
|
+
name: "decimals",
|
|
822
|
+
stateMutability: "view",
|
|
823
|
+
inputs: [],
|
|
824
|
+
outputs: [
|
|
825
|
+
{
|
|
826
|
+
name: "",
|
|
827
|
+
type: "uint8"
|
|
828
|
+
}
|
|
829
|
+
]
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
type: "function",
|
|
833
|
+
name: "name",
|
|
834
|
+
stateMutability: "view",
|
|
835
|
+
inputs: [],
|
|
836
|
+
outputs: [
|
|
837
|
+
{
|
|
838
|
+
name: "",
|
|
839
|
+
type: "string"
|
|
840
|
+
}
|
|
841
|
+
]
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
type: "function",
|
|
845
|
+
name: "symbol",
|
|
846
|
+
stateMutability: "view",
|
|
847
|
+
inputs: [],
|
|
848
|
+
outputs: [
|
|
849
|
+
{
|
|
850
|
+
name: "",
|
|
851
|
+
type: "string"
|
|
852
|
+
}
|
|
853
|
+
]
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
type: "function",
|
|
857
|
+
name: "totalSupply",
|
|
858
|
+
stateMutability: "view",
|
|
859
|
+
inputs: [],
|
|
860
|
+
outputs: [
|
|
861
|
+
{
|
|
862
|
+
name: "",
|
|
863
|
+
type: "uint256"
|
|
864
|
+
}
|
|
865
|
+
]
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
type: "function",
|
|
869
|
+
name: "transfer",
|
|
870
|
+
stateMutability: "nonpayable",
|
|
871
|
+
inputs: [
|
|
872
|
+
{
|
|
873
|
+
name: "recipient",
|
|
874
|
+
type: "address"
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
name: "amount",
|
|
878
|
+
type: "uint256"
|
|
879
|
+
}
|
|
880
|
+
],
|
|
881
|
+
outputs: [
|
|
882
|
+
{
|
|
883
|
+
name: "",
|
|
884
|
+
type: "bool"
|
|
885
|
+
}
|
|
886
|
+
]
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
type: "function",
|
|
890
|
+
name: "transferFrom",
|
|
891
|
+
stateMutability: "nonpayable",
|
|
892
|
+
inputs: [
|
|
893
|
+
{
|
|
894
|
+
name: "sender",
|
|
895
|
+
type: "address"
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
name: "recipient",
|
|
899
|
+
type: "address"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
name: "amount",
|
|
903
|
+
type: "uint256"
|
|
904
|
+
}
|
|
905
|
+
],
|
|
906
|
+
outputs: [
|
|
907
|
+
{
|
|
908
|
+
name: "",
|
|
909
|
+
type: "bool"
|
|
910
|
+
}
|
|
911
|
+
]
|
|
912
|
+
}
|
|
913
|
+
]);
|
|
914
|
+
|
|
915
|
+
// src/private-functions/evm/executeEvmTransaction.ts
|
|
916
|
+
var executeEvmTransaction = async (message, options) => {
|
|
917
|
+
const gasArray = chunkED2OY55G_cjs.ClientState.validateGasResults;
|
|
918
|
+
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
919
|
+
if (typeof gas?.error === "string") {
|
|
920
|
+
throw new Error(gas?.error);
|
|
921
|
+
}
|
|
922
|
+
const { evmTx } = message;
|
|
923
|
+
const getEvmSigner = options.getEvmSigner || chunkED2OY55G_cjs.ClientState.getEvmSigner;
|
|
924
|
+
if (!getEvmSigner) {
|
|
925
|
+
throw new Error("Unable to get EVM signer");
|
|
926
|
+
}
|
|
927
|
+
if (!evmTx?.chainId) {
|
|
928
|
+
throw new Error("chain id not found in evmTx");
|
|
929
|
+
}
|
|
930
|
+
const evmSigner = await getEvmSigner(evmTx.chainId);
|
|
931
|
+
if (!evmSigner.account) {
|
|
932
|
+
throw new Error("executeEVMTransaction error: failed to retrieve account from signer");
|
|
933
|
+
}
|
|
934
|
+
if (!evmTx.chainId) {
|
|
935
|
+
throw new Error("executeEVMTransaction error: chainId not found for evmTx");
|
|
936
|
+
}
|
|
937
|
+
if (!evmTx.value) {
|
|
938
|
+
throw new Error("executeEVMTransaction error: no value found in evmTx");
|
|
939
|
+
}
|
|
940
|
+
const { onApproveAllowance, onTransactionSigned, bypassApprovalCheck, useUnlimitedApproval } = options;
|
|
941
|
+
const extendedSigner = evmSigner.extend(viem.publicActions);
|
|
942
|
+
if (!bypassApprovalCheck && evmTx.requiredErc20Approvals) {
|
|
943
|
+
for (const requiredApproval of evmTx.requiredErc20Approvals) {
|
|
944
|
+
const allowance = await extendedSigner.readContract({
|
|
945
|
+
address: requiredApproval.tokenContract,
|
|
946
|
+
abi: erc20ABI,
|
|
947
|
+
functionName: "allowance",
|
|
948
|
+
args: [
|
|
949
|
+
evmSigner.account.address,
|
|
950
|
+
requiredApproval.spender
|
|
951
|
+
]
|
|
952
|
+
});
|
|
953
|
+
if (!requiredApproval.amount) {
|
|
954
|
+
throw new Error("executeEVMTransaction error: no amount found in a requiredApproval");
|
|
955
|
+
}
|
|
956
|
+
if (allowance > BigInt(requiredApproval.amount)) {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
onApproveAllowance?.({
|
|
960
|
+
status: "pending",
|
|
961
|
+
allowance: requiredApproval
|
|
962
|
+
});
|
|
963
|
+
const txHash2 = await extendedSigner.writeContract({
|
|
964
|
+
account: evmSigner.account,
|
|
965
|
+
address: requiredApproval.tokenContract,
|
|
966
|
+
abi: erc20ABI,
|
|
967
|
+
functionName: "approve",
|
|
968
|
+
args: [
|
|
969
|
+
requiredApproval.spender,
|
|
970
|
+
useUnlimitedApproval ? viem.maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
|
|
971
|
+
],
|
|
972
|
+
chain: evmSigner.chain
|
|
973
|
+
});
|
|
974
|
+
const receipt2 = await extendedSigner.waitForTransactionReceipt({
|
|
975
|
+
hash: txHash2
|
|
976
|
+
});
|
|
977
|
+
if (receipt2.status === "reverted") {
|
|
978
|
+
throw new Error(
|
|
979
|
+
`executeEVMTransaction error: evm tx reverted for hash ${receipt2.transactionHash}`
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
onApproveAllowance?.({
|
|
984
|
+
status: "completed"
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
const txHash = await extendedSigner.sendTransaction({
|
|
988
|
+
account: evmSigner.account,
|
|
989
|
+
to: evmTx.to,
|
|
990
|
+
data: `0x${evmTx.data}`,
|
|
991
|
+
chain: evmSigner.chain,
|
|
992
|
+
value: evmTx.value === "" ? void 0 : BigInt(evmTx.value)
|
|
993
|
+
});
|
|
994
|
+
onTransactionSigned?.({
|
|
995
|
+
chainId: evmTx.chainId
|
|
996
|
+
});
|
|
997
|
+
const receipt = await extendedSigner.waitForTransactionReceipt({
|
|
998
|
+
hash: txHash
|
|
999
|
+
});
|
|
1000
|
+
return receipt;
|
|
1001
|
+
};
|
|
1002
|
+
var executeSvmTransaction = async (tx, options) => {
|
|
1003
|
+
const gasArray = chunkED2OY55G_cjs.ClientState.validateGasResults;
|
|
1004
|
+
if (tx === void 0) {
|
|
1005
|
+
throw new Error("executeSvmTransaction error: tx is undefined");
|
|
1006
|
+
}
|
|
1007
|
+
const gas = gasArray?.find((gas2) => gas2?.error !== null && gas2?.error !== void 0);
|
|
1008
|
+
if (typeof gas?.error === "string") {
|
|
1009
|
+
throw new Error(gas?.error);
|
|
1010
|
+
}
|
|
1011
|
+
const svmTx = tx?.svmTx;
|
|
1012
|
+
const getSvmSigner = options?.getSvmSigner || chunkED2OY55G_cjs.ClientState.getSvmSigner;
|
|
1013
|
+
if (!getSvmSigner) {
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
"executeRoute error: 'getSVMSigner' is not provided or configured in skip router"
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
const signer = await getSvmSigner();
|
|
1019
|
+
if (!svmTx?.chainId) {
|
|
1020
|
+
throw new Error("executeSvmTransaction error: chainId not found in svmTx");
|
|
1021
|
+
}
|
|
1022
|
+
const txBuffer = Buffer.from(svmTx.tx ?? "", "base64");
|
|
1023
|
+
const transaction = web3_js.Transaction.from(txBuffer);
|
|
1024
|
+
const endpoint = await chunkSW3SEQMJ_cjs.getRpcEndpointForChain(svmTx.chainId);
|
|
1025
|
+
const connection = new web3_js.Connection(endpoint);
|
|
1026
|
+
let signature;
|
|
1027
|
+
if ("signTransaction" in signer) {
|
|
1028
|
+
const signedTx = await signer.signTransaction(transaction);
|
|
1029
|
+
options?.onTransactionSigned?.({ chainId: svmTx.chainId });
|
|
1030
|
+
const serializedTx = signedTx.serialize();
|
|
1031
|
+
await chunkL5V5PASH_cjs.submitTransaction({
|
|
1032
|
+
chainId: svmTx.chainId,
|
|
1033
|
+
tx: serializedTx.toString("base64")
|
|
1034
|
+
}).then((res) => {
|
|
1035
|
+
signature = res?.txHash;
|
|
1036
|
+
});
|
|
1037
|
+
const rpcSig = await connection.sendRawTransaction(serializedTx, {
|
|
1038
|
+
preflightCommitment: "confirmed",
|
|
1039
|
+
maxRetries: 5
|
|
1040
|
+
});
|
|
1041
|
+
signature = rpcSig;
|
|
1042
|
+
}
|
|
1043
|
+
if (!signature) {
|
|
1044
|
+
throw new Error("executeSvmTransaction error: signature not found");
|
|
1045
|
+
}
|
|
1046
|
+
let getStatusCount = 0;
|
|
1047
|
+
let errorCount = 0;
|
|
1048
|
+
while (true) {
|
|
1049
|
+
try {
|
|
1050
|
+
const status = await connection.getSignatureStatus(signature, {
|
|
1051
|
+
searchTransactionHistory: true
|
|
1052
|
+
});
|
|
1053
|
+
if (status?.value?.confirmationStatus === "confirmed") {
|
|
1054
|
+
return {
|
|
1055
|
+
chainId: svmTx.chainId,
|
|
1056
|
+
txHash: signature
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
if (getStatusCount > 12) {
|
|
1060
|
+
await chunkHAR3IXDE_cjs.wait(3e3);
|
|
1061
|
+
throw new Error(
|
|
1062
|
+
`executeSvmTransaction error: waiting finalized status timed out for ${signature}`
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
getStatusCount++;
|
|
1066
|
+
await chunkHAR3IXDE_cjs.wait(3e3);
|
|
1067
|
+
} catch (error) {
|
|
1068
|
+
errorCount++;
|
|
1069
|
+
if (errorCount > 12) {
|
|
1070
|
+
throw error;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
var DEFAULT_GAS_MULTIPLIER = 1.5;
|
|
1076
|
+
async function getCosmosGasAmountForMessage(client, signerAddress, chainId, messages2, encodedMsgs, multiplier = DEFAULT_GAS_MULTIPLIER) {
|
|
1077
|
+
if (!messages2 && !encodedMsgs) {
|
|
1078
|
+
throw new Error("Either message or encodedMsg must be provided");
|
|
1079
|
+
}
|
|
1080
|
+
const _encodedMsgs = messages2?.map((message) => getEncodeObjectFromCosmosMessage(message));
|
|
1081
|
+
encodedMsgs = encodedMsgs || _encodedMsgs;
|
|
1082
|
+
if (!encodedMsgs) {
|
|
1083
|
+
throw new Error("Either message or encodedMsg must be provided");
|
|
1084
|
+
}
|
|
1085
|
+
if (chainId.includes("evmos") || chainId.includes("injective") || chainId.includes("dymension") || process?.env.NODE_ENV === "test") {
|
|
1086
|
+
if (messages2?.find((i) => i.msgTypeUrl === "/cosmwasm.wasm.v1.MsgExecuteContract")) {
|
|
1087
|
+
return "2400000";
|
|
1088
|
+
}
|
|
1089
|
+
return "280000";
|
|
1090
|
+
}
|
|
1091
|
+
const estimatedGas = await client.simulate(signerAddress, encodedMsgs, "");
|
|
1092
|
+
const estimatedGasWithBuffer = estimatedGas * multiplier;
|
|
1093
|
+
return Math.ceil(estimatedGasWithBuffer).toFixed(0);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// src/private-functions/cosmos/validateCosmosGasBalance.ts
|
|
1097
|
+
var validateCosmosGasBalance = async ({
|
|
1098
|
+
chainId,
|
|
1099
|
+
signerAddress,
|
|
1100
|
+
messages: messages2,
|
|
1101
|
+
getFallbackGasAmount,
|
|
1102
|
+
getOfflineSigner,
|
|
1103
|
+
txIndex,
|
|
1104
|
+
simulate
|
|
1105
|
+
}) => {
|
|
1106
|
+
const skipAssets = (await chunkED2OY55G_cjs.ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
1107
|
+
const skipChains = await chunkED2OY55G_cjs.ClientState.getSkipChains();
|
|
1108
|
+
const chain = skipChains?.find((c) => c.chainId === chainId);
|
|
1109
|
+
if (!chain) {
|
|
1110
|
+
throw new Error(`failed to find chain id for '${chainId}'`);
|
|
1111
|
+
}
|
|
1112
|
+
const { feeAssets } = chain;
|
|
1113
|
+
if (!feeAssets) {
|
|
1114
|
+
throw new Error(`failed to find fee assets for chain '${chainId}'`);
|
|
1115
|
+
}
|
|
1116
|
+
const estimatedGasAmount = await (async () => {
|
|
1117
|
+
try {
|
|
1118
|
+
if (!simulate) throw new Error("simulate");
|
|
1119
|
+
if (txIndex !== 0 && chainId === "noble-1") {
|
|
1120
|
+
return "0";
|
|
1121
|
+
}
|
|
1122
|
+
const { stargateClient } = await chunkSW3SEQMJ_cjs.getSigningStargateClient({
|
|
1123
|
+
chainId,
|
|
1124
|
+
getOfflineSigner
|
|
1125
|
+
});
|
|
1126
|
+
const estimatedGas = await getCosmosGasAmountForMessage(
|
|
1127
|
+
stargateClient,
|
|
1128
|
+
signerAddress,
|
|
1129
|
+
chainId,
|
|
1130
|
+
messages2
|
|
1131
|
+
);
|
|
1132
|
+
return estimatedGas;
|
|
1133
|
+
} catch (e) {
|
|
1134
|
+
const error = e;
|
|
1135
|
+
if (error.message === "simulate" && !getFallbackGasAmount) {
|
|
1136
|
+
throw new Error(`unable to get gas amount for ${chainId}'s message(s)`);
|
|
1137
|
+
}
|
|
1138
|
+
if (getFallbackGasAmount) {
|
|
1139
|
+
const fallbackGasAmount = await getFallbackGasAmount(chainId, "cosmos" /* Cosmos */);
|
|
1140
|
+
if (!fallbackGasAmount) {
|
|
1141
|
+
throw new Error(`unable to estimate gas for message(s) ${messages2}`);
|
|
1142
|
+
}
|
|
1143
|
+
return String(fallbackGasAmount);
|
|
1144
|
+
}
|
|
1145
|
+
throw error;
|
|
1146
|
+
}
|
|
1147
|
+
})();
|
|
1148
|
+
const fees = feeAssets.map((asset) => {
|
|
1149
|
+
const gasPrice = (() => {
|
|
1150
|
+
if (!asset?.gasPrice) return void 0;
|
|
1151
|
+
let price = asset.gasPrice.average;
|
|
1152
|
+
if (price === "") {
|
|
1153
|
+
price = asset.gasPrice.high;
|
|
1154
|
+
}
|
|
1155
|
+
if (price === "") {
|
|
1156
|
+
price = asset.gasPrice.low;
|
|
1157
|
+
}
|
|
1158
|
+
if (!price) return;
|
|
1159
|
+
return new stargate.GasPrice(
|
|
1160
|
+
decimal.Decimal.fromUserInput(chunk4R6OCWRR_cjs.BigNumber(price).toFixed(), 18),
|
|
1161
|
+
asset?.denom ?? ""
|
|
1162
|
+
);
|
|
1163
|
+
})();
|
|
1164
|
+
if (!gasPrice) {
|
|
1165
|
+
return null;
|
|
1166
|
+
}
|
|
1167
|
+
if (chainId === "noble-1") {
|
|
1168
|
+
const fee = stargate.calculateFee(2e5, gasPrice);
|
|
1169
|
+
return fee;
|
|
1170
|
+
}
|
|
1171
|
+
return stargate.calculateFee(Math.ceil(parseFloat(estimatedGasAmount)), gasPrice);
|
|
1172
|
+
});
|
|
1173
|
+
const feeBalance = await chunkED2OY55G_cjs.balances({
|
|
1174
|
+
chains: {
|
|
1175
|
+
[chainId]: {
|
|
1176
|
+
address: signerAddress,
|
|
1177
|
+
denoms: feeAssets.map((asset) => asset.denom ?? "")
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
const validatedAssets = feeAssets.map((asset, index) => {
|
|
1182
|
+
const chainAsset = skipAssets?.find((x) => x.denom === asset.denom);
|
|
1183
|
+
const symbol = chainAsset?.recommendedSymbol?.toUpperCase();
|
|
1184
|
+
const decimal = Number(chainAsset?.decimals);
|
|
1185
|
+
if (!chainAsset) {
|
|
1186
|
+
return {
|
|
1187
|
+
error: `(${chain?.prettyName}) Unable to find asset for ${asset.denom}`
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
if (isNaN(decimal))
|
|
1191
|
+
return {
|
|
1192
|
+
error: `(${chain?.prettyName}) Unable to find decimal for ${symbol}`
|
|
1193
|
+
};
|
|
1194
|
+
const fee = fees[index];
|
|
1195
|
+
if (!fee) {
|
|
1196
|
+
return {
|
|
1197
|
+
error: `(${chain?.prettyName}) Unable to calculate fee for ${symbol}`,
|
|
1198
|
+
asset
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
if (txIndex !== 0 && chainId === "noble-1") {
|
|
1202
|
+
return {
|
|
1203
|
+
error: null,
|
|
1204
|
+
asset,
|
|
1205
|
+
fee
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
let balance = feeBalance?.chains?.[chainId]?.denoms?.[asset?.denom ?? ""];
|
|
1209
|
+
if (!balance) {
|
|
1210
|
+
balance = {
|
|
1211
|
+
amount: "0",
|
|
1212
|
+
formattedAmount: "0"
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
if (!fee.amount[0]?.amount) {
|
|
1216
|
+
return {
|
|
1217
|
+
error: `(${chain?.prettyName}) Unable to get fee for ${symbol}`,
|
|
1218
|
+
asset
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
if (parseInt(balance?.amount ?? "") < parseInt(fee.amount[0]?.amount)) {
|
|
1222
|
+
const userAmount = new chunk4R6OCWRR_cjs.BigNumber(parseFloat(balance?.amount ?? "")).shiftedBy(-decimal).toFixed(decimal);
|
|
1223
|
+
const feeAmount = new chunk4R6OCWRR_cjs.BigNumber(parseFloat(fee.amount[0]?.amount)).shiftedBy(-decimal).toFixed(decimal);
|
|
1224
|
+
return {
|
|
1225
|
+
error: `Insufficient balance for gas on ${chain?.prettyName}. Need ${feeAmount} ${symbol} but only have ${userAmount} ${symbol}.`,
|
|
1226
|
+
asset
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
return {
|
|
1230
|
+
error: null,
|
|
1231
|
+
asset,
|
|
1232
|
+
fee
|
|
1233
|
+
};
|
|
1234
|
+
});
|
|
1235
|
+
const feeUsed = validatedAssets.find((res) => res?.error === null);
|
|
1236
|
+
if (!feeUsed) {
|
|
1237
|
+
if (validatedAssets.length > 1) {
|
|
1238
|
+
throw new Error(
|
|
1239
|
+
validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chainId}.`
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
throw new Error(
|
|
1243
|
+
validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chainId}.`
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
return feeUsed;
|
|
1247
|
+
};
|
|
1248
|
+
var validateEvmTokenApproval = async ({
|
|
1249
|
+
requiredErc20Approvals,
|
|
1250
|
+
signer,
|
|
1251
|
+
chain,
|
|
1252
|
+
gasBalance,
|
|
1253
|
+
tx,
|
|
1254
|
+
useUnlimitedApproval
|
|
1255
|
+
}) => {
|
|
1256
|
+
if (!signer.account?.address) {
|
|
1257
|
+
throw new Error("validateEvmGasBalance: Signer address not found");
|
|
1258
|
+
}
|
|
1259
|
+
for (const requiredApproval of requiredErc20Approvals) {
|
|
1260
|
+
const extendedSigner = signer.extend(viem.publicActions);
|
|
1261
|
+
const allowance = await extendedSigner.readContract({
|
|
1262
|
+
address: requiredApproval.tokenContract,
|
|
1263
|
+
abi: erc20ABI,
|
|
1264
|
+
functionName: "allowance",
|
|
1265
|
+
args: [signer.account?.address, requiredApproval.spender]
|
|
1266
|
+
});
|
|
1267
|
+
if (allowance > BigInt(requiredApproval.amount)) {
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
const fee = await extendedSigner.estimateFeesPerGas();
|
|
1271
|
+
const allowanceGasFee = BigInt(fee.maxFeePerGas) * BigInt(1e5);
|
|
1272
|
+
if (!gasBalance) {
|
|
1273
|
+
const chainAssets = (await chunkED2OY55G_cjs.ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
|
|
1274
|
+
const nativeAsset = chainAssets?.find((x) => x.denom.includes("-native"));
|
|
1275
|
+
const zeroAddressAsset = chainAssets?.find(
|
|
1276
|
+
(x) => x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1277
|
+
);
|
|
1278
|
+
const asset = nativeAsset || zeroAddressAsset;
|
|
1279
|
+
if (!asset?.decimals) {
|
|
1280
|
+
throw new Error(
|
|
1281
|
+
`Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei.`
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
const formattedGasAmount = viem.formatUnits(allowanceGasFee, asset?.decimals);
|
|
1285
|
+
throw new Error(
|
|
1286
|
+
`Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
if (chunk4R6OCWRR_cjs.BigNumber(gasBalance.amount).lt(Number(allowanceGasFee))) {
|
|
1290
|
+
const chainAssets = (await chunkED2OY55G_cjs.ClientState.getSkipAssets({ chainId: tx.chainId }))[tx.chainId];
|
|
1291
|
+
const asset = chainAssets?.find(
|
|
1292
|
+
(x) => x.denom.includes("-native") || x.denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1293
|
+
);
|
|
1294
|
+
if (!asset?.decimals) {
|
|
1295
|
+
return {
|
|
1296
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${allowanceGasFee} gwei but only have ${gasBalance.amount} gwei.`,
|
|
1297
|
+
asset: null,
|
|
1298
|
+
fee: null
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
const formattedGasAmount = viem.formatUnits(allowanceGasFee, asset?.decimals);
|
|
1302
|
+
return {
|
|
1303
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
|
|
1304
|
+
asset: null,
|
|
1305
|
+
fee: null
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
const txHash = await extendedSigner.writeContract({
|
|
1309
|
+
account: signer.account,
|
|
1310
|
+
address: requiredApproval.tokenContract,
|
|
1311
|
+
abi: erc20ABI,
|
|
1312
|
+
functionName: "approve",
|
|
1313
|
+
args: [
|
|
1314
|
+
requiredApproval.spender,
|
|
1315
|
+
useUnlimitedApproval ? viem.maxUint256 : BigInt(requiredApproval.amount) + BigInt(1e3)
|
|
1316
|
+
],
|
|
1317
|
+
chain: signer.chain
|
|
1318
|
+
});
|
|
1319
|
+
const receipt = await extendedSigner.waitForTransactionReceipt({
|
|
1320
|
+
hash: txHash
|
|
1321
|
+
});
|
|
1322
|
+
if (receipt.status === "reverted") {
|
|
1323
|
+
throw new Error(
|
|
1324
|
+
`executeEVMTransaction error: evm tx reverted for hash ${receipt.transactionHash}`
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
async function getEVMGasAmountForMessage(signer, tx, getFallbackGasAmount) {
|
|
1330
|
+
const { to, data, value } = tx;
|
|
1331
|
+
if (!signer.account) throw new Error("estimateGasForEvmTx: No account found");
|
|
1332
|
+
const extendedSigner = signer.extend(viem.publicActions);
|
|
1333
|
+
const fee = await extendedSigner.estimateFeesPerGas();
|
|
1334
|
+
try {
|
|
1335
|
+
const gasAmount = await extendedSigner.estimateGas({
|
|
1336
|
+
account: signer.account,
|
|
1337
|
+
to,
|
|
1338
|
+
data: `0x${data}`,
|
|
1339
|
+
value: value === "" ? void 0 : BigInt(value ?? "")
|
|
1340
|
+
});
|
|
1341
|
+
return gasAmount * fee.maxFeePerGas;
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
const fallbackGasAmount = await getFallbackGasAmount?.(tx.chainId ?? "", "evm" /* Evm */);
|
|
1344
|
+
if (fallbackGasAmount) {
|
|
1345
|
+
return BigInt(fallbackGasAmount) * fee.maxFeePerGas;
|
|
1346
|
+
}
|
|
1347
|
+
throw error;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// src/private-functions/evm/validateEvmGasBalance.ts
|
|
1352
|
+
var validateEvmGasBalance = async ({
|
|
1353
|
+
signer,
|
|
1354
|
+
tx,
|
|
1355
|
+
getFallbackGasAmount,
|
|
1356
|
+
useUnlimitedApproval
|
|
1357
|
+
}) => {
|
|
1358
|
+
const chainId = tx?.chainId ?? "";
|
|
1359
|
+
const skipAssets = (await chunkED2OY55G_cjs.ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
1360
|
+
const skipChains = await chunkED2OY55G_cjs.ClientState.getSkipChains();
|
|
1361
|
+
const chain = skipChains?.find?.((chain2) => chain2.chainId === chainId);
|
|
1362
|
+
if (!chain) {
|
|
1363
|
+
throw new Error(`failed to find chain for chainId: '${chainId}'`);
|
|
1364
|
+
}
|
|
1365
|
+
if (!signer.account?.address) {
|
|
1366
|
+
throw new Error("validateEvmGasBalance: Signer address not found");
|
|
1367
|
+
}
|
|
1368
|
+
const skipBalances = (await chunkED2OY55G_cjs.balances({
|
|
1369
|
+
chains: {
|
|
1370
|
+
[tx?.chainId ?? ""]: {
|
|
1371
|
+
address: signer.account?.address
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}))?.chains?.[tx?.chainId ?? ""]?.denoms;
|
|
1375
|
+
const nativeGasBalance = skipBalances && Object.entries(skipBalances).find(([denom]) => denom.includes("-native"))?.[1];
|
|
1376
|
+
const zeroAddressGasBalance = skipBalances && Object.entries(skipBalances).find(
|
|
1377
|
+
([denom]) => denom.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1378
|
+
)?.[1];
|
|
1379
|
+
const gasBalance = nativeGasBalance || zeroAddressGasBalance;
|
|
1380
|
+
const { requiredErc20Approvals } = tx;
|
|
1381
|
+
if (requiredErc20Approvals) {
|
|
1382
|
+
try {
|
|
1383
|
+
await validateEvmTokenApproval({
|
|
1384
|
+
requiredErc20Approvals,
|
|
1385
|
+
signer,
|
|
1386
|
+
chain,
|
|
1387
|
+
gasBalance,
|
|
1388
|
+
tx,
|
|
1389
|
+
useUnlimitedApproval
|
|
1390
|
+
});
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
const err = error;
|
|
1393
|
+
return {
|
|
1394
|
+
error: err.message,
|
|
1395
|
+
asset: null,
|
|
1396
|
+
fee: null
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const gasAmount = await getEVMGasAmountForMessage(signer, tx, getFallbackGasAmount);
|
|
1401
|
+
if (!gasBalance) {
|
|
1402
|
+
const nativeAsset = skipAssets?.find((x) => x.denom?.includes("-native"));
|
|
1403
|
+
const zeroAddressAsset = skipAssets?.find(
|
|
1404
|
+
(x) => x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1405
|
+
);
|
|
1406
|
+
const asset = nativeAsset || zeroAddressAsset;
|
|
1407
|
+
if (!asset?.decimals) {
|
|
1408
|
+
return {
|
|
1409
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei.`,
|
|
1410
|
+
asset: null,
|
|
1411
|
+
fee: null
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
const formattedGasAmount = viem.formatUnits(gasAmount, asset?.decimals);
|
|
1415
|
+
return {
|
|
1416
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol}.`,
|
|
1417
|
+
asset: null,
|
|
1418
|
+
fee: null
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
if (chunk4R6OCWRR_cjs.BigNumber(gasBalance.amount ?? "").lt(Number(gasAmount))) {
|
|
1422
|
+
const asset = skipAssets?.find(
|
|
1423
|
+
(x) => x.denom?.includes("-native") || x.denom?.toLowerCase() === "0x0000000000000000000000000000000000000000"
|
|
1424
|
+
);
|
|
1425
|
+
if (!asset?.decimals) {
|
|
1426
|
+
return {
|
|
1427
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${gasAmount} gwei but only have ${gasBalance.amount} gwei.`,
|
|
1428
|
+
asset: null,
|
|
1429
|
+
fee: null
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
const formattedGasAmount = viem.formatUnits(gasAmount, asset?.decimals);
|
|
1433
|
+
return {
|
|
1434
|
+
error: `Insufficient balance for gas on ${chain.prettyName}. Need ${formattedGasAmount} ${asset.symbol} but only have ${gasBalance.formattedAmount} ${asset.symbol}.`,
|
|
1435
|
+
asset: null,
|
|
1436
|
+
fee: null
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
var validateSvmGasBalance = async ({
|
|
1441
|
+
tx
|
|
1442
|
+
}) => {
|
|
1443
|
+
if (!tx) throw new Error("Transaction is required");
|
|
1444
|
+
const endpoint = await chunkSW3SEQMJ_cjs.getRpcEndpointForChain(tx.chainId ?? "");
|
|
1445
|
+
const connection = new web3_js.Connection(endpoint);
|
|
1446
|
+
if (!connection) throw new Error(`Failed to connect to ${tx.chainId}`);
|
|
1447
|
+
if (!tx.tx) {
|
|
1448
|
+
throw new Error("Transaction is required");
|
|
1449
|
+
}
|
|
1450
|
+
const txBuffer = Buffer.from(tx.tx, "base64");
|
|
1451
|
+
let transaction;
|
|
1452
|
+
try {
|
|
1453
|
+
transaction = web3_js.Transaction.from(txBuffer);
|
|
1454
|
+
} catch (decodeError) {
|
|
1455
|
+
return {
|
|
1456
|
+
success: false,
|
|
1457
|
+
error: { decodeError: decodeError.message },
|
|
1458
|
+
asset: null,
|
|
1459
|
+
fee: null
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
const simulation = await connection.simulateTransaction(transaction);
|
|
1463
|
+
if (simulation.value.err) {
|
|
1464
|
+
const logs = simulation.value.logs ?? [];
|
|
1465
|
+
const shortfall = getSolShortfall(logs);
|
|
1466
|
+
const insufficientLamports = logs.some((log) => log.includes("insufficient lamports")) && shortfall !== null;
|
|
1467
|
+
const insufficientFundsForRent = Object.keys(simulation.value.err).includes(
|
|
1468
|
+
"InsufficientFundsForRent"
|
|
1469
|
+
);
|
|
1470
|
+
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";
|
|
1471
|
+
return {
|
|
1472
|
+
success: false,
|
|
1473
|
+
logs,
|
|
1474
|
+
error: errMsg,
|
|
1475
|
+
asset: null,
|
|
1476
|
+
fee: null
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
return {
|
|
1480
|
+
success: true,
|
|
1481
|
+
logs: simulation.value.logs ?? [],
|
|
1482
|
+
error: null,
|
|
1483
|
+
asset: null,
|
|
1484
|
+
fee: null
|
|
1485
|
+
};
|
|
1486
|
+
};
|
|
1487
|
+
function getSolShortfall(logs) {
|
|
1488
|
+
const line = logs.find((l) => l.includes("insufficient lamports"));
|
|
1489
|
+
if (!line) return null;
|
|
1490
|
+
const m = line.match(/insufficient lamports (\d+), need (\d+)/);
|
|
1491
|
+
if (!m) return null;
|
|
1492
|
+
const have = parseInt(m[1] ?? "0", 10);
|
|
1493
|
+
const need = parseInt(m[2] ?? "0", 10);
|
|
1494
|
+
const shortfallLamports = need - have;
|
|
1495
|
+
return shortfallLamports / web3_js.LAMPORTS_PER_SOL;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// src/private-functions/validateGasBalances.ts
|
|
1499
|
+
var validateGasBalances = async ({
|
|
1500
|
+
txs,
|
|
1501
|
+
onValidateGasBalance,
|
|
1502
|
+
getFallbackGasAmount,
|
|
1503
|
+
getCosmosSigner,
|
|
1504
|
+
getEvmSigner,
|
|
1505
|
+
simulate,
|
|
1506
|
+
disabledChainIds,
|
|
1507
|
+
enabledChainIds,
|
|
1508
|
+
useUnlimitedApproval
|
|
1509
|
+
}) => {
|
|
1510
|
+
if (txs.every((tx) => "cosmosTx" in tx === void 0) || txs.every((tx) => "svmTx" in tx === void 0)) {
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
onValidateGasBalance?.({
|
|
1514
|
+
status: "pending"
|
|
1515
|
+
});
|
|
1516
|
+
const validateResult = await Promise.all(
|
|
1517
|
+
txs.map(async (tx, i) => {
|
|
1518
|
+
if (!tx) {
|
|
1519
|
+
throw new Error(`invalid tx at index ${i}`);
|
|
1520
|
+
}
|
|
1521
|
+
if ("cosmosTx" in tx && !disabledChainIds?.includes(tx?.cosmosTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.cosmosTx?.chainId ?? ""))) {
|
|
1522
|
+
if (!tx?.cosmosTx?.msgs) {
|
|
1523
|
+
throw new Error(`invalid msgs ${tx?.cosmosTx?.msgs}`);
|
|
1524
|
+
}
|
|
1525
|
+
try {
|
|
1526
|
+
const res = await validateCosmosGasBalance({
|
|
1527
|
+
chainId: tx.cosmosTx.chainId ?? "",
|
|
1528
|
+
signerAddress: tx.cosmosTx.signerAddress ?? "",
|
|
1529
|
+
messages: tx.cosmosTx.msgs,
|
|
1530
|
+
getFallbackGasAmount,
|
|
1531
|
+
getOfflineSigner: getCosmosSigner,
|
|
1532
|
+
txIndex: i,
|
|
1533
|
+
simulate
|
|
1534
|
+
});
|
|
1535
|
+
return res;
|
|
1536
|
+
} catch (e) {
|
|
1537
|
+
const error = e;
|
|
1538
|
+
return {
|
|
1539
|
+
error: error.message,
|
|
1540
|
+
asset: null,
|
|
1541
|
+
fee: null
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if ("evmTx" in tx && !disabledChainIds?.includes(tx?.evmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.evmTx?.chainId ?? ""))) {
|
|
1546
|
+
const signer = await getEvmSigner?.(tx?.evmTx?.chainId ?? "");
|
|
1547
|
+
if (!signer) {
|
|
1548
|
+
throw new Error(`failed to get signer for chain ${tx?.evmTx?.chainId}`);
|
|
1549
|
+
}
|
|
1550
|
+
try {
|
|
1551
|
+
const res = await validateEvmGasBalance({
|
|
1552
|
+
tx: tx.evmTx,
|
|
1553
|
+
signer,
|
|
1554
|
+
getFallbackGasAmount,
|
|
1555
|
+
useUnlimitedApproval
|
|
1556
|
+
});
|
|
1557
|
+
return res;
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
const error = e;
|
|
1560
|
+
return {
|
|
1561
|
+
error: error.message,
|
|
1562
|
+
asset: null,
|
|
1563
|
+
fee: null
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
if ("svmTx" in tx && !disabledChainIds?.includes(tx?.svmTx?.chainId ?? "") && (enabledChainIds === void 0 || enabledChainIds.includes(tx?.svmTx?.chainId ?? ""))) {
|
|
1568
|
+
try {
|
|
1569
|
+
const res = await validateSvmGasBalance({
|
|
1570
|
+
tx: tx.svmTx
|
|
1571
|
+
});
|
|
1572
|
+
return res;
|
|
1573
|
+
} catch (e) {
|
|
1574
|
+
const error = e;
|
|
1575
|
+
return {
|
|
1576
|
+
error: error.message,
|
|
1577
|
+
asset: null,
|
|
1578
|
+
fee: null
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
})
|
|
1583
|
+
);
|
|
1584
|
+
if (validateResult.filter(Boolean).length === 0) {
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const txError = validateResult.find((res) => res && res?.error !== null);
|
|
1588
|
+
if (txError) {
|
|
1589
|
+
onValidateGasBalance?.({
|
|
1590
|
+
status: "error"
|
|
1591
|
+
});
|
|
1592
|
+
chunkED2OY55G_cjs.ClientState.validateGasResults = validateResult;
|
|
1593
|
+
throw new Error(`${txError.error}`);
|
|
1594
|
+
}
|
|
1595
|
+
onValidateGasBalance?.({
|
|
1596
|
+
status: "completed"
|
|
1597
|
+
});
|
|
1598
|
+
chunkED2OY55G_cjs.ClientState.validateGasResults = validateResult;
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
// src/private-functions/waitForTransaction.ts
|
|
1602
|
+
var waitForTransaction = async ({
|
|
1603
|
+
chainId,
|
|
1604
|
+
txHash,
|
|
1605
|
+
onTransactionTracked
|
|
1606
|
+
}) => {
|
|
1607
|
+
const { explorerLink } = await chunkKDN7RCGP_cjs.trackTransaction({
|
|
1608
|
+
chainId,
|
|
1609
|
+
txHash
|
|
1610
|
+
});
|
|
1611
|
+
await onTransactionTracked?.({ txHash, chainId, explorerLink });
|
|
1612
|
+
while (true) {
|
|
1613
|
+
const txStatusResponse = await chunkDAMZSSOH_cjs.transactionStatus({
|
|
1614
|
+
chainId,
|
|
1615
|
+
txHash
|
|
1616
|
+
});
|
|
1617
|
+
if (txStatusResponse.state === "STATE_COMPLETED_SUCCESS") {
|
|
1618
|
+
return txStatusResponse;
|
|
1619
|
+
}
|
|
1620
|
+
if (txStatusResponse.state === "STATE_COMPLETED_ERROR") {
|
|
1621
|
+
throw new Error(`${txStatusResponse.error?.type}: ${txStatusResponse.error?.message}`);
|
|
1622
|
+
}
|
|
1623
|
+
if (txStatusResponse.state === "STATE_ABANDONED") {
|
|
1624
|
+
throw new Error("Tracking for the transaction has been abandoned");
|
|
1625
|
+
}
|
|
1626
|
+
await chunkHAR3IXDE_cjs.wait(1e3);
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
// src/private-functions/executeTransactions.ts
|
|
1631
|
+
var executeTransactions = async (options) => {
|
|
1632
|
+
const {
|
|
1633
|
+
txs,
|
|
1634
|
+
onTransactionBroadcast,
|
|
1635
|
+
onTransactionCompleted,
|
|
1636
|
+
simulate = true,
|
|
1637
|
+
batchSimulate = true
|
|
1638
|
+
} = options;
|
|
1639
|
+
if (txs === void 0) {
|
|
1640
|
+
throw new Error("executeTransactions error: txs is undefined in executeTransactions");
|
|
1641
|
+
}
|
|
1642
|
+
const chainIds = txs.map((tx) => {
|
|
1643
|
+
if ("cosmosTx" in tx) {
|
|
1644
|
+
return {
|
|
1645
|
+
chainType: "cosmos",
|
|
1646
|
+
chainId: tx.cosmosTx?.chainId
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
if ("svmTx" in tx) {
|
|
1650
|
+
return {
|
|
1651
|
+
chainType: "svm",
|
|
1652
|
+
chainId: tx.svmTx?.chainId
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
if ("evmTx" in tx) {
|
|
1656
|
+
return {
|
|
1657
|
+
chainType: "evm",
|
|
1658
|
+
chainId: tx.evmTx?.chainId
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
const isGasStationSourceEVM = chainIds.find((item, i, array) => {
|
|
1663
|
+
return chunkKZOSEIWH_cjs.GAS_STATION_CHAIN_IDS.includes(item?.chainId ?? "") && array[i - 1]?.chainType === "evm";
|
|
1664
|
+
});
|
|
1665
|
+
chunkED2OY55G_cjs.ClientState.validateGasResults = void 0;
|
|
1666
|
+
const validateChainIds = !batchSimulate ? chainIds.map((x) => x?.chainId ?? "") : isGasStationSourceEVM ? chunkKZOSEIWH_cjs.GAS_STATION_CHAIN_IDS : [];
|
|
1667
|
+
await validateGasBalances({
|
|
1668
|
+
txs,
|
|
1669
|
+
getFallbackGasAmount: options.getFallbackGasAmount,
|
|
1670
|
+
getCosmosSigner: options.getCosmosSigner,
|
|
1671
|
+
getEvmSigner: options.getEvmSigner,
|
|
1672
|
+
onValidateGasBalance: options.onValidateGasBalance,
|
|
1673
|
+
simulate,
|
|
1674
|
+
disabledChainIds: validateChainIds
|
|
1675
|
+
});
|
|
1676
|
+
const validateEnabledChainIds = async (chainId) => {
|
|
1677
|
+
await validateGasBalances({
|
|
1678
|
+
txs,
|
|
1679
|
+
getFallbackGasAmount: options.getFallbackGasAmount,
|
|
1680
|
+
getCosmosSigner: options.getCosmosSigner,
|
|
1681
|
+
getEvmSigner: options.getEvmSigner,
|
|
1682
|
+
onValidateGasBalance: options.onValidateGasBalance,
|
|
1683
|
+
simulate,
|
|
1684
|
+
enabledChainIds: !batchSimulate ? [chainId] : validateChainIds
|
|
1685
|
+
});
|
|
1686
|
+
};
|
|
1687
|
+
for (let i = 0; i < txs.length; i++) {
|
|
1688
|
+
const tx = txs[i];
|
|
1689
|
+
if (!tx) {
|
|
1690
|
+
throw new Error(`executeRoute error: invalid message at index ${i}`);
|
|
1691
|
+
}
|
|
1692
|
+
let txResult;
|
|
1693
|
+
if ("cosmosTx" in tx) {
|
|
1694
|
+
await validateEnabledChainIds(tx.cosmosTx?.chainId ?? "");
|
|
1695
|
+
txResult = await executeCosmosTransaction({
|
|
1696
|
+
tx,
|
|
1697
|
+
options,
|
|
1698
|
+
index: i
|
|
1699
|
+
});
|
|
1700
|
+
} else if ("evmTx" in tx) {
|
|
1701
|
+
await validateEnabledChainIds(tx.evmTx?.chainId ?? "");
|
|
1702
|
+
const txResponse = await executeEvmTransaction(tx, options);
|
|
1703
|
+
txResult = {
|
|
1704
|
+
chainId: tx?.evmTx?.chainId ?? "",
|
|
1705
|
+
txHash: txResponse.transactionHash
|
|
1706
|
+
};
|
|
1707
|
+
} else if ("svmTx" in tx) {
|
|
1708
|
+
await validateEnabledChainIds(tx.svmTx?.chainId ?? "");
|
|
1709
|
+
txResult = await executeSvmTransaction(tx, options);
|
|
1710
|
+
} else {
|
|
1711
|
+
throw new Error("executeRoute error: invalid message type");
|
|
1712
|
+
}
|
|
1713
|
+
await onTransactionBroadcast?.({ ...txResult });
|
|
1714
|
+
const txStatusResponse = await waitForTransaction({
|
|
1715
|
+
...txResult,
|
|
1716
|
+
onTransactionTracked: options.onTransactionTracked
|
|
1717
|
+
});
|
|
1718
|
+
await onTransactionCompleted?.({
|
|
1719
|
+
chainId: txResult.chainId,
|
|
1720
|
+
txHash: txResult.txHash,
|
|
1721
|
+
status: txStatusResponse
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
var executeRoute = async (options) => {
|
|
1726
|
+
const { route, userAddresses, beforeMsg, afterMsg, timeoutSeconds } = options;
|
|
1727
|
+
let addressList = [];
|
|
1728
|
+
userAddresses.forEach((userAddress, index) => {
|
|
1729
|
+
const requiredChainAddress = route.requiredChainAddresses[index];
|
|
1730
|
+
if (requiredChainAddress === userAddress?.chainId) {
|
|
1731
|
+
addressList.push(userAddress.address);
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
if (addressList.length !== route.requiredChainAddresses.length) {
|
|
1735
|
+
addressList = userAddresses.map((x) => x.address);
|
|
1736
|
+
}
|
|
1737
|
+
const validLength = addressList.length === route.requiredChainAddresses.length || addressList.length === route.chainIds?.length;
|
|
1738
|
+
if (!validLength) {
|
|
1739
|
+
throw new Error("executeRoute error: invalid address list");
|
|
1740
|
+
}
|
|
1741
|
+
const isUserAddressesValid = await validateUserAddresses(userAddresses);
|
|
1742
|
+
if (!isUserAddressesValid) {
|
|
1743
|
+
throw new Error("executeRoute error: invalid user addresses");
|
|
1744
|
+
}
|
|
1745
|
+
const response = await chunk32MRDO7V_cjs.messages({
|
|
1746
|
+
timeoutSeconds,
|
|
1747
|
+
amountIn: route?.amountIn,
|
|
1748
|
+
amountOut: route.estimatedAmountOut || "0",
|
|
1749
|
+
sourceAssetChainId: route?.sourceAssetChainId,
|
|
1750
|
+
sourceAssetDenom: route?.sourceAssetDenom,
|
|
1751
|
+
destAssetChainId: route?.destAssetChainId,
|
|
1752
|
+
destAssetDenom: route?.destAssetDenom,
|
|
1753
|
+
operations: route?.operations,
|
|
1754
|
+
addressList,
|
|
1755
|
+
slippageTolerancePercent: options.slippageTolerancePercent || "1",
|
|
1756
|
+
chainIdsToAffiliates: chunkHAR3IXDE_cjs.ApiState.chainIdsToAffiliates
|
|
1757
|
+
});
|
|
1758
|
+
if (beforeMsg && (response?.txs?.length ?? 0) > 0) {
|
|
1759
|
+
const firstTx = response?.txs?.[0];
|
|
1760
|
+
if (firstTx && "cosmosTx" in firstTx) {
|
|
1761
|
+
firstTx.cosmosTx?.msgs?.unshift(beforeMsg);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (afterMsg && (response?.txs?.length ?? 0) > 0) {
|
|
1765
|
+
const lastTx = response?.txs?.[response.txs.length - 1];
|
|
1766
|
+
if (lastTx && "cosmosTx" in lastTx) {
|
|
1767
|
+
lastTx.cosmosTx?.msgs?.push(afterMsg);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
await executeTransactions({ ...options, txs: response?.txs });
|
|
1771
|
+
};
|
|
1772
|
+
var validateUserAddresses = async (userAddresses) => {
|
|
1773
|
+
const chains2 = await chunkED2OY55G_cjs.ClientState.getSkipChains();
|
|
1774
|
+
const validations = userAddresses.map((userAddress) => {
|
|
1775
|
+
const chain = chains2.find((chain2) => chain2.chainId === userAddress.chainId);
|
|
1776
|
+
switch (chain?.chainType) {
|
|
1777
|
+
case "cosmos" /* Cosmos */:
|
|
1778
|
+
try {
|
|
1779
|
+
if (chain.chainId?.includes("penumbra")) {
|
|
1780
|
+
try {
|
|
1781
|
+
return chain.bech32Prefix === bech32.bech32m.decode(userAddress.address, 143)?.prefix;
|
|
1782
|
+
} catch {
|
|
1783
|
+
return ["penumbracompat1", "tpenumbra"].includes(
|
|
1784
|
+
bech32.bech32.decode(userAddress.address, 1023).prefix
|
|
1785
|
+
);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return chain.bech32Prefix === bech32.bech32.decode(userAddress.address, 1023).prefix;
|
|
1789
|
+
} catch {
|
|
1790
|
+
return false;
|
|
1791
|
+
}
|
|
1792
|
+
case "evm" /* Evm */:
|
|
1793
|
+
try {
|
|
1794
|
+
return viem.isAddress(userAddress.address);
|
|
1795
|
+
} catch (_error) {
|
|
1796
|
+
return false;
|
|
1797
|
+
}
|
|
1798
|
+
case "svm" /* Svm */:
|
|
1799
|
+
try {
|
|
1800
|
+
const publicKey = new web3_js.PublicKey(userAddress.address);
|
|
1801
|
+
return web3_js.PublicKey.isOnCurve(publicKey);
|
|
1802
|
+
} catch (_error) {
|
|
1803
|
+
return false;
|
|
1804
|
+
}
|
|
1805
|
+
default:
|
|
1806
|
+
return false;
|
|
1807
|
+
}
|
|
1808
|
+
});
|
|
1809
|
+
return validations.every((validation) => validation);
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
exports.executeRoute = executeRoute;
|