@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.
- package/{RPCLibrary.ts → RPCLibrary.js} +7 -121
- package/assets/{getAsset.ts → getAsset.js} +6 -6
- package/assets/{getAssets.ts → getAssets.js} +2 -3
- package/assets/{getSupply.ts → getSupply.js} +5 -7
- package/configs/chains/index.js +13 -0
- package/configs/index.js +17 -0
- package/contracts/feeCollector/{claimRewardFromPool.ts → claimRewardFromPool.js} +4 -10
- package/contracts/{getContract.ts → getContract.js} +5 -6
- package/contracts/{getContractAddress.ts → getContractAddress.js} +4 -6
- package/contracts/housePrices/{getLatestPrice.ts → getLatestPrice.js} +6 -8
- package/contracts/housePrices/{setOracle.ts → setOracle.js} +6 -8
- package/contracts/indexToken/{getNextRandomNFT.ts → getNextRandomNFT.js} +5 -7
- package/contracts/indexToken/{redeemNFT.ts → redeemNFT.js} +5 -7
- package/contracts/zeno/{createAuction.ts → createAuction.js} +14 -16
- package/contracts/zeno/{createZeno.ts → createZeno.js} +8 -10
- package/contracts/zeno/{getAuctions.ts → getAuctions.js} +5 -7
- package/contracts/zeno/{getZenos.ts → getZenos.js} +5 -7
- package/methods/commons/{checkAllowance.ts → checkAllowance.js} +10 -12
- package/methods/commons/{estimateGasPrice.ts → estimateGasPrice.js} +5 -7
- package/minter/{get.ts → get.js} +6 -8
- package/minter/{getApy.ts → getApy.js} +5 -7
- package/minter/{tick.ts → tick.js} +5 -7
- package/nfts/{getAllTokens.ts → getAllTokens.js} +7 -9
- package/nfts/{getBaseUri.ts → getBaseUri.js} +5 -7
- package/nfts/{getHousePrice.ts → getHousePrice.js} +6 -8
- package/nfts/{getMintFeePercentage.ts → getMintFeePercentage.js} +4 -6
- package/nfts/{getMintPrice.ts → getMintPrice.js} +7 -9
- package/nfts/{getTokenURI.ts → getTokenURI.js} +7 -9
- package/nfts/{getTokensByOwner.ts → getTokensByOwner.js} +8 -10
- package/nfts/{getTotalPropertiesCount.ts → getTotalPropertiesCount.js} +5 -7
- package/nfts/{mint.ts → mint.js} +7 -9
- package/nfts/{setBaseUri.ts → setBaseUri.js} +4 -6
- package/nfts/{totalNFTSupply.ts → totalNFTSupply.js} +4 -6
- package/package.json +1 -1
- package/pools/lendingPool/{borrowFromLendingPool.ts → borrowFromLendingPool.js} +8 -10
- package/pools/lendingPool/{borrowFromLendingPoolWithInsurance.ts → borrowFromLendingPoolWithInsurance.js} +8 -10
- package/pools/lendingPool/{calculateInsuranceFee.ts → calculateInsuranceFee.js} +9 -11
- package/pools/lendingPool/{claimReward.ts → claimReward.js} +5 -7
- package/pools/lendingPool/{closeLiquidation.ts → closeLiquidation.js} +7 -9
- package/pools/lendingPool/{depositNFTToLendingPool.ts → depositNFTToLendingPool.js} +6 -8
- package/pools/lendingPool/{depositToLendingPool.ts → depositToLendingPool.js} +6 -8
- package/pools/lendingPool/{getAllUserData.ts → getAllUserData.js} +7 -14
- package/pools/lendingPool/{getEligibleUserDeposits.ts → getEligibleUserDeposits.js} +7 -9
- package/pools/lendingPool/{getHealthFactor.ts → getHealthFactor.js} +8 -10
- package/pools/lendingPool/{getHousePrice.ts → getHousePrice.js} +6 -8
- package/pools/lendingPool/{getLendingPoolInfo.ts → getLendingPoolInfo.js} +23 -31
- package/pools/lendingPool/{getLendingPoolTotalLiquidity.ts → getLendingPoolTotalLiquidity.js} +7 -10
- package/pools/lendingPool/{getPendingReward.ts → getPendingReward.js} +7 -9
- package/pools/lendingPool/{getPositionDebt.ts → getPositionDebt.js} +8 -10
- package/pools/lendingPool/{getPositionScaledDebt.ts → getPositionScaledDebt.js} +8 -10
- package/pools/lendingPool/{getPositionView.ts → getPositionView.js} +9 -11
- package/pools/lendingPool/{getPositionsScaledDebt.ts → getPositionsScaledDebt.js} +7 -9
- package/pools/lendingPool/{getRawUserDepositsInLendingPool.ts → getRawUserDepositsInLendingPool.js} +7 -9
- package/pools/lendingPool/{getUserCollateralValue.ts → getUserCollateralValue.js} +7 -9
- package/pools/lendingPool/{initializeLiquidation.ts → initializeLiquidation.js} +8 -10
- package/pools/lendingPool/{repayToLendingPool.ts → repayToLendingPool.js} +8 -10
- package/pools/lendingPool/{withdrawFromLendingPool.ts → withdrawFromLendingPool.js} +9 -10
- package/pools/lendingPool/{withdrawNFTFromLendingPool.ts → withdrawNFTFromLendingPool.js} +7 -9
- package/pools/stabilityPool/{calculateRAACRewards.ts → calculateRAACRewards.js} +6 -9
- package/pools/stabilityPool/configs/chains/index.js +17 -0
- package/pools/stabilityPool/configs/index.js +43 -0
- package/pools/stabilityPool/{depositNFTToStabilityPool.ts → depositNFTToStabilityPool.js} +6 -9
- package/pools/stabilityPool/{depositToStabilityPool.ts → depositToStabilityPool.js} +6 -8
- package/pools/stabilityPool/{getRawUserDepositsInStabilityPool.ts → getRawUserDepositsInStabilityPool.js} +7 -9
- package/pools/stabilityPool/{getStabilityPoolInfo.ts → getStabilityPoolInfo.js} +10 -12
- package/pools/stabilityPool/{getStabilityPoolTotalDeposits.ts → getStabilityPoolTotalDeposits.js} +6 -8
- package/pools/stabilityPool/methods/commons/estimateGasPrice.js +28 -0
- package/pools/stabilityPool/pools/stabilityPool/withdrawFromStabilityPool.js +34 -0
- package/pools/stabilityPool/utils/artifacts.js +74 -0
- package/pools/stabilityPool/utils/contracts.js +82 -0
- package/pools/stabilityPool/{withdrawFromStabilityPool.ts → withdrawFromStabilityPool.js} +6 -8
- package/ts-to-js.sh +42 -0
- package/utils/{artifacts.ts → artifacts.js} +1 -4
- package/utils/{contracts.ts → contracts.js} +16 -18
- package/wallet/assets/{approveAsset.ts → approveAsset.js} +7 -8
- package/wallet/assets/{burnAsset.ts → burnAsset.js} +7 -9
- package/wallet/assets/{getAllowance.ts → getAllowance.js} +9 -10
- package/wallet/assets/{getAsset.ts → getAsset.js} +6 -7
- package/wallet/assets/{getAssets.ts → getAssets.js} +5 -6
- package/wallet/assets/{getBalance.ts → getBalance.js} +8 -9
- package/wallet/assets/{mintAsset.ts → mintAsset.js} +8 -9
- package/wallet/assets/{transferAsset.ts → transferAsset.js} +10 -11
- package/configs/chains/index.ts +0 -17
- package/configs/index.ts +0 -51
- /package/configs/chains/{chain.d.ts → chain.d.js} +0 -0
- /package/configs/{createConfig.ts → createConfig.js} +0 -0
- /package/contracts/crvUSDToken/{getBalance.ts → getBalance.js} +0 -0
- /package/contracts/crvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
- /package/contracts/rcrvUSDToken/{getBalance.ts → getBalance.js} +0 -0
- /package/contracts/rcrvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
- /package/{custom-types.d.ts → custom-types.d.js} +0 -0
- /package/{index.ts → index.js} +0 -0
- /package/methods/{approveToken.ts → approveToken.js} +0 -0
- /package/methods/{getAssetBalance.ts → getAssetBalance.js} +0 -0
- /package/methods/{getAssetsBalance.ts → getAssetsBalance.js} +0 -0
- /package/pools/liquidityPool/{getLiquidityPoolInfo.ts → getLiquidityPoolInfo.js} +0 -0
- /package/scripts/{index.ts → index.js} +0 -0
- /package/tests/{test.ts → test.js} +0 -0
- /package/utils/{chain.ts → chain.js} +0 -0
- /package/utils/{config.ts → config.js} +0 -0
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
9
|
-
address
|
|
10
|
-
tokenId
|
|
11
|
-
amount
|
|
12
|
-
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
|
-
)
|
|
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
|
|
30
|
+
} catch (error) {
|
|
33
31
|
console.error("Error in calculateInsuranceFee:", error);
|
|
34
32
|
throw error;
|
|
35
33
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
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
|
-
)
|
|
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
|
|
22
|
+
} catch (error) {
|
|
25
23
|
console.error("Error in claimReward:", error);
|
|
26
24
|
throw error;
|
|
27
25
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
16
|
-
tokenId
|
|
17
|
-
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
|
-
)
|
|
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
|
|
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
|
|
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
|
|
11
|
-
tokenId
|
|
12
|
-
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
|
-
)
|
|
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
|
|
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
|
|
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
|
|
11
|
-
amount
|
|
12
|
-
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
|
-
)
|
|
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
|
|
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
|
|
16
|
-
address
|
|
17
|
-
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
|
-
)
|
|
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
|
|
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] || [])
|
|
29
|
+
(data[3] || [])
|
|
37
30
|
).map((e) => transformPositionView(e)),
|
|
38
31
|
};
|
|
39
32
|
|
|
40
33
|
return formattedData;
|
|
41
|
-
} catch (error
|
|
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
|
|
2
|
-
import
|
|
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
|
|
16
|
-
address
|
|
17
|
-
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
|
-
)
|
|
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
|
|
31
|
+
} catch (error) {
|
|
34
32
|
console.error("Error in getEligibleUserDeposits:", error);
|
|
35
33
|
throw error;
|
|
36
34
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
16
|
-
address
|
|
17
|
-
tokenId
|
|
18
|
-
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
|
-
)
|
|
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
|
|
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
|
|
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
|
|
10
|
-
tokenId
|
|
11
|
-
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
|
-
)
|
|
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
|
|
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
|
|
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
|
|
11
|
-
address
|
|
12
|
-
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
|
-
)
|
|
18
|
+
);
|
|
22
19
|
|
|
23
20
|
const handleError =
|
|
24
|
-
(operation
|
|
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
|
-
|
|
44
|
-
|
|
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
|
|
67
|
-
const totalUsage
|
|
68
|
-
const liquidityIndex
|
|
69
|
-
const usageIndex
|
|
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
|
|
79
|
-
const currentUsageRate
|
|
80
|
-
const primeRate
|
|
81
|
-
const baseRate
|
|
82
|
-
const optimalRate
|
|
83
|
-
const maxRate
|
|
84
|
-
const optimalUtilizationRate
|
|
85
|
-
|
|
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
|
|
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
|
|
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
|
|
143
|
+
} catch (error) {
|
|
152
144
|
console.error("Error fetching lending pool info:", error);
|
|
153
145
|
throw error;
|
|
154
146
|
}
|
package/pools/lendingPool/{getLendingPoolTotalLiquidity.ts → getLendingPoolTotalLiquidity.js}
RENAMED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
12
|
-
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
|
-
)
|
|
18
|
+
);
|
|
22
19
|
|
|
23
|
-
const reserve =
|
|
20
|
+
const reserve = await lendingPoolContract.reserve();
|
|
24
21
|
const totalLiquidity = reserve.totalLiquidity;
|
|
25
22
|
return totalLiquidity;
|
|
26
|
-
} catch (error
|
|
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
|
|
2
|
-
import
|
|
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
|
|
9
|
-
address
|
|
10
|
-
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
|
-
)
|
|
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
|
|
24
|
+
} catch (error) {
|
|
27
25
|
console.error("Error in getPendingReward:", error);
|
|
28
26
|
throw error;
|
|
29
27
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
16
|
-
address
|
|
17
|
-
tokenId
|
|
18
|
-
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
|
-
)
|
|
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
|
|
32
|
+
} catch (error) {
|
|
35
33
|
console.error("Error in getPositionDebt:", error);
|
|
36
34
|
throw error;
|
|
37
35
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
16
|
-
address
|
|
17
|
-
tokenId
|
|
18
|
-
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
|
-
)
|
|
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
|
|
35
|
+
} catch (error) {
|
|
38
36
|
console.error("Error in getPositionScaledDebt:", error);
|
|
39
37
|
throw error;
|
|
40
38
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
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
|
|
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
|
|
29
|
-
address
|
|
30
|
-
tokenId
|
|
31
|
-
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
|
-
)
|
|
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
|
|
44
|
+
} catch (error) {
|
|
47
45
|
console.error("Error in getPositionView:", error);
|
|
48
46
|
throw error;
|
|
49
47
|
}
|