@defisaver/positions-sdk 2.1.8 → 2.1.9
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/CLAUDE.md +32 -0
- package/README.md +64 -64
- package/cjs/fluid/index.js +40 -12
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/markets/fluid/index.d.ts +4 -0
- package/cjs/markets/fluid/index.js +4 -0
- package/cjs/types/fluid.d.ts +7 -3
- package/cjs/types/fluid.js +4 -0
- package/esm/fluid/index.js +40 -12
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/markets/fluid/index.d.ts +4 -0
- package/esm/markets/fluid/index.js +4 -0
- package/esm/types/fluid.d.ts +7 -3
- package/esm/types/fluid.js +4 -0
- package/package.json +47 -47
- package/src/aaveV2/index.ts +240 -240
- package/src/aaveV3/index.ts +614 -614
- package/src/aaveV3/merit.ts +97 -97
- package/src/aaveV3/merkl.ts +74 -74
- package/src/claiming/aaveV3.ts +154 -154
- package/src/claiming/compV3.ts +22 -22
- package/src/claiming/index.ts +12 -12
- package/src/claiming/king.ts +66 -66
- package/src/claiming/morphoBlue.ts +118 -118
- package/src/claiming/spark.ts +225 -225
- package/src/compoundV2/index.ts +244 -244
- package/src/compoundV3/index.ts +274 -274
- package/src/config/contracts.ts +1251 -1251
- package/src/constants/index.ts +10 -10
- package/src/contracts.ts +120 -120
- package/src/curveUsd/index.ts +254 -254
- package/src/eulerV2/index.ts +324 -324
- package/src/exchange/index.ts +25 -25
- package/src/fluid/index.ts +1668 -1638
- package/src/helpers/aaveHelpers/index.ts +187 -187
- package/src/helpers/compoundHelpers/index.ts +283 -283
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +222 -222
- package/src/helpers/fluidHelpers/index.ts +326 -326
- package/src/helpers/index.ts +10 -10
- package/src/helpers/liquityV2Helpers/index.ts +82 -82
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +52 -52
- package/src/helpers/morphoBlueHelpers/index.ts +396 -396
- package/src/helpers/sparkHelpers/index.ts +155 -155
- package/src/index.ts +47 -47
- package/src/liquity/index.ts +159 -159
- package/src/liquityV2/index.ts +657 -657
- package/src/llamaLend/index.ts +305 -305
- package/src/maker/index.ts +223 -223
- package/src/markets/aave/index.ts +116 -116
- package/src/markets/aave/marketAssets.ts +54 -54
- package/src/markets/compound/index.ts +238 -238
- package/src/markets/compound/marketsAssets.ts +97 -97
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/fluid/index.ts +2460 -2456
- package/src/markets/index.ts +25 -25
- package/src/markets/liquityV2/index.ts +102 -102
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +12 -12
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoBlue/index.ts +274 -274
- package/src/portfolio/index.ts +570 -570
- package/src/services/priceService.ts +159 -159
- package/src/services/utils.ts +115 -115
- package/src/services/viem.ts +34 -34
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +445 -445
- package/src/staking/eligibility.ts +53 -53
- package/src/staking/index.ts +1 -1
- package/src/staking/staking.ts +170 -170
- package/src/types/aave.ts +189 -189
- package/src/types/claiming.ts +109 -109
- package/src/types/common.ts +107 -107
- package/src/types/compound.ts +136 -136
- package/src/types/curveUsd.ts +123 -123
- package/src/types/euler.ts +175 -175
- package/src/types/fluid.ts +452 -448
- package/src/types/index.ts +13 -13
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +126 -126
- package/src/types/llamaLend.ts +159 -159
- package/src/types/maker.ts +63 -63
- package/src/types/merit.ts +1 -1
- package/src/types/merkl.ts +70 -70
- package/src/types/morphoBlue.ts +194 -194
- package/src/types/portfolio.ts +60 -60
- package/src/types/spark.ts +135 -135
- package/src/umbrella/index.ts +69 -69
- package/src/umbrella/umbrellaUtils.ts +29 -29
package/.mocharc.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"require": "ts-node/register",
|
|
3
|
-
"extension": ["ts"]
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"require": "ts-node/register",
|
|
3
|
+
"extension": ["ts"]
|
|
4
|
+
}
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v20.17.0
|
|
1
|
+
v20.17.0
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# DeFiSaver Positions SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for DeFi positions tracking and management.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Development
|
|
9
|
+
npm run dev # Watch mode compilation
|
|
10
|
+
npm run build # Lint and build both CJS and ESM
|
|
11
|
+
npm run build:cjs # Build CommonJS
|
|
12
|
+
npm run build:esm # Build ES modules
|
|
13
|
+
|
|
14
|
+
# Linting
|
|
15
|
+
npm run lint # Lint and fix
|
|
16
|
+
npm run lint-check # Lint without fixing
|
|
17
|
+
|
|
18
|
+
# Testing
|
|
19
|
+
npm run test # Run all tests
|
|
20
|
+
npm run test-single # Run single test (use --name=filename)
|
|
21
|
+
npm run test:debugger # Run tests with debugger
|
|
22
|
+
|
|
23
|
+
# Versioning
|
|
24
|
+
npm run version-bump # Commit and bump patch version
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Project Structure
|
|
28
|
+
|
|
29
|
+
- `src/` - TypeScript source code
|
|
30
|
+
- `tests/` - Test files
|
|
31
|
+
- `esm/` - ES module build output
|
|
32
|
+
- `cjs/` - CommonJS build output
|
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# DeFi Saver Positions SDK
|
|
2
|
-
|
|
3
|
-
Supported protocols:
|
|
4
|
-
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
-
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
-
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
-
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
-
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
-
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
10
|
-
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
11
|
-
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
12
|
-
|
|
13
|
-
## Setup
|
|
14
|
-
Supported Node version is v10.
|
|
15
|
-
|
|
16
|
-
- run `npm install` (first time)
|
|
17
|
-
- run `npm run build`
|
|
18
|
-
|
|
19
|
-
`build` command will generate contracts and build ejs and esm folders
|
|
20
|
-
|
|
21
|
-
## How to use
|
|
22
|
-
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
23
|
-
|
|
24
|
-
This is a Compound V3 example, and every other protocol is similar
|
|
25
|
-
```js
|
|
26
|
-
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// every protocol has market data and user data getters
|
|
30
|
-
const {
|
|
31
|
-
getCompoundV3MarketsData,
|
|
32
|
-
getCompoundV3AccountData,
|
|
33
|
-
} = compoundV3;
|
|
34
|
-
|
|
35
|
-
const provider = 'Your RPC provider';
|
|
36
|
-
|
|
37
|
-
const user = '0x123...';
|
|
38
|
-
|
|
39
|
-
const { assetsData } = await getCompoundV3MarketsData(
|
|
40
|
-
provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
41
|
-
1, // network
|
|
42
|
-
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
43
|
-
provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const userData = await getCompoundV3AccountData(
|
|
47
|
-
provider,
|
|
48
|
-
1, // network
|
|
49
|
-
userAddress, // EOA or DSProxy
|
|
50
|
-
'', // proxy address of the user, or just empty string if checking for EOA
|
|
51
|
-
{
|
|
52
|
-
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
53
|
-
assetsData,
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
59
|
-
|
|
60
|
-
## Testing
|
|
61
|
-
|
|
62
|
-
`npm run test` - Run all tests
|
|
63
|
-
|
|
64
|
-
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
|
1
|
+
# DeFi Saver Positions SDK
|
|
2
|
+
|
|
3
|
+
Supported protocols:
|
|
4
|
+
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
+
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
+
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
+
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
+
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
+
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
10
|
+
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
11
|
+
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
Supported Node version is v10.
|
|
15
|
+
|
|
16
|
+
- run `npm install` (first time)
|
|
17
|
+
- run `npm run build`
|
|
18
|
+
|
|
19
|
+
`build` command will generate contracts and build ejs and esm folders
|
|
20
|
+
|
|
21
|
+
## How to use
|
|
22
|
+
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
23
|
+
|
|
24
|
+
This is a Compound V3 example, and every other protocol is similar
|
|
25
|
+
```js
|
|
26
|
+
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// every protocol has market data and user data getters
|
|
30
|
+
const {
|
|
31
|
+
getCompoundV3MarketsData,
|
|
32
|
+
getCompoundV3AccountData,
|
|
33
|
+
} = compoundV3;
|
|
34
|
+
|
|
35
|
+
const provider = 'Your RPC provider';
|
|
36
|
+
|
|
37
|
+
const user = '0x123...';
|
|
38
|
+
|
|
39
|
+
const { assetsData } = await getCompoundV3MarketsData(
|
|
40
|
+
provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
41
|
+
1, // network
|
|
42
|
+
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
43
|
+
provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const userData = await getCompoundV3AccountData(
|
|
47
|
+
provider,
|
|
48
|
+
1, // network
|
|
49
|
+
userAddress, // EOA or DSProxy
|
|
50
|
+
'', // proxy address of the user, or just empty string if checking for EOA
|
|
51
|
+
{
|
|
52
|
+
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
53
|
+
assetsData,
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
`npm run test` - Run all tests
|
|
63
|
+
|
|
64
|
+
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
package/cjs/fluid/index.js
CHANGED
|
@@ -1099,19 +1099,21 @@ const _getFluidTokenData = (provider, network, token) => __awaiter(void 0, void
|
|
|
1099
1099
|
exports._getFluidTokenData = _getFluidTokenData;
|
|
1100
1100
|
const getFluidTokenData = (provider, network, token) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getFluidTokenData)((0, viem_1.getViemProvider)(provider, network), network, token); });
|
|
1101
1101
|
exports.getFluidTokenData = getFluidTokenData;
|
|
1102
|
-
const parseFDepositTokenData = (fTokenData, userPosition, fTokenAddress) => {
|
|
1103
|
-
|
|
1104
|
-
const rewardsRate = new decimal_js_1.default(fTokenData.rewardsRate).div(1e12).toString();
|
|
1102
|
+
const parseFDepositTokenData = (fTokenData, userPosition, apiData, fTokenAddress) => {
|
|
1103
|
+
var _a, _b;
|
|
1105
1104
|
const decimals = fTokenData.decimals.toString();
|
|
1106
1105
|
const depositRate = new decimal_js_1.default((0, utils_1.getEthAmountForDecimals)(fTokenData.convertToShares.toString(), decimals)).toString();
|
|
1107
1106
|
const withdrawRate = new decimal_js_1.default((0, utils_1.getEthAmountForDecimals)(fTokenData.convertToAssets.toString(), decimals)).toString();
|
|
1107
|
+
const supplyRate = new decimal_js_1.default((apiData === null || apiData === void 0 ? void 0 : apiData.supplyRate) || '0').div(100).toString();
|
|
1108
|
+
const rewardRates = ((_a = apiData === null || apiData === void 0 ? void 0 : apiData.rewards) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => acc.add(new decimal_js_1.default(item.rate || '0').div(100)), new decimal_js_1.default(0))) || '0';
|
|
1109
|
+
const stakeRate = new decimal_js_1.default(((_b = apiData === null || apiData === void 0 ? void 0 : apiData.asset) === null || _b === void 0 ? void 0 : _b.stakingApr) || '0').div(100).toString();
|
|
1108
1110
|
return {
|
|
1109
1111
|
fTokenAddress,
|
|
1110
1112
|
fTokenSymbol: fTokenData.symbol,
|
|
1111
1113
|
decimals,
|
|
1112
1114
|
totalDeposited: (0, utils_1.getEthAmountForDecimals)(fTokenData.totalAssets.toString(), decimals),
|
|
1113
1115
|
withdrawable: (0, utils_1.getEthAmountForDecimals)(fTokenData.withdrawable.toString(), decimals),
|
|
1114
|
-
apy: new decimal_js_1.default(supplyRate).
|
|
1116
|
+
apy: new decimal_js_1.default(supplyRate).plus(rewardRates).plus(stakeRate).toString(),
|
|
1115
1117
|
depositRate,
|
|
1116
1118
|
withdrawRate,
|
|
1117
1119
|
deposited: (0, utils_1.getEthAmountForDecimals)(userPosition.underlyingAssets.toString(), decimals),
|
|
@@ -1121,21 +1123,44 @@ const parseFDepositTokenData = (fTokenData, userPosition, fTokenAddress) => {
|
|
|
1121
1123
|
const _getFluidDepositData = (provider, network, token, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1122
1124
|
const view = (0, contracts_1.FluidViewContractViem)(provider, network);
|
|
1123
1125
|
const fTokenAddress = (0, markets_1.getFTokenAddress)(token, network);
|
|
1124
|
-
const [userPosition, fTokenData] = yield
|
|
1125
|
-
|
|
1126
|
+
const [[userPosition, fTokenData], rewardsApiResponse,] = yield Promise.all([
|
|
1127
|
+
view.read.getUserEarnPositionWithFToken([fTokenAddress, address]),
|
|
1128
|
+
fetch(`https://api.fluid.instadapp.io/v2/lending/${network}/tokens/${fTokenAddress}`),
|
|
1129
|
+
]);
|
|
1130
|
+
let rewardsData = { rewards: [] };
|
|
1131
|
+
if (!rewardsApiResponse.ok) {
|
|
1132
|
+
console.log('External API Failure: Failed to fetch fluid rewards APY');
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
rewardsData = yield rewardsApiResponse.json();
|
|
1136
|
+
}
|
|
1137
|
+
return parseFDepositTokenData(fTokenData, userPosition, rewardsData, fTokenAddress);
|
|
1126
1138
|
});
|
|
1127
1139
|
exports._getFluidDepositData = _getFluidDepositData;
|
|
1128
1140
|
const getFluidDepositData = (provider, network, token, address) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getFluidDepositData)((0, viem_1.getViemProvider)(provider, network), network, token, address); });
|
|
1129
1141
|
exports.getFluidDepositData = getFluidDepositData;
|
|
1130
1142
|
const _getAllUserEarnPositionsWithFTokens = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1131
1143
|
const view = (0, contracts_1.FluidViewContractViem)(provider, network);
|
|
1132
|
-
const [userPositions, fTokensData] = yield
|
|
1144
|
+
const [[userPositions, fTokensData], rewardsApiResponse,] = yield Promise.all([
|
|
1145
|
+
view.read.getAllUserEarnPositionsWithFTokens([user]),
|
|
1146
|
+
fetch(`https://api.fluid.instadapp.io/v2/lending/${network}/tokens`),
|
|
1147
|
+
]);
|
|
1148
|
+
let rewardsData = {
|
|
1149
|
+
data: [{ address: constants_1.ZERO_ADDRESS, rewards: [] }],
|
|
1150
|
+
};
|
|
1151
|
+
if (!rewardsApiResponse.ok) {
|
|
1152
|
+
console.log('External API Failure: Failed to fetch fluid rewards APY');
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
rewardsData = yield rewardsApiResponse.json();
|
|
1156
|
+
}
|
|
1133
1157
|
const parsedRes = fTokensData.reduce((acc, fTokenData, i) => {
|
|
1134
1158
|
const userPosition = userPositions[i];
|
|
1135
1159
|
const deposited = userPosition === null || userPosition === void 0 ? void 0 : userPosition.underlyingAssets;
|
|
1136
1160
|
if (Number(deposited) > 0) {
|
|
1137
1161
|
const fTokenAddress = fTokenData.tokenAddress;
|
|
1138
|
-
|
|
1162
|
+
const apiData = rewardsData.data.find((item) => (0, utils_1.compareAddresses)(item.address, fTokenAddress));
|
|
1163
|
+
acc.push(parseFDepositTokenData(fTokenData, userPosition, apiData, fTokenAddress));
|
|
1139
1164
|
}
|
|
1140
1165
|
return acc;
|
|
1141
1166
|
}, []);
|
|
@@ -1184,19 +1209,22 @@ const getTokenPricePortfolio = (token, provider, network) => __awaiter(void 0, v
|
|
|
1184
1209
|
const tokensWithoutChainlinkPrices = ['sUSDS', 'USDA', 'ezETH', 'rsETH', 'weETHs', 'LBTC'];
|
|
1185
1210
|
const handleTokenWithoutChainlinkPrice = (token, prices) => {
|
|
1186
1211
|
if (token === 'sUSDS') {
|
|
1187
|
-
return new decimal_js_1.default('
|
|
1212
|
+
return new decimal_js_1.default('107057929').div(1e8).toString();
|
|
1188
1213
|
}
|
|
1189
1214
|
if (token === 'USDA') {
|
|
1190
1215
|
return new decimal_js_1.default('100000000').div(1e8).toString();
|
|
1191
1216
|
}
|
|
1217
|
+
if (token === 'wstUSR') {
|
|
1218
|
+
return new decimal_js_1.default('111280000').div(1e8).toString();
|
|
1219
|
+
}
|
|
1192
1220
|
if (token === 'ezETH') {
|
|
1193
|
-
return new decimal_js_1.default(prices.ETH).mul(1.
|
|
1221
|
+
return new decimal_js_1.default(prices.ETH).mul(1.06).toString();
|
|
1194
1222
|
}
|
|
1195
1223
|
if (token === 'rsETH') {
|
|
1196
|
-
return new decimal_js_1.default(prices.wstETH).mul(1.
|
|
1224
|
+
return new decimal_js_1.default(prices.wstETH).mul(1.0557).toString();
|
|
1197
1225
|
}
|
|
1198
1226
|
if (token === 'weETHs') {
|
|
1199
|
-
return new decimal_js_1.default(prices.wstETH).mul(1.
|
|
1227
|
+
return new decimal_js_1.default(prices.wstETH).mul(1.032).toString();
|
|
1200
1228
|
}
|
|
1201
1229
|
if (token === 'LBTC') {
|
|
1202
1230
|
return prices.WBTC;
|
|
@@ -128,73 +128,73 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network)
|
|
|
128
128
|
});
|
|
129
129
|
exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
|
|
130
130
|
const API_URL = 'https://blue-api.morpho.org/graphql';
|
|
131
|
-
const MARKET_QUERY = `
|
|
132
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
133
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
134
|
-
reallocatableLiquidityAssets
|
|
135
|
-
targetBorrowUtilization
|
|
136
|
-
loanAsset {
|
|
137
|
-
address
|
|
138
|
-
decimals
|
|
139
|
-
priceUsd
|
|
140
|
-
}
|
|
141
|
-
state {
|
|
142
|
-
liquidityAssets
|
|
143
|
-
borrowAssets
|
|
144
|
-
supplyAssets
|
|
145
|
-
}
|
|
146
|
-
publicAllocatorSharedLiquidity {
|
|
147
|
-
assets
|
|
148
|
-
vault {
|
|
149
|
-
address
|
|
150
|
-
name
|
|
151
|
-
}
|
|
152
|
-
allocationMarket {
|
|
153
|
-
uniqueKey
|
|
154
|
-
loanAsset {
|
|
155
|
-
address
|
|
156
|
-
}
|
|
157
|
-
collateralAsset {
|
|
158
|
-
address
|
|
159
|
-
}
|
|
160
|
-
irmAddress
|
|
161
|
-
oracle {
|
|
162
|
-
address
|
|
163
|
-
}
|
|
164
|
-
lltv
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
loanAsset {
|
|
168
|
-
address
|
|
169
|
-
}
|
|
170
|
-
collateralAsset {
|
|
171
|
-
address
|
|
172
|
-
}
|
|
173
|
-
oracle {
|
|
174
|
-
address
|
|
175
|
-
}
|
|
176
|
-
irmAddress
|
|
177
|
-
lltv
|
|
178
|
-
}
|
|
179
|
-
}
|
|
131
|
+
const MARKET_QUERY = `
|
|
132
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
133
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
134
|
+
reallocatableLiquidityAssets
|
|
135
|
+
targetBorrowUtilization
|
|
136
|
+
loanAsset {
|
|
137
|
+
address
|
|
138
|
+
decimals
|
|
139
|
+
priceUsd
|
|
140
|
+
}
|
|
141
|
+
state {
|
|
142
|
+
liquidityAssets
|
|
143
|
+
borrowAssets
|
|
144
|
+
supplyAssets
|
|
145
|
+
}
|
|
146
|
+
publicAllocatorSharedLiquidity {
|
|
147
|
+
assets
|
|
148
|
+
vault {
|
|
149
|
+
address
|
|
150
|
+
name
|
|
151
|
+
}
|
|
152
|
+
allocationMarket {
|
|
153
|
+
uniqueKey
|
|
154
|
+
loanAsset {
|
|
155
|
+
address
|
|
156
|
+
}
|
|
157
|
+
collateralAsset {
|
|
158
|
+
address
|
|
159
|
+
}
|
|
160
|
+
irmAddress
|
|
161
|
+
oracle {
|
|
162
|
+
address
|
|
163
|
+
}
|
|
164
|
+
lltv
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
loanAsset {
|
|
168
|
+
address
|
|
169
|
+
}
|
|
170
|
+
collateralAsset {
|
|
171
|
+
address
|
|
172
|
+
}
|
|
173
|
+
oracle {
|
|
174
|
+
address
|
|
175
|
+
}
|
|
176
|
+
irmAddress
|
|
177
|
+
lltv
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
180
|
`;
|
|
181
|
-
const REWARDS_QUERY = `
|
|
182
|
-
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
183
|
-
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
184
|
-
uniqueKey
|
|
185
|
-
state {
|
|
186
|
-
rewards {
|
|
187
|
-
amountPerSuppliedToken
|
|
188
|
-
supplyApr
|
|
189
|
-
amountPerBorrowedToken
|
|
190
|
-
borrowApr
|
|
191
|
-
asset {
|
|
192
|
-
address
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
181
|
+
const REWARDS_QUERY = `
|
|
182
|
+
query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
|
|
183
|
+
marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
|
|
184
|
+
uniqueKey
|
|
185
|
+
state {
|
|
186
|
+
rewards {
|
|
187
|
+
amountPerSuppliedToken
|
|
188
|
+
supplyApr
|
|
189
|
+
amountPerBorrowedToken
|
|
190
|
+
borrowApr
|
|
191
|
+
asset {
|
|
192
|
+
address
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
198
|
`;
|
|
199
199
|
/**
|
|
200
200
|
* Get reallocatable liquidity to a given market and target borrow utilization
|
|
@@ -244,17 +244,21 @@ export declare const FluidFTokens: (networkId: NetworkNumber) => {
|
|
|
244
244
|
wstETH: string;
|
|
245
245
|
GHO: string;
|
|
246
246
|
sUSDS: string;
|
|
247
|
+
USDtb: string;
|
|
247
248
|
} | {
|
|
248
249
|
ETH: string;
|
|
249
250
|
USDC: string;
|
|
250
251
|
USDT: string;
|
|
251
252
|
wstETH: string;
|
|
252
253
|
ARB: string;
|
|
254
|
+
GHO: string;
|
|
255
|
+
sUSDS: string;
|
|
253
256
|
} | {
|
|
254
257
|
ETH: string;
|
|
255
258
|
USDC: string;
|
|
256
259
|
EURC: string;
|
|
257
260
|
wstETH: string;
|
|
258
261
|
sUSDS: string;
|
|
262
|
+
GHO: string;
|
|
259
263
|
};
|
|
260
264
|
export declare const getFTokenAddress: (token: string, networkId: NetworkNumber) => any;
|
|
@@ -2415,6 +2415,7 @@ const FluidMainnetFTokenAddresses = {
|
|
|
2415
2415
|
[types_1.FluidMainnetDepositToken.wstETH]: '0x2411802D8BEA09be0aF8fD8D08314a63e706b29C',
|
|
2416
2416
|
[types_1.FluidMainnetDepositToken.GHO]: '0x6A29A46E21C730DcA1d8b23d637c101cec605C5B',
|
|
2417
2417
|
[types_1.FluidMainnetDepositToken.sUSDS]: '0x2BBE31d63E6813E3AC858C04dae43FB2a72B0D11',
|
|
2418
|
+
[types_1.FluidMainnetDepositToken.USDtb]: '0x15e8c742614b5D8Db4083A41Df1A14F5D2bFB400',
|
|
2418
2419
|
};
|
|
2419
2420
|
const FluidArbitrumFTokenAddresses = {
|
|
2420
2421
|
[types_1.FluidArbitrumDepositToken.ETH]: '0x45Df0656F8aDf017590009d2f1898eeca4F0a205',
|
|
@@ -2422,6 +2423,8 @@ const FluidArbitrumFTokenAddresses = {
|
|
|
2422
2423
|
[types_1.FluidArbitrumDepositToken.USDT]: '0x4A03F37e7d3fC243e3f99341d36f4b829BEe5E03',
|
|
2423
2424
|
[types_1.FluidArbitrumDepositToken.wstETH]: '0x66C25Cd75EBdAA7E04816F643d8E46cecd3183c9',
|
|
2424
2425
|
[types_1.FluidArbitrumDepositToken.ARB]: '0xbE3860FD4c3facDf8ad57Aa8c1A36D6dc4390a49',
|
|
2426
|
+
[types_1.FluidArbitrumDepositToken.GHO]: '0x037dFf1C12805707d7c29F163E0F09fC9102657A',
|
|
2427
|
+
[types_1.FluidArbitrumDepositToken.sUSDS]: '0x3459fcc94390C3372c0F7B4cD3F8795F0E5aFE96',
|
|
2425
2428
|
};
|
|
2426
2429
|
const FluidBaseFTokenAddresses = {
|
|
2427
2430
|
[types_1.FluidBaseDepositToken.ETH]: '0x9272D6153133175175Bc276512B2336BE3931CE9',
|
|
@@ -2429,6 +2432,7 @@ const FluidBaseFTokenAddresses = {
|
|
|
2429
2432
|
[types_1.FluidBaseDepositToken.EURC]: '0x1943FA26360f038230442525Cf1B9125b5DCB401',
|
|
2430
2433
|
[types_1.FluidBaseDepositToken.wstETH]: '0x896E39f0E9af61ECA9dD2938E14543506ef2c2b5',
|
|
2431
2434
|
[types_1.FluidBaseDepositToken.sUSDS]: '0xf62e339f21d8018940f188F6987Bcdf02A849619',
|
|
2435
|
+
[types_1.FluidBaseDepositToken.GHO]: '0x8DdbfFA3CFda2355a23d6B11105AC624BDbE3631',
|
|
2432
2436
|
};
|
|
2433
2437
|
const FluidFTokens = (networkId) => {
|
|
2434
2438
|
switch (networkId) {
|
package/cjs/types/fluid.d.ts
CHANGED
|
@@ -149,21 +149,25 @@ export declare enum FluidMainnetDepositToken {
|
|
|
149
149
|
USDC = "USDC",
|
|
150
150
|
USDT = "USDT",
|
|
151
151
|
GHO = "GHO",
|
|
152
|
-
sUSDS = "sUSDS"
|
|
152
|
+
sUSDS = "sUSDS",
|
|
153
|
+
USDtb = "USDtb"
|
|
153
154
|
}
|
|
154
155
|
export declare enum FluidArbitrumDepositToken {
|
|
155
156
|
ETH = "ETH",
|
|
156
157
|
wstETH = "wstETH",
|
|
157
158
|
USDC = "USDC",
|
|
158
159
|
USDT = "USDT",
|
|
159
|
-
ARB = "ARB"
|
|
160
|
+
ARB = "ARB",
|
|
161
|
+
GHO = "GHO",
|
|
162
|
+
sUSDS = "sUSDS"
|
|
160
163
|
}
|
|
161
164
|
export declare enum FluidBaseDepositToken {
|
|
162
165
|
ETH = "ETH",
|
|
163
166
|
USDC = "USDC",
|
|
164
167
|
wstETH = "wstETH",
|
|
165
168
|
EURC = "EURC",
|
|
166
|
-
sUSDS = "sUSDS"
|
|
169
|
+
sUSDS = "sUSDS",
|
|
170
|
+
GHO = "GHO"
|
|
167
171
|
}
|
|
168
172
|
export type FluidDepositTokenByNetwork = {
|
|
169
173
|
[NetworkNumber.Eth]: FluidMainnetDepositToken;
|
package/cjs/types/fluid.js
CHANGED
|
@@ -136,6 +136,7 @@ var FluidMainnetDepositToken;
|
|
|
136
136
|
FluidMainnetDepositToken["USDT"] = "USDT";
|
|
137
137
|
FluidMainnetDepositToken["GHO"] = "GHO";
|
|
138
138
|
FluidMainnetDepositToken["sUSDS"] = "sUSDS";
|
|
139
|
+
FluidMainnetDepositToken["USDtb"] = "USDtb";
|
|
139
140
|
})(FluidMainnetDepositToken || (exports.FluidMainnetDepositToken = FluidMainnetDepositToken = {}));
|
|
140
141
|
var FluidArbitrumDepositToken;
|
|
141
142
|
(function (FluidArbitrumDepositToken) {
|
|
@@ -144,6 +145,8 @@ var FluidArbitrumDepositToken;
|
|
|
144
145
|
FluidArbitrumDepositToken["USDC"] = "USDC";
|
|
145
146
|
FluidArbitrumDepositToken["USDT"] = "USDT";
|
|
146
147
|
FluidArbitrumDepositToken["ARB"] = "ARB";
|
|
148
|
+
FluidArbitrumDepositToken["GHO"] = "GHO";
|
|
149
|
+
FluidArbitrumDepositToken["sUSDS"] = "sUSDS";
|
|
147
150
|
})(FluidArbitrumDepositToken || (exports.FluidArbitrumDepositToken = FluidArbitrumDepositToken = {}));
|
|
148
151
|
var FluidBaseDepositToken;
|
|
149
152
|
(function (FluidBaseDepositToken) {
|
|
@@ -152,6 +155,7 @@ var FluidBaseDepositToken;
|
|
|
152
155
|
FluidBaseDepositToken["wstETH"] = "wstETH";
|
|
153
156
|
FluidBaseDepositToken["EURC"] = "EURC";
|
|
154
157
|
FluidBaseDepositToken["sUSDS"] = "sUSDS";
|
|
158
|
+
FluidBaseDepositToken["GHO"] = "GHO";
|
|
155
159
|
})(FluidBaseDepositToken || (exports.FluidBaseDepositToken = FluidBaseDepositToken = {}));
|
|
156
160
|
var FluidVaultType;
|
|
157
161
|
(function (FluidVaultType) {
|
package/esm/fluid/index.js
CHANGED
|
@@ -1081,19 +1081,21 @@ export const _getFluidTokenData = (provider, network, token) => __awaiter(void 0
|
|
|
1081
1081
|
};
|
|
1082
1082
|
});
|
|
1083
1083
|
export const getFluidTokenData = (provider, network, token) => __awaiter(void 0, void 0, void 0, function* () { return _getFluidTokenData(getViemProvider(provider, network), network, token); });
|
|
1084
|
-
const parseFDepositTokenData = (fTokenData, userPosition, fTokenAddress) => {
|
|
1085
|
-
|
|
1086
|
-
const rewardsRate = new Dec(fTokenData.rewardsRate).div(1e12).toString();
|
|
1084
|
+
const parseFDepositTokenData = (fTokenData, userPosition, apiData, fTokenAddress) => {
|
|
1085
|
+
var _a, _b;
|
|
1087
1086
|
const decimals = fTokenData.decimals.toString();
|
|
1088
1087
|
const depositRate = new Dec(getEthAmountForDecimals(fTokenData.convertToShares.toString(), decimals)).toString();
|
|
1089
1088
|
const withdrawRate = new Dec(getEthAmountForDecimals(fTokenData.convertToAssets.toString(), decimals)).toString();
|
|
1089
|
+
const supplyRate = new Dec((apiData === null || apiData === void 0 ? void 0 : apiData.supplyRate) || '0').div(100).toString();
|
|
1090
|
+
const rewardRates = ((_a = apiData === null || apiData === void 0 ? void 0 : apiData.rewards) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => acc.add(new Dec(item.rate || '0').div(100)), new Dec(0))) || '0';
|
|
1091
|
+
const stakeRate = new Dec(((_b = apiData === null || apiData === void 0 ? void 0 : apiData.asset) === null || _b === void 0 ? void 0 : _b.stakingApr) || '0').div(100).toString();
|
|
1090
1092
|
return {
|
|
1091
1093
|
fTokenAddress,
|
|
1092
1094
|
fTokenSymbol: fTokenData.symbol,
|
|
1093
1095
|
decimals,
|
|
1094
1096
|
totalDeposited: getEthAmountForDecimals(fTokenData.totalAssets.toString(), decimals),
|
|
1095
1097
|
withdrawable: getEthAmountForDecimals(fTokenData.withdrawable.toString(), decimals),
|
|
1096
|
-
apy: new Dec(supplyRate).
|
|
1098
|
+
apy: new Dec(supplyRate).plus(rewardRates).plus(stakeRate).toString(),
|
|
1097
1099
|
depositRate,
|
|
1098
1100
|
withdrawRate,
|
|
1099
1101
|
deposited: getEthAmountForDecimals(userPosition.underlyingAssets.toString(), decimals),
|
|
@@ -1103,19 +1105,42 @@ const parseFDepositTokenData = (fTokenData, userPosition, fTokenAddress) => {
|
|
|
1103
1105
|
export const _getFluidDepositData = (provider, network, token, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1104
1106
|
const view = FluidViewContractViem(provider, network);
|
|
1105
1107
|
const fTokenAddress = getFTokenAddress(token, network);
|
|
1106
|
-
const [userPosition, fTokenData] = yield
|
|
1107
|
-
|
|
1108
|
+
const [[userPosition, fTokenData], rewardsApiResponse,] = yield Promise.all([
|
|
1109
|
+
view.read.getUserEarnPositionWithFToken([fTokenAddress, address]),
|
|
1110
|
+
fetch(`https://api.fluid.instadapp.io/v2/lending/${network}/tokens/${fTokenAddress}`),
|
|
1111
|
+
]);
|
|
1112
|
+
let rewardsData = { rewards: [] };
|
|
1113
|
+
if (!rewardsApiResponse.ok) {
|
|
1114
|
+
console.log('External API Failure: Failed to fetch fluid rewards APY');
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
rewardsData = yield rewardsApiResponse.json();
|
|
1118
|
+
}
|
|
1119
|
+
return parseFDepositTokenData(fTokenData, userPosition, rewardsData, fTokenAddress);
|
|
1108
1120
|
});
|
|
1109
1121
|
export const getFluidDepositData = (provider, network, token, address) => __awaiter(void 0, void 0, void 0, function* () { return _getFluidDepositData(getViemProvider(provider, network), network, token, address); });
|
|
1110
1122
|
export const _getAllUserEarnPositionsWithFTokens = (provider, network, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1111
1123
|
const view = FluidViewContractViem(provider, network);
|
|
1112
|
-
const [userPositions, fTokensData] = yield
|
|
1124
|
+
const [[userPositions, fTokensData], rewardsApiResponse,] = yield Promise.all([
|
|
1125
|
+
view.read.getAllUserEarnPositionsWithFTokens([user]),
|
|
1126
|
+
fetch(`https://api.fluid.instadapp.io/v2/lending/${network}/tokens`),
|
|
1127
|
+
]);
|
|
1128
|
+
let rewardsData = {
|
|
1129
|
+
data: [{ address: ZERO_ADDRESS, rewards: [] }],
|
|
1130
|
+
};
|
|
1131
|
+
if (!rewardsApiResponse.ok) {
|
|
1132
|
+
console.log('External API Failure: Failed to fetch fluid rewards APY');
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
rewardsData = yield rewardsApiResponse.json();
|
|
1136
|
+
}
|
|
1113
1137
|
const parsedRes = fTokensData.reduce((acc, fTokenData, i) => {
|
|
1114
1138
|
const userPosition = userPositions[i];
|
|
1115
1139
|
const deposited = userPosition === null || userPosition === void 0 ? void 0 : userPosition.underlyingAssets;
|
|
1116
1140
|
if (Number(deposited) > 0) {
|
|
1117
1141
|
const fTokenAddress = fTokenData.tokenAddress;
|
|
1118
|
-
|
|
1142
|
+
const apiData = rewardsData.data.find((item) => compareAddresses(item.address, fTokenAddress));
|
|
1143
|
+
acc.push(parseFDepositTokenData(fTokenData, userPosition, apiData, fTokenAddress));
|
|
1119
1144
|
}
|
|
1120
1145
|
return acc;
|
|
1121
1146
|
}, []);
|
|
@@ -1160,19 +1185,22 @@ const getTokenPricePortfolio = (token, provider, network) => __awaiter(void 0, v
|
|
|
1160
1185
|
const tokensWithoutChainlinkPrices = ['sUSDS', 'USDA', 'ezETH', 'rsETH', 'weETHs', 'LBTC'];
|
|
1161
1186
|
const handleTokenWithoutChainlinkPrice = (token, prices) => {
|
|
1162
1187
|
if (token === 'sUSDS') {
|
|
1163
|
-
return new Dec('
|
|
1188
|
+
return new Dec('107057929').div(1e8).toString();
|
|
1164
1189
|
}
|
|
1165
1190
|
if (token === 'USDA') {
|
|
1166
1191
|
return new Dec('100000000').div(1e8).toString();
|
|
1167
1192
|
}
|
|
1193
|
+
if (token === 'wstUSR') {
|
|
1194
|
+
return new Dec('111280000').div(1e8).toString();
|
|
1195
|
+
}
|
|
1168
1196
|
if (token === 'ezETH') {
|
|
1169
|
-
return new Dec(prices.ETH).mul(1.
|
|
1197
|
+
return new Dec(prices.ETH).mul(1.06).toString();
|
|
1170
1198
|
}
|
|
1171
1199
|
if (token === 'rsETH') {
|
|
1172
|
-
return new Dec(prices.wstETH).mul(1.
|
|
1200
|
+
return new Dec(prices.wstETH).mul(1.0557).toString();
|
|
1173
1201
|
}
|
|
1174
1202
|
if (token === 'weETHs') {
|
|
1175
|
-
return new Dec(prices.wstETH).mul(1.
|
|
1203
|
+
return new Dec(prices.wstETH).mul(1.032).toString();
|
|
1176
1204
|
}
|
|
1177
1205
|
if (token === 'LBTC') {
|
|
1178
1206
|
return prices.WBTC;
|