carbon-js-sdk 0.2.18-dev.0 → 0.3.0

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 (50) hide show
  1. package/lib/clients/CarbonQueryClient.js +2 -2
  2. package/lib/clients/ETHClient.js +15 -15
  3. package/lib/clients/HydrogenClient.js +1 -1
  4. package/lib/clients/NEOClient.js +6 -6
  5. package/lib/clients/ZILClient.js +16 -16
  6. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  7. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  8. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  9. package/lib/constant/generic.js +1 -1
  10. package/lib/modules/cdp.js +45 -45
  11. package/lib/modules/gov.js +14 -14
  12. package/lib/modules/liquiditypool.js +1 -1
  13. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  14. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  15. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  16. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  17. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  18. package/lib/provider/amino/types/admin.js +30 -30
  19. package/lib/provider/amino/types/bank.js +1 -1
  20. package/lib/provider/amino/types/broker.js +1 -1
  21. package/lib/provider/amino/types/cdp.js +22 -22
  22. package/lib/provider/amino/types/coin.js +2 -2
  23. package/lib/provider/amino/types/gov.js +4 -4
  24. package/lib/provider/amino/types/ibc.js +1 -1
  25. package/lib/provider/amino/types/leverage.js +1 -1
  26. package/lib/provider/amino/types/liquidityPool.js +7 -7
  27. package/lib/provider/amino/types/market.js +1 -1
  28. package/lib/provider/amino/types/oracle.js +1 -1
  29. package/lib/provider/amino/types/order.js +4 -4
  30. package/lib/provider/amino/types/position.js +1 -1
  31. package/lib/provider/amino/types/profile.js +1 -1
  32. package/lib/provider/amino/types/staking.js +4 -4
  33. package/lib/provider/amino/types/subaccount.js +3 -3
  34. package/lib/provider/amino/utils.js +11 -11
  35. package/lib/provider/keplr/KeplrStore.js +1 -1
  36. package/lib/provider/ledger/ledger.js +2 -2
  37. package/lib/provider/metamask/MetaMask.js +1 -1
  38. package/lib/provider/o3/O3Wallet.js +2 -2
  39. package/lib/util/address.js +13 -13
  40. package/lib/util/api.js +4 -4
  41. package/lib/util/fetch.js +1 -1
  42. package/lib/util/generic.js +3 -3
  43. package/lib/util/number.js +5 -5
  44. package/lib/wallet/CarbonSigner.js +2 -2
  45. package/lib/wallet/CarbonSigningClient.js +8 -8
  46. package/lib/wallet/CarbonWallet.js +6 -6
  47. package/lib/websocket/connector.js +3 -3
  48. package/package.json +1 -1
  49. package/lib/codec/bank/tx.d.ts +0 -64
  50. package/lib/codec/bank/tx.js +0 -236
@@ -44,7 +44,7 @@ class CarbonQueryClient {
44
44
  constructor(tmClient) {
45
45
  this.tmClient = tmClient;
46
46
  this.baseClient = new stargate_1.QueryClient(this.tmClient);
47
- const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
47
+ const rpcClient = (0, stargate_1.createProtobufRpcClient)(this.baseClient);
48
48
  this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
49
49
  this.adl = new query_1.QueryClientImpl(rpcClient);
50
50
  this.book = new query_2.QueryClientImpl(rpcClient);
@@ -85,7 +85,7 @@ class CarbonQueryClient {
85
85
  };
86
86
  }
87
87
  getProtobufRpcClient() {
88
- return stargate_1.createProtobufRpcClient(this.baseClient);
88
+ return (0, stargate_1.createProtobufRpcClient)(this.baseClient);
89
89
  }
90
90
  }
91
91
  exports.default = CarbonQueryClient;
@@ -40,13 +40,13 @@ class ETHClient {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  const tokenQueryResults = yield api.token.getAllTokens();
42
42
  const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
43
- const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
43
+ const tokens = tokenQueryResults.filter((token) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
44
44
  token.tokenAddress.length == 40 &&
45
- token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
45
+ token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
46
46
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
47
- this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
47
+ this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress)));
48
48
  const assetIds = tokens.map((token) => {
49
- return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
49
+ return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
50
50
  });
