carbon-js-sdk 0.4.4 → 0.4.6-beta.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 (105) hide show
  1. package/lib/CarbonSDK.js +1 -1
  2. package/lib/clients/CarbonQueryClient.js +2 -2
  3. package/lib/clients/ETHClient.d.ts +11 -4
  4. package/lib/clients/ETHClient.js +32 -18
  5. package/lib/clients/HydrogenClient.d.ts +16 -7
  6. package/lib/clients/HydrogenClient.js +56 -10
  7. package/lib/clients/InsightsQueryClient.d.ts +1 -0
  8. package/lib/clients/InsightsQueryClient.js +8 -0
  9. package/lib/clients/NEOClient.d.ts +1 -1
  10. package/lib/clients/NEOClient.js +15 -10
  11. package/lib/clients/TokenClient.d.ts +29 -5
  12. package/lib/clients/TokenClient.js +268 -55
  13. package/lib/clients/ZILClient.d.ts +1 -1
  14. package/lib/clients/ZILClient.js +25 -20
  15. package/lib/codec/cdp/e_mode_category.d.ts +23 -0
  16. package/lib/codec/cdp/e_mode_category.js +135 -0
  17. package/lib/codec/cosmos/gov/v1/query.js +2 -2
  18. package/lib/codec/cosmos/gov/v1/tx.js +2 -2
  19. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  20. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  21. package/lib/codec/cosmos/group/v1/events.js +2 -2
  22. package/lib/codec/cosmos/group/v1/tx.js +4 -4
  23. package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
  24. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.d.ts +1 -0
  25. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.js +6 -0
  26. package/lib/codec/ethermint/evm/v1/export.d.ts +5 -0
  27. package/lib/codec/ethermint/evm/v1/export.js +53 -0
  28. package/lib/codec/ethermint/feemarket/v1/export.d.ts +4 -0
  29. package/lib/codec/ethermint/feemarket/v1/export.js +18 -0
  30. package/lib/codec/ethermint/types/v1/export.d.ts +4 -0
  31. package/lib/codec/ethermint/types/v1/export.js +11 -0
  32. package/lib/codec/ethermint-models.d.ts +4 -0
  33. package/lib/codec/ethermint-models.js +26 -0
  34. package/lib/codec/index.d.ts +2 -2
  35. package/lib/codec/index.js +2 -2
  36. package/lib/constant/eip712.d.ts +28 -0
  37. package/lib/constant/eip712.js +40 -0
  38. package/lib/constant/generic.js +1 -1
  39. package/lib/constant/ibc.d.ts +7 -0
  40. package/lib/constant/ibc.js +4 -1
  41. package/lib/constant/network.d.ts +2 -0
  42. package/lib/constant/network.js +5 -1
  43. package/lib/hydrogen/transfer.d.ts +5 -5
  44. package/lib/insights/common.d.ts +1 -0
  45. package/lib/insights/common.js +1 -0
  46. package/lib/insights/competition.d.ts +20 -0
  47. package/lib/modules/cdp.js +43 -43
  48. package/lib/modules/cosmwasm.js +1 -1
  49. package/lib/modules/evm.d.ts +46 -0
  50. package/lib/modules/evm.js +127 -0
  51. package/lib/modules/evmmerge.d.ts +12 -0
  52. package/lib/modules/evmmerge.js +35 -0
  53. package/lib/modules/feemarket.d.ts +20 -0
  54. package/lib/modules/feemarket.js +45 -0
  55. package/lib/modules/gov.js +12 -12
  56. package/lib/modules/ibc.d.ts +5 -1
  57. package/lib/modules/ibc.js +78 -0
  58. package/lib/modules/liquiditypool.js +1 -1
  59. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  60. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  61. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  62. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  63. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  64. package/lib/provider/amino/types/admin.js +27 -27
  65. package/lib/provider/amino/types/bank.js +1 -1
  66. package/lib/provider/amino/types/broker.js +1 -1
  67. package/lib/provider/amino/types/cdp.js +22 -22
  68. package/lib/provider/amino/types/coin.js +4 -4
  69. package/lib/provider/amino/types/gov.js +4 -4
  70. package/lib/provider/amino/types/ibc.js +1 -1
  71. package/lib/provider/amino/types/leverage.js +1 -1
  72. package/lib/provider/amino/types/liquidityPool.js +7 -7
  73. package/lib/provider/amino/types/market.js +1 -1
  74. package/lib/provider/amino/types/oracle.js +1 -1
  75. package/lib/provider/amino/types/order.js +4 -4
  76. package/lib/provider/amino/types/position.js +1 -1
  77. package/lib/provider/amino/types/profile.js +1 -1
  78. package/lib/provider/amino/types/staking.js +4 -4
  79. package/lib/provider/amino/types/subaccount.js +3 -3
  80. package/lib/provider/amino/utils.js +11 -11
  81. package/lib/provider/keplr/KeplrStore.d.ts +1 -1
  82. package/lib/provider/keplr/KeplrStore.js +2 -5
  83. package/lib/provider/ledger/ledger.js +2 -2
  84. package/lib/provider/metamask/MetaMask.d.ts +5 -5
  85. package/lib/provider/metamask/MetaMask.js +37 -37
  86. package/lib/provider/o3/O3Wallet.js +2 -2
  87. package/lib/util/address.js +13 -13
  88. package/lib/util/api.js +4 -4
  89. package/lib/util/blockchain.d.ts +26 -0
  90. package/lib/util/blockchain.js +160 -1
  91. package/lib/util/eip712.d.ts +10 -0
  92. package/lib/util/eip712.js +46 -0
  93. package/lib/util/ethermint.d.ts +4 -0
  94. package/lib/util/ethermint.js +26 -0
  95. package/lib/util/fetch.js +1 -1
  96. package/lib/util/generic.js +3 -3
  97. package/lib/util/ibc.d.ts +5 -3
  98. package/lib/util/ibc.js +26 -1
  99. package/lib/util/number.js +5 -5
  100. package/lib/util/tx.d.ts +2 -2
  101. package/lib/wallet/CarbonSigner.js +2 -2
  102. package/lib/wallet/CarbonSigningClient.js +8 -8
  103. package/lib/wallet/CarbonWallet.js +6 -6
  104. package/lib/websocket/connector.js +3 -3
  105. 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);
