carbon-js-sdk 0.3.52 → 0.3.53-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.
Files changed (116) hide show
  1. package/lib/CarbonSDK.js +1 -1
  2. package/lib/clients/ETHClient.d.ts +11 -4
  3. package/lib/clients/ETHClient.js +20 -6
  4. package/lib/clients/HydrogenClient.d.ts +16 -7
  5. package/lib/clients/HydrogenClient.js +55 -9
  6. package/lib/clients/NEOClient.d.ts +1 -1
  7. package/lib/clients/NEOClient.js +9 -4
  8. package/lib/clients/TokenClient.d.ts +17 -4
  9. package/lib/clients/TokenClient.js +121 -8
  10. package/lib/clients/ZILClient.d.ts +1 -1
  11. package/lib/clients/ZILClient.js +9 -4
  12. package/lib/codec/cosmos/app/module/v1alpha1/module.d.ts +18 -0
  13. package/lib/codec/cosmos/app/module/v1alpha1/module.js +46 -0
  14. package/lib/codec/cosmos/app/v1alpha1/config.d.ts +57 -0
  15. package/lib/codec/cosmos/app/v1alpha1/config.js +125 -0
  16. package/lib/codec/cosmos/app/v1alpha1/export.d.ts +3 -0
  17. package/lib/codec/cosmos/app/v1alpha1/export.js +13 -0
  18. package/lib/codec/cosmos/app/v1alpha1/module.d.ts +109 -0
  19. package/lib/codec/cosmos/app/v1alpha1/module.js +192 -0
  20. package/lib/codec/cosmos/app/v1alpha1/query.d.ts +44 -0
  21. package/lib/codec/cosmos/app/v1alpha1/query.js +107 -0
  22. package/lib/codec/cosmos/authz/v1beta1/export.d.ts +4 -0
  23. package/lib/codec/cosmos/authz/v1beta1/export.js +25 -0
  24. package/lib/codec/cosmos/base/node/v1beta1/query.d.ts +42 -0
  25. package/lib/codec/cosmos/base/node/v1beta1/query.js +104 -0
  26. package/lib/codec/cosmos/base/tendermint/v1beta1/types.d.ts +67 -0
  27. package/lib/codec/cosmos/base/tendermint/v1beta1/types.js +423 -0
  28. package/lib/codec/cosmos/capability/v1beta1/export.d.ts +2 -0
  29. package/lib/codec/cosmos/capability/v1beta1/export.js +9 -0
  30. package/lib/codec/cosmos/crisis/v1beta1/export.d.ts +1 -0
  31. package/lib/codec/cosmos/crisis/v1beta1/export.js +6 -0
  32. package/lib/codec/cosmos/crypto/hd/v1/hd.d.ts +32 -0
  33. package/lib/codec/cosmos/crypto/hd/v1/hd.js +114 -0
  34. package/lib/codec/cosmos/crypto/keyring/v1/record.d.ts +78 -0
  35. package/lib/codec/cosmos/crypto/keyring/v1/record.js +309 -0
  36. package/lib/codec/cosmos/evidence/v1beta1/export.d.ts +3 -0
  37. package/lib/codec/cosmos/evidence/v1beta1/export.js +13 -0
  38. package/lib/codec/cosmos/feegrant/v1beta1/export.d.ts +3 -0
  39. package/lib/codec/cosmos/feegrant/v1beta1/export.js +20 -0
  40. package/lib/codec/cosmos/gov/v1/export.d.ts +3 -0
  41. package/lib/codec/cosmos/gov/v1/export.js +46 -0
  42. package/lib/codec/cosmos/gov/v1/genesis.d.ts +34 -0
  43. package/lib/codec/cosmos/gov/v1/genesis.js +166 -0
  44. package/lib/codec/cosmos/gov/v1/gov.d.ts +198 -0
  45. package/lib/codec/cosmos/gov/v1/gov.js +855 -0
  46. package/lib/codec/cosmos/gov/v1/query.d.ts +264 -0
  47. package/lib/codec/cosmos/gov/v1/query.js +1045 -0
  48. package/lib/codec/cosmos/gov/v1/tx.d.ts +167 -0
  49. package/lib/codec/cosmos/gov/v1/tx.js +639 -0
  50. package/lib/codec/cosmos/group/v1/events.d.ts +124 -0
  51. package/lib/codec/cosmos/group/v1/events.js +480 -0
  52. package/lib/codec/cosmos/group/v1/export.d.ts +4 -0
  53. package/lib/codec/cosmos/group/v1/export.js +94 -0
  54. package/lib/codec/cosmos/group/v1/genesis.d.ts +45 -0
  55. package/lib/codec/cosmos/group/v1/genesis.js +176 -0
  56. package/lib/codec/cosmos/group/v1/query.d.ts +412 -0
  57. package/lib/codec/cosmos/group/v1/query.js +1648 -0
  58. package/lib/codec/cosmos/group/v1/tx.d.ts +483 -0
  59. package/lib/codec/cosmos/group/v1/tx.js +1840 -0
  60. package/lib/codec/cosmos/group/v1/types.d.ts +356 -0
  61. package/lib/codec/cosmos/group/v1/types.js +1306 -0
  62. package/lib/codec/cosmos/msg/v1/msg.d.ts +1 -0
  63. package/lib/codec/cosmos/msg/v1/msg.js +14 -0
  64. package/lib/codec/cosmos/nft/v1beta1/event.d.ts +48 -0
  65. package/lib/codec/cosmos/nft/v1beta1/event.js +227 -0
  66. package/lib/codec/cosmos/nft/v1beta1/export.d.ts +5 -0
  67. package/lib/codec/cosmos/nft/v1beta1/export.js +30 -0
  68. package/lib/codec/cosmos/nft/v1beta1/genesis.d.ts +36 -0
  69. package/lib/codec/cosmos/nft/v1beta1/genesis.js +140 -0
  70. package/lib/codec/cosmos/nft/v1beta1/nft.d.ts +53 -0
  71. package/lib/codec/cosmos/nft/v1beta1/nft.js +233 -0
  72. package/lib/codec/cosmos/nft/v1beta1/query.d.ts +206 -0
  73. package/lib/codec/cosmos/nft/v1beta1/query.js +817 -0
  74. package/lib/codec/cosmos/nft/v1beta1/tx.d.ts +49 -0
  75. package/lib/codec/cosmos/nft/v1beta1/tx.js +137 -0
  76. package/lib/codec/cosmos/orm/module/v1alpha1/module.d.ts +22 -0
  77. package/lib/codec/cosmos/orm/module/v1alpha1/module.js +46 -0
  78. package/lib/codec/cosmos/orm/v1/export.d.ts +1 -0
  79. package/lib/codec/cosmos/orm/v1/export.js +8 -0
  80. package/lib/codec/cosmos/orm/v1/orm.d.ts +123 -0
  81. package/lib/codec/cosmos/orm/v1/orm.js +263 -0
  82. package/lib/codec/cosmos/orm/v1alpha1/export.d.ts +1 -0
  83. package/lib/codec/cosmos/orm/v1alpha1/export.js +9 -0
  84. package/lib/codec/cosmos/orm/v1alpha1/schema.d.ts +96 -0
  85. package/lib/codec/cosmos/orm/v1alpha1/schema.js +265 -0
  86. package/lib/codec/cosmos/upgrade/v1beta1/export.d.ts +3 -0
  87. package/lib/codec/cosmos/upgrade/v1beta1/export.js +24 -0
  88. package/lib/codec/cosmos/upgrade/v1beta1/tx.d.ts +97 -0
  89. package/lib/codec/cosmos/upgrade/v1beta1/tx.js +203 -0
  90. package/lib/codec/ibc/applications/fee/v1/ack.d.ts +24 -0
  91. package/lib/codec/ibc/applications/fee/v1/ack.js +125 -0
  92. package/lib/codec/ibc/applications/fee/v1/export.d.ts +6 -0
  93. package/lib/codec/ibc/applications/fee/v1/export.js +47 -0
  94. package/lib/codec/ibc/applications/fee/v1/fee.d.ts +68 -0
  95. package/lib/codec/ibc/applications/fee/v1/fee.js +289 -0
  96. package/lib/codec/ibc/applications/fee/v1/genesis.d.ts +93 -0
  97. package/lib/codec/ibc/applications/fee/v1/genesis.js +390 -0
  98. package/lib/codec/ibc/applications/fee/v1/metadata.d.ts +25 -0
  99. package/lib/codec/ibc/applications/fee/v1/metadata.js +71 -0
  100. package/lib/codec/ibc/applications/fee/v1/query.d.ts +312 -0
  101. package/lib/codec/ibc/applications/fee/v1/query.js +1187 -0
  102. package/lib/codec/ibc/applications/fee/v1/tx.d.ts +171 -0
  103. package/lib/codec/ibc/applications/fee/v1/tx.js +524 -0
  104. package/lib/codec/ibc/applications/interchain_accounts/controller/v1/tx.d.ts +78 -0
  105. package/lib/codec/ibc/applications/interchain_accounts/controller/v1/tx.js +296 -0
  106. package/lib/codec/ibc/applications/interchain_accounts/genesis/v1/genesis.d.ts +80 -0
  107. package/lib/codec/ibc/applications/interchain_accounts/genesis/v1/genesis.js +439 -0
  108. package/lib/hydrogen/transfer.d.ts +5 -5
  109. package/lib/insights/competition.d.ts +1 -0
  110. package/lib/provider/metamask/MetaMask.d.ts +5 -5
  111. package/lib/provider/metamask/MetaMask.js +35 -35
  112. package/lib/util/blockchain.d.ts +9 -0
  113. package/lib/util/blockchain.js +143 -1
  114. package/lib/util/ibc.d.ts +4 -4
  115. package/lib/util/ibc.js +17 -18
  116. package/package.json +1 -1
