carbon-js-sdk 0.3.45 → 0.3.46
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.
- package/lib/modules/cdp.d.ts +13 -2
- package/lib/modules/cdp.js +47 -18
- package/package.json +1 -1
package/lib/modules/cdp.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="long" />
|
|
2
2
|
import { AssetParams, DebtInfo, RateStrategyParams, StablecoinDebtInfo } from "../codec";
|
|
3
|
+
import { Params } from "../codec/cdp/params";
|
|
3
4
|
import { CarbonTx } from "../util";
|
|
4
5
|
import { BigNumber } from "bignumber.js";
|
|
5
6
|
import { Debt } from "./../codec/cdp/query";
|
|
6
7
|
import BaseModule from "./base";
|
|
7
|
-
import { Params } from "../codec/cdp/params";
|
|
8
8
|
export declare class CDPModule extends BaseModule {
|
|
9
9
|
private cdpModuleAddress;
|
|
10
10
|
supplyAsset(params: CDPModule.SupplyAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
@@ -12,13 +12,19 @@ export declare class CDPModule extends BaseModule {
|
|
|
12
12
|
lockCollateral(params: CDPModule.LockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
13
13
|
unlockCollateral(params: CDPModule.UnlockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
14
14
|
borrowAsset(params: CDPModule.BorrowAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
15
|
-
repayAsset(params: CDPModule.RepayAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
16
15
|
supplyAssetAndLockCollateral(params: CDPModule.SupplyAssetAndLockCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
17
16
|
unlockCollateralAndWithdrawAsset(params: CDPModule.UnlockCollateralAndWithdrawAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
18
17
|
liquidateCollateral(params: CDPModule.LiquidateCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
19
18
|
liquidateCollateralWithCdpTokens(params: CDPModule.LiquidateCollateralWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
20
19
|
liquidateCollateralWithCollateral(params: CDPModule.LiquidateCollateralWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
21
20
|
liquidateCollateralWithStablecoin(params: CDPModule.LiquidateCollateralWithStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
21
|
+
repayAsset(params: CDPModule.RepayAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Uses grouped token balance to repay for existing CDP asset debt.
|
|
24
|
+
* Calls 2 msg in 1 tx, MsgWithdrawFromGroup and MsgRepayAsset.
|
|
25
|
+
* Ensure that grouped token balance is sufficient.
|
|
26
|
+
*/
|
|
27
|
+
repayAssetWithGroupedToken(params: CDPModule.RepayAssetWithGroupedToken, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
22
28
|
repayAssetWithCdpTokens(params: CDPModule.RepayAssetWithCdpTokensParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
23
29
|
repayAssetWithCollateral(params: CDPModule.RepayAssetWithCollateralParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
24
30
|
mintStablecoin(params: CDPModule.MintStablecoinParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
@@ -162,6 +168,11 @@ export declare namespace CDPModule {
|
|
|
162
168
|
cdpDenom: string;
|
|
163
169
|
cdpAmount: BigNumber;
|
|
164
170
|
}
|
|
171
|
+
interface RepayAssetWithGroupedToken {
|
|
172
|
+
denom: string;
|
|
173
|
+
amount: BigNumber;
|
|
174
|
+
debtor?: string;
|
|
175
|
+
}
|
|
165
176
|
interface RepayAssetWithCollateralParams {
|
|
166
177
|
debtor?: string;
|
|
167
178
|
debtDenom: string;
|
package/lib/modules/cdp.js
CHANGED
|
@@ -13,18 +13,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CDPModule = void 0;
|
|
16
|
+
const TokenClient_1 = __importDefault(require("../clients/TokenClient"));
|
|
16
17
|
const codec_1 = require("../codec");
|
|
17
18
|
const query_1 = require("../codec/cdp/query");
|
|
18
19
|
const tx_1 = require("../codec/cdp/tx");
|
|
19
20
|
const query_2 = require("../codec/cosmos/bank/v1beta1/query");
|
|
21
|
+
const constant_1 = require("../constant");
|
|
20
22
|
const util_1 = require("../util");
|
|
23
|
+
const address_1 = require("../util/address");
|
|
21
24
|
const number_1 = require("../util/number");
|
|
22
25
|
const bignumber_js_1 = require("bignumber.js");
|
|
23
26
|
const query_3 = require("./../codec/cdp/query");
|
|
24
27
|
const base_1 = __importDefault(require("./base"));
|
|
25
|
-
const constant_1 = require("../constant");
|
|
26
|
-
const TokenClient_1 = __importDefault(require("../clients/TokenClient"));
|
|
27
|
-
const address_1 = require("../util/address");
|
|
28
28
|
class CDPModule extends base_1.default {
|
|
29
29
|
supplyAsset(params, opts) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,21 +96,6 @@ class CDPModule extends base_1.default {
|
|
|
96
96
|
}, opts);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
repayAsset(params, opts) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const wallet = this.getWallet();
|
|
102
|
-
const value = tx_1.MsgRepayAsset.fromPartial({
|
|
103
|
-
creator: wallet.bech32Address,
|
|
104
|
-
denom: params.denom,
|
|
105
|
-
amount: params.amount.toString(10),
|
|
106
|
-
debtor: params.debtor,
|
|
107
|
-
});
|
|
108
|
-
return yield wallet.sendTx({
|
|
109
|
-
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
110
|
-
value,
|
|
111
|
-
}, opts);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
99
|
supplyAssetAndLockCollateral(params, opts) {
|
|
115
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
101
|
const wallet = this.getWallet();
|
|
@@ -215,6 +200,50 @@ class CDPModule extends base_1.default {
|
|
|
215
200
|
}, opts);
|
|
216
201
|
});
|
|
217
202
|
}
|
|
203
|
+
repayAsset(params, opts) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const wallet = this.getWallet();
|
|
206
|
+
const value = tx_1.MsgRepayAsset.fromPartial({
|
|
207
|
+
creator: wallet.bech32Address,
|
|
208
|
+
denom: params.denom,
|
|
209
|
+
amount: params.amount.toString(10),
|
|
210
|
+
debtor: params.debtor,
|
|
211
|
+
});
|
|
212
|
+
return yield wallet.sendTx({
|
|
213
|
+
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
214
|
+
value,
|
|
215
|
+
}, opts);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Uses grouped token balance to repay for existing CDP asset debt.
|
|
220
|
+
* Calls 2 msg in 1 tx, MsgWithdrawFromGroup and MsgRepayAsset.
|
|
221
|
+
* Ensure that grouped token balance is sufficient.
|
|
222
|
+
*/
|
|
223
|
+
repayAssetWithGroupedToken(params, opts) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const wallet = this.getWallet();
|
|
226
|
+
const debtor = params.debtor ? params.debtor : wallet.bech32Address;
|
|
227
|
+
return yield wallet.sendTxs([{
|
|
228
|
+
typeUrl: util_1.CarbonTx.Types.MsgWithdrawFromGroup,
|
|
229
|
+
value: codec_1.MsgWithdrawFromGroup.fromPartial({
|
|
230
|
+
creator: wallet.bech32Address,
|
|
231
|
+
sourceCoin: {
|
|
232
|
+
amount: params.amount.toString(10),
|
|
233
|
+
denom: params.denom,
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
}, {
|
|
237
|
+
typeUrl: util_1.CarbonTx.Types.MsgRepayAsset,
|
|
238
|
+
value: tx_1.MsgRepayAsset.fromPartial({
|
|
239
|
+
creator: wallet.bech32Address,
|
|
240
|
+
debtor: debtor,
|
|
241
|
+
denom: params.denom,
|
|
242
|
+
amount: params.amount.toString(10),
|
|
243
|
+
}),
|
|
244
|
+
}], opts);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
218
247
|
repayAssetWithCdpTokens(params, opts) {
|
|
219
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
249
|
const wallet = this.getWallet();
|