carbon-js-sdk 0.3.42 → 0.3.43-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) 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 +7 -7
  5. package/lib/clients/TokenClient.js +1 -1
  6. package/lib/clients/ZILClient.js +17 -17
  7. package/lib/codec/broker/amm.d.ts +1 -1
  8. package/lib/codec/broker/amm.js +16 -18
  9. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  10. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  11. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  12. package/lib/codec/index.d.ts +14 -11
  13. package/lib/codec/index.js +49 -34
  14. package/lib/codec/liquiditypool/genesis.d.ts +2 -1
  15. package/lib/codec/liquiditypool/genesis.js +17 -2
  16. package/lib/codec/liquiditypool/legacy.d.ts +18 -0
  17. package/lib/codec/liquiditypool/legacy.js +64 -0
  18. package/lib/codec/liquiditypool/liquiditypool.d.ts +40 -0
  19. package/lib/codec/liquiditypool/liquiditypool.js +320 -2
  20. package/lib/codec/liquiditypool/proposal.d.ts +37 -25
  21. package/lib/codec/liquiditypool/proposal.js +139 -61
  22. package/lib/codec/liquiditypool/query.d.ts +25 -1
  23. package/lib/codec/liquiditypool/query.js +124 -1
  24. package/lib/codec/liquiditypool/tx.d.ts +101 -66
  25. package/lib/codec/liquiditypool/tx.js +570 -333
  26. package/lib/codec/order/order.d.ts +1 -0
  27. package/lib/codec/order/order.js +45 -1
  28. package/lib/constant/generic.js +1 -1
  29. package/lib/modules/admin.d.ts +0 -2
  30. package/lib/modules/admin.js +0 -26
  31. package/lib/modules/cdp.js +43 -43
  32. package/lib/modules/coin.d.ts +19 -0
  33. package/lib/modules/coin.js +39 -0
  34. package/lib/modules/gov.js +12 -26
  35. package/lib/modules/liquiditypool.d.ts +11 -1
  36. package/lib/modules/liquiditypool.js +34 -2
  37. package/lib/modules/market.d.ts +11 -0
  38. package/lib/modules/market.js +19 -0
  39. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  40. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  41. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  42. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  43. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  44. package/lib/provider/amino/types/admin.js +28 -32
  45. package/lib/provider/amino/types/bank.js +1 -1
  46. package/lib/provider/amino/types/broker.js +1 -1
  47. package/lib/provider/amino/types/cdp.js +22 -22
  48. package/lib/provider/amino/types/coin.js +4 -4
  49. package/lib/provider/amino/types/gov.js +4 -32
  50. package/lib/provider/amino/types/ibc.js +1 -1
  51. package/lib/provider/amino/types/leverage.js +1 -1
  52. package/lib/provider/amino/types/liquidityPool.js +7 -7
  53. package/lib/provider/amino/types/market.js +1 -1
  54. package/lib/provider/amino/types/oracle.js +1 -1
  55. package/lib/provider/amino/types/order.js +4 -4
  56. package/lib/provider/amino/types/position.js +1 -1
  57. package/lib/provider/amino/types/profile.js +1 -1
  58. package/lib/provider/amino/types/staking.js +4 -4
  59. package/lib/provider/amino/types/subaccount.js +3 -3
  60. package/lib/provider/amino/utils.js +11 -11
  61. package/lib/provider/ledger/ledger.js +2 -2
  62. package/lib/provider/metamask/MetaMask.js +1 -1
  63. package/lib/provider/o3/O3Wallet.js +2 -2
  64. package/lib/util/address.js +13 -13
  65. package/lib/util/api.js +4 -4
  66. package/lib/util/fetch.js +1 -1
  67. package/lib/util/generic.js +3 -3
  68. package/lib/util/gov.d.ts +0 -2
  69. package/lib/util/gov.js +0 -6
  70. package/lib/util/number.js +5 -5
  71. package/lib/util/tx.d.ts +9 -6
  72. package/lib/wallet/CarbonSigner.js +2 -2
  73. package/lib/wallet/CarbonSigningClient.js +8 -8
  74. package/lib/wallet/CarbonWallet.js +6 -6
  75. package/lib/websocket/connector.js +3 -3
  76. package/package.json +1 -1
@@ -34,6 +34,7 @@ export interface Order {
34
34
  referralAddress: string;
35
35
  referralCommission: number;
36
36
  referralKickback: number;
37
+ poolRoute: Uint8Array;
37
38
  }