package/lib/CarbonSDK.js CHANGED
@@ -68,8 +68,8 @@ class CarbonSDK {
68
68
  this.chainId = (_d = (_c = opts.chainId) !== null && _c !== void 0 ? _c : constant_1.CarbonChainIDs[this.network]) !== null && _d !== void 0 ? _d : constant_1.CarbonChainIDs[constant_1.Network.MainNet];
69
69
  this.query = new clients_1.CarbonQueryClient(opts.tmClient);
70
70
  this.insights = new clients_1.InsightsQueryClient(this.networkConfig);
71
- this.hydrogen = new clients_1.HydrogenClient(this.networkConfig);
72
71
  this.token = (_e = opts.token) !== null && _e !== void 0 ? _e : clients_1.TokenClient.instance(this.query, this);
72
+ this.hydrogen = clients_1.HydrogenClient.instance(this.networkConfig, this.token);
73
73
  this.admin = new modules_1.AdminModule(this);
74
74
  this.order = new modules_1.OrderModule(this);
75
75
  this.lp = new modules_1.LiquidityPoolModule(this);
@@ -9,7 +9,7 @@ import TokenClient from "./TokenClient";
9
9
  export interface ETHClientOpts {
10
10
  configProvider: NetworkConfigProvider;
11
11
  tokenClient: TokenClient;
12
- blockchain: Blockchain;
12
+ blockchain: typeof ETHClient.SUPPORTED_BLOCKCHAINS[number];
13
13
  }
14
14
  interface ETHTxParams {
15
15
  gasPriceGwei: BigNumber;
@@ -47,9 +47,9 @@ export interface EthersTransactionResponse extends ethers.Transaction {
47
47
  export declare const FEE_MULTIPLIER: ethers.BigNumber;
48
48
  export declare class ETHClient {
49
49
  readonly configProvider: NetworkConfigProvider;
50
- readonly blockchain: Blockchain;
50
+ readonly blockchain: typeof ETHClient.SUPPORTED_BLOCKCHAINS[number];
51
51
  readonly tokenClient: TokenClient;
52
- static SUPPORTED_BLOCKCHAINS: Blockchain[];
52
+ static SUPPORTED_BLOCKCHAINS: readonly [Blockchain.BinanceSmartChain, Blockchain.Ethereum, Blockchain.Arbitrum, Blockchain.Polygon, Blockchain.Okc];
53
53
  static BLOCKCHAIN_KEY: {
54
54
  bsc: string;
55
55
  eth: string;
@@ -57,9 +57,16 @@ export declare class ETHClient {
57
57
  polygon: string;
58
58
  okc: string;
59
59
  };
60
+ static BLOCKCHAINV2_MAPPING: {
61
+ bsc: string;
62
+ eth: string;
63
+ arbitrum: string;
64
+ polygon: string;
65
+ okc: string;
66
+ };
60
67
  private constructor();
61
68
  static instance(opts: ETHClientOpts): CarbonSDK.ETHClient;
62
- getExternalBalances(api: CarbonSDK, address: string, whitelistDenoms?: string[]): Promise<TokensWithExternalBalance[]>;
69
+ getExternalBalances(api: CarbonSDK, address: string, whitelistDenoms?: string[], version?: string): Promise<TokensWithExternalBalance[]>;
63
70
  approveERC20(params: ApproveERC20Params): Promise<EthersTransactionResponse>;
64
71
  checkAllowanceERC20(token: Models.Token, owner: string, spender: string): Promise<BigNumber>;
65
72
  bridgeTokens(params: BridgeParams): Promise<EthersTransactionResponse>;
@@ -35,15 +35,22 @@ class ETHClient {
35
35
  throw new Error(`unsupported blockchain - ${blockchain}`);
36
36
  return new ETHClient(configProvider, blockchain, tokenClient);
37
37
  }
38
- getExternalBalances(api, address, whitelistDenoms) {
38
+ getExternalBalances(api, address, whitelistDenoms, version = "V1") {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  const tokenQueryResults = yield api.token.getAllTokens();
41
41
  const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
42
- const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain &&
43
- token.tokenAddress.length == 40 &&
44
- token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
45
- (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
46
- this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
42
+ const tokens = tokenQueryResults.filter((token) => {
43
+ const isCorrectBlockchain = version === "V2"
44
+ ?
45
+ this.tokenClient.getBlockchainV2(token.denom) == ETHClient.BLOCKCHAINV2_MAPPING[this.blockchain]
46
+ :
47
+ blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain;
48
+ return isCorrectBlockchain &&
49
+ token.tokenAddress.length == 40 &&
50
+ token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
51
+ (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
52
+ this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
53
+ });
47
54
  const assetIds = tokens.map((token) => {
48
55
  return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
49
56
  });
@@ -358,4 +365,11 @@ ETHClient.BLOCKCHAIN_KEY = {
358
365
  [blockchain_1.Blockchain.Polygon]: "polygon",
359
366
  [blockchain_1.Blockchain.Okc]: "okc",
360
367
  };
368
+ ETHClient.BLOCKCHAINV2_MAPPING = {
369
+ [blockchain_1.Blockchain.BinanceSmartChain]: "Binance Smart Chain",
370
+ [blockchain_1.Blockchain.Ethereum]: "Ethereum",
371
+ [blockchain_1.Blockchain.Arbitrum]: "Arbitrum",
372
+ [blockchain_1.Blockchain.Polygon]: "Polygon",
373
+ [blockchain_1.Blockchain.Okc]: "Okc",
374
+ };
361
375
  exports.default = ETHClient;
@@ -1,6 +1,8 @@
1
1
  import { NetworkConfig } from "../constant";
2
- import { GetDetailedTransfersResponse, GetRelaysRequest, GetRelaysResponse, GetStatsResponse, GetTransfersRequest, GetTransfersResponse } from "../hydrogen";
3
- import { GetFeeQuoteRequest, GetFeeQuoteResponse } from "../hydrogen/feeQuote";
2
+ import { BlockchainUtils } from "../util";
3
+ import { ChainTransaction, CrossChainTransfer, CrossChainTransferDetailed, GetDetailedTransfersResponse, GetRelaysRequest, GetRelaysResponse, GetStatsResponse, GetTransfersRequest, GetTransfersResponse, RelaysResponse } from "../hydrogen";
4
+ import { FeeQuote, GetFeeQuoteRequest, GetFeeQuoteResponse } from "../hydrogen/feeQuote";
5
+ import TokenClient from './TokenClient';
4
6
  export declare const HydrogenEndpoints: {
5
7
  stats: string;
6
8
  transfer_payloads: string;
@@ -10,12 +12,19 @@ export declare const HydrogenEndpoints: {
10
12
  declare class HydrogenClient {
11
13
  private config;
12
14
  private readonly apiManager;
13
- constructor(config: NetworkConfig);
15
+ private readonly tokenClient;
16
+ constructor(config: NetworkConfig, tokenClient: TokenClient);
17
+ static instance(config: NetworkConfig, tokenClient: TokenClient): HydrogenClient;
14
18
  checkState(): void;
19
+ formatCrossChainTransferV2: (value: any) => CrossChainTransfer;
20
+ formatCrossChainTransferDetailedV2: (value: any) => CrossChainTransferDetailed;
21
+ formatRelaysTransfersV2: (value: any) => RelaysResponse;
22
+ formatChainEventV2: (value: any, blockchain: BlockchainUtils.BlockchainV2) => ChainTransaction | null;
23
+ formatFeeQuoteV2: (value: any, blockchain: BlockchainUtils.BlockchainV2) => FeeQuote;
15
24
  getStats(): Promise<GetStatsResponse>;
16
- getTransfers(req: GetTransfersRequest): Promise<GetTransfersResponse>;
17
- getDetailedTransfers(req: GetTransfersRequest): Promise<GetDetailedTransfersResponse>;
18
- getRelaysTransfers(req: GetRelaysRequest): Promise<GetRelaysResponse>;
19
- getFeeQuote(req: GetFeeQuoteRequest): Promise<GetFeeQuoteResponse>;
25
+ getTransfers(req: GetTransfersRequest, version?: string): Promise<GetTransfersResponse>;
26
+ getDetailedTransfers(req: GetTransfersRequest, version?: string): Promise<GetDetailedTransfersResponse>;
27
+ getRelaysTransfers(req: GetRelaysRequest, version?: string): Promise<GetRelaysResponse>;
28
+ getFeeQuote(req: GetFeeQuoteRequest, blockchain?: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2 | undefined, version?: string): Promise<GetFeeQuoteResponse>;
20
29
  }
21
30
  export default HydrogenClient;
@@ -60,10 +60,56 @@ const formatFeeQuote = (value) => {
60
60
  return value;
61
61
  return Object.assign(Object.assign({}, value), { blockchain: util_1.BlockchainUtils.parseBlockchain(value.blockchain), created_at: formatDateField((_a = value.created_at) === null || _a === void 0 ? void 0 : _a.toString()), expires_at: formatDateField((_b = value.expires_at) === null || _b === void 0 ? void 0 : _b.toString()) });
62
62
  };
63
+ const getBridgeBlockchainFromId = (bridgeId) => {
64
+ switch (bridgeId) {
65
+ case 1:
66
+ return 'Polynetwork';
67
+ case 2:
68
+ return 'Ibc';
69
+ default:
70
+ return 'Polynetwork';
71
+ }
72
+ };
63
73
  class HydrogenClient {
64
- constructor(config) {
74
+ constructor(config, tokenClient) {
65
75
  this.config = config;
76
+ this.formatCrossChainTransferV2 = (value) => {
77
+ var _a, _b;
78
+ if (typeof value !== "object")
79
+ return value;
80
+ return Object.assign(Object.assign({}, value), { created_at: formatDateField((_a = value.created_at) === null || _a === void 0 ? void 0 : _a.toString()), updated_at: formatDateField((_b = value.updated_at) === null || _b === void 0 ? void 0 : _b.toString()), source_blockchain: this.tokenClient.getBlockchainV2FromIDs(value.from_chain_id, value.bridge_id), bridging_blockchain: getBridgeBlockchainFromId(value.bridge_id), destination_blockchain: this.tokenClient.getBlockchainV2FromIDs(value.to_chain_id, value.bridge_id) });
81
+ };
82
+ this.formatCrossChainTransferDetailedV2 = (value) => {
83
+ if (!value || typeof value !== "object")
84
+ return value;
85
+ const source_blockchain = this.tokenClient.getBlockchainV2FromIDs(value.from_chain_id, value.bridge_id);
86
+ const destination_blockchain = this.tokenClient.getBlockchainV2FromIDs(value.to_chain_id, value.bridge_id);
87
+ const bridging_blockchain = getBridgeBlockchainFromId(value.bridge_id);
88
+ return Object.assign(Object.assign({}, this.formatCrossChainTransferV2(value)), { source_event: this.formatChainEventV2(value.source_event, source_blockchain !== null && source_blockchain !== void 0 ? source_blockchain : ''), bridging_event: this.formatChainEventV2(value.bridging_event, bridging_blockchain), destination_event: this.formatChainEventV2(value.destination_event, destination_blockchain !== null && destination_blockchain !== void 0 ? destination_blockchain : '') });
89
+ };
90
+ this.formatRelaysTransfersV2 = (value) => {
91
+ var _a, _b;
92
+ if (!value || typeof value !== "object")
93
+ return value;
94
+ return Object.assign(Object.assign({}, value), { created_at: formatDateField((_a = value.created_at) === null || _a === void 0 ? void 0 : _a.toString()), updated_at: formatDateField((_b = value.updated_at) === null || _b === void 0 ? void 0 : _b.toString()), source_blockchain: this.tokenClient.getBlockchainV2FromIDs(value.from_chain_id, value.bridge_id), bridging_blockchain: getBridgeBlockchainFromId(value.bridge_id), destination_blockchain: this.tokenClient.getBlockchainV2FromIDs(value.to_chain_id, value.bridge_id) });
95
+ };
96
+ this.formatChainEventV2 = (value, blockchain) => {
97
+ var _a, _b, _c;
98
+ if (!value || typeof value !== "object")
99
+ return value;
100
+ return Object.assign(Object.assign({}, value), { confirmed_at: formatDateField((_a = value.confirmed_at) === null || _a === void 0 ? void 0 : _a.toString()), created_at: formatDateField((_b = value.created_at) === null || _b === void 0 ? void 0 : _b.toString()), updated_at: formatDateField((_c = value.updated_at) === null || _c === void 0 ? void 0 : _c.toString()), blockchain });
101
+ };
102
+ this.formatFeeQuoteV2 = (value, blockchain) => {
103
+ var _a, _b;
104
+ if (typeof value !== "object")
105
+ return value;
106
+ return Object.assign(Object.assign({}, value), { blockchain, created_at: formatDateField((_a = value.created_at) === null || _a === void 0 ? void 0 : _a.toString()), expires_at: formatDateField((_b = value.expires_at) === null || _b === void 0 ? void 0 : _b.toString()) });
107
+ };
66
108
  this.apiManager = new util_1.APIUtils.APIManager(config.hydrogenUrl, exports.HydrogenEndpoints);
109
+ this.tokenClient = tokenClient;
110
+ }
111
+ static instance(config, tokenClient) {
112
+ return new HydrogenClient(config, tokenClient);
67
113
  }
68
114
  checkState() {
69
115
  var _a;
@@ -82,40 +128,40 @@ class HydrogenClient {
82
128
  return response.data;
83
129
  });
84
130
  }
85
- getTransfers(req) {
131
+ getTransfers(req, version = "V1") {
86
132
  return __awaiter(this, void 0, void 0, function* () {
87
133
  this.checkState();
88
134
  const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: false }));
89
135
  const response = yield request.get();
90
136
  const result = response.data;
91
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransfer) });
137
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatCrossChainTransfer : this.formatCrossChainTransferV2) });
92
138
  });
93
139
  }
94
- getDetailedTransfers(req) {
140
+ getDetailedTransfers(req, version = "V1") {
95
141
  return __awaiter(this, void 0, void 0, function* () {
96
142
  this.checkState();
97
143
  const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
98
144
  const response = yield request.get();
99
145
  const result = response.data;
100
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransferDetailed) });
146
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatCrossChainTransferDetailed : this.formatCrossChainTransferDetailedV2) });
101
147
  });