@@ -47,7 +47,7 @@ class CarbonQueryClient {
47
47
  constructor(tmClient) {
48
48
  this.tmClient = tmClient;
49
49
  this.baseClient = new stargate_1.QueryClient(this.tmClient);
50
- const rpcClient = (0, stargate_1.createProtobufRpcClient)(this.baseClient);
50
+ const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
51
51
  this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
52
52
  this.adl = new query_1.QueryClientImpl(rpcClient);
53
53
  this.book = new query_2.QueryClientImpl(rpcClient);
@@ -91,7 +91,7 @@ class CarbonQueryClient {
91
91
  };
92
92
  }
93
93
  getProtobufRpcClient() {
94
- return (0, stargate_1.createProtobufRpcClient)(this.baseClient);
94
+ return stargate_1.createProtobufRpcClient(this.baseClient);
95
95
  }
96
96
  }
97
97
  exports.default = CarbonQueryClient;
@@ -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,17 +35,24 @@ 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) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), api.network) == this.blockchain &&
43
- token.tokenAddress.length == 40 &&
44
- token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
45
- (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
46
- this.verifyChecksum((0, 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
- return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
55
+ return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
49
56
  });
50
57
  const provider = this.getProvider();
51
58
  const contractAddress = this.getBalanceReaderAddress();
@@ -96,14 +103,14 @@ class ETHClient {
96
103
  }
97
104
  const carbonNetwork = networkConfig.network;
98
105
  const fromTokenId = fromToken.id;
99
- const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
106
+ const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
100
107
  const toTokenDenom = toToken.denom;
101
108
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
102
109
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
103
110
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
104
111
  const nonce = yield rpcProvider.getTransactionCount(fromAddress);
105
112
  const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
106
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
113
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
107
114
  const tokenCreator = fromToken.creator;
108
115
  const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
109
116
  const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
@@ -138,9 +145,9 @@ class ETHClient {
138
145
  throw new Error("Minimum gas required: 150,000");
139
146
  }
140
147
  const networkConfig = this.getNetworkConfig();
141
- const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
142
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
143
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
148
+ const assetId = generic_1.appendHexPrefix(token.tokenAddress);
149
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
150
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
144
151
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
145
152
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
146
153
  const contractAddress = this.getLockProxyAddress();
@@ -191,16 +198,16 @@ class ETHClient {
191
198
  return "insufficient balance";
192
199
  }
193
200
  const networkConfig = this.getNetworkConfig();
194
- const assetId = (0, generic_1.appendHexPrefix)(tokenWithExternalBalances.tokenAddress);
195
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(tokenWithExternalBalances));
196
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
201
+ const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
202
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
203
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
197
204
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
198
205
  const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
