carbon-js-sdk 0.3.53-beta.1 → 0.3.53-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/lib/CarbonSDK.js +1 -1
  2. package/lib/clients/CarbonQueryClient.d.ts +6 -0
  3. package/lib/clients/CarbonQueryClient.js +36 -30
  4. package/lib/clients/ETHClient.d.ts +11 -4
  5. package/lib/clients/ETHClient.js +32 -18
  6. package/lib/clients/HydrogenClient.d.ts +16 -7
  7. package/lib/clients/HydrogenClient.js +56 -10
  8. package/lib/clients/NEOClient.d.ts +1 -1
  9. package/lib/clients/NEOClient.js +15 -10
  10. package/lib/clients/TokenClient.d.ts +19 -4
  11. package/lib/clients/TokenClient.js +187 -10
  12. package/lib/clients/ZILClient.d.ts +1 -1
  13. package/lib/clients/ZILClient.js +25 -20
  14. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  15. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  16. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  17. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/keys.d.ts +39 -0
  18. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/keys.js +138 -0
  19. package/lib/codec/ethermint/evm/v1/events.d.ts +72 -0
  20. package/lib/codec/ethermint/evm/v1/events.js +303 -0
  21. package/lib/codec/ethermint/evm/v1/evm.d.ts +239 -0
  22. package/lib/codec/ethermint/evm/v1/evm.js +1140 -0
  23. package/lib/codec/ethermint/evm/v1/genesis.d.ts +43 -0
  24. package/lib/codec/ethermint/evm/v1/genesis.js +153 -0
  25. package/lib/codec/ethermint/evm/v1/query.d.ts +424 -0
  26. package/lib/codec/ethermint/evm/v1/query.js +1637 -0
  27. package/lib/codec/ethermint/evm/v1/tx.d.ts +219 -0
  28. package/lib/codec/ethermint/evm/v1/tx.js +935 -0
  29. package/lib/codec/ethermint/feemarket/v1/events.d.ts +34 -0
  30. package/lib/codec/ethermint/feemarket/v1/events.js +116 -0
  31. package/lib/codec/ethermint/feemarket/v1/feemarket.d.ts +51 -0
  32. package/lib/codec/ethermint/feemarket/v1/feemarket.js +176 -0
  33. package/lib/codec/ethermint/feemarket/v1/genesis.d.ts +26 -0
  34. package/lib/codec/ethermint/feemarket/v1/genesis.js +79 -0
  35. package/lib/codec/ethermint/feemarket/v1/query.d.ts +100 -0
  36. package/lib/codec/ethermint/feemarket/v1/query.js +276 -0
  37. package/lib/codec/ethermint/feemarket/v1/tx.d.ts +55 -0
  38. package/lib/codec/ethermint/feemarket/v1/tx.js +120 -0
  39. package/lib/codec/ethermint/types/v1/account.d.ts +26 -0
  40. package/lib/codec/ethermint/types/v1/account.js +78 -0
  41. package/lib/codec/ethermint/types/v1/dynamic_fee.d.ts +20 -0
  42. package/lib/codec/ethermint/types/v1/dynamic_fee.js +60 -0
  43. package/lib/codec/ethermint/types/v1/indexer.d.ts +41 -0
  44. package/lib/codec/ethermint/types/v1/indexer.js +153 -0
  45. package/lib/codec/ethermint/types/v1/web3.d.ts +36 -0
  46. package/lib/codec/ethermint/types/v1/web3.js +124 -0
  47. package/lib/codec/evmbank/genesis.d.ts +32 -0
  48. package/lib/codec/evmbank/genesis.js +152 -0
  49. package/lib/codec/evmbank/query.d.ts +40 -0
  50. package/lib/codec/evmbank/query.js +116 -0
  51. package/lib/codec/evmmerge/event.d.ts +20 -0
  52. package/lib/codec/evmmerge/event.js +90 -0
  53. package/lib/codec/evmmerge/genesis.d.ts +48 -0
  54. package/lib/codec/evmmerge/genesis.js +216 -0
  55. package/lib/codec/evmmerge/offchain.d.ts +22 -0
  56. package/lib/codec/evmmerge/offchain.js +105 -0
  57. package/lib/codec/evmmerge/query.d.ts +43 -0
  58. package/lib/codec/evmmerge/query.js +117 -0
  59. package/lib/codec/evmmerge/tx.d.ts +45 -0
  60. package/lib/codec/evmmerge/tx.js +128 -0
  61. package/lib/constant/generic.js +1 -1
  62. package/lib/hydrogen/transfer.d.ts +5 -5
  63. package/lib/modules/cdp.js +43 -43
  64. package/lib/modules/cosmwasm.js +1 -1
  65. package/lib/modules/gov.js +12 -12
  66. package/lib/modules/liquiditypool.js +1 -1
  67. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  68. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  69. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  70. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  71. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  72. package/lib/provider/amino/types/admin.js +28 -28
  73. package/lib/provider/amino/types/bank.js +1 -1
  74. package/lib/provider/amino/types/broker.js +1 -1
  75. package/lib/provider/amino/types/cdp.js +22 -22
  76. package/lib/provider/amino/types/coin.js +4 -4
  77. package/lib/provider/amino/types/gov.js +4 -4
  78. package/lib/provider/amino/types/ibc.js +1 -1
  79. package/lib/provider/amino/types/leverage.js +1 -1
  80. package/lib/provider/amino/types/liquidityPool.js +7 -7
  81. package/lib/provider/amino/types/market.js +1 -1
  82. package/lib/provider/amino/types/oracle.js +1 -1
  83. package/lib/provider/amino/types/order.js +4 -4
  84. package/lib/provider/amino/types/position.js +1 -1
  85. package/lib/provider/amino/types/profile.js +1 -1
  86. package/lib/provider/amino/types/staking.js +4 -4
  87. package/lib/provider/amino/types/subaccount.js +3 -3
  88. package/lib/provider/amino/utils.js +11 -11
  89. package/lib/provider/ledger/ledger.js +2 -2
  90. package/lib/provider/metamask/MetaMask.d.ts +5 -5
  91. package/lib/provider/metamask/MetaMask.js +35 -35
  92. package/lib/provider/o3/O3Wallet.js +2 -2
  93. package/lib/util/address.js +13 -13
  94. package/lib/util/api.js +4 -4
  95. package/lib/util/blockchain.d.ts +12 -0
  96. package/lib/util/blockchain.js +143 -1
  97. package/lib/util/fetch.js +1 -1
  98. package/lib/util/generic.js +3 -3
  99. package/lib/util/ibc.d.ts +4 -4
  100. package/lib/util/ibc.js +17 -18
  101. package/lib/util/number.js +5 -5
  102. package/lib/wallet/CarbonSigner.js +2 -2
  103. package/lib/wallet/CarbonSigningClient.js +8 -8
  104. package/lib/wallet/CarbonWallet.js +6 -6
  105. package/lib/websocket/connector.js +3 -3
  106. package/package.json +1 -1
