carbon-js-sdk 0.6.9 → 0.6.10-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 (114) hide show
  1. package/lib/CarbonSDK.d.ts +6 -3
  2. package/lib/CarbonSDK.js +8 -5
  3. package/lib/clients/BatchQueryClient.js +4 -4
  4. package/lib/clients/CarbonQueryClient.d.ts +4 -0
  5. package/lib/clients/CarbonQueryClient.js +5 -1
  6. package/lib/clients/ETHClient.d.ts +8 -8
  7. package/lib/clients/ETHClient.js +15 -15
  8. package/lib/clients/HydrogenClient.js +1 -1
  9. package/lib/clients/InsightsQueryClient.js +3 -3
  10. package/lib/clients/NEOClient.d.ts +2 -2
  11. package/lib/clients/NEOClient.js +7 -7
  12. package/lib/clients/TokenClient.d.ts +23 -23
  13. package/lib/clients/TokenClient.js +2 -2
  14. package/lib/clients/ZILClient.d.ts +7 -7
  15. package/lib/clients/ZILClient.js +17 -17
  16. package/lib/codec/broker/amm.d.ts +35 -7
  17. package/lib/codec/broker/amm.js +181 -6
  18. package/lib/codec/broker/event.d.ts +13 -0
  19. package/lib/codec/broker/event.js +89 -1
  20. package/lib/codec/broker/genesis.d.ts +3 -2
  21. package/lib/codec/broker/genesis.js +26 -11
  22. package/lib/codec/cdp/event.d.ts +2 -1
  23. package/lib/codec/cdp/event.js +17 -13
  24. package/lib/codec/cdp/export.d.ts +1 -1
  25. package/lib/codec/cdp/export.js +5 -3
  26. package/lib/codec/cdp/params.d.ts +2 -2
  27. package/lib/codec/cdp/params.js +16 -11
  28. package/lib/codec/cdp/tx.d.ts +40 -18
  29. package/lib/codec/cdp/tx.js +115 -31
  30. package/lib/codec/coin/token.d.ts +1 -0
  31. package/lib/codec/coin/token.js +19 -0
  32. package/lib/codec/cosmos/gov/v1/query.js +2 -2
  33. package/lib/codec/cosmos/gov/v1/tx.js +2 -2
  34. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  35. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  36. package/lib/codec/cosmos/group/v1/events.js +2 -2
  37. package/lib/codec/cosmos/group/v1/tx.js +4 -4
  38. package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
  39. package/lib/codec/google/protobuf/any.d.ts +4 -1
  40. package/lib/codec/google/protobuf/timestamp.d.ts +0 -2
  41. package/lib/codec/index.d.ts +29 -134
  42. package/lib/codec/index.js +1351 -1456
  43. package/lib/constant/generic.js +1 -1
  44. package/lib/insights/balance.d.ts +2 -2
  45. package/lib/modules/admin.d.ts +3 -2
  46. package/lib/modules/admin.js +40 -46
  47. package/lib/modules/alliance.js +13 -13
  48. package/lib/modules/cdp.d.ts +16 -16
  49. package/lib/modules/cdp.js +126 -104
  50. package/lib/modules/cosmwasm.js +2 -2
  51. package/lib/modules/evm.js +5 -5
  52. package/lib/modules/gov.js +12 -12
  53. package/lib/modules/index.d.ts +2 -0
  54. package/lib/modules/index.js +2 -0
  55. package/lib/modules/liquiditypool.js +9 -9
  56. package/lib/modules/market.d.ts +7 -7
  57. package/lib/modules/order.js +2 -2
  58. package/lib/modules/test.d.ts +0 -0
  59. package/lib/modules/test.js +1 -0
  60. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  61. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  62. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  63. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  64. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  65. package/lib/provider/amino/AminoTypesMap.js +1 -1
  66. package/lib/provider/amino/types/admin.js +27 -27
  67. package/lib/provider/amino/types/bank.js +1 -1
  68. package/lib/provider/amino/types/broker.js +1 -1
  69. package/lib/provider/amino/types/cdp.js +34 -28
  70. package/lib/provider/amino/types/coin.js +4 -4
  71. package/lib/provider/amino/types/evm.js +2 -2
  72. package/lib/provider/amino/types/evmmerge.js +1 -1
  73. package/lib/provider/amino/types/feemarket.js +1 -1
  74. package/lib/provider/amino/types/gov.js +30 -30
  75. package/lib/provider/amino/types/ibc.js +1 -1
  76. package/lib/provider/amino/types/index.d.ts +2 -0
  77. package/lib/provider/amino/types/index.js +5 -1
  78. package/lib/provider/amino/types/leverage.js +1 -1
  79. package/lib/provider/amino/types/liquidityPool.js +7 -10
  80. package/lib/provider/amino/types/market.js +6 -6
  81. package/lib/provider/amino/types/oracle.js +2 -2
  82. package/lib/provider/amino/types/order.js +4 -4
  83. package/lib/provider/amino/types/position.js +1 -1
  84. package/lib/provider/amino/types/profile.js +1 -1
  85. package/lib/provider/amino/types/staking.js +4 -4
  86. package/lib/provider/amino/types/subaccount.js +3 -3
  87. package/lib/provider/amino/utils.js +11 -11
  88. package/lib/provider/keplr/KeplrAccount.js +31 -18
  89. package/lib/provider/ledger/ledger.js +2 -2
  90. package/lib/provider/metamask/MetaMask.js +22 -15
  91. package/lib/provider/o3/O3Wallet.d.ts +3 -2
  92. package/lib/provider/o3/O3Wallet.js +6 -6
  93. package/lib/util/address.js +14 -14
  94. package/lib/util/api.js +4 -4
  95. package/lib/util/blockchain.d.ts +5 -5
  96. package/lib/util/blockchain.js +4 -4
  97. package/lib/util/eip712.js +3 -3
  98. package/lib/util/ethermint.js +1 -1
  99. package/lib/util/external.d.ts +2 -2
  100. package/lib/util/fetch.js +1 -1
  101. package/lib/util/generic.js +3 -3
  102. package/lib/util/gov.js +16 -16
  103. package/lib/util/legacyEIP712.js +2 -2
  104. package/lib/util/network.js +3 -3
  105. package/lib/util/number.js +5 -5
  106. package/lib/util/tx.d.ts +28 -18
  107. package/lib/wallet/CarbonSigner.js +2 -2
  108. package/lib/wallet/CarbonSigningClient.js +15 -15
  109. package/lib/wallet/CarbonWallet.js +9 -9
  110. package/lib/websocket/channel.js +17 -0
  111. package/lib/websocket/connector.js +3 -3
  112. package/lib/websocket/types.d.ts +9 -2
  113. package/lib/websocket/types.js +2 -0
  114. package/package.json +2 -2
