carbon-js-sdk 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/lib/CarbonSDK.d.ts +1 -0
  2. package/lib/CarbonSDK.js +8 -6
  3. package/lib/clients/BatchQueryClient.js +4 -4
  4. package/lib/clients/CarbonQueryClient.js +1 -1
  5. package/lib/clients/ETHClient.d.ts +1 -0
  6. package/lib/clients/ETHClient.js +19 -17
  7. package/lib/clients/HydrogenClient.js +1 -1
  8. package/lib/clients/InsightsQueryClient.js +3 -3
  9. package/lib/clients/NEOClient.js +7 -7
  10. package/lib/clients/TokenClient.js +2 -2
  11. package/lib/clients/ZILClient.js +17 -17
  12. package/lib/codec/book/book.d.ts +14 -2
  13. package/lib/codec/book/book.js +80 -13
  14. package/lib/codec/book/legacy.d.ts +22 -0
  15. package/lib/codec/book/legacy.js +120 -0
  16. package/lib/codec/book/query.d.ts +48 -1
  17. package/lib/codec/book/query.js +224 -1
  18. package/lib/codec/cdp/event.d.ts +12 -6
  19. package/lib/codec/cdp/event.js +146 -68
  20. package/lib/codec/cdp/params.d.ts +0 -2
  21. package/lib/codec/cdp/params.js +8 -23
  22. package/lib/codec/cdp/query.d.ts +22 -1
  23. package/lib/codec/cdp/query.js +104 -17
  24. package/lib/codec/cosmos/gov/v1/query.js +2 -2
  25. package/lib/codec/cosmos/gov/v1/tx.js +2 -2
  26. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  27. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  28. package/lib/codec/cosmos/group/v1/events.js +2 -2
  29. package/lib/codec/cosmos/group/v1/tx.js +4 -4
  30. package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
  31. package/lib/codec/index.d.ts +11 -9
  32. package/lib/codec/index.js +405 -133
  33. package/lib/codec/liquiditypool/event.d.ts +25 -1
  34. package/lib/codec/liquiditypool/event.js +147 -1
  35. package/lib/codec/liquiditypool/genesis.d.ts +4 -5
  36. package/lib/codec/liquiditypool/genesis.js +34 -49
  37. package/lib/codec/liquiditypool/query.d.ts +2 -51
  38. package/lib/codec/liquiditypool/query.js +18 -265
  39. package/lib/codec/liquiditypool/reward.d.ts +21 -21
  40. package/lib/codec/liquiditypool/reward.js +97 -111
  41. package/lib/codec/oracle/query.d.ts +37 -34
  42. package/lib/codec/oracle/query.js +37 -31
  43. package/lib/codec/position/position.d.ts +2 -0
  44. package/lib/codec/position/position.js +34 -0
  45. package/lib/codec/subaccount/genesis.d.ts +5 -1
  46. package/lib/codec/subaccount/genesis.js +48 -2
  47. package/lib/codec/subaccount/query.d.ts +110 -21
  48. package/lib/codec/subaccount/query.js +503 -47
  49. package/lib/codec/subaccount/subaccount.d.ts +29 -3
  50. package/lib/codec/subaccount/subaccount.js +234 -31
  51. package/lib/codec/subaccount/tx.d.ts +7 -1
  52. package/lib/codec/subaccount/tx.js +101 -16
  53. package/lib/constant/generic.js +1 -1
  54. package/lib/modules/cdp.js +45 -45
  55. package/lib/modules/cosmwasm.js +2 -2
  56. package/lib/modules/evm.js +5 -5
  57. package/lib/modules/gov.js +12 -12
  58. package/lib/modules/liquiditypool.js +1 -1
  59. package/lib/modules/order.js +2 -2
  60. package/lib/modules/subaccount.js +1 -1
  61. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  62. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  63. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  64. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  65. package/lib/provider/account/NeoLedgerAccount/NeonLedger.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 +25 -25
  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 +5 -5
  75. package/lib/provider/amino/types/ibc.js +1 -1
  76. package/lib/provider/amino/types/leverage.js +1 -1
  77. package/lib/provider/amino/types/liquidityPool.js +7 -7
  78. package/lib/provider/amino/types/market.js +6 -6
  79. package/lib/provider/amino/types/oracle.js +2 -2
  80. package/lib/provider/amino/types/order.js +4 -4
  81. package/lib/provider/amino/types/position.js +1 -1
  82. package/lib/provider/amino/types/profile.js +1 -1
  83. package/lib/provider/amino/types/staking.js +4 -4
  84. package/lib/provider/amino/types/subaccount.js +3 -3
  85. package/lib/provider/amino/utils.js +11 -11
  86. package/lib/provider/keplr/KeplrAccount.js +2 -2
  87. package/lib/provider/ledger/ledger.js +2 -2
  88. package/lib/provider/metamask/MetaMask.js +13 -13
  89. package/lib/provider/o3/O3Wallet.js +2 -2
  90. package/lib/util/address.js +14 -14
  91. package/lib/util/api.js +4 -4
  92. package/lib/util/blockchain.d.ts +1 -1
  93. package/lib/util/blockchain.js +4 -4
  94. package/lib/util/eip712.js +3 -3
  95. package/lib/util/fetch.js +1 -1
  96. package/lib/util/generic.js +3 -3
  97. package/lib/util/legacyEIP712.js +2 -2
  98. package/lib/util/network.js +3 -3
  99. package/lib/util/number.js +5 -5
  100. package/lib/wallet/CarbonSigner.js +2 -2
  101. package/lib/wallet/CarbonSigningClient.js +15 -15
  102. package/lib/wallet/CarbonWallet.js +9 -9
  103. package/lib/websocket/connector.js +3 -3
  104. package/package.json +1 -1
  105. package/lib/codec/ibc/applications/interchain_accounts/v1/genesis.d.ts +0 -76
  106. package/lib/codec/ibc/applications/interchain_accounts/v1/genesis.js +0 -424
