@raac/rpc 1.0.2-beta.3 → 1.0.2-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/{RPCLibrary.ts → RPCLibrary.js} +7 -121
  2. package/assets/{getAsset.ts → getAsset.js} +6 -6
  3. package/assets/{getAssets.ts → getAssets.js} +2 -3
  4. package/assets/{getSupply.ts → getSupply.js} +5 -7
  5. package/configs/chains/index.js +13 -0
  6. package/configs/index.js +17 -0
  7. package/contracts/feeCollector/{claimRewardFromPool.ts → claimRewardFromPool.js} +4 -10
  8. package/contracts/{getContract.ts → getContract.js} +5 -6
  9. package/contracts/{getContractAddress.ts → getContractAddress.js} +4 -6
  10. package/contracts/housePrices/{getLatestPrice.ts → getLatestPrice.js} +6 -8
  11. package/contracts/housePrices/{setOracle.ts → setOracle.js} +6 -8
  12. package/contracts/indexToken/{getNextRandomNFT.ts → getNextRandomNFT.js} +5 -7
  13. package/contracts/indexToken/{redeemNFT.ts → redeemNFT.js} +5 -7
  14. package/contracts/zeno/{createAuction.ts → createAuction.js} +14 -16
  15. package/contracts/zeno/{createZeno.ts → createZeno.js} +8 -10
  16. package/contracts/zeno/{getAuctions.ts → getAuctions.js} +5 -7
  17. package/contracts/zeno/{getZenos.ts → getZenos.js} +5 -7
  18. package/methods/commons/{checkAllowance.ts → checkAllowance.js} +10 -12
  19. package/methods/commons/{estimateGasPrice.ts → estimateGasPrice.js} +5 -7
  20. package/minter/{get.ts → get.js} +6 -8
  21. package/minter/{getApy.ts → getApy.js} +5 -7
  22. package/minter/{tick.ts → tick.js} +5 -7
  23. package/nfts/{getAllTokens.ts → getAllTokens.js} +7 -9
  24. package/nfts/{getBaseUri.ts → getBaseUri.js} +5 -7
  25. package/nfts/{getHousePrice.ts → getHousePrice.js} +6 -8
  26. package/nfts/{getMintFeePercentage.ts → getMintFeePercentage.js} +4 -6
  27. package/nfts/{getMintPrice.ts → getMintPrice.js} +7 -9
  28. package/nfts/{getTokenURI.ts → getTokenURI.js} +7 -9
  29. package/nfts/{getTokensByOwner.ts → getTokensByOwner.js} +8 -10
  30. package/nfts/{getTotalPropertiesCount.ts → getTotalPropertiesCount.js} +5 -7
  31. package/nfts/{mint.ts → mint.js} +7 -9
  32. package/nfts/{setBaseUri.ts → setBaseUri.js} +4 -6
  33. package/nfts/{totalNFTSupply.ts → totalNFTSupply.js} +4 -6
  34. package/package.json +1 -1
  35. package/pools/lendingPool/{borrowFromLendingPool.ts → borrowFromLendingPool.js} +8 -10
  36. package/pools/lendingPool/{borrowFromLendingPoolWithInsurance.ts → borrowFromLendingPoolWithInsurance.js} +8 -10
  37. package/pools/lendingPool/{calculateInsuranceFee.ts → calculateInsuranceFee.js} +9 -11
  38. package/pools/lendingPool/{claimReward.ts → claimReward.js} +5 -7
  39. package/pools/lendingPool/{closeLiquidation.ts → closeLiquidation.js} +7 -9
  40. package/pools/lendingPool/{depositNFTToLendingPool.ts → depositNFTToLendingPool.js} +6 -8
  41. package/pools/lendingPool/{depositToLendingPool.ts → depositToLendingPool.js} +6 -8
  42. package/pools/lendingPool/{getAllUserData.ts → getAllUserData.js} +7 -14
  43. package/pools/lendingPool/{getEligibleUserDeposits.ts → getEligibleUserDeposits.js} +7 -9
  44. package/pools/lendingPool/{getHealthFactor.ts → getHealthFactor.js} +8 -10
  45. package/pools/lendingPool/{getHousePrice.ts → getHousePrice.js} +6 -8
  46. package/pools/lendingPool/{getLendingPoolInfo.ts → getLendingPoolInfo.js} +23 -31
  47. package/pools/lendingPool/{getLendingPoolTotalLiquidity.ts → getLendingPoolTotalLiquidity.js} +7 -10
  48. package/pools/lendingPool/{getPendingReward.ts → getPendingReward.js} +7 -9
  49. package/pools/lendingPool/{getPositionDebt.ts → getPositionDebt.js} +8 -10
  50. package/pools/lendingPool/{getPositionScaledDebt.ts → getPositionScaledDebt.js} +8 -10
  51. package/pools/lendingPool/{getPositionView.ts → getPositionView.js} +9 -11
  52. package/pools/lendingPool/{getPositionsScaledDebt.ts → getPositionsScaledDebt.js} +7 -9
  53. package/pools/lendingPool/{getRawUserDepositsInLendingPool.ts → getRawUserDepositsInLendingPool.js} +7 -9
  54. package/pools/lendingPool/{getUserCollateralValue.ts → getUserCollateralValue.js} +7 -9
  55. package/pools/lendingPool/{initializeLiquidation.ts → initializeLiquidation.js} +8 -10
  56. package/pools/lendingPool/{repayToLendingPool.ts → repayToLendingPool.js} +8 -10
  57. package/pools/lendingPool/{withdrawFromLendingPool.ts → withdrawFromLendingPool.js} +9 -10
  58. package/pools/lendingPool/{withdrawNFTFromLendingPool.ts → withdrawNFTFromLendingPool.js} +7 -9
  59. package/pools/stabilityPool/{calculateRAACRewards.ts → calculateRAACRewards.js} +6 -9
  60. package/pools/stabilityPool/configs/chains/index.js +17 -0
  61. package/pools/stabilityPool/configs/index.js +43 -0
  62. package/pools/stabilityPool/{depositNFTToStabilityPool.ts → depositNFTToStabilityPool.js} +6 -9
  63. package/pools/stabilityPool/{depositToStabilityPool.ts → depositToStabilityPool.js} +6 -8
  64. package/pools/stabilityPool/{getRawUserDepositsInStabilityPool.ts → getRawUserDepositsInStabilityPool.js} +7 -9
  65. package/pools/stabilityPool/{getStabilityPoolInfo.ts → getStabilityPoolInfo.js} +10 -12
  66. package/pools/stabilityPool/{getStabilityPoolTotalDeposits.ts → getStabilityPoolTotalDeposits.js} +6 -8
  67. package/pools/stabilityPool/methods/commons/estimateGasPrice.js +28 -0
  68. package/pools/stabilityPool/pools/stabilityPool/withdrawFromStabilityPool.js +34 -0
  69. package/pools/stabilityPool/utils/artifacts.js +74 -0
  70. package/pools/stabilityPool/utils/contracts.js +82 -0
  71. package/pools/stabilityPool/{withdrawFromStabilityPool.ts → withdrawFromStabilityPool.js} +6 -8
  72. package/ts-to-js.sh +42 -0
  73. package/utils/{artifacts.ts → artifacts.js} +1 -4
  74. package/utils/{contracts.ts → contracts.js} +16 -18
  75. package/wallet/assets/{approveAsset.ts → approveAsset.js} +7 -8
  76. package/wallet/assets/{burnAsset.ts → burnAsset.js} +7 -9
  77. package/wallet/assets/{getAllowance.ts → getAllowance.js} +9 -10
  78. package/wallet/assets/{getAsset.ts → getAsset.js} +6 -7
  79. package/wallet/assets/{getAssets.ts → getAssets.js} +5 -6
  80. package/wallet/assets/{getBalance.ts → getBalance.js} +8 -9
  81. package/wallet/assets/{mintAsset.ts → mintAsset.js} +8 -9
  82. package/wallet/assets/{transferAsset.ts → transferAsset.js} +10 -11
  83. package/configs/chains/index.ts +0 -17
  84. package/configs/index.ts +0 -51
  85. /package/configs/chains/{chain.d.ts → chain.d.js} +0 -0
  86. /package/configs/{createConfig.ts → createConfig.js} +0 -0
  87. /package/contracts/crvUSDToken/{getBalance.ts → getBalance.js} +0 -0
  88. /package/contracts/crvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
  89. /package/contracts/rcrvUSDToken/{getBalance.ts → getBalance.js} +0 -0
  90. /package/contracts/rcrvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
  91. /package/{custom-types.d.ts → custom-types.d.js} +0 -0
  92. /package/{index.ts → index.js} +0 -0
  93. /package/methods/{approveToken.ts → approveToken.js} +0 -0
  94. /package/methods/{getAssetBalance.ts → getAssetBalance.js} +0 -0
  95. /package/methods/{getAssetsBalance.ts → getAssetsBalance.js} +0 -0
  96. /package/pools/liquidityPool/{getLiquidityPoolInfo.ts → getLiquidityPoolInfo.js} +0 -0
  97. /package/scripts/{index.ts → index.js} +0 -0
  98. /package/tests/{test.ts → test.js} +0 -0
  99. /package/utils/{chain.ts → chain.js} +0 -0
  100. /package/utils/{config.ts → config.js} +0 -0