@@ -20,6 +20,9 @@ const util_1 = require("../util");
20
20
  const number_1 = require("../util/number");
21
21
  const long_1 = __importDefault(require("long"));
22
22
  const InsightsQueryClient_1 = __importDefault(require("./InsightsQueryClient"));
23
+ const blockchain_1 = require("../util/blockchain");
24
+ const pagination_1 = require("../codec/cosmos/base/query/v1beta1/pagination");
25
+ const tendermint_1 = require("../codec/ibc/lightclients/tendermint/v1/tendermint");
23
26
  const SYMBOL_OVERRIDE = {
24
27
  swth: "SWTH",
25
28
  NNEO: "nNEO",
@@ -43,11 +46,16 @@ class TokenClient {
43
46
  this.wrapperMap = {};
44
47
  this.poolTokens = {};
45
48
  this.cdpTokens = {};
49
+ this.bridges = { polynetwork: [], ibc: [] };
46
50
  this.symbols = {};
47
51
  this.usdValues = {};
48
52
  this.commonAssetNames = constant_1.CommonAssetName;
49
53
  this.geckoTokenNames = constant_1.CoinGeckoTokenNames;
50
54
  this.additionalGeckoDenoms = {};
55
+ this.getIbcChainFromBlockchainV2 = (blockchain) => {
56
+ const ibcBridge = this.bridges.ibc.find(bridge => (bridge.chainName === blockchain || bridge.chainName.toLowerCase() === blockchain));
57
+ return ibcBridge === null || ibcBridge === void 0 ? void 0 : ibcBridge.chain_id_name;
58
+ };
51
59
  }
52
60
  static instance(query, configProvider) {
53
61
  return new TokenClient(query, configProvider);
@@ -58,6 +66,7 @@ class TokenClient {
58
66
  yield this.reloadWrapperMap();
59
67
  yield this.reloadTokens();
60
68
  yield this.reloadDenomGeckoMap();
69
+ yield this.getBridges();
61
70
  // non-blocking reload
62
71
  try {
63
72
  this.reloadUSDValues();
@@ -95,6 +104,18 @@ class TokenClient {
95
104
  const blockchain = util_1.BlockchainUtils.blockchainForChainId(chainId, networkConfig.network);
96
105
  return blockchain;
97
106
  }
107
+ getBlockchainV2(denom) {
108
+ if (!denom)
109
+ return undefined;
110
+ let token = this.tokens[denom];
111
+ if (this.isNativeToken(denom) || this.isNativeStablecoin(denom) || TokenClient.isPoolToken(denom) || TokenClient.isCdpToken(denom) || this.isGroupedToken(denom)) {
112
+ // native denoms "swth" and "usc" should be native.
113
+ // pool and cdp tokens are on the Native blockchain, hence 0
114
+ return 'Native';
115
+ }
116
+ const bridge = this.getBridgeFromToken(token);
117
+ return bridge === null || bridge === void 0 ? void 0 : bridge.chainName;
118
+ }
98
119
  getSymbol(denom) {
99
120
  var _a, _b;
100
121
  if (TokenClient.isCdpToken(denom)) {
@@ -229,7 +250,7 @@ class TokenClient {
229
250
  }
230
251
  return result;
231
252
  }
232
- getWrappedToken(denom, blockchain) {
253
+ getWrappedToken(denom, blockchain, version = 'V1') {
233
254
  const networkConfig = this.configProvider.getConfig();
234
255
  // if denom is already a wrapped denom or no blockchain was specified,
235
256
  // just return the input denom.
@@ -245,9 +266,15 @@ class TokenClient {
245
266
  }
246
267
  // check if wrapped denom is of correct blockchain
247
268
  const token = this.tokens[wrappedDenom];
248
- let tokenChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
249
- if (TokenClient.isIBCDenom(wrappedDenom)) {
250
- tokenChain = util_1.IBCUtils.BlockchainMap[wrappedDenom];
269
+ let tokenChain = '';
270
+ if (version === "V1") {
271
+ tokenChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber());
272
+ if (TokenClient.isIBCDenom(token.denom)) {
273
+ tokenChain = util_1.IBCUtils.BlockchainMap[wrappedDenom];
274
+ }
275
+ }
276
+ else {
277
+ tokenChain = this.getBlockchainV2(token.denom);
251
278
  }
252
279
  if (!tokenChain) {
253
280
  continue; // unknown chain! just ignore this source token
@@ -283,21 +310,31 @@ class TokenClient {
283
310
  isNativeStablecoin(denom) {
284
311
  return denom === "usc";
285
312
  }
286
- getDepositTokenFor(tokenDenom, chain) {
313
+ isGroupedToken(denom) {
314
+ const groupedTokenRegex = new RegExp(/^cgt\/\d+$/);
315
+ return groupedTokenRegex.test(denom);
316
+ }
317
+ getDepositTokenFor(tokenDenom, chain, version = "V1") {
287
318
  const networkConfig = this.configProvider.getConfig();
288
319
  const token = this.tokenForDenom(tokenDenom);
289
320
  if (!token) {
290
321
  console.error("getDepositTokenFor token not found for", tokenDenom);
291
322
  return;
292
323
  }
324
+ let targetChain = "";
293
325
  // check if selected token is a source token
294
- let targetChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
295
- if (TokenClient.isIBCDenom(token.denom)) {
296
- targetChain = util_1.IBCUtils.BlockchainMap[token.denom];
326
+ if (version === "V1") {
327
+ targetChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
328
+ if (TokenClient.isIBCDenom(token.denom)) {
329
+ targetChain = util_1.IBCUtils.BlockchainMap[token.denom];
330
+ }
331
+ }
332
+ else {
333
+ targetChain = this.getBlockchainV2(token.denom);
297
334
  }
298
335
  const isSourceToken = targetChain === chain && token.denom !== "swth";
299
336
  // if not source token find wrapped token for chain
300
- const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain);
337
+ const depositToken = isSourceToken ? token : this.getWrappedToken(token.denom, chain, version);
301
338
  if (!depositToken) {
302
339
  console.error(`getDepositTokenFor wrapped token not found for "${token.denom}"`);
303
340
  return;
@@ -363,6 +400,146 @@ class TokenClient {
363
400
  return this.tokens;
364
401
  });
365
402
  }
403
+ getBridges() {
404
+ return __awaiter(this, void 0, void 0, function* () {
405
+ const allBridges = yield this.query.coin.BridgeAll({
406
+ pagination: {
407
+ key: new Uint8Array(),
408
+ limit: new long_1.default(10000),
409
+ offset: long_1.default.UZERO,
410
+ countTotal: true,
411
+ reverse: false,
412
+ },
413
+ });
414
+ const unmatchedIbcBridgeList = allBridges.bridges.filter(bridge => {
415
+ if (!bridge.enabled)
416
+ return;
417
+ return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc;
418
+ });
419
+ const ibcBridges = yield this.matchChainsWithDifferentChainIds(unmatchedIbcBridgeList);
420
+ const polynetworkBridges = allBridges.bridges.filter(bridge => {
421
+ if (!bridge.enabled)
422
+ return;
423
+ return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork;
424
+ });
425
+ Object.assign(this.bridges, {
426
+ polynetwork: polynetworkBridges,
427
+ ibc: ibcBridges
428
+ });
429
+ return this.bridges;
430
+ });
431
+ }
432
+ matchChainsWithDifferentChainIds(bridges) {
433
+ return __awaiter(this, void 0, void 0, function* () {
434
+ let newBridges = [];
435
+ try {
436
+ const channels_to_connection = yield this.query.ibc.channel.Channels({
437
+ pagination: pagination_1.PageRequest.fromPartial({
438
+ limit: new long_1.default(1000000)
439
+ })
440
+ });
441
+ const connection_to_clientId = yield this.query.ibc.connection.Connections({
442
+ pagination: pagination_1.PageRequest.fromPartial({
443
+ limit: new long_1.default(1000000)
444
+ })
445
+ });
446
+ const clientId_to_chainIdName = yield this.query.ibc.client.ClientStates({
447
+ pagination: pagination_1.PageRequest.fromPartial({
448
+ limit: new long_1.default(1000000)
449
+ })
450
+ });
451
+ const clientStates = clientId_to_chainIdName.clientStates.map(s => ({
452
+ clientState: Object.assign({}, tendermint_1.ClientState.decode(s.clientState.value)),
453
+ clientId: s.clientId,
454
+ }));
455
+ newBridges = bridges.map(bridge => {
456
+ var _a, _b, _c, _d;
457
+ const connectionId = (_a = channels_to_connection.channels.find(channel => channel.channelId === ("channel-" + (bridge.chainId.toNumber() - 1)))) === null || _a === void 0 ? void 0 : _a.connectionHops[0];
458
+ const clientId = (_b = connection_to_clientId.connections.find(connection => connection.id === connectionId)) === null || _b === void 0 ? void 0 : _b.clientId;
459
+ const chainIdName = (_d = ((_c = clientStates.find(client => client.clientId === clientId)) === null || _c === void 0 ? void 0 : _c.clientState)) === null || _d === void 0 ? void 0 : _d.chainId;
460
+ return Object.assign(Object.assign({}, bridge), { chain_id_name: chainIdName !== null && chainIdName !== void 0 ? chainIdName : "" });
461
+ });
462
+ }
463
+ finally {
464
+ const checkedBefore = new Array(newBridges.length).fill(false);
465
+ const chainMap = {};
466
+ for (let i = 0; i < newBridges.length; i++) {
467
+ if (checkedBefore[i])
468
+ continue;
469
+ const bridge = newBridges[i];
470
+ const chainId = bridge.chain_id_name;
471
+ if (chainMap[chainId]) {
472
+ const chainName = chainMap[chainId];
473
+ for (let j = i; j < newBridges.length; j++) {
474
+ const subBridge = newBridges[j];
475
+ if (subBridge.chain_id_name === chainId) {
476
+ subBridge.chainName = chainName;
477
+ checkedBefore[j] = true;
478
+ }
479
+ }
480
+ }
481
+ else {
482
+ chainMap[chainId] = bridge.chainName;
483
+ }
484
+ }
485
+ return newBridges;
486
+ }
487
+ });
488
+ }
489
+ getIbcBlockchainNames() {
490
+ return this.bridges.ibc.map(bridge => bridge.chainName);
491
+ }
492
+ getPolynetworkBlockchainNames() {
493
+ return this.bridges.polynetwork.map(bridge => bridge.chainName);
494
+ }
495
+ getAllBlockchainNames() {
496
+ return this.getIbcBlockchainNames().concat(this.getPolynetworkBlockchainNames());
497
+ }
498
+ getBridgesFromBridgeId(bridgeId) {
499
+ switch (bridgeId) {
500
+ case blockchain_1.BRIDGE_IDS.polynetwork:
501
+ return this.bridges.polynetwork;
502
+ case blockchain_1.BRIDGE_IDS.ibc:
503
+ return this.bridges.ibc;
504
+ default:
505
+ return this.bridges.polynetwork;
506
+ }
507
+ }
508
+ getIbcTokens() {
509
+ const ibcTokens = Object.values(this.tokens).reduce((prev, token) => {
510
+ const newPrev = prev;
511
+ if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc) {
512
+ newPrev[token.denom] = token;
513
+ }
514
+ return newPrev;
515
+ }, {});
516
+ return ibcTokens;
517
+ }
518
+ getPolyNetworkTokens() {
519
+ const polynetworkTokens = Object.values(this.tokens).reduce((prev, token) => {
520
+ const newPrev = prev;
521
+ if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork) {
522
+ newPrev[token.denom] = token;
523
+ }
524
+ return newPrev;
525
+ }, {});
526
+ return polynetworkTokens;
527
+ }
528
+ getBlockchainV2FromIDs(chainId, bridgeId) {
529
+ var _a, _b;
530
+ const chainIdNum = Number(chainId);
531
+ const bridgeIdNum = Number(bridgeId);
532
+ if ((chainIdNum === 5 && bridgeIdNum === 1) || (chainIdNum === 0 && bridgeIdNum === 2))
533
+ return "Carbon";
534
+ const bridgeList = this.getBridgesFromBridgeId(bridgeIdNum);
535
+ return (_b = (_a = bridgeList.find(bridge => bridge.chainId.toNumber() === chainIdNum)) === null || _a === void 0 ? void 0 : _a.chainName) !== null && _b !== void 0 ? _b : undefined;
536
+ }
537
+ getBridgeFromToken(token) {
538
+ if (!token || !token.bridgeId)
539
+ return undefined;
540
+ const bridgeList = this.getBridgesFromBridgeId(token.bridgeId.toNumber());
541
+ return bridgeList.find(bridge => token.chainId.equals(bridge.chainId));
542
+ }
366
543
  getCarbonIbcTokens() {
367
544
  const swthTokens = ibc_1.swthIbcWhitelist.map((chainId) => {
368
545
  var _a, _b, _c;
@@ -456,7 +633,7 @@ class TokenClient {
456
633
  processTokenPrices(tokenPrices) {
457
634
  return tokenPrices.reduce((prevPrices, price) => {
458
635
  const newPrev = prevPrices;
459
- newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
636
+ newPrev[price.denom] = (0, number_1.bnOrZero)(price.twap).shiftedBy(-constant_1.decTypeDecimals);
460
637
  return newPrev;
461
638
  }, {});
462
639
  }
@@ -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>;
@@ -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) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain &&
76
- token.tokenAddress.length == 40 &&
77
- (!whitelistDenoms || whitelistDenoms.includes(token.denom)));
75
+ const tokens = tokenQueryResults.filter((token) => {
76
+ const isCorrectBlockchain = version === "V2"
77
+ ?
78
+ 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 &&
@@ -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) {
@@ -618,13 +618,13 @@ exports.ModeInfo_Single = {
618
618
  const message = Object.assign({}, baseModeInfo_Single);
619
619
  message.mode =
620
620
  object.mode !== undefined && object.mode !== null
621
- ? signing_1.signModeFromJSON(object.mode)
621
+ ? (0, signing_1.signModeFromJSON)(object.mode)
622
622
  : 0;
623
623
  return message;
624
624
  },
625
625
  toJSON(message) {
626
626
  const obj = {};
627
- message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
627
+ message.mode !== undefined && (obj.mode = (0, signing_1.signModeToJSON)(message.mode));
628
628
  return obj;
629
629
  },
630
630
  fromPartial(object) {
@@ -0,0 +1,39 @@
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal";
3
+ export declare const protobufPackage = "ethermint.crypto.v1.ethsecp256k1";
4
+ /**
5
+ * PubKey defines a type alias for an ecdsa.PublicKey that implements
6
+ * Tendermint's PubKey interface. It represents the 33-byte compressed public
7
+ * key format.
8
+ */
9
+ export interface PubKey {
10
+ /** key is the public key in byte form */
11
+ key: Uint8Array;
12
+ }
13
+ /**
14
+ * PrivKey defines a type alias for an ecdsa.PrivateKey that implements
15
+ * Tendermint's PrivateKey interface.
16
+ */
17
+ export interface PrivKey {
18
+ /** key is the private key in byte form */
19
+ key: Uint8Array;
20
+ }
21
+ export declare const PubKey: {
22
+ encode(message: PubKey, writer?: _m0.Writer): _m0.Writer;
23
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): PubKey;
24
+ fromJSON(object: any): PubKey;
25
+ toJSON(message: PubKey): unknown;
26
+ fromPartial(object: DeepPartial<PubKey>): PubKey;
27
+ };
28
+ export declare const PrivKey: {
29
+ encode(message: PrivKey, writer?: _m0.Writer): _m0.Writer;
30
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): PrivKey;
31
+ fromJSON(object: any): PrivKey;
32
+ toJSON(message: PrivKey): unknown;
33
+ fromPartial(object: DeepPartial<PrivKey>): PrivKey;
34
+ };
35
+ declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
36
+ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
37
+ [K in keyof T]?: DeepPartial<T[K]>;
38
+ } : Partial<T>;
39
+ export {};
@@ -0,0 +1,138 @@
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.PrivKey = exports.PubKey = exports.protobufPackage = void 0;
7
+ /* eslint-disable */
8
+ const long_1 = __importDefault(require("long"));
9
+ const minimal_1 = __importDefault(require("protobufjs/minimal"));
10
+ exports.protobufPackage = "ethermint.crypto.v1.ethsecp256k1";
11
+ const basePubKey = {};
12
+ exports.PubKey = {
13
+ encode(message, writer = minimal_1.default.Writer.create()) {
14
+ if (message.key.length !== 0) {
15
+ writer.uint32(10).bytes(message.key);
16
+ }
17
+ return writer;
18
+ },
19
+ decode(input, length) {
20
+ const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
21
+ let end = length === undefined ? reader.len : reader.pos + length;
22
+ const message = Object.assign({}, basePubKey);
23
+ message.key = new Uint8Array();
24
+ while (reader.pos < end) {
25
+ const tag = reader.uint32();
26
+ switch (tag >>> 3) {
27
+ case 1:
28
+ message.key = reader.bytes();
29
+ break;
30
+ default:
31
+ reader.skipType(tag & 7);
32
+ break;
33
+ }
34
+ }
35
+ return message;
36
+ },
37
+ fromJSON(object) {
38
+ const message = Object.assign({}, basePubKey);
39
+ message.key =
40
+ object.key !== undefined && object.key !== null
41
+ ? bytesFromBase64(object.key)
42
+ : new Uint8Array();
43
+ return message;
44
+ },
45
+ toJSON(message) {
46
+ const obj = {};
47
+ message.key !== undefined &&
48
+ (obj.key = base64FromBytes(message.key !== undefined ? message.key : new Uint8Array()));
49
+ return obj;
50
+ },
51
+ fromPartial(object) {
52
+ var _a;
53
+ const message = Object.assign({}, basePubKey);
54
+ message.key = (_a = object.key) !== null && _a !== void 0 ? _a : new Uint8Array();
55
+ return message;
56
+ },
57
+ };
58
+ const basePrivKey = {};
59
+ exports.PrivKey = {
60
+ encode(message, writer = minimal_1.default.Writer.create()) {
61
+ if (message.key.length !== 0) {
62
+ writer.uint32(10).bytes(message.key);
63
+ }
64
+ return writer;
65
+ },
66
+ decode(input, length) {
67
+ const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
68
+ let end = length === undefined ? reader.len : reader.pos + length;
69
+ const message = Object.assign({}, basePrivKey);
70
+ message.key = new Uint8Array();
71
+ while (reader.pos < end) {
72
+ const tag = reader.uint32();
73
+ switch (tag >>> 3) {
74
+ case 1:
75
+ message.key = reader.bytes();
76
+ break;
77
+ default:
78
+ reader.skipType(tag & 7);
79
+ break;
80
+ }
81
+ }
82
+ return message;
83
+ },
84
+ fromJSON(object) {
85
+ const message = Object.assign({}, basePrivKey);
86
+ message.key =
87
+ object.key !== undefined && object.key !== null
88
+ ? bytesFromBase64(object.key)
89
+ : new Uint8Array();
90
+ return message;
91
+ },
92
+ toJSON(message) {
93
+ const obj = {};
94
+ message.key !== undefined &&
95
+ (obj.key = base64FromBytes(message.key !== undefined ? message.key : new Uint8Array()));
96
+ return obj;
97
+ },
98
+ fromPartial(object) {
99
+ var _a;
100
+ const message = Object.assign({}, basePrivKey);
101
+ message.key = (_a = object.key) !== null && _a !== void 0 ? _a : new Uint8Array();
102
+ return message;
103
+ },
104
+ };
105
+ var globalThis = (() => {
106
+ if (typeof globalThis !== "undefined")
107
+ return globalThis;
108
+ if (typeof self !== "undefined")
109
+ return self;
110
+ if (typeof window !== "undefined")
111
+ return window;
112
+ if (typeof global !== "undefined")
113
+ return global;
114
+ throw "Unable to locate global object";
115
+ })();
116
+ const atob = globalThis.atob ||
117
+ ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary"));
118
+ function bytesFromBase64(b64) {
119
+ const bin = atob(b64);
120
+ const arr = new Uint8Array(bin.length);
121
+ for (let i = 0; i < bin.length; ++i) {
122
+ arr[i] = bin.charCodeAt(i);
123
+ }
124
+ return arr;
125
+ }
126
+ const btoa = globalThis.btoa ||
127
+ ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64"));
128
+ function base64FromBytes(arr) {
129
+ const bin = [];
130
+ for (const byte of arr) {
131
+ bin.push(String.fromCharCode(byte));
132
+ }
133
+ return btoa(bin.join(""));
134
+ }
135
+ if (minimal_1.default.util.Long !== long_1.default) {
136
+ minimal_1.default.util.Long = long_1.default;
137
+ minimal_1.default.configure();
138
+ }