@@ -5,14 +5,15 @@ import * as clients from "./clients";
5
5
  import { CarbonQueryClient, ETHClient, HydrogenClient, InsightsQueryClient, NEOClient, TokenClient, ZILClient } from "./clients";
6
6
  import GrpcQueryClient from "./clients/GrpcQueryClient";
7
7
  import N3Client from "./clients/N3Client";
8
- import { AdminModule, AllianceModule, BankModule, BrokerModule, CDPModule, CoinModule, EvmMergeModule, EvmModule, FeeModule, FeemarketModule, GovModule, IBCModule, LeverageModule, LiquidityPoolModule, MarketModule, OracleModule, OrderModule, PositionModule, ProfileModule, SubAccountModule, XChainModule } from "./modules";
8
+ import { AdminModule, AllianceModule, BankModule, BrokerModule, CDPModule, CoinModule, ERC20Module, EvmMergeModule, EvmModule, FeeModule, FeemarketModule, GovModule, IBCModule, LeverageModule, LiquidityPoolModule, MarketModule, OracleModule, OrderModule, PerpspoolModule, PositionModule, ProfileModule, SubAccountModule, XChainModule } from "./modules";
9
9
  import { StakingModule } from "./modules/staking";
10
10
  import { CosmosLedger, Keplr, LeapExtended } from "./provider";
11
11
  import { MetaMask } from "./provider/metamask/MetaMask";
12
- import { CarbonSigner, CarbonWallet, CarbonWalletGenericOpts, MetaMaskWalletOpts } from "./wallet";
13
- export { CarbonTx } from "./util";
12
+ import { CarbonWallet, CarbonWalletGenericOpts, CarbonSigner, MetaMaskWalletOpts } from "./wallet";
14
13
  export { CarbonSigner, CarbonSignerTypes, CarbonWallet, CarbonWalletGenericOpts, CarbonWalletInitOpts } from "./wallet";
14
+ export { CarbonTx } from "./util";
15
15
  export { DenomPrefix } from "./constant";