38
39
  export interface DBOrder {
39
40
  order?: Order;
@@ -163,12 +163,16 @@ exports.Order = {
163
163
  if (message.referralKickback !== 0) {
164
164
  writer.uint32(208).uint32(message.referralKickback);
165
165
  }
166
+ if (message.poolRoute.length !== 0) {
167
+ writer.uint32(218).bytes(message.poolRoute);
168
+ }
166
169
  return writer;
167
170
  },
168
171
  decode(input, length) {
169
172
  const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
170
173
  let end = length === undefined ? reader.len : reader.pos + length;
171
174
  const message = Object.assign({}, baseOrder);
175
+ message.poolRoute = new Uint8Array();
172
176
  while (reader.pos < end) {
173
177
  const tag = reader.uint32();
174
178
  switch (tag >>> 3) {
@@ -250,6 +254,9 @@ exports.Order = {
250
254
  case 26:
251
255
  message.referralKickback = reader.uint32();
252
256
  break;
257
+ case 27:
258
+ message.poolRoute = reader.bytes();
259
+ break;
253
260
  default:
254
261
  reader.skipType(tag & 7);
255
262
  break;
@@ -363,6 +370,10 @@ exports.Order = {
363
370
  object.referralKickback !== undefined && object.referralKickback !== null
364
371
  ? Number(object.referralKickback)
365
372
  : 0;
373
+ message.poolRoute =
374
+ object.poolRoute !== undefined && object.poolRoute !== null
375
+ ? bytesFromBase64(object.poolRoute)
376
+ : new Uint8Array();
366
377
  return message;
367
378
  },
368
379
  toJSON(message) {
@@ -408,10 +419,12 @@ exports.Order = {
408
419
  (obj.referralCommission = message.referralCommission);
409
420
  message.referralKickback !== undefined &&
410
421
  (obj.referralKickback = message.referralKickback);
422
+ message.poolRoute !== undefined &&
423
+ (obj.poolRoute = base64FromBytes(message.poolRoute !== undefined ? message.poolRoute : new Uint8Array()));
411
424
  return obj;
412
425
  },
413
426
  fromPartial(object) {
414
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
427
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
415
428
  const message = Object.assign({}, baseOrder);
416
429
  message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
417
430
  message.blockHeight =
@@ -452,6 +465,7 @@ exports.Order = {
452
465
  message.referralAddress = (_v = object.referralAddress) !== null && _v !== void 0 ? _v : "";
453
466
  message.referralCommission = (_w = object.referralCommission) !== null && _w !== void 0 ? _w : 0;
454
467
  message.referralKickback = (_x = object.referralKickback) !== null && _x !== void 0 ? _x : 0;
468
+ message.poolRoute = (_y = object.poolRoute) !== null && _y !== void 0 ? _y : new Uint8Array();
455
469
  return message;
456
470
  },
457
471
  };
@@ -787,6 +801,36 @@ exports.Orders = {
787
801
  return message;
788
802
  },
789
803
  };
804
+ var globalThis = (() => {
805
+ if (typeof globalThis !== "undefined")
806
+ return globalThis;
807
+ if (typeof self !== "undefined")
808
+ return self;
809
+ if (typeof window !== "undefined")
810
+ return window;
811
+ if (typeof global !== "undefined")
812
+ return global;
813
+ throw "Unable to locate global object";
814
+ })();
815
+ const atob = globalThis.atob ||
816
+ ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary"));
817
+ function bytesFromBase64(b64) {
818
+ const bin = atob(b64);
819
+ const arr = new Uint8Array(bin.length);
820
+ for (let i = 0; i < bin.length; ++i) {
821
+ arr[i] = bin.charCodeAt(i);
822
+ }
823
+ return arr;
824
+ }
825
+ const btoa = globalThis.btoa ||
826
+ ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64"));
827
+ function base64FromBytes(arr) {
828
+ const bin = [];
829
+ for (const byte of arr) {
830
+ bin.push(String.fromCharCode(byte));
831
+ }
832
+ return btoa(bin.join(""));
833
+ }
790
834
  function toTimestamp(date) {
791
835
  const seconds = numberToLong(date.getTime() / 1000);
792
836
  const nanos = (date.getTime() % 1000) * 1000000;
@@ -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.CARBON_GAS_PRICE = {
@@ -16,8 +16,6 @@ export declare class AdminModule extends BaseModule {
16
16
  linkToken(params: AdminModule.LinkTokenParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
17
17
  createMarket(params: AdminModule.CreateMarketParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
18
18
  createMarkets(params: AdminModule.CreateMarketParams[], opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
19
- linkPool(params: AdminModule.LinkPoolParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
20
- unlinkPool(params: AdminModule.UnlinkPoolParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
21
19
  setRewardsWeights(params: AdminModule.SetRewardsWeightsParams[], opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
22
20
  setRewardCurve(params: AdminModule.SetRewardCurveParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
23
21
  setCommitmentCurve(params: AdminModule.SetCommitmentCurveParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
@@ -172,32 +172,6 @@ class AdminModule extends base_1.default {
172
172
  return yield wallet.sendTxs(msgs, opts);
173
173
  });
174
174
  }
175
- linkPool(params, opts) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- const wallet = this.getWallet();
178
- const value = tx_4.MsgLinkPool.fromPartial({
179
- creator: wallet.bech32Address,
180
- linkPoolParams: transfromLinkPoolParams(params),
181
- });
182
- return yield wallet.sendTx({
183
- typeUrl: util_1.CarbonTx.Types.MsgLinkPool,
184
- value,
185
- }, opts);
186
- });
187
- }
188
- unlinkPool(params, opts) {
189
- return __awaiter(this, void 0, void 0, function* () {
190
- const wallet = this.getWallet();
191
- const value = tx_4.MsgUnlinkPool.fromPartial({
192
- creator: wallet.bech32Address,
193
- unlinkPoolParams: transfromUnlinkPoolParams(params),
194
- });
195
- return yield wallet.sendTx({
196
- typeUrl: util_1.CarbonTx.Types.MsgUnlinkPool,
197
- value,
198
- }, opts);
199
- });
200
- }
201
175
  setRewardsWeights(params, opts) {
202
176
  return __awaiter(this, void 0, void 0, function* () {
203
177
  const wallet = this.getWallet();
@@ -429,7 +429,7 @@ class CDPModule extends base_1.default {
429
429
  let availableBorrowsUsd = number_1.BN_ZERO;
430
430
  let currLiquidationThreshold = number_1.BN_ZERO;
431
431
  for (let i = 0; i < collaterals.length; i++) {
432
- const amount = number_1.bnOrZero(collaterals[i].collateralAmount);
432
+ const amount = (0, number_1.bnOrZero)(collaterals[i].collateralAmount);
433
433
  if (amount.isZero()) {
434
434
  continue; // no collateral for denom
435
435
  }
@@ -446,9 +446,9 @@ class CDPModule extends base_1.default {
446
446
  if (!assetParam) {
447
447
  continue;
448
448
  }
449
- const ltv = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
449
+ const ltv = (0, number_1.bnOrZero)(assetParam.loanToValue).div(number_1.BN_10000);
450
450
  const availableBorrowUsd = collateralUsdVal.times(ltv);
451
- const liquidationThreshold = number_1.bnOrZero(assetParam.liquidationThreshold).div(number_1.BN_10000);
451
+ const liquidationThreshold = (0, number_1.bnOrZero)(assetParam.liquidationThreshold).div(number_1.BN_10000);
452
452
  const liquidationThresholdVal = collateralUsdVal.times(liquidationThreshold);
453
453
  totalCollateralsUsd = totalCollateralsUsd.plus(collateralUsdVal);
454
454
  availableBorrowsUsd = availableBorrowsUsd.plus(availableBorrowUsd);
@@ -459,7 +459,7 @@ class CDPModule extends base_1.default {
459
459
  const debts = debtsRsp.debts;
460
460
  let totalDebtsUsd = number_1.BN_ZERO;
461
461
  for (let i = 0; i < debts.length; i++) {
462
- const amount = number_1.bnOrZero(debts[i].principalDebt);
462
+ const amount = (0, number_1.bnOrZero)(debts[i].principalDebt);
463
463
  const denom = debts[i].denom;
464
464
  if (amount.isZero()) {
465
465
  continue;
@@ -481,7 +481,7 @@ class CDPModule extends base_1.default {
481
481
  if (stablecoinDebtInfo) {
482
482
  const accountStablecoin = yield sdk.query.cdp.AccountStablecoin({ address: account });
483
483
  const stablecoinDecimals = (_a = (yield this.sdkProvider.getTokenClient().getDecimals(stablecoinDebtInfo.denom))) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
484
- const stablecoinDebtAmount = number_1.bnOrZero(accountStablecoin.principalDebt).plus(number_1.bnOrZero(accountStablecoin.interestDebt));
484
+ const stablecoinDebtAmount = (0, number_1.bnOrZero)(accountStablecoin.principalDebt).plus((0, number_1.bnOrZero)(accountStablecoin.interestDebt));
485
485
  stablecoinDebtUsd = stablecoinDebtAmount.shiftedBy(-stablecoinDecimals);
486
486
  totalDebtsUsd = totalDebtsUsd.plus(stablecoinDebtUsd);
487
487
  }
@@ -502,7 +502,7 @@ class CDPModule extends base_1.default {
502
502
  const sdk = this.sdkProvider;
503
503
  const cdpAddress = this.getCdpModuleAddress();
504
504
  const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
505
- return number_1.bnOrZero((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
505
+ return (0, number_1.bnOrZero)((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
506
506
  });
507
507
  }
508
508
  getCdpToActualRatio(cdpDenom) {
@@ -513,13 +513,13 @@ class CDPModule extends base_1.default {
513
513
  const cdpAmountRsp = supplyRsp.amount;
514
514
  if (!cdpAmountRsp)
515
515
  throw new Error("unable to retrieve cdp token supply");
516
- const cdpAmount = number_1.bnOrZero(cdpAmountRsp.amount);
516
+ const cdpAmount = (0, number_1.bnOrZero)(cdpAmountRsp.amount);
517
517
  const cdpAddress = this.getCdpModuleAddress();
518
518
  const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
519
519
  if (!balanceRsp.balance)
520
520
  throw new Error("unable to retrieve cdp module balance");
521
521
  const owedAmount = yield this.getTotalTokenDebt(denom);
522
- const actualAmount = number_1.bnOrZero(balanceRsp.balance.amount).plus(owedAmount);
522
+ const actualAmount = (0, number_1.bnOrZero)(balanceRsp.balance.amount).plus(owedAmount);
523
523
  if (!owedAmount)
524
524
  throw new Error("unable to retrieve total token debt");
525
525
  return cdpAmount.div(actualAmount);
@@ -541,8 +541,8 @@ class CDPModule extends base_1.default {
541
541
  const allDebts = allDebtsRes.debtInfosAll;
542
542
  for (let i = 0; i < allDebts.length; i++) {
543
543
  const denom = allDebts[i].denom;
544
- const interest = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
545
- const principal = number_1.bnOrZero(allDebts[i].totalPrincipal);
544
+ const interest = (0, number_1.bnOrZero)(allDebts[i].totalAccumulatedInterest);
545
+ const principal = (0, number_1.bnOrZero)(allDebts[i].totalPrincipal);
546
546
  const debtAmt = interest.plus(principal);
547
547
  const debtUsdVal = yield this.getTokenUsdVal(denom, debtAmt);
548
548
  if (!debtUsdVal) {
@@ -554,7 +554,7 @@ class CDPModule extends base_1.default {
554
554
  const stablecoinDebtRes = yield this.sdkProvider.query.cdp.StablecoinDebt({});
555
555
  if (stablecoinDebtRes.stablecoinDebtInfo) {
556
556
  const debtInfo = stablecoinDebtRes.stablecoinDebtInfo;
557
- const debtAmt = number_1.bnOrZero(debtInfo.totalPrincipal).plus(number_1.bnOrZero(debtInfo.totalAccumulatedInterest));
557
+ const debtAmt = (0, number_1.bnOrZero)(debtInfo.totalPrincipal).plus((0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest));
558
558
  const stablecoinDecimals = (_a = (yield sdk.getTokenClient().getDecimals(debtInfo.denom))) !== null && _a !== void 0 ? _a : 0;
559
559
  const debtUsdVal = debtAmt.shiftedBy(-stablecoinDecimals);
560
560
  totalDebt = totalDebt.plus(debtUsdVal);
@@ -572,7 +572,7 @@ class CDPModule extends base_1.default {
572
572
  if (!TokenClient_1.default.isCdpToken(balance.denom)) {
573
573
  continue;
574
574
  }
575
- const amount = number_1.bnOrZero(balance.amount);
575
+ const amount = (0, number_1.bnOrZero)(balance.amount);
576
576
  const collateralUsdValue = yield this.getCdpTokenUsdVal(balance.denom, amount);
577
577
  allCollateralsUsdValue = allCollateralsUsdValue.plus(collateralUsdValue);
578
578
  }
@@ -596,7 +596,7 @@ class CDPModule extends base_1.default {
596
596
  const priceResult = yield sdk.query.pricing.TokenPrice(codec_1.QueryTokenPriceRequest.fromPartial({ denom }));
597
597
  if (!priceResult.tokenPrice)
598
598
  throw new Error("unable to retrieve token price for " + denom);
599
- const twap = number_1.bnOrZero(priceResult.tokenPrice.twap).shiftedBy(-18);
599
+ const twap = (0, number_1.bnOrZero)(priceResult.tokenPrice.twap).shiftedBy(-18);
600
600
  return amount.multipliedBy(twap).shiftedBy(-decimals);
601
601
  });
602
602
  }
@@ -611,11 +611,11 @@ class CDPModule extends base_1.default {
611
611
  throw new Error("unable to retrieve debt info");
612
612
  const cimRsp = yield this.recalculateCIM(denom, debtInfo);
613
613
  const newInterestRate = cimRsp.interest;
614
- const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
615
- const accumInterest = number_1.bnOrZero(debtInfo.totalAccumulatedInterest);
614
+ const principal = (0, number_1.bnOrZero)(debtInfo.totalPrincipal);
615
+ const accumInterest = (0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest);
616
616
  const newInterest = principal.times(newInterestRate).plus(accumInterest.times(number_1.BN_ONE.plus(newInterestRate)));
617
617
  const cdpParamsRsp = yield this.sdkProvider.query.cdp.Params(query_1.QueryParamsRequest.fromPartial({}));
618
- const interestFee = number_1.bnOrZero((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
618
+ const interestFee = (0, number_1.bnOrZero)((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
619
619
  const interest = newInterest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
620
620
  return principal.plus(interest);
621
621
  });
@@ -633,8 +633,8 @@ class CDPModule extends base_1.default {
633
633
  const debtRes = yield sdk.query.cdp.AccountDebt({ address: account, denom: denom });
634
634
  debt = debtRes.debt;
635
635
  }
636
- const principalAmount = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
637
- const initialCIM = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
636
+ const principalAmount = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
637
+ const initialCIM = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
638
638
  if (principalAmount.isZero() || initialCIM.isZero())
639
639
  return number_1.BN_ZERO;
640
640
  const cimRsp = yield this.recalculateCIM(denom, debtInfo);
@@ -660,8 +660,8 @@ class CDPModule extends base_1.default {
660
660
  const debtResp = yield sdk.query.cdp.AccountStablecoin(query_1.QueryAccountStablecoinRequest.fromPartial({ address: account }));
661
661
  debt = debtResp;
662
662
  }
663
- principalAmount = number_1.bnOrZero(debt.principalDebt);
664
- const initialCIM = number_1.bnOrZero(debt.initialCumulativeInterestMultiplier);
663
+ principalAmount = (0, number_1.bnOrZero)(debt.principalDebt);
664
+ const initialCIM = (0, number_1.bnOrZero)(debt.initialCumulativeInterestMultiplier);
665
665
  const cim = yield this.recalculateStablecoinCIM(debtInfo);
666
666
  if (!cim)
667
667
  throw new Error("unable to retrieve account debt");
@@ -702,7 +702,7 @@ class CDPModule extends base_1.default {
702
702
  return number_1.BN_ZERO;
703
703
  }
704
704
  const diffSeconds = new bignumber_js_1.BigNumber(diffMs).shiftedBy(-3).dp(0, bignumber_js_1.BigNumber.ROUND_CEIL);
705
- const secondsAYear = number_1.bnOrZero(31536000);
705
+ const secondsAYear = (0, number_1.bnOrZero)(31536000);
706
706
  const numPeriods = secondsAYear.div(diffSeconds).dp(18);
707
707
  return apy.div(numPeriods).dp(18); // carbon backend sdk.dec max 18 dp
708
708
  }
@@ -726,8 +726,8 @@ class CDPModule extends base_1.default {
726
726
  throw new Error("unable to retrieve cdp params for " + denom);
727
727
  }
728
728
  }
729
- const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
730
- const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
729
+ const interestFeeRate = (0, number_1.bnOrZero)(params.interestFee).div(number_1.BN_10000);
730
+ const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
731
731
  return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
732
732
  });
733
733
  }
@@ -742,7 +742,7 @@ class CDPModule extends base_1.default {
742
742
  return { cim: number_1.BN_ZERO, interest: number_1.BN_ZERO };
743
743
  }
744
744
  }
745
- const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
745
+ const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
746
746
  const apy = yield this.calculateAPY(denom, debtInfo);
747
747
  const newInterest = CDPModule.calculateInterestForTimePeriod(apy, (_a = debtInfo.lastUpdatedTime) !== null && _a !== void 0 ? _a : new Date(0), new Date());
748
748
  const newCIM = cim.times(newInterest.plus(1));
@@ -761,8 +761,8 @@ class CDPModule extends base_1.default {
761
761
  }
762
762
  }
763
763
  const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
764
- const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
765
- const apy = number_1.bnOrZero((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
764
+ const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
765
+ const apy = (0, number_1.bnOrZero)((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
766
766
  if (!apy) {
767
767
  return number_1.BN_ZERO;
768
768
  }
@@ -788,7 +788,7 @@ class CDPModule extends base_1.default {
788
788
  const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
789
789
  const unlockableUsd = availableBorrowsUsd.multipliedBy(number_1.BN_10000).div(unlockRatio);
790
790
  const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom });
791
- const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
791
+ const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
792
792
  if (tokenTwap.isZero())
793
793
  throw new Error("unable to retrieve token price for " + denom);
794
794
  const tokenAmt = unlockableUsd.div(tokenTwap.shiftedBy(-18)).shiftedBy(tokenDecimals);
@@ -799,7 +799,7 @@ class CDPModule extends base_1.default {
799
799
  address: account,
800
800
  cdpDenom: cdpDenom,
801
801
  });
802
- const lockedAmount = number_1.bnOrZero((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
802
+ const lockedAmount = (0, number_1.bnOrZero)((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
803
803
  return lockedAmount.lt(cdpTokenAmt) ? lockedAmount : cdpTokenAmt;
804
804
  });
805
805
  }
@@ -817,7 +817,7 @@ class CDPModule extends base_1.default {
817
817
  const denom = this.getUnderlyingDenom(cdpDenom);
818
818
  const cdpToActualRatio = (_a = (yield this.getCdpToActualRatio(cdpDenom))) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
819
819
  const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
820
- const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
820
+ const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
821
821
  return tokenTwap.multipliedBy(cdpToActualRatio);
822
822
  });
823
823
  }
@@ -838,26 +838,26 @@ class CDPModule extends base_1.default {
838
838
  });
839
839
  if (!asset.assetParams)
840
840
  throw new Error("unable to retrieve asset param for " + cdpActualDenom);
841
- const bonus = number_1.bnOrZero(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
841
+ const bonus = (0, number_1.bnOrZero)(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
842
842
  const cdpTokenPrice = yield this.getCdpTokenPrice(cdpDenom);
843
843
  const cdpTokenDiscountedPrice = cdpTokenPrice.multipliedBy(number_1.BN_ONE.minus(bonus));
844
844
  // get close factor
845
845
  const debtorAccountData = yield sdk.query.cdp.AccountData({
846
846
  address: debtor,
847
847
  });
848
- const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
849
- const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
850
- const currentLiqThreshold = number_1.bnOrZero(debtorAccountData.currLiquidationThreshold);
848
+ const debtorTotalCollateralVal = (0, number_1.bnOrZero)(debtorAccountData.totalCollateralsUsd);
849
+ const debtorTotalDebtVal = (0, number_1.bnOrZero)(debtorAccountData.totalDebtsUsd);
850
+ const currentLiqThreshold = (0, number_1.bnOrZero)(debtorAccountData.currLiquidationThreshold);
851
851
  const params = yield sdk.query.cdp.Params({});
852
852
  if (!params.params) {
853
853
  throw new Error("unable to retrieve cdp params");
854
854
  }
855
- const smallLiqSize = number_1.bnOrZero(params.params.smallLiquidationSize);
856
- const minCloseFactor = number_1.bnOrZero(params.params.minimumCloseFactor);
857
- const completeLiqThreshold = number_1.bnOrZero(params.params.completeLiquidationThreshold);
855
+ const smallLiqSize = (0, number_1.bnOrZero)(params.params.smallLiquidationSize);
856
+ const minCloseFactor = (0, number_1.bnOrZero)(params.params.minimumCloseFactor);
857
+ const completeLiqThreshold = (0, number_1.bnOrZero)(params.params.completeLiquidationThreshold);
858
858
  const closeFactor = this.computeCloseFactor(debtorTotalDebtVal, debtorTotalCollateralVal, currentLiqThreshold, smallLiqSize, minCloseFactor, completeLiqThreshold);
859
859
  // get max repayable amount given the debtor's debt and how much liquidator wants to repay
860
- const debtDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(debtDenom));
860
+ const debtDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(debtDenom));
861
861
  const maxRepayableValue = debtorTotalDebtVal.multipliedBy(closeFactor);
862
862
  const maxRepayableAmt = maxRepayableValue.shiftedBy(debtDecimals.toNumber());
863
863
  if (debtRepaymentAmount.isGreaterThan(maxRepayableAmt)) {
@@ -865,7 +865,7 @@ class CDPModule extends base_1.default {
865
865
  }
866
866
  // calculate collateral amount that can be obtained given that debt amount and debtor's collateral balance
867
867
  // AND, recalculate debt repay amount if needed
868
- const cdpTokenDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
868
+ const cdpTokenDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
869
869
  let collateralAmtToLiquidate = this.calculateCollateralRequiredForDebt(number_1.BN_ONE, // assumes USC is $1
870
870
  cdpTokenDiscountedPrice, debtRepaymentAmount, cdpTokenDecimals, debtDecimals);
871
871
  const debtorAccountCollateral = yield sdk.query.cdp.AccountCollateral({
@@ -937,11 +937,11 @@ class CDPModule extends base_1.default {
937
937
  }
938
938
  exports.CDPModule = CDPModule;
939
939
  CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
940
- const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
941
- const optimalUsage = number_1.bnOrZero(rateStrategy.optimalUsage).shiftedBy(-4);
942
- const variableRate1 = number_1.bnOrZero(rateStrategy.variableRateSlope1).shiftedBy(-4);
943
- const variableRate2 = number_1.bnOrZero(rateStrategy.variableRateSlope2).shiftedBy(-4);
944
- const baseVariableBorrowRate = number_1.bnOrZero(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
940
+ const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
941
+ const optimalUsage = (0, number_1.bnOrZero)(rateStrategy.optimalUsage).shiftedBy(-4);
942
+ const variableRate1 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope1).shiftedBy(-4);
943
+ const variableRate2 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope2).shiftedBy(-4);
944
+ const baseVariableBorrowRate = (0, number_1.bnOrZero)(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
945
945
  if (utilizationRate.lte(optimalUsage)) {
946
946
  const vRate = utilizationRate.times(variableRate1).div(optimalUsage).dp(4, bignumber_js_1.BigNumber.ROUND_CEIL);
947
947
  return vRate.plus(baseVariableBorrowRate);
@@ -2,12 +2,15 @@ import { Coin } from "../codec/cosmos/base/v1beta1/coin";
2
2
  import { CarbonTx } from "../util";
3
3
  import BigNumber from "bignumber.js";
4
4
  import BaseModule from "./base";
5
+ import Long from "long";
5
6
  export declare class CoinModule extends BaseModule {
6
7
  createWithdrawal(params: CoinModule.CreateWithdrawalParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
7
8
  mintToken(params: CoinModule.MintTokenParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
8
9
  depositToGroup(params: CoinModule.DepositToGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
9
10
  convertToGroup(params: CoinModule.DepositToGroupParams[], opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
10
11
  withdrawFromGroup(params: CoinModule.WithdrawFromGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
12
+ addBridgeAddress(params: CoinModule.AddBridgeAddressParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
13
+ createToken(params: CoinModule.CreateTokenParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
11
14
  }
12
15
  export declare namespace CoinModule {
13
16
  interface CreateWithdrawalParams {
@@ -31,4 +34,20 @@ export declare namespace CoinModule {
31
34
  creator?: string;
32
35
  sourceCoin: Coin;
33
36
  }
37
+ interface AddBridgeAddressParams {
38
+ creator?: string;
39
+ chainId: Long;
40
+ bridgeId: Long;
41
+ bridgeAddress: string;
42
+ }
43
+ interface CreateTokenParams {
44
+ creator?: string;
45
+ name: string;
46
+ symbol: string;
47
+ decimals: Long;
48
+ chainId: Long;
49
+ bridgeId: Long;
50
+ bridgeAddress: string;
51
+ tokenAddress: string;
52
+ }
34
53
  }
@@ -94,5 +94,44 @@ class CoinModule extends base_1.default {
94
94
  }, opts);
95
95
  });
96
96
  }
97
+ addBridgeAddress(params, opts) {
98
+ var _a;
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const wallet = this.getWallet();
101
+ const value = tx_1.MsgAddBridgeAddress.fromPartial({
102
+ creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
103
+ chainId: params.chainId,
104
+ bridgeId: params.bridgeId,
105
+ bridgeAddress: params.bridgeAddress,
106
+ });
107
+ return yield wallet.sendTx({
108
+ typeUrl: util_1.CarbonTx.Types.MsgAddBridgeAddress,
109
+ value,
110
+ }, opts);
111
+ });
112
+ }
113
+ createToken(params, opts) {
114
+ var _a, _b;
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const wallet = this.getWallet();
117
+ const value = tx_1.MsgCreateToken.fromPartial({
118
+ creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
119
+ createTokenParams: {
120
+ creator: (_b = params.creator) !== null && _b !== void 0 ? _b : wallet.bech32Address,
121
+ name: params.name,
122
+ symbol: params.symbol,
123
+ decimals: params.decimals,
124
+ chainId: params.chainId,
125
+ bridgeId: params.bridgeId,
126
+ bridgeAddress: params.bridgeAddress,
127
+ tokenAddress: params.tokenAddress,
128
+ }
129
+ });
130
+ return yield wallet.sendTx({
131
+ typeUrl: util_1.CarbonTx.Types.MsgCreateToken,
132
+ value,
133
+ }, opts);
134
+ });
135
+ }
97
136
  }
98
137
  exports.CoinModule = CoinModule;
@@ -48,7 +48,7 @@ class GovModule extends base_1.default {
48
48
  const value = tx_1.MsgDeposit.fromPartial({
49
49
  proposalId: new long_1.default(params.proposalId),
50
50
  depositor: wallet.bech32Address,
51
- amount: amino_1.coins(params.amount, params.denom),
51
+ amount: (0, amino_1.coins)(params.amount, params.denom),
52
52
  });
53
53
  return yield wallet.sendTx({
54
54
  typeUrl: util_1.CarbonTx.Types.MsgDeposit,
@@ -78,21 +78,21 @@ class GovModule extends base_1.default {
78
78
  const createTokenMsg = {
79
79
  title: title,
80
80
  description: description,
81
- msg: admin_1.transfromCreateTokenParams(msg, wallet.bech32Address),
81
+ msg: (0, admin_1.transfromCreateTokenParams)(msg, wallet.bech32Address),
82
82
  };
83
83
  return proposal_1.CreateTokenProposal.encode(createTokenMsg).finish();
84
84
  case "SetMsgGasCostProposal":
85
85
  const setMsgGasCostMsg = {
86
86
  title: title,
87
87
  description: description,
88
- msg: admin_1.transfromSetMsgGasCostParams(msg),
88
+ msg: (0, admin_1.transfromSetMsgGasCostParams)(msg),
89
89
  };
90
90
  return proposal_2.SetMsgGasCostProposal.encode(setMsgGasCostMsg).finish();
91
91
  case "SetMinGasPriceProposal":
92
92
  const setMinGasPriceMsg = {
93
93
  title: title,
94
94
  description: description,
95
- msg: admin_1.transfromSetMinGasPriceParams(msg),
95
+ msg: (0, admin_1.transfromSetMinGasPriceParams)(msg),
96
96
  };
97
97
  return proposal_2.SetMinGasPriceProposal.encode(setMinGasPriceMsg).finish();
98
98
  case "RemoveMsgGasCostProposal":
@@ -109,67 +109,53 @@ class GovModule extends base_1.default {
109
109
  denom: proposalMsg.denom,
110
110
  };
111
111
  return proposal_2.RemoveMinGasPriceProposal.encode(removeMinGasPriceMsg).finish();
112
- case "LinkPoolProposal":
113
- const linkPoolMsg = {
114
- title: title,
115
- description: description,
116
- msg: admin_1.transfromLinkPoolParams(msg),
117
- };
118
- return proposal_3.LinkPoolProposal.encode(linkPoolMsg).finish();
119
- case "UnlinkPoolProposal":
120
- const unlinkPoolMsg = {
121
- title: title,
122
- description: description,
123
- msg: admin_1.transfromUnlinkPoolParams(msg),
124
- };
125
- return proposal_3.UnlinkPoolProposal.encode(unlinkPoolMsg).finish();
126
112
  case "SetRewardCurveProposal":
127
113
  const setRewardCurveMsg = {
128
114
  title: title,
129
115
  description: description,
130
- msg: admin_1.transfromSetRewardCurveParams(msg),
116
+ msg: (0, admin_1.transfromSetRewardCurveParams)(msg),
131
117
  };
132
118
  return proposal_3.SetRewardCurveProposal.encode(setRewardCurveMsg).finish();
133
119
  case "SetCommitmentCurveProposal":
134
120
  const setCommitmentCurveMsg = {
135
121
  title: title,
136
122
  description: description,
137
- msg: admin_1.transfromSetCommitmentCurveParams(msg),
123
+ msg: (0, admin_1.transfromSetCommitmentCurveParams)(msg),
138
124
  };
139
125
  return proposal_3.SetCommitmentCurveProposal.encode(setCommitmentCurveMsg).finish();
140
126
  case "SetRewardsWeightsProposal":
141
127
  const setRewardsWeightsMsg = {
142
128
  title: title,
143
129
  description: description,
144
- msg: admin_1.transfromSetRewardsWeightsParams(msg),
130
+ msg: (0, admin_1.transfromSetRewardsWeightsParams)(msg),
145
131
  };
146
132
  return proposal_3.SetRewardsWeightsProposal.encode(setRewardsWeightsMsg).finish();
147
133
  case "UpdatePoolProposal":
148
134
  const updatePoolProposalMsg = {
149
135
  title: title,
150
136
  description: description,
151
- msg: admin_1.transfromUpdatePoolParams(msg),
137
+ msg: (0, admin_1.transfromUpdatePoolParams)(msg),
152
138
  };
153
139
  return proposal_3.UpdatePoolProposal.encode(updatePoolProposalMsg).finish();
154
140
  case "UpdateMarketProposal":
155
141
  const updateMarketProposalMsg = {
156
142
  title: title,
157
143
  description: description,
158
- msg: market_1.transfromUpdateMarketParams(msg),
144
+ msg: (0, market_1.transfromUpdateMarketParams)(msg),
159
145
  };
160
146
  return proposal_4.UpdateMarketProposal.encode(updateMarketProposalMsg).finish();
161
147
  case "CreateOracleProposal":
162
148
  const createOracleProposalMsg = {
163
149
  title: title,
164
150
  description: description,
165
- msg: admin_1.transfromCreateOracleParams(msg, wallet.bech32Address),
151
+ msg: (0, admin_1.transfromCreateOracleParams)(msg, wallet.bech32Address),
166
152
  };
167
153
  return proposal_5.CreateOracleProposal.encode(createOracleProposalMsg).finish();
168
154
  case "SettlementPriceProposal":
169
155
  const settlementPriceProposalMsg = {
170
156
  title: title,
171
157
  description: description,
172
- msg: admin_1.transformSetSettlementPriceParams(msg),
158
+ msg: (0, admin_1.transformSetSettlementPriceParams)(msg),
173
159
  };
174
160
  return proposal_6.SettlementPriceProposal.encode(settlementPriceProposalMsg).finish();
175
161
  case "ParameterChangeProposal":
@@ -191,7 +177,7 @@ class GovModule extends base_1.default {
191
177
  title: title,
192
178
  description: description,
193
179
  recipient: proposalMsg.recipient,
194
- amount: admin_1.transformCommunityPoolSpendAmount(proposalMsg.amount),
180
+ amount: (0, admin_1.transformCommunityPoolSpendAmount)(proposalMsg.amount),
195
181
  };
196
182
  return distribution_1.CommunityPoolSpendProposal.encode(communityPoolSpendProposalMsg).finish();
197
183
  case "CancelSoftwareUpgradeProposal":
@@ -18,6 +18,8 @@ export declare class LiquidityPoolModule extends BaseModule {
18
18
  */
19
19
  getWeeklyRewards(): Promise<BigNumber>;
20
20
  claimMultiPoolRewards(params: LiquidityPoolModule.ClaimMultiPoolRewards, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
21
+ createPoolRoute(params: LiquidityPoolModule.CreatePoolRouteParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
22
+ removePoolRoute(params: LiquidityPoolModule.RemovePoolRouteParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
21
23
  }
22
24
  export declare namespace LiquidityPoolModule {
23
25
  interface CreatePoolParams {
@@ -27,7 +29,6 @@ export declare namespace LiquidityPoolModule {
27
29
  tokenBWeight: BigNumber;
28
30
  swapFee: BigNumber;
29
31
  ampBps: Long;
30
- numQuotes: number;
31
32
  }
32
33
  interface CreatePoolWithLiquidityParams {
33
34
  tokenADenom: string;
@@ -73,4 +74,13 @@ export declare namespace LiquidityPoolModule {
73
74
  poolId: string;
74
75
  address: string;
75
76
  }
77
+ interface CreatePoolRouteParams {
78
+ marketName: string;
79
+ poolIds: Long[];
80
+ numQuotes: Long;
81
+ }
82
+ interface RemovePoolRouteParams {
83
+ marketName: string;
84
+ poolIds: Long[];
85
+ }
76
86
  }