@gearbox-protocol/sdk 14.6.0-next.4 → 14.6.0
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/cjs/abi/compressors/subcompressors/withdrawal/infinifiWithdrawalSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/kelpLRTWithdrawalSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/subcompressors/withdrawal/upshiftWithdrawalSubcompressor.js +2 -1
- package/dist/cjs/abi/compressors/withdrawalCompressor.js +2 -1
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list-core.js +66 -0
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list.js +7 -18
- package/dist/cjs/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers.js +4 -6
- package/dist/cjs/common-utils/utils/strategies/credit-managers/index.js +2 -0
- package/dist/cjs/common-utils/utils/strategies/lists/get-released-strategies-list-core.js +61 -0
- package/dist/cjs/common-utils/utils/strategies/lists/get-released-strategies-list.js +9 -31
- package/dist/cjs/common-utils/utils/strategies/lists/index.js +3 -1
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-info-core.js +104 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-info.js +35 -59
- package/dist/cjs/common-utils/utils/strategies/strategy-info/index.js +2 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-state/is-strategy-disabled.js +3 -1
- package/dist/cjs/common-utils/utils/strategies/types/index.js +4 -0
- package/dist/cjs/common-utils/utils/strategies/types/legacy-strategy-data-source.js +62 -0
- package/dist/cjs/common-utils/utils/strategies/types/strategy-data-source.js +16 -0
- package/dist/cjs/plugins/apy/ApyPlugin.js +65 -0
- package/dist/cjs/plugins/apy/strategy-data-source.js +176 -0
- package/dist/esm/abi/compressors/subcompressors/withdrawal/infinifiWithdrawalSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/kelpLRTWithdrawalSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/subcompressors/withdrawal/upshiftWithdrawalSubcompressor.js +2 -1
- package/dist/esm/abi/compressors/withdrawalCompressor.js +2 -1
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list-core.js +42 -0
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list.js +7 -18
- package/dist/esm/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers.js +4 -6
- package/dist/esm/common-utils/utils/strategies/credit-managers/index.js +1 -0
- package/dist/esm/common-utils/utils/strategies/lists/get-released-strategies-list-core.js +37 -0
- package/dist/esm/common-utils/utils/strategies/lists/get-released-strategies-list.js +9 -31
- package/dist/esm/common-utils/utils/strategies/lists/index.js +1 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-info-core.js +80 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-info.js +35 -59
- package/dist/esm/common-utils/utils/strategies/strategy-info/index.js +1 -0
- package/dist/esm/common-utils/utils/strategies/strategy-state/is-strategy-disabled.js +3 -1
- package/dist/esm/common-utils/utils/strategies/types/index.js +2 -0
- package/dist/esm/common-utils/utils/strategies/types/legacy-strategy-data-source.js +38 -0
- package/dist/esm/common-utils/utils/strategies/types/strategy-data-source.js +0 -0
- package/dist/esm/plugins/apy/ApyPlugin.js +70 -0
- package/dist/esm/plugins/apy/strategy-data-source.js +159 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/infinifiWithdrawalSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/kelpLRTWithdrawalSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/subcompressors/withdrawal/upshiftWithdrawalSubcompressor.d.ts +4 -0
- package/dist/types/abi/compressors/withdrawalCompressor.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list-core.d.ts +7 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers-list.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers.d.ts +3 -3
- package/dist/types/common-utils/utils/strategies/credit-managers/index.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/credit-managers/is-credit-manager-usable.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/eligibility/is-strategy-eligible.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/lists/get-available-and-disabled-strategies.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/lists/get-available-strategies.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/lists/get-disabled-strategies.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/lists/get-released-strategies-list-core.d.ts +9 -0
- package/dist/types/common-utils/utils/strategies/lists/get-released-strategies-list.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/lists/index.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-strategy-info-core.d.ts +12 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/index.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/strategy-state/is-strategy-disabled.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/tokens/is-activated-token.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/tokens/is-forbidden-token.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/types/credit-manager-data-legacy.d.ts +3 -7
- package/dist/types/common-utils/utils/strategies/types/index.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/types/legacy-strategy-data-source.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/types/sdk-state.d.ts +5 -4
- package/dist/types/common-utils/utils/strategies/types/strategies-cm-list.d.ts +2 -2
- package/dist/types/common-utils/utils/strategies/types/strategy-data-source.d.ts +19 -0
- package/dist/types/common-utils/utils/strategies/types/targetable.d.ts +2 -2
- package/dist/types/permissionless/bindings/compressors/withdrawal-compressor.d.ts +4 -0
- package/dist/types/plugins/apy/ApyPlugin.d.ts +8 -1
- package/dist/types/plugins/apy/strategy-data-source.d.ts +16 -0
- package/dist/types/plugins/apy/types.d.ts +18 -1
- package/package.json +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { PriceUtils } from "../../price-math.js";
|
|
2
|
+
import { getFactorFromLeverage } from "../leverage/index.js";
|
|
3
|
+
import { sortStrategyCMsByAvailability } from "../sort-strategy-cms-by-availability/index.js";
|
|
4
|
+
import { getStrategyMaxAPY } from "./get-strategy-max-apy.js";
|
|
5
|
+
import { isStrategyCMDisabled } from "./is-strategy-cm-disabled.js";
|
|
6
|
+
const EMPTY_ADDRESS = "";
|
|
7
|
+
const lc = (address) => address.toLowerCase();
|
|
8
|
+
function getStrategyInfoCore({
|
|
9
|
+
strategy,
|
|
10
|
+
creditManagers,
|
|
11
|
+
source,
|
|
12
|
+
apyListByNetwork,
|
|
13
|
+
quotaReserve,
|
|
14
|
+
slippage
|
|
15
|
+
}) {
|
|
16
|
+
const strategyCMsList = Object.values(creditManagers || {});
|
|
17
|
+
if (strategyCMsList.length === 0) return void 0;
|
|
18
|
+
const targetTokenAddress = lc(strategy.tokenOutAddress);
|
|
19
|
+
const openableCMsList = strategyCMsList.filter(
|
|
20
|
+
(cm) => !isStrategyCMDisabled(cm, cm.quotas[targetTokenAddress])
|
|
21
|
+
);
|
|
22
|
+
const pools = strategyCMsList.reduce(
|
|
23
|
+
(acc, cm) => {
|
|
24
|
+
const pool = source.getPool(cm.chainId, cm.pool);
|
|
25
|
+
if (pool) acc[cm.pool] = pool;
|
|
26
|
+
return acc;
|
|
27
|
+
},
|
|
28
|
+
{}
|
|
29
|
+
);
|
|
30
|
+
const minCreditManager = sortStrategyCMsByAvailability({
|
|
31
|
+
targetToken: targetTokenAddress,
|
|
32
|
+
allCreditManagers: openableCMsList.length > 0 ? openableCMsList : strategyCMsList,
|
|
33
|
+
apyListByNetwork,
|
|
34
|
+
slippage,
|
|
35
|
+
quotaReserve,
|
|
36
|
+
pools,
|
|
37
|
+
leverageLimit: strategy.maxLeverage,
|
|
38
|
+
isStrategy: true
|
|
39
|
+
})?.[0] || strategyCMsList[0];
|
|
40
|
+
const { underlyingToken = EMPTY_ADDRESS, availableToBorrow = 0n } = minCreditManager || {};
|
|
41
|
+
const {
|
|
42
|
+
bonusAPY,
|
|
43
|
+
totalMaxApy = 0,
|
|
44
|
+
maxLeverage = 0n,
|
|
45
|
+
baseBorrowRate = 0,
|
|
46
|
+
quotaRateMin = 0n
|
|
47
|
+
} = getStrategyMaxAPY(
|
|
48
|
+
targetTokenAddress,
|
|
49
|
+
minCreditManager,
|
|
50
|
+
apyListByNetwork,
|
|
51
|
+
slippage,
|
|
52
|
+
quotaReserve,
|
|
53
|
+
strategy.maxLeverage
|
|
54
|
+
) || {};
|
|
55
|
+
const prices = source.getMarketPrices(
|
|
56
|
+
minCreditManager?.chainId ?? strategy.chainId,
|
|
57
|
+
minCreditManager?.pool || EMPTY_ADDRESS
|
|
58
|
+
);
|
|
59
|
+
const underlyingPrice = prices?.[underlyingToken] || 0n;
|
|
60
|
+
const underlyingDecimals = source.getToken(strategy.chainId, underlyingToken)?.decimals || 18;
|
|
61
|
+
const availableToBorrowMoney = PriceUtils.calcTotalPrice(
|
|
62
|
+
underlyingPrice,
|
|
63
|
+
availableToBorrow,
|
|
64
|
+
underlyingDecimals
|
|
65
|
+
);
|
|
66
|
+
const r = BigInt(baseBorrowRate) * getFactorFromLeverage(maxLeverage) / maxLeverage;
|
|
67
|
+
const qr = quotaRateMin;
|
|
68
|
+
const totalBorrowRate = Number(r + qr);
|
|
69
|
+
return {
|
|
70
|
+
maxLeverage,
|
|
71
|
+
maxAPY: totalMaxApy,
|
|
72
|
+
bonusAPY,
|
|
73
|
+
totalBorrowRate,
|
|
74
|
+
availableToBorrowMoney,
|
|
75
|
+
minCreditManager
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
getStrategyInfoCore
|
|
80
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { isStrategyCMDisabled } from "./is-strategy-cm-disabled.js";
|
|
6
|
-
const EMPTY_ADDRESS = "";
|
|
7
|
-
const EMPTY_CHAIN_ID = 0;
|
|
1
|
+
import { getStrategyInfoCore } from "./get-strategy-info-core.js";
|
|
2
|
+
function getByAddress(record, address) {
|
|
3
|
+
return record?.[address] ?? record?.[address.toLowerCase()];
|
|
4
|
+
}
|
|
8
5
|
function getStrategyInfo({
|
|
9
6
|
strategy,
|
|
10
7
|
creditManagers,
|
|
@@ -14,60 +11,39 @@ function getStrategyInfo({
|
|
|
14
11
|
slippage,
|
|
15
12
|
allPricesByChain
|
|
16
13
|
}) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
minCreditManager,
|
|
14
|
+
return getStrategyInfoCore({
|
|
15
|
+
strategy,
|
|
16
|
+
creditManagers: creditManagers?.[strategy.chainId]?.[strategy.id],
|
|
17
|
+
source: {
|
|
18
|
+
hasToken(chainId, token) {
|
|
19
|
+
return !!getByAddress(
|
|
20
|
+
sdkStateByChain?.[chainId]?.tokens?.tokenDataList,
|
|
21
|
+
token
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
getToken(chainId, token) {
|
|
25
|
+
return getByAddress(
|
|
26
|
+
sdkStateByChain?.[chainId]?.tokens?.tokenDataList,
|
|
27
|
+
token
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
getPool(chainId, pool) {
|
|
31
|
+
return getByAddress(sdkStateByChain?.[chainId]?.pools, pool);
|
|
32
|
+
},
|
|
33
|
+
getCreditManager() {
|
|
34
|
+
return void 0;
|
|
35
|
+
},
|
|
36
|
+
getMarketPrices(chainId, pool) {
|
|
37
|
+
return getByAddress(allPricesByChain?.[chainId]?.prices, pool) || {};
|
|
38
|
+
},
|
|
39
|
+
getLastSyncTimestamp() {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
47
43
|
apyListByNetwork,
|
|
48
|
-
slippage,
|
|
49
44
|
quotaReserve,
|
|
50
|
-
|
|
51
|
-
)
|
|
52
|
-
const prices = allPricesByChain?.[minCreditManager?.chainId ?? EMPTY_CHAIN_ID]?.prices?.[minCreditManager?.pool || EMPTY_ADDRESS];
|
|
53
|
-
const underlyingPrice = prices?.[underlyingToken] || 0n;
|
|
54
|
-
const underlyingDecimals = tokensList?.[underlyingToken]?.decimals || 18;
|
|
55
|
-
const availableToBorrowMoney = PriceUtils.calcTotalPrice(
|
|
56
|
-
underlyingPrice,
|
|
57
|
-
availableToBorrow,
|
|
58
|
-
underlyingDecimals
|
|
59
|
-
);
|
|
60
|
-
const r = BigInt(baseBorrowRate) * getFactorFromLeverage(maxLeverage) / maxLeverage;
|
|
61
|
-
const qr = quotaRateMin;
|
|
62
|
-
const totalBorrowRate = Number(r + qr);
|
|
63
|
-
return {
|
|
64
|
-
maxLeverage,
|
|
65
|
-
maxAPY: totalMaxApy,
|
|
66
|
-
bonusAPY,
|
|
67
|
-
totalBorrowRate,
|
|
68
|
-
availableToBorrowMoney,
|
|
69
|
-
minCreditManager
|
|
70
|
-
};
|
|
45
|
+
slippage
|
|
46
|
+
});
|
|
71
47
|
}
|
|
72
48
|
export {
|
|
73
49
|
getStrategyInfo
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isStrategyCMDisabled } from "../strategy-info/is-strategy-cm-disabled.js";
|
|
2
|
+
const lc = (address) => address.toLowerCase();
|
|
2
3
|
function isStrategyDisabled(tokenOutAddress, cms) {
|
|
3
4
|
if (cms.length === 0) return true;
|
|
5
|
+
const targetToken = lc(tokenOutAddress);
|
|
4
6
|
const allCmsUnavailable = cms.every((cm) => {
|
|
5
|
-
const quota = cm.quotas[
|
|
7
|
+
const quota = cm.quotas[targetToken];
|
|
6
8
|
return isStrategyCMDisabled(cm, quota);
|
|
7
9
|
});
|
|
8
10
|
return allCmsUnavailable;
|
|
@@ -2,7 +2,9 @@ export * from "./chains.js";
|
|
|
2
2
|
export * from "./constants.js";
|
|
3
3
|
export * from "./credit-manager-data-legacy.js";
|
|
4
4
|
export * from "./curator-filter.js";
|
|
5
|
+
export * from "./legacy-strategy-data-source.js";
|
|
5
6
|
export * from "./sdk-state.js";
|
|
6
7
|
export * from "./strategies-cm-list.js";
|
|
7
8
|
export * from "./strategy.js";
|
|
9
|
+
export * from "./strategy-data-source.js";
|
|
8
10
|
export * from "./targetable.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const lc = (address) => address.toLowerCase();
|
|
2
|
+
function getByAddress(record, address) {
|
|
3
|
+
return record?.[address] ?? record?.[lc(address)];
|
|
4
|
+
}
|
|
5
|
+
function createLegacyStrategyDataSource(sdkStateByChain, pricesByChain) {
|
|
6
|
+
return {
|
|
7
|
+
hasToken(chainId, token) {
|
|
8
|
+
return !!getByAddress(
|
|
9
|
+
sdkStateByChain?.[chainId]?.tokens?.tokenDataList,
|
|
10
|
+
token
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
getToken(chainId, token) {
|
|
14
|
+
return getByAddress(
|
|
15
|
+
sdkStateByChain?.[chainId]?.tokens?.tokenDataList,
|
|
16
|
+
token
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
getPool(chainId, pool) {
|
|
20
|
+
return getByAddress(sdkStateByChain?.[chainId]?.pools, pool);
|
|
21
|
+
},
|
|
22
|
+
getCreditManager(chainId, creditManager) {
|
|
23
|
+
return getByAddress(
|
|
24
|
+
sdkStateByChain?.[chainId]?.creditManagers,
|
|
25
|
+
creditManager
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
getMarketPrices(chainId, pool) {
|
|
29
|
+
return getByAddress(pricesByChain?.[chainId]?.prices, pool) ?? {};
|
|
30
|
+
},
|
|
31
|
+
getLastSyncTimestamp(chainId) {
|
|
32
|
+
return sdkStateByChain?.[chainId]?.lastSyncBlock?.blockTimestamp_js;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
createLegacyStrategyDataSource
|
|
38
|
+
};
|
|
File without changes
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
|
|
2
|
+
import {
|
|
3
|
+
getAvailableAndDisabledStrategies,
|
|
4
|
+
getReleasedStrategiesListCore,
|
|
5
|
+
getStrategyCreditManagersListCore,
|
|
6
|
+
getStrategyInfoCore
|
|
7
|
+
} from "../../common-utils/utils/strategies/index.js";
|
|
2
8
|
import { PoolPointsAPI } from "../../rewards/rewards/extra-apy.js";
|
|
3
9
|
import {
|
|
4
10
|
AddressMap,
|
|
@@ -20,6 +26,7 @@ import {
|
|
|
20
26
|
calculateSupplyApy7d,
|
|
21
27
|
getPoolExtraAPY
|
|
22
28
|
} from "./pool-apy-utils.js";
|
|
29
|
+
import { OnchainSdkStrategyDataSource } from "./strategy-data-source.js";
|
|
23
30
|
const MAP_LABEL = "pools7DAgo";
|
|
24
31
|
class ApyPlugin extends BasePlugin {
|
|
25
32
|
#apyUrl;
|
|
@@ -171,6 +178,69 @@ class ApyPlugin extends BasePlugin {
|
|
|
171
178
|
}
|
|
172
179
|
return { data, data7DAgo, pointsBase: poolPointsBase, points };
|
|
173
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Computes a strategy-info snapshot from the current SDK and APY state.
|
|
183
|
+
*
|
|
184
|
+
* @throws if plugin is not loaded
|
|
185
|
+
*/
|
|
186
|
+
getStrategyInfoSnapshot({
|
|
187
|
+
slippage,
|
|
188
|
+
quotaReserve,
|
|
189
|
+
curatorFilter,
|
|
190
|
+
strategyPayloadsList,
|
|
191
|
+
showHiddenStrategies
|
|
192
|
+
}) {
|
|
193
|
+
if (!this.loaded) {
|
|
194
|
+
throw new Error("apy plugin not loaded");
|
|
195
|
+
}
|
|
196
|
+
const chainId = this.sdk.chainId;
|
|
197
|
+
const network = this.sdk.networkType;
|
|
198
|
+
const allowedChains = { [chainId]: network };
|
|
199
|
+
const source = new OnchainSdkStrategyDataSource(this.sdk);
|
|
200
|
+
const releasedStrategies = getReleasedStrategiesListCore({
|
|
201
|
+
strategyPayloadsList,
|
|
202
|
+
allowedChains,
|
|
203
|
+
source,
|
|
204
|
+
curatorFilter,
|
|
205
|
+
showHiddenStrategies
|
|
206
|
+
});
|
|
207
|
+
const cmsOfStrategiesByChain = getStrategyCreditManagersListCore({
|
|
208
|
+
strategies: releasedStrategies,
|
|
209
|
+
source,
|
|
210
|
+
curatorFilter
|
|
211
|
+
});
|
|
212
|
+
const { available, disabled, availableList, disabledList } = getAvailableAndDisabledStrategies(
|
|
213
|
+
releasedStrategies,
|
|
214
|
+
cmsOfStrategiesByChain,
|
|
215
|
+
curatorFilter
|
|
216
|
+
);
|
|
217
|
+
const apyListByNetwork = {
|
|
218
|
+
[chainId]: this.apySnapshot.apy
|
|
219
|
+
};
|
|
220
|
+
const strategiesInfo = releasedStrategies?.reduce((acc, strategy) => {
|
|
221
|
+
const info = getStrategyInfoCore({
|
|
222
|
+
strategy,
|
|
223
|
+
creditManagers: cmsOfStrategiesByChain?.[strategy.chainId]?.[strategy.id],
|
|
224
|
+
source,
|
|
225
|
+
apyListByNetwork,
|
|
226
|
+
quotaReserve,
|
|
227
|
+
slippage
|
|
228
|
+
});
|
|
229
|
+
if (info) {
|
|
230
|
+
acc[strategy.chainId] ??= {};
|
|
231
|
+
acc[strategy.chainId][strategy.id] = info;
|
|
232
|
+
}
|
|
233
|
+
return acc;
|
|
234
|
+
}, {}) ?? {};
|
|
235
|
+
return {
|
|
236
|
+
availableStrategies: available,
|
|
237
|
+
disabledStrategies: disabled,
|
|
238
|
+
availableList,
|
|
239
|
+
disabledList,
|
|
240
|
+
cmsOfStrategiesByChain,
|
|
241
|
+
strategiesInfo
|
|
242
|
+
};
|
|
243
|
+
}
|
|
174
244
|
// ---------------------------------------------------------------------------
|
|
175
245
|
// Plugin lifecycle
|
|
176
246
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ADDRESS_0X0,
|
|
3
|
+
AP_WETH_TOKEN,
|
|
4
|
+
NATIVE_ADDRESS,
|
|
5
|
+
PERCENTAGE_DECIMALS,
|
|
6
|
+
PERCENTAGE_FACTOR,
|
|
7
|
+
RAY
|
|
8
|
+
} from "../../sdk/index.js";
|
|
9
|
+
const lc = (address) => address.toLowerCase();
|
|
10
|
+
class OnchainSdkStrategyDataSource {
|
|
11
|
+
constructor(sdk) {
|
|
12
|
+
this.sdk = sdk;
|
|
13
|
+
}
|
|
14
|
+
sdk;
|
|
15
|
+
hasToken(chainId, token) {
|
|
16
|
+
return !!this.getToken(chainId, token);
|
|
17
|
+
}
|
|
18
|
+
getToken(chainId, token) {
|
|
19
|
+
if (chainId !== this.sdk.chainId) return void 0;
|
|
20
|
+
const meta = this.sdk.tokensMeta.get(token);
|
|
21
|
+
if (!meta) return void 0;
|
|
22
|
+
const address = lc(token);
|
|
23
|
+
return { address, decimals: meta.decimals };
|
|
24
|
+
}
|
|
25
|
+
getPool(chainId, pool) {
|
|
26
|
+
if (chainId !== this.sdk.chainId) return void 0;
|
|
27
|
+
const market = this.sdk.marketRegister.markets.find(
|
|
28
|
+
(m) => lc(m.pool.pool.address) === lc(pool)
|
|
29
|
+
);
|
|
30
|
+
if (!market) return void 0;
|
|
31
|
+
return {
|
|
32
|
+
address: lc(market.pool.pool.address),
|
|
33
|
+
totalDebtLimit: market.pool.pool.totalDebtLimit,
|
|
34
|
+
totalBorrowed: market.pool.pool.totalBorrowed
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getCreditManager(chainId, creditManager) {
|
|
38
|
+
if (chainId !== this.sdk.chainId) return void 0;
|
|
39
|
+
try {
|
|
40
|
+
const found = this.findCreditManager(creditManager);
|
|
41
|
+
if (!found) return void 0;
|
|
42
|
+
return this.toCreditManagerView(found.creditSuite, found.market.pool);
|
|
43
|
+
} catch {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getMarketPrices(chainId, pool) {
|
|
48
|
+
if (chainId !== this.sdk.chainId) return {};
|
|
49
|
+
const market = this.sdk.marketRegister.markets.find(
|
|
50
|
+
(m) => lc(m.pool.pool.address) === lc(pool)
|
|
51
|
+
);
|
|
52
|
+
if (!market) return {};
|
|
53
|
+
const marketPrices = Object.fromEntries(
|
|
54
|
+
market.priceOracle.mainPrices.entries().map(([token, mainPrice]) => {
|
|
55
|
+
const tokenLc = lc(token);
|
|
56
|
+
const reservePrice = market.priceOracle.reservePrices?.get(token);
|
|
57
|
+
return [tokenLc, mainPrice?.price || reservePrice?.price || 0n];
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
const wrappedNativeToken = this.getWrappedNativeToken();
|
|
61
|
+
const wrappedNativePrice = marketPrices[wrappedNativeToken || ADDRESS_0X0];
|
|
62
|
+
if (wrappedNativePrice !== void 0) {
|
|
63
|
+
marketPrices[lc(NATIVE_ADDRESS)] = wrappedNativePrice;
|
|
64
|
+
}
|
|
65
|
+
return marketPrices;
|
|
66
|
+
}
|
|
67
|
+
getLastSyncTimestamp(chainId) {
|
|
68
|
+
return chainId === this.sdk.chainId ? Number(this.sdk.timestamp) : void 0;
|
|
69
|
+
}
|
|
70
|
+
toCreditManagerView(cs, pool) {
|
|
71
|
+
const cm = cs.creditManager;
|
|
72
|
+
const facade = cs.creditFacade;
|
|
73
|
+
const debtParams = pool.pool.creditManagerDebtParams.get(cm.address);
|
|
74
|
+
const liquidationThresholds = {};
|
|
75
|
+
const supportedTokens = {};
|
|
76
|
+
const forbiddenTokens = {};
|
|
77
|
+
const quotas = {};
|
|
78
|
+
for (const [token, q] of pool.pqk.quotas.entries()) {
|
|
79
|
+
const tokenLc = lc(token);
|
|
80
|
+
quotas[tokenLc] = {
|
|
81
|
+
token: tokenLc,
|
|
82
|
+
rate: BigInt(q.rate) * PERCENTAGE_DECIMALS,
|
|
83
|
+
quotaIncreaseFee: BigInt(q.quotaIncreaseFee),
|
|
84
|
+
totalQuoted: q.totalQuoted,
|
|
85
|
+
limit: q.limit,
|
|
86
|
+
isActive: q.isActive
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
for (const token of cm.collateralTokens) {
|
|
90
|
+
const tokenLc = lc(token);
|
|
91
|
+
const lt = cm.liquidationThresholds.get(token);
|
|
92
|
+
if (lt !== void 0) {
|
|
93
|
+
liquidationThresholds[tokenLc] = BigInt(lt);
|
|
94
|
+
}
|
|
95
|
+
supportedTokens[tokenLc] = true;
|
|
96
|
+
}
|
|
97
|
+
const forbiddenMask = facade.forbiddenTokensMask;
|
|
98
|
+
for (let i = 0; i < cm.collateralTokens.length; i++) {
|
|
99
|
+
const tokenLc = lc(cm.collateralTokens[i]);
|
|
100
|
+
if ((forbiddenMask & 1n << BigInt(i)) !== 0n) {
|
|
101
|
+
forbiddenTokens[tokenLc] = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const baseBorrowRate = debtParams ? Number(
|
|
105
|
+
pool.pool.baseInterestRate * (BigInt(cm.feeInterest) + PERCENTAGE_FACTOR) * PERCENTAGE_DECIMALS / RAY
|
|
106
|
+
) : 0;
|
|
107
|
+
return {
|
|
108
|
+
address: lc(cm.address),
|
|
109
|
+
underlyingToken: lc(cm.underlying),
|
|
110
|
+
pool: lc(cm.pool),
|
|
111
|
+
chainId: this.sdk.chainId,
|
|
112
|
+
baseBorrowRate,
|
|
113
|
+
feeInterest: cm.feeInterest,
|
|
114
|
+
availableToBorrow: debtParams?.available ?? 0n,
|
|
115
|
+
minDebt: facade.minDebt,
|
|
116
|
+
maxDebt: facade.maxDebt,
|
|
117
|
+
totalDebt: debtParams?.borrowed ?? 0n,
|
|
118
|
+
totalDebtLimit: debtParams?.limit ?? 0n,
|
|
119
|
+
isDegenMode: lc(facade.degenNFT) !== ADDRESS_0X0,
|
|
120
|
+
degenNFT: lc(facade.degenNFT),
|
|
121
|
+
liquidationThresholds,
|
|
122
|
+
quotas,
|
|
123
|
+
collateralTokens: cm.collateralTokens.map(lc),
|
|
124
|
+
version: Number(facade.version),
|
|
125
|
+
isBorrowingForbidden: facade.maxDebtPerBlockMultiplier === 0,
|
|
126
|
+
marketConfigurator: lc(cs.marketConfigurator),
|
|
127
|
+
supportedTokens,
|
|
128
|
+
forbiddenTokens
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
findCreditManager(creditManager) {
|
|
132
|
+
const marketRegister = this.sdk.marketRegister;
|
|
133
|
+
if (marketRegister.findCreditManager && marketRegister.findByCreditManager) {
|
|
134
|
+
const creditSuite = marketRegister.findCreditManager(creditManager);
|
|
135
|
+
const market = marketRegister.findByCreditManager(
|
|
136
|
+
creditSuite.creditManager.address
|
|
137
|
+
);
|
|
138
|
+
return { creditSuite, market };
|
|
139
|
+
}
|
|
140
|
+
const cmLc = lc(creditManager);
|
|
141
|
+
for (const market of marketRegister.markets) {
|
|
142
|
+
const creditSuite = market.creditManagers.find(
|
|
143
|
+
(cs) => lc(cs.creditManager.address) === cmLc
|
|
144
|
+
);
|
|
145
|
+
if (creditSuite) return { creditSuite, market };
|
|
146
|
+
}
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
getWrappedNativeToken() {
|
|
150
|
+
try {
|
|
151
|
+
return this.sdk.addressProvider.getAddress(AP_WETH_TOKEN, 0)?.toLowerCase();
|
|
152
|
+
} catch {
|
|
153
|
+
return void 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
OnchainSdkStrategyDataSource
|
|
159
|
+
};
|
package/dist/types/abi/compressors/subcompressors/withdrawal/infinifiWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const infinifiWithdrawalSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/kelpLRTWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const kelpLRTWithdrawalSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/mellowWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const mellowWithdrawalSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/midasWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const midasWithdrawalSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/securitizeRedemptionSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const securitizeRedemptionSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
package/dist/types/abi/compressors/subcompressors/withdrawal/upshiftWithdrawalSubcompressor.d.ts
CHANGED
|
@@ -135,6 +135,10 @@ export declare const upshiftWithdrawalSubcompressorAbi: readonly [{
|
|
|
135
135
|
readonly name: "withdrawalLength";
|
|
136
136
|
readonly type: "uint256";
|
|
137
137
|
readonly internalType: "uint256";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "maxWithdrawals";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
readonly internalType: "uint256";
|
|
138
142
|
}];
|
|
139
143
|
}];
|
|
140
144
|
readonly stateMutability: "view";
|
|
@@ -163,6 +163,10 @@ export declare const withdrawalCompressorAbi: readonly [{
|
|
|
163
163
|
readonly name: "withdrawalLength";
|
|
164
164
|
readonly type: "uint256";
|
|
165
165
|
readonly internalType: "uint256";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "maxWithdrawals";
|
|
168
|
+
readonly type: "uint256";
|
|
169
|
+
readonly internalType: "uint256";
|
|
166
170
|
}];
|
|
167
171
|
}];
|
|
168
172
|
readonly stateMutability: "view";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CuratorFilter, StrategiesCMListByChain, Strategy, StrategyCreditManagerView, StrategyDataSource } from "../types.js";
|
|
2
|
+
export interface GetStrategyCreditManagersListCoreArgs<CM extends StrategyCreditManagerView> {
|
|
3
|
+
strategies: Array<Strategy> | undefined;
|
|
4
|
+
source: StrategyDataSource<CM>;
|
|
5
|
+
curatorFilter: CuratorFilter;
|
|
6
|
+
}
|
|
7
|
+
export declare function getStrategyCreditManagersListCore<CM extends StrategyCreditManagerView>({ strategies, source, curatorFilter, }: GetStrategyCreditManagersListCoreArgs<CM>): StrategiesCMListByChain<CM> | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function getStrategyCreditManagersList<CM extends
|
|
1
|
+
import type { CuratorFilter, GearboxSDKFullStateByChain, Strategy, StrategyCreditManagerView } from "../types.js";
|
|
2
|
+
export declare function getStrategyCreditManagersList<CM extends StrategyCreditManagerView>(strategies: Array<Strategy> | undefined, sdkStateByChain: GearboxSDKFullStateByChain<CM> | undefined, curatorFilter: CuratorFilter): import("../types.js").StrategiesCMListByChain<CM> | undefined;
|
package/dist/types/common-utils/utils/strategies/credit-managers/get-strategy-credit-managers.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type {
|
|
3
|
-
interface GetStrategyCreditManagersProps<CM extends
|
|
2
|
+
import type { Strategy, StrategyCreditManagerView } from "../types.js";
|
|
3
|
+
interface GetStrategyCreditManagersProps<CM extends StrategyCreditManagerView> {
|
|
4
4
|
strategy: Pick<Strategy, "tokenOutAddress" | "creditManagers">;
|
|
5
5
|
allCreditManagers: Record<Address, CM>;
|
|
6
6
|
}
|
|
7
|
-
export declare function getStrategyCreditManagers<CM extends
|
|
7
|
+
export declare function getStrategyCreditManagers<CM extends StrategyCreditManagerView>({ strategy, allCreditManagers }: GetStrategyCreditManagersProps<CM>): Record<`0x${string}`, CM>;
|
|
8
8
|
export {};
|
package/dist/types/common-utils/utils/strategies/credit-managers/is-credit-manager-usable.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function isCreditManagerUsable(cm: Pick<
|
|
1
|
+
import type { StrategyCreditManagerView } from "../types.js";
|
|
2
|
+
export declare function isCreditManagerUsable(cm: Pick<StrategyCreditManagerView, "isBorrowingForbidden" | "version">): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppChains,
|
|
2
|
-
export declare function isStrategyEligible<CM extends
|
|
1
|
+
import type { AppChains, CuratorFilter, GearboxSDKFullState, NotValidatedStrategy, StrategyCreditManagerView } from "../types.js";
|
|
2
|
+
export declare function isStrategyEligible<CM extends StrategyCreditManagerView>(s: Pick<NotValidatedStrategy, "chainId" | "network" | "hideInProd" | "tokenOutAddress" | "showInMainApp">, allowedChains: AppChains, showHiddenStrategies: boolean, sdkStateByChain: Record<number, Pick<GearboxSDKFullState<CM>, "tokens"> | undefined> | undefined, curatorFilter: CuratorFilter): {
|
|
3
3
|
readonly isEligible: true;
|
|
4
4
|
readonly network: "Mainnet" | "Arbitrum" | "Optimism" | "Base" | "Sonic" | "MegaETH" | "Monad" | "Berachain" | "Avalanche" | "BNB" | "WorldChain" | "Etherlink" | "Hemi" | "Lisk" | "Plasma" | "Somnia";
|
|
5
5
|
} | {
|
package/dist/types/common-utils/utils/strategies/lists/get-available-and-disabled-strategies.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function getAvailableAndDisabledStrategies<CM extends
|
|
1
|
+
import type { CuratorFilter, StrategiesCMListByChain, Strategy, StrategyCreditManagerView } from "../types.js";
|
|
2
|
+
export declare function getAvailableAndDisabledStrategies<CM extends StrategyCreditManagerView>(list: Strategy[] | undefined | undefined, listCMs: StrategiesCMListByChain<CM> | undefined, curatorFilter: CuratorFilter | undefined): {
|
|
3
3
|
available: Error | import("../types.js").StrategyRecord | null;
|
|
4
4
|
disabled: import("../types.js").StrategyRecord;
|
|
5
5
|
availableList: Error | Strategy[] | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function getAvailableStrategies<CM extends
|
|
1
|
+
import type { StrategiesCMListByChain, Strategy, StrategyCreditManagerView, StrategyRecord } from "../types.js";
|
|
2
|
+
export declare function getAvailableStrategies<CM extends StrategyCreditManagerView>(list: Strategy[] | undefined | undefined, listCMs: StrategiesCMListByChain<CM> | undefined): {
|
|
3
3
|
record: StrategyRecord | null | Error;
|
|
4
4
|
list: Array<Strategy> | null | Error;
|
|
5
5
|
};
|