199
206
  const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
200
207
  // logger("sendDeposit message", message)
201
208
  let signatureResult;
202
209
  const { address, signature } = yield getSignatureCallback(message);
203
- const signatureBytes = ethers_1.ethers.utils.arrayify((0, generic_1.appendHexPrefix)(signature));
210
+ const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
204
211
  const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
205
212
  // logger("sign result", address, signature)
206
213
  signatureResult = {
@@ -239,7 +246,7 @@ class ETHClient {
239
246
  if (!feeInfo.deposit_fee) {
240
247
  throw new Error("unsupported token");
241
248
  }
242
- if ((0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
249
+ if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
243
250
  throw new Error("unsupported token");
244
251
  }
245
252
  let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
@@ -305,7 +312,7 @@ class ETHClient {
305
312
  getTargetProxyHash(token) {
306
313
  const networkConfig = this.getNetworkConfig();
307
314
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
308
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
315
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
309
316
  return addressHex;
310
317
  }
311
318
  getProvider() {
@@ -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;
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
29
29
  const formatDateField = (value) => {
30
30
  if (typeof value !== "string")
31
31
  return null;
32
- return (0, dayjs_1.default)(value);
32
+ return dayjs_1.default(value);
33
33
  };
34
34
  // temporary function to parse okt/okc blockchain
35
35
  // to remove when automatic deposit/withdraw feature is deployed
@@ -67,10 +67,56 @@ const formatFeeQuote = (value) => {
67
67
  return value;
68
68
  return Object.assign(Object.assign({}, value), { blockchain: parseHydrogenBlockchain(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()) });
69
69
  };
70
+ const getBridgeBlockchainFromId = (bridgeId) => {
71
+ switch (bridgeId) {
72
+ case 1:
73
+ return 'Polynetwork';
74
+ case 2:
75
+ return 'Ibc';
76
+ default:
77
+ return 'Polynetwork';
78
+ }
79
+ };
70
80
  class HydrogenClient {
71
- constructor(config) {
81
+ constructor(config, tokenClient) {
72
82
  this.config = config;
83
+ this.formatCrossChainTransferV2 = (value) => {
84
+ var _a, _b;
85
+ if (typeof value !== "object")
86
+ return value;
87
+ 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) });
88
+ };
89
+ this.formatCrossChainTransferDetailedV2 = (value) => {
90
+ if (!value || typeof value !== "object")
91
+ return value;
92
+ const source_blockchain = this.tokenClient.getBlockchainV2FromIDs(value.from_chain_id, value.bridge_id);
93
+ const destination_blockchain = this.tokenClient.getBlockchainV2FromIDs(value.to_chain_id, value.bridge_id);
94
+ const bridging_blockchain = getBridgeBlockchainFromId(value.bridge_id);
95
+ 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 : '') });
96
+ };
97
+ this.formatRelaysTransfersV2 = (value) => {
98
+ var _a, _b;
99
+ if (!value || typeof value !== "object")
100
+ return value;
101
+ 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) });
102
+ };
103
+ this.formatChainEventV2 = (value, blockchain) => {
104
+ var _a, _b, _c;
105
+ if (!value || typeof value !== "object")
106
+ return value;
107
+ 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 });
108
+ };
109
+ this.formatFeeQuoteV2 = (value, blockchain) => {
110
+ var _a, _b;
111
+ if (typeof value !== "object")
112
+ return value;
113
+ 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()) });
114
+ };
73
115
  this.apiManager = new util_1.APIUtils.APIManager(config.hydrogenUrl, exports.HydrogenEndpoints);