@@ -1,15 +1,13 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  async function calculateInsuranceFee(
8
- chainId: ChainId,
9
- address: string,
10
- tokenId: string,
11
- amount: string,
12
- provider: Provider
6
+ chainId,
7
+ address,
8
+ tokenId,
9
+ amount,
10
+ provider
13
11
  ) {
14
12
  try {
15
13
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -18,7 +16,7 @@ async function calculateInsuranceFee(
18
16
  lendingPoolAddress,
19
17
  lendingPoolABI,
20
18
  provider
21
- ) as any as LendingPool;
19
+ );
22
20
 
23
21
  const amountInWei = ethers.parseEther(amount);
24
22
 
@@ -29,7 +27,7 @@ async function calculateInsuranceFee(
29
27
  );
30
28
 
31
29
  return ethers.formatEther(insuranceFee);
32
- } catch (error: any) {
30
+ } catch (error) {
33
31
  console.error("Error in calculateInsuranceFee:", error);
34
32
  throw error;
35
33
  }
@@ -1,10 +1,8 @@
1
- import { ethers, Signer } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
- async function claimReward(chainId: ChainId, signer: Signer) {
5
+ async function claimReward(chainId, signer) {
8
6
  try {
9
7
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
10
8
  const lendingPoolABI = getABI("lendingpool");
@@ -12,7 +10,7 @@ async function claimReward(chainId: ChainId, signer: Signer) {
12
10
  lendingPoolAddress,
13
11
  lendingPoolABI,
14
12
  signer
15
- ) as any as LendingPool;
13
+ );
16
14
 
17
15
  const tx = await lendingPoolContract.claimReward();
18
16
  const receipt = await tx.wait();
@@ -21,7 +19,7 @@ async function claimReward(chainId: ChainId, signer: Signer) {
21
19
  console.log(`Transaction hash: ${receipt?.hash}`);
22
20
 
23
21
  return receipt;
24
- } catch (error: any) {
22
+ } catch (error) {
25
23
  console.error("Error in claimReward:", error);
26
24
  throw error;
27
25
  }
@@ -1,8 +1,6 @@
1
- import { ethers, Provider, Signer } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  /**
8
6
  * @description Close the liqudation after the debt has been paid
@@ -12,9 +10,9 @@ import { LendingPool } from "../../typechain-types";
12
10
  * @returns
13
11
  */
14
12
  async function closeLiquidation(
15
- chainId: ChainId,
16
- tokenId: string,
17
- signer: Signer
13
+ chainId,
14
+ tokenId,
15
+ signer
18
16
  ) {
19
17
  try {
20
18
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -23,7 +21,7 @@ async function closeLiquidation(
23
21
  lendingPoolAddress,
24
22
  lendingPoolABI,
25
23
  signer
26
- ) as any as LendingPool;
24
+ );
27
25
 
28
26
  const tx = await lendingPoolContract.closeLiquidation(tokenId);
29
27
  await tx.wait();
@@ -31,7 +29,7 @@ async function closeLiquidation(
31
29
  console.log(`closeLiquidation result: ${tx.hash}`);
32
30
 
33
31
  return tx;
34
- } catch (error: any) {
32
+ } catch (error) {
35
33
  console.error("Error in closeLiquidation:", error);
36
34
  throw error;
37
35
  }
@@ -1,15 +1,13 @@
1
1
  import { ethers, Signer } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
4
  import estimateGasPrice from "../../methods/commons/estimateGasPrice";
5
- import { ChainId } from "../../configs/chains";
6
- import { LendingPool } from "../../typechain-types";
7
5
 
8
6
  //checked
9
7
  async function depositNFTToLendingPool(
10
- chainId: ChainId,
11
- tokenId: number | string,
12
- signer: Signer
8
+ chainId,
9
+ tokenId,
10
+ signer
13
11
  ) {
14
12
  if (!signer) {
15
13
  throw new Error("Wallet not connected");
@@ -25,7 +23,7 @@ async function depositNFTToLendingPool(
25
23
  lendingPoolAddress,
26
24
  lendingPoolABI,
27
25
  signer
28
- ) as any as LendingPool;
26
+ );
29
27
  const nftContract = new ethers.Contract(nftAddress, nftABI, signer);
30
28
 
31
29
  const { maxFeePerGas } = await estimateGasPrice(signer);
@@ -60,7 +58,7 @@ async function depositNFTToLendingPool(
60
58
  receipt?.hash
61
59
  );
62
60
  return receipt;
63
- } catch (error: any) {
61
+ } catch (error) {
64
62
  console.error(`NFT Deposit to Lending Pool error:`, error);
65
63
  throw new Error(`NFT Deposit to Lending Pool failed: ${error.message}`);
66
64
  }
@@ -1,15 +1,13 @@
1
1
  import { ethers, Signer } from "ethers";
2
- import { getContractAddress } from "../../utils/contracts";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
4
  import estimateGasPrice from "../../methods/commons/estimateGasPrice";
5
- import { ChainId } from "../../configs/chains";
6
- import { LendingPool } from "../../typechain-types";
7
5
 
8
6
  // checked
9
7
  async function depositToLendingPool(
10
- chainId: ChainId,
11
- amount: string,
12
- signer: Signer
8
+ chainId,
9
+ amount,
10
+ signer
13
11
  ) {
14
12
  if (!signer) {
15
13
  throw new Error("Wallet not connected");
@@ -23,7 +21,7 @@ async function depositToLendingPool(
23
21
  lendingPoolAddress,
24
22
  lendingPoolABI,
25
23
  signer
26
- ) as any as LendingPool;
24
+ );
27
25
 
28
26
  const amountInWei = ethers.parseEther(amount);
29
27
  const { maxFeePerGas } = await estimateGasPrice(signer);
@@ -43,7 +41,7 @@ async function depositToLendingPool(
43
41
  receipt?.hash
44
42
  );
45
43
  return receipt;
46
- } catch (error: any) {
44
+ } catch (error) {
47
45
  console.error(`Lending Pool Deposit error:`, error);
48
46
  throw new Error(`Lending Pool Deposit failed: ${error.message}`);
49
47
  }
@@ -1,20 +1,13 @@
1
1
  import { ethers, Provider } from "ethers";
2
2
  import { getContractAddress } from "../../utils/contracts";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains";
5
- import {
6
- ILendingPool,
7
- LendingPool,
8
- ReserveLibrary,
9
- } from "../../typechain-types";
10
- import { RawData, Reserve } from "../../custom-types";
11
4
  import { transformPositionView } from "./getPositionView";
12
5
 
13
6
  // checked
14
7
  async function getAllUserData(
15
- chainId: ChainId,
16
- address: string,
17
- provider: Provider
8
+ chainId,
9
+ address,
10
+ provider
18
11
  ) {
19
12
  try {
20
13
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -23,22 +16,22 @@ async function getAllUserData(
23
16
  lendingPoolAddress,
24
17
  abi,
25
18
  provider
26
- ) as any as LendingPool;
19
+ );
27
20
 
28
21
  const data = await lendingPoolContract.getAllUserData(address);
29
22
 
30
23
  // ILendingPool.UserDataView
31
24
  const formattedData = {
32
- nftTokenIds: (data[0] || []).map((id: any) => id.toString()) as string[],
25
+ nftTokenIds: (data[0] || []).map((id) => id.toString()),
33
26
  scaledDebtBalance: ethers.formatEther(data[1] || 0n),
34
27
  userCollateralValue: ethers.formatEther(data[2] || 0n),
35
28
  positions: (
36
- (data[3] || []) as ILendingPool.NFTPositionViewStructOutput[]
29
+ (data[3] || [])
37
30
  ).map((e) => transformPositionView(e)),
38
31
  };
39
32
 
40
33
  return formattedData;
41
- } catch (error: any) {
34
+ } catch (error) {
42
35
  console.error("Error fetching lending pool info:", error);
43
36
  throw error;
44
37
  }
@@ -1,8 +1,6 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  /**
8
6
  * @description Total amount of RToken + DEToken = total crvUSD they put in the system so far. How much they have contributed to the system.
@@ -12,9 +10,9 @@ import { LendingPool } from "../../typechain-types";
12
10
  * @returns
13
11
  */
14
12
  async function getEligibleUserDeposits(
15
- chainId: ChainId,
16
- address: string,
17
- provider: Provider
13
+ chainId,
14
+ address,
15
+ provider
18
16
  ) {
19
17
  try {
20
18
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -23,14 +21,14 @@ async function getEligibleUserDeposits(
23
21
  lendingPoolAddress,
24
22
  lendingPoolABI,
25
23
  provider
26
- ) as any as LendingPool;
24
+ );
27
25
 
28
26
  const value = await lendingPoolContract.getEligibleUserDeposits(address);
29
27
 
30
28
  console.log(`Eligible user deposits: ${ethers.formatEther(value)}`);
31
29
 
32
30
  return value;
33
- } catch (error: any) {
31
+ } catch (error) {
34
32
  console.error("Error in getEligibleUserDeposits:", error);
35
33
  throw error;
36
34
  }
@@ -1,8 +1,6 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  /**
8
6
  * @description Get the health factor of a NFT position -> factor < 1 : undercollateralized.
@@ -12,10 +10,10 @@ import { LendingPool } from "../../typechain-types";
12
10
  * @returns The health factor of a position (0, inf)
13
11
  */
14
12
  async function getHealthFactor(
15
- chainId: ChainId,
16
- address: string,
17
- tokenId: string,
18
- provider: Provider
13
+ chainId,
14
+ address,
15
+ tokenId,
16
+ provider
19
17
  ) {
20
18
  try {
21
19
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -24,7 +22,7 @@ async function getHealthFactor(
24
22
  lendingPoolAddress,
25
23
  lendingPoolABI,
26
24
  provider
27
- ) as any as LendingPool;
25
+ );
28
26
 
29
27
  const value = await lendingPoolContract.calculateHealthFactor(
30
28
  address,
@@ -34,7 +32,7 @@ async function getHealthFactor(
34
32
  console.log(`getHealthFactor result: ${value}`);
35
33
 
36
34
  return value;
37
- } catch (error: any) {
35
+ } catch (error) {
38
36
  console.error("Error in getHealthFactor:", error);
39
37
  throw error;
40
38
  }
@@ -1,14 +1,12 @@
1
1
  import { ethers, Signer } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { RAACHousePrices } from "../../typechain-types";
6
4
 
7
5
  // checked
8
6
  async function getHousePrice(
9
- chainId: ChainId,
10
- tokenId: number | string,
11
- signer: Signer
7
+ chainId,
8
+ tokenId,
9
+ signer
12
10
  ) {
13
11
  console.log(chainId, tokenId, signer);
14
12
  if (!signer) {
@@ -19,7 +17,7 @@ async function getHousePrice(
19
17
  const raacHousePricesAddress = getContractAddress(
20
18
  chainId,
21
19
  "raachouseprices"
22
- ) as any as RAACHousePrices;
20
+ );
23
21
  const raacHousePricesABI = getABI("raachouseprices");
24
22
 
25
23
  const raacHousePricesContract = new ethers.Contract(
@@ -37,7 +35,7 @@ async function getHousePrice(
37
35
  )} ETH`
38
36
  );
39
37
  return housePrice;
40
- } catch (error: any) {
38
+ } catch (error) {
41
39
  console.error(`Error getting house price for token ID ${tokenId}:`, error);
42
40
  throw new Error(`Failed to get house price: ${error.message}`);
43
41
  }
@@ -1,15 +1,12 @@
1
1
  import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../utils/contracts";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains";
5
- import { LendingPool, ReserveLibrary } from "../../typechain-types";
6
- import { RawData, Reserve } from "../../custom-types";
7
4
 
8
5
  // checked
9
6
  async function getLendingPoolInfo(
10
- chainId: ChainId,
11
- address: string,
12
- provider: Provider
7
+ chainId,
8
+ address,
9
+ provider
13
10
  ) {
14
11
  try {
15
12
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -18,10 +15,10 @@ async function getLendingPoolInfo(
18
15
  lendingPoolAddress,
19
16
  abi,
20
17
  provider
21
- ) as any as LendingPool;
18
+ );
22
19
 
23
20
  const handleError =
24
- (operation: string, returnType?: any) => (error: any) => {
21
+ (operation, returnType) => (error) => {
25
22
  if (error.code === "BAD_DATA") {
26
23
  console.log(
27
24
  `BAD_DATA from ${operation} - Pool empty?`,
@@ -40,12 +37,8 @@ async function getLendingPoolInfo(
40
37
  liquidationThreshold,
41
38
  healthFactorLiquidationThreshold,
42
39
  ] = await Promise.all([
43
- (lendingPoolContract.reserve() as Promise<Reserve>).catch(
44
- handleError("reserve")
45
- ),
46
- (lendingPoolContract.rateData() as Promise<RawData>).catch(
47
- handleError("rateData")
48
- ),
40
+ lendingPoolContract.reserve().catch(handleError("reserve")),
41
+ lendingPoolContract.rateData().catch(handleError("rateData")),
49
42
  lendingPoolContract
50
43
  .getNormalizedIncome()
51
44
  .catch(handleError("getNormalizedIncome", 0n)),
@@ -63,10 +56,10 @@ async function getLendingPoolInfo(
63
56
  console.log(reserve);
64
57
 
65
58
  // Extract data from reserve
66
- const totalLiquidity: bigint = reserve?.totalLiquidity ?? 0n;
67
- const totalUsage: bigint = reserve?.totalUsage ?? 0n;
68
- const liquidityIndex: bigint = reserve?.liquidityIndex ?? 0n;
69
- const usageIndex: bigint = reserve?.usageIndex ?? 0n;
59
+ const totalLiquidity = reserve?.totalLiquidity ?? 0n;
60
+ const totalUsage = reserve?.totalUsage ?? 0n;
61
+ const liquidityIndex = reserve?.liquidityIndex ?? 0n;
62
+ const usageIndex = reserve?.usageIndex ?? 0n;
70
63
 
71
64
  // Compute utilization
72
65
  let utilization = 0n;
@@ -75,18 +68,17 @@ async function getLendingPoolInfo(
75
68
  }
76
69
 
77
70
  // Extract rate data
78
- const currentLiquidityRate: bigint = rateData?.currentLiquidityRate ?? 0n;
79
- const currentUsageRate: bigint = rateData?.currentUsageRate ?? 0n;
80
- const primeRate: bigint = rateData?.primeRate ?? 0n;
81
- const baseRate: bigint = rateData?.baseRate ?? 0n;
82
- const optimalRate: bigint = rateData?.optimalRate ?? 0n;
83
- const maxRate: bigint = rateData?.maxRate ?? 0n;
84
- const optimalUtilizationRate: bigint =
85
- rateData?.optimalUtilizationRate ?? 0n;
86
- const protocolFeeRate: bigint = rateData?.protocolFeeRate ?? 0n;
71
+ const currentLiquidityRate = rateData?.currentLiquidityRate ?? 0n;
72
+ const currentUsageRate = rateData?.currentUsageRate ?? 0n;
73
+ const primeRate = rateData?.primeRate ?? 0n;
74
+ const baseRate = rateData?.baseRate ?? 0n;
75
+ const optimalRate = rateData?.optimalRate ?? 0n;
76
+ const maxRate = rateData?.maxRate ?? 0n;
77
+ const optimalUtilizationRate = rateData?.optimalUtilizationRate ?? 0n;
78
+ const protocolFeeRate = rateData?.protocolFeeRate ?? 0n;
87
79
 
88
80
  // Compute APY
89
- let apy: bigint;
81
+ let apy;
90
82
  if (utilization <= optimalUtilizationRate && optimalUtilizationRate > 0) {
91
83
  const rateSlope = primeRate - baseRate;
92
84
  const rateIncrease = (utilization * rateSlope) / optimalUtilizationRate;
@@ -103,7 +95,7 @@ async function getLendingPoolInfo(
103
95
  let userRedeemable = 0n;
104
96
  if (address) {
105
97
  // Fetch user's scaled RToken balance
106
- const rTokenAddress = reserve?.reserveRTokenAddress as string;
98
+ const rTokenAddress = reserve?.reserveRTokenAddress;
107
99
  const rTokenABI = getABI("rtoken");
108
100
  const rTokenContract = new ethers.Contract(
109
101
  rTokenAddress,
@@ -148,7 +140,7 @@ async function getLendingPoolInfo(
148
140
  };
149
141
 
150
142
  return result;
151
- } catch (error: any) {
143
+ } catch (error) {
152
144
  console.error("Error fetching lending pool info:", error);
153
145
  throw error;
154
146
  }
@@ -1,15 +1,12 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../utils/contracts";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains";
5
- import { LendingPool } from "../../typechain-types";
6
- import { Reserve } from "../../custom-types";
7
4
 
8
5
  // The lending pool reserve contains the total liquidity of the lending pool. see getLendingPooInfo.ts
9
6
  // @deprecated
10
7
  async function getLendingPoolTotalLiquidity(
11
- chainId: ChainId,
12
- provider: Provider
8
+ chainId,
9
+ provider
13
10
  ) {
14
11
  try {
15
12
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -18,12 +15,12 @@ async function getLendingPoolTotalLiquidity(
18
15
  lendingPoolAddress,
19
16
  abi,
20
17
  provider
21
- ) as any as LendingPool;
18
+ );
22
19
 
23
- const reserve = (await lendingPoolContract.reserve()) as Reserve;
20
+ const reserve = await lendingPoolContract.reserve();
24
21
  const totalLiquidity = reserve.totalLiquidity;
25
22
  return totalLiquidity;
26
- } catch (error: any) {
23
+ } catch (error) {
27
24
  console.error("Error fetching total liquidity:", error);
28
25
  throw error;
29
26
  }
@@ -1,13 +1,11 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  async function getPendingReward(
8
- chainId: ChainId,
9
- address: string,
10
- provider: Provider
6
+ chainId,
7
+ address,
8
+ provider
11
9
  ) {
12
10
  try {
13
11
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -16,14 +14,14 @@ async function getPendingReward(
16
14
  lendingPoolAddress,
17
15
  lendingPoolABI,
18
16
  provider
19
- ) as any as LendingPool;
17
+ );
20
18
 
21
19
  const reward = await lendingPoolContract.getPendingReward(address);
22
20
 
23
21
  console.log(`Pending reward: ${ethers.formatEther(reward)}`);
24
22
 
25
23
  return reward;
26
- } catch (error: any) {
24
+ } catch (error) {
27
25
  console.error("Error in getPendingReward:", error);
28
26
  throw error;
29
27
  }
@@ -1,8 +1,6 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  /**
8
6
  * @description Get the raw debt of the user on a NFT. Equivant to the original amount borrowed on NFT.
@@ -12,10 +10,10 @@ import { LendingPool } from "../../typechain-types";
12
10
  * @returns The raw debt of the user on a NFT
13
11
  */
14
12
  async function getPositionDebt(
15
- chainId: ChainId,
16
- address: string,
17
- tokenId: string,
18
- provider: Provider
13
+ chainId,
14
+ address,
15
+ tokenId,
16
+ provider
19
17
  ) {
20
18
  try {
21
19
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -24,14 +22,14 @@ async function getPositionDebt(
24
22
  lendingPoolAddress,
25
23
  lendingPoolABI,
26
24
  provider
27
- ) as any as LendingPool;
25
+ );
28
26
 
29
27
  const reward = await lendingPoolContract.getPositionDebt(address, tokenId);
30
28
 
31
29
  console.log(`getPositionDebt result: ${ethers.formatEther(reward)}`);
32
30
 
33
31
  return reward;
34
- } catch (error: any) {
32
+ } catch (error) {
35
33
  console.error("Error in getPositionDebt:", error);
36
34
  throw error;
37
35
  }
@@ -1,8 +1,6 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { LendingPool } from "../../typechain-types";
6
4
 
7
5
  /**
8
6
  * @description Get the scaled debt of the user on a NFT (contains the accured interest)
@@ -12,10 +10,10 @@ import { LendingPool } from "../../typechain-types";
12
10
  * @returns The debt of the user on a NFT with the accured interest
13
11
  */
14
12
  async function getPositionScaledDebt(
15
- chainId: ChainId,
16
- address: string,
17
- tokenId: string,
18
- provider: Provider
13
+ chainId,
14
+ address,
15
+ tokenId,
16
+ provider
19
17
  ) {
20
18
  try {
21
19
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -24,7 +22,7 @@ async function getPositionScaledDebt(
24
22
  lendingPoolAddress,
25
23
  lendingPoolABI,
26
24
  provider
27
- ) as any as LendingPool;
25
+ );
28
26
 
29
27
  const reward = await lendingPoolContract.getPositionScaledDebt(
30
28
  address,
@@ -34,7 +32,7 @@ async function getPositionScaledDebt(
34
32
  console.log(`getPositionScaledDebt result: ${ethers.formatEther(reward)}`);
35
33
 
36
34
  return reward;
37
- } catch (error: any) {
35
+ } catch (error) {
38
36
  console.error("Error in getPositionScaledDebt:", error);
39
37
  throw error;
40
38
  }
@@ -1,11 +1,9 @@
1
- import { ethers, Provider } from "ethers";
2
- import { getContractAddress } from "../../contracts/getContractAddress";
1
+ import { ethers } from "ethers";
2
+ import getContractAddress from "../../contracts/getContractAddress";
3
3
  import { getABI } from "../../utils/artifacts";
4
- import { ChainId } from "../../configs/chains/index";
5
- import { ILendingPool, LendingPool } from "../../typechain-types";
6
4
 
7
5
  export function transformPositionView(
8
- positionView: ILendingPool.NFTPositionViewStructOutput
6
+ positionView
9
7
  ) {
10
8
  return {
11
9
  rawDebtBalance: ethers.formatEther(positionView?.[0] || 0n),
@@ -25,10 +23,10 @@ export function transformPositionView(
25
23
  * @returns All information about a NFT position
26
24
  */
27
25
  async function getPositionView(
28
- chainId: ChainId,
29
- address: string,
30
- tokenId: string,
31
- provider: Provider
26
+ chainId,
27
+ address,
28
+ tokenId,
29
+ provider
32
30
  ) {
33
31
  try {
34
32
  const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
@@ -37,13 +35,13 @@ async function getPositionView(
37
35
  lendingPoolAddress,
38
36
  lendingPoolABI,
39
37
  provider
40
- ) as any as LendingPool;
38
+ );
41
39
 
42
40
  const res = await lendingPoolContract.getPositionView(address, tokenId);
43
41
  console.log(`getPositionView result: ${res}`);
44
42
 
45
43
  return transformPositionView(res);
46
- } catch (error: any) {
44
+ } catch (error) {
47
45
  console.error("Error in getPositionView:", error);
48
46
  throw error;
49
47
  }