carbon-js-sdk 0.3.2 → 0.3.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.
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +6 -6
- package/lib/clients/TokenClient.js +4 -2
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/bank/tx.d.ts +64 -0
- package/lib/codec/bank/tx.js +236 -0
- package/lib/codec/cdp/query.d.ts +14 -2
- package/lib/codec/cdp/query.js +40 -2
- package/lib/codec/cdp/tx.d.ts +4 -11
- package/lib/codec/cdp/tx.js +5 -130
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/codec/index.d.ts +2 -2
- package/lib/codec/index.js +11 -13
- package/lib/codec/oracle/event.d.ts +1 -33
- package/lib/codec/oracle/event.js +1 -166
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.d.ts +4 -1
- package/lib/modules/cdp.js +54 -50
- package/lib/modules/gov.js +14 -14
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +30 -30
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +22 -22
- package/lib/provider/amino/types/coin.js +2 -2
- package/lib/provider/amino/types/gov.js +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/keplr/KeplrStore.js +1 -1
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/number.js +5 -5
- package/lib/util/tx.d.ts +5 -1
- package/lib/util/tx.js +8 -1
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.js +7 -7
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
|
@@ -3,177 +3,12 @@ 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.OracleSlashEvent = exports.ResultEvent = exports.
|
|
6
|
+
exports.OracleSlashEvent = exports.ResultEvent = 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"));
|
|
10
10
|
const oracle_1 = require("./oracle");
|
|
11
11
|
exports.protobufPackage = "Switcheo.carbon.oracle";
|
|
12
|
-
const baseNewVoteEvent = { voterAccount: "" };
|
|
13
|
-
exports.NewVoteEvent = {
|
|
14
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
15
|
-
if (message.voterAccount !== "") {
|
|
16
|
-
writer.uint32(10).string(message.voterAccount);
|
|
17
|
-
}
|
|
18
|
-
return writer;
|
|
19
|
-
},
|
|
20
|
-
decode(input, length) {
|
|
21
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
22
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
23
|
-
const message = Object.assign({}, baseNewVoteEvent);
|
|
24
|
-
while (reader.pos < end) {
|
|
25
|
-
const tag = reader.uint32();
|
|
26
|
-
switch (tag >>> 3) {
|
|
27
|
-
case 1:
|
|
28
|
-
message.voterAccount = reader.string();
|
|
29
|
-
break;
|
|
30
|
-
default:
|
|
31
|
-
reader.skipType(tag & 7);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return message;
|
|
36
|
-
},
|
|
37
|
-
fromJSON(object) {
|
|
38
|
-
const message = Object.assign({}, baseNewVoteEvent);
|
|
39
|
-
message.voterAccount =
|
|
40
|
-
object.voterAccount !== undefined && object.voterAccount !== null
|
|
41
|
-
? String(object.voterAccount)
|
|
42
|
-
: "";
|
|
43
|
-
return message;
|
|
44
|
-
},
|
|
45
|
-
toJSON(message) {
|
|
46
|
-
const obj = {};
|
|
47
|
-
message.voterAccount !== undefined &&
|
|
48
|
-
(obj.voterAccount = message.voterAccount);
|
|
49
|
-
return obj;
|
|
50
|
-
},
|
|
51
|
-
fromPartial(object) {
|
|
52
|
-
var _a;
|
|
53
|
-
const message = Object.assign({}, baseNewVoteEvent);
|
|
54
|
-
message.voterAccount = (_a = object.voterAccount) !== null && _a !== void 0 ? _a : "";
|
|
55
|
-
return message;
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const baseRecordVoteEvent = { voterAccount: "" };
|
|
59
|
-
exports.RecordVoteEvent = {
|
|
60
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
61
|
-
if (message.voterAccount !== "") {
|
|
62
|
-
writer.uint32(10).string(message.voterAccount);
|
|
63
|
-
}
|
|
64
|
-
return writer;
|
|
65
|
-
},
|
|
66
|
-
decode(input, length) {
|
|
67
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
68
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
69
|
-
const message = Object.assign({}, baseRecordVoteEvent);
|
|
70
|
-
while (reader.pos < end) {
|
|
71
|
-
const tag = reader.uint32();
|
|
72
|
-
switch (tag >>> 3) {
|
|
73
|
-
case 1:
|
|
74
|
-
message.voterAccount = reader.string();
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
reader.skipType(tag & 7);
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return message;
|
|
82
|
-
},
|
|
83
|
-
fromJSON(object) {
|
|
84
|
-
const message = Object.assign({}, baseRecordVoteEvent);
|
|
85
|
-
message.voterAccount =
|
|
86
|
-
object.voterAccount !== undefined && object.voterAccount !== null
|
|
87
|
-
? String(object.voterAccount)
|
|
88
|
-
: "";
|
|
89
|
-
return message;
|
|
90
|
-
},
|
|
91
|
-
toJSON(message) {
|
|
92
|
-
const obj = {};
|
|
93
|
-
message.voterAccount !== undefined &&
|
|
94
|
-
(obj.voterAccount = message.voterAccount);
|
|
95
|
-
return obj;
|
|
96
|
-
},
|
|
97
|
-
fromPartial(object) {
|
|
98
|
-
var _a;
|
|
99
|
-
const message = Object.assign({}, baseRecordVoteEvent);
|
|
100
|
-
message.voterAccount = (_a = object.voterAccount) !== null && _a !== void 0 ? _a : "";
|
|
101
|
-
return message;
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
const baseVoteEvent = { voteId: "", type: "" };
|
|
105
|
-
exports.VoteEvent = {
|
|
106
|
-
encode(message, writer = minimal_1.default.Writer.create()) {
|
|
107
|
-
if (message.vote !== undefined) {
|
|
108
|
-
oracle_1.Vote.encode(message.vote, writer.uint32(10).fork()).ldelim();
|
|
109
|
-
}
|
|
110
|
-
if (message.voteId !== "") {
|
|
111
|
-
writer.uint32(18).string(message.voteId);
|
|
112
|
-
}
|
|
113
|
-
if (message.type !== "") {
|
|
114
|
-
writer.uint32(26).string(message.type);
|
|
115
|
-
}
|
|
116
|
-
return writer;
|
|
117
|
-
},
|
|
118
|
-
decode(input, length) {
|
|
119
|
-
const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
|
|
120
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
121
|
-
const message = Object.assign({}, baseVoteEvent);
|
|
122
|
-
while (reader.pos < end) {
|
|
123
|
-
const tag = reader.uint32();
|
|
124
|
-
switch (tag >>> 3) {
|
|
125
|
-
case 1:
|
|
126
|
-
message.vote = oracle_1.Vote.decode(reader, reader.uint32());
|
|
127
|
-
break;
|
|
128
|
-
case 2:
|
|
129
|
-
message.voteId = reader.string();
|
|
130
|
-
break;
|
|
131
|
-
case 3:
|
|
132
|
-
message.type = reader.string();
|
|
133
|
-
break;
|
|
134
|
-
default:
|
|
135
|
-
reader.skipType(tag & 7);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return message;
|
|
140
|
-
},
|
|
141
|
-
fromJSON(object) {
|
|
142
|
-
const message = Object.assign({}, baseVoteEvent);
|
|
143
|
-
message.vote =
|
|
144
|
-
object.vote !== undefined && object.vote !== null
|
|
145
|
-
? oracle_1.Vote.fromJSON(object.vote)
|
|
146
|
-
: undefined;
|
|
147
|
-
message.voteId =
|
|
148
|
-
object.voteId !== undefined && object.voteId !== null
|
|
149
|
-
? String(object.voteId)
|
|
150
|
-
: "";
|
|
151
|
-
message.type =
|
|
152
|
-
object.type !== undefined && object.type !== null
|
|
153
|
-
? String(object.type)
|
|
154
|
-
: "";
|
|
155
|
-
return message;
|
|
156
|
-
},
|
|
157
|
-
toJSON(message) {
|
|
158
|
-
const obj = {};
|
|
159
|
-
message.vote !== undefined &&
|
|
160
|
-
(obj.vote = message.vote ? oracle_1.Vote.toJSON(message.vote) : undefined);
|
|
161
|
-
message.voteId !== undefined && (obj.voteId = message.voteId);
|
|
162
|
-
message.type !== undefined && (obj.type = message.type);
|
|
163
|
-
return obj;
|
|
164
|
-
},
|
|
165
|
-
fromPartial(object) {
|
|
166
|
-
var _a, _b;
|
|
167
|
-
const message = Object.assign({}, baseVoteEvent);
|
|
168
|
-
message.vote =
|
|
169
|
-
object.vote !== undefined && object.vote !== null
|
|
170
|
-
? oracle_1.Vote.fromPartial(object.vote)
|
|
171
|
-
: undefined;
|
|
172
|
-
message.voteId = (_a = object.voteId) !== null && _a !== void 0 ? _a : "";
|
|
173
|
-
message.type = (_b = object.type) !== null && _b !== void 0 ? _b : "";
|
|
174
|
-
return message;
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
12
|
const baseResultEvent = { resultId: "", type: "" };
|
|
178
13
|
exports.ResultEvent = {
|
|
179
14
|
encode(message, writer = minimal_1.default.Writer.create()) {
|
package/lib/constant/generic.js
CHANGED
|
@@ -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:
|
|
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.CURRENT_GAS_PRICE = 769.23077;
|
package/lib/modules/cdp.d.ts
CHANGED
|
@@ -47,7 +47,10 @@ export declare class CDPModule extends BaseModule {
|
|
|
47
47
|
calculateAPY(denom: string, debtInfo?: DebtInfo, assetParams?: AssetParams, rateStrategyParams?: RateStrategyParams): Promise<BigNumber>;
|
|
48
48
|
static calculateInterestForTimePeriod(apy: BigNumber, start: Date, end: Date): BigNumber;
|
|
49
49
|
calculateLendAPY(denom: string, borrowInterest?: BigNumber, debtInfo?: DebtInfo, params?: Params): Promise<BigNumber>;
|
|
50
|
-
recalculateCIM(denom: string, debtInfo?: DebtInfo): Promise<
|
|
50
|
+
recalculateCIM(denom: string, debtInfo?: DebtInfo): Promise<{
|
|
51
|
+
cim: BigNumber;
|
|
52
|
+
interest: BigNumber;
|
|
53
|
+
}>;
|
|
51
54
|
recalculateStablecoinCIM(debtInfo?: StablecoinDebtInfo): Promise<BigNumber>;
|
|
52
55
|
getMaxCollateralForUnlock(account: string, cdpDenom: string): Promise<BigNumber | undefined>;
|
|
53
56
|
getCdpModuleAddress(): string;
|
package/lib/modules/cdp.js
CHANGED
|
@@ -336,7 +336,7 @@ class CDPModule extends base_1.default {
|
|
|
336
336
|
let availableBorrowsUsd = number_1.BN_ZERO;
|
|
337
337
|
let currLiquidationThreshold = number_1.BN_ZERO;
|
|
338
338
|
for (let i = 0; i < collaterals.length; i++) {
|
|
339
|
-
const amount =
|
|
339
|
+
const amount = number_1.bnOrZero(collaterals[i].collateralAmount);
|
|
340
340
|
if (amount.isZero()) {
|
|
341
341
|
continue; // no collateral for denom
|
|
342
342
|
}
|
|
@@ -353,9 +353,9 @@ class CDPModule extends base_1.default {
|
|
|
353
353
|
if (!assetParam) {
|
|
354
354
|
continue;
|
|
355
355
|
}
|
|
356
|
-
const ltv =
|
|
356
|
+
const ltv = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
|
|
357
357
|
const availableBorrowUsd = collateralUsdVal.times(ltv);
|
|
358
|
-
const liquidationThreshold =
|
|
358
|
+
const liquidationThreshold = number_1.bnOrZero(assetParam.liquidationThreshold).div(number_1.BN_10000);
|
|
359
359
|
const liquidationThresholdVal = collateralUsdVal.times(liquidationThreshold);
|
|
360
360
|
totalCollateralsUsd = totalCollateralsUsd.plus(collateralUsdVal);
|
|
361
361
|
availableBorrowsUsd = availableBorrowsUsd.plus(availableBorrowUsd);
|
|
@@ -366,7 +366,7 @@ class CDPModule extends base_1.default {
|
|
|
366
366
|
const debts = debtsRsp.debts;
|
|
367
367
|
let totalDebtsUsd = number_1.BN_ZERO;
|
|
368
368
|
for (let i = 0; i < debts.length; i++) {
|
|
369
|
-
const amount =
|
|
369
|
+
const amount = number_1.bnOrZero(debts[i].principalDebt);
|
|
370
370
|
const denom = debts[i].denom;
|
|
371
371
|
if (amount.isZero()) {
|
|
372
372
|
continue;
|
|
@@ -388,7 +388,7 @@ class CDPModule extends base_1.default {
|
|
|
388
388
|
if (stablecoinDebtInfo) {
|
|
389
389
|
const accountStablecoin = yield sdk.query.cdp.AccountStablecoin({ address: account });
|
|
390
390
|
const stablecoinDecimals = (_a = yield this.sdkProvider.getTokenClient().getDecimals(stablecoinDebtInfo.denom)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
|
|
391
|
-
const stablecoinDebtAmount =
|
|
391
|
+
const stablecoinDebtAmount = number_1.bnOrZero(accountStablecoin.principalDebt).plus(number_1.bnOrZero(accountStablecoin.interestDebt));
|
|
392
392
|
stablecoinDebtUsd = stablecoinDebtAmount.shiftedBy(-stablecoinDecimals);
|
|
393
393
|
totalDebtsUsd = totalDebtsUsd.plus(stablecoinDebtUsd);
|
|
394
394
|
}
|
|
@@ -409,7 +409,7 @@ class CDPModule extends base_1.default {
|
|
|
409
409
|
const sdk = this.sdkProvider;
|
|
410
410
|
const cdpAddress = this.getCdpModuleAddress();
|
|
411
411
|
const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
|
|
412
|
-
return
|
|
412
|
+
return number_1.bnOrZero((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
getCdpToActualRatio(cdpDenom) {
|
|
@@ -420,13 +420,13 @@ class CDPModule extends base_1.default {
|
|
|
420
420
|
const cdpAmountRsp = supplyRsp.amount;
|
|
421
421
|
if (!cdpAmountRsp)
|
|
422
422
|
throw new Error("unable to retrieve cdp token supply");
|
|
423
|
-
const cdpAmount =
|
|
423
|
+
const cdpAmount = number_1.bnOrZero(cdpAmountRsp.amount);
|
|
424
424
|
const cdpAddress = this.getCdpModuleAddress();
|
|
425
425
|
const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
|
|
426
426
|
if (!balanceRsp.balance)
|
|
427
427
|
throw new Error("unable to retrieve cdp module balance");
|
|
428
428
|
const owedAmount = yield this.getTotalTokenDebt(denom);
|
|
429
|
-
const actualAmount =
|
|
429
|
+
const actualAmount = number_1.bnOrZero(balanceRsp.balance.amount).plus(owedAmount);
|
|
430
430
|
if (!owedAmount)
|
|
431
431
|
throw new Error("unable to retrieve total token debt");
|
|
432
432
|
return cdpAmount.div(actualAmount);
|
|
@@ -448,8 +448,8 @@ class CDPModule extends base_1.default {
|
|
|
448
448
|
const allDebts = allDebtsRes.debtInfosAll;
|
|
449
449
|
for (let i = 0; i < allDebts.length; i++) {
|
|
450
450
|
const denom = allDebts[i].denom;
|
|
451
|
-
const interest =
|
|
452
|
-
const principal =
|
|
451
|
+
const interest = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
|
|
452
|
+
const principal = number_1.bnOrZero(allDebts[i].totalPrincipal);
|
|
453
453
|
const debtAmt = interest.plus(principal);
|
|
454
454
|
const debtUsdVal = yield this.getTokenUsdVal(denom, debtAmt);
|
|
455
455
|
if (!debtUsdVal) {
|
|
@@ -461,7 +461,7 @@ class CDPModule extends base_1.default {
|
|
|
461
461
|
const stablecoinDebtRes = yield this.sdkProvider.query.cdp.StablecoinDebt({});
|
|
462
462
|
if (stablecoinDebtRes.stablecoinDebtInfo) {
|
|
463
463
|
const debtInfo = stablecoinDebtRes.stablecoinDebtInfo;
|
|
464
|
-
const debtAmt =
|
|
464
|
+
const debtAmt = number_1.bnOrZero(debtInfo.totalPrincipal).plus(number_1.bnOrZero(debtInfo.totalAccumulatedInterest));
|
|
465
465
|
const stablecoinDecimals = (_a = yield sdk.getTokenClient().getDecimals(debtInfo.denom)) !== null && _a !== void 0 ? _a : 0;
|
|
466
466
|
const debtUsdVal = (debtAmt).shiftedBy(-stablecoinDecimals);
|
|
467
467
|
totalDebt = totalDebt.plus(debtUsdVal);
|
|
@@ -479,7 +479,7 @@ class CDPModule extends base_1.default {
|
|
|
479
479
|
if (!TokenClient_1.default.isCdpToken(balance.denom)) {
|
|
480
480
|
continue;
|
|
481
481
|
}
|
|
482
|
-
const amount =
|
|
482
|
+
const amount = number_1.bnOrZero(balance.amount);
|
|
483
483
|
const collateralUsdValue = yield this.getCdpTokenUsdVal(balance.denom, amount);
|
|
484
484
|
allCollateralsUsdValue = allCollateralsUsdValue.plus(collateralUsdValue);
|
|
485
485
|
}
|
|
@@ -503,7 +503,7 @@ class CDPModule extends base_1.default {
|
|
|
503
503
|
const priceResult = yield sdk.query.pricing.TokenPrice(codec_1.QueryTokenPriceRequest.fromPartial({ denom }));
|
|
504
504
|
if (!priceResult.tokenPrice)
|
|
505
505
|
throw new Error("unable to retrieve token price for " + denom);
|
|
506
|
-
const twap =
|
|
506
|
+
const twap = number_1.bnOrZero(priceResult.tokenPrice.twap).shiftedBy(-18);
|
|
507
507
|
return amount.multipliedBy(twap).shiftedBy(-decimals);
|
|
508
508
|
});
|
|
509
509
|
}
|
|
@@ -516,12 +516,15 @@ class CDPModule extends base_1.default {
|
|
|
516
516
|
}
|
|
517
517
|
if (!debtInfo)
|
|
518
518
|
throw new Error("unable to retrieve debt info");
|
|
519
|
-
const
|
|
520
|
-
const
|
|
519
|
+
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
520
|
+
const newInterestRate = cimRsp.interest;
|
|
521
|
+
const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
|
|
522
|
+
const accumInterest = number_1.bnOrZero(debtInfo.totalAccumulatedInterest);
|
|
523
|
+
const newInterest = principal.times(newInterestRate).plus(accumInterest.times(number_1.BN_ONE.plus(newInterestRate)));
|
|
521
524
|
const cdpParamsRsp = yield this.sdkProvider.query.cdp.Params(query_1.QueryParamsRequest.fromPartial({}));
|
|
522
|
-
const interestFee =
|
|
523
|
-
const
|
|
524
|
-
return principal.plus(
|
|
525
|
+
const interestFee = number_1.bnOrZero((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
|
|
526
|
+
const interest = newInterest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
|
|
527
|
+
return principal.plus(interest);
|
|
525
528
|
});
|
|
526
529
|
}
|
|
527
530
|
getTotalAccountTokenDebt(account, denom, debt, debtInfo) {
|
|
@@ -537,11 +540,12 @@ class CDPModule extends base_1.default {
|
|
|
537
540
|
const debtRes = yield sdk.query.cdp.AccountDebt({ address: account, denom: denom });
|
|
538
541
|
debt = debtRes.debt;
|
|
539
542
|
}
|
|
540
|
-
const principalAmount =
|
|
541
|
-
const initialCIM =
|
|
543
|
+
const principalAmount = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
|
|
544
|
+
const initialCIM = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
|
|
542
545
|
if (principalAmount.isZero() || initialCIM.isZero())
|
|
543
546
|
return number_1.BN_ZERO;
|
|
544
|
-
const
|
|
547
|
+
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
548
|
+
const cim = cimRsp.cim;
|
|
545
549
|
if (!cim)
|
|
546
550
|
throw new Error("unable to retrieve account debt");
|
|
547
551
|
// TODO: change to round up
|
|
@@ -563,8 +567,8 @@ class CDPModule extends base_1.default {
|
|
|
563
567
|
const debtResp = yield sdk.query.cdp.AccountStablecoin(query_1.QueryAccountStablecoinRequest.fromPartial({ address: account }));
|
|
564
568
|
debt = debtResp;
|
|
565
569
|
}
|
|
566
|
-
principalAmount =
|
|
567
|
-
const initialCIM =
|
|
570
|
+
principalAmount = number_1.bnOrZero(debt.principalDebt);
|
|
571
|
+
const initialCIM = number_1.bnOrZero(debt.initialCumulativeInterestMultiplier);
|
|
568
572
|
const cim = yield this.recalculateStablecoinCIM(debtInfo);
|
|
569
573
|
if (!cim)
|
|
570
574
|
throw new Error("unable to retrieve account debt");
|
|
@@ -605,7 +609,7 @@ class CDPModule extends base_1.default {
|
|
|
605
609
|
return number_1.BN_ZERO;
|
|
606
610
|
}
|
|
607
611
|
const diffSeconds = new bignumber_js_1.BigNumber(diffMs).shiftedBy(-3).dp(0, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
608
|
-
const secondsAYear =
|
|
612
|
+
const secondsAYear = number_1.bnOrZero(31536000);
|
|
609
613
|
const numPeriods = secondsAYear.div(diffSeconds).dp(18);
|
|
610
614
|
return apy.div(numPeriods).dp(18); // carbon backend sdk.dec max 18 dp
|
|
611
615
|
}
|
|
@@ -629,8 +633,8 @@ class CDPModule extends base_1.default {
|
|
|
629
633
|
throw new Error("unable to retrieve cdp params for " + denom);
|
|
630
634
|
}
|
|
631
635
|
}
|
|
632
|
-
const interestFeeRate =
|
|
633
|
-
const utilizationRate =
|
|
636
|
+
const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
|
|
637
|
+
const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
|
|
634
638
|
return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
|
|
635
639
|
});
|
|
636
640
|
}
|
|
@@ -642,14 +646,14 @@ class CDPModule extends base_1.default {
|
|
|
642
646
|
const debtInfoResponse = yield sdk.query.cdp.TokenDebt(query_1.QueryTokenDebtRequest.fromPartial({ denom }));
|
|
643
647
|
debtInfo = debtInfoResponse.debtInfo;
|
|
644
648
|
if (!debtInfo) {
|
|
645
|
-
return number_1.BN_ZERO;
|
|
649
|
+
return { cim: number_1.BN_ZERO, interest: number_1.BN_ZERO };
|
|
646
650
|
}
|
|
647
651
|
}
|
|
648
|
-
const cim =
|
|
652
|
+
const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
|
|
649
653
|
const apy = yield this.calculateAPY(denom, debtInfo);
|
|
650
|
-
const
|
|
651
|
-
const newCIM = cim.times(
|
|
652
|
-
return newCIM;
|
|
654
|
+
const newInterest = CDPModule.calculateInterestForTimePeriod(apy, (_a = debtInfo.lastUpdatedTime) !== null && _a !== void 0 ? _a : new Date(0), new Date());
|
|
655
|
+
const newCIM = cim.times(newInterest.plus(1));
|
|
656
|
+
return { cim: newCIM, interest: newInterest };
|
|
653
657
|
});
|
|
654
658
|
}
|
|
655
659
|
recalculateStablecoinCIM(debtInfo) {
|
|
@@ -664,8 +668,8 @@ class CDPModule extends base_1.default {
|
|
|
664
668
|
}
|
|
665
669
|
}
|
|
666
670
|
const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
|
|
667
|
-
const cim =
|
|
668
|
-
const apy =
|
|
671
|
+
const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
|
|
672
|
+
const apy = number_1.bnOrZero((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
|
|
669
673
|
if (!apy) {
|
|
670
674
|
return number_1.BN_ZERO;
|
|
671
675
|
}
|
|
@@ -691,7 +695,7 @@ class CDPModule extends base_1.default {
|
|
|
691
695
|
const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
|
|
692
696
|
const unlockableUsd = availableBorrowsUsd.multipliedBy(number_1.BN_10000).div(unlockRatio);
|
|
693
697
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom });
|
|
694
|
-
const tokenTwap =
|
|
698
|
+
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
|
|
695
699
|
if (tokenTwap.isZero())
|
|
696
700
|
throw new Error("unable to retrieve token price for " + denom);
|
|
697
701
|
const tokenAmt = unlockableUsd.div(tokenTwap.shiftedBy(-18)).shiftedBy(tokenDecimals);
|
|
@@ -702,7 +706,7 @@ class CDPModule extends base_1.default {
|
|
|
702
706
|
address: account,
|
|
703
707
|
cdpDenom: cdpDenom
|
|
704
708
|
});
|
|
705
|
-
const lockedAmount =
|
|
709
|
+
const lockedAmount = number_1.bnOrZero((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
|
|
706
710
|
return lockedAmount.lt(cdpTokenAmt) ? lockedAmount : cdpTokenAmt;
|
|
707
711
|
});
|
|
708
712
|
}
|
|
@@ -720,7 +724,7 @@ class CDPModule extends base_1.default {
|
|
|
720
724
|
const denom = this.getUnderlyingDenom(cdpDenom);
|
|
721
725
|
const cdpToActualRatio = (_a = yield this.getCdpToActualRatio(cdpDenom)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
|
|
722
726
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
|
|
723
|
-
const tokenTwap =
|
|
727
|
+
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
|
|
724
728
|
return tokenTwap.multipliedBy(cdpToActualRatio);
|
|
725
729
|
});
|
|
726
730
|
}
|
|
@@ -741,26 +745,26 @@ class CDPModule extends base_1.default {
|
|
|
741
745
|
});
|
|
742
746
|
if (!asset.assetParams)
|
|
743
747
|
throw new Error("unable to retrieve asset param for " + cdpActualDenom);
|
|
744
|
-
const bonus =
|
|
748
|
+
const bonus = number_1.bnOrZero(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
|
|
745
749
|
const cdpTokenPrice = yield this.getCdpTokenPrice(cdpDenom);
|
|
746
750
|
const cdpTokenDiscountedPrice = cdpTokenPrice.multipliedBy(number_1.BN_ONE.minus(bonus));
|
|
747
751
|
// get close factor
|
|
748
752
|
const debtorAccountData = yield sdk.query.cdp.AccountData({
|
|
749
753
|
address: debtor
|
|
750
754
|
});
|
|
751
|
-
const debtorTotalCollateralVal =
|
|
752
|
-
const debtorTotalDebtVal =
|
|
753
|
-
const currentLiqThreshold =
|
|
755
|
+
const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
|
|
756
|
+
const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
|
|
757
|
+
const currentLiqThreshold = number_1.bnOrZero(debtorAccountData.currLiquidationThreshold);
|
|
754
758
|
const params = yield sdk.query.cdp.Params({});
|
|
755
759
|
if (!params.params) {
|
|
756
760
|
throw new Error("unable to retrieve cdp params");
|
|
757
761
|
}
|
|
758
|
-
const smallLiqSize =
|
|
759
|
-
const minCloseFactor =
|
|
760
|
-
const completeLiqThreshold =
|
|
762
|
+
const smallLiqSize = number_1.bnOrZero(params.params.smallLiquidationSize);
|
|
763
|
+
const minCloseFactor = number_1.bnOrZero(params.params.minimumCloseFactor);
|
|
764
|
+
const completeLiqThreshold = number_1.bnOrZero(params.params.completeLiquidationThreshold);
|
|
761
765
|
const closeFactor = this.computeCloseFactor(debtorTotalDebtVal, debtorTotalCollateralVal, currentLiqThreshold, smallLiqSize, minCloseFactor, completeLiqThreshold);
|
|
762
766
|
// get max repayable amount given the debtor's debt and how much liquidator wants to repay
|
|
763
|
-
const debtDecimals =
|
|
767
|
+
const debtDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(debtDenom));
|
|
764
768
|
const maxRepayableValue = debtorTotalDebtVal.multipliedBy(closeFactor);
|
|
765
769
|
const maxRepayableAmt = maxRepayableValue.shiftedBy(debtDecimals.toNumber());
|
|
766
770
|
if (debtRepaymentAmount.isGreaterThan(maxRepayableAmt)) {
|
|
@@ -768,7 +772,7 @@ class CDPModule extends base_1.default {
|
|
|
768
772
|
}
|
|
769
773
|
// calculate collateral amount that can be obtained given that debt amount and debtor's collateral balance
|
|
770
774
|
// AND, recalculate debt repay amount if needed
|
|
771
|
-
const cdpTokenDecimals =
|
|
775
|
+
const cdpTokenDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
|
|
772
776
|
let collateralAmtToLiquidate = this.calculateCollateralRequiredForDebt(number_1.BN_ONE, // assumes USC is $1
|
|
773
777
|
cdpTokenDiscountedPrice, debtRepaymentAmount, cdpTokenDecimals, debtDecimals);
|
|
774
778
|
const debtorAccountCollateral = yield sdk.query.cdp.AccountCollateral({
|
|
@@ -841,11 +845,11 @@ class CDPModule extends base_1.default {
|
|
|
841
845
|
}
|
|
842
846
|
exports.CDPModule = CDPModule;
|
|
843
847
|
CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
|
|
844
|
-
const utilizationRate =
|
|
845
|
-
const optimalUsage =
|
|
846
|
-
const variableRate1 =
|
|
847
|
-
const variableRate2 =
|
|
848
|
-
const baseVariableBorrowRate =
|
|
848
|
+
const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
|
|
849
|
+
const optimalUsage = number_1.bnOrZero(rateStrategy.optimalUsage).shiftedBy(-4);
|
|
850
|
+
const variableRate1 = number_1.bnOrZero(rateStrategy.variableRateSlope1).shiftedBy(-4);
|
|
851
|
+
const variableRate2 = number_1.bnOrZero(rateStrategy.variableRateSlope2).shiftedBy(-4);
|
|
852
|
+
const baseVariableBorrowRate = number_1.bnOrZero(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
|
|
849
853
|
if (utilizationRate.lte(optimalUsage)) {
|
|
850
854
|
const vRate = utilizationRate.times(variableRate1).div(optimalUsage).dp(4, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
851
855
|
return vRate.plus(baseVariableBorrowRate);
|
package/lib/modules/gov.js
CHANGED
|
@@ -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:
|
|
51
|
+
amount: 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:
|
|
81
|
+
msg: 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:
|
|
88
|
+
msg: 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:
|
|
95
|
+
msg: admin_1.transfromSetMinGasPriceParams(msg)
|
|
96
96
|
};
|
|
97
97
|
return proposal_2.SetMinGasPriceProposal.encode(setMinGasPriceMsg).finish();
|
|
98
98
|
case "RemoveMsgGasCostProposal":
|
|
@@ -113,63 +113,63 @@ class GovModule extends base_1.default {
|
|
|
113
113
|
const linkPoolMsg = {
|
|
114
114
|
title: title,
|
|
115
115
|
description: description,
|
|
116
|
-
msg:
|
|
116
|
+
msg: admin_1.transfromLinkPoolParams(msg)
|
|
117
117
|
};
|
|
118
118
|
return proposal_3.LinkPoolProposal.encode(linkPoolMsg).finish();
|
|
119
119
|
case "UnlinkPoolProposal":
|
|
120
120
|
const unlinkPoolMsg = {
|
|
121
121
|
title: title,
|
|
122
122
|
description: description,
|
|
123
|
-
msg:
|
|
123
|
+
msg: admin_1.transfromUnlinkPoolParams(msg)
|
|
124
124
|
};
|
|
125
125
|
return proposal_3.UnlinkPoolProposal.encode(unlinkPoolMsg).finish();
|
|
126
126
|
case "SetRewardCurveProposal":
|
|
127
127
|
const setRewardCurveMsg = {
|
|
128
128
|
title: title,
|
|
129
129
|
description: description,
|
|
130
|
-
msg:
|
|
130
|
+
msg: admin_1.transfromSetRewardCurveParams(msg)
|
|
131
131
|
};
|
|
132
132
|
return proposal_3.SetRewardCurveProposal.encode(setRewardCurveMsg).finish();
|
|
133
133
|
case "SetCommitmentCurveProposal":
|
|
134
134
|
const setCommitmentCurveMsg = {
|
|
135
135
|
title: title,
|
|
136
136
|
description: description,
|
|
137
|
-
msg:
|
|
137
|
+
msg: admin_1.transfromSetCommitmentCurveParams(msg)
|
|
138
138
|
};
|
|
139
139
|
return proposal_3.SetCommitmentCurveProposal.encode(setCommitmentCurveMsg).finish();
|
|
140
140
|
case "SetRewardsWeightsProposal":
|
|
141
141
|
const setRewardsWeightsMsg = {
|
|
142
142
|
title: title,
|
|
143
143
|
description: description,
|
|
144
|
-
msg:
|
|
144
|
+
msg: admin_1.transfromSetRewardsWeightsParams(msg)
|
|
145
145
|
};
|
|
146
146
|
return proposal_3.SetRewardsWeightsProposal.encode(setRewardsWeightsMsg).finish();
|
|
147
147
|
case "UpdatePoolProposal":
|
|
148
148
|
const updatePoolProposalMsg = {
|
|
149
149
|
title: title,
|
|
150
150
|
description: description,
|
|
151
|
-
msg:
|
|
151
|
+
msg: admin_1.transfromUpdatePoolParams(msg)
|
|
152
152
|
};
|
|
153
153
|
return proposal_3.UpdatePoolProposal.encode(updatePoolProposalMsg).finish();
|
|
154
154
|
case "UpdateMarketProposal":
|
|
155
155
|
const updateMarketProposalMsg = {
|
|
156
156
|
title: title,
|
|
157
157
|
description: description,
|
|
158
|
-
msg:
|
|
158
|
+
msg: market_1.transfromUpdateMarketParams(msg)
|
|
159
159
|
};
|
|
160
160
|
return proposal_4.UpdateMarketProposal.encode(updateMarketProposalMsg).finish();
|
|
161
161
|
case "CreateOracleProposal":
|
|
162
162
|
const createOracleProposalMsg = {
|
|
163
163
|
title: title,
|
|
164
164
|
description: description,
|
|
165
|
-
msg:
|
|
165
|
+
msg: admin_1.transfromCreateOracleParams(msg, wallet.bech32Address)
|
|
166
166
|
};
|
|
167
167
|
return proposal_5.CreateOracleProposal.encode(createOracleProposalMsg).finish();
|
|
168
168
|
case "SettlementPriceProposal":
|
|
169
169
|
const settlementPriceProposalMsg = {
|
|
170
170
|
title: title,
|
|
171
171
|
description: description,
|
|
172
|
-
msg:
|
|
172
|
+
msg: admin_1.transformSetSettlementPriceParams(msg),
|
|
173
173
|
};
|
|
174
174
|
return proposal_6.SettlementPriceProposal.encode(settlementPriceProposalMsg).finish();
|
|
175
175
|
case "ParameterChangeProposal":
|
|
@@ -191,7 +191,7 @@ class GovModule extends base_1.default {
|
|
|
191
191
|
title: title,
|
|
192
192
|
description: description,
|
|
193
193
|
recipient: proposalMsg.recipient,
|
|
194
|
-
amount:
|
|
194
|
+
amount: admin_1.transformCommunityPoolSpendAmount(proposalMsg.amount),
|
|
195
195
|
};
|
|
196
196
|
return distribution_1.CommunityPoolSpendProposal.encode(communityPoolSpendProposalMsg).finish();
|
|
197
197
|
case "CancelSoftwareUpgradeProposal":
|
|
@@ -147,7 +147,7 @@ class LiquidityPoolModule extends base_1.default {
|
|
|
147
147
|
const SECONDS_IN_A_WEEK = new bignumber_js_1.BigNumber(604800);
|
|
148
148
|
const mintDataResponse = yield this.sdkProvider.query.inflation.MintData({});
|
|
149
149
|
const mintData = mintDataResponse.mintData;
|
|
150
|
-
const nowTime = new bignumber_js_1.BigNumber(
|
|
150
|
+
const nowTime = new bignumber_js_1.BigNumber(dayjs_1.default().unix());
|
|
151
151
|
const firstBlockTime = (_a = mintData === null || mintData === void 0 ? void 0 : mintData.firstBlockTime.toNumber()) !== null && _a !== void 0 ? _a : 0;
|
|
152
152
|
const difference = nowTime.minus(firstBlockTime);
|
|
153
153
|
const currentWeek = difference.div(SECONDS_IN_A_WEEK).dp(0, bignumber_js_1.BigNumber.ROUND_DOWN);
|
|
@@ -85,7 +85,7 @@ class EthLedgerAccount {
|
|
|
85
85
|
static tryConnect() {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
try {
|
|
88
|
-
const transport = yield
|
|
88
|
+
const transport = yield ledger_1.getLedgerTransport();
|
|
89
89
|
// get public key to assert that NEO app is open
|
|
90
90
|
const ethApp = new hw_app_eth_1.default(transport);
|
|
91
91
|
const bipString = EthLedgerAccount.getETHBIP44String();
|
|
@@ -39,7 +39,7 @@ exports.looksLikeTransportStatusError = looksLikeTransportStatusError;
|
|
|
39
39
|
* @returns error with modified message if found.
|
|
40
40
|
*/
|
|
41
41
|
function evalTransportError(err) {
|
|
42
|
-
const transportErr =
|
|
42
|
+
const transportErr = lodash_1.cloneDeep(err);
|
|
43
43
|
switch (transportErr.statusCode) {
|
|
44
44
|
case StatusWord.APP_CLOSED:
|
|
45
45
|
transportErr.message = "Your NEO app is closed! Please login.";
|