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