116
+ this.tokenClient = tokenClient;
117
+ }
118
+ static instance(config, tokenClient) {
119
+ return new HydrogenClient(config, tokenClient);
74
120
  }
75
121
  checkState() {
76
122
  var _a;
@@ -89,40 +135,40 @@ class HydrogenClient {
89
135
  return response.data;
90
136
  });
91
137
  }
92
- getTransfers(req) {
138
+ getTransfers(req, version = "V1") {
93
139
  return __awaiter(this, void 0, void 0, function* () {
94
140
  this.checkState();
95
141
  const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: false }));
96
142
  const response = yield request.get();
97
143
  const result = response.data;
98
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransfer) });
144
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatCrossChainTransfer : this.formatCrossChainTransferV2) });
99
145
  });
100
146
  }
101
- getDetailedTransfers(req) {
147
+ getDetailedTransfers(req, version = "V1") {
102
148
  return __awaiter(this, void 0, void 0, function* () {
103
149
  this.checkState();
104
150
  const request = this.apiManager.path("transfer_payloads", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
105
151
  const response = yield request.get();
106
152
  const result = response.data;
107
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatCrossChainTransferDetailed) });
153
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatCrossChainTransferDetailed : this.formatCrossChainTransferDetailedV2) });
108
154
  });
109
155
  }
