carbon-js-sdk 0.2.14-dev.2 → 0.2.14-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,15 @@ export declare class CDPModule extends BaseModule {
15
15
  supplyAssetAndLockCollateral(params: CDPModule.SupplyAssetAndLockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
16
16
  unlockCollateralAndWithdrawAsset(params: CDPModule.UnlockCollateralAndWithdrawAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
17
17
  liquidateCollateral(params: CDPModule.LiquidateCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
18
+ liquidateCollateralWithCdpTokens(params: CDPModule.LiquidateCollateralWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
19
+ liquidateCollateralWithCollateral(params: CDPModule.LiquidateCollateralWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
20
+ liquidateCollateralWithStablecoin(params: CDPModule.LiquidateCollateralWithStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
18
21
  repayAssetWithCdpTokens(params: CDPModule.RepayAssetWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
19
22
  repayAssetWithCollateral(params: CDPModule.RepayAssetWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
20
23
  mintStablecoin(params: CDPModule.MintStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
21
24
  returnStablecoin(params: CDPModule.ReturnStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
22
25
  updateRateStrategy(params: CDPModule.UpdateRateStrategyParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
26
+ claimRewards(opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
23
27
  getAccountData(account: string): Promise<{
24
28
  TotalCollateralsUsd: BigNumber;
25
29
  AvailableBorrowsUsd: BigNumber;
@@ -88,6 +92,34 @@ export declare namespace CDPModule {
88
92
  debtDenom: string;
89
93
  debtAmount: BigNumber;
90
94
  }
95
+ interface LiquidateCollateralWithCdpTokensParams {
96
+ debtor: string;
97
+ collateralDenom: string;
98
+ minCollateralAmount: BigNumber;
99
+ debtDenom: string;
100
+ debtAmount: BigNumber;
101
+ debtCollateralDenom: string;
102
+ debtCollateralAmount: BigNumber;
103
+ }
104
+ interface LiquidateCollateralWithCollateralParams {
105
+ debtor: string;
106
+ collateralDenom: string;
107
+ minCollateralAmount: BigNumber;
108
+ debtDenom: string;
109
+ debtAmount: BigNumber;
110
+ debtCollateralDenom: string;
111
+ debtCollateralAmount: BigNumber;
112
+ }
113
+ interface LiquidateCollateralWithStablecoinParams {
114
+ debtor: string;
115
+ collateralDenom: string;
116
+ minCollateralAmount: BigNumber;
117
+ debtDenom: string;
118
+ debtAmount: BigNumber;
119
+ principalAmount: BigNumber;
120
+ interestDenom: string;
121
+ interestAmount: BigNumber;
122
+ }
91
123
  interface RepayAssetWithCdpTokensParams {
92
124
  debtor?: string;
93
125
  debtDenom: string;
@@ -104,7 +136,6 @@ export declare namespace CDPModule {
104
136
  amount: BigNumber;
105
137
  }
106
138
  interface ReturnStablecoinParams {
107
- creator: string;
108
139
  principalAmount: BigNumber;
109
140
  interestDenom: string;
110
141
  interestAmount: BigNumber;
@@ -22,6 +22,7 @@ const number_1 = require("../util/number");
22
22
  const bignumber_js_1 = require("bignumber.js");
23
23
  const query_3 = require("./../codec/cdp/query");
24
24
  const base_1 = __importDefault(require("./base"));
25
+ const constant_1 = require("../constant");
25
26
  class CDPModule extends base_1.default {
26
27
  constructor() {
27
28
  super(...arguments);
@@ -159,6 +160,64 @@ class CDPModule extends base_1.default {
159
160
  }, opts);
160
161
  });
161
162
  }
163
+ liquidateCollateralWithCdpTokens(params, opts) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const wallet = this.getWallet();
166
+ const value = tx_1.MsgLiquidateCollateralWithCdpTokens.fromPartial({
167
+ creator: wallet.bech32Address,
168
+ debtor: params.debtor,
169
+ collateralDenom: params.collateralDenom,
170
+ minCollateralAmount: params.minCollateralAmount.toString(10),
171
+ debtDenom: params.debtDenom,
172
+ debtAmount: params.debtAmount.toString(10),
173
+ debtCollateralDenom: params.debtCollateralDenom,
174
+ debtCollateralAmount: params.debtCollateralAmount.toString(10)
175
+ });
176
+ return yield wallet.sendTx({
177
+ typeUrl: util_1.CarbonTx.Types.MsgLiquidateCollateralWithCdpTokens,
178
+ value
179
+ }, opts);
180
+ });
181
+ }
182
+ liquidateCollateralWithCollateral(params, opts) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ const wallet = this.getWallet();
185
+ const value = tx_1.MsgLiquidateCollateralWithCollateral.fromPartial({
186
+ creator: wallet.bech32Address,
187
+ debtor: params.debtor,
188
+ collateralDenom: params.collateralDenom,
189
+ minCollateralAmount: params.minCollateralAmount.toString(10),
190
+ debtDenom: params.debtDenom,
191
+ debtAmount: params.debtAmount.toString(10),
192
+ debtCollateralDenom: params.debtCollateralDenom,
193
+ debtCollateralAmount: params.debtCollateralAmount.toString(10)
194
+ });
195
+ return yield wallet.sendTx({
196
+ typeUrl: util_1.CarbonTx.Types.MsgLiquidateCollateralWithCollateral,
197
+ value
198
+ }, opts);
199
+ });
200
+ }
201
+ liquidateCollateralWithStablecoin(params, opts) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ const wallet = this.getWallet();
204
+ const value = tx_1.MsgLiquidateCollateralWithStablecoin.fromPartial({
205
+ creator: wallet.bech32Address,
206
+ debtor: params.debtor,
207
+ collateralDenom: params.collateralDenom,
208
+ minCollateralAmount: params.minCollateralAmount.toString(10),
209
+ debtDenom: params.debtDenom,
210
+ debtAmount: params.debtAmount.toString(10),
211
+ principalAmount: params.principalAmount.toString(10),
212
+ interestDenom: params.interestDenom,
213
+ interestAmount: params.interestAmount.toString(10),
214
+ });
215
+ return yield wallet.sendTx({
216
+ typeUrl: util_1.CarbonTx.Types.MsgLiquidateCollateralWithStablecoin,
217
+ value
218
+ }, opts);
219
+ });
220
+ }
162
221
  repayAssetWithCdpTokens(params, opts) {
163
222
  return __awaiter(this, void 0, void 0, function* () {
164
223
  const wallet = this.getWallet();
@@ -182,7 +241,7 @@ class CDPModule extends base_1.default {
182
241
  const debtor = params.debtor ? params.debtor : wallet.bech32Address;
183
242
  const value = tx_1.MsgRepayAssetWithCollateral.fromPartial({
184
243
  creator: wallet.bech32Address,
185
- debtor: params.debtor,
244
+ debtor: debtor,
186
245
  debtDenom: params.debtDenom,
187
246
  cdpDenom: params.cdpDenom,
188
247
  cdpAmount: params.cdpAmount.toString(10),
@@ -234,6 +293,18 @@ class CDPModule extends base_1.default {
234
293
  }, opts);
235
294
  });
236
295
  }
296
+ claimRewards(opts) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ const wallet = this.getWallet();
299
+ const value = tx_1.MsgClaimRewards.fromPartial({
300
+ creator: wallet.bech32Address,
301
+ });
302
+ return yield wallet.sendTx({
303
+ typeUrl: util_1.CarbonTx.Types.MsgClaimRewards,
304
+ value,
305
+ }, opts);
306
+ });
307
+ }
237
308
  // start of cdp calculations
238
309
  getAccountData(account) {
239
310
  var _a;
@@ -631,7 +702,10 @@ class CDPModule extends base_1.default {
631
702
  const assetParams = yield sdk.query.cdp.Asset({ denom: denom });
632
703
  if (!assetParams.assetParams)
633
704
  return;
634
- const ltv = new bignumber_js_1.BigNumber(assetParams.assetParams.loanToValue);
705
+ let unlockRatio = new bignumber_js_1.BigNumber(assetParams.assetParams.loanToValue);
706
+ if (sdk.getConfig().network === constant_1.Network.LocalHost || sdk.getConfig().network === constant_1.Network.DevNet) {
707
+ unlockRatio = new bignumber_js_1.BigNumber(assetParams.assetParams.liquidationThreshold);
708
+ }
635
709
  const accountData = yield this.getAccountData(account);
636
710
  if (!accountData)
637
711
  return;
@@ -639,7 +713,7 @@ class CDPModule extends base_1.default {
639
713
  if (!tokenDecimals)
640
714
  return;
641
715
  const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
642
- const unlockableUsd = availableBorrowsUsd.multipliedBy(10000).div(ltv);
716
+ const unlockableUsd = availableBorrowsUsd.multipliedBy(10000).div(unlockRatio);
643
717
  const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
644
718
  if (!tokenPrice.tokenPrice)
645
719
  return;
@@ -50,7 +50,10 @@ const TxTypes = {
50
50
  UpdateAsset: "cdp/UpdateAsset",
51
51
  SetLiquidationFee: "cdp/SetLiquidationFee",
52
52
  SetInterestFee: "cdp/SetInterestFee",
53
- SetStableCoinInterestRate: "cdp/SetStableCoinInterestRate",
53
+ SetStablecoinInterestRate: "cdp/SetStablecoinInterestRate",
54
+ SetCompleteLiquidationThreshold: "cdp/SetCompleteLiquidationThreshold",
55
+ SetMinimumCloseFactor: "cdp/SetMinimumCloseFactor",
56
+ SetSmallLiquidationSize: "cdp/SetSmallLiquidationSize",
54
57
  };
55
58
  const MsgCreateOracle = {
56
59
  aminoType: TxTypes.CreateOracle,
@@ -181,35 +184,53 @@ const MsgEditValidator = {
181
184
  };
182
185
  const MsgAddRateStrategy = {
183
186
  aminoType: TxTypes.AddRateStrategy,
184
- valueMap: {}
187
+ valueMap: {},
185
188
  };
186
189
  const MsgUpdateRateStrategy = {
187
190
  aminoType: TxTypes.UpdateRateStrategy,
188
- valueMap: {}
191
+ valueMap: {},
189
192
  };
190
193
  const MsgRemoveRateStrategy = {
191
194
  aminoType: TxTypes.RemoveRateStrategy,
192
- valueMap: {}
195
+ valueMap: {},
193
196
  };
194
197
  const MsgAddAsset = {
195
198
  aminoType: TxTypes.AddAsset,
196
- valueMap: {}
199
+ valueMap: {},
197
200
  };
198
201
  const MsgUpdateAsset = {
199
202
  aminoType: TxTypes.UpdateAsset,
200
- valueMap: {}
203
+ valueMap: {},
201
204
  };
202
205
  const MsgSetLiquidationFee = {
203
206
  aminoType: TxTypes.SetLiquidationFee,
204
- valueMap: {}
207
+ valueMap: {},
205
208
  };
206
209
  const MsgSetInterestFee = {
207
210
  aminoType: TxTypes.SetInterestFee,
208
- valueMap: {}
211
+ valueMap: {},
212
+ };
213
+ const MsgSetStablecoinInterestRate = {
214
+ aminoType: TxTypes.SetStablecoinInterestRate,
215
+ valueMap: {},
209
216
  };
210
- const MsgSetStableCoinInterestRate = {
211
- aminoType: TxTypes.SetStableCoinInterestRate,
212
- valueMap: {}
217
+ const MsgSetCompleteLiquidationThreshold = {
218
+ aminoType: TxTypes.SetCompleteLiquidationThreshold,
219
+ valueMap: {
220
+ completeLiquidationThreshold: utils_1.ConvertEncType.Dec,
221
+ },
222
+ };
223
+ const MsgSetMinimumCloseFactor = {
224
+ aminoType: TxTypes.SetMinimumCloseFactor,
225
+ valueMap: {
226
+ minimumCloseFactor: utils_1.ConvertEncType.Dec,
227
+ },
228
+ };
229
+ const MsgSetSmallLiquidationSize = {
230
+ aminoType: TxTypes.SetSmallLiquidationSize,
231
+ valueMap: {
232
+ smallLiquidationSize: utils_1.ConvertEncType.Dec,
233
+ },
213
234
  };
214
235
  const AdminAmino = {
215
236
  [CarbonTx.Types.MsgCreateOracle]: (0, utils_1.generateAminoType)(MsgCreateOracle),
@@ -238,6 +259,9 @@ const AdminAmino = {
238
259
  [CarbonTx.Types.MsgUpdateAsset]: (0, utils_1.generateAminoType)(MsgUpdateAsset),
239
260
  [CarbonTx.Types.MsgSetLiquidationFee]: (0, utils_1.generateAminoType)(MsgSetLiquidationFee),
240
261
  [CarbonTx.Types.MsgSetInterestFee]: (0, utils_1.generateAminoType)(MsgSetInterestFee),
241
- [CarbonTx.Types.MsgSetStablecoinInterestRate]: (0, utils_1.generateAminoType)(MsgSetStableCoinInterestRate),
262
+ [CarbonTx.Types.MsgSetStablecoinInterestRate]: (0, utils_1.generateAminoType)(MsgSetStablecoinInterestRate),
263
+ [CarbonTx.Types.MsgSetCompleteLiquidationThreshold]: (0, utils_1.generateAminoType)(MsgSetCompleteLiquidationThreshold),
264
+ [CarbonTx.Types.MsgSetMinimumCloseFactor]: (0, utils_1.generateAminoType)(MsgSetMinimumCloseFactor),
265
+ [CarbonTx.Types.MsgSetSmallLiquidationSize]: (0, utils_1.generateAminoType)(MsgSetSmallLiquidationSize),
242
266
  };
243
267
  exports.default = AdminAmino;
@@ -34,6 +34,11 @@ const TxTypes = {
34
34
  RepayAssetWithCdpTokens: "cdp/RepayAssetWithCdpTokens",
35
35
  RepayAssetWithCollateral: "cdp/RepayAssetWithCollateral",
36
36
  MintStablecoin: "cdp/MintStablecoin",
37
+ ReturnStablecoin: "cdp/ReturnStablecoin",
38
+ LiquidateCollateralWithCdpTokens: "cdp/LiquidateCollateralWithCdpTokens",
39
+ LiquidateCollateralWithCollateral: "cdp/LiquidateCollateralWithCollateral",
40
+ LiquidateCollateralWithStablecoin: "cdp/LiquidateCollateralWithStablecoin",
41
+ ClaimRewards: "cdp/ClaimRewards",
37
42
  };
38
43
  const MsgSupplyAsset = {
39
44
  aminoType: TxTypes.SupplyAsset,
@@ -83,6 +88,26 @@ const MsgMintStablecoin = {
83
88
  aminoType: TxTypes.MintStablecoin,
84
89
  valueMap: {},
85
90
  };
91
+ const MsgReturnStablecoin = {
92
+ aminoType: TxTypes.ReturnStablecoin,
93
+ valueMap: {},
94
+ };
95
+ const MsgLiquidateCollateralWithCdpTokens = {
96
+ aminoType: TxTypes.LiquidateCollateralWithCdpTokens,
97
+ valueMap: {},
98
+ };
99
+ const MsgLiquidateCollateralWithCollateral = {
100
+ aminoType: TxTypes.LiquidateCollateralWithCollateral,
101
+ valueMap: {},
102
+ };
103
+ const MsgLiquidateCollateralWithStablecoin = {
104
+ aminoType: TxTypes.LiquidateCollateralWithStablecoin,
105
+ valueMap: {},
106
+ };
107
+ const MsgClaimRewards = {
108
+ aminoType: TxTypes.ClaimRewards,
109
+ valueMap: {},
110
+ };
86
111
  const CdpAmino = {
87
112
  [CarbonTx.Types.MsgSupplyAsset]: (0, utils_1.generateAminoType)(MsgSupplyAsset),
88
113
  [CarbonTx.Types.MsgWithdrawAsset]: (0, utils_1.generateAminoType)(MsgWithdrawAsset),
@@ -96,5 +121,10 @@ const CdpAmino = {
96
121
  [CarbonTx.Types.MsgRepayAssetWithCdpTokens]: (0, utils_1.generateAminoType)(MsgRepayAssetWithCdpTokens),
97
122
  [CarbonTx.Types.MsgRepayAssetWithCollateral]: (0, utils_1.generateAminoType)(MsgRepayAssetWithCollateral),
98
123
  [CarbonTx.Types.MsgMintStablecoin]: (0, utils_1.generateAminoType)(MsgMintStablecoin),
124
+ [CarbonTx.Types.MsgReturnStablecoin]: (0, utils_1.generateAminoType)(MsgReturnStablecoin),
125
+ [CarbonTx.Types.MsgLiquidateCollateralWithCdpTokens]: (0, utils_1.generateAminoType)(MsgLiquidateCollateralWithCdpTokens),
126
+ [CarbonTx.Types.MsgLiquidateCollateralWithCollateral]: (0, utils_1.generateAminoType)(MsgLiquidateCollateralWithCollateral),
127
+ [CarbonTx.Types.MsgLiquidateCollateralWithStablecoin]: (0, utils_1.generateAminoType)(MsgLiquidateCollateralWithStablecoin),
128
+ [CarbonTx.Types.MsgClaimRewards]: (0, utils_1.generateAminoType)(MsgClaimRewards),
99
129
  };
100
130
  exports.default = CdpAmino;
package/lib/util/tx.d.ts CHANGED
@@ -117,6 +117,8 @@ export declare const Types: {
117
117
  MsgUpdateRewardSchemeResponse: string;
118
118
  MsgAddRewardReserve: string;
119
119
  MsgAddRewardReserveResponse: string;
120
+ MsgClaimRewards: string;
121
+ MsgClaimRewardsResponse: string;
120
122
  MsgSyncGenesis: string;
121
123
  MsgSyncGenesisResponse: string;
122
124
  MsgSyncHeaders: string;
@@ -335,6 +337,14 @@ export declare const Types: {
335
337
  SetCommitmentCurveProposal: string;
336
338
  SetRewardsWeightsProposal: string;
337
339
  UpdatePoolProposal: string;
340
+ MsgSetBackfillTimeInterval: string;
341
+ MsgSetBackfillTimeIntervalResponse: string;
342
+ MsgSetSmoothenBand: string;
343
+ MsgSetSmoothenBandResponse: string;
344
+ MsgSetImpactBand: string;
345
+ MsgSetImpactBandResponse: string;
346
+ MsgSetStaleIndexAllowance: string;
347
+ MsgSetStaleIndexAllowanceResponse: string;
338
348
  SettlementPriceProposal: string;
339
349
  MsgSetWrapperMapping: string;
340
350
  MsgSetWrapperMappingResponse: string;
@@ -122,6 +122,11 @@ export interface WsGetCdpStablecoinDebt {
122
122
  }
123
123
  export interface WsGetCdpLiquidations {
124
124
  }
125
+ export interface WsGetCdpRewardSchemes {
126
+ }
127
+ export interface WsGetCdpRewardDebts {
128
+ address: string;
129
+ }
125
130
  export interface WsSubscribeParams {
126
131
  channel: WSChannel;
127
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.2.14-dev.2+8037d7433bdd",
3
+ "version": "0.2.14-dev.4+b00fe13d8bb3",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",