@raac/rpc 1.1.0-beta.11 → 1.1.0-beta.13
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/dist/pools/lendingPool/_helpers.js +2 -3
- package/dist/pools/lendingPool/borrowFromLendingPool.js +2 -2
- package/dist/pools/lendingPool/borrowFromLendingPoolWithInsurance.js +2 -2
- package/dist/pools/lendingPool/calculateInsuranceFee.js +1 -1
- package/dist/pools/lendingPool/closeLiquidation.js +2 -2
- package/dist/pools/lendingPool/depositAssetToLendingPool.js +2 -2
- package/dist/pools/lendingPool/depositToLendingPool.js +1 -1
- package/dist/pools/lendingPool/getAdapters.js +1 -1
- package/dist/pools/lendingPool/getEligibleUserDeposits.js +1 -1
- package/dist/pools/lendingPool/getHealthFactor.js +2 -2
- package/dist/pools/lendingPool/getLendingPoolInfo.js +9 -9
- package/dist/pools/lendingPool/getLendingPoolTotalLiquidity.js +1 -1
- package/dist/pools/lendingPool/getParameters.js +1 -1
- package/dist/pools/lendingPool/getPositionDebt.js +2 -2
- package/dist/pools/lendingPool/getPositionScaledDebt.js +2 -2
- package/dist/pools/lendingPool/getPositionView.js +1 -1
- package/dist/pools/lendingPool/getPositionsScaledDebt.js +1 -1
- package/dist/pools/lendingPool/getRawUserDepositsInLendingPool.js +1 -1
- package/dist/pools/lendingPool/getUserCollateralValue.js +1 -1
- package/dist/pools/lendingPool/getWithdrawRequestInfo.js +1 -1
- package/dist/pools/lendingPool/initializeLiquidation.js +2 -2
- package/dist/pools/lendingPool/openVaultPosition.js +1 -1
- package/dist/pools/lendingPool/repayToLendingPool.js +2 -2
- package/dist/pools/lendingPool/requestWithdraw.js +1 -1
- package/dist/pools/lendingPool/withdrawAssetFromLendingPool.js +2 -2
- package/dist/pools/lendingPool/withdrawFromLendingPool.js +1 -1
- package/dist/scripts/index.js +50 -72
- package/dist/types/pools/lendingPool/_helpers.d.ts +2 -2
- package/dist/types/pools/lendingPool/borrowFromLendingPool.d.ts +2 -2
- package/dist/types/pools/lendingPool/borrowFromLendingPoolWithInsurance.d.ts +2 -2
- package/dist/types/pools/lendingPool/closeLiquidation.d.ts +2 -2
- package/dist/types/pools/lendingPool/depositAssetToLendingPool.d.ts +2 -2
- package/dist/types/pools/lendingPool/getHealthFactor.d.ts +2 -2
- package/dist/types/pools/lendingPool/getPositionDebt.d.ts +2 -2
- package/dist/types/pools/lendingPool/getPositionScaledDebt.d.ts +2 -2
- package/dist/types/pools/lendingPool/initializeLiquidation.d.ts +2 -2
- package/dist/types/pools/lendingPool/repayToLendingPool.d.ts +2 -2
- package/dist/types/pools/lendingPool/withdrawAssetFromLendingPool.d.ts +2 -2
- package/dist/types/wallet/assets/getAllowance.d.ts +1 -1
- package/dist/wallet/assets/getAllowance.js +3 -3
- package/package.json +1 -1
|
@@ -33,9 +33,8 @@ function getLendingPoolAdapterByAddress(chainId, address) {
|
|
|
33
33
|
throw new Error("Adapter not found in config.");
|
|
34
34
|
return adaptersConfig[matchKey];
|
|
35
35
|
}
|
|
36
|
-
async function getLendingPoolContract(chainId) {
|
|
36
|
+
async function getLendingPoolContract(chainId, providerOrProvider) {
|
|
37
37
|
const lendingPoolAddress = (0, getContractAddress_1.default)(chainId, "lendingpool");
|
|
38
38
|
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
39
|
-
|
|
40
|
-
return new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
39
|
+
return new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, providerOrProvider);
|
|
41
40
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
|
-
async function borrowFromLendingPool(chainId, adapterName, amount, data) {
|
|
5
|
+
async function borrowFromLendingPool(chainId, adapterName, amount, data, signer) {
|
|
6
6
|
try {
|
|
7
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
7
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
8
8
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
9
9
|
if (!adapterAddress) {
|
|
10
10
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
5
|
// TODO: interface changed
|
|
6
|
-
async function borrowFromLendingPoolWithInsurance(chainId, adapterName, amount, data) {
|
|
6
|
+
async function borrowFromLendingPoolWithInsurance(chainId, adapterName, amount, data, signer) {
|
|
7
7
|
try {
|
|
8
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
9
9
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
10
10
|
if (!adapterAddress) {
|
|
11
11
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -10,7 +10,7 @@ async function calculateInsuranceFee(chainId, adapterName, userAddress, data, am
|
|
|
10
10
|
if (!adapterAddress) {
|
|
11
11
|
throw new Error(`Adapter ${adapterName} not found`);
|
|
12
12
|
}
|
|
13
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
13
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
14
14
|
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
15
15
|
const fee = await lendingPoolContract.calculateInsuranceFee(adapterAddress, userAddress, data, amountInWei.toString());
|
|
16
16
|
console.log(`Insurance fee: ${ethers_1.ethers.formatEther(fee)}`);
|
|
@@ -11,9 +11,9 @@ const _helpers_1 = require("./_helpers");
|
|
|
11
11
|
* @param data
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
async function closeLiquidation(chainId, adapterName, data) {
|
|
14
|
+
async function closeLiquidation(chainId, adapterName, data, signer) {
|
|
15
15
|
try {
|
|
16
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
16
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
17
17
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
18
18
|
if (!adapterAddress) {
|
|
19
19
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
5
|
// TODO: interface changed
|
|
6
|
-
async function depositAssetToLendingPool(chainId, adapterName, data) {
|
|
6
|
+
async function depositAssetToLendingPool(chainId, adapterName, data, signer) {
|
|
7
7
|
try {
|
|
8
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
9
9
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
10
10
|
if (!adapterAddress) {
|
|
11
11
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -8,7 +8,7 @@ async function depositToLendingPool(chainId, amount, signer) {
|
|
|
8
8
|
throw new Error("Wallet not connected");
|
|
9
9
|
}
|
|
10
10
|
try {
|
|
11
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
12
12
|
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
13
13
|
// const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
14
14
|
const depositTx = await lendingPoolContract.deposit(amountInWei.toString(), {
|
|
@@ -4,7 +4,7 @@ const index_1 = require("../../configs/chains/index");
|
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
5
|
async function getAdapters(chainId, provider) {
|
|
6
6
|
try {
|
|
7
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
7
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
8
8
|
const adapters = await lendingPoolContract.getAdapters();
|
|
9
9
|
const adapterConfig = index_1.configs[chainId].adapters;
|
|
10
10
|
return {
|
|
@@ -11,7 +11,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
11
11
|
*/
|
|
12
12
|
async function getEligibleUserDeposits(chainId, address, provider) {
|
|
13
13
|
try {
|
|
14
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
14
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
15
15
|
const value = await lendingPoolContract.getEligibleUserDeposits(address);
|
|
16
16
|
console.log(`Eligible user deposits: ${ethers_1.ethers.formatEther(value)}`);
|
|
17
17
|
return value;
|
|
@@ -12,9 +12,9 @@ const _helpers_1 = require("./_helpers");
|
|
|
12
12
|
* @param provider
|
|
13
13
|
* @returns The health factor of a position (0, inf)
|
|
14
14
|
*/
|
|
15
|
-
async function getHealthFactor(chainId, adapterName, userAddress, data) {
|
|
15
|
+
async function getHealthFactor(chainId, adapterName, userAddress, data, provider) {
|
|
16
16
|
try {
|
|
17
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
17
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
18
18
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
19
19
|
if (!adapterAddress) {
|
|
20
20
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -5,7 +5,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
5
5
|
const artifacts_1 = require("../../utils/artifacts");
|
|
6
6
|
async function getLendingPoolInfo(chainId, userAddress, provider) {
|
|
7
7
|
try {
|
|
8
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
9
9
|
const handleError = (operation, returnType) => (error) => {
|
|
10
10
|
if (error.code === "BAD_DATA") {
|
|
11
11
|
console.log(`BAD_DATA from ${operation} - Pool empty?`, error.messag);
|
|
@@ -71,17 +71,17 @@ async function getLendingPoolInfo(chainId, userAddress, provider) {
|
|
|
71
71
|
utilization: (Number(utilization.toString()) / 1e27).toFixed(6), // Utilization as a decimal value between 0 and 1
|
|
72
72
|
liquidityIndex: (Number(liquidityIndex.toString()) / 1e27).toFixed(6),
|
|
73
73
|
usageIndex: (Number(usageIndex.toString()) / 1e27).toFixed(6),
|
|
74
|
-
currentLiquidityRate: (Number(currentLiquidityRate.toString()) / 1e25).toFixed(2)
|
|
75
|
-
currentUsageRate: (Number(currentUsageRate.toString()) / 1e25).toFixed(2)
|
|
76
|
-
primeRate: (Number(primeRate.toString()) / 1e25).toFixed(2)
|
|
77
|
-
baseRate: (Number(baseRate.toString()) / 1e25).toFixed(2)
|
|
78
|
-
optimalRate: (Number(optimalRate.toString()) / 1e25).toFixed(2)
|
|
79
|
-
maxRate: (Number(maxRate.toString()) / 1e25).toFixed(2)
|
|
74
|
+
currentLiquidityRate: (Number(currentLiquidityRate.toString()) / 1e25).toFixed(2),
|
|
75
|
+
currentUsageRate: (Number(currentUsageRate.toString()) / 1e25).toFixed(2),
|
|
76
|
+
primeRate: (Number(primeRate.toString()) / 1e25).toFixed(2),
|
|
77
|
+
baseRate: (Number(baseRate.toString()) / 1e25).toFixed(2),
|
|
78
|
+
optimalRate: (Number(optimalRate.toString()) / 1e25).toFixed(2),
|
|
79
|
+
maxRate: (Number(maxRate.toString()) / 1e25).toFixed(2),
|
|
80
80
|
optimalUtilizationRate: (Number(optimalUtilizationRate.toString()) / 1e27).toFixed(6),
|
|
81
|
-
protocolFeeRate: (Number(protocolFeeRate.toString()) / 1e25).toFixed(2)
|
|
81
|
+
protocolFeeRate: (Number(protocolFeeRate.toString()) / 1e25).toFixed(2),
|
|
82
82
|
normalizedIncome: (Number(normalizedIncome.toString()) / 1e27).toFixed(6),
|
|
83
83
|
normalizedDebt: (Number(normalizedDebt.toString()) / 1e27).toFixed(6),
|
|
84
|
-
apy: (Number(apy.toString()) / 1e25).toFixed(2)
|
|
84
|
+
apy: (Number(apy.toString()) / 1e25).toFixed(2),
|
|
85
85
|
userRedeemable: ethers_1.ethers.formatEther(userRedeemable ?? 0n),
|
|
86
86
|
};
|
|
87
87
|
return result;
|
|
@@ -5,7 +5,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
5
5
|
// @deprecated
|
|
6
6
|
async function getLendingPoolTotalLiquidity(chainId, provider) {
|
|
7
7
|
try {
|
|
8
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
9
9
|
const reserve = (await lendingPoolContract.reserve());
|
|
10
10
|
const totalLiquidity = reserve.totalLiquidity;
|
|
11
11
|
return totalLiquidity;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const _helpers_1 = require("./_helpers");
|
|
4
4
|
async function getParameters(chainId, provider) {
|
|
5
5
|
try {
|
|
6
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
6
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
7
7
|
const [canPaybackDebt, withdrawalsPaused, liquidationThreshold, healthFactorLiquidationThreshold, liquidationGracePeriod, insuranceFee, depositFee, liquidityBufferRatio, supplyCap, borrowCap, withdrawTimelockDuration, vaultOpeningFee,] = await lendingPoolContract.parameters();
|
|
8
8
|
const parameters = {
|
|
9
9
|
canPaybackDebt,
|
|
@@ -10,9 +10,9 @@ const _helpers_1 = require("./_helpers");
|
|
|
10
10
|
* @param provider
|
|
11
11
|
* @returns The raw debt of the user on a NFT
|
|
12
12
|
*/
|
|
13
|
-
async function getPositionDebt(chainId, adapterName, userAddress, data) {
|
|
13
|
+
async function getPositionDebt(chainId, adapterName, userAddress, data, provider) {
|
|
14
14
|
try {
|
|
15
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
16
16
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
17
17
|
if (!adapterAddress) {
|
|
18
18
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -12,9 +12,9 @@ const _helpers_1 = require("./_helpers");
|
|
|
12
12
|
* @param data
|
|
13
13
|
* @returns The debt of the user on a NFT with the accured interest
|
|
14
14
|
*/
|
|
15
|
-
async function getPositionScaledDebt(chainId, adapterName, userAddress, data) {
|
|
15
|
+
async function getPositionScaledDebt(chainId, adapterName, userAddress, data, provider) {
|
|
16
16
|
try {
|
|
17
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
17
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
18
18
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
19
19
|
if (!adapterAddress) {
|
|
20
20
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -33,7 +33,7 @@ async function getPositionView(chainId, adapterName, userAddress, data, provider
|
|
|
33
33
|
if (!adapterAddress) {
|
|
34
34
|
throw new Error(`Adapter ${adapterName} not found`);
|
|
35
35
|
}
|
|
36
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
36
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
37
37
|
const position = await lendingPoolContract.getPositionView(adapterAddress, userAddress, data);
|
|
38
38
|
return transformPositionView(position);
|
|
39
39
|
}
|
|
@@ -12,7 +12,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
12
12
|
*/
|
|
13
13
|
async function getPositionsScaledDebt(chainId, address, provider) {
|
|
14
14
|
try {
|
|
15
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
16
16
|
const reward = await lendingPoolContract.getPositionsScaledDebt(address);
|
|
17
17
|
console.log(`getPositionsScaledDebt result: ${ethers_1.ethers.formatEther(reward)}`);
|
|
18
18
|
return reward;
|
|
@@ -5,7 +5,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
5
5
|
// Get the amount of RToken RAW deposit in the lending pool, without the accured interest
|
|
6
6
|
async function getRawUserDepositsInLendingPool(chainId, address, provider) {
|
|
7
7
|
try {
|
|
8
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
9
9
|
const value = await lendingPoolContract.getUserDeposits(address);
|
|
10
10
|
console.log(`User deposits in lending pool: ${ethers_1.ethers.formatEther(value)}`);
|
|
11
11
|
return value;
|
|
@@ -12,7 +12,7 @@ const _helpers_1 = require("./_helpers");
|
|
|
12
12
|
*/
|
|
13
13
|
async function getUserCollateralValue(chainId, address, provider) {
|
|
14
14
|
try {
|
|
15
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, provider);
|
|
16
16
|
const reward = await lendingPoolContract.getUserCollateralValue(address);
|
|
17
17
|
console.log(`getUserCollateralValue result: ${ethers_1.ethers.formatEther(reward)}`);
|
|
18
18
|
return reward;
|
|
@@ -8,7 +8,7 @@ async function getWithdrawRequestInfo(chainId, userAddress, signer) {
|
|
|
8
8
|
throw new Error("Wallet not connected");
|
|
9
9
|
}
|
|
10
10
|
try {
|
|
11
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
12
12
|
const request = await lendingPoolContract.withdrawTimelock(userAddress);
|
|
13
13
|
if (request[0] === 0n) {
|
|
14
14
|
return null;
|
|
@@ -9,9 +9,9 @@ const _helpers_1 = require("./_helpers");
|
|
|
9
9
|
* @param provider
|
|
10
10
|
* @returns The debt of the user
|
|
11
11
|
*/
|
|
12
|
-
async function initializeLiquidation(chainId, adapterName, userAddress, data) {
|
|
12
|
+
async function initializeLiquidation(chainId, adapterName, userAddress, data, signer) {
|
|
13
13
|
try {
|
|
14
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
14
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
15
15
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
16
16
|
if (!adapterAddress) {
|
|
17
17
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -12,7 +12,7 @@ async function openVaultPosition(chainId, signer) {
|
|
|
12
12
|
throw new Error("Wallet not connected");
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
15
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
16
16
|
// Get parameters to check vault opening fee
|
|
17
17
|
const parameters = await lendingPoolContract.parameters();
|
|
18
18
|
const vaultOpeningFee = parameters.vaultOpeningFee;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
|
-
async function repayToLendingPool(chainId, adapterName, amount, data) {
|
|
5
|
+
async function repayToLendingPool(chainId, adapterName, amount, data, signer) {
|
|
6
6
|
try {
|
|
7
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
7
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
8
8
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
9
9
|
if (!adapterAddress) {
|
|
10
10
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -8,7 +8,7 @@ async function requestWithdraw(chainId, amount, signer) {
|
|
|
8
8
|
throw new Error("Wallet not connected");
|
|
9
9
|
}
|
|
10
10
|
try {
|
|
11
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
12
12
|
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
13
13
|
// Check if withdrawals are paused
|
|
14
14
|
const parameters = await lendingPoolContract.parameters();
|
|
@@ -4,9 +4,9 @@ exports.withdrawAssetFromLendingPool = withdrawAssetFromLendingPool;
|
|
|
4
4
|
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
5
5
|
const _helpers_1 = require("./_helpers");
|
|
6
6
|
exports.default = withdrawAssetFromLendingPool;
|
|
7
|
-
async function withdrawAssetFromLendingPool(chainId, adapterName, data) {
|
|
7
|
+
async function withdrawAssetFromLendingPool(chainId, adapterName, data, signer) {
|
|
8
8
|
try {
|
|
9
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
9
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
10
10
|
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
11
11
|
if (!adapterAddress) {
|
|
12
12
|
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
@@ -6,7 +6,7 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
6
6
|
const _helpers_1 = require("./_helpers");
|
|
7
7
|
async function withdrawFromLendingPool(chainId, amount, signer) {
|
|
8
8
|
try {
|
|
9
|
-
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
9
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId, signer);
|
|
10
10
|
const rtokenAddress = (0, getContractAddress_1.getContractAddress)(chainId, "rtoken");
|
|
11
11
|
const assetABI = (0, artifacts_1.getABI)("rtoken");
|
|
12
12
|
const rTokenContract = new ethers_1.ethers.Contract(rtokenAddress, assetABI, signer);
|
package/dist/scripts/index.js
CHANGED
|
@@ -36,79 +36,57 @@ async function setup() {
|
|
|
36
36
|
rpc.provider = provider;
|
|
37
37
|
rpc.chainId = chainId;
|
|
38
38
|
// // send myself some CRVUSD
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
// 10000000n,
|
|
43
|
-
// signer.address,
|
|
44
|
-
// signer
|
|
45
|
-
// );
|
|
46
|
-
// // // set the base uri to instruxi data gateway
|
|
47
|
-
// await rpc.nfts.setBaseUri(
|
|
48
|
-
// chainId,
|
|
49
|
-
// "https://gateway-staging.instruxi.dev/api/v1/vnft/metadata/public/1/0x0000000000000000000000000000",
|
|
50
|
-
// signer
|
|
51
|
-
// );
|
|
39
|
+
await rpc.wallet.assets.mintAsset(chainId, "crvusd", 10000000n, signer.address, signer);
|
|
40
|
+
// // set the base uri to instruxi data gateway
|
|
41
|
+
await rpc.nfts.setBaseUri(chainId, "http://44.211.155.244:3000/v1/properties/", signer);
|
|
52
42
|
console.log(await rpc.pools.lendingPool.getLendingPoolInfo(chainId, signer.address, provider));
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// // //
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// // //
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// //
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// //
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// // Generate some random NFT and set price only: not purchased yet
|
|
101
|
-
// let nftIdStart = countTokens + 1;
|
|
102
|
-
// let nftIdEnd = countTokens + 10;
|
|
103
|
-
// for (let i = nftIdStart; i <= nftIdEnd; i++) {
|
|
104
|
-
// const price = Math.floor(Math.random() * (2000000 - 100000) + 100000);
|
|
105
|
-
// const tx = await housePriceContract.setHousePrice(
|
|
106
|
-
// i,
|
|
107
|
-
// parseEther(price.toString())
|
|
108
|
-
// );
|
|
109
|
-
// await tx.wait();
|
|
110
|
-
// console.log("Price set for house", i);
|
|
111
|
-
// }
|
|
43
|
+
console.log(await rpc.wallet.assets.getBalance(chainId, "rtoken", signer.address, provider));
|
|
44
|
+
console.log(await rpc.nfts.getTokensByOwner(chainId, signer.address, provider));
|
|
45
|
+
// // // set the oracle address of the RAACHousePrice. TEmporarily simulating that I AM THE ORACLE
|
|
46
|
+
await rpc.contracts.housePrices.setOracle(chainId, signer.address, signer);
|
|
47
|
+
// // // // set price for 3 houses
|
|
48
|
+
const housePriceAddress = (0, contracts_1.getContractAddress)(chainId, "raachouseprices");
|
|
49
|
+
const housePriceABI = (0, artifacts_1.getABI)("raachouseprices");
|
|
50
|
+
const housePriceContract = new ethers_1.ethers.Contract(housePriceAddress, housePriceABI, signer);
|
|
51
|
+
const raacNFTAddress = (0, contracts_1.getContractAddress)(chainId, "raacnft");
|
|
52
|
+
const raacNFTABI = (0, artifacts_1.getABI)("raacnft");
|
|
53
|
+
const raacNFTContract = new ethers_1.ethers.Contract(raacNFTAddress, raacNFTABI, signer);
|
|
54
|
+
const countTokens = 3;
|
|
55
|
+
// // // Generate 10 house prices between 100K and 2M
|
|
56
|
+
const housePrices = [];
|
|
57
|
+
for (let i = 1; i <= countTokens; i++) {
|
|
58
|
+
const price = Math.floor(Math.random() * (2000000 - 100000) + 100000);
|
|
59
|
+
housePrices.push(price);
|
|
60
|
+
}
|
|
61
|
+
// // // Mint the new properties
|
|
62
|
+
for (let i = 1; i <= countTokens; i++) {
|
|
63
|
+
const tx = await raacNFTContract.minterMint(signer.address, i);
|
|
64
|
+
await tx.wait();
|
|
65
|
+
console.log("Minted NFT", i);
|
|
66
|
+
}
|
|
67
|
+
// // set house prices
|
|
68
|
+
for (let i = 1; i <= countTokens; i++) {
|
|
69
|
+
const tx = await housePriceContract.setHousePrice(i, (0, ethers_1.parseEther)(housePrices[i - 1].toString()));
|
|
70
|
+
await tx.wait();
|
|
71
|
+
console.log("Price set for house", i);
|
|
72
|
+
}
|
|
73
|
+
// // confirm the house prices are set
|
|
74
|
+
for (let i = 1; i <= countTokens; i++) {
|
|
75
|
+
const price = await rpc.nfts.getHousePrice(chainId, i, provider);
|
|
76
|
+
console.log("Price for house", i, price);
|
|
77
|
+
if (price !== housePrices[i - 1].toString() + ".0") {
|
|
78
|
+
throw new Error("Price not set correctly");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Generate some random NFT and set price only: not purchased yet
|
|
82
|
+
let nftIdStart = countTokens + 1;
|
|
83
|
+
let nftIdEnd = countTokens + 10;
|
|
84
|
+
for (let i = nftIdStart; i <= nftIdEnd; i++) {
|
|
85
|
+
const price = Math.floor(Math.random() * (2000000 - 100000) + 100000);
|
|
86
|
+
const tx = await housePriceContract.setHousePrice(i, (0, ethers_1.parseEther)(price.toString()));
|
|
87
|
+
await tx.wait();
|
|
88
|
+
console.log("Price set for house", i);
|
|
89
|
+
}
|
|
112
90
|
}
|
|
113
91
|
const execute = async () => {
|
|
114
92
|
const provider = await getProvider();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BytesLike, ethers } from "ethers";
|
|
1
|
+
import { BytesLike, ethers, Provider, Signer } from "ethers";
|
|
2
2
|
import { ChainId } from "../../configs/chains";
|
|
3
3
|
import { Adapter } from "../../configs/chains/chain";
|
|
4
4
|
import { LendingPool } from "../../typechain-types";
|
|
@@ -7,4 +7,4 @@ export declare function decodeERC721(data: BytesLike): ethers.Result;
|
|
|
7
7
|
export declare function encodeERC20(amount: string): string;
|
|
8
8
|
export declare function decodeERC20(data: BytesLike): bigint;
|
|
9
9
|
export declare function getLendingPoolAdapterByAddress(chainId: ChainId, address: string): Adapter;
|
|
10
|
-
export declare function getLendingPoolContract(chainId: ChainId): Promise<LendingPool>;
|
|
10
|
+
export declare function getLendingPoolContract(chainId: ChainId, providerOrProvider?: Provider | Signer): Promise<LendingPool>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BigNumberish, BytesLike } from "ethers";
|
|
4
|
-
declare function borrowFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: BigNumberish, data: BytesLike): Promise<boolean>;
|
|
3
|
+
import { BigNumberish, BytesLike, Signer } from "ethers";
|
|
4
|
+
declare function borrowFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: BigNumberish, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
5
5
|
export default borrowFromLendingPool;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BigNumberish, BytesLike } from "ethers";
|
|
1
|
+
import { BigNumberish, 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): Promise<boolean>;
|
|
4
|
+
declare function borrowFromLendingPoolWithInsurance(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: BigNumberish, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
5
5
|
export default borrowFromLendingPoolWithInsurance;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BytesLike } from "ethers";
|
|
3
|
+
import { BytesLike, Signer } from "ethers";
|
|
4
4
|
/**
|
|
5
5
|
* @description Close the liqudation after the debt has been paid
|
|
6
6
|
* @param chainId
|
|
@@ -9,5 +9,5 @@ import { BytesLike } from "ethers";
|
|
|
9
9
|
* @param data
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
declare function closeLiquidation(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike): Promise<boolean>;
|
|
12
|
+
declare function closeLiquidation(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
13
13
|
export default closeLiquidation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BytesLike } from "ethers";
|
|
1
|
+
import { BytesLike, Signer } from "ethers";
|
|
2
2
|
import { ChainId } from "../../configs/chains";
|
|
3
3
|
import { LendingPoolAdapterId } from "./types";
|
|
4
|
-
declare function depositAssetToLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike): Promise<boolean>;
|
|
4
|
+
declare function depositAssetToLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
5
5
|
export default depositAssetToLendingPool;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BytesLike } from "ethers";
|
|
1
|
+
import { BytesLike, Provider } from "ethers";
|
|
2
2
|
import { ChainId } from "../../configs/chains/index";
|
|
3
3
|
import { LendingPoolAdapterId } from "./types";
|
|
4
4
|
/**
|
|
@@ -10,4 +10,4 @@ import { LendingPoolAdapterId } from "./types";
|
|
|
10
10
|
* @param provider
|
|
11
11
|
* @returns The health factor of a position (0, inf)
|
|
12
12
|
*/
|
|
13
|
-
export default function getHealthFactor(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike): Promise<bigint>;
|
|
13
|
+
export default function getHealthFactor(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike, provider: Provider): Promise<bigint>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BytesLike } from "ethers";
|
|
3
|
+
import { BytesLike, Provider } from "ethers";
|
|
4
4
|
/**
|
|
5
5
|
* @description Get the raw debt of the user on a NFT. Equivant to the original amount borrowed on NFT.
|
|
6
6
|
* @param chainId
|
|
@@ -8,5 +8,5 @@ import { BytesLike } from "ethers";
|
|
|
8
8
|
* @param provider
|
|
9
9
|
* @returns The raw debt of the user on a NFT
|
|
10
10
|
*/
|
|
11
|
-
declare function getPositionDebt(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike): Promise<bigint>;
|
|
11
|
+
declare function getPositionDebt(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike, provider: Provider): Promise<bigint>;
|
|
12
12
|
export default getPositionDebt;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BytesLike } from "ethers";
|
|
3
|
+
import { BytesLike, Provider } from "ethers";
|
|
4
4
|
/**
|
|
5
5
|
* @description Get the scaled debt of the user on a NFT (contains the accured interest)
|
|
6
6
|
* @param chainId
|
|
@@ -10,5 +10,5 @@ import { BytesLike } from "ethers";
|
|
|
10
10
|
* @param data
|
|
11
11
|
* @returns The debt of the user on a NFT with the accured interest
|
|
12
12
|
*/
|
|
13
|
-
declare function getPositionScaledDebt(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike): Promise<bigint>;
|
|
13
|
+
declare function getPositionScaledDebt(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike, provider: Provider): Promise<bigint>;
|
|
14
14
|
export default getPositionScaledDebt;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BytesLike } from "ethers";
|
|
3
|
+
import { BytesLike, Signer } from "ethers";
|
|
4
4
|
/**
|
|
5
5
|
* @description Get the sum of all the scaled debts of a user over all NFTs
|
|
6
6
|
* @param chainId
|
|
@@ -8,5 +8,5 @@ import { BytesLike } from "ethers";
|
|
|
8
8
|
* @param provider
|
|
9
9
|
* @returns The debt of the user
|
|
10
10
|
*/
|
|
11
|
-
declare function initializeLiquidation(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike): Promise<boolean>;
|
|
11
|
+
declare function initializeLiquidation(chainId: ChainId, adapterName: LendingPoolAdapterId, userAddress: string, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
12
12
|
export default initializeLiquidation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChainId } from "../../configs/chains";
|
|
2
2
|
import { LendingPoolAdapterId } from "./types";
|
|
3
|
-
import { BytesLike } from "ethers";
|
|
4
|
-
declare function repayToLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: bigint, data: BytesLike): Promise<boolean>;
|
|
3
|
+
import { BytesLike, Signer } from "ethers";
|
|
4
|
+
declare function repayToLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, amount: bigint, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
5
5
|
export default repayToLendingPool;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BytesLike } from "ethers";
|
|
1
|
+
import { BytesLike, Signer } from "ethers";
|
|
2
2
|
import { ChainId } from "../../configs/chains/index";
|
|
3
3
|
import { LendingPoolAdapterId } from "./types";
|
|
4
4
|
export default withdrawAssetFromLendingPool;
|
|
5
|
-
export declare function withdrawAssetFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike): Promise<boolean>;
|
|
5
|
+
export declare function withdrawAssetFromLendingPool(chainId: ChainId, adapterName: LendingPoolAdapterId, data: BytesLike, signer: Signer): Promise<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from "ethers";
|
|
2
2
|
import { AssetType } from "../../utils/artifacts";
|
|
3
3
|
import { ChainId } from "../../configs/chains/index";
|
|
4
|
-
declare function getAllowance(chainId: ChainId, assetId: AssetType, owner: string, spender: string, provider: Provider): Promise<
|
|
4
|
+
declare function getAllowance(chainId: ChainId, assetId: AssetType, owner: string, spender: string, provider: Provider): Promise<bigint>;
|
|
5
5
|
export default getAllowance;
|
|
@@ -6,7 +6,7 @@ async function getAllowance(chainId, assetId, owner, spender, provider) {
|
|
|
6
6
|
try {
|
|
7
7
|
if (assetId === "eth") {
|
|
8
8
|
// ETH doesn't have an allowance concept, return max uint256 value ?
|
|
9
|
-
return ethers_1.ethers.
|
|
9
|
+
return ethers_1.ethers.MaxUint256;
|
|
10
10
|
}
|
|
11
11
|
const ALLOWANCE_ABI = [
|
|
12
12
|
"function allowance(address,address) view returns (uint256)",
|
|
@@ -14,13 +14,13 @@ async function getAllowance(chainId, assetId, owner, spender, provider) {
|
|
|
14
14
|
const contractAddress = (0, contracts_1.getContractAddress)(chainId, assetId);
|
|
15
15
|
const contract = new ethers_1.ethers.Contract(contractAddress, ALLOWANCE_ABI, provider);
|
|
16
16
|
const allowance = await contract.allowance(owner, spender);
|
|
17
|
-
return
|
|
17
|
+
return allowance;
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
console.error(`Error getting allowance for asset ${assetId}:`, error);
|
|
21
21
|
console.log({ assetId, owner, spender });
|
|
22
22
|
console.log(error);
|
|
23
|
-
return
|
|
23
|
+
return 0n;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
exports.default = getAllowance;
|