110
- getRelaysTransfers(req) {
156
+ getRelaysTransfers(req, version = "V1") {
111
157
  return __awaiter(this, void 0, void 0, function* () {
112
158
  this.checkState();
113
159
  const request = this.apiManager.path("relays", {}, Object.assign(Object.assign({}, req), { include_tx: true }));
114
160
  const response = yield request.get();
115
161
  const result = response.data;
116
- return Object.assign(Object.assign({}, result), { data: result.data.map(formatRelaysTransfers) });
162
+ return Object.assign(Object.assign({}, result), { data: result.data.map(version === "V1" ? formatRelaysTransfers : this.formatRelaysTransfersV2) });
117
163
  });
118
164
  }
119
- getFeeQuote(req) {
165
+ getFeeQuote(req, blockchain = undefined, version = "V1") {
120
166
  return __awaiter(this, void 0, void 0, function* () {
121
167
  this.checkState();
122
168
  const request = this.apiManager.path("fee_quote", {}, Object.assign({}, req));
123
169
  const response = yield request.get();
124
170
  const result = response.data;
125
- return formatFeeQuote(result);
171
+ return version === "V1" ? formatFeeQuote(result) : this.formatFeeQuoteV2(result, blockchain);
126
172
  });
127
173
  }
128
174
  }
@@ -19,6 +19,7 @@ declare class InsightsQueryClient {
19
19
  CompetitionList(req?: Insights.QueryGetCompetitionListRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetCompetitionListResponse>>;
20
20
  VolumeCompetitionLeaderboard(req: Insights.QueryGetVolumeCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetVolumeCompetitionLeaderboardResponse>>;
21
21
  PNLCompetitionLeaderboard(req: Insights.QueryGetPNLCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPNLCompetitionLeaderboardResponse>>;
22
+ LotteryCompetitionLeaderboard(req: Insights.QueryGetLotteryCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetLotteryCompetitionLeaderboardResponse>>;
22
23
  PoolsLiquidity(req?: Insights.QueryGetPoolsLiquidityRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolsLiquidityResponse>>;
23
24
  MarketsVolume(req?: Insights.QueryGetMarketVolumeRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetMarketVolumeResponse>>;
24
25
  Nodes(req?: Insights.QueryGetNodesRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetNodesResponse>>;
@@ -158,6 +158,14 @@ class InsightsQueryClient {
158
158
  return response.data;
159
159
  });
160
160
  }
161
+ LotteryCompetitionLeaderboard(req) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const queryParams = Object.assign({ competitionId: req.competitionId }, (req.market && { market: req.market }));
164
+ const request = this.apiManager.path("competition/leaderboardlottery", {}, queryParams);
165
+ const response = yield request.get();
166
+ return response.data;
167
+ });
168
+ }
161
169
  PoolsLiquidity(req = {}) {
162
170
  return __awaiter(this, void 0, void 0, function* () {
163
171
  const queryParams = {
@@ -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,17 +60,22 @@ 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) => (0, 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) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[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
73
- const promises = (0, lodash_1.chunk)(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
78
+ const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
74
79
  var _a, _b, _c;
75
80
  let acc = {};
76
81
  for (const token of partition) {
@@ -112,8 +117,8 @@ class NEOClient {
112
117
  const targetProxyHash = this.getTargetProxyHash(token);
113
118
  const toAssetHash = Neon.u.str2hexstring(token.id);
114
119
  const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
115
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
116
- const zeroAddressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
120
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
121
+ const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
117
122
  const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
118
123
  const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
119
124
  const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
@@ -160,7 +165,7 @@ class NEOClient {
160
165
  const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
161
166
  const targetProxyHash = this.getTargetProxyHash(token);
162
167
  const toAssetHash = Neon.u.str2hexstring(token.id);
163
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
168
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
164
169
  const nonce = Math.floor(Math.random() * 1000000);
165
170
  if (amount.lt(feeAmount)) {
166
171
  throw new Error("Invalid amount");
@@ -196,7 +201,7 @@ class NEOClient {
196
201
  const fromAddress = ledger.scriptHash;
197
202
  const targetProxyHash = this.getTargetProxyHash(token);
198
203
  const toAssetHash = Neon.u.str2hexstring(token.id);
199
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
204
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
200
205
  const feeAddress = networkConfig.feeAddress;
201
206
  const nonce = Math.floor(Math.random() * 1000000);
202
207
  if (amount.lt(feeAmount)) {
@@ -316,7 +321,7 @@ class NEOClient {
316
321
  getTargetProxyHash(token) {
317
322
  const networkConfig = this.getNetworkConfig();
318
323
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
319
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
324
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
320
325
  return addressHex;
321
326
  }
322
327
  getNetworkConfig() {
@@ -1,9 +1,14 @@
1
- import { Token, TokenPrice } from "../codec";
1
+ import { Bridge, Token, TokenPrice } from "../codec";
2
+ import { DenomTrace } from "../codec/ibc/applications/transfer/v1/transfer";
2
3
  import { NetworkConfigProvider } from "../constant";
3
4
  import { FeeQuote } from "../hydrogen/feeQuote";
4
5
  import { BlockchainUtils, TypeUtils } from "../util";
6
+ import { BlockchainV2, BridgeMap, IbcBridge } from '../util/blockchain';
5
7
  import BigNumber from "bignumber.js";
6
8
  import CarbonQueryClient from "./CarbonQueryClient";
9
+ export interface DenomTraceExtended extends DenomTrace {
10
+ token?: Token;
11
+ }
7
12
  declare class TokenClient {
8
13
  readonly query: CarbonQueryClient;
9
14
  readonly configProvider: NetworkConfigProvider;
@@ -12,10 +17,12 @@ declare class TokenClient {
12
17
  readonly wrapperMap: TypeUtils.SimpleMap<string>;
13
18
  readonly poolTokens: TypeUtils.SimpleMap<Token>;
14
19
  readonly cdpTokens: TypeUtils.SimpleMap<Token>;
20
+ readonly bridges: BridgeMap;
15
21
  readonly symbols: TypeUtils.SimpleMap<string>;
16
22
  readonly usdValues: TypeUtils.SimpleMap<BigNumber>;
17
23
  readonly commonAssetNames: TypeUtils.SimpleMap<string>;
18
24
  readonly geckoTokenNames: TypeUtils.SimpleMap<string>;
25
+ readonly denomTraces: TypeUtils.SimpleMap<DenomTraceExtended>;
19
26
  private additionalGeckoDenoms;
20
27
  private constructor();
21
28
  static instance(query: CarbonQueryClient, configProvider: NetworkConfigProvider): TokenClient;
@@ -23,7 +30,8 @@ declare class TokenClient {
23
30
  registerGeckoIdMap(map: TypeUtils.SimpleMap<string>): void;
24
31
  getCommonDenom(denom: string): string;
25
32
  getDecimals(denom: string): number | undefined;
26
- getBlockchain(denom: string): BlockchainUtils.Blockchain | undefined;
33
+ getBlockchain(denom: string): BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2 | undefined;
34
+ getBlockchainV2(denom: string | undefined): BlockchainUtils.BlockchainV2 | undefined;
27
35
  getSymbol(denom: string): string;
28
36
  getUSDValue(denom: string): BigNumber | undefined;
29
37
  toHuman(denom: string, unitlessAmt: BigNumber): BigNumber;
@@ -42,16 +50,32 @@ declare class TokenClient {
42
50
  isWrappedToken(denom?: string): boolean;
43
51
  hasWrappedToken(denom?: string): boolean;
44
52
  getWrappedTokens(denom: string): Token[];
45
- getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain): Token | null;
53
+ getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | null;
46
54
  getSourceToken(denom: string): Token | null;
47
55
  getNativeToken(): Token | undefined;
48
56
  getNativeStablecoin(): Token | undefined;
49
57
  isNativeToken(denom: string): boolean;
50
58
  isNativeStablecoin(denom: string): boolean;
51
- getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain): Token | undefined;
59
+ isGroupedToken(denom: string): boolean;
60
+ isCarbonToken(token?: Token | null): boolean;
61
+ getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | undefined;
52
62
  getAllTokens(): Promise<Token[]>;
53
63
  reloadTokens(): Promise<TypeUtils.SimpleMap<Token>>;
54
- getCarbonIbcTokens(): Token[];
64
+ reloadDenomTraces(): Promise<TypeUtils.SimpleMap<DenomTraceExtended>>;
65
+ getDenomTraceData(denom: string): DenomTrace | undefined;
66
+ getBridges(): Promise<BridgeMap>;
67
+ matchChainsWithDifferentChainIds(bridges: Bridge[]): Promise<IbcBridge[]>;
68
+ getIbcBlockchainNames(): string[];
69
+ getIbcChainFromBlockchainV2: (blockchain: BlockchainV2 | undefined) => string | undefined;
70
+ getPolynetworkBlockchainNames(): string[];
71
+ getAllBlockchainNames(): string[];
72
+ getBridgesFromBridgeId(bridgeId: number): Bridge[] | IbcBridge[];
73
+ getIbcTokens(): TypeUtils.SimpleMap<Token>;
74
+ getPolyNetworkTokens(): TypeUtils.SimpleMap<Token>;
75
+ getBlockchainV2FromIDs(chainId: string, bridgeId: string): BlockchainV2 | undefined;
76
+ getBridgeFromToken(token: Token | null): Bridge | IbcBridge | undefined;
77
+ getIbcChainIdFromToken(token: Token | null): string | undefined;
78
+ getCarbonDenomTraces(): Promise<TypeUtils.SimpleMap<DenomTrace>>;
55
79
  getCdpUnderlyingToken(cdpDenom: string): Token | undefined;
56
80
  reloadWrapperMap(): Promise<TypeUtils.SimpleMap<string>>;
57
81
  reloadDenomGeckoMap(): Promise<void>;