carbon-js-sdk 0.4.6 → 0.4.7
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/ETHClient.d.ts +11 -4
- package/lib/clients/ETHClient.js +20 -6
- package/lib/clients/HydrogenClient.d.ts +16 -7
- package/lib/clients/HydrogenClient.js +55 -9
- package/lib/clients/NEOClient.d.ts +1 -1
- package/lib/clients/NEOClient.js +9 -4
- package/lib/clients/TokenClient.d.ts +29 -5
- package/lib/clients/TokenClient.js +257 -52
- package/lib/clients/ZILClient.d.ts +1 -1
- package/lib/clients/ZILClient.js +9 -4
- package/lib/codec/ethermint-models.d.ts +1 -1
- package/lib/codec/ethermint-models.js +2 -2
- package/lib/codec/index.d.ts +2 -2
- package/lib/codec/index.js +2 -2
- 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/modules/ibc.d.ts +5 -1
- package/lib/modules/ibc.js +78 -0
- package/lib/provider/keplr/KeplrStore.d.ts +1 -1
- package/lib/provider/keplr/KeplrStore.js +2 -5
- package/lib/provider/metamask/MetaMask.d.ts +5 -5
- package/lib/provider/metamask/MetaMask.js +37 -37
- package/lib/util/blockchain.d.ts +26 -0
- package/lib/util/blockchain.js +160 -1
- package/lib/util/ibc.d.ts +5 -3
- package/lib/util/ibc.js +26 -1
- package/lib/util/tx.d.ts +2 -2
- package/package.json +1 -1
|
@@ -12,12 +12,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const pagination_1 = require("../codec/cosmos/base/query/v1beta1/pagination");
|
|
16
|
+
const tendermint_1 = require("../codec/ibc/lightclients/tendermint/v1/tendermint");
|
|
15
17
|
const constant_1 = require("../constant");
|
|
16
18
|
const ibc_1 = require("../constant/ibc");
|
|
17
19
|
const network_1 = require("../constant/network");
|
|
18
|
-
const KeplrAccount_1 = __importDefault(require("../provider/keplr/KeplrAccount"));
|
|
19
20
|
const util_1 = require("../util");
|
|
21
|
+
const blockchain_1 = require("../util/blockchain");
|
|
20
22
|
const number_1 = require("../util/number");
|
|
23
|
+
const query_1 = require("../codec/ibc/applications/transfer/v1/query");
|
|
24
|
+
const stargate_1 = require("@cosmjs/stargate");
|
|
25
|
+
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
21
26
|
const long_1 = __importDefault(require("long"));
|
|
22
27
|
const InsightsQueryClient_1 = __importDefault(require("./InsightsQueryClient"));
|
|
23
28
|
const SYMBOL_OVERRIDE = {
|
|
@@ -43,11 +48,18 @@ class TokenClient {
|
|
|
43
48
|
this.wrapperMap = {};
|
|
44
49
|
this.poolTokens = {};
|
|
45
50
|
this.cdpTokens = {};
|
|
51
|
+
this.bridges = { polynetwork: [], ibc: [] };
|
|
46
52
|
this.symbols = {};
|
|
47
53
|
this.usdValues = {};
|
|
48
54
|
this.commonAssetNames = constant_1.CommonAssetName;
|
|
49
55
|
this.geckoTokenNames = constant_1.CoinGeckoTokenNames;
|
|
56
|
+
// ibc apis
|
|
57
|
+
this.denomTraces = {};
|
|
50
58
|
this.additionalGeckoDenoms = {};
|
|
59
|
+
this.getIbcChainFromBlockchainV2 = (blockchain) => {
|
|
60
|
+
const ibcBridge = this.bridges.ibc.find(bridge => (bridge.chainName === blockchain || bridge.chainName.toLowerCase() === blockchain));
|
|
61
|
+
return ibcBridge === null || ibcBridge === void 0 ? void 0 : ibcBridge.chain_id_name;
|
|
62
|
+
};
|
|
51
63
|
}
|
|
52
64
|
static instance(query, configProvider) {
|
|
53
65
|
return new TokenClient(query, configProvider);
|
|
@@ -58,6 +70,8 @@ class TokenClient {
|
|
|
58
70
|
yield this.reloadWrapperMap();
|
|
59
71
|
yield this.reloadTokens();
|
|
60
72
|
yield this.reloadDenomGeckoMap();
|
|
73
|
+
yield this.reloadDenomTraces();
|
|
74
|
+
yield this.getBridges();
|
|
61
75
|
// non-blocking reload
|
|
62
76
|
try {
|
|
63
77
|
this.reloadUSDValues();
|
|
@@ -80,10 +94,11 @@ class TokenClient {
|
|
|
80
94
|
return (_c = ((_b = (_a = this.tokens[denom]) !== null && _a !== void 0 ? _a : this.poolTokens[denom]) !== null && _b !== void 0 ? _b : this.cdpTokens[denom])) === null || _c === void 0 ? void 0 : _c.decimals.toNumber();
|
|
81
95
|
}
|
|
82
96
|
getBlockchain(denom) {
|
|
83
|
-
var _a, _b
|
|
97
|
+
var _a, _b;
|
|
84
98
|
const networkConfig = this.configProvider.getConfig();
|
|
99
|
+
const tokenData = this.tokens[denom];
|
|
85
100
|
// chainId defaults to 3 so that blockchain will be undefined
|
|
86
|
-
let chainId = (
|
|
101
|
+
let chainId = (_b = (_a = tokenData === null || tokenData === void 0 ? void 0 : tokenData.chainId) === null || _a === void 0 ? void 0 : _a.toNumber()) !== null && _b !== void 0 ? _b : 3;
|
|
87
102
|
if (this.isNativeToken(denom) || this.isNativeStablecoin(denom) || TokenClient.isPoolToken(denom) || TokenClient.isCdpToken(denom)) {
|
|
88
103
|
// native denoms "swth" and "usc" should be native.
|
|
89
104
|
// pool and cdp tokens are on the Native blockchain, hence 0
|
|
@@ -95,6 +110,18 @@ class TokenClient {
|
|
|
95
110
|
const blockchain = util_1.BlockchainUtils.blockchainForChainId(chainId, networkConfig.network);
|
|
96
111
|
return blockchain;
|
|
97
112
|
}
|
|
113
|
+
getBlockchainV2(denom) {
|
|
114
|
+
if (!denom)
|
|
115
|
+
return undefined;
|
|
116
|
+
let token = this.tokens[denom];
|
|
117
|
+
if (this.isNativeToken(denom) || this.isNativeStablecoin(denom) || TokenClient.isPoolToken(denom) || TokenClient.isCdpToken(denom) || this.isGroupedToken(denom)) {
|
|
118
|
+
// native denoms "swth" and "usc" should be native.
|
|
119
|
+
// pool and cdp tokens are on the Native blockchain, hence 0
|
|
120
|
+
return 'Native';
|
|
121
|
+
}
|
|
122
|
+
const bridge = this.getBridgeFromToken(token);
|
|
123
|
+
return bridge === null || bridge === void 0 ? void 0 : bridge.chainName;
|
|
124
|
+
}
|
|
98
125
|
getSymbol(denom) {
|
|
99
126
|
var _a, _b;
|
|
100
127
|
if (TokenClient.isCdpToken(denom)) {
|
|
@@ -237,7 +264,7 @@ class TokenClient {
|
|
|
237
264
|
}
|
|
238
265
|
return result;
|
|
239
266
|
}
|
|
240
|
-
getWrappedToken(denom, blockchain) {
|
|
267
|
+
getWrappedToken(denom, blockchain, version = 'V1') {
|
|
241
268
|
const networkConfig = this.configProvider.getConfig();
|
|
242
269
|
// if denom is already a wrapped denom or no blockchain was specified,
|
|
243
270
|
// just return the input denom.
|
|
@@ -253,9 +280,15 @@ class TokenClient {
|
|
|
253
280
|
}
|
|
254
281
|
// check if wrapped denom is of correct blockchain
|
|
255
282
|
const token = this.tokens[wrappedDenom];
|
|
256
|
-
let tokenChain =
|
|
257
|
-
if (
|
|
258
|
-
tokenChain = util_1.
|
|
283
|
+
let tokenChain = '';
|
|
284
|
+
if (version === "V1") {
|
|
285
|
+
tokenChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber());
|
|
286
|
+
if (TokenClient.isIBCDenom(token.denom)) {
|
|
287
|
+
tokenChain = util_1.IBCUtils.BlockchainMap[wrappedDenom];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
tokenChain = this.getBlockchainV2(token.denom);
|
|
259
292
|
}
|
|
260
293
|
if (!tokenChain) {
|
|
261
294
|
continue; // unknown chain! just ignore this source token
|
|
@@ -291,21 +324,34 @@ class TokenClient {
|
|
|
291
324
|
isNativeStablecoin(denom) {
|
|
292
325
|
return denom === "usc";
|
|
293
326
|
}
|
|
294
|
-
|
|
327
|
+
isGroupedToken(denom) {
|
|
328
|
+
const groupedTokenRegex = new RegExp(/^cgt\/\d+$/);
|
|
329
|
+
return groupedTokenRegex.test(denom);
|
|
330
|
+
}
|
|
331
|
+
isCarbonToken(token) {
|
|
332
|
+
return Boolean(token && (this.isNativeToken(token.denom) || token.bridgeId.eq(0)));
|
|
333
|
+
}
|
|
334
|
+
getDepositTokenFor(tokenDenom, chain, version = "V1") {
|
|
295
335
|
const networkConfig = this.configProvider.getConfig();
|
|
296
336
|
const token = this.tokenForDenom(tokenDenom);
|
|
297
337
|
if (!token) {
|
|
298
338
|
console.error("getDepositTokenFor token not found for", tokenDenom);
|
|
299
339
|
return;
|
|
300
340
|
}
|
|
341
|
+
let targetChain = "";
|
|
301
342
|
// check if selected token is a source token
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
343
|
+
if (version === "V1") {
|
|
344
|
+
targetChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
|
|
345
|
+
if (TokenClient.isIBCDenom(token.denom)) {
|
|
346
|
+
targetChain = util_1.IBCUtils.BlockchainMap[token.denom];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
targetChain = this.getBlockchainV2(token.denom);
|
|
305
351
|
}
|
|
306
352
|
const isSourceToken = targetChain === chain && token.denom !== "swth";
|
|
307
353
|
// if not source token find wrapped token for chain
|
|
308
|
-
const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain);
|
|
354
|
+
const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain, version);
|
|
309
355
|
if (!depositToken) {
|
|
310
356
|
console.error(`getDepositTokenFor wrapped token not found for "${token.denom}"`);
|
|
311
357
|
return;
|
|
@@ -349,52 +395,211 @@ class TokenClient {
|
|
|
349
395
|
this.symbols[token.denom] = token.symbol;
|
|
350
396
|
}
|
|
351
397
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
398
|
+
return this.tokens;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
reloadDenomTraces() {
|
|
402
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
const result = yield this.query.ibc.transfer.DenomTraces({
|
|
404
|
+
pagination: {
|
|
405
|
+
limit: new long_1.default(1000000),
|
|
406
|
+
offset: long_1.default.UZERO,
|
|
407
|
+
key: new Uint8Array(),
|
|
408
|
+
countTotal: false,
|
|
409
|
+
reverse: false,
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
result.denomTraces.forEach((denomTrace) => {
|
|
413
|
+
const ibcDenom = util_1.IBCUtils.makeIBCMinimalDenom(denomTrace.path, denomTrace.baseDenom);
|
|
414
|
+
const token = this.tokenForDenom(ibcDenom);
|
|
415
|
+
this.denomTraces[ibcDenom] = Object.assign(Object.assign({}, denomTrace), { token });
|
|
416
|
+
});
|
|
417
|
+
const swthTraces = yield this.getCarbonDenomTraces();
|
|
418
|
+
return Object.assign(Object.assign({}, this.denomTraces), swthTraces);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
getDenomTraceData(denom) {
|
|
422
|
+
return this.denomTraces[denom];
|
|
423
|
+
}
|
|
424
|
+
getBridges() {
|
|
425
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
+
const allBridges = yield this.query.coin.BridgeAll({
|
|
427
|
+
pagination: {
|
|
428
|
+
key: new Uint8Array(),
|
|
429
|
+
limit: new long_1.default(10000),
|
|
430
|
+
offset: long_1.default.UZERO,
|
|
431
|
+
countTotal: true,
|
|
432
|
+
reverse: false,
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
const unmatchedIbcBridgeList = allBridges.bridges.filter(bridge => {
|
|
436
|
+
if (!bridge.enabled)
|
|
437
|
+
return;
|
|
438
|
+
return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc;
|
|
439
|
+
});
|
|
440
|
+
const ibcBridges = yield this.matchChainsWithDifferentChainIds(unmatchedIbcBridgeList);
|
|
441
|
+
const polynetworkBridges = allBridges.bridges.reduce((prev, bridge) => {
|
|
442
|
+
if (!bridge.enabled || bridge.bridgeId.toNumber() !== blockchain_1.BRIDGE_IDS.polynetwork)
|
|
443
|
+
return prev;
|
|
444
|
+
prev.push(Object.assign(Object.assign({}, bridge), { isEvmChain: util_1.BlockchainUtils.isEvmChain(bridge.chainName) }));
|
|
445
|
+
return prev;
|
|
446
|
+
}, []);
|
|
447
|
+
Object.assign(this.bridges, {
|
|
448
|
+
polynetwork: polynetworkBridges,
|
|
449
|
+
ibc: ibcBridges
|
|
450
|
+
});
|
|
451
|
+
return this.bridges;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
matchChainsWithDifferentChainIds(bridges) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
let newBridges = [];
|
|
457
|
+
try {
|
|
458
|
+
const channels_to_connection = yield this.query.ibc.channel.Channels({
|
|
459
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
460
|
+
limit: new long_1.default(1000000)
|
|
461
|
+
})
|
|
462
|
+
});
|
|
463
|
+
const connection_to_clientId = yield this.query.ibc.connection.Connections({
|
|
464
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
465
|
+
limit: new long_1.default(1000000)
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
const clientId_to_chainIdName = yield this.query.ibc.client.ClientStates({
|
|
469
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
470
|
+
limit: new long_1.default(1000000)
|
|
471
|
+
})
|
|
472
|
+
});
|
|
473
|
+
const clientStates = clientId_to_chainIdName.clientStates.map(s => ({
|
|
474
|
+
clientState: Object.assign({}, tendermint_1.ClientState.decode(s.clientState.value)),
|
|
475
|
+
clientId: s.clientId,
|
|
476
|
+
}));
|
|
477
|
+
newBridges = bridges.map(bridge => {
|
|
478
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
479
|
+
const connection = channels_to_connection.channels.find(channel => channel.channelId === ("channel-" + (bridge.chainId.toNumber() - 1)));
|
|
480
|
+
const connectionId = connection === null || connection === void 0 ? void 0 : connection.connectionHops[0];
|
|
481
|
+
const src_channel = (_a = connection === null || connection === void 0 ? void 0 : connection.channelId) !== null && _a !== void 0 ? _a : "";
|
|
482
|
+
const dst_channel = (_c = (_b = connection === null || connection === void 0 ? void 0 : connection.counterparty) === null || _b === void 0 ? void 0 : _b.channelId) !== null && _c !== void 0 ? _c : "";
|
|
483
|
+
const cosmRegexArr = (_e = (_d = connection === null || connection === void 0 ? void 0 : connection.counterparty) === null || _d === void 0 ? void 0 : _d.portId) === null || _e === void 0 ? void 0 : _e.match(ibc_1.cosmBridgeRegex);
|
|
484
|
+
const portId = (_f = cosmRegexArr === null || cosmRegexArr === void 0 ? void 0 : cosmRegexArr[1]) !== null && _f !== void 0 ? _f : "transfer";
|
|
485
|
+
const clientId = (_g = connection_to_clientId.connections.find(connection => connection.id === connectionId)) === null || _g === void 0 ? void 0 : _g.clientId;
|
|
486
|
+
const chainIdName = (_j = ((_h = clientStates.find(client => client.clientId === clientId)) === null || _h === void 0 ? void 0 : _h.clientState)) === null || _j === void 0 ? void 0 : _j.chainId;
|
|
487
|
+
return Object.assign(Object.assign({}, bridge), { chain_id_name: chainIdName !== null && chainIdName !== void 0 ? chainIdName : "", channels: { src_channel, dst_channel, port_id: portId } });
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
finally {
|
|
491
|
+
const checkedBefore = new Array(newBridges.length).fill(false);
|
|
492
|
+
const chainMap = {};
|
|
493
|
+
for (let i = 0; i < newBridges.length; i++) {
|
|
494
|
+
if (checkedBefore[i])
|
|
495
|
+
continue;
|
|
496
|
+
const bridge = newBridges[i];
|
|
497
|
+
const chainId = bridge.chain_id_name;
|
|
498
|
+
if (chainMap[chainId]) {
|
|
499
|
+
const chainName = chainMap[chainId];
|
|
500
|
+
for (let j = i; j < newBridges.length; j++) {
|
|
501
|
+
const subBridge = newBridges[j];
|
|
502
|
+
if (subBridge.chain_id_name === chainId) {
|
|
503
|
+
subBridge.chainName = chainName;
|
|
504
|
+
checkedBefore[j] = true;
|
|
505
|
+
}
|
|
367
506
|
}
|
|
368
507
|
}
|
|
369
|
-
|
|
508
|
+
else {
|
|
509
|
+
chainMap[chainId] = bridge.chainName;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return newBridges;
|
|
370
513
|
}
|
|
371
|
-
return this.tokens;
|
|
372
514
|
});
|
|
373
515
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
516
|
+
getIbcBlockchainNames() {
|
|
517
|
+
return this.bridges.ibc.map(bridge => bridge.chainName);
|
|
518
|
+
}
|
|
519
|
+
getPolynetworkBlockchainNames() {
|
|
520
|
+
return this.bridges.polynetwork.map(bridge => bridge.chainName);
|
|
521
|
+
}
|
|
522
|
+
getAllBlockchainNames() {
|
|
523
|
+
return this.getIbcBlockchainNames().concat(this.getPolynetworkBlockchainNames());
|
|
524
|
+
}
|
|
525
|
+
getBridgesFromBridgeId(bridgeId) {
|
|
526
|
+
switch (bridgeId) {
|
|
527
|
+
case blockchain_1.BRIDGE_IDS.polynetwork:
|
|
528
|
+
return this.bridges.polynetwork;
|
|
529
|
+
case blockchain_1.BRIDGE_IDS.ibc:
|
|
530
|
+
return this.bridges.ibc;
|
|
531
|
+
default:
|
|
532
|
+
return this.bridges.polynetwork;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
getIbcTokens() {
|
|
536
|
+
const ibcTokens = Object.values(this.tokens).reduce((prev, token) => {
|
|
537
|
+
const newPrev = prev;
|
|
538
|
+
if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc) {
|
|
539
|
+
newPrev[token.denom] = token;
|
|
540
|
+
}
|
|
541
|
+
return newPrev;
|
|
542
|
+
}, {});
|
|
543
|
+
return ibcTokens;
|
|
544
|
+
}
|
|
545
|
+
getPolyNetworkTokens() {
|
|
546
|
+
const polynetworkTokens = Object.values(this.tokens).reduce((prev, token) => {
|
|
547
|
+
const newPrev = prev;
|
|
548
|
+
if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork) {
|
|
549
|
+
newPrev[token.denom] = token;
|
|
550
|
+
}
|
|
551
|
+
return newPrev;
|
|
552
|
+
}, {});
|
|
553
|
+
return polynetworkTokens;
|
|
554
|
+
}
|
|
555
|
+
getBlockchainV2FromIDs(chainId, bridgeId) {
|
|
556
|
+
var _a, _b;
|
|
557
|
+
const chainIdNum = Number(chainId);
|
|
558
|
+
const bridgeIdNum = Number(bridgeId);
|
|
559
|
+
if ((chainIdNum === 5 && bridgeIdNum === 1) || (chainIdNum === 0 && bridgeIdNum === 2))
|
|
560
|
+
return "Carbon";
|
|
561
|
+
const bridgeList = this.getBridgesFromBridgeId(bridgeIdNum);
|
|
562
|
+
return (_b = (_a = bridgeList.find(bridge => bridge.chainId.toNumber() === chainIdNum)) === null || _a === void 0 ? void 0 : _a.chainName) !== null && _b !== void 0 ? _b : undefined;
|
|
563
|
+
}
|
|
564
|
+
getBridgeFromToken(token) {
|
|
565
|
+
if (!token || !token.bridgeId)
|
|
566
|
+
return undefined;
|
|
567
|
+
const bridgeList = this.getBridgesFromBridgeId(token.bridgeId.toNumber());
|
|
568
|
+
return bridgeList.find(bridge => token.chainId.equals(bridge.chainId));
|
|
569
|
+
}
|
|
570
|
+
getIbcChainIdFromToken(token) {
|
|
571
|
+
if (!token)
|
|
572
|
+
return undefined;
|
|
573
|
+
const bridge = this.getBridgeFromToken(token);
|
|
574
|
+
if (!bridge || !blockchain_1.isIbcBridge(bridge))
|
|
575
|
+
return undefined;
|
|
576
|
+
return bridge.chain_id_name;
|
|
577
|
+
}
|
|
578
|
+
getCarbonDenomTraces() {
|
|
579
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
580
|
+
// get swth on osmosis
|
|
581
|
+
const osmoTmClient = yield tendermint_rpc_1.Tendermint34Client.connect(network_1.publicRpcNodes.Osmosis);
|
|
582
|
+
const osmoClient = new stargate_1.QueryClient(osmoTmClient);
|
|
583
|
+
const osmosRpcClient = stargate_1.createProtobufRpcClient(osmoClient);
|
|
584
|
+
const osmoIbcClient = new query_1.QueryClientImpl(osmosRpcClient);
|
|
585
|
+
const osmoDenomTraces = yield osmoIbcClient.DenomTraces({
|
|
586
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
587
|
+
limit: new long_1.default(1000000),
|
|
588
|
+
}),
|
|
589
|
+
});
|
|
590
|
+
const osmoSwthDenomTrace = osmoDenomTraces.denomTraces.filter((trace) => {
|
|
591
|
+
return trace.baseDenom === "swth";
|
|
592
|
+
});
|
|
593
|
+
return osmoSwthDenomTrace.reduce((prev, trace) => {
|
|
594
|
+
var _a;
|
|
595
|
+
const coinMinimalDenom = util_1.IBCUtils.makeIBCMinimalDenom(trace.path, trace.baseDenom);
|
|
596
|
+
const token = (_a = this.tokenForDenom(coinMinimalDenom)) !== null && _a !== void 0 ? _a : this.tokenForDenom(trace.baseDenom);
|
|
597
|
+
const traceExtended = Object.assign(Object.assign({}, trace), { token });
|
|
598
|
+
this.denomTraces[coinMinimalDenom] = traceExtended;
|
|
599
|
+
prev[coinMinimalDenom] = traceExtended;
|
|
600
|
+
return prev;
|
|
601
|
+
}, {});
|
|
396
602
|
});
|
|
397
|
-
return swthTokens;
|
|
398
603
|
}
|
|
399
604
|
getCdpUnderlyingToken(cdpDenom) {
|
|
400
605
|
if (!this.cdpTokens[cdpDenom]) {
|
|
@@ -77,7 +77,7 @@ export declare class ZILClient {
|
|
|
77
77
|
private walletProvider?;
|
|
78
78
|
private constructor();
|
|
79
79
|
static instance(opts: ZILClientOpts): CarbonSDK.ZILClient;
|
|
80
|
-
getExternalBalances(sdk: CarbonSDK, address: string, whitelistDenoms?: string[]): Promise<TokensWithExternalBalance[]>;
|
|
80
|
+
getExternalBalances(sdk: CarbonSDK, address: string, whitelistDenoms?: string[], version?: string): Promise<TokensWithExternalBalance[]>;
|
|
81
81
|
formatWithdrawalAddress(bech32Address: string): Promise<string>;
|
|
82
82
|
private callContract;
|
|
83
83
|
approveZRC2(params: ApproveZRC2Params): Promise<Transaction>;
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -69,12 +69,17 @@ class ZILClient {
|
|
|
69
69
|
}
|
|
70
70
|
return new ZILClient(configProvider, blockchain);
|
|
71
71
|
}
|
|
72
|
-
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
72
|
+
getExternalBalances(sdk, address, whitelistDenoms, version = "V1") {
|
|
73
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
74
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
75
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const tokens = tokenQueryResults.filter((token) => {
|
|
76
|
+
const isCorrectBlockchain = version === "V2"
|
|
77
|
+
?
|
|
78
|
+
!!sdk.token.getBlockchainV2(token.denom) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[sdk.token.getBlockchainV2(token.denom)] == this.blockchain)
|
|
79
|
+
:
|
|
80
|
+
blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
|
|
81
|
+
return isCorrectBlockchain && token.tokenAddress.length == 40 && (!whitelistDenoms || whitelistDenoms.includes(token.denom));
|
|
82
|
+
});
|
|
78
83
|
const requests = tokens.map((token) => token.tokenAddress === zeroAddress
|
|
79
84
|
? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
|
|
80
85
|
: exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * as Crypto from "./ethermint/crypto/v1/ethsecp256k1/export";
|
|
2
2
|
export * as Evm from "./ethermint/evm/v1/export";
|
|
3
|
-
export * as
|
|
3
|
+
export * as Feemarket from "./ethermint/feemarket/v1/export";
|
|
4
4
|
export * as Types from "./ethermint/types/v1/export";
|
|
@@ -19,8 +19,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.Types = exports.
|
|
22
|
+
exports.Types = exports.Feemarket = exports.Evm = exports.Crypto = void 0;
|
|
23
23
|
exports.Crypto = __importStar(require("./ethermint/crypto/v1/ethsecp256k1/export"));
|
|
24
24
|
exports.Evm = __importStar(require("./ethermint/evm/v1/export"));
|
|
25
|
-
exports.
|
|
25
|
+
exports.Feemarket = __importStar(require("./ethermint/feemarket/v1/export"));
|
|
26
26
|
exports.Types = __importStar(require("./ethermint/types/v1/export"));
|
package/lib/codec/index.d.ts
CHANGED
|
@@ -141,8 +141,8 @@ export declare const TxTypes: {
|
|
|
141
141
|
MsgRevokeAllowanceResponse: string;
|
|
142
142
|
MsgSubmitEvidence: string;
|
|
143
143
|
MsgSubmitEvidenceResponse: string;
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
MsgNftSend: string;
|
|
145
|
+
MsgNftSendResponse: string;
|
|
146
146
|
MsgCreateGroup: string;
|
|
147
147
|
MsgCreateGroupResponse: string;
|
|
148
148
|
MsgUpdateGroupMembers: string;
|
package/lib/codec/index.js
CHANGED
|
@@ -648,8 +648,8 @@ exports.TxTypes = {
|
|
|
648
648
|
"MsgRevokeAllowanceResponse": "/cosmos.feegrant.v1beta1.MsgRevokeAllowanceResponse",
|
|
649
649
|
"MsgSubmitEvidence": "/cosmos.evidence.v1beta1.MsgSubmitEvidence",
|
|
650
650
|
"MsgSubmitEvidenceResponse": "/cosmos.evidence.v1beta1.MsgSubmitEvidenceResponse",
|
|
651
|
-
"
|
|
652
|
-
"
|
|
651
|
+
"MsgNftSend": "/cosmos.nft.v1beta1.MsgSend",
|
|
652
|
+
"MsgNftSendResponse": "/cosmos.nft.v1beta1.MsgSendResponse",
|
|
653
653
|
"MsgCreateGroup": "/cosmos.group.v1.MsgCreateGroup",
|
|
654
654
|
"MsgCreateGroupResponse": "/cosmos.group.v1.MsgCreateGroupResponse",
|
|
655
655
|
"MsgUpdateGroupMembers": "/cosmos.group.v1.MsgUpdateGroupMembers",
|
package/lib/constant/ibc.d.ts
CHANGED
|
@@ -78,6 +78,13 @@ export interface CosmWasmChannelSet extends ChannelSet {
|
|
|
78
78
|
export declare const swthChannels: SimpleMap<ChannelConfig>;
|
|
79
79
|
export declare const cibtIbcTokenRegex: RegExp;
|
|
80
80
|
export declare const ibcTokenRegex: RegExp;
|
|
81
|
+
export declare const cw20TokenRegex: RegExp;
|
|
82
|
+
export declare const cosmBridgeRegex: RegExp;
|
|
81
83
|
export declare const ibcNetworkRegex: RegExp;
|
|
84
|
+
export declare const ibcTransferChannelRegex: RegExp;
|
|
82
85
|
export declare const ibcDefaultGas: number;
|
|
83
86
|
export declare const DefaultGasPriceStep: GasPriceStep;
|
|
87
|
+
export declare type MinimalDenomMap = SimpleMap<string>;
|
|
88
|
+
export interface ExtendedChainInfo extends ChainInfo {
|
|
89
|
+
minimalDenomMap: MinimalDenomMap;
|
|
90
|
+
}
|
package/lib/constant/ibc.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.DefaultGasPriceStep = exports.ibcDefaultGas = exports.ibcNetworkRegex = exports.ibcTokenRegex = exports.cibtIbcTokenRegex = exports.swthChannels = exports.EmbedChainInfosInit = exports.ibcWhitelist = exports.swthIbcWhitelist = exports.ChainIds = exports.IBCAddress = void 0;
|
|
22
|
+
exports.DefaultGasPriceStep = exports.ibcDefaultGas = exports.ibcTransferChannelRegex = exports.ibcNetworkRegex = exports.cosmBridgeRegex = exports.cw20TokenRegex = exports.ibcTokenRegex = exports.cibtIbcTokenRegex = exports.swthChannels = exports.EmbedChainInfosInit = exports.ibcWhitelist = exports.swthIbcWhitelist = exports.ChainIds = exports.IBCAddress = void 0;
|
|
23
23
|
const bech32 = __importStar(require("bech32"));
|
|
24
24
|
const generic_1 = require("./generic");
|
|
25
25
|
const token_1 = require("./token");
|
|
@@ -2116,7 +2116,10 @@ exports.swthChannels = {
|
|
|
2116
2116
|
};
|
|
2117
2117
|
exports.cibtIbcTokenRegex = RegExp(`^${token_1.DenomPrefix.CDPToken}/ibc/([a-f\\d]+)$`, "i");
|
|
2118
2118
|
exports.ibcTokenRegex = /^ibc\/([a-f\d]+)$/i;
|
|
2119
|
+
exports.cw20TokenRegex = /^cw20:([a-z\d]+)$/i;
|
|
2120
|
+
exports.cosmBridgeRegex = /^wasm\.([a-z\d]+)$/i;
|
|
2119
2121
|
exports.ibcNetworkRegex = /^([a-z\d_-]+)-([\d]+)$/i;
|
|
2122
|
+
exports.ibcTransferChannelRegex = /^transfer\/channel-(\d+)/i;
|
|
2120
2123
|
exports.ibcDefaultGas = 300000;
|
|
2121
2124
|
exports.DefaultGasPriceStep = {
|
|
2122
2125
|
low: 0.01,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SimpleMap } from "../util/type";
|
|
1
2
|
export declare enum Network {
|
|
2
3
|
MainNet = "mainnet",
|
|
3
4
|
TestNet = "testnet",
|
|
@@ -64,3 +65,4 @@ export interface NetworkConfigProvider {
|
|
|
64
65
|
export declare const NetworkConfigs: {
|
|
65
66
|
[key in Network]: NetworkConfig;
|
|
66
67
|
};
|
|
68
|
+
export declare const publicRpcNodes: SimpleMap<string>;
|
package/lib/constant/network.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkConfigs = exports.DEFAULT_NETWORK = exports.CarbonChainIDs = exports.Network = void 0;
|
|
3
|
+
exports.publicRpcNodes = exports.NetworkConfigs = exports.DEFAULT_NETWORK = exports.CarbonChainIDs = exports.Network = void 0;
|
|
4
4
|
const neon_core_next_1 = require("@cityofzion/neon-core-next");
|
|
5
5
|
var Network;
|
|
6
6
|
(function (Network) {
|
|
@@ -318,3 +318,7 @@ exports.NetworkConfigs = {
|
|
|
318
318
|
},
|
|
319
319
|
},
|
|
320
320
|
};
|
|
321
|
+
exports.publicRpcNodes = {
|
|
322
|
+
Osmosis: "https://rpc.osmosis.zone/",
|
|
323
|
+
Terra: "https://terra-rpc.lavenderfive.com:443/",
|
|
324
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Blockchain } from "../util/blockchain";
|
|
1
|
+
import { Blockchain, BlockchainV2 } from "../util/blockchain";
|
|
2
2
|
export interface GetTransfersRequest {
|
|
3
3
|
bridging_blockchain?: string;
|
|
4
4
|
source_blockchain?: string;
|
|
@@ -53,9 +53,9 @@ export interface CrossChainTransfer {
|
|
|
53
53
|
nonce: string;
|
|
54
54
|
created_at: Date;
|
|
55
55
|
updated_at: Date;
|
|
56
|
-
source_blockchain: Blockchain | null;
|
|
57
|
-
bridging_blockchain: Blockchain | null;
|
|
58
|
-
destination_blockchain: Blockchain | null;
|
|
56
|
+
source_blockchain: Blockchain | BlockchainV2 | null;
|
|
57
|
+
bridging_blockchain: Blockchain | BlockchainV2 | null;
|
|
58
|
+
destination_blockchain: Blockchain | BlockchainV2 | null;
|
|
59
59
|
status: CrossChainFlowStatus;
|
|
60
60
|
carbon_token_id: string;
|
|
61
61
|
recovery_address_hash: string;
|
|
@@ -68,7 +68,7 @@ export interface CrossChainTransferDetailed extends CrossChainTransfer {
|
|
|
68
68
|
}
|
|
69
69
|
export interface ChainTransaction {
|
|
70
70
|
id: string;
|
|
71
|
-
blockchain: Blockchain;
|
|
71
|
+
blockchain: Blockchain | BlockchainV2;
|
|
72
72
|
contract: string;
|
|
73
73
|
block_height: number;
|
|
74
74
|
tx_hash: string;
|
package/lib/modules/ibc.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtendedChainInfo } from "../constant";
|
|
2
|
+
import { ChainInfo } from "../provider";
|
|
3
|
+
import { CarbonTx, TypeUtils } from "../util";
|
|
2
4
|
import BigNumber from "bignumber.js";
|
|
3
5
|
import BaseModule from "./base";
|
|
4
6
|
export declare class IBCModule extends BaseModule {
|
|
5
7
|
/** @deprecated please use sendIbcTransferUpdated instead */
|
|
6
8
|
sendIBCTransfer(params: IBCModule.SendIBCTransferParams, msgOpts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
7
9
|
sendIbcTransferV2(params: IBCModule.SendIBCTransferV2Params, msgOpts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
10
|
+
getChainInfoMap(): Promise<TypeUtils.SimpleMap<ExtendedChainInfo>>;
|
|
11
|
+
getChainInfo(chainName: string, chainId: string): Promise<ChainInfo | undefined>;
|
|
8
12
|
}
|
|
9
13
|
export declare namespace IBCModule {
|
|
10
14
|
/** @deprecated sendIBCTransfer function is deprecated, please use sendIbcTransferUpdated instead */
|