carbon-js-sdk 0.4.1 → 0.4.3-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/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/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/crisis/genesis.d.ts +18 -0
- package/lib/codec/crisis/genesis.js +46 -0
- package/lib/codec/crisis/query.d.ts +43 -0
- package/lib/codec/crisis/query.js +103 -0
- package/lib/codec/crisis/tx.d.ts +12 -0
- package/lib/codec/crisis/tx.js +20 -0
- package/lib/codec/index.d.ts +4 -4
- package/lib/codec/index.js +4 -4
- 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/modules/cdp.js +43 -43
- package/lib/modules/cosmwasm.js +1 -1
- 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/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/ibc.d.ts +4 -3
- package/lib/util/ibc.js +20 -1
- package/lib/util/number.js +5 -5
- package/lib/util/tx.d.ts +4 -4
- 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.d.ts +2 -1
- package/lib/websocket/connector.js +7 -9
- package/package.json +1 -1
- package/lib/codec/broker/incoming_pool_swap.d.ts +0 -23
- package/lib/codec/broker/incoming_pool_swap.js +0 -136
- package/lib/codec/cosmos/base/store/v1beta1/snapshot.d.ts +0 -45
- package/lib/codec/cosmos/base/store/v1beta1/snapshot.js +0 -246
|
@@ -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)) {
|
|
@@ -229,7 +256,7 @@ class TokenClient {
|
|
|
229
256
|
}
|
|
230
257
|
return result;
|
|
231
258
|
}
|
|
232
|
-
getWrappedToken(denom, blockchain) {
|
|
259
|
+
getWrappedToken(denom, blockchain, version = 'V1') {
|
|
233
260
|
const networkConfig = this.configProvider.getConfig();
|
|
234
261
|
// if denom is already a wrapped denom or no blockchain was specified,
|
|
235
262
|
// just return the input denom.
|
|
@@ -245,9 +272,15 @@ class TokenClient {
|
|
|
245
272
|
}
|
|
246
273
|
// check if wrapped denom is of correct blockchain
|
|
247
274
|
const token = this.tokens[wrappedDenom];
|
|
248
|
-
let tokenChain =
|
|
249
|
-
if (
|
|
250
|
-
tokenChain = util_1.
|
|
275
|
+
let tokenChain = '';
|
|
276
|
+
if (version === "V1") {
|
|
277
|
+
tokenChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber());
|
|
278
|
+
if (TokenClient.isIBCDenom(token.denom)) {
|
|
279
|
+
tokenChain = util_1.IBCUtils.BlockchainMap[wrappedDenom];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
tokenChain = this.getBlockchainV2(token.denom);
|
|
251
284
|
}
|
|
252
285
|
if (!tokenChain) {
|
|
253
286
|
continue; // unknown chain! just ignore this source token
|
|
@@ -283,21 +316,34 @@ class TokenClient {
|
|
|
283
316
|
isNativeStablecoin(denom) {
|
|
284
317
|
return denom === "usc";
|
|
285
318
|
}
|
|
286
|
-
|
|
319
|
+
isGroupedToken(denom) {
|
|
320
|
+
const groupedTokenRegex = new RegExp(/^cgt\/\d+$/);
|
|
321
|
+
return groupedTokenRegex.test(denom);
|
|
322
|
+
}
|
|
323
|
+
isCarbonToken(token) {
|
|
324
|
+
return Boolean(token && (this.isNativeToken(token.denom) || token.bridgeId.eq(0)));
|
|
325
|
+
}
|
|
326
|
+
getDepositTokenFor(tokenDenom, chain, version = "V1") {
|
|
287
327
|
const networkConfig = this.configProvider.getConfig();
|
|
288
328
|
const token = this.tokenForDenom(tokenDenom);
|
|
289
329
|
if (!token) {
|
|
290
330
|
console.error("getDepositTokenFor token not found for", tokenDenom);
|
|
291
331
|
return;
|
|
292
332
|
}
|
|
333
|
+
let targetChain = "";
|
|
293
334
|
// check if selected token is a source token
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
335
|
+
if (version === "V1") {
|
|
336
|
+
targetChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
|
|
337
|
+
if (TokenClient.isIBCDenom(token.denom)) {
|
|
338
|
+
targetChain = util_1.IBCUtils.BlockchainMap[token.denom];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
targetChain = this.getBlockchainV2(token.denom);
|
|
297
343
|
}
|
|
298
344
|
const isSourceToken = targetChain === chain && token.denom !== "swth";
|
|
299
345
|
// if not source token find wrapped token for chain
|
|
300
|
-
const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain);
|
|
346
|
+
const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain, version);
|
|
301
347
|
if (!depositToken) {
|
|
302
348
|
console.error(`getDepositTokenFor wrapped token not found for "${token.denom}"`);
|
|
303
349
|
return;
|
|
@@ -341,52 +387,211 @@ class TokenClient {
|
|
|
341
387
|
this.symbols[token.denom] = token.symbol;
|
|
342
388
|
}
|
|
343
389
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
390
|
+
return this.tokens;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
reloadDenomTraces() {
|
|
394
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
const result = yield this.query.ibc.transfer.DenomTraces({
|
|
396
|
+
pagination: {
|
|
397
|
+
limit: new long_1.default(1000000),
|
|
398
|
+
offset: long_1.default.UZERO,
|
|
399
|
+
key: new Uint8Array(),
|
|
400
|
+
countTotal: false,
|
|
401
|
+
reverse: false,
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
result.denomTraces.forEach((denomTrace) => {
|
|
405
|
+
const ibcDenom = util_1.IBCUtils.makeIBCMinimalDenom(denomTrace.path, denomTrace.baseDenom);
|
|
406
|
+
const token = this.tokenForDenom(ibcDenom);
|
|
407
|
+
this.denomTraces[ibcDenom] = Object.assign(Object.assign({}, denomTrace), { token });
|
|
408
|
+
});
|
|
409
|
+
const swthTraces = yield this.getCarbonDenomTraces();
|
|
410
|
+
return Object.assign(Object.assign({}, this.denomTraces), swthTraces);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
getDenomTraceData(denom) {
|
|
414
|
+
return this.denomTraces[denom];
|
|
415
|
+
}
|
|
416
|
+
getBridges() {
|
|
417
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
const allBridges = yield this.query.coin.BridgeAll({
|
|
419
|
+
pagination: {
|
|
420
|
+
key: new Uint8Array(),
|
|
421
|
+
limit: new long_1.default(10000),
|
|
422
|
+
offset: long_1.default.UZERO,
|
|
423
|
+
countTotal: true,
|
|
424
|
+
reverse: false,
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
const unmatchedIbcBridgeList = allBridges.bridges.filter(bridge => {
|
|
428
|
+
if (!bridge.enabled)
|
|
429
|
+
return;
|
|
430
|
+
return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc;
|
|
431
|
+
});
|
|
432
|
+
const ibcBridges = yield this.matchChainsWithDifferentChainIds(unmatchedIbcBridgeList);
|
|
433
|
+
const polynetworkBridges = allBridges.bridges.reduce((prev, bridge) => {
|
|
434
|
+
if (!bridge.enabled || bridge.bridgeId.toNumber() !== blockchain_1.BRIDGE_IDS.polynetwork)
|
|
435
|
+
return prev;
|
|
436
|
+
prev.push(Object.assign(Object.assign({}, bridge), { isEvmChain: util_1.BlockchainUtils.isEvmChain(bridge.chainName) }));
|
|
437
|
+
return prev;
|
|
438
|
+
}, []);
|
|
439
|
+
Object.assign(this.bridges, {
|
|
440
|
+
polynetwork: polynetworkBridges,
|
|
441
|
+
ibc: ibcBridges
|
|
442
|
+
});
|
|
443
|
+
return this.bridges;
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
matchChainsWithDifferentChainIds(bridges) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
let newBridges = [];
|
|
449
|
+
try {
|
|
450
|
+
const channels_to_connection = yield this.query.ibc.channel.Channels({
|
|
451
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
452
|
+
limit: new long_1.default(1000000)
|
|
453
|
+
})
|
|
454
|
+
});
|
|
455
|
+
const connection_to_clientId = yield this.query.ibc.connection.Connections({
|
|
456
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
457
|
+
limit: new long_1.default(1000000)
|
|
458
|
+
})
|
|
459
|
+
});
|
|
460
|
+
const clientId_to_chainIdName = yield this.query.ibc.client.ClientStates({
|
|
461
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
462
|
+
limit: new long_1.default(1000000)
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
const clientStates = clientId_to_chainIdName.clientStates.map(s => ({
|
|
466
|
+
clientState: Object.assign({}, tendermint_1.ClientState.decode(s.clientState.value)),
|
|
467
|
+
clientId: s.clientId,
|
|
468
|
+
}));
|
|
469
|
+
newBridges = bridges.map(bridge => {
|
|
470
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
471
|
+
const connection = channels_to_connection.channels.find(channel => channel.channelId === ("channel-" + (bridge.chainId.toNumber() - 1)));
|
|
472
|
+
const connectionId = connection === null || connection === void 0 ? void 0 : connection.connectionHops[0];
|
|
473
|
+
const src_channel = (_a = connection === null || connection === void 0 ? void 0 : connection.channelId) !== null && _a !== void 0 ? _a : "";
|
|
474
|
+
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 : "";
|
|
475
|
+
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);
|
|
476
|
+
const portId = (_f = cosmRegexArr === null || cosmRegexArr === void 0 ? void 0 : cosmRegexArr[1]) !== null && _f !== void 0 ? _f : "transfer";
|
|
477
|
+
const clientId = (_g = connection_to_clientId.connections.find(connection => connection.id === connectionId)) === null || _g === void 0 ? void 0 : _g.clientId;
|
|
478
|
+
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;
|
|
479
|
+
return Object.assign(Object.assign({}, bridge), { chain_id_name: chainIdName !== null && chainIdName !== void 0 ? chainIdName : "", channels: { src_channel, dst_channel, port_id: portId } });
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
finally {
|
|
483
|
+
const checkedBefore = new Array(newBridges.length).fill(false);
|
|
484
|
+
const chainMap = {};
|
|
485
|
+
for (let i = 0; i < newBridges.length; i++) {
|
|
486
|
+
if (checkedBefore[i])
|
|
487
|
+
continue;
|
|
488
|
+
const bridge = newBridges[i];
|
|
489
|
+
const chainId = bridge.chain_id_name;
|
|
490
|
+
if (chainMap[chainId]) {
|
|
491
|
+
const chainName = chainMap[chainId];
|
|
492
|
+
for (let j = i; j < newBridges.length; j++) {
|
|
493
|
+
const subBridge = newBridges[j];
|
|
494
|
+
if (subBridge.chain_id_name === chainId) {
|
|
495
|
+
subBridge.chainName = chainName;
|
|
496
|
+
checkedBefore[j] = true;
|
|
497
|
+
}
|
|
359
498
|
}
|
|
360
499
|
}
|
|
361
|
-
|
|
500
|
+
else {
|
|
501
|
+
chainMap[chainId] = bridge.chainName;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return newBridges;
|
|
362
505
|
}
|
|
363
|
-
return this.tokens;
|
|
364
506
|
});
|
|
365
507
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
508
|
+
getIbcBlockchainNames() {
|
|
509
|
+
return this.bridges.ibc.map(bridge => bridge.chainName);
|
|
510
|
+
}
|
|
511
|
+
getPolynetworkBlockchainNames() {
|
|
512
|
+
return this.bridges.polynetwork.map(bridge => bridge.chainName);
|
|
513
|
+
}
|
|
514
|
+
getAllBlockchainNames() {
|
|
515
|
+
return this.getIbcBlockchainNames().concat(this.getPolynetworkBlockchainNames());
|
|
516
|
+
}
|
|
517
|
+
getBridgesFromBridgeId(bridgeId) {
|
|
518
|
+
switch (bridgeId) {
|
|
519
|
+
case blockchain_1.BRIDGE_IDS.polynetwork:
|
|
520
|
+
return this.bridges.polynetwork;
|
|
521
|
+
case blockchain_1.BRIDGE_IDS.ibc:
|
|
522
|
+
return this.bridges.ibc;
|
|
523
|
+
default:
|
|
524
|
+
return this.bridges.polynetwork;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
getIbcTokens() {
|
|
528
|
+
const ibcTokens = Object.values(this.tokens).reduce((prev, token) => {
|
|
529
|
+
const newPrev = prev;
|
|
530
|
+
if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc) {
|
|
531
|
+
newPrev[token.denom] = token;
|
|
532
|
+
}
|
|
533
|
+
return newPrev;
|
|
534
|
+
}, {});
|
|
535
|
+
return ibcTokens;
|
|
536
|
+
}
|
|
537
|
+
getPolyNetworkTokens() {
|
|
538
|
+
const polynetworkTokens = Object.values(this.tokens).reduce((prev, token) => {
|
|
539
|
+
const newPrev = prev;
|
|
540
|
+
if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork) {
|
|
541
|
+
newPrev[token.denom] = token;
|
|
542
|
+
}
|
|
543
|
+
return newPrev;
|
|
544
|
+
}, {});
|
|
545
|
+
return polynetworkTokens;
|
|
546
|
+
}
|
|
547
|
+
getBlockchainV2FromIDs(chainId, bridgeId) {
|
|
548
|
+
var _a, _b;
|
|
549
|
+
const chainIdNum = Number(chainId);
|
|
550
|
+
const bridgeIdNum = Number(bridgeId);
|
|
551
|
+
if ((chainIdNum === 5 && bridgeIdNum === 1) || (chainIdNum === 0 && bridgeIdNum === 2))
|
|
552
|
+
return "Carbon";
|
|
553
|
+
const bridgeList = this.getBridgesFromBridgeId(bridgeIdNum);
|
|
554
|
+
return (_b = (_a = bridgeList.find(bridge => bridge.chainId.toNumber() === chainIdNum)) === null || _a === void 0 ? void 0 : _a.chainName) !== null && _b !== void 0 ? _b : undefined;
|
|
555
|
+
}
|
|
556
|
+
getBridgeFromToken(token) {
|
|
557
|
+
if (!token || !token.bridgeId)
|
|
558
|
+
return undefined;
|
|
559
|
+
const bridgeList = this.getBridgesFromBridgeId(token.bridgeId.toNumber());
|
|
560
|
+
return bridgeList.find(bridge => token.chainId.equals(bridge.chainId));
|
|
561
|
+
}
|
|
562
|
+
getIbcChainIdFromToken(token) {
|
|
563
|
+
if (!token)
|
|
564
|
+
return undefined;
|
|
565
|
+
const bridge = this.getBridgeFromToken(token);
|
|
566
|
+
if (!bridge || !(0, blockchain_1.isIbcBridge)(bridge))
|
|
567
|
+
return undefined;
|
|
568
|
+
return bridge.chain_id_name;
|
|
569
|
+
}
|
|
570
|
+
getCarbonDenomTraces() {
|
|
571
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
572
|
+
// get swth on osmosis
|
|
573
|
+
const osmoTmClient = yield tendermint_rpc_1.Tendermint34Client.connect(network_1.publicRpcNodes.Osmosis);
|
|
574
|
+
const osmoClient = new stargate_1.QueryClient(osmoTmClient);
|
|
575
|
+
const osmosRpcClient = (0, stargate_1.createProtobufRpcClient)(osmoClient);
|
|
576
|
+
const osmoIbcClient = new query_1.QueryClientImpl(osmosRpcClient);
|
|
577
|
+
const osmoDenomTraces = yield osmoIbcClient.DenomTraces({
|
|
578
|
+
pagination: pagination_1.PageRequest.fromPartial({
|
|
579
|
+
limit: new long_1.default(1000000),
|
|
580
|
+
}),
|
|
581
|
+
});
|
|
582
|
+
const osmoSwthDenomTrace = osmoDenomTraces.denomTraces.filter((trace) => {
|
|
583
|
+
return trace.baseDenom === "swth";
|
|
584
|
+
});
|
|
585
|
+
return osmoSwthDenomTrace.reduce((prev, trace) => {
|
|
586
|
+
var _a;
|
|
587
|
+
const coinMinimalDenom = util_1.IBCUtils.makeIBCMinimalDenom(trace.path, trace.baseDenom);
|
|
588
|
+
const token = (_a = this.tokenForDenom(coinMinimalDenom)) !== null && _a !== void 0 ? _a : this.tokenForDenom(trace.baseDenom);
|
|
589
|
+
const traceExtended = Object.assign(Object.assign({}, trace), { token });
|
|
590
|
+
this.denomTraces[coinMinimalDenom] = traceExtended;
|
|
591
|
+
prev[coinMinimalDenom] = traceExtended;
|
|
592
|
+
return prev;
|
|
593
|
+
}, {});
|
|
388
594
|
});
|
|
389
|
-
return swthTokens;
|
|
390
595
|
}
|
|
391
596
|
getCdpUnderlyingToken(cdpDenom) {
|
|
392
597
|
if (!this.cdpTokens[cdpDenom]) {
|
|
@@ -459,7 +664,7 @@ class TokenClient {
|
|
|
459
664
|
processTokenPrices(tokenPrices) {
|
|
460
665
|
return tokenPrices.reduce((prevPrices, price) => {
|
|
461
666
|
const newPrev = prevPrices;
|
|
462
|
-
newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
|
|
667
|
+
newPrev[price.denom] = (0, number_1.bnOrZero)(price.twap).shiftedBy(-constant_1.decTypeDecimals);
|
|
463
668
|
return newPrev;
|
|
464
669
|
}, {});
|
|
465
670
|
}
|
|
@@ -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,15 +69,20 @@ 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
|
+
(0, 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
|
-
? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
|
|
80
|
-
: exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
84
|
+
? (0, exports.balanceBatchRequest)(address.replace(/^0x/i, ""))
|
|
85
|
+
: (0, exports.tokenBalanceBatchRequest)(token.tokenAddress, address));
|
|
81
86
|
const response = yield fetch(this.getProviderUrl(), {
|
|
82
87
|
method: "post",
|
|
83
88
|
headers: { "content-type": "application/json" },
|
|
@@ -102,7 +107,7 @@ class ZILClient {
|
|
|
102
107
|
// if (!isValidAddress) {
|
|
103
108
|
// throw new Error("invalid address")
|
|
104
109
|
// }
|
|
105
|
-
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
110
|
+
return (0, zilliqa_1.fromBech32Address)(bech32Address).toLowerCase().substr(2);
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
113
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -148,7 +153,7 @@ class ZILClient {
|
|
|
148
153
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
149
154
|
}
|
|
150
155
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
151
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
156
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
|
|
152
157
|
if (balanceAndNonceResp.error !== undefined) {
|
|
153
158
|
throw new Error(balanceAndNonceResp.error.message);
|
|
154
159
|
}
|
|
@@ -166,7 +171,7 @@ class ZILClient {
|
|
|
166
171
|
vname: "spender",
|
|
167
172
|
type: "ByStr20",
|
|
168
173
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
169
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
174
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : (0, generic_1.appendHexPrefix)(token.bridgeAddress),
|
|
170
175
|
},
|
|
171
176
|
{
|
|
172
177
|
vname: "amount",
|
|
@@ -184,7 +189,7 @@ class ZILClient {
|
|
|
184
189
|
}
|
|
185
190
|
checkAllowanceZRC2(token, owner, spender) {
|
|
186
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
192
|
+
const contractAddress = (0, generic_1.appendHexPrefix)(token.tokenAddress);
|
|
188
193
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
189
194
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
190
195
|
if (resp.error !== undefined) {
|
|
@@ -206,13 +211,13 @@ class ZILClient {
|
|
|
206
211
|
}
|
|
207
212
|
const carbonNetwork = networkConfig.network;
|
|
208
213
|
const fromTokenId = fromToken.id;
|
|
209
|
-
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
214
|
+
const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
|
|
210
215
|
const toTokenDenom = toToken.denom;
|
|
211
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
216
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
|
|
212
217
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
|
|
213
218
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
214
219
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
215
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
220
|
+
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
216
221
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
217
222
|
let zilliqa;
|
|
218
223
|
if (typeof signer === "string") {
|
|
@@ -227,7 +232,7 @@ class ZILClient {
|
|
|
227
232
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
228
233
|
}
|
|
229
234
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
230
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
235
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(fromAddress));
|
|
231
236
|
if (balanceAndNonceResp.error !== undefined) {
|
|
232
237
|
throw new Error(balanceAndNonceResp.error.message);
|
|
233
238
|
}
|
|
@@ -304,13 +309,13 @@ class ZILClient {
|
|
|
304
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
310
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
306
311
|
const networkConfig = this.getNetworkConfig();
|
|
307
|
-
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
308
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
309
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
312
|
+
const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
|
|
313
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
|
|
314
|
+
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
310
315
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
311
316
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
312
317
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
313
|
-
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
318
|
+
const contractAddress = (0, generic_1.appendHexPrefix)(token.bridgeAddress);
|
|
314
319
|
let zilliqa;
|
|
315
320
|
if (typeof signer === "string") {
|
|
316
321
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -324,7 +329,7 @@ class ZILClient {
|
|
|
324
329
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
325
330
|
}
|
|
326
331
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
327
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
332
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
|
|
328
333
|
if (balanceAndNonceResp.error !== undefined) {
|
|
329
334
|
throw new Error(balanceAndNonceResp.error.message);
|
|
330
335
|
}
|
|
@@ -409,7 +414,7 @@ class ZILClient {
|
|
|
409
414
|
getTargetProxyHash(token) {
|
|
410
415
|
const networkConfig = this.getNetworkConfig();
|
|
411
416
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
412
|
-
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
417
|
+
const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
413
418
|
return addressHex;
|
|
414
419
|
}
|
|
415
420
|
getNetworkConfig() {
|
|
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
|
|
|
159
159
|
const message = Object.assign({}, baseQueryProposalsRequest);
|
|
160
160
|
message.proposalStatus =
|
|
161
161
|
object.proposalStatus !== undefined && object.proposalStatus !== null
|
|
162
|
-
? gov_1.proposalStatusFromJSON(object.proposalStatus)
|
|
162
|
+
? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
|
|
163
163
|
: 0;
|
|
164
164
|
message.voter =
|
|
165
165
|
object.voter !== undefined && object.voter !== null
|
|
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
|
|
|
178
178
|
toJSON(message) {
|
|
179
179
|
const obj = {};
|
|
180
180
|
message.proposalStatus !== undefined &&
|
|
181
|
-
(obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
|
|
181
|
+
(obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
|
|
182
182
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
183
183
|
message.depositor !== undefined && (obj.depositor = message.depositor);
|
|
184
184
|
message.pagination !== undefined &&
|
|
@@ -300,7 +300,7 @@ exports.MsgVote = {
|
|
|
300
300
|
: "";
|
|
301
301
|
message.option =
|
|
302
302
|
object.option !== undefined && object.option !== null
|
|
303
|
-
? gov_1.voteOptionFromJSON(object.option)
|
|
303
|
+
? (0, gov_1.voteOptionFromJSON)(object.option)
|
|
304
304
|
: 0;
|
|
305
305
|
message.metadata =
|
|
306
306
|
object.metadata !== undefined && object.metadata !== null
|
|
@@ -314,7 +314,7 @@ exports.MsgVote = {
|
|
|
314
314
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
315
315
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
316
316
|
message.option !== undefined &&
|
|
317
|
-
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
317
|
+
(obj.option = (0, gov_1.voteOptionToJSON)(message.option));
|
|
318
318
|
message.metadata !== undefined && (obj.metadata = message.metadata);
|
|
319
319
|
return obj;
|
|
320
320
|
},
|
|
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
|
|
|
159
159
|
const message = Object.assign({}, baseQueryProposalsRequest);
|
|
160
160
|
message.proposalStatus =
|
|
161
161
|
object.proposalStatus !== undefined && object.proposalStatus !== null
|
|
162
|
-
? gov_1.proposalStatusFromJSON(object.proposalStatus)
|
|
162
|
+
? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
|
|
163
163
|
: 0;
|
|
164
164
|
message.voter =
|
|
165
165
|
object.voter !== undefined && object.voter !== null
|
|
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
|
|
|
178
178
|
toJSON(message) {
|
|
179
179
|
const obj = {};
|
|
180
180
|
message.proposalStatus !== undefined &&
|
|
181
|
-
(obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
|
|
181
|
+
(obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
|
|
182
182
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
183
183
|
message.depositor !== undefined && (obj.depositor = message.depositor);
|
|
184
184
|
message.pagination !== undefined &&
|
|
@@ -185,7 +185,7 @@ exports.MsgVote = {
|
|
|
185
185
|
: "";
|
|
186
186
|
message.option =
|
|
187
187
|
object.option !== undefined && object.option !== null
|
|
188
|
-
? gov_1.voteOptionFromJSON(object.option)
|
|
188
|
+
? (0, gov_1.voteOptionFromJSON)(object.option)
|
|
189
189
|
: 0;
|
|
190
190
|
return message;
|
|
191
191
|
},
|
|
@@ -195,7 +195,7 @@ exports.MsgVote = {
|
|
|
195
195
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
196
196
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
197
197
|
message.option !== undefined &&
|
|
198
|
-
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
198
|
+
(obj.option = (0, gov_1.voteOptionToJSON)(message.option));
|
|
199
199
|
return obj;
|
|
200
200
|
},
|
|
201
201
|
fromPartial(object) {
|
|
@@ -384,7 +384,7 @@ exports.EventExec = {
|
|
|
384
384
|
: long_1.default.UZERO;
|
|
385
385
|
message.result =
|
|
386
386
|
object.result !== undefined && object.result !== null
|
|
387
|
-
? types_1.proposalExecutorResultFromJSON(object.result)
|
|
387
|
+
? (0, types_1.proposalExecutorResultFromJSON)(object.result)
|
|
388
388
|
: 0;
|
|
389
389
|
message.logs =
|
|
390
390
|
object.logs !== undefined && object.logs !== null
|
|
@@ -397,7 +397,7 @@ exports.EventExec = {
|
|
|
397
397
|
message.proposalId !== undefined &&
|
|
398
398
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
399
399
|
message.result !== undefined &&
|
|
400
|
-
(obj.result = types_1.proposalExecutorResultToJSON(message.result));
|
|
400
|
+
(obj.result = (0, types_1.proposalExecutorResultToJSON)(message.result));
|
|
401
401
|
message.logs !== undefined && (obj.logs = message.logs);
|
|
402
402
|
return obj;
|
|
403
403
|
},
|