carbon-js-sdk 0.3.38-beta.2 → 0.3.39

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 (78) hide show
  1. package/lib/clients/CarbonQueryClient.js +2 -2
  2. package/lib/clients/ETHClient.js +19 -20
  3. package/lib/clients/HydrogenClient.js +1 -1
  4. package/lib/clients/NEOClient.js +7 -7
  5. package/lib/clients/TokenClient.js +3 -6
  6. package/lib/clients/ZILClient.js +20 -21
  7. package/lib/codec/cdp/asset_params.d.ts +0 -1
  8. package/lib/codec/cdp/tx.d.ts +1 -23
  9. package/lib/codec/cdp/tx.js +1 -100
  10. package/lib/codec/coin/event.d.ts +0 -81
  11. package/lib/codec/coin/event.js +1 -486
  12. package/lib/codec/coin/genesis.d.ts +1 -3
  13. package/lib/codec/coin/genesis.js +2 -18
  14. package/lib/codec/coin/query.d.ts +0 -85
  15. package/lib/codec/coin/query.js +1 -422
  16. package/lib/codec/coin/tx.d.ts +2 -197
  17. package/lib/codec/coin/tx.js +17 -1050
  18. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  19. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  20. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  21. package/lib/codec/index.d.ts +5 -24
  22. package/lib/codec/index.js +11 -86
  23. package/lib/codec/pricing/pricing.d.ts +0 -1
  24. package/lib/codec/pricing/pricing.js +2 -14
  25. package/lib/codec/pricing/tx.d.ts +0 -23
  26. package/lib/codec/pricing/tx.js +1 -112
  27. package/lib/constant/generic.js +1 -1
  28. package/lib/constant/ibc.js +5 -0
  29. package/lib/constant/network.js +1 -1
  30. package/lib/modules/admin.d.ts +0 -32
  31. package/lib/modules/admin.js +0 -76
  32. package/lib/modules/cdp.js +43 -43
  33. package/lib/modules/coin.d.ts +0 -12
  34. package/lib/modules/coin.js +0 -44
  35. package/lib/modules/gov.js +14 -14
  36. package/lib/modules/liquiditypool.js +1 -1
  37. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  38. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  39. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  40. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  41. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  42. package/lib/provider/amino/types/admin.js +30 -30
  43. package/lib/provider/amino/types/bank.js +1 -1
  44. package/lib/provider/amino/types/broker.js +1 -1
  45. package/lib/provider/amino/types/cdp.js +22 -22
  46. package/lib/provider/amino/types/coin.js +2 -14
  47. package/lib/provider/amino/types/gov.js +4 -75
  48. package/lib/provider/amino/types/ibc.js +1 -1
  49. package/lib/provider/amino/types/leverage.js +1 -1
  50. package/lib/provider/amino/types/liquidityPool.js +7 -7
  51. package/lib/provider/amino/types/market.js +1 -1
  52. package/lib/provider/amino/types/oracle.js +1 -1
  53. package/lib/provider/amino/types/order.js +4 -4
  54. package/lib/provider/amino/types/position.js +1 -1
  55. package/lib/provider/amino/types/profile.js +1 -1
  56. package/lib/provider/amino/types/staking.js +4 -4
  57. package/lib/provider/amino/types/subaccount.js +3 -3
  58. package/lib/provider/amino/utils.d.ts +1 -1
  59. package/lib/provider/amino/utils.js +11 -11
  60. package/lib/provider/ledger/ledger.js +2 -2
  61. package/lib/provider/metamask/MetaMask.d.ts +1 -1
  62. package/lib/provider/metamask/MetaMask.js +9 -9
  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/blockchain.d.ts +1 -3
  67. package/lib/util/blockchain.js +62 -97
  68. package/lib/util/fetch.js +1 -1
  69. package/lib/util/generic.js +3 -3
  70. package/lib/util/gov.d.ts +1 -8
  71. package/lib/util/gov.js +0 -7
  72. package/lib/util/number.js +5 -5
  73. package/lib/util/tx.d.ts +0 -18
  74. package/lib/wallet/CarbonSigner.js +2 -2
  75. package/lib/wallet/CarbonSigningClient.js +8 -8
  76. package/lib/wallet/CarbonWallet.js +6 -6
  77. package/lib/websocket/connector.js +3 -3
  78. package/package.json +1 -1