@@ -49,6 +49,7 @@ declare class CarbonSDK {
49
49
  CDPToken: string;
50
50
  };
51
51
  readonly query: CarbonQueryClient;
52
+ readonly useTmAbciQuery: boolean;
52
53
  insights: InsightsQueryClient;
53
54
  hydrogen: HydrogenClient;
54
55
  wallet?: CarbonWallet;
package/lib/CarbonSDK.js CHANGED
@@ -62,17 +62,18 @@ const DEFAULT_SDK_INIT_OPTS = {
62
62
  */
63
63
  class CarbonSDK {
64
64
  constructor(opts) {
65
- var _a, _b, _c, _d, _e, _f, _g, _h;
65
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
66
66
  this.network = (_a = opts.network) !== null && _a !== void 0 ? _a : constant_1.DEFAULT_NETWORK;
67
67
  this.configOverride = (_b = opts.config) !== null && _b !== void 0 ? _b : {};
68
68
  this.networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[this.network], this.configOverride);
69
+ this.useTmAbciQuery = (_c = opts.useTmAbciQuery) !== null && _c !== void 0 ? _c : false;
69
70
  this.tmClient = opts.tmClient;
70
- 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];
71
- this.evmChainId = (_f = (_e = opts.evmChainId) !== null && _e !== void 0 ? _e : constant_1.CarbonEvmChainIDs[this.network]) !== null && _f !== void 0 ? _f : constant_1.CarbonEvmChainIDs[constant_1.Network.MainNet];
71
+ this.chainId = (_e = (_d = opts.chainId) !== null && _d !== void 0 ? _d : constant_1.CarbonChainIDs[this.network]) !== null && _e !== void 0 ? _e : constant_1.CarbonChainIDs[constant_1.Network.MainNet];
72
+ 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];
72
73
  let grpcClient;
73
74
  if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