102
148
  }
103
- getRelaysTransfers(req) {
149
+ getRelaysTransfers(req, version = "V1") {
104
150
  return __awaiter(this, void 0, void 0, function* () {
105
151
  this.checkState();
106
152
  const request = this.apiManager.path("relays", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
107
153
  const response = yield request.get();
108
154
  const result = response.data;
109
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatRelaysTransfers) });
155
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatRelaysTransfers : this.formatRelaysTransfersV2) });
110
156
  });
111
157
  }
112
- getFeeQuote(req) {
158
+ getFeeQuote(req, blockchain = undefined, version = "V1") {
113
159
  return __awaiter(this, void 0, void 0, function* () {
114
160
  this.checkState();
115
161
  const request = this.apiManager.path("fee_quote", {}, Object.assign({}, req));
116
162
  const response = yield request.get();
117
163
  const result = response.data;
118
- return formatFeeQuote(result);
164
+ return version === "V1" ? formatFeeQuote(result) : this.formatFeeQuoteV2(result, blockchain);
119
165
  });
120
166
  }
121
167
  }
@@ -36,7 +36,7 @@ export declare class NEOClient {
36
36
  private constructor();
37
37
  static instance(opts: NEOClientOpts): CarbonSDK.NEOClient;
38
38
  static parseHexNum(hex: string, exp?: number): string;
39
- getExternalBalances(sdk: CarbonSDK, address: string, url: string, whitelistDenoms?: string[]): Promise<TokensWithExternalBalance[]>;
39
+ getExternalBalances(sdk: CarbonSDK, address: string, url: string, whitelistDenoms?: string[], version?: string): Promise<TokensWithExternalBalance[]>;
40
40
  lockDeposit(token: TokensWithExternalBalance, feeAmountInput: string, swthAddress: string, neoPrivateKey: string): Promise<false | import("@cityofzion/neon-api/lib/funcs/types").DoInvokeConfig>;
41
41
  lockO3Deposit(params: LockO3DepositParams): Promise<any>;
42
42
  lockLedgerDeposit(params: LockLedgerDepositParams): Promise<any>;
@@ -60,13 +60,18 @@ class NEOClient {
60
60
  const res = hex.length % 2 !== 0 ? `0${hex}` : hex;
61
61
  return new bignumber_js_1.default(res ? Neon.u.reverseHex(res) : "00", 16).shiftedBy(-exp).toString();
62
62
  }
63
- getExternalBalances(sdk, address, url, whitelistDenoms) {
63
+ getExternalBalances(sdk, address, url, whitelistDenoms, version = "V1") {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  const tokenQueryResults = yield sdk.token.getAllTokens();
66
66
  const account = new Neon.wallet.Account(address);
67
- const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain &&
68
- token.tokenAddress.length == 40 &&
69
- token.bridgeAddress.length == 40);
67
+ const tokens = tokenQueryResults.filter((token) => {
68
+ const isCorrectBlockchain = version === "V2"
69
+ ?
70
+ sdk.token.getBlockchainV2(token.denom) == this.blockchain
71
+ :
72
+ blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
73
+ return isCorrectBlockchain && token.tokenAddress.length == 40 && token.bridgeAddress.length == 40;
74
+ });
70
75
  const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
71
76
  // NOTE: fetching of tokens is chunked in sets of 15 as we may hit
72
77
  // the gas limit on the RPC node and error out otherwise
@@ -1,9 +1,10 @@
1
- import { Token, TokenPrice } from "../codec";
1
+ import { Bridge, Token, TokenPrice } from "../codec";
2
2
  import { NetworkConfigProvider } from "../constant";
3
3
  import { FeeQuote } from "../hydrogen/feeQuote";
4
4
  import { BlockchainUtils, TypeUtils } from "../util";
5
5
  import BigNumber from "bignumber.js";
6
6
  import CarbonQueryClient from "./CarbonQueryClient";
7
+ import { BlockchainV2, BridgeMap } from '../util/blockchain';
7
8
  declare class TokenClient {
8
9
  readonly query: CarbonQueryClient;
9
10
  readonly configProvider: NetworkConfigProvider;
@@ -12,6 +13,7 @@ declare class TokenClient {
12
13
  readonly wrapperMap: TypeUtils.SimpleMap<string>;
13
14
  readonly poolTokens: TypeUtils.SimpleMap<Token>;
14
15
  readonly cdpTokens: TypeUtils.SimpleMap<Token>;
16
+ readonly bridges: BridgeMap;
15
17
  readonly symbols: TypeUtils.SimpleMap<string>;
16
18
  readonly usdValues: TypeUtils.SimpleMap<BigNumber>;
17
19
  readonly commonAssetNames: TypeUtils.SimpleMap<string>;
@@ -23,7 +25,8 @@ declare class TokenClient {
23
25
  registerGeckoIdMap(map: TypeUtils.SimpleMap<string>): void;
24
26
  getCommonDenom(denom: string): string;
25
27
  getDecimals(denom: string): number | undefined;
26
- getBlockchain(denom: string): BlockchainUtils.Blockchain | undefined;
28
+ getBlockchain(denom: string): BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2 | undefined;
29
+ getBlockchainV2(denom: string | undefined): BlockchainUtils.BlockchainV2 | undefined;
27
30
  getSymbol(denom: string): string;
28
31
  getUSDValue(denom: string): BigNumber | undefined;
29
32
  toHuman(denom: string, unitlessAmt: BigNumber): BigNumber;
@@ -42,15 +45,25 @@ declare class TokenClient {
42
45
  isWrappedToken(denom?: string): boolean;
43
46
  hasWrappedToken(denom?: string): boolean;
44
47
  getWrappedTokens(denom: string): Token[];
45
- getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain): Token | null;
48
+ getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | null;
46
49
  getSourceToken(denom: string): Token | null;
47
50
  getNativeToken(): Token | undefined;
48
51
  getNativeStablecoin(): Token | undefined;
49
52
  isNativeToken(denom: string): boolean;
50
53
  isNativeStablecoin(denom: string): boolean;
51
- getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain): Token | undefined;
54
+ isGroupedToken(denom: string): boolean;
55
+ getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | undefined;
52
56
  getAllTokens(): Promise<Token[]>;
53
57
  reloadTokens(): Promise<TypeUtils.SimpleMap<Token>>;
58
+ getBridges(): Promise<BridgeMap>;
59
+ getIbcBlockchainNames(): string[];
60
+ getPolynetworkBlockchainNames(): string[];
61
+ getAllBlockchainNames(): string[];
62
+ getBridgesFromBridgeId(bridgeId: number): Bridge[];
63
+ getIbcTokens(): TypeUtils.SimpleMap<Token>;
64
+ getPolyNetworkTokens(): TypeUtils.SimpleMap<Token>;
65
+ getBlockchainV2FromIDs(chainId: string, bridgeId: string): BlockchainV2 | undefined;
66
+ getBridgeFromToken(token: Token): Bridge | undefined;
54
67
  getCarbonIbcTokens(): Token[];
55
68
  getCdpUnderlyingToken(cdpDenom: string): Token | undefined;
56
69
  reloadWrapperMap(): Promise<TypeUtils.SimpleMap<string>>;
@@ -20,6 +20,7 @@ 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");
23
24
  const SYMBOL_OVERRIDE = {
24
25
  swth: "SWTH",
25
26
  NNEO: "nNEO",
@@ -43,6 +44,7 @@ class TokenClient {
43
44
  this.wrapperMap = {};
44
45
  this.poolTokens = {};
45
46
  this.cdpTokens = {};
47
+ this.bridges = { polynetwork: [], ibc: [] };
46
48
  this.symbols = {};
47
49
  this.usdValues = {};
48
50
  this.commonAssetNames = constant_1.CommonAssetName;
@@ -58,6 +60,7 @@ class TokenClient {
58
60
  yield this.reloadWrapperMap();
59
61
  yield this.reloadTokens();
60
62
  yield this.reloadDenomGeckoMap();
63
+ yield this.getBridges();
61
64
  // non-blocking reload
62
65
  try {
63
66
  this.reloadUSDValues();
@@ -95,6 +98,18 @@ class TokenClient {
95
98
  const blockchain = util_1.BlockchainUtils.blockchainForChainId(chainId, networkConfig.network);
96
99
  return blockchain;
97
100
  }
101
+ getBlockchainV2(denom) {
102
+ if (!denom)
103
+ return undefined;
104
+ let token = this.tokens[denom];
105
+ if (this.isNativeToken(denom) || this.isNativeStablecoin(denom) || TokenClient.isPoolToken(denom) || TokenClient.isCdpToken(denom) || this.isGroupedToken(denom)) {
106
+ // native denoms "swth" and "usc" should be native.
107
+ // pool and cdp tokens are on the Native blockchain, hence 0
108
+ return 'Native';
109
+ }
110
+ const bridge = this.getBridgeFromToken(token);
111
+ return bridge === null || bridge === void 0 ? void 0 : bridge.chainName;
112
+ }
98
113
  getSymbol(denom) {
99
114
  var _a, _b;
100
115
  if (TokenClient.isCdpToken(denom)) {
@@ -229,7 +244,7 @@ class TokenClient {
229
244
  }
230
245
  return result;
231
246
  }
232
- getWrappedToken(denom, blockchain) {
247
+ getWrappedToken(denom, blockchain, version = 'V1') {
233
248
  const networkConfig = this.configProvider.getConfig();
234
249
  // if denom is already a wrapped denom or no blockchain was specified,
235
250
  // just return the input denom.
@@ -245,9 +260,15 @@ class TokenClient {
245
260
  }
246
261
  // check if wrapped denom is of correct blockchain
247
262
  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];
263
+ let tokenChain = '';
264
+ if (version === "V1") {
265
+ tokenChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber());
266
+ if (TokenClient.isIBCDenom(token.denom)) {
267
+ tokenChain = util_1.IBCUtils.BlockchainMap[wrappedDenom];
268
+ }
269
+ }
270
+ else {
271
+ tokenChain = this.getBlockchainV2(token.denom);
251
272
  }
252
273
  if (!tokenChain) {
253
274
  continue; // unknown chain! just ignore this source token
@@ -283,17 +304,27 @@ class TokenClient {
283
304
  isNativeStablecoin(denom) {
284
305
  return denom === "usc";
285
306
  }
286
- getDepositTokenFor(tokenDenom, chain) {
307
+ isGroupedToken(denom) {
308
+ const groupedTokenRegex = new RegExp(/^cgt\/\d+$/);
309
+ return groupedTokenRegex.test(denom);
310
+ }
311
+ getDepositTokenFor(tokenDenom, chain, version = "V1") {
287
312
  const networkConfig = this.configProvider.getConfig();
288
313
  const token = this.tokenForDenom(tokenDenom);
289
314
  if (!token) {
290
315
  console.error("getDepositTokenFor token not found for", tokenDenom);
291
316
  return;
292
317
  }
318
+ let targetChain = "";
293
319
  // 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];
320
+ if (version === "V1") {
321
+ targetChain = util_1.BlockchainUtils.blockchainForChainId(token.chainId.toNumber(), networkConfig.network);
322
+ if (TokenClient.isIBCDenom(token.denom)) {
323
+ targetChain = util_1.IBCUtils.BlockchainMap[token.denom];
324
+ }
325
+ }
326
+ else {
327
+ targetChain = this.getBlockchainV2(token.denom);
297
328
  }
298
329
  const isSourceToken = targetChain === chain && token.denom !== "swth";
299
330
  // if not source token find wrapped token for chain
@@ -363,6 +394,88 @@ class TokenClient {
363
394
  return this.tokens;
364
395
  });
365
396
  }
397
+ getBridges() {
398
+ return __awaiter(this, void 0, void 0, function* () {
399
+ const allBridges = yield this.query.coin.BridgeAll({
400
+ pagination: {
401
+ key: new Uint8Array(),
402
+ limit: new long_1.default(10000),
403
+ offset: long_1.default.UZERO,
404
+ countTotal: true,
405
+ reverse: false,
406
+ },
407
+ });
408
+ const ibcBridges = allBridges.bridges.filter(bridge => {
409
+ if (!bridge.enabled)
410
+ return;
411
+ return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc;
412
+ });
413
+ const polynetworkBridges = allBridges.bridges.filter(bridge => {
414
+ if (!bridge.enabled)
415
+ return;
416
+ return bridge.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork;
417
+ });
418
+ Object.assign(this.bridges, {
419
+ polynetwork: polynetworkBridges,
420
+ ibc: ibcBridges
421
+ });
422
+ return this.bridges;
423
+ });
424
+ }
425
+ getIbcBlockchainNames() {
426
+ return this.bridges.ibc.map(bridge => bridge.chainName);
427
+ }
428
+ getPolynetworkBlockchainNames() {
429
+ return this.bridges.polynetwork.map(bridge => bridge.chainName);
430
+ }
431
+ getAllBlockchainNames() {
432
+ return this.getIbcBlockchainNames().concat(this.getPolynetworkBlockchainNames());
433
+ }
434
+ getBridgesFromBridgeId(bridgeId) {
435
+ switch (bridgeId) {
436
+ case blockchain_1.BRIDGE_IDS.polynetwork:
437
+ return this.bridges.polynetwork;
438
+ case blockchain_1.BRIDGE_IDS.ibc:
439
+ return this.bridges.ibc;
440
+ default:
441
+ return this.bridges.polynetwork;
442
+ }
443
+ }
444
+ getIbcTokens() {
445
+ const ibcTokens = Object.values(this.tokens).reduce((prev, token) => {
446
+ const newPrev = prev;
447
+ if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.ibc) {
448
+ newPrev[token.denom] = token;
449
+ }
450
+ return newPrev;
451
+ }, {});
452
+ return ibcTokens;
453
+ }
454
+ getPolyNetworkTokens() {
455
+ const polynetworkTokens = Object.values(this.tokens).reduce((prev, token) => {
456
+ const newPrev = prev;
457
+ if (token.bridgeId.toNumber() === blockchain_1.BRIDGE_IDS.polynetwork) {
458
+ newPrev[token.denom] = token;
459
+ }
460
+ return newPrev;
461
+ }, {});
462
+ return polynetworkTokens;
463
+ }
464
+ getBlockchainV2FromIDs(chainId, bridgeId) {
465
+ var _a, _b;
466
+ const chainIdNum = Number(chainId);
467
+ const bridgeIdNum = Number(bridgeId);
468
+ if ((chainIdNum === 5 && bridgeIdNum === 1) || (chainIdNum === 0 && bridgeIdNum === 2))
469
+ return "Carbon";
470
+ const bridgeList = this.getBridgesFromBridgeId(bridgeIdNum);
471
+ return (_b = (_a = bridgeList.find(bridge => bridge.chainId.toNumber() === chainIdNum)) === null || _a === void 0 ? void 0 : _a.chainName) !== null && _b !== void 0 ? _b : undefined;
472
+ }
473
+ getBridgeFromToken(token) {
474
+ if (!token.bridgeId)
475
+ return undefined;
476
+ const bridgeList = this.getBridgesFromBridgeId(token.bridgeId.toNumber());
477
+ return bridgeList.find(bridge => token.chainId.equals(bridge.chainId));
478
+ }
366
479
  getCarbonIbcTokens() {
367
480
  const swthTokens = ibc_1.swthIbcWhitelist.map((chainId) => {
368
481
  var _a, _b, _c;
@@ -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,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) => 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
+ 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));
@@ -0,0 +1,18 @@
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal";
3
+ export declare const protobufPackage = "cosmos.app.module.v1alpha1";
4
+ /** Module is the module config object for the cosmos.app v1 app module. */
5
+ export interface Module {
6
+ }
7
+ export declare const Module: {
8
+ encode(_: Module, writer?: _m0.Writer): _m0.Writer;
9
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): Module;
10
+ fromJSON(_: any): Module;
11
+ toJSON(_: Module): unknown;
12
+ fromPartial(_: DeepPartial<Module>): Module;
13
+ };
14
+ declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
15
+ 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 {} ? {
16
+ [K in keyof T]?: DeepPartial<T[K]>;
17
+ } : Partial<T>;
18
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Module = 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 = "cosmos.app.module.v1alpha1";
11
+ const baseModule = {};
12
+ exports.Module = {
13
+ encode(_, writer = minimal_1.default.Writer.create()) {
14
+ return writer;
15
+ },
16
+ decode(input, length) {
17
+ const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
18
+ let end = length === undefined ? reader.len : reader.pos + length;
19
+ const message = Object.assign({}, baseModule);
20
+ while (reader.pos < end) {
21
+ const tag = reader.uint32();
22
+ switch (tag >>> 3) {
23
+ default:
24
+ reader.skipType(tag & 7);
25
+ break;
26
+ }
27
+ }
28
+ return message;
29
+ },
30
+ fromJSON(_) {
31
+ const message = Object.assign({}, baseModule);
32
+ return message;
33
+ },
34
+ toJSON(_) {
35
+ const obj = {};
36
+ return obj;
37
+ },
38
+ fromPartial(_) {
39
+ const message = Object.assign({}, baseModule);
40
+ return message;
41
+ },
42
+ };
43
+ if (minimal_1.default.util.Long !== long_1.default) {
44
+ minimal_1.default.util.Long = long_1.default;
45
+ minimal_1.default.configure();
46
+ }