51
51
  const provider = this.getProvider();
52
52
  const contractAddress = this.getBalanceReaderAddress();
@@ -95,14 +95,14 @@ class ETHClient {
95
95
  throw new Error("Invalid recovery address");
96
96
  }
97
97
  const fromTokenId = fromToken.id;
98
- const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
98
+ const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
99
99
  const toTokenDenom = toToken.denom;
100
100
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
101
101
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
102
102
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
103
103
  const nonce = yield rpcProvider.getTransactionCount(fromAddress);
104
104
  const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
105
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
105
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
106
106
  const tokenCreator = fromToken.creator;
107
107
  const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, CarbonSDK_1.default.Network.MainNet);
108
108
  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 = generic_1.appendHexPrefix(token.tokenAddress);
141
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
142
- 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);
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 = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
194
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
195
- 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);
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(generic_1.appendHexPrefix(signature));
202
+ const signatureBytes = ethers_1.ethers.utils.arrayify((0, 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 (blockchain_1.blockchainForChainId(token.chainId.toNumber()) !== this.blockchain) {
241
+ if ((0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) !== 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 = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
307
+ const addressHex = (0, 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 dayjs_1.default(value);
32
+ return (0, dayjs_1.default)(value);
33
33
  };
34
34
  const formatCrossChainTransfer = (value) => {
35
35
  var _a, _b;
@@ -63,13 +63,13 @@ class NEOClient {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
64
  const tokenQueryResults = yield sdk.token.getAllTokens();
65
65
  const account = new Neon.wallet.Account(address);
66
- const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
66
+ const tokens = tokenQueryResults.filter(token => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
67
67
  token.tokenAddress.length == 40 &&
68
68
  token.bridgeAddress.length == 40);
69
69
  const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
70
70
  // NOTE: fetching of tokens is chunked in sets of 15 as we may hit
71
71
  // the gas limit on the RPC node and error out otherwise
72
- const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
72
+ const promises = (0, lodash_1.chunk)(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
73
73
  var _a, _b, _c;
74
74
  let acc = {};
75
75
  for (const token of partition) {
@@ -110,7 +110,7 @@ class NEOClient {
110
110
  const targetProxyHash = this.getTargetProxyHash(token);
111
111
  const toAssetHash = Neon.u.str2hexstring(token.id);
112
112
  const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
113
- const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
113
+ const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
114
114
  const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
115
115
  const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
116
116
  const feeAddress = networkConfig.feeAddress;
@@ -157,7 +157,7 @@ class NEOClient {
157
157
  const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
158
158
  const targetProxyHash = this.getTargetProxyHash(token);
159
159
  const toAssetHash = Neon.u.str2hexstring(token.id);
160
- const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
160
+ const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
161
161
  const nonce = Math.floor(Math.random() * 1000000);
162
162
  if (amount.lt(feeAmount)) {
163
163
  throw new Error("Invalid amount");
@@ -193,7 +193,7 @@ class NEOClient {
193
193
  const fromAddress = ledger.scriptHash;
194
194
  const targetProxyHash = this.getTargetProxyHash(token);
195
195
  const toAssetHash = Neon.u.str2hexstring(token.id);
196
- const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
196
+ const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
197
197
  const feeAddress = networkConfig.feeAddress;
198
198
  const nonce = Math.floor(Math.random() * 1000000);
199
199
  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() {
@@ -74,10 +74,10 @@ class ZILClient {
74
74
  getExternalBalances(sdk, address, whitelistDenoms) {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
76
  const tokenQueryResults = yield sdk.token.getAllTokens();
77
- const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
77
+ const tokens = tokenQueryResults.filter(token => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
78
78
  token.tokenAddress.length == 40 &&
79
79
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)));
80
- const requests = tokens.map(token => token.tokenAddress === zeroAddress ? exports.balanceBatchRequest(address.replace(/^0x/i, "")) : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
80
+ const requests = tokens.map(token => token.tokenAddress === zeroAddress ? (0, exports.balanceBatchRequest)(address.replace(/^0x/i, "")) : (0, exports.tokenBalanceBatchRequest)(token.tokenAddress, address));
81
81
  const response = yield fetch(this.getProviderUrl(), {
82
82
  method: "post",
83
83
  headers: { "content-type": "application/json" },
@@ -102,7 +102,7 @@ class ZILClient {
102
102
  // if (!isValidAddress) {
103
103
  // throw new Error("invalid address")
104
104
  // }
105
- return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
105
+ return (0, zilliqa_1.fromBech32Address)(bech32Address).toLowerCase().substr(2);
106
106
  });
107
107
  }
108
108
  // see examplesV2/zil_client.ts on how to confirm the transactions
@@ -148,7 +148,7 @@ class ZILClient {
148
148
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
149
149
  }
150
150
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
151
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
151
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
152
152
  if (balanceAndNonceResp.error !== undefined) {
153
153
  throw new Error(balanceAndNonceResp.error.message);
154
154
  }
@@ -166,7 +166,7 @@ class ZILClient {
166
166
  vname: 'spender',
167
167
  type: 'ByStr20',
168
168
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
169
- value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
169
+ value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : (0, generic_1.appendHexPrefix)(token.bridgeAddress),
170
170
  },
171
171
  {
172
172
  vname: 'amount',
@@ -184,7 +184,7 @@ class ZILClient {
184
184
  }
185
185
  checkAllowanceZRC2(token, owner, spender) {
186
186
  return __awaiter(this, void 0, void 0, function* () {
187
- const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
187
+ const contractAddress = (0, generic_1.appendHexPrefix)(token.tokenAddress);
188
188
  const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
189
189
  const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
190
190
  if (resp.error !== undefined) {
@@ -204,13 +204,13 @@ class ZILClient {
204
204
  throw new Error("Invalid recovery address");
205
205
  }
206
206
  const fromTokenId = fromToken.id;
207
- const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
207
+ const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
208
208
  const toTokenDenom = toToken.denom;
209
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
209
+ const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
210
210
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
211
211
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
212
212
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
213
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
213
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
214
214
  const contractAddress = this.getBridgeEntranceAddr();
215
215
  let zilliqa;
216
216
  if (typeof signer === 'string') {
@@ -225,7 +225,7 @@ class ZILClient {
225
225
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
226
226
  }
227
227
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
228
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
228
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(fromAddress));
229
229
  if (balanceAndNonceResp.error !== undefined) {
230
230
  throw new Error(balanceAndNonceResp.error.message);
231
231
  }
@@ -302,13 +302,13 @@ class ZILClient {
302
302
  return __awaiter(this, void 0, void 0, function* () {
303
303
  const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
304
304
  const networkConfig = this.getNetworkConfig();
305
- const assetId = generic_1.appendHexPrefix(token.tokenAddress);
306
- const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
307
- const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
305
+ const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
306
+ const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
307
+ const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
308
308
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
309
309
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
310
310
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
311
- const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
311
+ const contractAddress = (0, generic_1.appendHexPrefix)(token.bridgeAddress);
312
312
  let zilliqa;
313
313
  if (typeof signer === 'string') {
314
314
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
@@ -322,7 +322,7 @@ class ZILClient {
322
322
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
323
323
  }
324
324
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
325
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
325
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
326
326
  if (balanceAndNonceResp.error !== undefined) {
327
327
  throw new Error(balanceAndNonceResp.error.message);
328
328
  }
@@ -407,7 +407,7 @@ class ZILClient {
407
407
  getTargetProxyHash(token) {
408
408
  const networkConfig = this.getNetworkConfig();
409
409
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
410
- const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
410
+ const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
411
411
  return addressHex;
412
412
  }
413
413
  getNetworkConfig() {
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
159
159
  const message = Object.assign({}, baseQueryProposalsRequest);
160
160
  message.proposalStatus =
161
161
  object.proposalStatus !== undefined && object.proposalStatus !== null
162
- ? gov_1.proposalStatusFromJSON(object.proposalStatus)
162
+ ? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
163
163
  : 0;
164
164
  message.voter =
165
165
  object.voter !== undefined && object.voter !== null
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
178
178
  toJSON(message) {
179
179
  const obj = {};
180
180
  message.proposalStatus !== undefined &&
181
- (obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
181
+ (obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
182
182
  message.voter !== undefined && (obj.voter = message.voter);
183
183
  message.depositor !== undefined && (obj.depositor = message.depositor);
184
184
  message.pagination !== undefined &&
@@ -185,7 +185,7 @@ exports.MsgVote = {
185
185
  : "";
186
186
  message.option =
187
187
  object.option !== undefined && object.option !== null
188
- ? gov_1.voteOptionFromJSON(object.option)
188
+ ? (0, gov_1.voteOptionFromJSON)(object.option)
189
189
  : 0;
190
190
  return message;
191
191
  },
@@ -195,7 +195,7 @@ exports.MsgVote = {
195
195
  (obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
196
196
  message.voter !== undefined && (obj.voter = message.voter);
197
197
  message.option !== undefined &&
198
- (obj.option = gov_1.voteOptionToJSON(message.option));
198
+ (obj.option = (0, gov_1.voteOptionToJSON)(message.option));
199
199
  return obj;
200
200
  },
201
201
  fromPartial(object) {
@@ -618,13 +618,13 @@ exports.ModeInfo_Single = {
618
618
  const message = Object.assign({}, baseModeInfo_Single);
619
619
  message.mode =
620
620
  object.mode !== undefined && object.mode !== null
621
- ? signing_1.signModeFromJSON(object.mode)
621
+ ? (0, signing_1.signModeFromJSON)(object.mode)
622
622
  : 0;
623
623
  return message;
624
624
  },
625
625
  toJSON(message) {
626
626
  const obj = {};
627
- message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
627
+ message.mode !== undefined && (obj.mode = (0, signing_1.signModeToJSON)(message.mode));
628
628
  return obj;
629
629
  },
630
630
  fromPartial(object) {
@@ -12,7 +12,7 @@ exports.DEFAULT_FEE_DENOM = "swth";
12
12
  exports.DEFAULT_GAS_PRICE = new bignumber_js_1.default(10);
13
13
  exports.DEFAULT_GAS = new bignumber_js_1.default(10000000);
14
14
  exports.DEFAULT_FEE = {
15
- amount: proto_signing_1.coins(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
15
+ amount: (0, proto_signing_1.coins)(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
16
16
  gas: exports.DEFAULT_GAS.toString(10),
17
17
  };
18
18
  exports.CURRENT_GAS_PRICE = 769.23077;
@@ -336,7 +336,7 @@ class CDPModule extends base_1.default {
336
336
  let availableBorrowsUsd = number_1.BN_ZERO;
337
337
  let currLiquidationThreshold = number_1.BN_ZERO;
338
338
  for (let i = 0; i < collaterals.length; i++) {
339
- const amount = number_1.bnOrZero(collaterals[i].collateralAmount);
339
+ const amount = (0, number_1.bnOrZero)(collaterals[i].collateralAmount);
340
340
  if (amount.isZero()) {
341
341
  continue; // no collateral for denom
342
342
  }
@@ -353,9 +353,9 @@ class CDPModule extends base_1.default {
353
353
  if (!assetParam) {
354
354
  continue;
355
355
  }
356
- const ltv = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
356
+ const ltv = (0, number_1.bnOrZero)(assetParam.loanToValue).div(number_1.BN_10000);
357
357
  const availableBorrowUsd = collateralUsdVal.times(ltv);
358
- const liquidationThreshold = number_1.bnOrZero(assetParam.liquidationThreshold).div(number_1.BN_10000);
358
+ const liquidationThreshold = (0, number_1.bnOrZero)(assetParam.liquidationThreshold).div(number_1.BN_10000);
359
359
  const liquidationThresholdVal = collateralUsdVal.times(liquidationThreshold);
360
360
  totalCollateralsUsd = totalCollateralsUsd.plus(collateralUsdVal);
361
361
  availableBorrowsUsd = availableBorrowsUsd.plus(availableBorrowUsd);
@@ -366,7 +366,7 @@ class CDPModule extends base_1.default {
366
366
  const debts = debtsRsp.debts;
367
367
  let totalDebtsUsd = number_1.BN_ZERO;
368
368
  for (let i = 0; i < debts.length; i++) {
369
- const amount = number_1.bnOrZero(debts[i].principalDebt);
369
+ const amount = (0, number_1.bnOrZero)(debts[i].principalDebt);
370
370
  const denom = debts[i].denom;
371
371
  if (amount.isZero()) {
372
372
  continue;
@@ -388,7 +388,7 @@ class CDPModule extends base_1.default {
388
388
  if (stablecoinDebtInfo) {
389
389
  const accountStablecoin = yield sdk.query.cdp.AccountStablecoin({ address: account });
390
390
  const stablecoinDecimals = (_a = yield this.sdkProvider.getTokenClient().getDecimals(stablecoinDebtInfo.denom)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
391
- const stablecoinDebtAmount = number_1.bnOrZero(accountStablecoin.principalDebt).plus(number_1.bnOrZero(accountStablecoin.interestDebt));
391
+ const stablecoinDebtAmount = (0, number_1.bnOrZero)(accountStablecoin.principalDebt).plus((0, number_1.bnOrZero)(accountStablecoin.interestDebt));
392
392
  stablecoinDebtUsd = stablecoinDebtAmount.shiftedBy(-stablecoinDecimals);
393
393
  totalDebtsUsd = totalDebtsUsd.plus(stablecoinDebtUsd);
394
394
  }
@@ -409,7 +409,7 @@ class CDPModule extends base_1.default {
409
409
  const sdk = this.sdkProvider;
410
410
  const cdpAddress = this.getCdpModuleAddress();
411
411
  const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
412
- return number_1.bnOrZero((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
412
+ return (0, number_1.bnOrZero)((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
413
413
  });
414
414
  }
415
415
  getCdpToActualRatio(cdpDenom) {
@@ -420,13 +420,13 @@ class CDPModule extends base_1.default {
420
420
  const cdpAmountRsp = supplyRsp.amount;
421
421
  if (!cdpAmountRsp)
422
422
  throw new Error("unable to retrieve cdp token supply");
423
- const cdpAmount = number_1.bnOrZero(cdpAmountRsp.amount);
423
+ const cdpAmount = (0, number_1.bnOrZero)(cdpAmountRsp.amount);
424
424
  const cdpAddress = this.getCdpModuleAddress();
425
425
  const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
426
426
  if (!balanceRsp.balance)
427
427
  throw new Error("unable to retrieve cdp module balance");
428
428
  const owedAmount = yield this.getTotalTokenDebt(denom);
429
- const actualAmount = number_1.bnOrZero(balanceRsp.balance.amount).plus(owedAmount);
429
+ const actualAmount = (0, number_1.bnOrZero)(balanceRsp.balance.amount).plus(owedAmount);
430
430
  if (!owedAmount)
431
431
  throw new Error("unable to retrieve total token debt");
432
432
  return cdpAmount.div(actualAmount);
@@ -448,8 +448,8 @@ class CDPModule extends base_1.default {
448
448
  const allDebts = allDebtsRes.debtInfosAll;
449
449
  for (let i = 0; i < allDebts.length; i++) {
450
450
  const denom = allDebts[i].denom;
451
- const interest = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
452
- const principal = number_1.bnOrZero(allDebts[i].totalPrincipal);
451
+ const interest = (0, number_1.bnOrZero)(allDebts[i].totalAccumulatedInterest);
452
+ const principal = (0, number_1.bnOrZero)(allDebts[i].totalPrincipal);
453
453
  const debtAmt = interest.plus(principal);
454
454
  const debtUsdVal = yield this.getTokenUsdVal(denom, debtAmt);
455
455
  if (!debtUsdVal) {
@@ -461,7 +461,7 @@ class CDPModule extends base_1.default {
461
461
  const stablecoinDebtRes = yield this.sdkProvider.query.cdp.StablecoinDebt({});
462
462
  if (stablecoinDebtRes.stablecoinDebtInfo) {
463
463
  const debtInfo = stablecoinDebtRes.stablecoinDebtInfo;
464
- const debtAmt = number_1.bnOrZero(debtInfo.totalPrincipal).plus(number_1.bnOrZero(debtInfo.totalAccumulatedInterest));
464
+ const debtAmt = (0, number_1.bnOrZero)(debtInfo.totalPrincipal).plus((0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest));
465
465
  const stablecoinDecimals = (_a = yield sdk.getTokenClient().getDecimals(debtInfo.denom)) !== null && _a !== void 0 ? _a : 0;
466
466
  const debtUsdVal = (debtAmt).shiftedBy(-stablecoinDecimals);
467
467
  totalDebt = totalDebt.plus(debtUsdVal);
@@ -479,7 +479,7 @@ class CDPModule extends base_1.default {
479
479
  if (!TokenClient_1.default.isCdpToken(balance.denom)) {
480
480
  continue;
481
481
  }
482
- const amount = number_1.bnOrZero(balance.amount);
482
+ const amount = (0, number_1.bnOrZero)(balance.amount);
483
483
  const collateralUsdValue = yield this.getCdpTokenUsdVal(balance.denom, amount);
484
484
  allCollateralsUsdValue = allCollateralsUsdValue.plus(collateralUsdValue);
485
485
  }
@@ -503,7 +503,7 @@ class CDPModule extends base_1.default {
503
503
  const priceResult = yield sdk.query.pricing.TokenPrice(codec_1.QueryTokenPriceRequest.fromPartial({ denom }));
504
504
  if (!priceResult.tokenPrice)
505
505
  throw new Error("unable to retrieve token price for " + denom);
506
- const twap = number_1.bnOrZero(priceResult.tokenPrice.twap).shiftedBy(-18);
506
+ const twap = (0, number_1.bnOrZero)(priceResult.tokenPrice.twap).shiftedBy(-18);
507
507
  return amount.multipliedBy(twap).shiftedBy(-decimals);
508
508
  });
509
509
  }
@@ -516,12 +516,12 @@ class CDPModule extends base_1.default {
516
516
  }
517
517
  if (!debtInfo)
518
518
  throw new Error("unable to retrieve debt info");
519
- const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
520
- const accumInterest = number_1.bnOrZero(debtInfo.totalAccumulatedInterest);
519
+ const principal = (0, number_1.bnOrZero)(debtInfo.totalPrincipal);
520
+ const interest = principal.multipliedBy((0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier).shiftedBy(-18).minus(1));
521
521
  const cdpParamsRsp = yield this.sdkProvider.query.cdp.Params(query_1.QueryParamsRequest.fromPartial({}));
522
- const interestFee = number_1.bnOrZero((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
523
- const interest = accumInterest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
524
- return principal.plus(interest);
522
+ const interestFee = (0, number_1.bnOrZero)((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
523
+ const interestWithoutFee = interest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
524
+ return principal.plus(interestWithoutFee);
525
525
  });
526
526
  }
527
527
  getTotalAccountTokenDebt(account, denom, debt, debtInfo) {
@@ -537,8 +537,8 @@ class CDPModule extends base_1.default {
537
537
  const debtRes = yield sdk.query.cdp.AccountDebt({ address: account, denom: denom });
538
538
  debt = debtRes.debt;
539
539
  }
540
- const principalAmount = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
541
- const initialCIM = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
540
+ const principalAmount = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
541
+ const initialCIM = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
542
542
  if (principalAmount.isZero() || initialCIM.isZero())
543
543
  return number_1.BN_ZERO;
544
544
  const cim = yield this.recalculateCIM(denom, debtInfo);
@@ -563,8 +563,8 @@ class CDPModule extends base_1.default {
563
563
  const debtResp = yield sdk.query.cdp.AccountStablecoin(query_1.QueryAccountStablecoinRequest.fromPartial({ address: account }));
564
564
  debt = debtResp;
565
565
  }
566
- principalAmount = number_1.bnOrZero(debt.principalDebt);
567
- const initialCIM = number_1.bnOrZero(debt.initialCumulativeInterestMultiplier);
566
+ principalAmount = (0, number_1.bnOrZero)(debt.principalDebt);
567
+ const initialCIM = (0, number_1.bnOrZero)(debt.initialCumulativeInterestMultiplier);
568
568
  const cim = yield this.recalculateStablecoinCIM(debtInfo);
569
569
  if (!cim)
570
570
  throw new Error("unable to retrieve account debt");
@@ -605,7 +605,7 @@ class CDPModule extends base_1.default {
605
605
  return number_1.BN_ZERO;
606
606
  }
607
607
  const diffSeconds = new bignumber_js_1.BigNumber(diffMs).shiftedBy(-3).dp(0, bignumber_js_1.BigNumber.ROUND_CEIL);
608
- const secondsAYear = number_1.bnOrZero(31536000);
608
+ const secondsAYear = (0, number_1.bnOrZero)(31536000);
609
609
  const numPeriods = secondsAYear.div(diffSeconds).dp(18);
610
610
  return apy.div(numPeriods).dp(18); // carbon backend sdk.dec max 18 dp
611
611
  }
@@ -629,8 +629,8 @@ class CDPModule extends base_1.default {
629
629
  throw new Error("unable to retrieve cdp params for " + denom);
630
630
  }
631
631
  }
632
- const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
633
- const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
632
+ const interestFeeRate = (0, number_1.bnOrZero)(params.interestFee).div(number_1.BN_10000);
633
+ const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
634
634
  return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
635
635
  });
636
636
  }
@@ -645,7 +645,7 @@ class CDPModule extends base_1.default {
645
645
  return number_1.BN_ZERO;
646
646
  }
647
647
  }
648
- const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
648
+ const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
649
649
  const apy = yield this.calculateAPY(denom, debtInfo);
650
650
  const interest = CDPModule.calculateInterestForTimePeriod(apy, (_a = debtInfo.lastUpdatedTime) !== null && _a !== void 0 ? _a : new Date(0), new Date());
651
651
  const newCIM = cim.times(interest.plus(1));
@@ -664,8 +664,8 @@ class CDPModule extends base_1.default {
664
664
  }
665
665
  }
666
666
  const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
667
- const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
668
- const apy = number_1.bnOrZero((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
667
+ const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
668
+ const apy = (0, number_1.bnOrZero)((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
669
669
  if (!apy) {
670
670
  return number_1.BN_ZERO;
671
671
  }
@@ -691,7 +691,7 @@ class CDPModule extends base_1.default {
691
691
  const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
692
692
  const unlockableUsd = availableBorrowsUsd.multipliedBy(number_1.BN_10000).div(unlockRatio);
693
693
  const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom });
694
- const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
694
+ const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
695
695
  if (tokenTwap.isZero())
696
696
  throw new Error("unable to retrieve token price for " + denom);
697
697
  const tokenAmt = unlockableUsd.div(tokenTwap.shiftedBy(-18)).shiftedBy(tokenDecimals);
@@ -702,7 +702,7 @@ class CDPModule extends base_1.default {
702
702
  address: account,
703
703
  cdpDenom: cdpDenom
704
704
  });
705
- const lockedAmount = number_1.bnOrZero((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
705
+ const lockedAmount = (0, number_1.bnOrZero)((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
706
706
  return lockedAmount.lt(cdpTokenAmt) ? lockedAmount : cdpTokenAmt;
707
707
  });
708
708
  }
@@ -720,7 +720,7 @@ class CDPModule extends base_1.default {
720
720
  const denom = this.getUnderlyingDenom(cdpDenom);
721
721
  const cdpToActualRatio = (_a = yield this.getCdpToActualRatio(cdpDenom)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
722
722
  const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
723
- const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
723
+ const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
724
724
  return tokenTwap.multipliedBy(cdpToActualRatio);
725
725
  });
726
726
  }
@@ -741,26 +741,26 @@ class CDPModule extends base_1.default {
741
741
  });
742
742
  if (!asset.assetParams)
743
743
  throw new Error("unable to retrieve asset param for " + cdpActualDenom);
744
- const bonus = number_1.bnOrZero(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
744
+ const bonus = (0, number_1.bnOrZero)(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
745
745
  const cdpTokenPrice = yield this.getCdpTokenPrice(cdpDenom);
746
746
  const cdpTokenDiscountedPrice = cdpTokenPrice.multipliedBy(number_1.BN_ONE.minus(bonus));
747
747
  // get close factor
748
748
  const debtorAccountData = yield sdk.query.cdp.AccountData({
749
749
  address: debtor
750
750
  });
751
- const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
752
- const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
753
- const currentLiqThreshold = number_1.bnOrZero(debtorAccountData.currLiquidationThreshold);
751
+ const debtorTotalCollateralVal = (0, number_1.bnOrZero)(debtorAccountData.totalCollateralsUsd);
752
+ const debtorTotalDebtVal = (0, number_1.bnOrZero)(debtorAccountData.totalDebtsUsd);
753
+ const currentLiqThreshold = (0, number_1.bnOrZero)(debtorAccountData.currLiquidationThreshold);
754
754
  const params = yield sdk.query.cdp.Params({});
755
755
  if (!params.params) {
756
756
  throw new Error("unable to retrieve cdp params");
757
757
  }
758
- const smallLiqSize = number_1.bnOrZero(params.params.smallLiquidationSize);
759
- const minCloseFactor = number_1.bnOrZero(params.params.minimumCloseFactor);
760
- const completeLiqThreshold = number_1.bnOrZero(params.params.completeLiquidationThreshold);
758
+ const smallLiqSize = (0, number_1.bnOrZero)(params.params.smallLiquidationSize);
759
+ const minCloseFactor = (0, number_1.bnOrZero)(params.params.minimumCloseFactor);
760
+ const completeLiqThreshold = (0, number_1.bnOrZero)(params.params.completeLiquidationThreshold);
761
761
  const closeFactor = this.computeCloseFactor(debtorTotalDebtVal, debtorTotalCollateralVal, currentLiqThreshold, smallLiqSize, minCloseFactor, completeLiqThreshold);
762
762
  // get max repayable amount given the debtor's debt and how much liquidator wants to repay
763
- const debtDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(debtDenom));
763
+ const debtDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(debtDenom));
764
764
  const maxRepayableValue = debtorTotalDebtVal.multipliedBy(closeFactor);
765
765
  const maxRepayableAmt = maxRepayableValue.shiftedBy(debtDecimals.toNumber());
766
766
  if (debtRepaymentAmount.isGreaterThan(maxRepayableAmt)) {
@@ -768,7 +768,7 @@ class CDPModule extends base_1.default {
768
768
  }
769
769
  // calculate collateral amount that can be obtained given that debt amount and debtor's collateral balance
770
770
  // AND, recalculate debt repay amount if needed
771
- const cdpTokenDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
771
+ const cdpTokenDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
772
772
  let collateralAmtToLiquidate = this.calculateCollateralRequiredForDebt(number_1.BN_ONE, // assumes USC is $1
773
773
  cdpTokenDiscountedPrice, debtRepaymentAmount, cdpTokenDecimals, debtDecimals);
774
774
  const debtorAccountCollateral = yield sdk.query.cdp.AccountCollateral({
@@ -841,11 +841,11 @@ class CDPModule extends base_1.default {
841
841
  }
842
842
  exports.CDPModule = CDPModule;
843
843
  CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
844
- const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
845
- const optimalUsage = number_1.bnOrZero(rateStrategy.optimalUsage).shiftedBy(-4);
846
- const variableRate1 = number_1.bnOrZero(rateStrategy.variableRateSlope1).shiftedBy(-4);
847
- const variableRate2 = number_1.bnOrZero(rateStrategy.variableRateSlope2).shiftedBy(-4);
848
- const baseVariableBorrowRate = number_1.bnOrZero(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
844
+ const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
845
+ const optimalUsage = (0, number_1.bnOrZero)(rateStrategy.optimalUsage).shiftedBy(-4);
846
+ const variableRate1 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope1).shiftedBy(-4);
847
+ const variableRate2 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope2).shiftedBy(-4);
848
+ const baseVariableBorrowRate = (0, number_1.bnOrZero)(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
849
849
  if (utilizationRate.lte(optimalUsage)) {
850
850
  const vRate = utilizationRate.times(variableRate1).div(optimalUsage).dp(4, bignumber_js_1.BigNumber.ROUND_CEIL);
851
851
  return vRate.plus(baseVariableBorrowRate);