74
- const transport = typeof window === "undefined" ? grpc_web_node_http_transport_1.NodeHttpTransport() : undefined;
75
- grpcClient = (_g = opts.grpcQueryClient) !== null && _g !== void 0 ? _g : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
75
+ const transport = typeof window === "undefined" ? (0, grpc_web_node_http_transport_1.NodeHttpTransport)() : undefined;
76
+ grpcClient = (_h = opts.grpcQueryClient) !== null && _h !== void 0 ? _h : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
76
77
  transport,
77
78
  });
78
79
  }
@@ -81,7 +82,7 @@ class CarbonSDK {
81
82
  grpcClient,
82
83
  });
83
84
  this.insights = new clients_1.InsightsQueryClient(this.networkConfig);
84
- this.token = (_h = opts.token) !== null && _h !== void 0 ? _h : clients_1.TokenClient.instance(this.query, this);
85
+ this.token = (_j = opts.token) !== null && _j !== void 0 ? _j : clients_1.TokenClient.instance(this.query, this);
85
86
  this.hydrogen = new clients_1.HydrogenClient(this.networkConfig, this.token);
86
87
  this.hydrogen = clients_1.HydrogenClient.instance(this.networkConfig, this.token);
87
88
  this.admin = new modules_1.AdminModule(this);
@@ -238,6 +239,7 @@ class CarbonSDK {
238
239
  config: this.configOverride,
239
240
  tmClient: this.tmClient,
240
241
  chainId: this.chainId,
242
+ useTmAbciQuery: this.useTmAbciQuery,
241
243
  };
242
244
  }
