carbon-js-sdk 0.3.4 → 0.3.6
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/CarbonTendermintClient.d.ts +117 -0
- package/lib/clients/CarbonTendermintClient.js +376 -0
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/N3Client.js +3 -2
- package/lib/clients/NEOClient.js +8 -7
- package/lib/clients/ZILClient.js +16 -16
- 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/constant/address.d.ts +1 -0
- package/lib/constant/address.js +2 -1
- package/lib/constant/generic.js +1 -1
- package/lib/modules/cdp.js +43 -43
- 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/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonTendermintClient.js +376 -0
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
- package/lib/codec/bank/tx.d.ts +0 -64
- package/lib/codec/bank/tx.js +0 -236
package/lib/clients/NEOClient.js
CHANGED
|
@@ -33,6 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
34
|
exports.NEOClient = void 0;
|
|
35
35
|
const CarbonSDK_1 = __importDefault(require("../CarbonSDK"));
|
|
36
|
+
const constant_1 = require("../constant");
|
|
36
37
|
const util_1 = require("../util");
|
|
37
38
|
const address_1 = require("../util/address");
|
|
38
39
|
const blockchain_1 = require("../util/blockchain");
|
|
@@ -63,13 +64,13 @@ class NEOClient {
|
|
|
63
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
65
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
65
66
|
const account = new Neon.wallet.Account(address);
|
|
66
|
-
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
67
|
+
const tokens = tokenQueryResults.filter(token => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
|
|
67
68
|
token.tokenAddress.length == 40 &&
|
|
68
69
|
token.bridgeAddress.length == 40);
|
|
69
70
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
70
71
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
71
72
|
// the gas limit on the RPC node and error out otherwise
|
|
72
|
-
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const promises = (0, lodash_1.chunk)(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
73
74
|
var _a, _b, _c;
|
|
74
75
|
let acc = {};
|
|
75
76
|
for (const token of partition) {
|
|
@@ -110,10 +111,10 @@ class NEOClient {
|
|
|
110
111
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
111
112
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
112
113
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
113
|
-
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
114
|
+
const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
114
115
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
115
116
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
116
|
-
const feeAddress = networkConfig.feeAddress;
|
|
117
|
+
const feeAddress = feeAmount.isZero() ? constant_1.ZeroAddress : networkConfig.feeAddress;
|
|
117
118
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
118
119
|
if (amount.lt(feeAmount)) {
|
|
119
120
|
return false;
|
|
@@ -157,7 +158,7 @@ class NEOClient {
|
|
|
157
158
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
158
159
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
159
160
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
160
|
-
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
161
|
+
const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
|
|
161
162
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
162
163
|
if (amount.lt(feeAmount)) {
|
|
163
164
|
throw new Error("Invalid amount");
|
|
@@ -193,7 +194,7 @@ class NEOClient {
|
|
|
193
194
|
const fromAddress = ledger.scriptHash;
|
|
194
195
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
195
196
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
196
|
-
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
197
|
+
const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
|
|
197
198
|
const feeAddress = networkConfig.feeAddress;
|
|
198
199
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
199
200
|
if (amount.lt(feeAmount)) {
|
|
@@ -313,7 +314,7 @@ class NEOClient {
|
|
|
313
314
|
getTargetProxyHash(token) {
|
|
314
315
|
const networkConfig = this.getNetworkConfig();
|
|
315
316
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
316
|
-
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
317
|
+
const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
317
318
|
return addressHex;
|
|
318
319
|
}
|
|
319
320
|
getNetworkConfig() {
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -74,10 +74,10 @@ class ZILClient {
|
|
|
74
74
|
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
77
|
-
const tokens = tokenQueryResults.filter(token => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
77
|
+
const tokens = tokenQueryResults.filter(token => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber()) == this.blockchain &&
|
|
78
78
|
token.tokenAddress.length == 40 &&
|
|
79
79
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)));
|
|
80
|
-
const requests = tokens.map(token => token.tokenAddress === zeroAddress ? exports.balanceBatchRequest(address.replace(/^0x/i, "")) : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
80
|
+
const requests = tokens.map(token => token.tokenAddress === zeroAddress ? (0, exports.balanceBatchRequest)(address.replace(/^0x/i, "")) : (0, exports.tokenBalanceBatchRequest)(token.tokenAddress, address));
|
|
81
81
|
const response = yield fetch(this.getProviderUrl(), {
|
|
82
82
|
method: "post",
|
|
83
83
|
headers: { "content-type": "application/json" },
|
|
@@ -102,7 +102,7 @@ class ZILClient {
|
|
|
102
102
|
// if (!isValidAddress) {
|
|
103
103
|
// throw new Error("invalid address")
|
|
104
104
|
// }
|
|
105
|
-
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
105
|
+
return (0, zilliqa_1.fromBech32Address)(bech32Address).toLowerCase().substr(2);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -148,7 +148,7 @@ class ZILClient {
|
|
|
148
148
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
149
149
|
}
|
|
150
150
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
151
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
151
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
|
|
152
152
|
if (balanceAndNonceResp.error !== undefined) {
|
|
153
153
|
throw new Error(balanceAndNonceResp.error.message);
|
|
154
154
|
}
|
|
@@ -166,7 +166,7 @@ class ZILClient {
|
|
|
166
166
|
vname: 'spender',
|
|
167
167
|
type: 'ByStr20',
|
|
168
168
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
169
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
169
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : (0, generic_1.appendHexPrefix)(token.bridgeAddress),
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
vname: 'amount',
|
|
@@ -184,7 +184,7 @@ class ZILClient {
|
|
|
184
184
|
}
|
|
185
185
|
checkAllowanceZRC2(token, owner, spender) {
|
|
186
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
187
|
+
const contractAddress = (0, generic_1.appendHexPrefix)(token.tokenAddress);
|
|
188
188
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
189
189
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
190
190
|
if (resp.error !== undefined) {
|
|
@@ -204,13 +204,13 @@ class ZILClient {
|
|
|
204
204
|
throw new Error("Invalid recovery address");
|
|
205
205
|
}
|
|
206
206
|
const fromTokenId = fromToken.id;
|
|
207
|
-
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
207
|
+
const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
|
|
208
208
|
const toTokenDenom = toToken.denom;
|
|
209
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
209
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
|
|
210
210
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
211
211
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
212
212
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
213
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
213
|
+
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
214
214
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
215
215
|
let zilliqa;
|
|
216
216
|
if (typeof signer === 'string') {
|
|
@@ -225,7 +225,7 @@ class ZILClient {
|
|
|
225
225
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
226
226
|
}
|
|
227
227
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
228
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
228
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(fromAddress));
|
|
229
229
|
if (balanceAndNonceResp.error !== undefined) {
|
|
230
230
|
throw new Error(balanceAndNonceResp.error.message);
|
|
231
231
|
}
|
|
@@ -302,13 +302,13 @@ class ZILClient {
|
|
|
302
302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
303
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
304
304
|
const networkConfig = this.getNetworkConfig();
|
|
305
|
-
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
306
|
-
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
307
|
-
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
305
|
+
const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
|
|
306
|
+
const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
|
|
307
|
+
const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
|
|
308
308
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
309
309
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
310
310
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
311
|
-
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
311
|
+
const contractAddress = (0, generic_1.appendHexPrefix)(token.bridgeAddress);
|
|
312
312
|
let zilliqa;
|
|
313
313
|
if (typeof signer === 'string') {
|
|
314
314
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -322,7 +322,7 @@ class ZILClient {
|
|
|
322
322
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
323
323
|
}
|
|
324
324
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
325
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
325
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
|
|
326
326
|
if (balanceAndNonceResp.error !== undefined) {
|
|
327
327
|
throw new Error(balanceAndNonceResp.error.message);
|
|
328
328
|
}
|
|
@@ -407,7 +407,7 @@ class ZILClient {
|
|
|
407
407
|
getTargetProxyHash(token) {
|
|
408
408
|
const networkConfig = this.getNetworkConfig();
|
|
409
409
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
410
|
-
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
410
|
+
const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
411
411
|
return addressHex;
|
|
412
412
|
}
|
|
413
413
|
getNetworkConfig() {
|
|
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
|
|
|
159
159
|
const message = Object.assign({}, baseQueryProposalsRequest);
|
|
160
160
|
message.proposalStatus =
|
|
161
161
|
object.proposalStatus !== undefined && object.proposalStatus !== null
|
|
162
|
-
? gov_1.proposalStatusFromJSON(object.proposalStatus)
|
|
162
|
+
? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
|
|
163
163
|
: 0;
|
|
164
164
|
message.voter =
|
|
165
165
|
object.voter !== undefined && object.voter !== null
|
|
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
|
|
|
178
178
|
toJSON(message) {
|
|
179
179
|
const obj = {};
|
|
180
180
|
message.proposalStatus !== undefined &&
|
|
181
|
-
(obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
|
|
181
|
+
(obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
|
|
182
182
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
183
183
|
message.depositor !== undefined && (obj.depositor = message.depositor);
|
|
184
184
|
message.pagination !== undefined &&
|
|
@@ -185,7 +185,7 @@ exports.MsgVote = {
|
|
|
185
185
|
: "";
|
|
186
186
|
message.option =
|
|
187
187
|
object.option !== undefined && object.option !== null
|
|
188
|
-
? gov_1.voteOptionFromJSON(object.option)
|
|
188
|
+
? (0, gov_1.voteOptionFromJSON)(object.option)
|
|
189
189
|
: 0;
|
|
190
190
|
return message;
|
|
191
191
|
},
|
|
@@ -195,7 +195,7 @@ exports.MsgVote = {
|
|
|
195
195
|
(obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
|
|
196
196
|
message.voter !== undefined && (obj.voter = message.voter);
|
|
197
197
|
message.option !== undefined &&
|
|
198
|
-
(obj.option = gov_1.voteOptionToJSON(message.option));
|
|
198
|
+
(obj.option = (0, gov_1.voteOptionToJSON)(message.option));
|
|
199
199
|
return obj;
|
|
200
200
|
},
|
|
201
201
|
fromPartial(object) {
|
|
@@ -618,13 +618,13 @@ exports.ModeInfo_Single = {
|
|
|
618
618
|
const message = Object.assign({}, baseModeInfo_Single);
|
|
619
619
|
message.mode =
|
|
620
620
|
object.mode !== undefined && object.mode !== null
|
|
621
|
-
? signing_1.signModeFromJSON(object.mode)
|
|
621
|
+
? (0, signing_1.signModeFromJSON)(object.mode)
|
|
622
622
|
: 0;
|
|
623
623
|
return message;
|
|
624
624
|
},
|
|
625
625
|
toJSON(message) {
|
|
626
626
|
const obj = {};
|
|
627
|
-
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
627
|
+
message.mode !== undefined && (obj.mode = (0, signing_1.signModeToJSON)(message.mode));
|
|
628
628
|
return obj;
|
|
629
629
|
},
|
|
630
630
|
fromPartial(object) {
|
package/lib/constant/address.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NativeTokenHash = void 0;
|
|
3
|
+
exports.NativeTokenHash = exports.ZeroAddress = void 0;
|
|
4
|
+
exports.ZeroAddress = "0x0000000000000000000000000000000000000000";
|
|
4
5
|
exports.NativeTokenHash = "0000000000000000000000000000000000000000";
|
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: proto_signing_1.coins(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
|
|
15
|
+
amount: (0, proto_signing_1.coins)(exports.DEFAULT_GAS_PRICE.times(exports.DEFAULT_GAS).dp(0).toString(), "swth"),
|
|
16
16
|
gas: exports.DEFAULT_GAS.toString(10),
|
|
17
17
|
};
|
|
18
18
|
exports.CURRENT_GAS_PRICE = 769.23077;
|
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 = number_1.bnOrZero(collaterals[i].collateralAmount);
|
|
339
|
+
const amount = (0, 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 = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
|
|
356
|
+
const ltv = (0, number_1.bnOrZero)(assetParam.loanToValue).div(number_1.BN_10000);
|
|
357
357
|
const availableBorrowUsd = collateralUsdVal.times(ltv);
|
|
358
|
-
const liquidationThreshold = number_1.bnOrZero(assetParam.liquidationThreshold).div(number_1.BN_10000);
|
|
358
|
+
const liquidationThreshold = (0, 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 = number_1.bnOrZero(debts[i].principalDebt);
|
|
369
|
+
const amount = (0, 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 = number_1.bnOrZero(accountStablecoin.principalDebt).plus(number_1.bnOrZero(accountStablecoin.interestDebt));
|
|
391
|
+
const stablecoinDebtAmount = (0, number_1.bnOrZero)(accountStablecoin.principalDebt).plus((0, 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 number_1.bnOrZero((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
|
|
412
|
+
return (0, 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 = number_1.bnOrZero(cdpAmountRsp.amount);
|
|
423
|
+
const cdpAmount = (0, 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 = number_1.bnOrZero(balanceRsp.balance.amount).plus(owedAmount);
|
|
429
|
+
const actualAmount = (0, 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 = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
|
|
452
|
-
const principal = number_1.bnOrZero(allDebts[i].totalPrincipal);
|
|
451
|
+
const interest = (0, number_1.bnOrZero)(allDebts[i].totalAccumulatedInterest);
|
|
452
|
+
const principal = (0, 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 = number_1.bnOrZero(debtInfo.totalPrincipal).plus(number_1.bnOrZero(debtInfo.totalAccumulatedInterest));
|
|
464
|
+
const debtAmt = (0, number_1.bnOrZero)(debtInfo.totalPrincipal).plus((0, 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 = number_1.bnOrZero(balance.amount);
|
|
482
|
+
const amount = (0, 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 = number_1.bnOrZero(priceResult.tokenPrice.twap).shiftedBy(-18);
|
|
506
|
+
const twap = (0, number_1.bnOrZero)(priceResult.tokenPrice.twap).shiftedBy(-18);
|
|
507
507
|
return amount.multipliedBy(twap).shiftedBy(-decimals);
|
|
508
508
|
});
|
|
509
509
|
}
|
|
@@ -518,11 +518,11 @@ class CDPModule extends base_1.default {
|
|
|
518
518
|
throw new Error("unable to retrieve debt info");
|
|
519
519
|
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
520
520
|
const newInterestRate = cimRsp.interest;
|
|
521
|
-
const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
|
|
522
|
-
const accumInterest = number_1.bnOrZero(debtInfo.totalAccumulatedInterest);
|
|
521
|
+
const principal = (0, number_1.bnOrZero)(debtInfo.totalPrincipal);
|
|
522
|
+
const accumInterest = (0, number_1.bnOrZero)(debtInfo.totalAccumulatedInterest);
|
|
523
523
|
const newInterest = principal.times(newInterestRate).plus(accumInterest.times(number_1.BN_ONE.plus(newInterestRate)));
|
|
524
524
|
const cdpParamsRsp = yield this.sdkProvider.query.cdp.Params(query_1.QueryParamsRequest.fromPartial({}));
|
|
525
|
-
const interestFee = number_1.bnOrZero((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
|
|
525
|
+
const interestFee = (0, number_1.bnOrZero)((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
|
|
526
526
|
const interest = newInterest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
|
|
527
527
|
return principal.plus(interest);
|
|
528
528
|
});
|
|
@@ -540,8 +540,8 @@ class CDPModule extends base_1.default {
|
|
|
540
540
|
const debtRes = yield sdk.query.cdp.AccountDebt({ address: account, denom: denom });
|
|
541
541
|
debt = debtRes.debt;
|
|
542
542
|
}
|
|
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);
|
|
543
|
+
const principalAmount = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
|
|
544
|
+
const initialCIM = (0, number_1.bnOrZero)(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
|
|
545
545
|
if (principalAmount.isZero() || initialCIM.isZero())
|
|
546
546
|
return number_1.BN_ZERO;
|
|
547
547
|
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
@@ -567,8 +567,8 @@ class CDPModule extends base_1.default {
|
|
|
567
567
|
const debtResp = yield sdk.query.cdp.AccountStablecoin(query_1.QueryAccountStablecoinRequest.fromPartial({ address: account }));
|
|
568
568
|
debt = debtResp;
|
|
569
569
|
}
|
|
570
|
-
principalAmount = number_1.bnOrZero(debt.principalDebt);
|
|
571
|
-
const initialCIM = number_1.bnOrZero(debt.initialCumulativeInterestMultiplier);
|
|
570
|
+
principalAmount = (0, number_1.bnOrZero)(debt.principalDebt);
|
|
571
|
+
const initialCIM = (0, number_1.bnOrZero)(debt.initialCumulativeInterestMultiplier);
|
|
572
572
|
const cim = yield this.recalculateStablecoinCIM(debtInfo);
|
|
573
573
|
if (!cim)
|
|
574
574
|
throw new Error("unable to retrieve account debt");
|
|
@@ -609,7 +609,7 @@ class CDPModule extends base_1.default {
|
|
|
609
609
|
return number_1.BN_ZERO;
|
|
610
610
|
}
|
|
611
611
|
const diffSeconds = new bignumber_js_1.BigNumber(diffMs).shiftedBy(-3).dp(0, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
612
|
-
const secondsAYear = number_1.bnOrZero(31536000);
|
|
612
|
+
const secondsAYear = (0, number_1.bnOrZero)(31536000);
|
|
613
613
|
const numPeriods = secondsAYear.div(diffSeconds).dp(18);
|
|
614
614
|
return apy.div(numPeriods).dp(18); // carbon backend sdk.dec max 18 dp
|
|
615
615
|
}
|
|
@@ -633,8 +633,8 @@ class CDPModule extends base_1.default {
|
|
|
633
633
|
throw new Error("unable to retrieve cdp params for " + denom);
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
|
-
const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
|
|
637
|
-
const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
|
|
636
|
+
const interestFeeRate = (0, number_1.bnOrZero)(params.interestFee).div(number_1.BN_10000);
|
|
637
|
+
const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
|
|
638
638
|
return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
|
|
639
639
|
});
|
|
640
640
|
}
|
|
@@ -649,7 +649,7 @@ class CDPModule extends base_1.default {
|
|
|
649
649
|
return { cim: number_1.BN_ZERO, interest: number_1.BN_ZERO };
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
|
-
const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
|
|
652
|
+
const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
|
|
653
653
|
const apy = yield this.calculateAPY(denom, debtInfo);
|
|
654
654
|
const newInterest = CDPModule.calculateInterestForTimePeriod(apy, (_a = debtInfo.lastUpdatedTime) !== null && _a !== void 0 ? _a : new Date(0), new Date());
|
|
655
655
|
const newCIM = cim.times(newInterest.plus(1));
|
|
@@ -668,8 +668,8 @@ class CDPModule extends base_1.default {
|
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
|
|
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);
|
|
671
|
+
const cim = (0, number_1.bnOrZero)(debtInfo.cumulativeInterestMultiplier);
|
|
672
|
+
const apy = (0, number_1.bnOrZero)((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
|
|
673
673
|
if (!apy) {
|
|
674
674
|
return number_1.BN_ZERO;
|
|
675
675
|
}
|
|
@@ -695,7 +695,7 @@ class CDPModule extends base_1.default {
|
|
|
695
695
|
const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
|
|
696
696
|
const unlockableUsd = availableBorrowsUsd.multipliedBy(number_1.BN_10000).div(unlockRatio);
|
|
697
697
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom });
|
|
698
|
-
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
|
|
698
|
+
const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
|
|
699
699
|
if (tokenTwap.isZero())
|
|
700
700
|
throw new Error("unable to retrieve token price for " + denom);
|
|
701
701
|
const tokenAmt = unlockableUsd.div(tokenTwap.shiftedBy(-18)).shiftedBy(tokenDecimals);
|
|
@@ -706,7 +706,7 @@ class CDPModule extends base_1.default {
|
|
|
706
706
|
address: account,
|
|
707
707
|
cdpDenom: cdpDenom
|
|
708
708
|
});
|
|
709
|
-
const lockedAmount = number_1.bnOrZero((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
|
|
709
|
+
const lockedAmount = (0, number_1.bnOrZero)((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
|
|
710
710
|
return lockedAmount.lt(cdpTokenAmt) ? lockedAmount : cdpTokenAmt;
|
|
711
711
|
});
|
|
712
712
|
}
|
|
@@ -724,7 +724,7 @@ class CDPModule extends base_1.default {
|
|
|
724
724
|
const denom = this.getUnderlyingDenom(cdpDenom);
|
|
725
725
|
const cdpToActualRatio = (_a = yield this.getCdpToActualRatio(cdpDenom)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
|
|
726
726
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
|
|
727
|
-
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
|
|
727
|
+
const tokenTwap = (0, number_1.bnOrZero)((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
|
|
728
728
|
return tokenTwap.multipliedBy(cdpToActualRatio);
|
|
729
729
|
});
|
|
730
730
|
}
|
|
@@ -745,26 +745,26 @@ class CDPModule extends base_1.default {
|
|
|
745
745
|
});
|
|
746
746
|
if (!asset.assetParams)
|
|
747
747
|
throw new Error("unable to retrieve asset param for " + cdpActualDenom);
|
|
748
|
-
const bonus = number_1.bnOrZero(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
|
|
748
|
+
const bonus = (0, number_1.bnOrZero)(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
|
|
749
749
|
const cdpTokenPrice = yield this.getCdpTokenPrice(cdpDenom);
|
|
750
750
|
const cdpTokenDiscountedPrice = cdpTokenPrice.multipliedBy(number_1.BN_ONE.minus(bonus));
|
|
751
751
|
// get close factor
|
|
752
752
|
const debtorAccountData = yield sdk.query.cdp.AccountData({
|
|
753
753
|
address: debtor
|
|
754
754
|
});
|
|
755
|
-
const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
|
|
756
|
-
const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
|
|
757
|
-
const currentLiqThreshold = number_1.bnOrZero(debtorAccountData.currLiquidationThreshold);
|
|
755
|
+
const debtorTotalCollateralVal = (0, number_1.bnOrZero)(debtorAccountData.totalCollateralsUsd);
|
|
756
|
+
const debtorTotalDebtVal = (0, number_1.bnOrZero)(debtorAccountData.totalDebtsUsd);
|
|
757
|
+
const currentLiqThreshold = (0, number_1.bnOrZero)(debtorAccountData.currLiquidationThreshold);
|
|
758
758
|
const params = yield sdk.query.cdp.Params({});
|
|
759
759
|
if (!params.params) {
|
|
760
760
|
throw new Error("unable to retrieve cdp params");
|
|
761
761
|
}
|
|
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);
|
|
762
|
+
const smallLiqSize = (0, number_1.bnOrZero)(params.params.smallLiquidationSize);
|
|
763
|
+
const minCloseFactor = (0, number_1.bnOrZero)(params.params.minimumCloseFactor);
|
|
764
|
+
const completeLiqThreshold = (0, number_1.bnOrZero)(params.params.completeLiquidationThreshold);
|
|
765
765
|
const closeFactor = this.computeCloseFactor(debtorTotalDebtVal, debtorTotalCollateralVal, currentLiqThreshold, smallLiqSize, minCloseFactor, completeLiqThreshold);
|
|
766
766
|
// get max repayable amount given the debtor's debt and how much liquidator wants to repay
|
|
767
|
-
const debtDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(debtDenom));
|
|
767
|
+
const debtDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(debtDenom));
|
|
768
768
|
const maxRepayableValue = debtorTotalDebtVal.multipliedBy(closeFactor);
|
|
769
769
|
const maxRepayableAmt = maxRepayableValue.shiftedBy(debtDecimals.toNumber());
|
|
770
770
|
if (debtRepaymentAmount.isGreaterThan(maxRepayableAmt)) {
|
|
@@ -772,7 +772,7 @@ class CDPModule extends base_1.default {
|
|
|
772
772
|
}
|
|
773
773
|
// calculate collateral amount that can be obtained given that debt amount and debtor's collateral balance
|
|
774
774
|
// AND, recalculate debt repay amount if needed
|
|
775
|
-
const cdpTokenDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
|
|
775
|
+
const cdpTokenDecimals = (0, number_1.bnOrZero)(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
|
|
776
776
|
let collateralAmtToLiquidate = this.calculateCollateralRequiredForDebt(number_1.BN_ONE, // assumes USC is $1
|
|
777
777
|
cdpTokenDiscountedPrice, debtRepaymentAmount, cdpTokenDecimals, debtDecimals);
|
|
778
778
|
const debtorAccountCollateral = yield sdk.query.cdp.AccountCollateral({
|
|
@@ -845,11 +845,11 @@ class CDPModule extends base_1.default {
|
|
|
845
845
|
}
|
|
846
846
|
exports.CDPModule = CDPModule;
|
|
847
847
|
CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
|
|
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);
|
|
848
|
+
const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
|
|
849
|
+
const optimalUsage = (0, number_1.bnOrZero)(rateStrategy.optimalUsage).shiftedBy(-4);
|
|
850
|
+
const variableRate1 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope1).shiftedBy(-4);
|
|
851
|
+
const variableRate2 = (0, number_1.bnOrZero)(rateStrategy.variableRateSlope2).shiftedBy(-4);
|
|
852
|
+
const baseVariableBorrowRate = (0, number_1.bnOrZero)(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
|
|
853
853
|
if (utilizationRate.lte(optimalUsage)) {
|
|
854
854
|
const vRate = utilizationRate.times(variableRate1).div(optimalUsage).dp(4, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
855
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: amino_1.coins(params.amount, params.denom)
|
|
51
|
+
amount: (0, amino_1.coins)(params.amount, params.denom)
|
|
52
52
|
});
|
|
53
53
|
return yield wallet.sendTx({
|
|
54
54
|
typeUrl: util_1.CarbonTx.Types.MsgDeposit,
|
|
@@ -78,21 +78,21 @@ class GovModule extends base_1.default {
|
|
|
78
78
|
const createTokenMsg = {
|
|
79
79
|
title: title,
|
|
80
80
|
description: description,
|
|
81
|
-
msg: admin_1.transfromCreateTokenParams(msg, wallet.bech32Address)
|
|
81
|
+
msg: (0, admin_1.transfromCreateTokenParams)(msg, wallet.bech32Address)
|
|
82
82
|
};
|
|
83
83
|
return proposal_1.CreateTokenProposal.encode(createTokenMsg).finish();
|
|
84
84
|
case "SetMsgGasCostProposal":
|
|
85
85
|
const setMsgGasCostMsg = {
|
|
86
86
|
title: title,
|
|
87
87
|
description: description,
|
|
88
|
-
msg: admin_1.transfromSetMsgGasCostParams(msg)
|
|
88
|
+
msg: (0, admin_1.transfromSetMsgGasCostParams)(msg)
|
|
89
89
|
};
|
|
90
90
|
return proposal_2.SetMsgGasCostProposal.encode(setMsgGasCostMsg).finish();
|
|
91
91
|
case "SetMinGasPriceProposal":
|
|
92
92
|
const setMinGasPriceMsg = {
|
|
93
93
|
title: title,
|
|
94
94
|
description: description,
|
|
95
|
-
msg: admin_1.transfromSetMinGasPriceParams(msg)
|
|
95
|
+
msg: (0, admin_1.transfromSetMinGasPriceParams)(msg)
|
|
96
96
|
};
|
|
97
97
|
return proposal_2.SetMinGasPriceProposal.encode(setMinGasPriceMsg).finish();
|
|
98
98
|
case "RemoveMsgGasCostProposal":
|
|
@@ -113,63 +113,63 @@ class GovModule extends base_1.default {
|
|
|
113
113
|
const linkPoolMsg = {
|
|
114
114
|
title: title,
|
|
115
115
|
description: description,
|
|
116
|
-
msg: admin_1.transfromLinkPoolParams(msg)
|
|
116
|
+
msg: (0, 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: admin_1.transfromUnlinkPoolParams(msg)
|
|
123
|
+
msg: (0, 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: admin_1.transfromSetRewardCurveParams(msg)
|
|
130
|
+
msg: (0, 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: admin_1.transfromSetCommitmentCurveParams(msg)
|
|
137
|
+
msg: (0, 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: admin_1.transfromSetRewardsWeightsParams(msg)
|
|
144
|
+
msg: (0, 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: admin_1.transfromUpdatePoolParams(msg)
|
|
151
|
+
msg: (0, 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: market_1.transfromUpdateMarketParams(msg)
|
|
158
|
+
msg: (0, 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: admin_1.transfromCreateOracleParams(msg, wallet.bech32Address)
|
|
165
|
+
msg: (0, 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: admin_1.transformSetSettlementPriceParams(msg),
|
|
172
|
+
msg: (0, 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: admin_1.transformCommunityPoolSpendAmount(proposalMsg.amount),
|
|
194
|
+
amount: (0, admin_1.transformCommunityPoolSpendAmount)(proposalMsg.amount),
|
|
195
195
|
};
|
|
196
196
|
return distribution_1.CommunityPoolSpendProposal.encode(communityPoolSpendProposalMsg).finish();
|
|
197
197
|
case "CancelSoftwareUpgradeProposal":
|