16
+ export * as Carbon from "./codec/carbon-models";
16
17
  export interface CarbonSDKOpts {
17
18
  network: Network;
18
19
  tmClient: Tendermint34Client;
@@ -62,6 +63,8 @@ declare class CarbonSDK {
62
63
  alliance: AllianceModule;
63
64
  order: OrderModule;
64
65
  lp: LiquidityPoolModule;
66
+ erc20: ERC20Module;
67
+ perpspool: PerpspoolModule;
65
68
  subaccount: SubAccountModule;
66
69
  profile: ProfileModule;
67
70
  cdp: CDPModule;
package/lib/CarbonSDK.js CHANGED
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.ConnectedCarbonSDK = exports.DenomPrefix = exports.CarbonWallet = exports.CarbonSignerTypes = exports.CarbonTx = void 0;
34
+ exports.ConnectedCarbonSDK = exports.Carbon = exports.DenomPrefix = exports.CarbonTx = exports.CarbonWallet = exports.CarbonSignerTypes = void 0;
35
35
  const constant_1 = require("./constant");
36
36
  const util_1 = require("./util");
37
37
  const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
@@ -45,13 +45,14 @@ const staking_1 = require("./modules/staking");
45
45
  const provider_1 = require("./provider");
46
46
  const blockchain_1 = require("./util/blockchain");
47
47
  const wallet_1 = require("./wallet");
48
- var util_2 = require("./util");
49
- Object.defineProperty(exports, "CarbonTx", { enumerable: true, get: function () { return util_2.CarbonTx; } });
50
48
  var wallet_2 = require("./wallet");
51
49
  Object.defineProperty(exports, "CarbonSignerTypes", { enumerable: true, get: function () { return wallet_2.CarbonSignerTypes; } });
52
50
  Object.defineProperty(exports, "CarbonWallet", { enumerable: true, get: function () { return wallet_2.CarbonWallet; } });
51
+ var util_2 = require("./util");
52
+ Object.defineProperty(exports, "CarbonTx", { enumerable: true, get: function () { return util_2.CarbonTx; } });
53
53
  var constant_2 = require("./constant");
54
54
  Object.defineProperty(exports, "DenomPrefix", { enumerable: true, get: function () { return constant_2.DenomPrefix; } });
55
+ exports.Carbon = __importStar(require("./codec/carbon-models"));
55
56
  const DEFAULT_SDK_INIT_OPTS = {
56
57
  network: constant_1.DEFAULT_NETWORK,
57
58
  };
@@ -72,7 +73,7 @@ class CarbonSDK {
72
73
  this.evmChainId = (_g = (_f = opts.evmChainId) !== null && _f !== void 0 ? _f : constant_1.CarbonEvmChainIDs[this.network]) !== null && _g !== void 0 ? _g : constant_1.CarbonEvmChainIDs[constant_1.Network.MainNet];
73
74
  let grpcClient;
74
75
  if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
75
- const transport = typeof window === "undefined" ? (0, grpc_web_node_http_transport_1.NodeHttpTransport)() : undefined;
76
+ const transport = typeof window === "undefined" ? grpc_web_node_http_transport_1.NodeHttpTransport() : undefined;
76
77
  grpcClient = (_h = opts.grpcQueryClient) !== null && _h !== void 0 ? _h : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
77
78
  transport,
78
79
  });
@@ -89,6 +90,8 @@ class CarbonSDK {
89
90
  this.alliance = new modules_1.AllianceModule(this);
90
91
  this.order = new modules_1.OrderModule(this);
91
92
  this.lp = new modules_1.LiquidityPoolModule(this);
93
+ this.erc20 = new modules_1.ERC20Module(this);
94
+ this.perpspool = new modules_1.PerpspoolModule(this);
92
95
  this.subaccount = new modules_1.SubAccountModule(this);
93
96
  this.profile = new modules_1.ProfileModule(this);
94
97
  this.cdp = new modules_1.CDPModule(this);
@@ -322,7 +325,7 @@ class CarbonSDK {
322
325
  const evmChainId = this.evmChainId;
323
326
  const addressOptions = {
324
327
  network: this.networkConfig.network,
325
- bech32Prefix: this.networkConfig.Bech32Prefix
328
+ bech32Prefix: this.networkConfig.Bech32Prefix,
326
329
  };
327
330
  let publicKeyBase64;
328
331
  const address = yield metamask.defaultAccount();
@@ -29,7 +29,7 @@ class BatchQueryClient {
29
29
  };
30
30
  if (typeof endpoint === "string") {
31
31
  // accept host.name:port and assume http protocol
32
- this.url = (0, rpcclient_1.hasProtocol)(endpoint) ? endpoint : "http://" + endpoint;
32
+ this.url = rpcclient_1.hasProtocol(endpoint) ? endpoint : "http://" + endpoint;
33
33
  }
34
34
  else {
35
35
  this.url = endpoint.url;
@@ -71,7 +71,7 @@ class BatchQueryClient {
71
71
  return;
72
72
  const requests = batch.map((s) => s.request);
73
73
  const requestIds = requests.map((request) => request.id);
74
- (0, http_1.http)("POST", this.url, this.headers, requests).then((raw) => {
74
+ http_1.http("POST", this.url, this.headers, requests).then((raw) => {
75
75
  // Requests with a single entry return as an object
76
76
  const arr = Array.isArray(raw) ? raw : [raw];
77
77
  arr.forEach((el, i) => {
@@ -79,8 +79,8 @@ class BatchQueryClient {
79
79
  if (!req)
80
80
  return;
81
81
  const { reject, resolve } = req;
82
- const response = (0, json_rpc_1.parseJsonRpcResponse)(el);
83
- if ((0, json_rpc_1.isJsonRpcErrorResponse)(response)) {
82
+ const response = json_rpc_1.parseJsonRpcResponse(el);
83
+ if (json_rpc_1.isJsonRpcErrorResponse(response)) {
84
84
  reject(new Error(JSON.stringify(response.error)));
85
85
  }
86
86
  else {
@@ -42,6 +42,8 @@ import { QueryClientImpl as PricingQueryClient } from "../codec/pricing/query";
42
42
  import { QueryClientImpl as ProfileQueryClient } from "../codec/profile/query";
43
43
  import { QueryClientImpl as SubaccountQueryClient } from "../codec/subaccount/query";
44
44
  import { QueryClientImpl as AllianceClient } from "../codec/alliance/query";
45
+ import { QueryClientImpl as PerpspoolQueryClient } from "../codec/perpspool/query";
46
+ import { QueryClientImpl as ERC20QueryClient } from "../codec/erc20/query";
45
47
  import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
46
48
  import BlockchainClient from "./BlockchainClient";
47
49
  import GrpcQueryClient from "./GrpcQueryClient";
@@ -83,6 +85,7 @@ declare class CarbonQueryClient {
83
85
  profile: ProfileQueryClient;
84
86
  subaccount: SubaccountQueryClient;
85
87
  headersync: HeadersyncQueryClient;
88
+ perpspool: PerpspoolQueryClient;
86
89
  auth: AuthQueryClient;
87
90
  bank: BankQueryClient;
88
91
  nativeBank: NativeBankQueryClient;
@@ -101,6 +104,7 @@ declare class CarbonQueryClient {
101
104
  ethermint: EthermintClientGroup;
102
105
  evmmerge: EvmMergeQueryClient;
103
106
  evmbank: EvmBankQueryClient;
107
+ erc20: ERC20QueryClient;
104
108
  private readonly baseClient;
105
109
  private readonly tmClient;
106
110
  constructor(opts: CarbonQueryClientOpts);
@@ -47,12 +47,14 @@ const query_41 = require("../codec/pricing/query");
47
47
  const query_42 = require("../codec/profile/query");
48
48
  const query_43 = require("../codec/subaccount/query");
49
49
  const query_44 = require("../codec/alliance/query");
50
+ const query_45 = require("../codec/perpspool/query");
51
+ const query_46 = require("../codec/erc20/query");
50
52
  const stargate_1 = require("@cosmjs/stargate");
51
53
  const BlockchainClient_1 = __importDefault(require("./BlockchainClient"));
52
54
  class CarbonQueryClient {
53
55
  constructor(opts) {
54
56
  var _a;
55
- const rpcClient = (_a = opts.grpcClient) !== null && _a !== void 0 ? _a : (0, stargate_1.createProtobufRpcClient)(new stargate_1.QueryClient(opts.tmClient));
57
+ const rpcClient = (_a = opts.grpcClient) !== null && _a !== void 0 ? _a : stargate_1.createProtobufRpcClient(new stargate_1.QueryClient(opts.tmClient));
56
58
  this.tmClient = opts.tmClient;
57
59
  this.baseClient = rpcClient;
58
60
  this.chain = BlockchainClient_1.default.connectWithTm(opts.tmClient);
@@ -80,6 +82,7 @@ class CarbonQueryClient {
80
82
  this.headersync = new query_23.QueryClientImpl(rpcClient);
81
83
  this.evmmerge = new query_19.QueryClientImpl(rpcClient);
82
84
  this.evmbank = new query_20.QueryClientImpl(rpcClient);
85
+ this.perpspool = new query_45.QueryClientImpl(rpcClient);
83
86
  this.auth = new query_6.QueryClientImpl(rpcClient);
84
87
  this.bank = new query_7.QueryClientImpl(rpcClient);
85
88
  this.nativeBank = new query_8.QueryClientImpl(rpcClient);
@@ -93,6 +96,7 @@ class CarbonQueryClient {
93
96
  this.upgrade = new query_17.QueryClientImpl(rpcClient);
94
97
  this.cosmosTm = new query_9.ServiceClientImpl(rpcClient);
95
98
  this.alliance = new query_44.QueryClientImpl(rpcClient);
99
+ this.erc20 = new query_46.QueryClientImpl(rpcClient);
96
100
  this.ibc = {
97
101
  controller: new query_24.QueryClientImpl(rpcClient),
98
102
  host: new query_25.QueryClientImpl(rpcClient),
@@ -1,6 +1,6 @@
1
1
  import CarbonSDK from "../CarbonSDK";
2
2
  import { EthNetworkConfig, NetworkConfig, NetworkConfigProvider } from "../constant";
3
- import { Models } from "../index";
3
+ import { Carbon } from "../CarbonSDK";
4
4
  import { Blockchain } from "../util/blockchain";
5
5
  import { TokenInitInfo, TokensWithExternalBalance } from "../util/external";
6
6
  import BigNumber from "bignumber.js";
@@ -19,8 +19,8 @@ interface ETHTxParams {
19
19
  nonce?: number;
20
20
  }
21
21
  export interface BridgeParams {
22
- fromToken: Models.Token;
23
- toToken: Models.Token;
22
+ fromToken: Carbon.Coin.Token;
23
+ toToken: Carbon.Coin.Token;
24
24
  amount: BigNumber;
25
25
  fromAddress: string;
26
26
  recoveryAddress: string;
@@ -35,11 +35,11 @@ export interface BridgeParams {
35
35
  export interface LockParams extends ETHTxParams {
36
36
  address: Uint8Array;
37
37
  amount: BigNumber;
38
- token: Models.Token;
38
+ token: Carbon.Coin.Token;
39
39
  signCompleteCallback?: () => void;
40
40
  }
41
41
  export interface ApproveERC20Params extends ETHTxParams {
42
- token: Models.Token;
42
+ token: Carbon.Coin.Token;
43
43
  spenderAddress?: string;
44
44
  amount?: BigNumber;
45
45
  signCompleteCallback?: () => void;
@@ -71,7 +71,7 @@ export declare class ETHClient {
71
71
  static instance(opts: ETHClientOpts): CarbonSDK.ETHClient;
72
72
  getExternalBalances(api: CarbonSDK, address: string, whitelistDenoms?: string[], version?: string): Promise<TokensWithExternalBalance[]>;
73
73
  approveERC20(params: ApproveERC20Params): Promise<EthersTransactionResponse>;
74
- checkAllowanceERC20(token: Models.Token, owner: string, spender: string): Promise<BigNumber>;
74
+ checkAllowanceERC20(token: Carbon.Coin.Token, owner: string, spender: string): Promise<BigNumber>;
75
75
  bridgeTokens(params: BridgeParams): Promise<EthersTransactionResponse>;
76
76
  lockDeposit(params: LockParams): Promise<EthersTransactionResponse>;
77
77
  getDepositContractAddress(swthBech32Address: string, ownerEthAddress: string): Promise<string>;
@@ -79,7 +79,7 @@ export declare class ETHClient {
79
79
  address: string;
80
80
  signature: string;
81
81
  }>, overrideFee?: ethers.BigNumber): Promise<Response | "insufficient balance">;
82
- getDepositFeeAmount(token: Models.Token, depositAddress: string): Promise<ethers.BigNumber>;
82
+ getDepositFeeAmount(token: Carbon.Coin.Token, depositAddress: string): Promise<ethers.BigNumber>;
83
83
  isContract(address: string): Promise<boolean>;
84
84
  retrieveERC20Info(address: string): Promise<TokenInitInfo>;
85
85
  formatWithdrawalAddress(address: string): Promise<string>;
@@ -94,7 +94,7 @@ export declare class ETHClient {
94
94
  *
95
95
  * @param token
96
96
  */
97
- getTargetProxyHash(token: Models.Token): string;
97
+ getTargetProxyHash(token: Carbon.Coin.Token): string;
98
98
  getProvider(): ethers.providers.JsonRpcProvider;
99
99
  getNetworkConfig(): NetworkConfig;
100
100
  getConfig(): EthNetworkConfig;
@@ -44,15 +44,15 @@ class ETHClient {
44
44
  ?
45
45
  this.tokenClient.getBlockchainV2(token.denom) == ETHClient.BLOCKCHAINV2_MAPPING[this.blockchain]
46
46
  :
47
- (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), api.network) == this.blockchain;
47
+ blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain;
48
48
  return isCorrectBlockchain &&
49
49
  token.tokenAddress.length == 40 &&
50
- token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
50
+ token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
51
51
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
52
- this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
52
+ this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
53
53
  });
54
54
  const assetIds = tokens.map((token) => {
55
- return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
55
+ return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
56
56
  });
57
57
  const provider = this.getProvider();
58
58
  const contractAddress = this.getBalanceReaderAddress();
@@ -101,14 +101,14 @@ class ETHClient {
101
101
  }
102
102
  const carbonNetwork = networkConfig.network;
103
103
  const fromTokenId = fromToken.id;
104
- const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
104
+ const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
105
105
  const toTokenDenom = toToken.denom;
106
106
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
107
107
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
108
108
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
109
109
  const nonce = yield this.getTxNonce(fromAddress, params.nonce, rpcProvider);
110
110
  const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
111
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
111
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
112
112
  const tokenCreator = fromToken.creator;
113
113
  const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
114
114
  const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
@@ -137,9 +137,9 @@ class ETHClient {
137
137
  throw new Error("Minimum gas required: 150,000");
138
138
  }
139
139
  const networkConfig = this.getNetworkConfig();
140
- const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
141
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
142
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
140
+ const assetId = generic_1.appendHexPrefix(token.tokenAddress);
141
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
142
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
143
143
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
144
144
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
145
145
  const contractAddress = this.getLockProxyAddress();
@@ -190,16 +190,16 @@ class ETHClient {
190
190
  return "insufficient balance";
191
191
  }
192
192
  const networkConfig = this.getNetworkConfig();
193
- const assetId = (0, generic_1.appendHexPrefix)(tokenWithExternalBalances.tokenAddress);
194
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(tokenWithExternalBalances));
195
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
193
+ const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
194
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
195
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
196
196
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
197
197
  const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
198
198
  const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
199
199
  // logger("sendDeposit message", message)
200
200
  let signatureResult;
201
201
  const { address, signature } = yield getSignatureCallback(message);
202
- const signatureBytes = ethers_1.ethers.utils.arrayify((0, generic_1.appendHexPrefix)(signature));
202
+ const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
203
203
  const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
204
204
  // logger("sign result", address, signature)
205
205
  signatureResult = {
@@ -238,7 +238,7 @@ class ETHClient {
238
238
  if (!feeInfo.deposit_fee) {
239
239
  throw new Error("unsupported token");
240
240
  }
241
- if ((0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
241
+ if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
242
242
  throw new Error("unsupported token");
243
243
  }
244
244
  let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
@@ -304,7 +304,7 @@ class ETHClient {
304
304
  getTargetProxyHash(token) {
305
305
  const networkConfig = this.getNetworkConfig();
306
306
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
307
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
307
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
308
308
  return addressHex;
309
309
  }
310
310
  getProvider() {
@@ -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
@@ -101,12 +101,12 @@ class InsightsQueryClient {
101
101
  const meta = response.data.result.meta;
102
102
  const parsedEntries = rawEntries.map(entry => ({
103
103
  lastHeight: entry.lastHeight,
104
- time: (0, dayjs_1.default)(entry.time),
104
+ time: dayjs_1.default(entry.time),
105
105
  volumeValue: new bignumber_js_1.default(entry.volumeValue)
106
106
  }));
107
107
  const parsedMeta = {
108
- from: (0, dayjs_1.default)(meta.from),
109
- until: (0, dayjs_1.default)(meta.until),
108
+ from: dayjs_1.default(meta.from),
109
+ until: dayjs_1.default(meta.until),
110
110
  interval: meta.interval,
111
111
  };
112
112
  return { result: { entries: parsedEntries, meta: parsedMeta } };
@@ -1,6 +1,6 @@
1
1
  import CarbonSDK from "../CarbonSDK";
2
2
  import { NeoNetworkConfig, NetworkConfig, NetworkConfigProvider } from "../constant";
3
- import { Models } from "../index";
3
+ import { Carbon } from "../CarbonSDK";
4
4
  import { NeoLedgerAccount } from "../provider/account";
5
5
  import { O3Wallet } from "../provider/o3";
6
6
  import { Blockchain } from "../util/blockchain";
@@ -49,7 +49,7 @@ export declare class NEOClient {
49
49
  *
50
50
  * @param token
51
51
  */
52
- getTargetProxyHash(token: Models.Token): string;
52
+ getTargetProxyHash(token: Carbon.Coin.Token): string;
53
53
  getNetworkConfig(): NetworkConfig;
54
54
  getConfig(): NeoNetworkConfig;
55
55
  getProviderUrl(): string;
@@ -68,13 +68,13 @@ class NEOClient {
68
68
  ?
69
69
  !!sdk.token.getBlockchainV2(token.denom) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[sdk.token.getBlockchainV2(token.denom)] == this.blockchain)
70
70
  :
71
- (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), sdk.network) == this.blockchain;
71
+ blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
72
72
  return (isCorrectBlockchain || token.denom === "swth") && token.tokenAddress.length == 40 && token.bridgeAddress.length == 40;
73
73
  });
74
74
  const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
75
75
  // NOTE: fetching of tokens is chunked in sets of 15 as we may hit
76
76
  // the gas limit on the RPC node and error out otherwise
77
- const promises = (0, lodash_1.chunk)(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
77
+ const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
78
78
  var _a, _b, _c;
79
79
  let acc = {};
80
80
  for (const token of partition) {
@@ -116,8 +116,8 @@ class NEOClient {
116
116
  const targetProxyHash = this.getTargetProxyHash(token);
117
117
  const toAssetHash = Neon.u.str2hexstring(token.id);
118
118
  const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
119
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
120
- const zeroAddressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
119
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
120
+ const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
121
121
  const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
122
122
  const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
123
123
  const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
@@ -162,7 +162,7 @@ class NEOClient {
162
162
  const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
163
163
  const targetProxyHash = this.getTargetProxyHash(token);
164
164
  const toAssetHash = Neon.u.str2hexstring(token.id);
165
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
165
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
166
166
  const nonce = Math.floor(Math.random() * 1000000);
167
167
  if (amount.lt(feeAmount)) {
168
168
  throw new Error("Invalid amount");
@@ -198,7 +198,7 @@ class NEOClient {
198
198
  const fromAddress = ledger.scriptHash;
199
199
  const targetProxyHash = this.getTargetProxyHash(token);
200
200
  const toAssetHash = Neon.u.str2hexstring(token.id);
201
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
201
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
202
202
  const feeAddress = networkConfig.feeAddress;
203
203
  const nonce = Math.floor(Math.random() * 1000000);
204
204
  if (amount.lt(feeAmount)) {
@@ -313,7 +313,7 @@ class NEOClient {
313
313
  getTargetProxyHash(token) {
314
314
  const networkConfig = this.getNetworkConfig();
315
315
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
316
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
316
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
317
317
  return addressHex;
318
318
  }
319
319
  getNetworkConfig() {
@@ -1,4 +1,4 @@
1
- import { Bridge, Token, TokenPrice } from "../codec";
1
+ import { Carbon } from "../CarbonSDK";
2
2
  import { NetworkConfigProvider } from "../constant";
3
3
  import { GetFeeQuoteResponse } from "../hydrogen/feeQuote";
4
4
  import { BlockchainUtils, TypeUtils } from "../util";
@@ -9,10 +9,10 @@ declare class TokenClient {
9
9
  readonly query: CarbonQueryClient;
10
10
  readonly configProvider: NetworkConfigProvider;
11
11
  static Blacklist: Partial<TypeUtils.NetworkMap<string[]>>;
12
- readonly tokens: TypeUtils.SimpleMap<Token>;
12
+ readonly tokens: TypeUtils.SimpleMap<Carbon.Coin.Token>;
13
13
  readonly wrapperMap: TypeUtils.SimpleMap<string>;
14
- readonly poolTokens: TypeUtils.SimpleMap<Token>;
15
- readonly cdpTokens: TypeUtils.SimpleMap<Token>;
14
+ readonly poolTokens: TypeUtils.SimpleMap<Carbon.Coin.Token>;
15
+ readonly cdpTokens: TypeUtils.SimpleMap<Carbon.Coin.Token>;
16
16
  readonly bridges: BridgeMap;
17
17
  readonly symbols: TypeUtils.SimpleMap<string>;
18
18
  readonly usdValues: TypeUtils.SimpleMap<BigNumber>;
@@ -31,8 +31,8 @@ declare class TokenClient {
31
31
  getUSDValue(denom: string): BigNumber | undefined;
32
32
  toHuman(denom: string, unitlessAmt: BigNumber): BigNumber;
33
33
  toUnitless(denom: string, humanAmt: BigNumber): BigNumber;
34
- tokenForId(id: string): Token | undefined;
35
- tokenForDenom(denom: string): Token | undefined;
34
+ tokenForId(id: string): Carbon.Coin.Token | undefined;
35
+ tokenForDenom(denom: string): Carbon.Coin.Token | undefined;
36
36
  getFeeInfo(denom: string): Promise<GetFeeQuoteResponse>;
37
37
  getTokenName(denom: string, overrideMap?: TypeUtils.SimpleMap<string>): string;
38
38
  getTokenDesc(denom: string): string;
@@ -44,36 +44,36 @@ declare class TokenClient {
44
44
  static isCdpIbcDenom(denom: string): boolean;
45
45
  isWrappedToken(denom?: string): boolean;
46
46
  hasWrappedToken(denom?: string): boolean;
47
- getWrappedTokens(denom: string): Token[];
48
- getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | null;
49
- getSourceToken(denom: string): Token | null;
50
- getNativeToken(): Token | undefined;
51
- getNativeStablecoin(): Token | undefined;
47
+ getWrappedTokens(denom: string): Carbon.Coin.Token[];
48
+ getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Carbon.Coin.Token | null;
49
+ getSourceToken(denom: string): Carbon.Coin.Token | null;
50
+ getNativeToken(): Carbon.Coin.Token | undefined;
51
+ getNativeStablecoin(): Carbon.Coin.Token | undefined;
52
52
  isNativeToken(denom: string): boolean;
53
53
  isNativeStablecoin(denom: string): boolean;
54
54
  isGroupedToken(denom: string): boolean;
55
- isCarbonToken(token?: Token | null): boolean;
56
- getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Token | undefined;
57
- getAllTokens(): Promise<Token[]>;
58
- reloadTokens(): Promise<TypeUtils.SimpleMap<Token>>;
55
+ isCarbonToken(token?: Carbon.Coin.Token | null): boolean;
56
+ getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2, version?: string): Carbon.Coin.Token | undefined;
57
+ getAllTokens(): Promise<Carbon.Coin.Token[]>;
58
+ reloadTokens(): Promise<TypeUtils.SimpleMap<Carbon.Coin.Token>>;
59
59
  getBridges(): Promise<BridgeMap>;
60
- matchChainsWithDifferentChainIds(bridges: Bridge[]): Promise<IbcBridge[]>;
60
+ matchChainsWithDifferentChainIds(bridges: Carbon.Coin.Bridge[]): Promise<IbcBridge[]>;
61
61
  getIbcBlockchainNames(): string[];
62
62
  getIbcChainFromBlockchainV2: (blockchain: BlockchainV2 | undefined) => string | undefined;
63
63
  getPolynetworkBlockchainNames(): string[];
64
64
  getAllBlockchainNames(): string[];
65
- getBridgesFromBridgeId(bridgeId: number): Bridge[] | IbcBridge[];
66
- getIbcTokens(): TypeUtils.SimpleMap<Token>;
67
- getPolyNetworkTokens(): TypeUtils.SimpleMap<Token>;
65
+ getBridgesFromBridgeId(bridgeId: number): Carbon.Coin.Bridge[] | IbcBridge[];
66
+ getIbcTokens(): TypeUtils.SimpleMap<Carbon.Coin.Token>;
67
+ getPolyNetworkTokens(): TypeUtils.SimpleMap<Carbon.Coin.Token>;
68
68
  getBlockchainV2FromIDs(chainId: number, bridgeId: number): BlockchainV2 | undefined;
69
- getBridgeFromToken(token: Token | null): Bridge | IbcBridge | undefined;
70
- getIbcChainIdFromToken(token: Token | null): string | undefined;
71
- getCdpUnderlyingToken(cdpDenom: string): Token | undefined;
69
+ getBridgeFromToken(token: Carbon.Coin.Token | null): Carbon.Coin.Bridge | IbcBridge | undefined;
70
+ getIbcChainIdFromToken(token: Carbon.Coin.Token | null): string | undefined;
71
+ getCdpUnderlyingToken(cdpDenom: string): Carbon.Coin.Token | undefined;
72
72
  reloadWrapperMap(): Promise<TypeUtils.SimpleMap<string>>;
73
73
  reloadDenomGeckoMap(): Promise<void>;
74
74
  reloadUSDValues(denoms?: string[]): Promise<TypeUtils.SimpleMap<BigNumber>>;
75
75
  getUSDValuesFromCoinGecko(geckoIds: string[]): Promise<any>;
76
- processTokenPrices(tokenPrices: TokenPrice[]): TypeUtils.SimpleMap<BigNumber>;
76
+ processTokenPrices(tokenPrices: Carbon.Pricing.TokenPrice[]): TypeUtils.SimpleMap<BigNumber>;
77
77
  getUSDValuesFromPricingModule(): Promise<TypeUtils.SimpleMap<BigNumber>>;
78
78
  getDenomToGeckoIdMap(): Promise<TypeUtils.SimpleMap<string>>;
79
79
  setCommonAssetConfig(): void;
@@ -544,7 +544,7 @@ class TokenClient {
544
544
  if (!token)
545
545
  return undefined;
546
546
  const bridge = this.getBridgeFromToken(token);
547
- if (!bridge || !(0, blockchain_1.isIbcBridge)(bridge))
547
+ if (!bridge || !blockchain_1.isIbcBridge(bridge))
548
548
  return undefined;
549
549
  return bridge.chain_id_name;
550
550
  }
@@ -620,7 +620,7 @@ class TokenClient {
620
620
  processTokenPrices(tokenPrices) {
621
621
  return tokenPrices.reduce((prevPrices, price) => {
622
622
  const newPrev = prevPrices;
623
- newPrev[price.denom] = (0, number_1.bnOrZero)(price.twap).shiftedBy(-constant_1.decTypeDecimals);
623
+ newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
624
624
  return newPrev;
625
625
  }, {});
626
626
  }
@@ -1,6 +1,6 @@
1
1
  import CarbonSDK from "../CarbonSDK";
2
2
  import { NetworkConfig, NetworkConfigProvider, ZilNetworkConfig } from "../constant";
3
- import { Models } from "../index";
3
+ import { Carbon } from "../CarbonSDK";
4
4
  import { Blockchain } from "../util/blockchain";
5
5
  import { TokensWithExternalBalance } from "../util/external";
6
6
  import { Transaction, Wallet } from "@zilliqa-js/account";
@@ -29,12 +29,12 @@ interface ZILTxParams {
29
29
  export interface ZILLockParams extends ZILTxParams {
30
30
  address: Uint8Array;
31
31
  amount: BigNumber;
32
- token: Models.Token;
32
+ token: Carbon.Coin.Token;
33
33
  signCompleteCallback?: () => void;
34
34
  }
35
35
  export interface ZilBridgeParams {
36
- fromToken: Models.Token;
37
- toToken: Models.Token;
36
+ fromToken: Carbon.Coin.Token;
37
+ toToken: Carbon.Coin.Token;
38
38
  amount: BigNumber;
39
39
  fromAddress: string;
40
40
  recoveryAddress: string;
@@ -46,7 +46,7 @@ export interface ZilBridgeParams {
46
46
  signCompleteCallback?: () => void;
47
47
  }
48
48
  export interface ApproveZRC2Params extends ZILTxParams {
49
- token: Models.Token;
49
+ token: Carbon.Coin.Token;
50
50
  spenderAddress?: string;
51
51
  signCompleteCallback?: () => void;
52
52
  }
@@ -81,7 +81,7 @@ export declare class ZILClient {
81
81
  formatWithdrawalAddress(bech32Address: string): Promise<string>;
82
82
  private callContract;
83
83
  approveZRC2(params: ApproveZRC2Params): Promise<Transaction>;
84
- checkAllowanceZRC2(token: Models.Token, owner: string, spender: string): Promise<BigNumber>;
84
+ checkAllowanceZRC2(token: Carbon.Coin.Token, owner: string, spender: string): Promise<BigNumber>;
85
85
  bridgeTokens(params: ZilBridgeParams): Promise<Transaction>;
86
86
  lockDeposit(params: ZILLockParams): Promise<Transaction>;
87
87
  retrieveZRC2Info(address: string): Promise<{
@@ -96,7 +96,7 @@ export declare class ZILClient {
96
96
  *
97
97
  * @param token
98
98
  */
99
- getTargetProxyHash(token: Models.Token): string;
99
+ getTargetProxyHash(token: Carbon.Coin.Token): string;
100
100
  getNetworkConfig(): NetworkConfig;
101
101
  getConfig(): ZilNetworkConfig;
102
102
  getProviderUrl(): string;