243
245
  connect(wallet) {
@@ -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 = rpcclient_1.hasProtocol(endpoint) ? endpoint : "http://" + endpoint;
32
+ this.url = (0, 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
- http_1.http("POST", this.url, this.headers, requests).then((raw) => {
74
+ (0, 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 = json_rpc_1.parseJsonRpcResponse(el);
83
- if (json_rpc_1.isJsonRpcErrorResponse(response)) {
82
+ const response = (0, json_rpc_1.parseJsonRpcResponse)(el);
83
+ if ((0, json_rpc_1.isJsonRpcErrorResponse)(response)) {
84
84
  reject(new Error(JSON.stringify(response.error)));
85
85
  }
86
86
  else {
@@ -52,7 +52,7 @@ const BlockchainClient_1 = __importDefault(require("./BlockchainClient"));
52
52
  class CarbonQueryClient {
53
53
  constructor(opts) {
54
54
  var _a;
55
- const rpcClient = (_a = opts.grpcClient) !== null && _a !== void 0 ? _a : stargate_1.createProtobufRpcClient(new stargate_1.QueryClient(opts.tmClient));
55
+ const rpcClient = (_a = opts.grpcClient) !== null && _a !== void 0 ? _a : (0, stargate_1.createProtobufRpcClient)(new stargate_1.QueryClient(opts.tmClient));
56
56
  this.tmClient = opts.tmClient;
57
57
  this.baseClient = rpcClient;
58
58
  this.chain = BlockchainClient_1.default.connectWithTm(opts.tmClient);
@@ -41,6 +41,7 @@ export interface LockParams extends ETHTxParams {
41
41
  export interface ApproveERC20Params extends ETHTxParams {
42
42
  token: Models.Token;
43
43
  spenderAddress?: string;
44
+ amount?: BigNumber;
44
45
  signCompleteCallback?: () => void;
45
46
  }
46
47
  export interface EthersTransactionResponse extends ethers.Transaction {
@@ -44,15 +44,15 @@ class ETHClient {
44
44
  ?
45
45
  this.tokenClient.getBlockchainV2(token.denom) == ETHClient.BLOCKCHAINV2_MAPPING[this.blockchain]
46
46
  :
47
- blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain;
47
+ (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), api.network) == this.blockchain;
48
48
  return isCorrectBlockchain &&
49
49
  token.tokenAddress.length == 40 &&
50
- token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
50
+ token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
51
51
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
52
- this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
52
+ this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
53
53
  });
54
54
  const assetIds = tokens.map((token) => {
55
- return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
55
+ return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
56
56
  });
57
57
  const provider = this.getProvider();
58
58
  const contractAddress = this.getBalanceReaderAddress();
@@ -69,13 +69,15 @@ class ETHClient {
69
69
  });
70
70
  }
71
71
  approveERC20(params) {
72
+ var _a;
72
73
  return __awaiter(this, void 0, void 0, function* () {
73
- const { token, gasPriceGwei, gasLimit, ethAddress, spenderAddress, signer } = params;
74
+ const { token, gasPriceGwei, gasLimit, ethAddress, spenderAddress, signer, amount } = params;
74
75
  const contractAddress = token.tokenAddress;
75
76
  const rpcProvider = this.getProvider();
76
77
  const contract = new ethers_1.ethers.Contract(contractAddress, eth_1.ABIs.erc20, rpcProvider);
78
+ const approvalAmount = ethers_1.ethers.BigNumber.from((_a = amount === null || amount === void 0 ? void 0 : amount.toString(10)) !== null && _a !== void 0 ? _a : ethers_1.ethers.constants.MaxUint256);
77
79
  const nonce = yield this.getTxNonce(ethAddress, params.nonce, rpcProvider);
78
- const approveResultTx = yield contract.connect(signer).approve(spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : token.bridgeAddress, ethers_1.ethers.constants.MaxUint256, Object.assign(Object.assign({ nonce }, gasPriceGwei && ({ gasPrice: gasPriceGwei.shiftedBy(9).toString(10) })), gasLimit && ({ gasLimit: gasLimit.toString(10) })));
80
+ const approveResultTx = yield contract.connect(signer).approve(spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : token.bridgeAddress, approvalAmount, Object.assign(Object.assign({ nonce }, gasPriceGwei && ({ gasPrice: gasPriceGwei.shiftedBy(9).toString(10) })), gasLimit && ({ gasLimit: gasLimit.toString(10) })));
79
81
  return approveResultTx;
80
82
  });
81
83
  }
@@ -99,14 +101,14 @@ class ETHClient {
99
101
  }
100
102
  const carbonNetwork = networkConfig.network;
101
103
  const fromTokenId = fromToken.id;
102
- const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
104
+ const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
103
105
  const toTokenDenom = toToken.denom;
104
106
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
105
107
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
106
108
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
107
109
  const nonce = yield this.getTxNonce(fromAddress, params.nonce, rpcProvider);
108
110
  const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
109
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
111
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
110
112
  const tokenCreator = fromToken.creator;
111
113
  const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
112
114
  const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
@@ -135,9 +137,9 @@ class ETHClient {
135
137
  throw new Error("Minimum gas required: 150,000");
136
138
  }
137
139
  const networkConfig = this.getNetworkConfig();
138
- const assetId = generic_1.appendHexPrefix(token.tokenAddress);
139
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
140
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
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);
141
143
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
142
144
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
143
145
  const contractAddress = this.getLockProxyAddress();
@@ -188,16 +190,16 @@ class ETHClient {
188
190
  return "insufficient balance";
189
191
  }
190
192
  const networkConfig = this.getNetworkConfig();
191
- const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
192
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
193
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
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);
194
196
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
195
197
  const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
196
198
  const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
197
199
  // logger("sendDeposit message", message)
198
200
  let signatureResult;
199
201
  const { address, signature } = yield getSignatureCallback(message);
200
- const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
202
+ const signatureBytes = ethers_1.ethers.utils.arrayify((0, generic_1.appendHexPrefix)(signature));
201
203
  const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
202
204
  // logger("sign result", address, signature)
203
205
  signatureResult = {
@@ -236,7 +238,7 @@ class ETHClient {
236
238
  if (!feeInfo.deposit_fee) {
237
239
  throw new Error("unsupported token");
238
240
  }
239
- if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
241
+ if ((0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
240
242
  throw new Error("unsupported token");
241
243
  }
242
244
  let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
@@ -302,7 +304,7 @@ class ETHClient {
302
304
  getTargetProxyHash(token) {
303
305
  const networkConfig = this.getNetworkConfig();
304
306
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
305
- const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
307
+ const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
306
308
  return addressHex;
307
309
  }
308
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 dayjs_1.default(value);
32
+ return (0, 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: dayjs_1.default(entry.time),
104
+ time: (0, dayjs_1.default)(entry.time),
105
105
  volumeValue: new bignumber_js_1.default(entry.volumeValue)
106
106
  }));
107
107
  const parsedMeta = {
108
- from: dayjs_1.default(meta.from),
109
- until: dayjs_1.default(meta.until),
108
+ from: (0, dayjs_1.default)(meta.from),
109
+ until: (0, dayjs_1.default)(meta.until),
110
110
  interval: meta.interval,
111
111
  };
112
112
  return { result: { entries: parsedEntries, meta: parsedMeta } };
@@ -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
- blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
71
+ (0, 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 = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
77
+ const promises = (0, 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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
120
- const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
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));
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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
165
+ const toAddress = (0, 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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
201
+ const toAddress = (0, 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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
316
+ const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
317
317
  return addressHex;
318
318
  }
319
319
  getNetworkConfig() {
@@ -544,7 +544,7 @@ class TokenClient {
544
544
  if (!token)
545
545
  return undefined;
546
546
  const bridge = this.getBridgeFromToken(token);
547
- if (!bridge || !blockchain_1.isIbcBridge(bridge))
547
+ if (!bridge || !(0, 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] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
623
+ newPrev[price.denom] = (0, number_1.bnOrZero)(price.twap).shiftedBy(-constant_1.decTypeDecimals);
624
624
  return newPrev;
625
625
  }, {});
626
626
  }
@@ -77,12 +77,12 @@ class ZILClient {
77
77
  ?
78
78
  !!sdk.token.getBlockchainV2(token.denom) && (blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[sdk.token.getBlockchainV2(token.denom)] == this.blockchain)
79
79
  :
80
- blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain;
80
+ (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), sdk.network) == this.blockchain;
81
81
  return isCorrectBlockchain && token.tokenAddress.length == 40 && (!whitelistDenoms || whitelistDenoms.includes(token.denom));
82
82
  });
83
83
  const requests = tokens.map((token) => token.tokenAddress === zeroAddress
84
- ? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
85
- : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
84
+ ? (0, exports.balanceBatchRequest)(address.replace(/^0x/i, ""))
85
+ : (0, exports.tokenBalanceBatchRequest)(token.tokenAddress, address));
86
86
  const response = yield fetch(this.getProviderUrl(), {
87
87
  method: "post",
88
88
  headers: { "content-type": "application/json" },
@@ -107,7 +107,7 @@ class ZILClient {
107
107
  // if (!isValidAddress) {
108
108
  // throw new Error("invalid address")
109
109
  // }
110
- return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
110
+ return (0, zilliqa_1.fromBech32Address)(bech32Address).toLowerCase().substr(2);
111
111
  });
112
112
  }
113
113
  // see examplesV2/zil_client.ts on how to confirm the transactions
@@ -153,7 +153,7 @@ class ZILClient {
153
153
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
154
154
  }
155
155
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
156
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
156
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
157
157
  if (balanceAndNonceResp.error !== undefined) {
158
158
  throw new Error(balanceAndNonceResp.error.message);
159
159
  }
@@ -171,7 +171,7 @@ class ZILClient {
171
171
  vname: "spender",
172
172
  type: "ByStr20",
173
173
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
174
- value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
174
+ value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : (0, generic_1.appendHexPrefix)(token.bridgeAddress),
175
175
  },
176
176
  {
177
177
  vname: "amount",
@@ -189,7 +189,7 @@ class ZILClient {
189
189
  }
190
190
  checkAllowanceZRC2(token, owner, spender) {
191
191
  return __awaiter(this, void 0, void 0, function* () {
192
- const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
192
+ const contractAddress = (0, generic_1.appendHexPrefix)(token.tokenAddress);
193
193
  const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
194
194
  const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
195
195
  if (resp.error !== undefined) {
@@ -211,13 +211,13 @@ class ZILClient {
211
211
  }
212
212
  const carbonNetwork = networkConfig.network;
213
213
  const fromTokenId = fromToken.id;
214
- const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
214
+ const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
215
215
  const toTokenDenom = toToken.denom;
216
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
216
+ const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
217
217
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
218
218
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
219
219
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
220
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
220
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
221
221
  const contractAddress = this.getBridgeEntranceAddr();
222
222
  let zilliqa;
223
223
  if (typeof signer === "string") {
@@ -232,7 +232,7 @@ class ZILClient {
232
232
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
233
233
  }
234
234
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
235
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
235
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(fromAddress));
236
236
  if (balanceAndNonceResp.error !== undefined) {
237
237
  throw new Error(balanceAndNonceResp.error.message);
238
238
  }
@@ -309,13 +309,13 @@ class ZILClient {
309
309
  return __awaiter(this, void 0, void 0, function* () {
310
310
  const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
311
311
  const networkConfig = this.getNetworkConfig();
312
- const assetId = generic_1.appendHexPrefix(token.tokenAddress);
313
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
314
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
312
+ const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
313
+ const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
314
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
315
315
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
316
316
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
317
317
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
318
- const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
318
+ const contractAddress = (0, generic_1.appendHexPrefix)(token.bridgeAddress);
319
319
  let zilliqa;
320
320
  if (typeof signer === "string") {
321
321
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
@@ -329,7 +329,7 @@ class ZILClient {
329
329
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
330
330
  }
331
331
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
332
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
332
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
333
333
  if (balanceAndNonceResp.error !== undefined) {
334
334
  throw new Error(balanceAndNonceResp.error.message);
335
335
  }
@@ -414,7 +414,7 @@ class ZILClient {
414
414
  getTargetProxyHash(token) {
415
415
  const networkConfig = this.getNetworkConfig();
416
416
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
417
- const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
417
+ const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
418
418
  return addressHex;
419
419
  }
420
420
  getNetworkConfig() {
@@ -13,9 +13,14 @@ export interface OrderBook {
13
13
  }
14
14
  export interface StopBook {
15
15
  market: string;
16
- asks: string[];
17
- bids: string[];
16
+ asks: StopOrder[];
17
+ bids: StopOrder[];
18
18
  trigger: string;
19
+ stopType: string;
20
+ }
21
+ export interface StopOrder {
22
+ id: string;
23
+ stopPrice: string;
19
24
  }
20
25
  export declare const OrderBookLevel: {
21
26
  encode(message: OrderBookLevel, writer?: _m0.Writer): _m0.Writer;
@@ -38,6 +43,13 @@ export declare const StopBook: {
38
43
  toJSON(message: StopBook): unknown;
39
44
  fromPartial(object: DeepPartial<StopBook>): StopBook;
40
45
  };
46
+ export declare const StopOrder: {
47
+ encode(message: StopOrder, writer?: _m0.Writer): _m0.Writer;
48
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): StopOrder;
49
+ fromJSON(object: any): StopOrder;
50
+ toJSON(message: StopOrder): unknown;
51
+ fromPartial(object: DeepPartial<StopOrder>): StopOrder;
52
+ };
41
53
  declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
42
54
  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 {} ? {
43
55
  [K in keyof T]?: DeepPartial<T[K]>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.StopBook = exports.OrderBook = exports.OrderBookLevel = exports.protobufPackage = void 0;
6
+ exports.StopOrder = exports.StopBook = exports.OrderBook = exports.OrderBookLevel = exports.protobufPackage = void 0;
7
7
  /* eslint-disable */
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const minimal_1 = __importDefault(require("protobufjs/minimal"));
@@ -158,21 +158,24 @@ exports.OrderBook = {
158
158
  return message;
159
159
  },
160
160
  };
161
- const baseStopBook = { market: "", asks: "", bids: "", trigger: "" };
161
+ const baseStopBook = { market: "", trigger: "", stopType: "" };
162
162
  exports.StopBook = {
163
163
  encode(message, writer = minimal_1.default.Writer.create()) {
164
164
  if (message.market !== "") {
165
165
  writer.uint32(10).string(message.market);
166
166
  }
167
167
  for (const v of message.asks) {
168
- writer.uint32(18).string(v);
168
+ exports.StopOrder.encode(v, writer.uint32(18).fork()).ldelim();
169
169
  }
170
170
  for (const v of message.bids) {
171
- writer.uint32(26).string(v);
171
+ exports.StopOrder.encode(v, writer.uint32(26).fork()).ldelim();
172
172
  }
173
173
  if (message.trigger !== "") {
174
174
  writer.uint32(34).string(message.trigger);
175
175
  }
176
+ if (message.stopType !== "") {
177
+ writer.uint32(42).string(message.stopType);
178
+ }
176
179
  return writer;
177
180
  },
178
181
  decode(input, length) {
@@ -188,14 +191,17 @@ exports.StopBook = {
188
191
  message.market = reader.string();
189
192
  break;
190
193
  case 2:
191
- message.asks.push(reader.string());
194
+ message.asks.push(exports.StopOrder.decode(reader, reader.uint32()));
192
195
  break;
193
196
  case 3:
194
- message.bids.push(reader.string());
197
+ message.bids.push(exports.StopOrder.decode(reader, reader.uint32()));
195
198
  break;
196
199
  case 4:
197
200
  message.trigger = reader.string();
198
201
  break;
202
+ case 5:
203
+ message.stopType = reader.string();
204
+ break;
199
205
  default:
200
206
  reader.skipType(tag & 7);
201
207
  break;
@@ -210,39 +216,100 @@ exports.StopBook = {
210
216
  object.market !== undefined && object.market !== null
211
217
  ? String(object.market)
212
218
  : "";
213
- message.asks = ((_a = object.asks) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
214
- message.bids = ((_b = object.bids) !== null && _b !== void 0 ? _b : []).map((e) => String(e));
219
+ message.asks = ((_a = object.asks) !== null && _a !== void 0 ? _a : []).map((e) => exports.StopOrder.fromJSON(e));
220
+ message.bids = ((_b = object.bids) !== null && _b !== void 0 ? _b : []).map((e) => exports.StopOrder.fromJSON(e));
215
221
  message.trigger =
216
222
  object.trigger !== undefined && object.trigger !== null
217
223
  ? String(object.trigger)
218
224
  : "";
225
+ message.stopType =
226
+ object.stopType !== undefined && object.stopType !== null
227
+ ? String(object.stopType)
228
+ : "";
219
229
  return message;
220
230
  },
221
231
  toJSON(message) {
222
232
  const obj = {};
223
233
  message.market !== undefined && (obj.market = message.market);
224
234
  if (message.asks) {
225
- obj.asks = message.asks.map((e) => e);
235
+ obj.asks = message.asks.map((e) => (e ? exports.StopOrder.toJSON(e) : undefined));
226
236
  }
227
237
  else {
228
238
  obj.asks = [];
229
239
  }
230
240
  if (message.bids) {
231
- obj.bids = message.bids.map((e) => e);
241
+ obj.bids = message.bids.map((e) => (e ? exports.StopOrder.toJSON(e) : undefined));
232
242
  }
233
243
  else {
234
244
  obj.bids = [];
235
245
  }
236
246
  message.trigger !== undefined && (obj.trigger = message.trigger);
247
+ message.stopType !== undefined && (obj.stopType = message.stopType);
237
248
  return obj;
238
249
  },
239
250
  fromPartial(object) {
240
- var _a, _b, _c, _d;
251
+ var _a, _b, _c, _d, _e;
241
252
  const message = Object.assign({}, baseStopBook);
242
253
  message.market = (_a = object.market) !== null && _a !== void 0 ? _a : "";
243
- message.asks = ((_b = object.asks) !== null && _b !== void 0 ? _b : []).map((e) => e);
244
- message.bids = ((_c = object.bids) !== null && _c !== void 0 ? _c : []).map((e) => e);
254
+ message.asks = ((_b = object.asks) !== null && _b !== void 0 ? _b : []).map((e) => exports.StopOrder.fromPartial(e));
255
+ message.bids = ((_c = object.bids) !== null && _c !== void 0 ? _c : []).map((e) => exports.StopOrder.fromPartial(e));
245
256
  message.trigger = (_d = object.trigger) !== null && _d !== void 0 ? _d : "";
257
+ message.stopType = (_e = object.stopType) !== null && _e !== void 0 ? _e : "";
258
+ return message;
259
+ },
260
+ };
261
+ const baseStopOrder = { id: "", stopPrice: "" };
262
+ exports.StopOrder = {
263
+ encode(message, writer = minimal_1.default.Writer.create()) {
264
+ if (message.id !== "") {
265
+ writer.uint32(10).string(message.id);
266
+ }
267
+ if (message.stopPrice !== "") {
268
+ writer.uint32(18).string(message.stopPrice);
269
+ }
270
+ return writer;
271
+ },
272
+ decode(input, length) {
273
+ const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
274
+ let end = length === undefined ? reader.len : reader.pos + length;
275
+ const message = Object.assign({}, baseStopOrder);
276
+ while (reader.pos < end) {
277
+ const tag = reader.uint32();
278
+ switch (tag >>> 3) {
279
+ case 1:
280
+ message.id = reader.string();
281
+ break;
282
+ case 2:
283
+ message.stopPrice = reader.string();
284
+ break;
285
+ default:
286
+ reader.skipType(tag & 7);
287
+ break;
288
+ }
289
+ }
290
+ return message;
291
+ },
292
+ fromJSON(object) {
293
+ const message = Object.assign({}, baseStopOrder);
294
+ message.id =
295
+ object.id !== undefined && object.id !== null ? String(object.id) : "";
296
+ message.stopPrice =
297
+ object.stopPrice !== undefined && object.stopPrice !== null
298
+ ? String(object.stopPrice)
299
+ : "";
300
+ return message;
301
+ },
302
+ toJSON(message) {
303
+ const obj = {};
304
+ message.id !== undefined && (obj.id = message.id);
305
+ message.stopPrice !== undefined && (obj.stopPrice = message.stopPrice);
306
+ return obj;
307
+ },
308
+ fromPartial(object) {
309
+ var _a, _b;
310
+ const message = Object.assign({}, baseStopOrder);
311
+ message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
312
+ message.stopPrice = (_b = object.stopPrice) !== null && _b !== void 0 ? _b : "";
246
313
  return message;
247
314
  },
248
315
  };
@@ -0,0 +1,22 @@
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal";
3
+ export declare const protobufPackage = "Switcheo.carbon.book";
4
+ export interface StopbookV2320 {
5
+ market: string;
6
+ asks: string[];
7
+ bids: string[];
8
+ trigger: string;
9
+ stopType: string;
10
+ }
11
+ export declare const StopbookV2320: {
12
+ encode(message: StopbookV2320, writer?: _m0.Writer): _m0.Writer;
13
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): StopbookV2320;
14
+ fromJSON(object: any): StopbookV2320;
15
+ toJSON(message: StopbookV2320): unknown;
16
+ fromPartial(object: DeepPartial<StopbookV2320>): StopbookV2320;
17
+ };
18
+ declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
19
+ 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 {} ? {
20
+ [K in keyof T]?: DeepPartial<T[K]>;
21
+ } : Partial<T>;
22
+ export {};