@skip-go/client 1.6.0-alpha.3 → 1.6.0-alpha.5
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/postSubmitTransaction.cjs +12 -0
- package/dist/cjs/api/postTrackTransaction.cjs +12 -0
- package/dist/cjs/api/postTransactionStatus.cjs +12 -0
- package/dist/cjs/chunk-25TA7Z7R.cjs +460 -0
- package/dist/cjs/chunk-2QPPD3BB.cjs +210 -0
- package/dist/cjs/chunk-2SA3OAIJ.cjs +18 -0
- package/dist/cjs/chunk-3KO2DHFX.cjs +1495 -0
- package/dist/cjs/chunk-477CU2G2.cjs +280 -0
- package/dist/cjs/chunk-4BWE7SOV.cjs +68 -0
- package/dist/cjs/chunk-4GHUZDDP.cjs +16 -0
- package/dist/cjs/chunk-4ZIVDKQN.cjs +387 -0
- package/dist/cjs/chunk-6T4SBY5H.cjs +214 -0
- package/dist/cjs/chunk-A3UNNRKD.cjs +574 -0
- package/dist/cjs/chunk-A5S6SIYN.cjs +12 -0
- package/dist/cjs/chunk-ASDMDYTC.cjs +11 -0
- package/dist/cjs/chunk-ATW6UNT5.cjs +136 -0
- package/dist/cjs/chunk-AUTOIM57.cjs +22 -0
- package/dist/cjs/chunk-AVWWCQ5P.cjs +2264 -0
- package/dist/cjs/chunk-CIZTNJ3K.cjs +24 -0
- package/dist/cjs/chunk-CK6CQWQU.cjs +49 -0
- package/dist/cjs/chunk-EAZQ2ECA.cjs +185 -0
- package/dist/cjs/chunk-F3EB2AQG.cjs +28 -0
- package/dist/cjs/chunk-FCTBCHOT.cjs +12 -0
- package/dist/cjs/chunk-IJIBMN2F.cjs +12 -0
- package/dist/cjs/chunk-IUMMXFGP.cjs +189 -0
- package/dist/cjs/chunk-JRXPJ45U.cjs +12 -0
- package/dist/cjs/chunk-LJV45UGL.cjs +582 -0
- package/dist/cjs/chunk-MUJBB64F.cjs +291 -0
- package/dist/cjs/chunk-NCFH5MGF.cjs +39 -0
- package/dist/cjs/chunk-NM4PISTQ.cjs +3359 -0
- package/dist/cjs/chunk-OJISEAMX.cjs +13 -0
- package/dist/cjs/chunk-OVKHTOBP.cjs +99 -0
- package/dist/cjs/chunk-PDNKS5R2.cjs +13 -0
- package/dist/cjs/chunk-TELXDMYL.cjs +55 -0
- package/dist/cjs/chunk-UXW4XVHF.cjs +15 -0
- package/dist/cjs/index.cjs +349 -0
- package/dist/cjs/public-functions/executeMultipleRoutes.cjs +27 -0
- package/dist/cjs/public-functions/executeRoute.cjs +27 -0
- package/dist/cjs/public-functions/getCosmosGasAmountForMessage.cjs +16 -0
- package/dist/cjs/public-functions/getEvmGasAmountForMessage.cjs +11 -0
- package/dist/cjs/public-functions/getFeeInfoForChain.cjs +14 -0
- package/dist/cjs/public-functions/getRecommendedGasPrice.cjs +15 -0
- package/dist/cjs/public-functions/getRouteWithGasOnReceive.cjs +41 -0
- package/dist/cjs/public-functions/getSigningStargateClient.cjs +15 -0
- package/dist/cjs/public-functions/setApiOptions.cjs +12 -0
- package/dist/cjs/public-functions/setClientOptions.cjs +16 -0
- package/dist/cjs/public-functions/subscribeToRouteStatus.cjs +26 -0
- package/dist/cjs/public-functions/validateCosmosGasBalance.cjs +18 -0
- package/dist/cjs/public-functions/waitForTransaction.cjs +18 -0
- package/dist/esm/api/getAssets.d.ts +19 -0
- package/dist/esm/api/getAssets.js +3 -0
- package/dist/esm/api/getAssetsBetweenChains.d.ts +56 -0
- package/dist/esm/api/getAssetsBetweenChains.js +3 -0
- package/dist/esm/api/getBridges.d.ts +55 -0
- package/dist/esm/api/getBridges.js +3 -0
- package/dist/esm/api/getChains.d.ts +41 -0
- package/dist/esm/api/getChains.js +3 -0
- package/dist/esm/api/getVenues.d.ts +13 -0
- package/dist/esm/api/getVenues.js +3 -0
- package/dist/esm/api/postAssetsFromSource.d.ts +22 -0
- package/dist/esm/api/postAssetsFromSource.js +4 -0
- package/dist/esm/api/postBalances.d.ts +35 -0
- package/dist/esm/api/postBalances.js +3 -0
- package/dist/esm/api/postIbcOriginAssets.d.ts +32 -0
- package/dist/esm/api/postIbcOriginAssets.js +3 -0
- package/dist/esm/api/postMessages.d.ts +101 -0
- package/dist/esm/api/postMessages.js +3 -0
- package/dist/esm/api/postMessagesDirect.d.ts +640 -0
- package/dist/esm/api/postMessagesDirect.js +3 -0
- package/dist/esm/api/postRecommendAssets.d.ts +40 -0
- package/dist/esm/api/postRecommendAssets.js +3 -0
- package/dist/esm/api/postRoute.d.ts +530 -0
- package/dist/esm/api/postRoute.js +3 -0
- package/dist/esm/api/postSubmitTransaction.d.ts +17 -0
- package/dist/esm/api/postSubmitTransaction.js +3 -0
- package/dist/esm/api/postTrackTransaction.d.ts +12 -0
- package/dist/esm/api/postTrackTransaction.js +3 -0
- package/dist/esm/api/postTransactionStatus.d.ts +639 -0
- package/dist/esm/api/postTransactionStatus.js +3 -0
- package/dist/esm/apiState-1VvikVK-.d.ts +8 -0
- package/dist/esm/callbacks-DdC6QMlE.d.ts +158 -0
- package/dist/esm/chunk-3DIX6KRJ.js +566 -0
- package/dist/esm/chunk-3JHLVPRG.js +10 -0
- package/dist/esm/chunk-5WYMRZIO.js +97 -0
- package/dist/esm/chunk-A5NZMSTI.js +10 -0
- package/dist/esm/chunk-BU5RCZQH.js +187 -0
- package/dist/esm/chunk-CGJRRAFS.js +22 -0
- package/dist/esm/chunk-DMJMN4J3.js +379 -0
- package/dist/esm/chunk-E4NRDAVO.js +65 -0
- package/dist/esm/chunk-ETBJVFQP.js +10 -0
- package/dist/esm/chunk-F2LQB2DP.js +3323 -0
- package/dist/esm/chunk-F66EKL3W.js +203 -0
- package/dist/esm/chunk-G665WTT3.js +212 -0
- package/dist/esm/chunk-GPEO2I4P.js +272 -0
- package/dist/esm/chunk-GV2QOWB4.js +26 -0
- package/dist/esm/chunk-GZJLX2CP.js +2258 -0
- package/dist/esm/chunk-HNU2Y3JI.js +13 -0
- package/dist/esm/chunk-IZUHXTBP.js +53 -0
- package/dist/esm/chunk-J24LYWJE.js +130 -0
- package/dist/esm/chunk-KZKAL5ZN.js +16 -0
- package/dist/esm/chunk-N4PTRCNT.js +11 -0
- package/dist/esm/chunk-NUHMTWHP.js +180 -0
- package/dist/esm/chunk-P36PE4CR.js +37 -0
- package/dist/esm/chunk-QYXGDTUU.js +47 -0
- package/dist/esm/chunk-RH7PDDI5.js +433 -0
- package/dist/esm/chunk-RTDD7HZ3.js +275 -0
- package/dist/esm/chunk-SXBG57J3.js +20 -0
- package/dist/esm/chunk-TGTOO2ZQ.js +14 -0
- package/dist/esm/chunk-UHCKOKBM.js +9 -0
- package/dist/esm/chunk-ULUX2CVU.js +557 -0
- package/dist/esm/chunk-UN46DUOV.js +11 -0
- package/dist/esm/chunk-XIVAEU6S.js +1492 -0
- package/dist/esm/chunk-XNU3TKKM.js +10 -0
- package/dist/esm/client-types-D03Tellv.d.ts +114 -0
- package/dist/esm/generateApi-Bv02Xt5y.d.ts +56 -0
- package/dist/esm/index.d.ts +1859 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/public-functions/executeMultipleRoutes.d.ts +80 -0
- package/dist/esm/public-functions/executeMultipleRoutes.js +18 -0
- package/dist/esm/public-functions/executeRoute.d.ts +12 -0
- package/dist/esm/public-functions/executeRoute.js +18 -0
- package/dist/esm/public-functions/getCosmosGasAmountForMessage.d.ts +8 -0
- package/dist/esm/public-functions/getCosmosGasAmountForMessage.js +3 -0
- package/dist/esm/public-functions/getEvmGasAmountForMessage.d.ts +14 -0
- package/dist/esm/public-functions/getEvmGasAmountForMessage.js +2 -0
- package/dist/esm/public-functions/getFeeInfoForChain.d.ts +9 -0
- package/dist/esm/public-functions/getFeeInfoForChain.js +5 -0
- package/dist/esm/public-functions/getRecommendedGasPrice.d.ts +9 -0
- package/dist/esm/public-functions/getRecommendedGasPrice.js +6 -0
- package/dist/esm/public-functions/getRouteWithGasOnReceive.d.ts +20 -0
- package/dist/esm/public-functions/getRouteWithGasOnReceive.js +32 -0
- package/dist/esm/public-functions/getSigningStargateClient.d.ts +13 -0
- package/dist/esm/public-functions/getSigningStargateClient.js +6 -0
- package/dist/esm/public-functions/setApiOptions.d.ts +9 -0
- package/dist/esm/public-functions/setApiOptions.js +3 -0
- package/dist/esm/public-functions/setClientOptions.d.ts +11 -0
- package/dist/esm/public-functions/setClientOptions.js +7 -0
- package/dist/esm/public-functions/subscribeToRouteStatus.d.ts +12 -0
- package/dist/esm/public-functions/subscribeToRouteStatus.js +5 -0
- package/dist/esm/public-functions/validateCosmosGasBalance.d.ts +44 -0
- package/dist/esm/public-functions/validateCosmosGasBalance.js +9 -0
- package/dist/esm/public-functions/waitForTransaction.d.ts +1279 -0
- package/dist/esm/public-functions/waitForTransaction.js +5 -0
- package/dist/esm/setClientOptions-CTwe8YVX.d.ts +76 -0
- package/dist/esm/swaggerTypes-CzGbnX_b.d.ts +2067 -0
- package/package.json +1 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { getCosmosGasAmountForMessage } from './chunk-GPEO2I4P.js';
|
|
2
|
+
import { getSigningStargateClient } from './chunk-DMJMN4J3.js';
|
|
3
|
+
import { ClientState, balances } from './chunk-J24LYWJE.js';
|
|
4
|
+
import { BigNumber } from 'bignumber.js';
|
|
5
|
+
import { GasPrice, calculateFee } from '@cosmjs/stargate';
|
|
6
|
+
import { Decimal } from '@cosmjs/math';
|
|
7
|
+
|
|
8
|
+
var validateCosmosGasBalance = async ({
|
|
9
|
+
chainId,
|
|
10
|
+
signerAddress,
|
|
11
|
+
messages,
|
|
12
|
+
getFallbackGasAmount,
|
|
13
|
+
getOfflineSigner,
|
|
14
|
+
txIndex,
|
|
15
|
+
simulate,
|
|
16
|
+
getCosmosPriorityFeeDenom,
|
|
17
|
+
isMultiRoutes
|
|
18
|
+
}) => {
|
|
19
|
+
const skipAssets = (await ClientState.getSkipAssets({ chainId }))?.[chainId];
|
|
20
|
+
const skipChains = await ClientState.getSkipChains();
|
|
21
|
+
const prioFeeDenom = await getCosmosPriorityFeeDenom?.(chainId);
|
|
22
|
+
const chain = skipChains?.find((c) => c.chainId === chainId);
|
|
23
|
+
if (!chain) {
|
|
24
|
+
throw new Error(`failed to find chain id '${chainId}'`);
|
|
25
|
+
}
|
|
26
|
+
const { feeAssets } = chain;
|
|
27
|
+
if (!feeAssets) {
|
|
28
|
+
throw new Error(`failed to find fee assets for chain id '${chainId}'`);
|
|
29
|
+
}
|
|
30
|
+
const estimatedGasAmount = await (async () => {
|
|
31
|
+
try {
|
|
32
|
+
if (simulate === false) throw new Error("simulate");
|
|
33
|
+
if (txIndex !== 0 && chainId === "noble-1") {
|
|
34
|
+
return "0";
|
|
35
|
+
}
|
|
36
|
+
const { stargateClient } = await getSigningStargateClient({
|
|
37
|
+
chainId,
|
|
38
|
+
getOfflineSigner
|
|
39
|
+
});
|
|
40
|
+
const estimatedGas = await getCosmosGasAmountForMessage(
|
|
41
|
+
stargateClient,
|
|
42
|
+
signerAddress,
|
|
43
|
+
chainId,
|
|
44
|
+
messages
|
|
45
|
+
);
|
|
46
|
+
return estimatedGas;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
const error = e;
|
|
49
|
+
if (error.message === "simulate" && !getFallbackGasAmount) {
|
|
50
|
+
throw new Error(`unable to get gas amount for ${chainId}'s message(s)`);
|
|
51
|
+
}
|
|
52
|
+
if (getFallbackGasAmount) {
|
|
53
|
+
const fallbackGasAmount = await getFallbackGasAmount(
|
|
54
|
+
chainId,
|
|
55
|
+
"cosmos" /* Cosmos */
|
|
56
|
+
);
|
|
57
|
+
if (!fallbackGasAmount) {
|
|
58
|
+
throw new Error(`unable to estimate gas for message(s) ${messages}`);
|
|
59
|
+
}
|
|
60
|
+
return String(fallbackGasAmount);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
const fees = feeAssets.map((asset) => {
|
|
66
|
+
const gasPrice = (() => {
|
|
67
|
+
if (!asset?.gasPrice) return void 0;
|
|
68
|
+
let price = asset.gasPrice.average;
|
|
69
|
+
if (price === "") {
|
|
70
|
+
price = asset.gasPrice.high;
|
|
71
|
+
}
|
|
72
|
+
if (price === "") {
|
|
73
|
+
price = asset.gasPrice.low;
|
|
74
|
+
}
|
|
75
|
+
if (!price) return;
|
|
76
|
+
return new GasPrice(
|
|
77
|
+
Decimal.fromUserInput(BigNumber(price).toFixed(), 18),
|
|
78
|
+
asset?.denom ?? ""
|
|
79
|
+
);
|
|
80
|
+
})();
|
|
81
|
+
if (!gasPrice) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (chainId === "noble-1") {
|
|
85
|
+
if (isMultiRoutes && txIndex === 0) {
|
|
86
|
+
return calculateFee(
|
|
87
|
+
Math.ceil(parseFloat(estimatedGasAmount)),
|
|
88
|
+
gasPrice
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (asset.denom.toLowerCase() === "ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0".toLowerCase()) {
|
|
92
|
+
const fee2 = calculateFee(2e6, gasPrice);
|
|
93
|
+
return fee2;
|
|
94
|
+
}
|
|
95
|
+
const fee = calculateFee(2e5, gasPrice);
|
|
96
|
+
return fee;
|
|
97
|
+
}
|
|
98
|
+
return calculateFee(Math.ceil(parseFloat(estimatedGasAmount)), gasPrice);
|
|
99
|
+
});
|
|
100
|
+
const feeBalance = await balances({
|
|
101
|
+
chains: {
|
|
102
|
+
[chainId]: {
|
|
103
|
+
address: signerAddress,
|
|
104
|
+
denoms: feeAssets.map((asset) => asset.denom ?? "")
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const validatedAssets = feeAssets.map((asset, index) => {
|
|
109
|
+
const chainAsset = skipAssets?.find((x) => x.denom === asset.denom);
|
|
110
|
+
const symbol = chainAsset?.recommendedSymbol?.toUpperCase();
|
|
111
|
+
const decimal = Number(chainAsset?.decimals);
|
|
112
|
+
if (!chainAsset) {
|
|
113
|
+
return {
|
|
114
|
+
error: `(${chain?.prettyName}) Unable to find asset for ${asset.denom}`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (isNaN(decimal))
|
|
118
|
+
return {
|
|
119
|
+
error: `(${chain?.prettyName}) Unable to find decimal for ${symbol}`
|
|
120
|
+
};
|
|
121
|
+
const fee = fees[index];
|
|
122
|
+
if (!fee) {
|
|
123
|
+
return {
|
|
124
|
+
error: `(${chain?.prettyName}) Unable to calculate fee for ${symbol}`,
|
|
125
|
+
asset
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (txIndex !== 0 && chainId === "noble-1") {
|
|
129
|
+
return {
|
|
130
|
+
error: null,
|
|
131
|
+
asset,
|
|
132
|
+
fee
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
let balance = feeBalance?.chains?.[chainId]?.denoms?.[asset?.denom ?? ""];
|
|
136
|
+
if (!balance) {
|
|
137
|
+
balance = {
|
|
138
|
+
amount: "0",
|
|
139
|
+
formattedAmount: "0"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (!fee.amount[0]?.amount) {
|
|
143
|
+
return {
|
|
144
|
+
error: `(${chain?.prettyName}) Unable to get fee for ${symbol}`,
|
|
145
|
+
asset
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (parseInt(balance?.amount ?? "") < parseInt(fee.amount[0]?.amount)) {
|
|
149
|
+
const userAmount = new BigNumber(parseFloat(balance?.amount ?? "")).shiftedBy(-decimal).toFixed(decimal);
|
|
150
|
+
const feeAmount = new BigNumber(parseFloat(fee.amount[0]?.amount)).shiftedBy(-decimal).toFixed(decimal);
|
|
151
|
+
return {
|
|
152
|
+
error: `Insufficient balance for gas on ${chain?.prettyName}. Need ${feeAmount} ${symbol} but only have ${userAmount} ${symbol}.`,
|
|
153
|
+
asset
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
error: null,
|
|
158
|
+
asset,
|
|
159
|
+
fee
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
if (prioFeeDenom) {
|
|
163
|
+
const availableAssets = validatedAssets.filter(
|
|
164
|
+
(res) => res?.error === null
|
|
165
|
+
);
|
|
166
|
+
const prioFeeAsset = availableAssets.find(
|
|
167
|
+
(res) => res?.asset?.denom === prioFeeDenom
|
|
168
|
+
);
|
|
169
|
+
if (prioFeeAsset) {
|
|
170
|
+
return prioFeeAsset;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const feeUsed = validatedAssets.find((res) => res?.error === null);
|
|
174
|
+
if (!feeUsed) {
|
|
175
|
+
if (validatedAssets.length > 1) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chain.prettyName}.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
throw new Error(
|
|
181
|
+
validatedAssets[0]?.error || `Insufficient fee token to initiate transfer on ${chain.prettyName}.`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return feeUsed;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export { validateCosmosGasBalance };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getFeeInfoForChain } from './chunk-5WYMRZIO.js';
|
|
2
|
+
import { Decimal } from '@cosmjs/math';
|
|
3
|
+
import { GasPrice } from '@cosmjs/stargate';
|
|
4
|
+
import { BigNumber } from 'bignumber.js';
|
|
5
|
+
|
|
6
|
+
var getRecommendedGasPrice = async (props) => {
|
|
7
|
+
const feeInfo = await getFeeInfoForChain(props);
|
|
8
|
+
if (!feeInfo || !feeInfo.gasPrice) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
let price = feeInfo.gasPrice.average;
|
|
12
|
+
if (price === "") {
|
|
13
|
+
price = feeInfo.gasPrice.high;
|
|
14
|
+
}
|
|
15
|
+
if (price === "") {
|
|
16
|
+
price = feeInfo.gasPrice.low;
|
|
17
|
+
}
|
|
18
|
+
if (!price) return;
|
|
19
|
+
return new GasPrice(Decimal.fromUserInput(BigNumber(price).toFixed(), 18), feeInfo.denom);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { getRecommendedGasPrice };
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { BaseAccount as BaseAccount$1, base64FromBytes, bytesFromBase64, isSet } from './chunk-RTDD7HZ3.js';
|
|
2
|
+
import { chains, findFirstWorkingEndpoint } from './chunk-NUHMTWHP.js';
|
|
3
|
+
import { ClientState } from './chunk-J24LYWJE.js';
|
|
4
|
+
import { accountFromAny, SigningStargateClient } from '@cosmjs/stargate';
|
|
5
|
+
import { assertDefinedAndNotNull } from '@cosmjs/utils';
|
|
6
|
+
import { BinaryWriter, BinaryReader } from 'cosmjs-types/binary.js';
|
|
7
|
+
import { BaseAccount } from 'cosmjs-types/cosmos/auth/v1beta1/auth.js';
|
|
8
|
+
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin.js';
|
|
9
|
+
import { decodePubkey } from '@cosmjs/proto-signing';
|
|
10
|
+
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys.js';
|
|
11
|
+
import { encodeSecp256k1Pubkey } from '@cosmjs/amino';
|
|
12
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
13
|
+
|
|
14
|
+
var createBaseVestingAccount = () => {
|
|
15
|
+
return {
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
baseAccount: void 0,
|
|
18
|
+
originalVesting: [],
|
|
19
|
+
delegatedFree: [],
|
|
20
|
+
delegatedVesting: [],
|
|
21
|
+
endTime: BigInt(0)
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
var BaseVestingAccount = {
|
|
25
|
+
encode(message, writer = BinaryWriter.create()) {
|
|
26
|
+
if (message.baseAccount !== void 0) {
|
|
27
|
+
BaseAccount.encode(
|
|
28
|
+
message.baseAccount,
|
|
29
|
+
writer.uint32(10).fork()
|
|
30
|
+
).ldelim();
|
|
31
|
+
}
|
|
32
|
+
for (const v of message.originalVesting) {
|
|
33
|
+
Coin.encode(v, writer.uint32(18).fork()).ldelim();
|
|
34
|
+
}
|
|
35
|
+
for (const v of message.delegatedFree) {
|
|
36
|
+
Coin.encode(v, writer.uint32(26).fork()).ldelim();
|
|
37
|
+
}
|
|
38
|
+
for (const v of message.delegatedVesting) {
|
|
39
|
+
Coin.encode(v, writer.uint32(34).fork()).ldelim();
|
|
40
|
+
}
|
|
41
|
+
if (message.endTime !== BigInt(0)) {
|
|
42
|
+
writer.uint32(40).int64(message.endTime);
|
|
43
|
+
}
|
|
44
|
+
return writer;
|
|
45
|
+
},
|
|
46
|
+
decode(input, length) {
|
|
47
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
48
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
49
|
+
const message = createBaseVestingAccount();
|
|
50
|
+
while (reader.pos < end) {
|
|
51
|
+
const tag = reader.uint32();
|
|
52
|
+
switch (tag >>> 3) {
|
|
53
|
+
case 1:
|
|
54
|
+
message.baseAccount = BaseAccount.decode(reader, reader.uint32());
|
|
55
|
+
break;
|
|
56
|
+
case 2:
|
|
57
|
+
message.originalVesting.push(Coin.decode(reader, reader.uint32()));
|
|
58
|
+
break;
|
|
59
|
+
case 3:
|
|
60
|
+
message.delegatedFree.push(Coin.decode(reader, reader.uint32()));
|
|
61
|
+
break;
|
|
62
|
+
case 4:
|
|
63
|
+
message.delegatedVesting.push(Coin.decode(reader, reader.uint32()));
|
|
64
|
+
break;
|
|
65
|
+
case 5:
|
|
66
|
+
message.endTime = reader.int64();
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
reader.skipType(tag & 7);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return message;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function createBasePeriod() {
|
|
77
|
+
return {
|
|
78
|
+
startTime: BigInt(0),
|
|
79
|
+
length: BigInt(0),
|
|
80
|
+
amount: [],
|
|
81
|
+
actionType: 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var Period = {
|
|
85
|
+
encode(message, writer = BinaryWriter.create()) {
|
|
86
|
+
if (message.startTime !== BigInt(0)) {
|
|
87
|
+
writer.uint32(8).int64(message.startTime);
|
|
88
|
+
}
|
|
89
|
+
if (message.length !== BigInt(0)) {
|
|
90
|
+
writer.uint32(16).int64(message.length);
|
|
91
|
+
}
|
|
92
|
+
for (const v of message.amount) {
|
|
93
|
+
Coin.encode(v, writer.uint32(26).fork()).ldelim();
|
|
94
|
+
}
|
|
95
|
+
if (message.actionType !== 0) {
|
|
96
|
+
writer.uint32(32).int32(message.actionType);
|
|
97
|
+
}
|
|
98
|
+
return writer;
|
|
99
|
+
},
|
|
100
|
+
decode(input, length) {
|
|
101
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
102
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
103
|
+
const message = createBasePeriod();
|
|
104
|
+
while (reader.pos < end) {
|
|
105
|
+
const tag = reader.uint32();
|
|
106
|
+
switch (tag >>> 3) {
|
|
107
|
+
case 1:
|
|
108
|
+
message.startTime = reader.int64();
|
|
109
|
+
break;
|
|
110
|
+
case 2:
|
|
111
|
+
message.length = reader.int64();
|
|
112
|
+
break;
|
|
113
|
+
case 3:
|
|
114
|
+
message.amount.push(Coin.decode(reader, reader.uint32()));
|
|
115
|
+
break;
|
|
116
|
+
case 4:
|
|
117
|
+
message.actionType = reader.int32();
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
reader.skipType(tag & 7);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return message;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function createBaseStridePeriodicVestingAccount() {
|
|
128
|
+
return {
|
|
129
|
+
//eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
130
|
+
//@ts-ignore
|
|
131
|
+
baseVestingAccount: void 0,
|
|
132
|
+
vestingPeriods: []
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var StridePeriodicVestingAccount = {
|
|
136
|
+
encode(message, writer = BinaryWriter.create()) {
|
|
137
|
+
if (message.baseVestingAccount !== void 0) {
|
|
138
|
+
BaseVestingAccount.encode(
|
|
139
|
+
message.baseVestingAccount,
|
|
140
|
+
writer.uint32(10).fork()
|
|
141
|
+
).ldelim();
|
|
142
|
+
}
|
|
143
|
+
for (const v of message.vestingPeriods) {
|
|
144
|
+
Period.encode(v, writer.uint32(26).fork()).ldelim();
|
|
145
|
+
}
|
|
146
|
+
return writer;
|
|
147
|
+
},
|
|
148
|
+
decode(input, length) {
|
|
149
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
150
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
151
|
+
const message = createBaseStridePeriodicVestingAccount();
|
|
152
|
+
while (reader.pos < end) {
|
|
153
|
+
const tag = reader.uint32();
|
|
154
|
+
switch (tag >>> 3) {
|
|
155
|
+
case 1:
|
|
156
|
+
message.baseVestingAccount = BaseVestingAccount.decode(
|
|
157
|
+
reader,
|
|
158
|
+
reader.uint32()
|
|
159
|
+
);
|
|
160
|
+
break;
|
|
161
|
+
case 3:
|
|
162
|
+
message.vestingPeriods.push(Period.decode(reader, reader.uint32()));
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
reader.skipType(tag & 7);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return message;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
function createBaseEthAccount() {
|
|
173
|
+
return {
|
|
174
|
+
baseAccount: void 0,
|
|
175
|
+
codeHash: new Uint8Array()
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
var EthAccount = {
|
|
179
|
+
typeUrl: "/injective.types.v1beta1.EthAccount",
|
|
180
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
181
|
+
if (message.baseAccount !== void 0) {
|
|
182
|
+
BaseAccount$1.encode(message.baseAccount, writer.uint32(10).fork()).ldelim();
|
|
183
|
+
}
|
|
184
|
+
if (message.codeHash.length !== 0) {
|
|
185
|
+
writer.uint32(18).bytes(message.codeHash);
|
|
186
|
+
}
|
|
187
|
+
return writer;
|
|
188
|
+
},
|
|
189
|
+
decode(input, length) {
|
|
190
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
191
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
192
|
+
const message = createBaseEthAccount();
|
|
193
|
+
while (reader.pos < end) {
|
|
194
|
+
const tag = reader.uint32();
|
|
195
|
+
switch (tag >>> 3) {
|
|
196
|
+
case 1:
|
|
197
|
+
message.baseAccount = BaseAccount$1.decode(reader, reader.uint32());
|
|
198
|
+
break;
|
|
199
|
+
case 2:
|
|
200
|
+
message.codeHash = reader.bytes();
|
|
201
|
+
break;
|
|
202
|
+
default:
|
|
203
|
+
reader.skipType(tag & 7);
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return message;
|
|
208
|
+
},
|
|
209
|
+
fromJSON(object) {
|
|
210
|
+
return {
|
|
211
|
+
baseAccount: isSet(object.baseAccount) ? BaseAccount$1.fromJSON(object.baseAccount) : void 0,
|
|
212
|
+
codeHash: isSet(object.codeHash) ? bytesFromBase64(object.codeHash) : new Uint8Array()
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
toJSON(message) {
|
|
216
|
+
const obj = {};
|
|
217
|
+
message.baseAccount !== void 0 && (obj.baseAccount = message.baseAccount ? BaseAccount$1.toJSON(message.baseAccount) : void 0);
|
|
218
|
+
message.codeHash !== void 0 && (obj.codeHash = base64FromBytes(message.codeHash !== void 0 ? message.codeHash : new Uint8Array()));
|
|
219
|
+
return obj;
|
|
220
|
+
},
|
|
221
|
+
fromPartial(object) {
|
|
222
|
+
const message = createBaseEthAccount();
|
|
223
|
+
message.baseAccount = object.baseAccount !== void 0 && object.baseAccount !== null ? BaseAccount$1.fromPartial(object.baseAccount) : void 0;
|
|
224
|
+
message.codeHash = object.codeHash ?? new Uint8Array();
|
|
225
|
+
return message;
|
|
226
|
+
},
|
|
227
|
+
fromAmino(object) {
|
|
228
|
+
const message = createBaseEthAccount();
|
|
229
|
+
if (object.base_account !== void 0 && object.base_account !== null) {
|
|
230
|
+
message.baseAccount = BaseAccount$1.fromAmino(object.base_account);
|
|
231
|
+
}
|
|
232
|
+
if (object.code_hash !== void 0 && object.code_hash !== null) {
|
|
233
|
+
message.codeHash = bytesFromBase64(object.code_hash);
|
|
234
|
+
}
|
|
235
|
+
return message;
|
|
236
|
+
},
|
|
237
|
+
toAmino(message) {
|
|
238
|
+
const obj = {};
|
|
239
|
+
obj.base_account = message.baseAccount ? BaseAccount$1.toAmino(message.baseAccount) : void 0;
|
|
240
|
+
obj.code_hash = message.codeHash ? base64FromBytes(message.codeHash) : void 0;
|
|
241
|
+
return obj;
|
|
242
|
+
},
|
|
243
|
+
fromAminoMsg(object) {
|
|
244
|
+
return EthAccount.fromAmino(object.value);
|
|
245
|
+
},
|
|
246
|
+
fromProtoMsg(message) {
|
|
247
|
+
return EthAccount.decode(message.value);
|
|
248
|
+
},
|
|
249
|
+
toProto(message) {
|
|
250
|
+
return EthAccount.encode(message).finish();
|
|
251
|
+
},
|
|
252
|
+
toProtoMsg(message) {
|
|
253
|
+
return {
|
|
254
|
+
typeUrl: "/injective.types.v1beta1.EthAccount",
|
|
255
|
+
value: EthAccount.encode(message).finish()
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/registry.ts
|
|
261
|
+
var accountParser = (acc) => {
|
|
262
|
+
switch (acc.typeUrl) {
|
|
263
|
+
case "/stride.vesting.StridePeriodicVestingAccount": {
|
|
264
|
+
const baseAccount = StridePeriodicVestingAccount.decode(acc.value).baseVestingAccount?.baseAccount;
|
|
265
|
+
assertDefinedAndNotNull(baseAccount);
|
|
266
|
+
return {
|
|
267
|
+
address: baseAccount.address,
|
|
268
|
+
pubkey: baseAccount.pubKey ? decodePubkey(baseAccount.pubKey) : null,
|
|
269
|
+
accountNumber: Number(baseAccount.accountNumber),
|
|
270
|
+
sequence: Number(baseAccount.sequence)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
case "/injective.types.v1beta1.EthAccount":
|
|
274
|
+
return accountEthParser(
|
|
275
|
+
acc,
|
|
276
|
+
"/injective.crypto.v1beta1.ethsecp256k1.PubKey"
|
|
277
|
+
);
|
|
278
|
+
case "/ethermint.types.v1.EthAccount":
|
|
279
|
+
return accountEthParser(acc, "/ethermint.crypto.v1.ethsecp256k1.PubKey");
|
|
280
|
+
default: {
|
|
281
|
+
if (acc.typeUrl === "/cosmos.auth.v1beta1.BaseAccount") {
|
|
282
|
+
const { address, pubKey, accountNumber, sequence } = BaseAccount.decode(
|
|
283
|
+
acc.value
|
|
284
|
+
);
|
|
285
|
+
switch (pubKey?.typeUrl) {
|
|
286
|
+
case "/initia.crypto.v1beta1.ethsecp256k1.PubKey":
|
|
287
|
+
case "/ethermint.crypto.v1.ethsecp256k1.PubKey":
|
|
288
|
+
case "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey": {
|
|
289
|
+
const { key } = PubKey.decode(pubKey.value);
|
|
290
|
+
const pk = encodeSecp256k1Pubkey(key);
|
|
291
|
+
return {
|
|
292
|
+
address,
|
|
293
|
+
pubkey: pk,
|
|
294
|
+
accountNumber: Number(accountNumber),
|
|
295
|
+
sequence: Number(sequence)
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return accountFromAny(acc);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var accountEthParser = (ethAccount, pubKeyTypeUrl = "/injective.crypto.v1beta1.ethsecp256k1.PubKey") => {
|
|
305
|
+
const account = EthAccount.decode(
|
|
306
|
+
ethAccount.value
|
|
307
|
+
);
|
|
308
|
+
const baseAccount = account.baseAccount;
|
|
309
|
+
const pubKey = baseAccount.pubKey;
|
|
310
|
+
return {
|
|
311
|
+
address: baseAccount.address,
|
|
312
|
+
pubkey: pubKey ? {
|
|
313
|
+
type: pubKeyTypeUrl,
|
|
314
|
+
value: Buffer.from(pubKey.value).toString("base64")
|
|
315
|
+
} : null,
|
|
316
|
+
accountNumber: parseInt(baseAccount.accountNumber.toString(), 10),
|
|
317
|
+
sequence: parseInt(baseAccount.sequence.toString(), 10)
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/private-functions/getRpcEndpointForChain.ts
|
|
322
|
+
var getRpcEndpointForChain = async (chainId) => {
|
|
323
|
+
if (ClientState.endpointOptions.getRpcEndpointForChain) {
|
|
324
|
+
return ClientState.endpointOptions.getRpcEndpointForChain(chainId);
|
|
325
|
+
}
|
|
326
|
+
if (ClientState.endpointOptions.endpoints && ClientState.endpointOptions.endpoints[chainId]) {
|
|
327
|
+
const endpointOptions = ClientState.endpointOptions.endpoints[chainId];
|
|
328
|
+
if (endpointOptions?.rpc) {
|
|
329
|
+
return endpointOptions.rpc;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
console.warn(
|
|
333
|
+
"Warning: You are using unreliable public endpoints. We strongly recommend overriding them via endpointOptions for use beyond development settings."
|
|
334
|
+
);
|
|
335
|
+
const chain = chains().find((chain2) => chain2.chainId === chainId);
|
|
336
|
+
if (!chain) {
|
|
337
|
+
throw new Error(`getRpcEndpointForChain: failed to find chain id '${chainId}' in registry`);
|
|
338
|
+
}
|
|
339
|
+
if (chain.apis?.rpc?.length === 0 || !chain.apis?.rpc) {
|
|
340
|
+
throw new Error(
|
|
341
|
+
`getRpcEndpointForChain error: failed to find RPC endpoint for chain id '${chainId}'`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const endpoints = chain.apis?.rpc?.map((api) => api.address);
|
|
345
|
+
const endpoint = await findFirstWorkingEndpoint(endpoints, "rpc");
|
|
346
|
+
if (!endpoint) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`getRpcEndpointForChain error: failed to find RPC endpoint for chain id '${chainId}'`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
return endpoint;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// src/public-functions/getSigningStargateClient.ts
|
|
355
|
+
var getSigningStargateClient = async ({
|
|
356
|
+
chainId,
|
|
357
|
+
getOfflineSigner
|
|
358
|
+
}) => {
|
|
359
|
+
if (!getOfflineSigner) {
|
|
360
|
+
throw new Error("'getCosmosSigner' is not provided or configured in skip router");
|
|
361
|
+
}
|
|
362
|
+
if (!ClientState.signingStargateClientByChainId?.[chainId]) {
|
|
363
|
+
const [signer, endpoint] = await Promise.all([
|
|
364
|
+
getOfflineSigner(chainId),
|
|
365
|
+
getRpcEndpointForChain(chainId)
|
|
366
|
+
]);
|
|
367
|
+
ClientState.signingStargateClientByChainId[chainId] = await SigningStargateClient.connectWithSigner(endpoint, signer, {
|
|
368
|
+
aminoTypes: ClientState.aminoTypes,
|
|
369
|
+
registry: ClientState.registry,
|
|
370
|
+
accountParser
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
stargateClient: ClientState.signingStargateClientByChainId[chainId],
|
|
375
|
+
signer: await getOfflineSigner(chainId)
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export { accountParser, getRpcEndpointForChain, getSigningStargateClient };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { trackTransaction } from './chunk-SXBG57J3.js';
|
|
2
|
+
import { transactionStatus } from './chunk-N4PTRCNT.js';
|
|
3
|
+
import { wait } from './chunk-F66EKL3W.js';
|
|
4
|
+
|
|
5
|
+
// src/public-functions/waitForTransaction.ts
|
|
6
|
+
var waitForTransaction = async ({
|
|
7
|
+
chainId,
|
|
8
|
+
txHash,
|
|
9
|
+
explorerLink,
|
|
10
|
+
doNotTrack = false,
|
|
11
|
+
onStatusUpdated,
|
|
12
|
+
onError,
|
|
13
|
+
onTransactionTracked,
|
|
14
|
+
isCancelled,
|
|
15
|
+
...trackTxPollingOptions
|
|
16
|
+
}) => {
|
|
17
|
+
try {
|
|
18
|
+
if (!explorerLink && !doNotTrack) {
|
|
19
|
+
const response = await trackTransaction({
|
|
20
|
+
chainId,
|
|
21
|
+
txHash,
|
|
22
|
+
...trackTxPollingOptions
|
|
23
|
+
});
|
|
24
|
+
explorerLink = response.explorerLink;
|
|
25
|
+
await onTransactionTracked?.({ txHash, chainId, explorerLink });
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn(`track failed for txHash:${txHash}, chainId: ${chainId}`);
|
|
29
|
+
}
|
|
30
|
+
while (true) {
|
|
31
|
+
if (isCancelled?.()) {
|
|
32
|
+
throw new Error("waitForTransaction was aborted");
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const txStatusResponse = await transactionStatus({
|
|
36
|
+
chainId,
|
|
37
|
+
txHash
|
|
38
|
+
});
|
|
39
|
+
onStatusUpdated?.(txStatusResponse);
|
|
40
|
+
if (txStatusResponse.state === "STATE_COMPLETED_SUCCESS") {
|
|
41
|
+
return txStatusResponse;
|
|
42
|
+
}
|
|
43
|
+
if (txStatusResponse.state === "STATE_COMPLETED_ERROR") {
|
|
44
|
+
throw new Error(`${txStatusResponse.error?.type}: ${txStatusResponse.error?.message}`);
|
|
45
|
+
}
|
|
46
|
+
if (txStatusResponse.state === "STATE_ABANDONED") {
|
|
47
|
+
throw new Error("Tracking for the transaction has been abandoned");
|
|
48
|
+
}
|
|
49
|
+
await wait(1e3);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
onError?.(error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var waitForTransactionWithCancel = (props) => {
|
|
57
|
+
let isCancelled = false;
|
|
58
|
+
const cancel = () => {
|
|
59
|
+
isCancelled = true;
|
|
60
|
+
};
|
|
61
|
+
const wrappedPromise = waitForTransaction({ ...props, isCancelled: () => isCancelled });
|
|
62
|
+
return { promise: wrappedPromise, cancel };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { waitForTransaction, waitForTransactionWithCancel };
|