carbon-js-sdk 0.4.5 → 0.4.6-dev.1
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/lib/CarbonSDK.js +1 -1
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.d.ts +11 -4
- package/lib/clients/ETHClient.js +32 -18
- package/lib/clients/HydrogenClient.d.ts +16 -7
- package/lib/clients/HydrogenClient.js +56 -10
- package/lib/clients/InsightsQueryClient.d.ts +1 -0
- package/lib/clients/InsightsQueryClient.js +8 -0
- package/lib/clients/NEOClient.d.ts +1 -1
- package/lib/clients/NEOClient.js +15 -10
- package/lib/clients/TokenClient.d.ts +29 -5
- package/lib/clients/TokenClient.js +258 -53
- package/lib/clients/ZILClient.d.ts +1 -1
- package/lib/clients/ZILClient.js +25 -20
- package/lib/codec/cdp/e_mode_category.d.ts +23 -0
- package/lib/codec/cdp/e_mode_category.js +135 -0
- package/lib/codec/cosmos/gov/v1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1/tx.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/group/v1/events.js +2 -2
- package/lib/codec/cosmos/group/v1/tx.js +4 -4
- package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.d.ts +1 -0
- package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.js +6 -0
- package/lib/codec/ethermint/evm/v1/export.d.ts +5 -0
- package/lib/codec/ethermint/evm/v1/export.js +53 -0
- package/lib/codec/ethermint/feemarket/v1/export.d.ts +4 -0
- package/lib/codec/ethermint/feemarket/v1/export.js +18 -0
- package/lib/codec/ethermint/types/v1/export.d.ts +4 -0
- package/lib/codec/ethermint/types/v1/export.js +11 -0
- package/lib/codec/ethermint-models.d.ts +4 -0
- package/lib/codec/ethermint-models.js +26 -0
- package/lib/constant/eip712.d.ts +28 -0
- package/lib/constant/eip712.js +40 -0
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.d.ts +7 -0
- package/lib/constant/ibc.js +4 -1
- package/lib/constant/network.d.ts +2 -0
- package/lib/constant/network.js +5 -1
- package/lib/hydrogen/transfer.d.ts +5 -5
- package/lib/insights/common.d.ts +1 -0
- package/lib/insights/common.js +1 -0
- package/lib/insights/competition.d.ts +20 -0
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/evm.d.ts +46 -0
- package/lib/modules/evm.js +127 -0
- package/lib/modules/evmmerge.d.ts +12 -0
- package/lib/modules/evmmerge.js +35 -0
- package/lib/modules/feemarket.d.ts +20 -0
- package/lib/modules/feemarket.js +45 -0
- package/lib/modules/gov.js +12 -12
- package/lib/modules/ibc.d.ts +5 -1
- package/lib/modules/ibc.js +78 -0
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +27 -27
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +22 -22
- package/lib/provider/amino/types/coin.js +4 -4
- package/lib/provider/amino/types/gov.js +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/keplr/KeplrStore.d.ts +1 -1
- package/lib/provider/keplr/KeplrStore.js +2 -5
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.d.ts +5 -5
- package/lib/provider/metamask/MetaMask.js +37 -37
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/blockchain.d.ts +26 -0
- package/lib/util/blockchain.js +160 -1
- package/lib/util/eip712.d.ts +10 -0
- package/lib/util/eip712.js +46 -0
- package/lib/util/ethermint.d.ts +4 -0
- package/lib/util/ethermint.js +26 -0
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/ibc.d.ts +5 -3
- package/lib/util/ibc.js +26 -1
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
package/lib/util/blockchain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.BRIDGE_IDS = exports.Blockchain = void 0;
|
|
3
|
+
exports.isEvmChain = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = void 0;
|
|
4
4
|
const network_1 = require("../constant/network");
|
|
5
5
|
var Blockchain;
|
|
6
6
|
(function (Blockchain) {
|
|
@@ -38,10 +38,24 @@ var Blockchain;
|
|
|
38
38
|
Blockchain["Agoric"] = "agoric";
|
|
39
39
|
Blockchain["Sommelier"] = "sommelier";
|
|
40
40
|
})(Blockchain = exports.Blockchain || (exports.Blockchain = {}));
|
|
41
|
+
exports.BLOCKCHAIN_V2_TO_V1_MAPPING = {
|
|
42
|
+
"Binance Smart Chain": Blockchain.BinanceSmartChain,
|
|
43
|
+
"Ethereum": Blockchain.Ethereum,
|
|
44
|
+
"Arbitrum": Blockchain.Arbitrum,
|
|
45
|
+
"Polygon": Blockchain.Polygon,
|
|
46
|
+
"OKC": Blockchain.Okc,
|
|
47
|
+
"Zilliqa": Blockchain.Zilliqa,
|
|
48
|
+
"Neo": Blockchain.Neo,
|
|
49
|
+
"Neo3": Blockchain.Neo3
|
|
50
|
+
};
|
|
41
51
|
exports.BRIDGE_IDS = {
|
|
42
52
|
polynetwork: 1,
|
|
43
53
|
ibc: 2,
|
|
44
54
|
};
|
|
55
|
+
function isIbcBridge(object) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(object, "chain_id_name");
|
|
57
|
+
}
|
|
58
|
+
exports.isIbcBridge = isIbcBridge;
|
|
45
59
|
exports.ChainNames = {
|
|
46
60
|
1: "MainNet",
|
|
47
61
|
3: "Ropsten",
|
|
@@ -260,3 +274,148 @@ const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
|
260
274
|
}
|
|
261
275
|
};
|
|
262
276
|
exports.blockchainForChainId = blockchainForChainId;
|
|
277
|
+
const getBlockchainFromChainV2 = (chainId) => {
|
|
278
|
+
switch (chainId) {
|
|
279
|
+
case 1:
|
|
280
|
+
case 3:
|
|
281
|
+
case 4:
|
|
282
|
+
case 5:
|
|
283
|
+
return 'Ethereum';
|
|
284
|
+
case 56:
|
|
285
|
+
case 97:
|
|
286
|
+
return 'Binance Smart Chain';
|
|
287
|
+
case 65:
|
|
288
|
+
case 66:
|
|
289
|
+
return 'Okc';
|
|
290
|
+
case 137:
|
|
291
|
+
case 80001:
|
|
292
|
+
return 'Polygon';
|
|
293
|
+
case 110:
|
|
294
|
+
case 111:
|
|
295
|
+
return 'Zilliqa';
|
|
296
|
+
case 42161:
|
|
297
|
+
case 421611:
|
|
298
|
+
return 'Arbitrum';
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
};
|
|
302
|
+
exports.getBlockchainFromChainV2 = getBlockchainFromChainV2;
|
|
303
|
+
const blockchainForChainIdV2 = (chainId, network = network_1.Network.MainNet) => {
|
|
304
|
+
switch (network) {
|
|
305
|
+
case network_1.Network.MainNet:
|
|
306
|
+
switch (chainId) {
|
|
307
|
+
case 0:
|
|
308
|
+
return "Native";
|
|
309
|
+
case 1:
|
|
310
|
+
return "Bitcoin";
|
|
311
|
+
case 2:
|
|
312
|
+
return "Ethereum";
|
|
313
|
+
case 4:
|
|
314
|
+
return "Neo";
|
|
315
|
+
case 6:
|
|
316
|
+
return "Binance Smart Chain";
|
|
317
|
+
case 14:
|
|
318
|
+
return "Neo3";
|
|
319
|
+
case 9: /* FALLTHROUGH */
|
|
320
|
+
case 18:
|
|
321
|
+
return "Zilliqa";
|
|
322
|
+
case 12: /* FALLTHROUGH */
|
|
323
|
+
case 66:
|
|
324
|
+
return 'Okc';
|
|
325
|
+
case 17: /* FALLTHROUGH */
|
|
326
|
+
case 137:
|
|
327
|
+
return 'Polygon';
|
|
328
|
+
case 244:
|
|
329
|
+
return "Osmosis";
|
|
330
|
+
case 13: /* FALLTHROUGH */
|
|
331
|
+
case 245:
|
|
332
|
+
return "Terra Classic";
|
|
333
|
+
case 246:
|
|
334
|
+
return "Cosmos Hub";
|
|
335
|
+
case 5: /* FALLTHROUGH */
|
|
336
|
+
case 247:
|
|
337
|
+
return "Juno";
|
|
338
|
+
case 7: /* FALLTHROUGH */
|
|
339
|
+
case 248:
|
|
340
|
+
return "Evmos";
|
|
341
|
+
case 8: /* FALLTHROUGH */
|
|
342
|
+
case 249:
|
|
343
|
+
return "Axelar";
|
|
344
|
+
case 313:
|
|
345
|
+
return "Stride";
|
|
346
|
+
case 314:
|
|
347
|
+
return "Kujira";
|
|
348
|
+
case 315:
|
|
349
|
+
return "Terra";
|
|
350
|
+
case 316:
|
|
351
|
+
return "Quicksilver";
|
|
352
|
+
case 12: /* FALLTHROUGH */
|
|
353
|
+
case 317:
|
|
354
|
+
return "Comdex";
|
|
355
|
+
case 318:
|
|
356
|
+
return "Stafihub";
|
|
357
|
+
case 15: /* FALLTHROUGH */
|
|
358
|
+
case 319:
|
|
359
|
+
return "Persistence Core";
|
|
360
|
+
case 16: /* FALLTHROUGH */
|
|
361
|
+
case 320:
|
|
362
|
+
return "Stargaze";
|
|
363
|
+
case 321:
|
|
364
|
+
return "Canto";
|
|
365
|
+
case 322:
|
|
366
|
+
return "OmniFlix Hub";
|
|
367
|
+
case 323:
|
|
368
|
+
return "Agoric";
|
|
369
|
+
case 19: /* FALLTHROUGH */
|
|
370
|
+
case 42161:
|
|
371
|
+
return "Arbitrum";
|
|
372
|
+
default:
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
case network_1.Network.TestNet:
|
|
376
|
+
switch (chainId) {
|
|
377
|
+
case 1:
|
|
378
|
+
return "Bitcoin";
|
|
379
|
+
case 0:
|
|
380
|
+
case 5:
|
|
381
|
+
return "Carbon";
|
|
382
|
+
case 79:
|
|
383
|
+
return "Binance Smart Chain";
|
|
384
|
+
case 88:
|
|
385
|
+
return "Neo3";
|
|
386
|
+
case 111:
|
|
387
|
+
return "Zilliqa";
|
|
388
|
+
case 2: /* FALLTHROUGH */
|
|
389
|
+
case 502:
|
|
390
|
+
return "Ethereum";
|
|
391
|
+
default:
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
case network_1.Network.DevNet:
|
|
395
|
+
switch (chainId) {
|
|
396
|
+
case 0:
|
|
397
|
+
return 'Carbon';
|
|
398
|
+
case 1:
|
|
399
|
+
return 'Bitcoin';
|
|
400
|
+
case 2:
|
|
401
|
+
case 350:
|
|
402
|
+
return "Ethereum";
|
|
403
|
+
case 5:
|
|
404
|
+
return "Neo";
|
|
405
|
+
case 79:
|
|
406
|
+
return "Binance Smart Chain";
|
|
407
|
+
case 111:
|
|
408
|
+
return 'Zilliqa';
|
|
409
|
+
default:
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
case network_1.Network.LocalHost:
|
|
413
|
+
return undefined;
|
|
414
|
+
default:
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
exports.blockchainForChainIdV2 = blockchainForChainIdV2;
|
|
419
|
+
const evmChains = ['Ethereum', 'Binance Smart Chain', 'Arbitrum', 'Polygon', 'OKC'];
|
|
420
|
+
const isEvmChain = (chain) => evmChains.includes(chain);
|
|
421
|
+
exports.isEvmChain = isEvmChain;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StdSignDoc } from "@cosmjs/amino/build";
|
|
2
|
+
import { TypedDataDomain, TypedDataField } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { TypeUtils } from ".";
|
|
4
|
+
export interface EIP712Tx {
|
|
5
|
+
readonly types: TypeUtils.SimpleMap<Array<TypedDataField>>;
|
|
6
|
+
readonly primaryType: string;
|
|
7
|
+
readonly domain: TypedDataDomain;
|
|
8
|
+
readonly message: StdSignDoc;
|
|
9
|
+
}
|
|
10
|
+
export declare function constructEIP712Tx(doc: StdSignDoc): EIP712Tx;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.constructEIP712Tx = void 0;
|
|
7
|
+
const eip712_1 = require("../constant/eip712");
|
|
8
|
+
const ethermint_1 = require("../util/ethermint");
|
|
9
|
+
const codec_1 = require("../codec");
|
|
10
|
+
const AminoTypesMap_1 = __importDefault(require("../provider/amino/AminoTypesMap"));
|
|
11
|
+
function getTypes(msgTypeUrl, aminoMsgValue) {
|
|
12
|
+
return Object.assign(Object.assign({}, eip712_1.DEFAULT_EIP712_TYPES), getMsgValueType(msgTypeUrl, aminoMsgValue, "MsgValue"));
|
|
13
|
+
}
|
|
14
|
+
function getMsgValueType(msgTypeUrl, aminoMsgValue, msgTypeName, msgTypeDefinitions = {}) {
|
|
15
|
+
const packageName = msgTypeUrl.split(".").splice(-1).join();
|
|
16
|
+
const msgFieldType = msgTypeUrl.split(".").pop();
|
|
17
|
+
const fieldsDefinition = codec_1.EIP712Types[packageName][msgFieldType];
|
|
18
|
+
const nonZeroFieldsDefinition = [];
|
|
19
|
+
fieldsDefinition.forEach(({ packageName, name, type }) => {
|
|
20
|
+
const fieldValue = aminoMsgValue[name];
|
|
21
|
+
if (fieldValue && fieldValue.length) {
|
|
22
|
+
nonZeroFieldsDefinition.push({ name, type });
|
|
23
|
+
msgTypeDefinitions[msgTypeName] = Object.assign(Object.assign({}, msgTypeDefinitions[msgTypeName]), nonZeroFieldsDefinition);
|
|
24
|
+
if (packageName) {
|
|
25
|
+
const typeUrl = `${packageName}.${type}`;
|
|
26
|
+
const nestedAminoMsgValue = isMessage(typeUrl) ? aminoMsgValue[name]["value"] : aminoMsgValue[name];
|
|
27
|
+
getMsgValueType(typeUrl, nestedAminoMsgValue, type, msgTypeDefinitions);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return msgTypeDefinitions;
|
|
32
|
+
}
|
|
33
|
+
function isMessage(msgTypeUrl) {
|
|
34
|
+
return codec_1.registry.lookupType(msgTypeUrl) !== undefined;
|
|
35
|
+
}
|
|
36
|
+
function constructEIP712Tx(doc) {
|
|
37
|
+
// EIP-712 can only accept batch msgs of the same type
|
|
38
|
+
const msg = doc.msgs[0];
|
|
39
|
+
return {
|
|
40
|
+
types: getTypes(AminoTypesMap_1.default.fromAmino(msg).typeUrl, msg.value),
|
|
41
|
+
primaryType: "Tx",
|
|
42
|
+
domain: Object.assign(Object.assign({}, eip712_1.DEFAULT_CARBON_DOMAIN_FIELDS), { chainId: ethermint_1.parseChainId(doc.chain_id) }),
|
|
43
|
+
message: doc
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.constructEIP712Tx = constructEIP712Tx;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseChainId = exports.encodeAnyEthSecp256k1PubKey = exports.ETH_SECP256K1_TYPE = void 0;
|
|
4
|
+
const codec_1 = require("../codec");
|
|
5
|
+
const keys_1 = require("../codec/ethermint/crypto/v1/ethsecp256k1/keys");
|
|
6
|
+
exports.ETH_SECP256K1_TYPE = '/ethermint.crypto.v1.ethsecp256k1.PubKey';
|
|
7
|
+
function encodeAnyEthSecp256k1PubKey(pubkey) {
|
|
8
|
+
return codec_1.registry.encodeAsAny({
|
|
9
|
+
typeUrl: exports.ETH_SECP256K1_TYPE,
|
|
10
|
+
value: keys_1.PubKey.fromPartial({
|
|
11
|
+
key: pubkey,
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.encodeAnyEthSecp256k1PubKey = encodeAnyEthSecp256k1PubKey;
|
|
16
|
+
function parseChainId(evmChainId) {
|
|
17
|
+
const chainId = evmChainId.trim();
|
|
18
|
+
if (chainId.length > 48) {
|
|
19
|
+
throw new Error(`chain-id '${chainId}' cannot exceed 48 chars`);
|
|
20
|
+
}
|
|
21
|
+
if (!chainId.match(/^[0-9a-f]+$/i)) {
|
|
22
|
+
throw new Error(`chain-id '${chainId}' does not conform to the required format`);
|
|
23
|
+
}
|
|
24
|
+
return chainId.split("_")[1].split("-")[0];
|
|
25
|
+
}
|
|
26
|
+
exports.parseChainId = parseChainId;
|
package/lib/util/fetch.js
CHANGED
package/lib/util/generic.js
CHANGED
|
@@ -22,7 +22,7 @@ const overrideConfig = (defaults, override) => {
|
|
|
22
22
|
continue;
|
|
23
23
|
if (typeof member === "object") {
|
|
24
24
|
// @ts-ignore
|
|
25
|
-
result[key] =
|
|
25
|
+
result[key] = exports.overrideConfig(result[key], member);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
// @ts-ignore
|
|
@@ -41,7 +41,7 @@ const sortObject = (input) => {
|
|
|
41
41
|
Object.keys(input)
|
|
42
42
|
.sort()
|
|
43
43
|
// @ts-ignore noImplicitAny
|
|
44
|
-
.forEach((key) => (output[key] =
|
|
44
|
+
.forEach((key) => (output[key] = exports.sortObject(input[key])));
|
|
45
45
|
return output;
|
|
46
46
|
};
|
|
47
47
|
exports.sortObject = sortObject;
|
|
@@ -56,7 +56,7 @@ exports.appendHexPrefix = appendHexPrefix;
|
|
|
56
56
|
const computeTxHash = (bytes) => {
|
|
57
57
|
if (!bytes)
|
|
58
58
|
return bytes;
|
|
59
|
-
return
|
|
59
|
+
return exports.toTxHash(crypto_1.sha256(bytes));
|
|
60
60
|
};
|
|
61
61
|
exports.computeTxHash = computeTxHash;
|
|
62
62
|
const toTxHash = (bytes) => {
|
package/lib/util/ibc.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { ChainInfoExplorerTmRpc, ChainIds, GasPriceStep, AssetListObj } from "../constant";
|
|
2
2
|
import { AppCurrency } from "@keplr-wallet/types";
|
|
3
|
-
import { Blockchain } from "./blockchain";
|
|
3
|
+
import { Blockchain, BlockchainV2 } from "./blockchain";
|
|
4
4
|
import { SimpleMap } from "./type";
|
|
5
5
|
export declare function makeIBCMinimalDenom(sourceChannelId: string, coinMinimalDenom: string): string;
|
|
6
6
|
export declare const EmbedChainInfos: SimpleMap<ChainInfoExplorerTmRpc>;
|
|
7
7
|
export declare const totalAssetObj: AssetListObj;
|
|
8
|
+
export declare const ChainIdBlockchainMapV2: SimpleMap<BlockchainV2>;
|
|
8
9
|
export declare const ChainIdBlockchainMap: SimpleMap<Blockchain>;
|
|
9
|
-
export declare const getIbcChainFromBlockchain: (blockchain:
|
|
10
|
-
export declare const BlockchainMap: SimpleMap<
|
|
10
|
+
export declare const getIbcChainFromBlockchain: (blockchain: BlockchainV2 | undefined) => ChainIds | undefined;
|
|
11
|
+
export declare const BlockchainMap: SimpleMap<string | undefined>;
|
|
11
12
|
export interface ChainIdOutput {
|
|
12
13
|
identifier: string;
|
|
13
14
|
version: number;
|
|
14
15
|
}
|
|
15
16
|
export declare const parseChainId: (chainId: string) => ChainIdOutput;
|
|
16
17
|
export declare const calculateMaxFee: (gasStep?: GasPriceStep, gas?: number) => number;
|
|
18
|
+
export declare const estimateFeeStep: (gasStep?: GasPriceStep, gas?: number, stepId?: keyof GasPriceStep) => number;
|
|
17
19
|
export declare const isCw20Token: (currency: AppCurrency) => boolean;
|
package/lib/util/ibc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCw20Token = exports.calculateMaxFee = exports.parseChainId = exports.BlockchainMap = exports.getIbcChainFromBlockchain = exports.ChainIdBlockchainMap = exports.totalAssetObj = exports.EmbedChainInfos = exports.makeIBCMinimalDenom = void 0;
|
|
3
|
+
exports.isCw20Token = exports.estimateFeeStep = exports.calculateMaxFee = exports.parseChainId = exports.BlockchainMap = exports.getIbcChainFromBlockchain = exports.ChainIdBlockchainMap = exports.ChainIdBlockchainMapV2 = exports.totalAssetObj = exports.EmbedChainInfos = exports.makeIBCMinimalDenom = void 0;
|
|
4
4
|
const constant_1 = require("../constant");
|
|
5
5
|
const provider_1 = require("../provider");
|
|
6
6
|
const crypto_1 = require("@keplr-wallet/crypto");
|
|
@@ -46,6 +46,25 @@ exports.totalAssetObj = Object.values(exports.EmbedChainInfos).reduce((prev, cha
|
|
|
46
46
|
newAssetObj[chainInfo.chainId] = assetsObj;
|
|
47
47
|
return newAssetObj;
|
|
48
48
|
}, {});
|
|
49
|
+
exports.ChainIdBlockchainMapV2 = {
|
|
50
|
+
[constant_1.ChainIds.Osmosis]: "Osmosis",
|
|
51
|
+
[constant_1.ChainIds.Terra]: "Terra",
|
|
52
|
+
[constant_1.ChainIds.CosmosHub]: "Cosmos Hub",
|
|
53
|
+
[constant_1.ChainIds.Juno]: "Juno",
|
|
54
|
+
[constant_1.ChainIds.Evmos]: "Evmos",
|
|
55
|
+
[constant_1.ChainIds.Axelar]: "Axelar",
|
|
56
|
+
[constant_1.ChainIds.Stride]: "Stride",
|
|
57
|
+
[constant_1.ChainIds.Kujira]: "Kujira",
|
|
58
|
+
[constant_1.ChainIds.Terra2]: "Terra (CW20)",
|
|
59
|
+
[constant_1.ChainIds.Quicksilver]: "Quicksilver",
|
|
60
|
+
[constant_1.ChainIds.Comdex]: "Comdex",
|
|
61
|
+
[constant_1.ChainIds.StafiHub]: "Stafihub",
|
|
62
|
+
[constant_1.ChainIds.Persistence]: "Persistence Core",
|
|
63
|
+
[constant_1.ChainIds.Stargaze]: "Stargaze",
|
|
64
|
+
[constant_1.ChainIds.Canto]: "Canto",
|
|
65
|
+
[constant_1.ChainIds.OmniFlixHub]: "Omniflix Hub",
|
|
66
|
+
[constant_1.ChainIds.Agoric]: "Agoric",
|
|
67
|
+
};
|
|
49
68
|
exports.ChainIdBlockchainMap = {
|
|
50
69
|
[constant_1.ChainIds.Osmosis]: blockchain_1.Blockchain.Osmosis,
|
|
51
70
|
[constant_1.ChainIds.Terra]: blockchain_1.Blockchain.Terra,
|
|
@@ -115,6 +134,12 @@ const calculateMaxFee = (gasStep = constant_1.DefaultGasPriceStep, gas = 0) => {
|
|
|
115
134
|
return gasStep.high * gas;
|
|
116
135
|
};
|
|
117
136
|
exports.calculateMaxFee = calculateMaxFee;
|
|
137
|
+
const estimateFeeStep = (gasStep = constant_1.DefaultGasPriceStep, gas = 0, stepId = 'average') => {
|
|
138
|
+
var _a;
|
|
139
|
+
const currentGasStep = (_a = gasStep[stepId]) !== null && _a !== void 0 ? _a : 0;
|
|
140
|
+
return currentGasStep * gas;
|
|
141
|
+
};
|
|
142
|
+
exports.estimateFeeStep = estimateFeeStep;
|
|
118
143
|
const isCw20Token = (currency) => {
|
|
119
144
|
if (!currency.hasOwnProperty("type"))
|
|
120
145
|
return false;
|
package/lib/util/number.js
CHANGED
|
@@ -18,26 +18,26 @@ const parseBN = (input, defaultValue) => {
|
|
|
18
18
|
};
|
|
19
19
|
exports.parseBN = parseBN;
|
|
20
20
|
const bnOrZero = (input, defaultValue = exports.BN_ZERO) => {
|
|
21
|
-
return
|
|
21
|
+
return exports.parseBN(input, defaultValue);
|
|
22
22
|
};
|
|
23
23
|
exports.bnOrZero = bnOrZero;
|
|
24
24
|
const toHuman = (value, decimals) => {
|
|
25
25
|
if (value === undefined || value === null)
|
|
26
26
|
return undefined;
|
|
27
|
-
const valueBN =
|
|
27
|
+
const valueBN = exports.bnOrZero(value);
|
|
28
28
|
if (!decimals)
|
|
29
29
|
return valueBN; // decimals = 0 or nullish
|
|
30
|
-
const decimalsBN =
|
|
30
|
+
const decimalsBN = exports.bnOrZero(decimals);
|
|
31
31
|
return valueBN.shiftedBy(decimalsBN.negated().toNumber());
|
|
32
32
|
};
|
|
33
33
|
exports.toHuman = toHuman;
|
|
34
34
|
const toUnitless = (value, decimals) => {
|
|
35
35
|
if (value === undefined || value === null)
|
|
36
36
|
return undefined;
|
|
37
|
-
const valueBN =
|
|
37
|
+
const valueBN = exports.bnOrZero(value);
|
|
38
38
|
if (!decimals)
|
|
39
39
|
return valueBN; // decimals = 0 or nullish
|
|
40
|
-
const decimalsBN =
|
|
40
|
+
const decimalsBN = exports.bnOrZero(decimals);
|
|
41
41
|
return valueBN.shiftedBy(decimalsBN.toNumber());
|
|
42
42
|
};
|
|
43
43
|
exports.toUnitless = toUnitless;
|
|
@@ -106,9 +106,9 @@ class CarbonLedgerSigner {
|
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
const account = yield this.retrieveAccount();
|
|
108
108
|
const { pubkey } = account;
|
|
109
|
-
const msg = JSON.stringify(
|
|
109
|
+
const msg = JSON.stringify(generic_1.sortObject(doc));
|
|
110
110
|
const signBytes = yield this.ledger.sign(msg);
|
|
111
|
-
const signature =
|
|
111
|
+
const signature = amino_1.encodeSecp256k1Signature(pubkey, signBytes);
|
|
112
112
|
return {
|
|
113
113
|
signed: doc,
|
|
114
114
|
signature,
|
|
@@ -87,7 +87,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
87
87
|
*/
|
|
88
88
|
sign(signerAddress, messages, fee, memo, signerData) {
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
return
|
|
90
|
+
return proto_signing_1.isOfflineDirectSigner(this.signer)
|
|
91
91
|
? this.signDirect(signerAddress, messages, fee, memo, signerData)
|
|
92
92
|
: this.signAmino(signerAddress, messages, fee, memo, signerData);
|
|
93
93
|
});
|
|
@@ -99,7 +99,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
99
99
|
if (!accountFromSigner) {
|
|
100
100
|
throw new Error("Failed to retrieve account from signer");
|
|
101
101
|
}
|
|
102
|
-
const pubkey =
|
|
102
|
+
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
103
103
|
const txBodyEncodeObject = {
|
|
104
104
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
105
105
|
value: Object.assign({ messages: messages, memo: memo }, (timeoutHeight && {
|
|
@@ -108,13 +108,13 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
108
108
|
};
|
|
109
109
|
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
110
110
|
const gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
111
|
-
const authInfoBytes =
|
|
112
|
-
const signDoc =
|
|
111
|
+
const authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit);
|
|
112
|
+
const signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
113
113
|
const { signature, signed } = yield signer.signDirect(signerAddress, signDoc);
|
|
114
114
|
return tx_1.TxRaw.fromPartial({
|
|
115
115
|
bodyBytes: signed.bodyBytes,
|
|
116
116
|
authInfoBytes: signed.authInfoBytes,
|
|
117
|
-
signatures: [
|
|
117
|
+
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -125,7 +125,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
125
125
|
if (!accountFromSigner) {
|
|
126
126
|
throw new Error("Failed to retrieve account from signer");
|
|
127
127
|
}
|
|
128
|
-
const pubkey =
|
|
128
|
+
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
129
129
|
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
130
130
|
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
|
|
131
131
|
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight !== null && timeoutHeight !== void 0 ? timeoutHeight : 0);
|
|
@@ -140,11 +140,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
140
140
|
const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
|
|
141
141
|
const signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
|
|
142
142
|
const signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
|
|
143
|
-
const signedAuthInfoBytes =
|
|
143
|
+
const signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
|
|
144
144
|
return tx_1.TxRaw.fromPartial({
|
|
145
145
|
bodyBytes: signedTxBodyBytes,
|
|
146
146
|
authInfoBytes: signedAuthInfoBytes,
|
|
147
|
-
signatures: [
|
|
147
|
+
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
}
|
|
@@ -150,7 +150,7 @@ class CarbonWallet {
|
|
|
150
150
|
const signerData = Object.assign({ accountNumber: this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData);
|
|
151
151
|
const fee = (_a = opts === null || opts === void 0 ? void 0 : opts.fee) !== null && _a !== void 0 ? _a : this.estimateTxFee(messages, feeDenom);
|
|
152
152
|
const txRaw = yield signingClient.sign(signerAddress, messages, fee, memo, signerData);
|
|
153
|
-
signature =
|
|
153
|
+
signature = amino_1.encodeSecp256k1Signature(account.pubkey, txRaw.signatures[0]);
|
|
154
154
|
return txRaw;
|
|
155
155
|
}
|
|
156
156
|
finally {
|
|
@@ -168,7 +168,7 @@ class CarbonWallet {
|
|
|
168
168
|
const tx = CarbonWallet.TxRaw.encode(txRaw).finish();
|
|
169
169
|
const carbonClient = this.getSigningClient();
|
|
170
170
|
const response = yield carbonClient.broadcastTx(tx, timeoutMs, pollIntervalMs);
|
|
171
|
-
if (
|
|
171
|
+
if (stargate_1.isDeliverTxFailure(response)) {
|
|
172
172
|
// tx failed
|
|
173
173
|
throw new tx_1.CarbonTxError(`[${response.code}] ${response.rawLog}`, response);
|
|
174
174
|
}
|
|
@@ -207,9 +207,9 @@ class CarbonWallet {
|
|
|
207
207
|
try {
|
|
208
208
|
if (!this.accountInfo || this.sequenceInvalidated)
|
|
209
209
|
yield this.reloadAccountSequence();
|
|
210
|
-
const heightResponse = yield
|
|
210
|
+
const heightResponse = yield fetch_1.fetch(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
|
|
211
211
|
const heightRes = yield heightResponse.json();
|
|
212
|
-
const height =
|
|
212
|
+
const height = number_1.bnOrZero((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
|
|
213
213
|
const timeoutHeight = height.isZero() ? undefined : height.toNumber() + this.defaultTimeoutBlocks;
|
|
214
214
|
const sequence = this.accountInfo.sequence;
|
|
215
215
|
this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
|
|
@@ -343,12 +343,12 @@ class CarbonWallet {
|
|
|
343
343
|
const queryClient = this.getQueryClient();
|
|
344
344
|
const { msgGasCosts } = yield queryClient.fee.MsgGasCostAll({});
|
|
345
345
|
this.txGasCosts = msgGasCosts.reduce((result, item) => {
|
|
346
|
-
result[item.msgType] =
|
|
346
|
+
result[item.msgType] = number_1.bnOrZero(item.gasCost);
|
|
347
347
|
return result;
|
|
348
348
|
}, {});
|
|
349
349
|
const { minGasPrices } = yield queryClient.fee.MinGasPriceAll({});
|
|
350
350
|
this.txGasPrices = minGasPrices.reduce((result, item) => {
|
|
351
|
-
result[item.denom] =
|
|
351
|
+
result[item.denom] = number_1.bnOrZero(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
|
|
352
352
|
return result;
|
|
353
353
|
}, {});
|
|
354
354
|
if (!this.txGasPrices[this.defaultFeeDenom]) {
|
|
@@ -171,7 +171,7 @@ class WSConnector {
|
|
|
171
171
|
params = [params]; // eslint-disable-line no-param-reassign
|
|
172
172
|
}
|
|
173
173
|
for (const param of params) {
|
|
174
|
-
const channelId =
|
|
174
|
+
const channelId = channel_1.generateChannelId(param);
|
|
175
175
|
const shouldSubscribe = this.channelHandlers[channelId] === undefined;
|
|
176
176
|
this.channelHandlers[channelId] = handler;
|
|
177
177
|
if (shouldSubscribe) {
|
|
@@ -193,7 +193,7 @@ class WSConnector {
|
|
|
193
193
|
}
|
|
194
194
|
const channelIds = [];
|
|
195
195
|
for (const param of params) {
|
|
196
|
-
const channelId =
|
|
196
|
+
const channelId = channel_1.generateChannelId(param);
|
|
197
197
|
const shouldUnsubscribe = this.channelHandlers[channelId] !== undefined;
|
|
198
198
|
delete this.channelHandlers[channelId];
|
|
199
199
|
if (shouldUnsubscribe) {
|
|
@@ -281,7 +281,7 @@ class WSConnector {
|
|
|
281
281
|
if (!channelHandler) {
|
|
282
282
|
this.debugLog(`handler not found for channel: ${message.channel}`);
|
|
283
283
|
try {
|
|
284
|
-
const params =
|
|
284
|
+
const params = channel_1.parseChannelId(message.channel);
|
|
285
285
|
this.unsubscribe({ channel: params.channel });
|
|
286
286
|
}
|
|
287
287
|
catch (error) {
|