carbon-js-sdk 0.3.38 → 0.3.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +7 -7
- package/lib/clients/ZILClient.js +17 -17
- 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/generic.js +1 -1
- package/lib/constant/ibc.js +5 -0
- 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/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/CarbonWallet.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ class CarbonQueryClient {
|
|
|
44
44
|
constructor(tmClient) {
|
|
45
45
|
this.tmClient = tmClient;
|
|
46
46
|
this.baseClient = new stargate_1.QueryClient(this.tmClient);
|
|
47
|
-
const rpcClient =
|
|
47
|
+
const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
|
|
48
48
|
this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
|
|
49
49
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
50
50
|
this.book = new query_2.QueryClientImpl(rpcClient);
|
|
@@ -85,7 +85,7 @@ class CarbonQueryClient {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
getProtobufRpcClient() {
|
|
88
|
-
return
|
|
88
|
+
return stargate_1.createProtobufRpcClient(this.baseClient);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
exports.default = CarbonQueryClient;
|
package/lib/clients/ETHClient.js
CHANGED
|
@@ -40,13 +40,13 @@ class ETHClient {
|
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const tokenQueryResults = yield api.token.getAllTokens();
|
|
42
42
|
const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
|
|
43
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
43
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
44
44
|
token.tokenAddress.length == 40 &&
|
|
45
|
-
token.bridgeAddress.toLowerCase() ==
|
|
45
|
+
token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
|
|
46
46
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
|
|
47
|
-
this.verifyChecksum(
|
|
47
|
+
this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
|
|
48
48
|
const assetIds = tokens.map((token) => {
|
|
49
|
-
return this.verifyChecksum(
|
|
49
|
+
return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
|
|
50
50
|
});
|
|
51
51
|
const provider = this.getProvider();
|
|
52
52
|
const contractAddress = this.getBalanceReaderAddress();
|
|
@@ -95,14 +95,14 @@ class ETHClient {
|
|
|
95
95
|
throw new Error("Invalid recovery address");
|
|
96
96
|
}
|
|
97
97
|
const fromTokenId = fromToken.id;
|
|
98
|
-
const fromTokenAddress =
|
|
98
|
+
const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
99
99
|
const toTokenDenom = toToken.denom;
|
|
100
100
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
101
101
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
102
102
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
103
103
|
const nonce = yield rpcProvider.getTransactionCount(fromAddress);
|
|
104
104
|
const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
|
|
105
|
-
const feeAddress =
|
|
105
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
106
106
|
const tokenCreator = fromToken.creator;
|
|
107
107
|
const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, CarbonSDK_1.default.Network.MainNet);
|
|
108
108
|
const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
|
|
@@ -137,9 +137,9 @@ class ETHClient {
|
|
|
137
137
|
throw new Error("Minimum gas required: 150,000");
|
|
138
138
|
}
|
|
139
139
|
const networkConfig = this.getNetworkConfig();
|
|
140
|
-
const assetId =
|
|
141
|
-
const targetProxyHash =
|
|
142
|
-
const feeAddress =
|
|
140
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
141
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
142
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
143
143
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
144
144
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
145
145
|
const contractAddress = this.getLockProxyAddress();
|
|
@@ -190,16 +190,16 @@ class ETHClient {
|
|
|
190
190
|
return "insufficient balance";
|
|
191
191
|
}
|
|
192
192
|
const networkConfig = this.getNetworkConfig();
|
|
193
|
-
const assetId =
|
|
194
|
-
const targetProxyHash =
|
|
195
|
-
const feeAddress =
|
|
193
|
+
const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
|
|
194
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
|
|
195
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
196
196
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
|
|
197
197
|
const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
|
|
198
198
|
const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
|
|
199
199
|
// logger("sendDeposit message", message)
|
|
200
200
|
let signatureResult;
|
|
201
201
|
const { address, signature } = yield getSignatureCallback(message);
|
|
202
|
-
const signatureBytes = ethers_1.ethers.utils.arrayify(
|
|
202
|
+
const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
|
|
203
203
|
const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
|
|
204
204
|
// logger("sign result", address, signature)
|
|
205
205
|
signatureResult = {
|
|
@@ -238,7 +238,7 @@ class ETHClient {
|
|
|
238
238
|
if (!feeInfo.deposit_fee) {
|
|
239
239
|
throw new Error("unsupported token");
|
|
240
240
|
}
|
|
241
|
-
if (
|
|
241
|
+
if (blockchain_1.blockchainForChainId(token.chainId.toNumber()) !== this.blockchain) {
|
|
242
242
|
throw new Error("unsupported token");
|
|
243
243
|
}
|
|
244
244
|
let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
|
|
@@ -304,7 +304,7 @@ class ETHClient {
|
|
|
304
304
|
getTargetProxyHash(token) {
|
|
305
305
|
const networkConfig = this.getNetworkConfig();
|
|
306
306
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
307
|
-
const addressHex =
|
|
307
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
308
308
|
return addressHex;
|
|
309
309
|
}
|
|
310
310
|
getProvider() {
|
|
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
|
|
|
29
29
|
const formatDateField = (value) => {
|
|
30
30
|
if (typeof value !== "string")
|
|
31
31
|
return null;
|
|
32
|
-
return
|
|
32
|
+
return dayjs_1.default(value);
|
|
33
33
|
};
|
|
34
34
|
const formatCrossChainTransfer = (value) => {
|
|
35
35
|
var _a, _b;
|
package/lib/clients/NEOClient.js
CHANGED
|
@@ -64,13 +64,13 @@ class NEOClient {
|
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
65
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
66
66
|
const account = new Neon.wallet.Account(address);
|
|
67
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
67
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
68
68
|
token.tokenAddress.length == 40 &&
|
|
69
69
|
token.bridgeAddress.length == 40);
|
|
70
70
|
const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
|
|
71
71
|
// NOTE: fetching of tokens is chunked in sets of 15 as we may hit
|
|
72
72
|
// the gas limit on the RPC node and error out otherwise
|
|
73
|
-
const promises =
|
|
73
|
+
const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
|
|
74
74
|
var _a, _b, _c;
|
|
75
75
|
let acc = {};
|
|
76
76
|
for (const token of partition) {
|
|
@@ -112,8 +112,8 @@ class NEOClient {
|
|
|
112
112
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
113
113
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
114
114
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
|
|
115
|
-
const toAddress =
|
|
116
|
-
const zeroAddressHex =
|
|
115
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
116
|
+
const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
|
|
117
117
|
const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
|
|
118
118
|
const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
|
|
119
119
|
const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
|
|
@@ -160,7 +160,7 @@ class NEOClient {
|
|
|
160
160
|
const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
|
|
161
161
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
162
162
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
163
|
-
const toAddress =
|
|
163
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
164
164
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
165
165
|
if (amount.lt(feeAmount)) {
|
|
166
166
|
throw new Error("Invalid amount");
|
|
@@ -196,7 +196,7 @@ class NEOClient {
|
|
|
196
196
|
const fromAddress = ledger.scriptHash;
|
|
197
197
|
const targetProxyHash = this.getTargetProxyHash(token);
|
|
198
198
|
const toAssetHash = Neon.u.str2hexstring(token.id);
|
|
199
|
-
const toAddress =
|
|
199
|
+
const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
|
|
200
200
|
const feeAddress = networkConfig.feeAddress;
|
|
201
201
|
const nonce = Math.floor(Math.random() * 1000000);
|
|
202
202
|
if (amount.lt(feeAmount)) {
|
|
@@ -316,7 +316,7 @@ class NEOClient {
|
|
|
316
316
|
getTargetProxyHash(token) {
|
|
317
317
|
const networkConfig = this.getNetworkConfig();
|
|
318
318
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
319
|
-
const addressHex =
|
|
319
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
320
320
|
return addressHex;
|
|
321
321
|
}
|
|
322
322
|
getNetworkConfig() {
|
package/lib/clients/ZILClient.js
CHANGED
|
@@ -73,12 +73,12 @@ class ZILClient {
|
|
|
73
73
|
getExternalBalances(sdk, address, whitelistDenoms) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
75
|
const tokenQueryResults = yield sdk.token.getAllTokens();
|
|
76
|
-
const tokens = tokenQueryResults.filter((token) =>
|
|
76
|
+
const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber()) == this.blockchain &&
|
|
77
77
|
token.tokenAddress.length == 40 &&
|
|
78
78
|
(!whitelistDenoms || whitelistDenoms.includes(token.denom)));
|
|
79
79
|
const requests = tokens.map((token) => token.tokenAddress === zeroAddress
|
|
80
|
-
?
|
|
81
|
-
:
|
|
80
|
+
? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
|
|
81
|
+
: exports.tokenBalanceBatchRequest(token.tokenAddress, address));
|
|
82
82
|
const response = yield fetch(this.getProviderUrl(), {
|
|
83
83
|
method: "post",
|
|
84
84
|
headers: { "content-type": "application/json" },
|
|
@@ -103,7 +103,7 @@ class ZILClient {
|
|
|
103
103
|
// if (!isValidAddress) {
|
|
104
104
|
// throw new Error("invalid address")
|
|
105
105
|
// }
|
|
106
|
-
return
|
|
106
|
+
return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
// see examplesV2/zil_client.ts on how to confirm the transactions
|
|
@@ -149,7 +149,7 @@ class ZILClient {
|
|
|
149
149
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
150
150
|
}
|
|
151
151
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
152
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
152
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
153
153
|
if (balanceAndNonceResp.error !== undefined) {
|
|
154
154
|
throw new Error(balanceAndNonceResp.error.message);
|
|
155
155
|
}
|
|
@@ -167,7 +167,7 @@ class ZILClient {
|
|
|
167
167
|
vname: "spender",
|
|
168
168
|
type: "ByStr20",
|
|
169
169
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
170
|
-
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress :
|
|
170
|
+
value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
173
|
vname: "amount",
|
|
@@ -185,7 +185,7 @@ class ZILClient {
|
|
|
185
185
|
}
|
|
186
186
|
checkAllowanceZRC2(token, owner, spender) {
|
|
187
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const contractAddress =
|
|
188
|
+
const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
|
|
189
189
|
const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
190
190
|
const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
|
|
191
191
|
if (resp.error !== undefined) {
|
|
@@ -205,13 +205,13 @@ class ZILClient {
|
|
|
205
205
|
throw new Error("Invalid recovery address");
|
|
206
206
|
}
|
|
207
207
|
const fromTokenId = fromToken.id;
|
|
208
|
-
const fromTokenAddr =
|
|
208
|
+
const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
|
|
209
209
|
const toTokenDenom = toToken.denom;
|
|
210
|
-
const targetProxyHash =
|
|
210
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
|
|
211
211
|
const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, CarbonSDK_1.default.Network.MainNet));
|
|
212
212
|
const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
|
|
213
213
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
|
|
214
|
-
const feeAddress =
|
|
214
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
215
215
|
const contractAddress = this.getBridgeEntranceAddr();
|
|
216
216
|
let zilliqa;
|
|
217
217
|
if (typeof signer === "string") {
|
|
@@ -226,7 +226,7 @@ class ZILClient {
|
|
|
226
226
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
227
227
|
}
|
|
228
228
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
229
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
229
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
|
|
230
230
|
if (balanceAndNonceResp.error !== undefined) {
|
|
231
231
|
throw new Error(balanceAndNonceResp.error.message);
|
|
232
232
|
}
|
|
@@ -303,13 +303,13 @@ class ZILClient {
|
|
|
303
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
304
304
|
const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
|
|
305
305
|
const networkConfig = this.getNetworkConfig();
|
|
306
|
-
const assetId =
|
|
307
|
-
const targetProxyHash =
|
|
308
|
-
const feeAddress =
|
|
306
|
+
const assetId = generic_1.appendHexPrefix(token.tokenAddress);
|
|
307
|
+
const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
|
|
308
|
+
const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
|
|
309
309
|
const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
|
|
310
310
|
const swthAddress = ethers_1.ethers.utils.hexlify(address);
|
|
311
311
|
// TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
|
|
312
|
-
const contractAddress =
|
|
312
|
+
const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
|
|
313
313
|
let zilliqa;
|
|
314
314
|
if (typeof signer === "string") {
|
|
315
315
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
@@ -323,7 +323,7 @@ class ZILClient {
|
|
|
323
323
|
zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
|
|
324
324
|
}
|
|
325
325
|
const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
|
|
326
|
-
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(
|
|
326
|
+
const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
|
|
327
327
|
if (balanceAndNonceResp.error !== undefined) {
|
|
328
328
|
throw new Error(balanceAndNonceResp.error.message);
|
|
329
329
|
}
|
|
@@ -408,7 +408,7 @@ class ZILClient {
|
|
|
408
408
|
getTargetProxyHash(token) {
|
|
409
409
|
const networkConfig = this.getNetworkConfig();
|
|
410
410
|
const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
|
|
411
|
-
const addressHex =
|
|
411
|
+
const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
|
|
412
412
|
return addressHex;
|
|
413
413
|
}
|
|
414
414
|
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
|
-
?
|
|
162
|
+
? 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 =
|
|
181
|
+
(obj.proposalStatus = 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
|
-
?
|
|
188
|
+
? 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 =
|
|
198
|
+
(obj.option = 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
|
-
?
|
|
621
|
+
? 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 =
|
|
627
|
+
message.mode !== undefined && (obj.mode = signing_1.signModeToJSON(message.mode));
|
|
628
628
|
return obj;
|
|
629
629
|
},
|
|
630
630
|
fromPartial(object) {
|
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.CARBON_GAS_PRICE = {
|
package/lib/constant/ibc.js
CHANGED
|
@@ -1660,6 +1660,11 @@ exports.EmbedChainInfosInit = {
|
|
|
1660
1660
|
coinMinimalDenom: "stuluna",
|
|
1661
1661
|
coinDecimals: 6,
|
|
1662
1662
|
},
|
|
1663
|
+
{
|
|
1664
|
+
"coinDenom": "stEVMOS",
|
|
1665
|
+
"coinMinimalDenom": "staevmos",
|
|
1666
|
+
"coinDecimals": 18
|
|
1667
|
+
},
|
|
1663
1668
|
],
|
|
1664
1669
|
feeCurrencies: [
|
|
1665
1670
|
{
|
package/lib/modules/cdp.js
CHANGED
|
@@ -429,7 +429,7 @@ class CDPModule extends base_1.default {
|
|
|
429
429
|
let availableBorrowsUsd = number_1.BN_ZERO;
|
|
430
430
|
let currLiquidationThreshold = number_1.BN_ZERO;
|
|
431
431
|
for (let i = 0; i < collaterals.length; i++) {
|
|
432
|
-
const amount =
|
|
432
|
+
const amount = number_1.bnOrZero(collaterals[i].collateralAmount);
|
|
433
433
|
if (amount.isZero()) {
|
|
434
434
|
continue; // no collateral for denom
|
|
435
435
|
}
|
|
@@ -446,9 +446,9 @@ class CDPModule extends base_1.default {
|
|
|
446
446
|
if (!assetParam) {
|
|
447
447
|
continue;
|
|
448
448
|
}
|
|
449
|
-
const ltv =
|
|
449
|
+
const ltv = number_1.bnOrZero(assetParam.loanToValue).div(number_1.BN_10000);
|
|
450
450
|
const availableBorrowUsd = collateralUsdVal.times(ltv);
|
|
451
|
-
const liquidationThreshold =
|
|
451
|
+
const liquidationThreshold = number_1.bnOrZero(assetParam.liquidationThreshold).div(number_1.BN_10000);
|
|
452
452
|
const liquidationThresholdVal = collateralUsdVal.times(liquidationThreshold);
|
|
453
453
|
totalCollateralsUsd = totalCollateralsUsd.plus(collateralUsdVal);
|
|
454
454
|
availableBorrowsUsd = availableBorrowsUsd.plus(availableBorrowUsd);
|
|
@@ -459,7 +459,7 @@ class CDPModule extends base_1.default {
|
|
|
459
459
|
const debts = debtsRsp.debts;
|
|
460
460
|
let totalDebtsUsd = number_1.BN_ZERO;
|
|
461
461
|
for (let i = 0; i < debts.length; i++) {
|
|
462
|
-
const amount =
|
|
462
|
+
const amount = number_1.bnOrZero(debts[i].principalDebt);
|
|
463
463
|
const denom = debts[i].denom;
|
|
464
464
|
if (amount.isZero()) {
|
|
465
465
|
continue;
|
|
@@ -481,7 +481,7 @@ class CDPModule extends base_1.default {
|
|
|
481
481
|
if (stablecoinDebtInfo) {
|
|
482
482
|
const accountStablecoin = yield sdk.query.cdp.AccountStablecoin({ address: account });
|
|
483
483
|
const stablecoinDecimals = (_a = (yield this.sdkProvider.getTokenClient().getDecimals(stablecoinDebtInfo.denom))) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
|
|
484
|
-
const stablecoinDebtAmount =
|
|
484
|
+
const stablecoinDebtAmount = number_1.bnOrZero(accountStablecoin.principalDebt).plus(number_1.bnOrZero(accountStablecoin.interestDebt));
|
|
485
485
|
stablecoinDebtUsd = stablecoinDebtAmount.shiftedBy(-stablecoinDecimals);
|
|
486
486
|
totalDebtsUsd = totalDebtsUsd.plus(stablecoinDebtUsd);
|
|
487
487
|
}
|
|
@@ -502,7 +502,7 @@ class CDPModule extends base_1.default {
|
|
|
502
502
|
const sdk = this.sdkProvider;
|
|
503
503
|
const cdpAddress = this.getCdpModuleAddress();
|
|
504
504
|
const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
|
|
505
|
-
return
|
|
505
|
+
return number_1.bnOrZero((_a = balanceRsp.balance) === null || _a === void 0 ? void 0 : _a.amount);
|
|
506
506
|
});
|
|
507
507
|
}
|
|
508
508
|
getCdpToActualRatio(cdpDenom) {
|
|
@@ -513,13 +513,13 @@ class CDPModule extends base_1.default {
|
|
|
513
513
|
const cdpAmountRsp = supplyRsp.amount;
|
|
514
514
|
if (!cdpAmountRsp)
|
|
515
515
|
throw new Error("unable to retrieve cdp token supply");
|
|
516
|
-
const cdpAmount =
|
|
516
|
+
const cdpAmount = number_1.bnOrZero(cdpAmountRsp.amount);
|
|
517
517
|
const cdpAddress = this.getCdpModuleAddress();
|
|
518
518
|
const balanceRsp = yield sdk.query.bank.Balance(query_2.QueryBalanceRequest.fromPartial({ address: cdpAddress, denom }));
|
|
519
519
|
if (!balanceRsp.balance)
|
|
520
520
|
throw new Error("unable to retrieve cdp module balance");
|
|
521
521
|
const owedAmount = yield this.getTotalTokenDebt(denom);
|
|
522
|
-
const actualAmount =
|
|
522
|
+
const actualAmount = number_1.bnOrZero(balanceRsp.balance.amount).plus(owedAmount);
|
|
523
523
|
if (!owedAmount)
|
|
524
524
|
throw new Error("unable to retrieve total token debt");
|
|
525
525
|
return cdpAmount.div(actualAmount);
|
|
@@ -541,8 +541,8 @@ class CDPModule extends base_1.default {
|
|
|
541
541
|
const allDebts = allDebtsRes.debtInfosAll;
|
|
542
542
|
for (let i = 0; i < allDebts.length; i++) {
|
|
543
543
|
const denom = allDebts[i].denom;
|
|
544
|
-
const interest =
|
|
545
|
-
const principal =
|
|
544
|
+
const interest = number_1.bnOrZero(allDebts[i].totalAccumulatedInterest);
|
|
545
|
+
const principal = number_1.bnOrZero(allDebts[i].totalPrincipal);
|
|
546
546
|
const debtAmt = interest.plus(principal);
|
|
547
547
|
const debtUsdVal = yield this.getTokenUsdVal(denom, debtAmt);
|
|
548
548
|
if (!debtUsdVal) {
|
|
@@ -554,7 +554,7 @@ class CDPModule extends base_1.default {
|
|
|
554
554
|
const stablecoinDebtRes = yield this.sdkProvider.query.cdp.StablecoinDebt({});
|
|
555
555
|
if (stablecoinDebtRes.stablecoinDebtInfo) {
|
|
556
556
|
const debtInfo = stablecoinDebtRes.stablecoinDebtInfo;
|
|
557
|
-
const debtAmt =
|
|
557
|
+
const debtAmt = number_1.bnOrZero(debtInfo.totalPrincipal).plus(number_1.bnOrZero(debtInfo.totalAccumulatedInterest));
|
|
558
558
|
const stablecoinDecimals = (_a = (yield sdk.getTokenClient().getDecimals(debtInfo.denom))) !== null && _a !== void 0 ? _a : 0;
|
|
559
559
|
const debtUsdVal = debtAmt.shiftedBy(-stablecoinDecimals);
|
|
560
560
|
totalDebt = totalDebt.plus(debtUsdVal);
|
|
@@ -572,7 +572,7 @@ class CDPModule extends base_1.default {
|
|
|
572
572
|
if (!TokenClient_1.default.isCdpToken(balance.denom)) {
|
|
573
573
|
continue;
|
|
574
574
|
}
|
|
575
|
-
const amount =
|
|
575
|
+
const amount = number_1.bnOrZero(balance.amount);
|
|
576
576
|
const collateralUsdValue = yield this.getCdpTokenUsdVal(balance.denom, amount);
|
|
577
577
|
allCollateralsUsdValue = allCollateralsUsdValue.plus(collateralUsdValue);
|
|
578
578
|
}
|
|
@@ -596,7 +596,7 @@ class CDPModule extends base_1.default {
|
|
|
596
596
|
const priceResult = yield sdk.query.pricing.TokenPrice(codec_1.QueryTokenPriceRequest.fromPartial({ denom }));
|
|
597
597
|
if (!priceResult.tokenPrice)
|
|
598
598
|
throw new Error("unable to retrieve token price for " + denom);
|
|
599
|
-
const twap =
|
|
599
|
+
const twap = number_1.bnOrZero(priceResult.tokenPrice.twap).shiftedBy(-18);
|
|
600
600
|
return amount.multipliedBy(twap).shiftedBy(-decimals);
|
|
601
601
|
});
|
|
602
602
|
}
|
|
@@ -611,11 +611,11 @@ class CDPModule extends base_1.default {
|
|
|
611
611
|
throw new Error("unable to retrieve debt info");
|
|
612
612
|
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
613
613
|
const newInterestRate = cimRsp.interest;
|
|
614
|
-
const principal =
|
|
615
|
-
const accumInterest =
|
|
614
|
+
const principal = number_1.bnOrZero(debtInfo.totalPrincipal);
|
|
615
|
+
const accumInterest = number_1.bnOrZero(debtInfo.totalAccumulatedInterest);
|
|
616
616
|
const newInterest = principal.times(newInterestRate).plus(accumInterest.times(number_1.BN_ONE.plus(newInterestRate)));
|
|
617
617
|
const cdpParamsRsp = yield this.sdkProvider.query.cdp.Params(query_1.QueryParamsRequest.fromPartial({}));
|
|
618
|
-
const interestFee =
|
|
618
|
+
const interestFee = number_1.bnOrZero((_a = cdpParamsRsp.params) === null || _a === void 0 ? void 0 : _a.interestFee);
|
|
619
619
|
const interest = newInterest.times(number_1.BN_10000.minus(interestFee)).dividedToIntegerBy(number_1.BN_10000);
|
|
620
620
|
return principal.plus(interest);
|
|
621
621
|
});
|
|
@@ -633,8 +633,8 @@ class CDPModule extends base_1.default {
|
|
|
633
633
|
const debtRes = yield sdk.query.cdp.AccountDebt({ address: account, denom: denom });
|
|
634
634
|
debt = debtRes.debt;
|
|
635
635
|
}
|
|
636
|
-
const principalAmount =
|
|
637
|
-
const initialCIM =
|
|
636
|
+
const principalAmount = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.principalDebt);
|
|
637
|
+
const initialCIM = number_1.bnOrZero(debt === null || debt === void 0 ? void 0 : debt.initialCumulativeInterestMultiplier);
|
|
638
638
|
if (principalAmount.isZero() || initialCIM.isZero())
|
|
639
639
|
return number_1.BN_ZERO;
|
|
640
640
|
const cimRsp = yield this.recalculateCIM(denom, debtInfo);
|
|
@@ -660,8 +660,8 @@ class CDPModule extends base_1.default {
|
|
|
660
660
|
const debtResp = yield sdk.query.cdp.AccountStablecoin(query_1.QueryAccountStablecoinRequest.fromPartial({ address: account }));
|
|
661
661
|
debt = debtResp;
|
|
662
662
|
}
|
|
663
|
-
principalAmount =
|
|
664
|
-
const initialCIM =
|
|
663
|
+
principalAmount = number_1.bnOrZero(debt.principalDebt);
|
|
664
|
+
const initialCIM = number_1.bnOrZero(debt.initialCumulativeInterestMultiplier);
|
|
665
665
|
const cim = yield this.recalculateStablecoinCIM(debtInfo);
|
|
666
666
|
if (!cim)
|
|
667
667
|
throw new Error("unable to retrieve account debt");
|
|
@@ -702,7 +702,7 @@ class CDPModule extends base_1.default {
|
|
|
702
702
|
return number_1.BN_ZERO;
|
|
703
703
|
}
|
|
704
704
|
const diffSeconds = new bignumber_js_1.BigNumber(diffMs).shiftedBy(-3).dp(0, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
705
|
-
const secondsAYear =
|
|
705
|
+
const secondsAYear = number_1.bnOrZero(31536000);
|
|
706
706
|
const numPeriods = secondsAYear.div(diffSeconds).dp(18);
|
|
707
707
|
return apy.div(numPeriods).dp(18); // carbon backend sdk.dec max 18 dp
|
|
708
708
|
}
|
|
@@ -726,8 +726,8 @@ class CDPModule extends base_1.default {
|
|
|
726
726
|
throw new Error("unable to retrieve cdp params for " + denom);
|
|
727
727
|
}
|
|
728
728
|
}
|
|
729
|
-
const interestFeeRate =
|
|
730
|
-
const utilizationRate =
|
|
729
|
+
const interestFeeRate = number_1.bnOrZero(params.interestFee).div(number_1.BN_10000);
|
|
730
|
+
const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
|
|
731
731
|
return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
|
|
732
732
|
});
|
|
733
733
|
}
|
|
@@ -742,7 +742,7 @@ class CDPModule extends base_1.default {
|
|
|
742
742
|
return { cim: number_1.BN_ZERO, interest: number_1.BN_ZERO };
|
|
743
743
|
}
|
|
744
744
|
}
|
|
745
|
-
const cim =
|
|
745
|
+
const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
|
|
746
746
|
const apy = yield this.calculateAPY(denom, debtInfo);
|
|
747
747
|
const newInterest = CDPModule.calculateInterestForTimePeriod(apy, (_a = debtInfo.lastUpdatedTime) !== null && _a !== void 0 ? _a : new Date(0), new Date());
|
|
748
748
|
const newCIM = cim.times(newInterest.plus(1));
|
|
@@ -761,8 +761,8 @@ class CDPModule extends base_1.default {
|
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
763
|
const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
|
|
764
|
-
const cim =
|
|
765
|
-
const apy =
|
|
764
|
+
const cim = number_1.bnOrZero(debtInfo.cumulativeInterestMultiplier);
|
|
765
|
+
const apy = number_1.bnOrZero((_a = paramsResponse.params) === null || _a === void 0 ? void 0 : _a.stablecoinInterestRate);
|
|
766
766
|
if (!apy) {
|
|
767
767
|
return number_1.BN_ZERO;
|
|
768
768
|
}
|
|
@@ -788,7 +788,7 @@ class CDPModule extends base_1.default {
|
|
|
788
788
|
const availableBorrowsUsd = accountData.AvailableBorrowsUsd.minus(accountData.TotalDebtsUsd);
|
|
789
789
|
const unlockableUsd = availableBorrowsUsd.multipliedBy(number_1.BN_10000).div(unlockRatio);
|
|
790
790
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom });
|
|
791
|
-
const tokenTwap =
|
|
791
|
+
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap);
|
|
792
792
|
if (tokenTwap.isZero())
|
|
793
793
|
throw new Error("unable to retrieve token price for " + denom);
|
|
794
794
|
const tokenAmt = unlockableUsd.div(tokenTwap.shiftedBy(-18)).shiftedBy(tokenDecimals);
|
|
@@ -799,7 +799,7 @@ class CDPModule extends base_1.default {
|
|
|
799
799
|
address: account,
|
|
800
800
|
cdpDenom: cdpDenom,
|
|
801
801
|
});
|
|
802
|
-
const lockedAmount =
|
|
802
|
+
const lockedAmount = number_1.bnOrZero((_e = (_d = accountCollateral.collateral) === null || _d === void 0 ? void 0 : _d.collateralAmount) !== null && _e !== void 0 ? _e : "0");
|
|
803
803
|
return lockedAmount.lt(cdpTokenAmt) ? lockedAmount : cdpTokenAmt;
|
|
804
804
|
});
|
|
805
805
|
}
|
|
@@ -817,7 +817,7 @@ class CDPModule extends base_1.default {
|
|
|
817
817
|
const denom = this.getUnderlyingDenom(cdpDenom);
|
|
818
818
|
const cdpToActualRatio = (_a = (yield this.getCdpToActualRatio(cdpDenom))) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
|
|
819
819
|
const tokenPrice = yield sdk.query.pricing.TokenPrice({ denom: denom });
|
|
820
|
-
const tokenTwap =
|
|
820
|
+
const tokenTwap = number_1.bnOrZero((_b = tokenPrice.tokenPrice) === null || _b === void 0 ? void 0 : _b.twap).shiftedBy(-18);
|
|
821
821
|
return tokenTwap.multipliedBy(cdpToActualRatio);
|
|
822
822
|
});
|
|
823
823
|
}
|
|
@@ -838,26 +838,26 @@ class CDPModule extends base_1.default {
|
|
|
838
838
|
});
|
|
839
839
|
if (!asset.assetParams)
|
|
840
840
|
throw new Error("unable to retrieve asset param for " + cdpActualDenom);
|
|
841
|
-
const bonus =
|
|
841
|
+
const bonus = number_1.bnOrZero(asset.assetParams.liquidationDiscount).div(number_1.BN_10000);
|
|
842
842
|
const cdpTokenPrice = yield this.getCdpTokenPrice(cdpDenom);
|
|
843
843
|
const cdpTokenDiscountedPrice = cdpTokenPrice.multipliedBy(number_1.BN_ONE.minus(bonus));
|
|
844
844
|
// get close factor
|
|
845
845
|
const debtorAccountData = yield sdk.query.cdp.AccountData({
|
|
846
846
|
address: debtor,
|
|
847
847
|
});
|
|
848
|
-
const debtorTotalCollateralVal =
|
|
849
|
-
const debtorTotalDebtVal =
|
|
850
|
-
const currentLiqThreshold =
|
|
848
|
+
const debtorTotalCollateralVal = number_1.bnOrZero(debtorAccountData.totalCollateralsUsd);
|
|
849
|
+
const debtorTotalDebtVal = number_1.bnOrZero(debtorAccountData.totalDebtsUsd);
|
|
850
|
+
const currentLiqThreshold = number_1.bnOrZero(debtorAccountData.currLiquidationThreshold);
|
|
851
851
|
const params = yield sdk.query.cdp.Params({});
|
|
852
852
|
if (!params.params) {
|
|
853
853
|
throw new Error("unable to retrieve cdp params");
|
|
854
854
|
}
|
|
855
|
-
const smallLiqSize =
|
|
856
|
-
const minCloseFactor =
|
|
857
|
-
const completeLiqThreshold =
|
|
855
|
+
const smallLiqSize = number_1.bnOrZero(params.params.smallLiquidationSize);
|
|
856
|
+
const minCloseFactor = number_1.bnOrZero(params.params.minimumCloseFactor);
|
|
857
|
+
const completeLiqThreshold = number_1.bnOrZero(params.params.completeLiquidationThreshold);
|
|
858
858
|
const closeFactor = this.computeCloseFactor(debtorTotalDebtVal, debtorTotalCollateralVal, currentLiqThreshold, smallLiqSize, minCloseFactor, completeLiqThreshold);
|
|
859
859
|
// get max repayable amount given the debtor's debt and how much liquidator wants to repay
|
|
860
|
-
const debtDecimals =
|
|
860
|
+
const debtDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(debtDenom));
|
|
861
861
|
const maxRepayableValue = debtorTotalDebtVal.multipliedBy(closeFactor);
|
|
862
862
|
const maxRepayableAmt = maxRepayableValue.shiftedBy(debtDecimals.toNumber());
|
|
863
863
|
if (debtRepaymentAmount.isGreaterThan(maxRepayableAmt)) {
|
|
@@ -865,7 +865,7 @@ class CDPModule extends base_1.default {
|
|
|
865
865
|
}
|
|
866
866
|
// calculate collateral amount that can be obtained given that debt amount and debtor's collateral balance
|
|
867
867
|
// AND, recalculate debt repay amount if needed
|
|
868
|
-
const cdpTokenDecimals =
|
|
868
|
+
const cdpTokenDecimals = number_1.bnOrZero(yield sdk.getTokenClient().getDecimals(cdpActualDenom));
|
|
869
869
|
let collateralAmtToLiquidate = this.calculateCollateralRequiredForDebt(number_1.BN_ONE, // assumes USC is $1
|
|
870
870
|
cdpTokenDiscountedPrice, debtRepaymentAmount, cdpTokenDecimals, debtDecimals);
|
|
871
871
|
const debtorAccountCollateral = yield sdk.query.cdp.AccountCollateral({
|
|
@@ -937,11 +937,11 @@ class CDPModule extends base_1.default {
|
|
|
937
937
|
}
|
|
938
938
|
exports.CDPModule = CDPModule;
|
|
939
939
|
CDPModule.calculateInterestAPY = (debtInfo, rateStrategy) => {
|
|
940
|
-
const utilizationRate =
|
|
941
|
-
const optimalUsage =
|
|
942
|
-
const variableRate1 =
|
|
943
|
-
const variableRate2 =
|
|
944
|
-
const baseVariableBorrowRate =
|
|
940
|
+
const utilizationRate = number_1.bnOrZero(debtInfo.utilizationRate).shiftedBy(-18);
|
|
941
|
+
const optimalUsage = number_1.bnOrZero(rateStrategy.optimalUsage).shiftedBy(-4);
|
|
942
|
+
const variableRate1 = number_1.bnOrZero(rateStrategy.variableRateSlope1).shiftedBy(-4);
|
|
943
|
+
const variableRate2 = number_1.bnOrZero(rateStrategy.variableRateSlope2).shiftedBy(-4);
|
|
944
|
+
const baseVariableBorrowRate = number_1.bnOrZero(rateStrategy.baseVariableBorrowRate).shiftedBy(-4);
|
|
945
945
|
if (utilizationRate.lte(optimalUsage)) {
|
|
946
946
|
const vRate = utilizationRate.times(variableRate1).div(optimalUsage).dp(4, bignumber_js_1.BigNumber.ROUND_CEIL);
|
|
947
947
|
return vRate.plus(baseVariableBorrowRate);
|