@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
|
@@ -53,6 +53,11 @@
|
|
|
53
53
|
"id": "releaseorchestrator",
|
|
54
54
|
"name": "Release Orchestrator",
|
|
55
55
|
"contract": "0xdC5F980E0e0Ad46c94086450f2744CDe11cDcDce"
|
|
56
|
+
},
|
|
57
|
+
"rwavault": {
|
|
58
|
+
"id": "rwavault",
|
|
59
|
+
"name": "RWA Vault",
|
|
60
|
+
"contract": "0x0165878A594ca255338adfa4d48449f69242Eb8F"
|
|
56
61
|
}
|
|
57
62
|
},
|
|
58
63
|
"pools": {
|
|
@@ -117,43 +122,37 @@
|
|
|
117
122
|
"decimals": 18,
|
|
118
123
|
"contract": "0x3C9406aFa1d63A8e12b6E71f0D1d28A41b2e5D16"
|
|
119
124
|
},
|
|
120
|
-
"
|
|
121
|
-
"id": "
|
|
122
|
-
"name": "Index Token",
|
|
125
|
+
"rwaindextoken": {
|
|
126
|
+
"id": "rwaindextoken",
|
|
127
|
+
"name": "RWA Index Token",
|
|
123
128
|
"decimals": 18,
|
|
124
129
|
"contract": "0x3C9406aFa1d63A8e12b6E71f0D1d28A41b2e5D16"
|
|
125
130
|
}
|
|
126
131
|
},
|
|
127
132
|
"adapters": {
|
|
128
133
|
"lendingpool": {
|
|
129
|
-
"
|
|
130
|
-
"id": "
|
|
134
|
+
"raacnftadapter": {
|
|
135
|
+
"id": "raacnftadapter",
|
|
131
136
|
"name": "RAAC NFT Adapter",
|
|
132
137
|
"contract": "",
|
|
133
138
|
"type": "ERC721"
|
|
134
139
|
},
|
|
135
|
-
"
|
|
136
|
-
"id": "
|
|
140
|
+
"rwaindextokenadapter": {
|
|
141
|
+
"id": "rwaindextokenadapter",
|
|
137
142
|
"name": "RWA Index Token",
|
|
138
143
|
"contract": "",
|
|
139
144
|
"type": "ERC20"
|
|
140
145
|
}
|
|
141
146
|
},
|
|
142
147
|
"rwavault": {
|
|
143
|
-
"
|
|
144
|
-
"id": "
|
|
148
|
+
"raacnftadapter": {
|
|
149
|
+
"id": "raacnftadapter",
|
|
145
150
|
"name": "RAAC NFT Adapter",
|
|
146
151
|
"contract": "",
|
|
147
152
|
"type": "ERC721"
|
|
148
153
|
},
|
|
149
|
-
"
|
|
150
|
-
"id": "
|
|
151
|
-
"name": "RWA Index Token",
|
|
152
|
-
"contract": "",
|
|
153
|
-
"type": "ERC20"
|
|
154
|
-
},
|
|
155
|
-
"crvusd": {
|
|
156
|
-
"id": "crvusd",
|
|
154
|
+
"crvusdadapter": {
|
|
155
|
+
"id": "crvusdadapter",
|
|
157
156
|
"name": "CRVUSD",
|
|
158
157
|
"contract": "",
|
|
159
158
|
"type": "ERC20"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"raachouseprices": {
|
|
18
18
|
"id": "raachouseprices",
|
|
19
19
|
"name": "RAAC House Prices",
|
|
20
|
-
"contract": "
|
|
20
|
+
"contract": "0x0165878A594ca255338adfa4d48449f69242Eb8F"
|
|
21
21
|
},
|
|
22
22
|
"auctionfactory": {
|
|
23
23
|
"id": "auctionfactory",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"feecollector": {
|
|
38
38
|
"id": "feecollector",
|
|
39
39
|
"name": "Fee Collector",
|
|
40
|
-
"contract": "
|
|
40
|
+
"contract": "0x610178dA211FEF7D417bC0e6FeD39F05609AD788"
|
|
41
41
|
},
|
|
42
42
|
"treasury": {
|
|
43
43
|
"id": "treasury",
|
|
44
44
|
"name": "Treasury",
|
|
45
|
-
"contract": "
|
|
45
|
+
"contract": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"
|
|
46
46
|
},
|
|
47
47
|
"repairfund": {
|
|
48
48
|
"id": "repairfund",
|
|
@@ -53,6 +53,11 @@
|
|
|
53
53
|
"id": "releaseorchestrator",
|
|
54
54
|
"name": "Release Orchestrator",
|
|
55
55
|
"contract": "0x0165878A594ca255338adfa4d48449f69242Eb8F"
|
|
56
|
+
},
|
|
57
|
+
"rwavault": {
|
|
58
|
+
"id": "rwavault",
|
|
59
|
+
"name": "RWA Vault",
|
|
60
|
+
"contract": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E"
|
|
56
61
|
}
|
|
57
62
|
},
|
|
58
63
|
"pools": {
|
|
@@ -64,14 +69,14 @@
|
|
|
64
69
|
"lendingpool": {
|
|
65
70
|
"id": "lendingpool",
|
|
66
71
|
"name": "Lending Pool",
|
|
67
|
-
"contract": "
|
|
72
|
+
"contract": "0x59b670e9fA9D0A427751Af201D676719a970857b"
|
|
68
73
|
}
|
|
69
74
|
},
|
|
70
75
|
"nfts": {
|
|
71
76
|
"raacnft": {
|
|
72
77
|
"id": "raacnft",
|
|
73
78
|
"name": "RAAC NFT",
|
|
74
|
-
"contract": "
|
|
79
|
+
"contract": "0xf5059a5D33d5853360D16C683c16e67980206f36"
|
|
75
80
|
}
|
|
76
81
|
},
|
|
77
82
|
"assets": {
|
|
@@ -85,77 +90,71 @@
|
|
|
85
90
|
"id": "crvusd",
|
|
86
91
|
"name": "CRVUSD",
|
|
87
92
|
"decimals": 18,
|
|
88
|
-
"contract": "
|
|
93
|
+
"contract": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
|
|
89
94
|
},
|
|
90
95
|
"rtoken": {
|
|
91
96
|
"id": "rtoken",
|
|
92
97
|
"name": "RToken",
|
|
93
98
|
"decimals": 18,
|
|
94
|
-
"contract": "
|
|
99
|
+
"contract": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE"
|
|
95
100
|
},
|
|
96
101
|
"detoken": {
|
|
97
102
|
"id": "detoken",
|
|
98
103
|
"name": "DEToken",
|
|
99
104
|
"decimals": 18,
|
|
100
|
-
"contract": "
|
|
105
|
+
"contract": "0x4A679253410272dd5232B3Ff7cF5dbB88f295319"
|
|
101
106
|
},
|
|
102
107
|
"raactoken": {
|
|
103
108
|
"id": "raactoken",
|
|
104
109
|
"name": "RAAC",
|
|
105
110
|
"decimals": 18,
|
|
106
|
-
"contract": "
|
|
111
|
+
"contract": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
|
|
107
112
|
},
|
|
108
113
|
"veraac": {
|
|
109
114
|
"id": "veraac",
|
|
110
115
|
"name": "VERAAC",
|
|
111
116
|
"decimals": 18,
|
|
112
|
-
"contract": "
|
|
117
|
+
"contract": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
|
|
113
118
|
},
|
|
114
119
|
"debttoken": {
|
|
115
120
|
"id": "debttoken",
|
|
116
121
|
"name": "Debt Token",
|
|
117
122
|
"decimals": 18,
|
|
118
|
-
"contract": "
|
|
123
|
+
"contract": "0x68B1D87F95878fE05B998F19b66F4baba5De1aed"
|
|
119
124
|
},
|
|
120
|
-
"
|
|
121
|
-
"id": "
|
|
125
|
+
"rwaindextoken": {
|
|
126
|
+
"id": "rwaindextoken",
|
|
122
127
|
"name": "Index Token",
|
|
123
128
|
"decimals": 18,
|
|
124
|
-
"contract": "
|
|
129
|
+
"contract": "0x67d269191c92Caf3cD7723F116c85e6E9bf55933"
|
|
125
130
|
}
|
|
126
131
|
},
|
|
127
132
|
"adapters": {
|
|
128
133
|
"lendingpool": {
|
|
129
|
-
"
|
|
130
|
-
"id": "
|
|
134
|
+
"raacnftadapter": {
|
|
135
|
+
"id": "raacnftadapter",
|
|
131
136
|
"name": "RAAC NFT Adapter",
|
|
132
|
-
"contract": "",
|
|
137
|
+
"contract": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
|
|
133
138
|
"type": "ERC721"
|
|
134
139
|
},
|
|
135
|
-
"
|
|
136
|
-
"id": "
|
|
140
|
+
"rwaindextokenadapter": {
|
|
141
|
+
"id": "rwaindextokenadapter",
|
|
137
142
|
"name": "RWA Index Token",
|
|
138
|
-
"contract": "",
|
|
143
|
+
"contract": "0x95401dc811bb5740090279Ba06cfA8fcF6113778",
|
|
139
144
|
"type": "ERC20"
|
|
140
145
|
}
|
|
141
146
|
},
|
|
142
147
|
"rwavault": {
|
|
143
|
-
"
|
|
144
|
-
"id": "
|
|
148
|
+
"raacnftadapter": {
|
|
149
|
+
"id": "raacnftadapter",
|
|
145
150
|
"name": "RAAC NFT Adapter",
|
|
146
|
-
"contract": "",
|
|
151
|
+
"contract": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
|
|
147
152
|
"type": "ERC721"
|
|
148
153
|
},
|
|
149
|
-
"
|
|
150
|
-
"id": "
|
|
151
|
-
"name": "
|
|
152
|
-
"contract": "",
|
|
153
|
-
"type": "ERC20"
|
|
154
|
-
},
|
|
155
|
-
"crvusd": {
|
|
156
|
-
"id": "crvusd",
|
|
157
|
-
"name": "CRVUSD",
|
|
158
|
-
"contract": "",
|
|
154
|
+
"crvusdadapter": {
|
|
155
|
+
"id": "crvusdadapter",
|
|
156
|
+
"name": "CRVUSD Adapter",
|
|
157
|
+
"contract": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
|
159
158
|
"type": "ERC20"
|
|
160
159
|
}
|
|
161
160
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.encodeERC721 = encodeERC721;
|
|
4
7
|
exports.decodeERC721 = decodeERC721;
|
|
5
8
|
exports.encodeERC20 = encodeERC20;
|
|
6
9
|
exports.decodeERC20 = decodeERC20;
|
|
7
10
|
exports.getLendingPoolAdapterByAddress = getLendingPoolAdapterByAddress;
|
|
11
|
+
exports.getLendingPoolContract = getLendingPoolContract;
|
|
8
12
|
const ethers_1 = require("ethers");
|
|
9
13
|
const chains_1 = require("../../configs/chains");
|
|
14
|
+
const artifacts_1 = require("../../utils/artifacts");
|
|
15
|
+
const getContractAddress_1 = __importDefault(require("../../contracts/getContractAddress"));
|
|
10
16
|
function encodeERC721(tokenId) {
|
|
11
17
|
return new ethers_1.ethers.AbiCoder().encode(["uint256"], [tokenId.toString()]);
|
|
12
18
|
}
|
|
@@ -27,3 +33,9 @@ function getLendingPoolAdapterByAddress(chainId, address) {
|
|
|
27
33
|
throw new Error("Adapter not found in config.");
|
|
28
34
|
return adaptersConfig[matchKey];
|
|
29
35
|
}
|
|
36
|
+
async function getLendingPoolContract(chainId) {
|
|
37
|
+
const lendingPoolAddress = (0, getContractAddress_1.default)(chainId, "lendingpool");
|
|
38
|
+
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
39
|
+
const provider = new ethers_1.ethers.JsonRpcProvider();
|
|
40
|
+
return new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
41
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const artifacts_1 = require("../../../../utils/artifacts");
|
|
5
|
-
async function getERC20AdapterBalance(
|
|
5
|
+
async function getERC20AdapterBalance(adapterAddress, userAddress, signer) {
|
|
6
6
|
if (!signer) {
|
|
7
7
|
throw new Error("Wallet not connected");
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const artifacts_1 = require("../../../../utils/artifacts");
|
|
5
|
-
async function getERC20AdapterInfo(
|
|
5
|
+
async function getERC20AdapterInfo(adapterAddress, signer) {
|
|
6
6
|
if (!signer) {
|
|
7
7
|
throw new Error("Wallet not connected");
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const artifacts_1 = require("../../../../utils/artifacts");
|
|
5
|
-
async function getERC721AdapterDeposits(
|
|
5
|
+
async function getERC721AdapterDeposits(adapterAddress, userAddress, signer) {
|
|
6
6
|
if (!signer) {
|
|
7
7
|
throw new Error("Wallet not connected");
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const artifacts_1 = require("../../../../utils/artifacts");
|
|
5
|
-
async function getERC721AdapterInfo(
|
|
5
|
+
async function getERC721AdapterInfo(adapterAddress, signer) {
|
|
6
6
|
if (!signer) {
|
|
7
7
|
throw new Error("Wallet not connected");
|
|
8
8
|
}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
async function borrowFromLendingPool(chainId, adapter, data, amount, signer) {
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
5
|
+
async function borrowFromLendingPool(chainId, adapterName, amount, data) {
|
|
7
6
|
try {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const tx = await lendingPoolContract.borrow(
|
|
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.borrow(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 borrowing from lending pool:", error);
|
|
21
18
|
throw error;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
@@ -1,40 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
9
|
-
const checkAllowance_1 = __importDefault(require("../../methods/commons/checkAllowance"));
|
|
10
|
-
const approveAsset_1 = __importDefault(require("../../wallet/assets/approveAsset"));
|
|
3
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
11
5
|
// TODO: interface changed
|
|
12
|
-
async function borrowFromLendingPoolWithInsurance(chainId,
|
|
6
|
+
async function borrowFromLendingPoolWithInsurance(chainId, adapterName, amount, data) {
|
|
13
7
|
try {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const userAddress = await signer.getAddress();
|
|
19
|
-
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
20
|
-
console.log("Borrowing amount in wei:", amountInWei.toString());
|
|
21
|
-
// get the total insurance they need to pay
|
|
22
|
-
const insurance = await lendingPoolContract.calculateInsuranceFee(adapter, userAddress, data, amountInWei.toString());
|
|
23
|
-
// Approve the crvUSD balance to the fee collector
|
|
24
|
-
const allowance = await (0, checkAllowance_1.default)(chainId, "crvusd", userAddress, feeCollectorAddress, signer.provider);
|
|
25
|
-
// If the allowance is less than the insurance, approve the difference
|
|
26
|
-
if (allowance < insurance) {
|
|
27
|
-
await (0, approveAsset_1.default)(chainId, "crvusd", feeCollectorAddress, insurance.toString(), signer);
|
|
28
|
-
console.log(`Approved ${ethers_1.ethers.formatEther(insurance)} crvUSD to fee collector`);
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
9
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
10
|
+
if (!adapterAddress) {
|
|
11
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
29
12
|
}
|
|
30
|
-
const tx = await lendingPoolContract.borrowWithInsurance(
|
|
13
|
+
const tx = await lendingPoolContract.borrowWithInsurance(adapterAddress, data, amount);
|
|
31
14
|
const receipt = await tx.wait();
|
|
32
|
-
|
|
33
|
-
console.log(`Transaction hash: ${receipt?.hash}`);
|
|
34
|
-
return receipt;
|
|
15
|
+
return receipt.status === 1;
|
|
35
16
|
}
|
|
36
17
|
catch (error) {
|
|
37
|
-
console.error("Error
|
|
18
|
+
console.error("Error borrowing from lending pool with insurance:", error);
|
|
38
19
|
throw error;
|
|
39
20
|
}
|
|
40
21
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const getAdapterAddress_1 = require("./getAdapterAddress");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
6
|
// TODO: interface changed
|
|
7
|
-
async function calculateInsuranceFee(chainId,
|
|
7
|
+
async function calculateInsuranceFee(chainId, adapterName, userAddress, data, amount, provider) {
|
|
8
8
|
try {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
10
|
+
if (!adapterAddress) {
|
|
11
|
+
throw new Error(`Adapter ${adapterName} not found`);
|
|
12
|
+
}
|
|
13
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
12
14
|
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
+
const fee = await lendingPoolContract.calculateInsuranceFee(adapterAddress, userAddress, data, amountInWei.toString());
|
|
16
|
+
console.log(`Insurance fee: ${ethers_1.ethers.formatEther(fee)}`);
|
|
17
|
+
return fee;
|
|
15
18
|
}
|
|
16
19
|
catch (error) {
|
|
17
20
|
console.error("Error in calculateInsuranceFee:", error);
|
|
@@ -1,28 +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 Close the liqudation after the debt has been paid
|
|
9
8
|
* @param chainId
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
9
|
+
* @param lendingPoolAddress
|
|
10
|
+
* @param adapterName
|
|
11
|
+
* @param data
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
async function closeLiquidation(chainId,
|
|
14
|
+
async function closeLiquidation(chainId, adapterName, data) {
|
|
15
15
|
try {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
17
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
18
|
+
if (!adapterAddress) {
|
|
19
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
20
|
+
}
|
|
21
|
+
const tx = await lendingPoolContract.closeLiquidation(adapterAddress, data);
|
|
22
|
+
const receipt = await tx.wait();
|
|
23
|
+
return receipt.status === 1;
|
|
23
24
|
}
|
|
24
25
|
catch (error) {
|
|
25
|
-
console.error("Error
|
|
26
|
+
console.error("Error closing liquidation:", error);
|
|
26
27
|
throw error;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -1,60 +1,22 @@
|
|
|
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 getAdapterAddress_1 = require("./getAdapterAddress");
|
|
6
4
|
const _helpers_1 = require("./_helpers");
|
|
7
5
|
// TODO: interface changed
|
|
8
|
-
async function depositAssetToLendingPool(chainId,
|
|
9
|
-
if (!signer) {
|
|
10
|
-
throw new Error("Wallet not connected");
|
|
11
|
-
}
|
|
6
|
+
async function depositAssetToLendingPool(chainId, adapterName, data) {
|
|
12
7
|
try {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, signer);
|
|
18
|
-
const adapterConfig = (0, _helpers_1.getLendingPoolAdapterByAddress)(chainId, adapter);
|
|
19
|
-
if (adapterConfig.type === "ERC721") {
|
|
20
|
-
const nftContract = new ethers_1.ethers.Contract(nftAddress, nftABI, signer);
|
|
21
|
-
// Check if the signer owns the NFT
|
|
22
|
-
const tokenId = await (0, _helpers_1.decodeERC721)(data);
|
|
23
|
-
const owner = await nftContract.ownerOf(tokenId);
|
|
24
|
-
if (owner.toLowerCase() !== (await signer.getAddress()).toLowerCase()) {
|
|
25
|
-
throw new Error(`Signer does not own NFT #${tokenId}`);
|
|
26
|
-
}
|
|
27
|
-
// Approve the lending pool to transfer the NFT
|
|
28
|
-
const approveTx = await nftContract.approve(lendingPoolAddress, tokenId, {
|
|
29
|
-
// maxFeePerGas,
|
|
30
|
-
nonce: await signer.getNonce(),
|
|
31
|
-
});
|
|
32
|
-
await approveTx.wait();
|
|
33
|
-
console.log(`Approved lending pool to transfer NFT #${tokenId}`);
|
|
34
|
-
}
|
|
35
|
-
else if (adapterConfig.type === "ERC20") {
|
|
36
|
-
const amount = (0, _helpers_1.decodeERC20)(data);
|
|
37
|
-
const erc20Contract = new ethers_1.ethers.Contract((0, getContractAddress_1.getContractAddress)(chainId, "crvusd"), (0, artifacts_1.getABI)("crvusd"), signer);
|
|
38
|
-
const sufficientBalance = await erc20Contract.balanceOf(await signer.getAddress()) > amount;
|
|
39
|
-
if (!sufficientBalance)
|
|
40
|
-
throw new Error("User does not have sufficient balance.");
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
throw new Error("Adapter type is not configured.");
|
|
8
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
9
|
+
const adapterAddress = (0, getAdapterAddress_1.getAdapterAddressOnly)(chainId, adapterName);
|
|
10
|
+
if (!adapterAddress) {
|
|
11
|
+
throw new Error(`Adapter ${adapterName} not found for chain ${chainId}`);
|
|
44
12
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
nonce: await signer.getNonce(),
|
|
49
|
-
});
|
|
50
|
-
console.log(`Deposit transaction sent for Asset #${data}:`, depositTx.hash);
|
|
51
|
-
const receipt = await depositTx.wait();
|
|
52
|
-
console.log(`Deposited Asset #${data} to lending pool successfully:`, receipt?.hash);
|
|
53
|
-
return receipt;
|
|
13
|
+
const tx = await lendingPoolContract.depositAsset(adapterAddress, data);
|
|
14
|
+
const receipt = await tx.wait();
|
|
15
|
+
return receipt.status === 1;
|
|
54
16
|
}
|
|
55
17
|
catch (error) {
|
|
56
|
-
console.error(
|
|
57
|
-
throw
|
|
18
|
+
console.error("Error depositing asset to lending pool:", error);
|
|
19
|
+
throw error;
|
|
58
20
|
}
|
|
59
21
|
}
|
|
60
22
|
exports.default = depositAssetToLendingPool;
|
|
@@ -1,17 +1,14 @@
|
|
|
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
|
// checked
|
|
7
6
|
async function depositToLendingPool(chainId, amount, signer) {
|
|
8
7
|
if (!signer) {
|
|
9
8
|
throw new Error("Wallet not connected");
|
|
10
9
|
}
|
|
11
10
|
try {
|
|
12
|
-
const
|
|
13
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
14
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, signer);
|
|
11
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
15
12
|
const amountInWei = ethers_1.ethers.parseEther(amount);
|
|
16
13
|
// const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
17
14
|
const depositTx = await lendingPoolContract.deposit(amountInWei.toString(), {
|
|
@@ -0,0 +1,44 @@
|
|
|
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.getAdapterAddress = getAdapterAddress;
|
|
7
|
+
exports.getAdapterAddressOnly = getAdapterAddressOnly;
|
|
8
|
+
const chains_1 = __importDefault(require("../../configs/chains"));
|
|
9
|
+
/**
|
|
10
|
+
* Get the adapter address and type for a given adapter name
|
|
11
|
+
* @param chainId The chain ID
|
|
12
|
+
* @param adapterName The name of the adapter (e.g., "rwaindextokenadapter")
|
|
13
|
+
* @returns The adapter address and type, or null if not found
|
|
14
|
+
*/
|
|
15
|
+
function getAdapterAddress(chainId, adapterName) {
|
|
16
|
+
const chainConfig = chains_1.default[chainId];
|
|
17
|
+
if (!chainConfig) {
|
|
18
|
+
throw new Error(`Chain configuration not found for chain ID ${chainId}`);
|
|
19
|
+
}
|
|
20
|
+
// Search through all adapters in the chain config
|
|
21
|
+
for (const poolType in chainConfig.adapters) {
|
|
22
|
+
const poolAdapters = chainConfig.adapters[poolType];
|
|
23
|
+
for (const assetType in poolAdapters) {
|
|
24
|
+
const adapter = poolAdapters[assetType];
|
|
25
|
+
if (adapter.id === adapterName) {
|
|
26
|
+
return {
|
|
27
|
+
address: adapter.contract,
|
|
28
|
+
type: adapter.type
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the adapter address for a given adapter name
|
|
37
|
+
* @param chainId The chain ID
|
|
38
|
+
* @param adapterName The name of the adapter (e.g., "rwaindextokenadapter")
|
|
39
|
+
* @returns The adapter address, or null if not found
|
|
40
|
+
*/
|
|
41
|
+
function getAdapterAddressOnly(chainId, adapterName) {
|
|
42
|
+
const adapterInfo = getAdapterAddress(chainId, adapterName);
|
|
43
|
+
return adapterInfo?.address ?? null;
|
|
44
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ethers_1 = require("ethers");
|
|
4
|
-
const getContractAddress_1 = require("../../contracts/getContractAddress");
|
|
5
|
-
const artifacts_1 = require("../../utils/artifacts");
|
|
6
3
|
const index_1 = require("../../configs/chains/index");
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
7
5
|
async function getAdapters(chainId, provider) {
|
|
8
6
|
try {
|
|
9
|
-
const
|
|
10
|
-
const lendingPoolABI = (0, artifacts_1.getABI)("lendingpool");
|
|
11
|
-
const lendingPoolContract = new ethers_1.ethers.Contract(lendingPoolAddress, lendingPoolABI, provider);
|
|
7
|
+
const lendingPoolContract = await (0, _helpers_1.getLendingPoolContract)(chainId);
|
|
12
8
|
const adapters = await lendingPoolContract.getAdapters();
|
|
13
9
|
const adapterConfig = index_1.configs[chainId].adapters;
|
|
14
10
|
return {
|