@raac/rpc 1.1.0-beta.6 → 1.1.0-beta.8
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/RPCLibrary.js +14 -0
- package/dist/artifacts/core/tokens/RWAIndexToken.sol/RWAIndexToken.json +591 -0
- package/dist/configs/chains/11155111.json +8 -3
- package/dist/configs/chains/17000.json +16 -17
- package/dist/configs/chains/8453.json +32 -33
- package/dist/configs/createConfig.js +3 -3
- package/dist/pools/lendingPool/_helpers.js +12 -0
- package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.js +1 -1
- package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterInfo.js +1 -1
- package/dist/pools/lendingPool/adapters/erc721/getERC721AdapterDeposits.js +1 -1
- package/dist/pools/lendingPool/adapters/erc721/getERC721AdapterInfo.js +1 -1
- package/dist/pools/lendingPool/borrowFromLendingPool.js +11 -14
- package/dist/pools/lendingPool/borrowFromLendingPoolWithInsurance.js +10 -29
- package/dist/pools/lendingPool/calculateInsuranceFee.js +11 -8
- package/dist/pools/lendingPool/closeLiquidation.js +15 -14
- package/dist/pools/lendingPool/depositAssetToLendingPool.js +11 -49
- package/dist/pools/lendingPool/depositToLendingPool.js +2 -5
- package/dist/pools/lendingPool/getAdapterAddress.js +44 -0
- package/dist/pools/lendingPool/getAdapters.js +2 -6
- package/dist/pools/lendingPool/getEligibleUserDeposits.js +2 -5
- package/dist/pools/lendingPool/getHealthFactor.js +15 -13
- package/dist/pools/lendingPool/getLendingPoolInfo.js +6 -12
- package/dist/pools/lendingPool/getLendingPoolTotalLiquidity.js +2 -6
- package/dist/pools/lendingPool/getParameters.js +2 -6
- package/dist/pools/lendingPool/getPositionDebt.js +11 -11
- package/dist/pools/lendingPool/getPositionScaledDebt.js +15 -13
- package/dist/pools/lendingPool/getPositionView.js +13 -10
- package/dist/pools/lendingPool/getPositionsScaledDebt.js +2 -5
- package/dist/pools/lendingPool/getRawUserDepositsInLendingPool.js +2 -5
- package/dist/pools/lendingPool/getUserCollateralValue.js +2 -5
- package/dist/pools/lendingPool/getWithdrawRequestInfo.js +25 -0
- package/dist/pools/lendingPool/initializeLiquidation.js +12 -12
- package/dist/pools/lendingPool/openVaultPosition.js +42 -0
- package/dist/pools/lendingPool/repayToLendingPool.js +11 -14
- package/dist/pools/lendingPool/requestWithdraw.js +28 -0
- package/dist/pools/lendingPool/types.js +2 -0
- package/dist/pools/lendingPool/withdrawAssetFromLendingPool.js +15 -17
- package/dist/pools/lendingPool/withdrawFromLendingPool.js +3 -4
- package/dist/pools/rwaVault/_helpers.js +41 -0
- package/dist/pools/rwaVault/adapters/erc20/getERC20VaultAdapterAssetValue.js +2 -2
- package/dist/pools/rwaVault/adapters/erc20/getERC20VaultAdapterInfo.js +2 -2
- package/dist/pools/rwaVault/adapters/erc20/getERC20VaultAdapterTotalValue.js +2 -2
- package/dist/pools/rwaVault/adapters/erc721/getERC721VaultAdapterAssetValue.js +1 -1
- package/dist/pools/rwaVault/adapters/erc721/getERC721VaultAdapterDeposits.js +2 -2
- package/dist/pools/rwaVault/adapters/erc721/getERC721VaultAdapterInfo.js +2 -2
- package/dist/pools/rwaVault/adapters/erc721/getERC721VaultAdapterTotalValue.js +2 -2
- package/dist/pools/rwaVault/depositToRWAVault.js +2 -6
- package/dist/pools/rwaVault/getAdapterAddress.js +43 -0
- package/dist/pools/rwaVault/getAdapters.js +20 -0
- package/dist/pools/rwaVault/getNextRandomNFT.js +2 -6
- package/dist/pools/rwaVault/getRWAVaultInfo.js +2 -6
- package/dist/pools/rwaVault/redeemNFTFromRWAVault.js +2 -6
- package/dist/pools/rwaVault/requestRandomSeed.js +2 -6
- package/dist/pools/rwaVault/types.js +2 -0
- package/dist/scripts/index.js +169 -219
- package/dist/types/RPCLibrary.d.ts +15 -1
- package/dist/types/configs/createConfig.d.ts +1 -1
- package/dist/types/pools/lendingPool/_helpers.d.ts +2 -0
- package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.d.ts +1 -2
- package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterInfo.d.ts +1 -2
- package/dist/types/pools/lendingPool/adapters/erc721/getERC721AdapterDeposits.d.ts +1 -2
- package/dist/types/pools/lendingPool/adapters/erc721/getERC721AdapterInfo.d.ts +1 -2
- package/dist/types/pools/lendingPool/borrowFromLendingPool.d.ts +4 -3
- package/dist/types/pools/lendingPool/borrowFromLendingPoolWithInsurance.d.ts +4 -3
- package/dist/types/pools/lendingPool/calculateInsuranceFee.d.ts +2 -1
- package/dist/types/pools/lendingPool/closeLiquidation.d.ts +7 -5
- package/dist/types/pools/lendingPool/depositAssetToLendingPool.d.ts +3 -2
- package/dist/types/pools/lendingPool/getAdapterAddress.d.ts +16 -0
- package/dist/types/pools/lendingPool/getHealthFactor.d.ts +6 -4
- package/dist/types/pools/lendingPool/getPositionDebt.d.ts +4 -3
- package/dist/types/pools/lendingPool/getPositionScaledDebt.d.ts +8 -5
- package/dist/types/pools/lendingPool/getPositionView.d.ts +5 -12
- package/dist/types/pools/lendingPool/getWithdrawRequestInfo.d.ts +8 -0
- package/dist/types/pools/lendingPool/initializeLiquidation.d.ts +4 -3
- package/dist/types/pools/lendingPool/openVaultPosition.d.ts +4 -0
- package/dist/types/pools/lendingPool/repayToLendingPool.d.ts +4 -3
- package/dist/types/pools/lendingPool/requestWithdraw.d.ts +4 -0
- package/dist/types/pools/lendingPool/types.d.ts +7 -0
- package/dist/types/pools/lendingPool/withdrawAssetFromLendingPool.d.ts +3 -2
- package/dist/types/pools/rwaVault/_helpers.d.ts +10 -0
- package/dist/types/pools/rwaVault/adapters/erc20/getERC20VaultAdapterAssetValue.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc20/getERC20VaultAdapterInfo.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc20/getERC20VaultAdapterTotalValue.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc721/getERC721VaultAdapterAssetValue.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc721/getERC721VaultAdapterDeposits.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc721/getERC721VaultAdapterInfo.d.ts +1 -2
- package/dist/types/pools/rwaVault/adapters/erc721/getERC721VaultAdapterTotalValue.d.ts +1 -2
- package/dist/types/pools/rwaVault/depositToRWAVault.d.ts +3 -2
- package/dist/types/pools/rwaVault/getAdapterAddress.d.ts +16 -0
- package/dist/types/pools/rwaVault/getAdapters.d.ts +8 -0
- package/dist/types/pools/rwaVault/redeemNFTFromRWAVault.d.ts +2 -2
- package/dist/types/pools/rwaVault/requestRandomSeed.d.ts +2 -2
- package/dist/types/pools/rwaVault/types.d.ts +7 -0
- package/dist/types/scripts/index.d.ts +1 -0
- package/dist/types/utils/artifacts.d.ts +48 -81
- package/dist/types/wallet/assets/getBalance.d.ts +5 -1
- package/dist/utils/artifacts.js +3 -3
- package/dist/wallet/assets/getBalance.js +9 -3
- package/package.json +1 -1
- package/dist/artifacts/core/tokens/IndexToken.sol/IndexToken.json +0 -770
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
/**
|
|
7
6
|
* @description Total amount of RToken + DEToken = total crvUSD they put in the system so far. How much they have contributed to the system.
|
|
8
7
|
* @param chainId
|
|
@@ -12,9 +11,7 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
12
11
|
*/
|
|
13
12
|
async function getEligibleUserDeposits(chainId, address, provider) {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
17
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
14
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
18
15
|
const value = await lendingPoolContract.getEligibleUserDeposits(address);
|
|
19
16
|
console.log(`Eligible user deposits: ${ethers_1.ethers.formatEther(value)}`);
|
|
20
17
|
return value;
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.default = getHealthFactor;
|
|
4
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
6
|
/**
|
|
7
7
|
* @description Get the health factor of a NFT position -> factor < 1 : undercollateralized.
|
|
8
8
|
* @param chainId
|
|
9
|
-
* @param
|
|
9
|
+
* @param adapterName
|
|
10
|
+
* @param userAddress
|
|
11
|
+
* @param data
|
|
10
12
|
* @param provider
|
|
11
13
|
* @returns The health factor of a position (0, inf)
|
|
12
14
|
*/
|
|
13
|
-
async function getHealthFactor(chainId,
|
|
15
|
+
async function getHealthFactor(chainId, adapterName, userAddress, data) {
|
|
14
16
|
try {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
18
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
19
|
+
if (!adapterAddress) {
|
|
20
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
21
|
+
}
|
|
22
|
+
const healthFactor = await lendingPoolContract.calculateHealthFactor(adapterAddress, userAddress, data);
|
|
23
|
+
return healthFactor;
|
|
21
24
|
}
|
|
22
25
|
catch (error) {
|
|
23
|
-
console.error("Error
|
|
26
|
+
console.error("Error getting health factor:", error);
|
|
24
27
|
throw error;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
exports.default = getHealthFactor;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
4
|
+
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
|
|
9
|
-
const abi = (0, artifacts_1.getABI)("lendingpool");
|
|
10
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, abi, provider);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
11
9
|
const handleError = (operation, returnType) => (error) => {
|
|
12
10
|
if (error.code === "BAD_DATA") {
|
|
13
|
-
console.log(`BAD_DATA from ${operation} - Pool empty?`, error.
|
|
11
|
+
console.log(`BAD_DATA from ${operation} - Pool empty?`, error.messag);
|
|
14
12
|
return returnType || null;
|
|
15
13
|
}
|
|
16
14
|
throw error;
|
|
@@ -18,14 +16,9 @@ async function getLendingPoolInfo(chainId, userAddress, provider) {
|
|
|
18
16
|
const [reserve, rateData, normalizedIncome, normalizedDebt] = await Promise.all([
|
|
19
17
|
lendingPoolContract.reserve().catch(handleError("reserve")),
|
|
20
18
|
lendingPoolContract.rateData().catch(handleError("rateData")),
|
|
21
|
-
lendingPoolContract
|
|
22
|
-
|
|
23
|
-
.catch(handleError("getNormalizedIncome", 0n)),
|
|
24
|
-
lendingPoolContract
|
|
25
|
-
.getNormalizedDebt()
|
|
26
|
-
.catch(handleError("getNormalizedDebt", 0n)),
|
|
19
|
+
lendingPoolContract.getNormalizedIncome().catch(handleError("getNormalizedIncome", 0n)),
|
|
20
|
+
lendingPoolContract.getNormalizedDebt().catch(handleError("getNormalizedDebt", 0n)),
|
|
27
21
|
]);
|
|
28
|
-
console.log(reserve);
|
|
29
22
|
// Extract data from reserve
|
|
30
23
|
const totalLiquidity = reserve?.totalLiquidity ?? 0n;
|
|
31
24
|
const totalUsage = reserve?.totalUsage ?? 0n;
|
|
@@ -39,6 +32,7 @@ async function getLendingPoolInfo(chainId, userAddress, provider) {
|
|
|
39
32
|
// Extract rate data
|
|
40
33
|
const currentLiquidityRate = rateData?.currentLiquidityRate ?? 0n;
|
|
41
34
|
const currentUsageRate = rateData?.currentUsageRate ?? 0n;
|
|
35
|
+
// why is prime rate 0?
|
|
42
36
|
const primeRate = rateData?.primeRate ?? 0n;
|
|
43
37
|
const baseRate = rateData?.baseRate ?? 0n;
|
|
44
38
|
const optimalRate = rateData?.optimalRate ?? 0n;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const contracts_1 = require("../../utils/contracts");
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
3
|
+
const _helpers_1 = require("./_helpers");
|
|
6
4
|
// The lending pool reserve contains the total liquidity of the lending pool. see getLendingPooInfo.ts
|
|
7
5
|
// @deprecated
|
|
8
6
|
async function getLendingPoolTotalLiquidity(chainId, provider) {
|
|
9
7
|
try {
|
|
10
|
-
const
|
|
11
|
-
const abi = (0, artifacts_1.getABI)("lendingpool");
|
|
12
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, abi, provider);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
13
9
|
const reserve = (await lendingPoolContract.reserve());
|
|
14
10
|
const totalLiquidity = reserve.totalLiquidity;
|
|
15
11
|
return totalLiquidity;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const getContractAddress_1 = require("../../contracts/getContractAddress");
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
3
|
+
const _helpers_1 = require("./_helpers");
|
|
6
4
|
async function getParameters(chainId, provider) {
|
|
7
5
|
try {
|
|
8
|
-
const
|
|
9
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
10
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
6
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
11
7
|
const [canPaybackDebt, withdrawalsPaused, liquidationThreshold, healthFactorLiquidationThreshold, liquidationGracePeriod, insuranceFee, depositFee, liquidityBufferRatio, supplyCap, borrowCap, withdrawTimelockDuration, vaultOpeningFee,] = await lendingPoolContract.parameters();
|
|
12
8
|
const parameters = {
|
|
13
9
|
canPaybackDebt,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
// TODO: interface changed
|
|
7
6
|
/**
|
|
8
7
|
* @description Get the raw debt of the user on a NFT. Equivant to the original amount borrowed on NFT.
|
|
@@ -11,17 +10,18 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
11
10
|
* @param provider
|
|
12
11
|
* @returns The raw debt of the user on a NFT
|
|
13
12
|
*/
|
|
14
|
-
async function getPositionDebt(chainId,
|
|
13
|
+
async function getPositionDebt(chainId, adapterName, userAddress, data) {
|
|
15
14
|
try {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
16
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
17
|
+
if (!adapterAddress) {
|
|
18
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
19
|
+
}
|
|
20
|
+
const debt = await lendingPoolContract.getPositionDebt(adapterAddress, userAddress, data);
|
|
21
|
+
return debt;
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
|
-
console.error("Error
|
|
24
|
+
console.error("Error getting position debt:", error);
|
|
25
25
|
throw error;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
// TODO: interface changed
|
|
7
6
|
/**
|
|
8
7
|
* @description Get the scaled debt of the user on a NFT (contains the accured interest)
|
|
9
8
|
* @param chainId
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
9
|
+
* @param lendingPoolAddress
|
|
10
|
+
* @param adapterName
|
|
11
|
+
* @param userAddress
|
|
12
|
+
* @param data
|
|
12
13
|
* @returns The debt of the user on a NFT with the accured interest
|
|
13
14
|
*/
|
|
14
|
-
async function getPositionScaledDebt(chainId,
|
|
15
|
+
async function getPositionScaledDebt(chainId, adapterName, userAddress, data) {
|
|
15
16
|
try {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
18
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
19
|
+
if (!adapterAddress) {
|
|
20
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
21
|
+
}
|
|
22
|
+
const scaledDebt = await lendingPoolContract.getPositionScaledDebt(adapterAddress, userAddress, data);
|
|
23
|
+
return scaledDebt;
|
|
22
24
|
}
|
|
23
25
|
catch (error) {
|
|
24
|
-
console.error("Error
|
|
26
|
+
console.error("Error getting position scaled debt:", error);
|
|
25
27
|
throw error;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformPositionView = transformPositionView;
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
6
|
+
const _helpers_1 = require("./_helpers");
|
|
7
7
|
// TODO: interface changed
|
|
8
8
|
function transformPositionView(positionView) {
|
|
9
9
|
return {
|
|
@@ -21,18 +21,21 @@ function transformPositionView(positionView) {
|
|
|
21
21
|
/**
|
|
22
22
|
* @description Return all the information about a NFT position
|
|
23
23
|
* @param chainId
|
|
24
|
-
* @param
|
|
24
|
+
* @param adapterName
|
|
25
|
+
* @param userAddress
|
|
26
|
+
* @param data
|
|
25
27
|
* @param provider
|
|
26
28
|
* @returns All information about a NFT position
|
|
27
29
|
*/
|
|
28
|
-
async function getPositionView(chainId,
|
|
30
|
+
async function getPositionView(chainId, adapterName, userAddress, data, provider) {
|
|
29
31
|
try {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
33
|
+
if (!adapterAddress) {
|
|
34
|
+
throw new Error(`Adapter ${adapterName} not found`);
|
|
35
|
+
}
|
|
36
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
37
|
+
const position = await lendingPoolContract.getPositionView(adapterAddress, userAddress, data);
|
|
38
|
+
return transformPositionView(position);
|
|
36
39
|
}
|
|
37
40
|
catch (error) {
|
|
38
41
|
console.error("Error in getPositionView:", error);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
// TODO: interface changed
|
|
7
6
|
/**
|
|
8
7
|
* @description Get the sum of all the scaled debts of a user over all NFTs
|
|
@@ -13,9 +12,7 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
13
12
|
*/
|
|
14
13
|
async function getPositionsScaledDebt(chainId, address, provider) {
|
|
15
14
|
try {
|
|
16
|
-
const
|
|
17
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
18
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
19
16
|
const reward = await lendingPoolContract.getPositionsScaledDebt(address);
|
|
20
17
|
console.log(`getPositionsScaledDebt result: ${ethers_1.ethers.formatEther(reward)}`);
|
|
21
18
|
return reward;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
// Get the amount of RToken RAW deposit in the lending pool, without the accured interest
|
|
7
6
|
async function getRawUserDepositsInLendingPool(chainId, address, provider) {
|
|
8
7
|
try {
|
|
9
|
-
const
|
|
10
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
11
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
12
9
|
const value = await lendingPoolContract.getUserDeposits(address);
|
|
13
10
|
console.log(`User deposits in lending pool: ${ethers_1.ethers.formatEther(value)}`);
|
|
14
11
|
return value;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
// TODO: interface changed: not efficient
|
|
7
6
|
/**
|
|
8
7
|
* @description Sum of the prices of all the NFTS
|
|
@@ -13,9 +12,7 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
13
12
|
*/
|
|
14
13
|
async function getUserCollateralValue(chainId, address, provider) {
|
|
15
14
|
try {
|
|
16
|
-
const
|
|
17
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
18
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
19
16
|
const reward = await lendingPoolContract.getUserCollateralValue(address);
|
|
20
17
|
console.log(`getUserCollateralValue result: ${ethers_1.ethers.formatEther(reward)}`);
|
|
21
18
|
return reward;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWithdrawRequestInfo = getWithdrawRequestInfo;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
async function getWithdrawRequestInfo(chainId, userAddress, signer) {
|
|
7
|
+
if (!signer) {
|
|
8
|
+
throw new Error("Wallet not connected");
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
12
|
+
const request = await lendingPoolContract.withdrawTimelock(userAddress);
|
|
13
|
+
if (request[0] === 0n) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
amount: ethers_1.ethers.formatEther(request[0]),
|
|
18
|
+
readyAt: Number(request[1])
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error("Error in getWithdrawRequestInfo:", error);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
6
5
|
/**
|
|
7
6
|
* @description Get the sum of all the scaled debts of a user over all NFTs
|
|
8
7
|
* @param chainId
|
|
@@ -10,18 +9,19 @@ const artifacts_1 = require("../../utils/artifacts");
|
|
|
10
9
|
* @param provider
|
|
11
10
|
* @returns The debt of the user
|
|
12
11
|
*/
|
|
13
|
-
async function initializeLiquidation(chainId,
|
|
12
|
+
async function initializeLiquidation(chainId, adapterName, userAddress, data) {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
16
|
+
if (!adapterAddress) {
|
|
17
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
18
|
+
}
|
|
19
|
+
const tx = await lendingPoolContract.initiateLiquidation(adapterAddress, userAddress, data);
|
|
20
|
+
const receipt = await tx.wait();
|
|
21
|
+
return receipt.status === 1;
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
|
-
console.error("Error
|
|
24
|
+
console.error("Error initializing liquidation:", error);
|
|
25
25
|
throw error;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const checkAllowance_1 = __importDefault(require("../../methods/commons/checkAllowance"));
|
|
8
|
+
const approveAsset_1 = __importDefault(require("../../wallet/assets/approveAsset"));
|
|
9
|
+
const _helpers_1 = require("./_helpers");
|
|
10
|
+
async function openVaultPosition(chainId, signer) {
|
|
11
|
+
if (!signer) {
|
|
12
|
+
throw new Error("Wallet not connected");
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
16
|
+
// Get parameters to check vault opening fee
|
|
17
|
+
const parameters = await lendingPoolContract.parameters();
|
|
18
|
+
const vaultOpeningFee = parameters.vaultOpeningFee;
|
|
19
|
+
if (vaultOpeningFee === 0n) {
|
|
20
|
+
throw new Error("Vault opening fee is not set");
|
|
21
|
+
}
|
|
22
|
+
// Check if user has approved the fee
|
|
23
|
+
const userAddress = await signer.getAddress();
|
|
24
|
+
const allowance = await (0, checkAllowance_1.default)(chainId, "crvusd", userAddress, await lendingPoolContract.getAddress(), signer.provider);
|
|
25
|
+
// If allowance is less than the fee, approve it
|
|
26
|
+
if (allowance < vaultOpeningFee) {
|
|
27
|
+
await (0, approveAsset_1.default)(chainId, "crvusd", await lendingPoolContract.getAddress(), vaultOpeningFee.toString(), signer);
|
|
28
|
+
console.log(`Approved ${ethers_1.ethers.formatEther(vaultOpeningFee)} crvUSD for vault opening fee`);
|
|
29
|
+
}
|
|
30
|
+
// Open the vault position
|
|
31
|
+
const tx = await lendingPoolContract.openVaultPosition();
|
|
32
|
+
const receipt = await tx.wait();
|
|
33
|
+
console.log("Vault position opened successfully");
|
|
34
|
+
console.log(`Transaction hash: ${receipt?.hash}`);
|
|
35
|
+
return receipt;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("Error in openVaultPosition:", error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = openVaultPosition;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
async function repayToLendingPool(chainId, adapter, data, amount, signer) {
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
5
|
+
async function repayToLendingPool(chainId, adapterName, amount, data) {
|
|
7
6
|
try {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const tx = await lendingPoolContract.repay(
|
|
7
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
8
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
9
|
+
if (!adapterAddress) {
|
|
10
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
11
|
+
}
|
|
12
|
+
const tx = await lendingPoolContract.repay(adapterAddress, data, amount);
|
|
14
13
|
const receipt = await tx.wait();
|
|
15
|
-
|
|
16
|
-
console.log(`Transaction hash: ${receipt?.hash}`);
|
|
17
|
-
return receipt;
|
|
14
|
+
return receipt.status === 1;
|
|
18
15
|
}
|
|
19
16
|
catch (error) {
|
|
20
|
-
console.error("Error
|
|
17
|
+
console.error("Error repaying to lending pool:", error);
|
|
21
18
|
throw error;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestWithdraw = requestWithdraw;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
async function requestWithdraw(chainId, amount, signer) {
|
|
7
|
+
if (!signer) {
|
|
8
|
+
throw new Error("Wallet not connected");
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
12
|
+
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
13
|
+
// Check if withdrawals are paused
|
|
14
|
+
const parameters = await lendingPoolContract.parameters();
|
|
15
|
+
if (parameters.withdrawalsPaused) {
|
|
16
|
+
throw new Error("Withdrawals are currently paused");
|
|
17
|
+
}
|
|
18
|
+
const tx = await lendingPoolContract.requestWithdraw(amountInWei);
|
|
19
|
+
const receipt = await tx.wait();
|
|
20
|
+
console.log(`Withdrawal request for ${amount} submitted successfully`);
|
|
21
|
+
console.log(`Transaction hash: ${receipt?.hash}`);
|
|
22
|
+
return receipt;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error("Error in requestWithdraw:", error);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
throw new Error("Wallet not connected");
|
|
9
|
-
}
|
|
3
|
+
exports.withdrawAssetFromLendingPool = withdrawAssetFromLendingPool;
|
|
4
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
exports.default = withdrawAssetFromLendingPool;
|
|
7
|
+
async function withdrawAssetFromLendingPool(chainId, adapterName, data) {
|
|
10
8
|
try {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
10
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
11
|
+
if (!adapterAddress) {
|
|
12
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
13
|
+
}
|
|
14
|
+
const tx = await lendingPoolContract.withdrawAsset(adapterAddress, data);
|
|
15
|
+
const receipt = await tx.wait();
|
|
16
|
+
return receipt.status === 1;
|
|
18
17
|
}
|
|
19
18
|
catch (error) {
|
|
20
|
-
console.error("Error withdrawing
|
|
21
|
-
throw
|
|
19
|
+
console.error("Error withdrawing asset from lending pool:", error);
|
|
20
|
+
throw error;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
exports.default = withdrawAssetFromLendingPool;
|
|
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const getContractAddress_1 = require("../../contracts/getContractAddress");
|
|
5
5
|
const artifacts_1 = require("../../utils/artifacts");
|
|
6
|
+
const _helpers_1 = require("./_helpers");
|
|
6
7
|
async function withdrawFromLendingPool(chainId, amount, signer) {
|
|
7
8
|
try {
|
|
8
|
-
const
|
|
9
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
9
10
|
const rtokenAddress = (0, getContractAddress_1.getContractAddress)(chainId, "rtoken");
|
|
10
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
11
11
|
const assetABI = (0, artifacts_1.getABI)("rtoken");
|
|
12
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, signer);
|
|
13
12
|
const rTokenContract = new ethers_1.ethers.Contract(rtokenAddress, assetABI, signer);
|
|
14
13
|
const amountInWei = ethers_1.ethers.parseEther(amount.toString());
|
|
15
14
|
// const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
@@ -17,7 +16,7 @@ async function withdrawFromLendingPool(chainId, amount, signer) {
|
|
|
17
16
|
if (userBalance < parseFloat(amount)) {
|
|
18
17
|
throw new Error(`Insufficient rToken balance. Available: ${ethers_1.ethers.formatEther(userBalance)}, Requested: ${ethers_1.ethers.formatEther(amount)}`);
|
|
19
18
|
}
|
|
20
|
-
const approveTx = await rTokenContract.approve(
|
|
19
|
+
const approveTx = await rTokenContract.approve(await lendingPoolContract.getAddress(), amountInWei);
|
|
21
20
|
await approveTx.wait();
|
|
22
21
|
console.log(`Approved LendingPool to spend ${amount} rToken`);
|
|
23
22
|
// const withdraw = await lendingPoolContract.withdraw(amountInWei.toString(), {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encodeERC721 = encodeERC721;
|
|
7
|
+
exports.decodeERC721 = decodeERC721;
|
|
8
|
+
exports.encodeERC20 = encodeERC20;
|
|
9
|
+
exports.decodeERC20 = decodeERC20;
|
|
10
|
+
exports.getRWAVaultAdapterByAddress = getRWAVaultAdapterByAddress;
|
|
11
|
+
exports.getRWAVaultContract = getRWAVaultContract;
|
|
12
|
+
const ethers_1 = require("ethers");
|
|
13
|
+
const chains_1 = require("../../configs/chains");
|
|
14
|
+
const artifacts_1 = require("../../utils/artifacts");
|
|
15
|
+
const getContractAddress_1 = __importDefault(require("../../contracts/getContractAddress"));
|
|
16
|
+
function encodeERC721(tokenId) {
|
|
17
|
+
return new ethers_1.ethers.AbiCoder().encode(["uint256"], [tokenId.toString()]);
|
|
18
|
+
}
|
|
19
|
+
function decodeERC721(data) {
|
|
20
|
+
return new ethers_1.ethers.AbiCoder().decode(["uint256"], data);
|
|
21
|
+
}
|
|
22
|
+
function encodeERC20(amount) {
|
|
23
|
+
return new ethers_1.ethers.AbiCoder().encode(["uint256"], [amount.toString()]);
|
|
24
|
+
}
|
|
25
|
+
function decodeERC20(data) {
|
|
26
|
+
return new ethers_1.ethers.AbiCoder().decode(["uint256"], data);
|
|
27
|
+
}
|
|
28
|
+
function getRWAVaultAdapterByAddress(chainId, address) {
|
|
29
|
+
const adaptersConfig = chains_1.configs[chainId].adapters;
|
|
30
|
+
const keys = Object.keys(adaptersConfig.rwavault);
|
|
31
|
+
const matchKey = keys.find((k) => adaptersConfig.rwavault[k].contract === address);
|
|
32
|
+
if (matchKey === null)
|
|
33
|
+
throw new Error("Adapter not found in config.");
|
|
34
|
+
return adaptersConfig.rwavault[matchKey];
|
|
35
|
+
}
|
|
36
|
+
async function getRWAVaultContract(chainId) {
|
|
37
|
+
const rwaVaultAddress = (0, getContractAddress_1.default)(chainId, "rwavault");
|
|
38
|
+
const rwaVaultABI = (0, artifacts_1.getABI)("rwavault");
|
|
39
|
+
const provider = new ethers_1.ethers.JsonRpcProvider();
|
|
40
|
+
return new ethers_1.ethers.Contract(rwaVaultAddress, rwaVaultABI, provider);
|
|
41
|
+
}
|