@@ -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.MsgClientImpl = exports.MsgUpdateTokenPriceOracleResponse = exports.MsgUpdateTokenPriceOracle = exports.MsgSetStaleIndexAllowanceResponse = exports.MsgSetStaleIndexAllowance = exports.MsgSetImpactBandResponse = exports.MsgSetImpactBand = exports.MsgSetSmoothenBandResponse = exports.MsgSetSmoothenBand = exports.MsgSetBackfillTimeIntervalResponse = exports.MsgSetBackfillTimeInterval = exports.protobufPackage = void 0;
6
+ exports.MsgClientImpl = exports.MsgSetStaleIndexAllowanceResponse = exports.MsgSetStaleIndexAllowance = exports.MsgSetImpactBandResponse = exports.MsgSetImpactBand = exports.MsgSetSmoothenBandResponse = exports.MsgSetSmoothenBand = exports.MsgSetBackfillTimeIntervalResponse = exports.MsgSetBackfillTimeInterval = 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"));
@@ -382,111 +382,6 @@ exports.MsgSetStaleIndexAllowanceResponse = {
382
382
  return message;
383
383
  },
384
384
  };
385
- const baseMsgUpdateTokenPriceOracle = {
386
- creator: "",
387
- denom: "",
388
- oracleId: "",
389
- };
390
- exports.MsgUpdateTokenPriceOracle = {
391
- encode(message, writer = minimal_1.default.Writer.create()) {
392
- if (message.creator !== "") {
393
- writer.uint32(10).string(message.creator);
394
- }
395
- if (message.denom !== "") {
396
- writer.uint32(18).string(message.denom);
397
- }
398
- if (message.oracleId !== "") {
399
- writer.uint32(26).string(message.oracleId);
400
- }
401
- return writer;
402
- },
403
- decode(input, length) {
404
- const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
405
- let end = length === undefined ? reader.len : reader.pos + length;
406
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracle);
407
- while (reader.pos < end) {
408
- const tag = reader.uint32();
409
- switch (tag >>> 3) {
410
- case 1:
411
- message.creator = reader.string();
412
- break;
413
- case 2:
414
- message.denom = reader.string();
415
- break;
416
- case 3:
417
- message.oracleId = reader.string();
418
- break;
419
- default:
420
- reader.skipType(tag & 7);
421
- break;
422
- }
423
- }
424
- return message;
425
- },
426
- fromJSON(object) {
427
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracle);
428
- message.creator =
429
- object.creator !== undefined && object.creator !== null
430
- ? String(object.creator)
431
- : "";
432
- message.denom =
433
- object.denom !== undefined && object.denom !== null
434
- ? String(object.denom)
435
- : "";
436
- message.oracleId =
437
- object.oracleId !== undefined && object.oracleId !== null
438
- ? String(object.oracleId)
439
- : "";
440
- return message;
441
- },
442
- toJSON(message) {
443
- const obj = {};
444
- message.creator !== undefined && (obj.creator = message.creator);
445
- message.denom !== undefined && (obj.denom = message.denom);
446
- message.oracleId !== undefined && (obj.oracleId = message.oracleId);
447
- return obj;
448
- },
449
- fromPartial(object) {
450
- var _a, _b, _c;
451
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracle);
452
- message.creator = (_a = object.creator) !== null && _a !== void 0 ? _a : "";
453
- message.denom = (_b = object.denom) !== null && _b !== void 0 ? _b : "";
454
- message.oracleId = (_c = object.oracleId) !== null && _c !== void 0 ? _c : "";
455
- return message;
456
- },
457
- };
458
- const baseMsgUpdateTokenPriceOracleResponse = {};
459
- exports.MsgUpdateTokenPriceOracleResponse = {
460
- encode(_, writer = minimal_1.default.Writer.create()) {
461
- return writer;
462
- },
463
- decode(input, length) {
464
- const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
465
- let end = length === undefined ? reader.len : reader.pos + length;
466
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracleResponse);
467
- while (reader.pos < end) {
468
- const tag = reader.uint32();
469
- switch (tag >>> 3) {
470
- default:
471
- reader.skipType(tag & 7);
472
- break;
473
- }
474
- }
475
- return message;
476
- },
477
- fromJSON(_) {
478
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracleResponse);
479
- return message;
480
- },
481
- toJSON(_) {
482
- const obj = {};
483
- return obj;
484
- },
485
- fromPartial(_) {
486
- const message = Object.assign({}, baseMsgUpdateTokenPriceOracleResponse);
487
- return message;
488
- },
489
- };
490
385
  class MsgClientImpl {
491
386
  constructor(rpc) {
492
387
  this.rpc = rpc;
@@ -494,7 +389,6 @@ class MsgClientImpl {
494
389
  this.SetSmoothenBand = this.SetSmoothenBand.bind(this);
495
390
  this.SetImpactBand = this.SetImpactBand.bind(this);
496
391
  this.SetStaleIndexAllowance = this.SetStaleIndexAllowance.bind(this);
497
- this.UpdateTokenPriceOracle = this.UpdateTokenPriceOracle.bind(this);
498
392
  }
499
393
  SetBackfillTimeInterval(request) {
500
394
  const data = exports.MsgSetBackfillTimeInterval.encode(request).finish();
@@ -516,11 +410,6 @@ class MsgClientImpl {
516
410
  const promise = this.rpc.request("Switcheo.carbon.pricing.Msg", "SetStaleIndexAllowance", data);
517
411
  return promise.then((data) => exports.MsgSetStaleIndexAllowanceResponse.decode(new minimal_1.default.Reader(data)));
518
412
  }
519
- UpdateTokenPriceOracle(request) {
520
- const data = exports.MsgUpdateTokenPriceOracle.encode(request).finish();
521
- const promise = this.rpc.request("Switcheo.carbon.pricing.Msg", "UpdateTokenPriceOracle", data);
522
- return promise.then((data) => exports.MsgUpdateTokenPriceOracleResponse.decode(new minimal_1.default.Reader(data)));
523
- }
524
413
  }
525
414
  exports.MsgClientImpl = MsgClientImpl;
526
415
  if (minimal_1.default.util.Long !== long_1.default) {
@@ -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: (0, proto_signing_1.coins)(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
15
+ amount: 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 = {
@@ -1660,6 +1660,11 @@ exports.EmbedChainInfosInit = {
1660
1660
  coinMinimalDenom: "stuluna",
1661
1661
  coinDecimals: 6,
1662
1662
  },
1663
+ {
1664
+ "coinDenom": "stEVMOS",
1665
+ "coinMinimalDenom": "staevmos",
1666
+ "coinDecimals": 18
1667
+ },
1663
1668
  ],
1664
1669
  feeCurrencies: [
1665
1670
  {
@@ -125,7 +125,7 @@ exports.NetworkConfigs = {
125
125
  networkMagic: neon_core_next_1.CONST.MAGIC_NUMBER.TestNet,
126
126
  },
127
127
  zil: {
128
- rpcURL: "https://dev-api.zilliqa.com",
128
+ rpcURL: "",
129
129
  lockProxyAddr: "0xe7bef341044f1b8d5ab1a25172e2678a1e75479a",
130
130
  bridgeEntranceAddr: "0xccf798e633d6fb6505b494fc010903f9be3bc99b",
131
131
  chainId: 111,
@@ -43,11 +43,6 @@ export declare class AdminModule extends BaseModule {
43
43
  setCompleteLiquidationThreshold(params: AdminModule.SetCompleteLiquidationThresholdParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
44
44
  setMinimumCloseFactor(params: AdminModule.SetMinimumCloseFactorParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
45
45
  setSmallLiquidationSize(params: AdminModule.SetSmallLiquidationSizeParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
46
- createNewGroup(params: AdminModule.CreateNewGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
47
- updateGroup(params: AdminModule.UpdateGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
48
- registerToGroup(params: AdminModule.RegisterDeregisterToGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
49
- deregisterFromGroup(params: AdminModule.RegisterDeregisterToGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
50
- updateGroupConfig(params: AdminModule.UpdateGroupConfigParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
51
46
  }
52
47
  export declare namespace AdminModule {
53
48
  interface AuthorizeBridgeParams {
@@ -273,33 +268,6 @@ export declare namespace AdminModule {
273
268
  amount: BigNumber;
274
269
  denom: string;
275
270
  }
276
- interface CreateNewGroupParams {
277
- creator?: string;
278
- name: string;
279
- chequeTokenSymbol: string;
280
- oracleId: string;
281
- }
282
- interface UpdateGroupParams {
283
- creator?: string;
284
- groupId?: string;
285
- updateGroupParams?: GroupName;
286
- }
287
- interface GroupName {
288
- name: string;
289
- }
290
- interface RegisterDeregisterToGroupParams {
291
- creator?: string;
292
- groupId: string;
293
- denom: string;
294
- }
295
- interface UpdateGroupConfigParams {
296
- creator?: string;
297
- denom: string;
298
- updateGroupedTokenConfigParams: IsGroupActive;
299
- }
300
- interface IsGroupActive {
301
- isActive: boolean;
302
- }
303
271
  }
304
272
  export declare function transfromCreateOracleParams(msg: AdminModule.CreateOracleParams, address: string): {
305
273
  creator: string;
@@ -563,82 +563,6 @@ class AdminModule extends base_1.default {
563
563
  }, opts);
564
564
  });
565
565
  }
566
- createNewGroup(params, opts) {
567
- var _a;
568
- return __awaiter(this, void 0, void 0, function* () {
569
- const wallet = this.getWallet();
570
- const value = tx_1.MsgCreateGroup.fromPartial({
571
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
572
- name: params.name,
573
- chequeTokenSymbol: params.chequeTokenSymbol,
574
- oracleId: params.oracleId,
575
- });
576
- return yield wallet.sendTx({
577
- typeUrl: util_1.CarbonTx.Types.MsgCreateGroup,
578
- value,
579
- }, opts);
580
- });
581
- }
582
- updateGroup(params, opts) {
583
- var _a;
584
- return __awaiter(this, void 0, void 0, function* () {
585
- const wallet = this.getWallet();
586
- const value = tx_1.MsgUpdateGroup.fromPartial({
587
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
588
- groupId: params.groupId,
589
- updateGroupParams: params.updateGroupParams
590
- });
591
- return yield wallet.sendTx({
592
- typeUrl: util_1.CarbonTx.Types.MsgUpdateGroup,
593
- value,
594
- }, opts);
595
- });
596
- }
597
- registerToGroup(params, opts) {
598
- var _a;
599
- return __awaiter(this, void 0, void 0, function* () {
600
- const wallet = this.getWallet();
601
- const value = tx_1.MsgRegisterToGroup.fromPartial({
602
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
603
- groupId: params.groupId,
604
- denom: params.denom,
605
- });
606
- return yield wallet.sendTx({
607
- typeUrl: util_1.CarbonTx.Types.MsgRegisterToGroup,
608
- value,
609
- }, opts);
610
- });
611
- }
612
- deregisterFromGroup(params, opts) {
613
- var _a;
614
- return __awaiter(this, void 0, void 0, function* () {
615
- const wallet = this.getWallet();
616
- const value = tx_1.MsgDeregisterFromGroup.fromPartial({
617
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
618
- groupId: params.groupId,
619
- denom: params.denom,
620
- });
621
- return yield wallet.sendTx({
622
- typeUrl: util_1.CarbonTx.Types.MsgDeregisterFromGroup,
623
- value,
624
- }, opts);
625
- });
626
- }
627
- updateGroupConfig(params, opts) {
628
- var _a;
629
- return __awaiter(this, void 0, void 0, function* () {
630
- const wallet = this.getWallet();
631
- const value = tx_1.MsgUpdateGroupedTokenConfig.fromPartial({
632
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
633
- denom: params.denom,
634
- updateGroupedTokenConfigParams: params.updateGroupedTokenConfigParams,
635
- });
636
- return yield wallet.sendTx({
637
- typeUrl: util_1.CarbonTx.Types.MsgUpdateGroupedTokenConfig,
638
- value,
639
- }, opts);
640
- });
641
- }
642
566
  }
643
567
  exports.AdminModule = AdminModule;
644
568
  function transfromCreateOracleParams(msg, address) {
@@ -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 = (0, number_1.bnOrZero)(collaterals[i].collateralAmount);
432
+ const amount = 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 = (0, number_1.bnOrZero)(assetParam.loanToValue).div(number_1.BN_10000);
449
+ const ltv = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
450
450
  const availableBorrowUsd = collateralUsdVal.times(ltv);
451
- const liquidationThreshold = (0, number_1.bnOrZero)(assetParam.liquidationThreshold).div(number_1.BN_10000);
451
+ const liquidationThreshold = 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 = (0, number_1.bnOrZero)(debts[i].principalDebt);
462
+ const amount = 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 = (0, number_1.bnOrZero)(accountStablecoin.principalDebt).plus((0, number_1.bnOrZero)(accountStablecoin.interestDebt));
484
+ const stablecoinDebtAmount = number_1.bnOrZero(accountStablecoin.principalDebt).plus(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 (0, number_1.bnOrZero)((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
505
+ return 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 = (0, number_1.bnOrZero)(cdpAmountRsp.amount);
516
+ const cdpAmount = 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 = (0, number_1.bnOrZero)(balanceRsp.balance.amount).plus(owedAmount);
522
+ const actualAmount = 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 = (0, number_1.bnOrZero)(allDebts[i].totalAccumulatedInterest);
545
- const principal = (0, number_1.bnOrZero)(allDebts[i].totalPrincipal);
544
+ const interest = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
545
+ const principal = 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 = (0, number_1.bnOrZero)(debtInfo.totalPrincipal).plus((0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest));
557
+ const debtAmt = number_1.bnOrZero(debtInfo.totalPrincipal).plus(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 = (0, number_1.bnOrZero)(balance.amount);
575
+ const amount = 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 = (0, number_1.bnOrZero)(priceResult.tokenPrice.twap).shiftedBy(-18);
599
+ const twap = 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 = (0, number_1.bnOrZero)(debtInfo.totalPrincipal);
615
- const accumInterest = (0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest);
614
+ const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
615
+ const accumInterest = 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 = (0, number_1.bnOrZero)((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
618
+ const interestFee = 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 = (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);
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);
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 = (0, number_1.bnOrZero)(debt.principalDebt);
664
- const initialCIM = (0, number_1.bnOrZero)(debt.initialCumulativeInterestMultiplier);
663
+ principalAmount = number_1.bnOrZero(debt.principalDebt);
664
+ const initialCIM = 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 = (0, number_1.bnOrZero)(31536000);
705
+ const secondsAYear = 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 = (0, number_1.bnOrZero)(params.interestFee).div(number_1.BN_10000);
730
- const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
729
+ const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
730
+ const utilizationRate = 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 = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
745
+ const cim = 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 = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
765
- const apy = (0, number_1.bnOrZero)((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
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);
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 = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
791
+ const tokenTwap = 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 = (0, number_1.bnOrZero)((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
802
+ const lockedAmount = 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 = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
820
+ const tokenTwap = 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 = (0, number_1.bnOrZero)(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
841
+ const bonus = 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 = (0, number_1.bnOrZero)(debtorAccountData.totalCollateralsUsd);
849
- const debtorTotalDebtVal = (0, number_1.bnOrZero)(debtorAccountData.totalDebtsUsd);
850
- const currentLiqThreshold = (0, number_1.bnOrZero)(debtorAccountData.currLiquidationThreshold);
848
+ const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
849
+ const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
850
+ const currentLiqThreshold = 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 = (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);
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);
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 = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(debtDenom));
860
+ const debtDecimals = 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 = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
868
+ const cdpTokenDecimals = 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 = (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);
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);
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);
@@ -1,13 +1,9 @@
1
- import { Coin } from "../codec/cosmos/base/v1beta1/coin";
2
1
  import { CarbonTx } from "../util";
3
2
  import BigNumber from "bignumber.js";
4
3
  import BaseModule from "./base";
5
4
  export declare class CoinModule extends BaseModule {
6
5
  createWithdrawal(params: CoinModule.CreateWithdrawalParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
7
6
  mintToken(params: CoinModule.MintTokenParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
8
- depositToGroup(params: CoinModule.DepositToGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
9
- convertToGroup(params: CoinModule.DepositToGroupParams[], opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
10
- withdrawFromGroup(params: CoinModule.WithdrawFromGroupParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
11
7
  }
12
8
  export declare namespace CoinModule {
13
9
  interface CreateWithdrawalParams {
@@ -23,12 +19,4 @@ export declare namespace CoinModule {
23
19
  amount: BigNumber;
24
20
  to?: string;
25
21
  }
26
- interface DepositToGroupParams {
27
- creator?: string;
28
- depositCoin: Coin;
29
- }
30
- interface WithdrawFromGroupParams {
31
- creator?: string;
32
- sourceCoin: Coin;
33
- }
34
22
  }
@@ -50,49 +50,5 @@ class CoinModule extends base_1.default {
50
50
  }, opts);
51
51
  });
52
52
  }
53
- depositToGroup(params, opts) {
54
- var _a;
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const wallet = this.getWallet();
57
- const value = tx_1.MsgDepositToGroup.fromPartial({
58
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
59
- depositCoin: params.depositCoin
60
- });
61
- return yield wallet.sendTx({
62
- typeUrl: util_1.CarbonTx.Types.MsgDepositToGroup,
63
- value,
64
- }, opts);
65
- });
66
- }
67
- convertToGroup(params, opts) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- const wallet = this.getWallet();
70
- const messages = params.map(param => {
71
- var _a;
72
- return ({
73
- typeUrl: util_1.CarbonTx.Types.MsgDepositToGroup,
74
- value: tx_1.MsgDepositToGroup.fromPartial({
75
- creator: (_a = param.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
76
- depositCoin: param.depositCoin,
77
- }),
78
- });
79
- });
80
- return yield wallet.sendTxs(messages, opts);
81
- });
82
- }
83
- withdrawFromGroup(params, opts) {
84
- var _a;
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const wallet = this.getWallet();
87
- const value = tx_1.MsgWithdrawFromGroup.fromPartial({
88
- creator: (_a = params.creator) !== null && _a !== void 0 ? _a : wallet.bech32Address,
89
- sourceCoin: params.sourceCoin
90
- });
91
- return yield wallet.sendTx({
92
- typeUrl: util_1.CarbonTx.Types.MsgWithdrawFromGroup,
93
- value,
94
- }, opts);
95
- });
96
- }
97
53
  }
98
54
  exports.CoinModule = CoinModule;