@raac/rpc 1.1.0-beta.23 → 1.1.0-beta.24
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.
|
@@ -9,6 +9,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
9
9
|
const checkAllowance_1 = __importDefault(require("../../methods/commons/checkAllowance"));
|
|
10
10
|
const approveAsset_1 = __importDefault(require("../../wallet/assets/approveAsset"));
|
|
11
11
|
const calculateInsuranceFee_1 = __importDefault(require("./calculateInsuranceFee"));
|
|
12
|
+
const contracts_1 = require("../../utils/contracts");
|
|
12
13
|
// TODO: interface changed
|
|
13
14
|
async function borrowFromLendingPoolWithInsurance(chainId, adapterName, amount, data, signer) {
|
|
14
15
|
try {
|
|
@@ -19,15 +20,19 @@ async function borrowFromLendingPoolWithInsurance(chainId, adapterName, amount,
|
|
|
19
20
|
}
|
|
20
21
|
const userAddress = await signer.getAddress();
|
|
21
22
|
const lendingPoolAddress = await lendingPoolContract.getAddress();
|
|
23
|
+
const feeCollectorAddress = (0, contracts_1.getContractAddress)(chainId, "feecollector");
|
|
22
24
|
// Calculate the insurance fee they need to pay
|
|
23
25
|
const insuranceFee = await (0, calculateInsuranceFee_1.default)(chainId, adapterName, userAddress, data, amount, signer.provider);
|
|
24
26
|
console.log(`Insurance fee required: ${ethers_1.ethers.formatEther(insuranceFee)} crvUSD`);
|
|
25
27
|
// Check if the user has approved enough crvUSD for the insurance fee
|
|
26
|
-
|
|
28
|
+
// TODO: With the new changes, need to check approval towards the lending pool address
|
|
29
|
+
const currentAllowance = await (0, checkAllowance_1.default)(chainId, "crvusd", userAddress, feeCollectorAddress, signer.provider);
|
|
27
30
|
// If allowance is less than the insurance fee, approve it
|
|
28
31
|
if (currentAllowance < insuranceFee) {
|
|
29
32
|
const amountToApprove = insuranceFee;
|
|
30
|
-
await (0, approveAsset_1.default)(chainId, "crvusd",
|
|
33
|
+
await (0, approveAsset_1.default)(chainId, "crvusd",
|
|
34
|
+
// TODO: With the new changes, need to approve towards the lending pool address
|
|
35
|
+
feeCollectorAddress, ethers_1.ethers.formatEther(amountToApprove), signer);
|
|
31
36
|
console.log(`Approved ${ethers_1.ethers.formatEther(insuranceFee)} crvUSD for insurance fee`);
|
|
32
37
|
}
|
|
33
38
|
else {
|