@raac/rpc 1.1.0-beta.22 → 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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const getAdapterAddress_1 = require("./getAdapterAddress");
4
4
  const _helpers_1 = require("./_helpers");
5
+ const ethers_1 = require("ethers");
5
6
  async function borrowFromLendingPool(chainId, adapterName, amount, data, signer) {
6
7
  try {
7
8
  const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
@@ -9,7 +10,8 @@ async function borrowFromLendingPool(chainId, adapterName, amount, data, signer)
9
10
  if (!adapterAddress) {
10
11
  throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
11
12
  }
12
- const tx = await lendingPoolContract.borrow(adapterAddress, data, amount);
13
+ const amountInWei = ethers_1.ethers.parseEther(amount);
14
+ const tx = await lendingPoolContract.borrow(adapterAddress, data, amountInWei);
13
15
  const receipt = await tx.wait();
14
16
  return receipt.status === 1;
15
17
  }
@@ -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,22 +20,27 @@ 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
- const insuranceFee = await (0, calculateInsuranceFee_1.default)(chainId, adapterName, userAddress, data, ethers_1.ethers.formatEther(amount.toString()), signer.provider);
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
- const currentAllowance = await (0, checkAllowance_1.default)(chainId, "crvusd", userAddress, lendingPoolAddress, signer.provider);
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
- const amountToApprove = insuranceFee.toString();
30
- await (0, approveAsset_1.default)(chainId, "crvusd", lendingPoolAddress, ethers_1.ethers.formatEther(amountToApprove), signer);
32
+ const amountToApprove = insuranceFee;
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 {
34
39
  console.log(`Already approved sufficient crvUSD for insurance fee: ${ethers_1.ethers.formatEther(currentAllowance)}`);
35
40
  }
36
41
  // Now proceed with the borrow transaction
37
- const tx = await lendingPoolContract.borrowWithInsurance(adapterAddress, data, amount);
42
+ const amountInWei = ethers_1.ethers.parseEther(amount);
43
+ const tx = await lendingPoolContract.borrowWithInsurance(adapterAddress, data, amountInWei);
38
44
  const receipt = await tx.wait();
39
45
  console.log(`Borrowed with insurance successfully. Transaction hash: ${receipt?.hash}`);
40
46
  return receipt.status === 1;
@@ -12,7 +12,7 @@ async function calculateInsuranceFee(chainId, adapterName, userAddress, data, am
12
12
  }
13
13
  const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
14
14
  const amountInWei = ethers_1.ethers.parseEther(amount);
15
- const fee = await lendingPoolContract.calculateInsuranceFee(adapterAddress, userAddress, data, amountInWei.toString());
15
+ const fee = await lendingPoolContract.calculateInsuranceFee(adapterAddress, userAddress, data, amountInWei);
16
16
  console.log(`Insurance fee: ${ethers_1.ethers.formatEther(fee)}`);
17
17
  return fee;
18
18
  }
@@ -1,5 +1,5 @@
1
1
  import { ChainId } from "../../configs/chains";
2
2
  import { LendingPoolAdapterId } from "./types";
3
- import { BigNumberish, BytesLike, Signer } from "ethers";
4
- declare function borrowFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: BigNumberish, data: BytesLike, signer: Signer): Promise<boolean>;
3
+ import { BytesLike, Signer } from "ethers";
4
+ declare function borrowFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: string, data: BytesLike, signer: Signer): Promise<boolean>;
5
5
  export default borrowFromLendingPool;
@@ -1,5 +1,5 @@
1
- import { BigNumberish, BytesLike, Signer } from "ethers";
1
+ import { BytesLike, Signer } from "ethers";
2
2
  import { ChainId } from "../../configs/chains";
3
3
  import { LendingPoolAdapterId } from "./types";
4
- declare function borrowFromLendingPoolWithInsurance(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: BigNumberish, data: BytesLike, signer: Signer): Promise<boolean>;
4
+ declare function borrowFromLendingPoolWithInsurance(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: string, data: BytesLike, signer: Signer): Promise<boolean>;
5
5
  export default borrowFromLendingPoolWithInsurance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raac/rpc",
3
- "version": "1.1.0-beta.22",
3
+ "version": "1.1.0-beta.24",
4
4
  "description": "RPC Library for RAAC ",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",