@gearbox-protocol/sdk 13.6.0-kyc.7 → 13.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/dev/AccountOpener.js +5 -45
- package/dist/cjs/plugins/adapters/abi/actionAbi.js +1 -1
- package/dist/cjs/plugins/adapters/abi/conctructorAbi.js +1 -1
- package/dist/cjs/plugins/adapters/createAdapter.js +1 -1
- package/dist/cjs/plugins/adapters/types.js +1 -1
- package/dist/cjs/plugins/apy/ApyPlugin.js +266 -0
- package/dist/cjs/plugins/apy/apy-cache.js +120 -0
- package/dist/cjs/plugins/apy/apy-parser.js +169 -0
- package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/constants.js +6 -3
- package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/index.js +14 -6
- package/dist/cjs/{sdk/market/kyc/securitize/types.js → plugins/apy/pool-apy-types.js} +2 -2
- package/dist/cjs/plugins/apy/pool-apy-utils.js +141 -0
- package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
- package/dist/cjs/sdk/GearboxSDK.js +5 -52
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +16 -324
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -7
- package/dist/cjs/sdk/base/TokensMeta.js +43 -32
- package/dist/cjs/sdk/base/token-types.js +0 -9
- package/dist/cjs/sdk/chain/chains.js +32 -17
- package/dist/cjs/sdk/constants/address-provider.js +0 -3
- package/dist/cjs/sdk/market/MarketRegister.js +116 -70
- package/dist/cjs/sdk/market/MarketSuite.js +0 -3
- package/dist/cjs/sdk/market/index.js +0 -2
- package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -11
- package/dist/cjs/sdk/market/pool/index.js +0 -2
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
- package/dist/cjs/sdk/options.js +1 -7
- package/dist/cjs/sdk/pools/PoolService.js +12 -104
- package/dist/cjs/sdk/utils/viem/index.js +0 -2
- package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +39 -2
- package/dist/esm/dev/AccountOpener.js +6 -47
- package/dist/esm/plugins/adapters/abi/actionAbi.js +1 -1
- package/dist/esm/plugins/adapters/abi/conctructorAbi.js +1 -1
- package/dist/esm/plugins/adapters/createAdapter.js +1 -1
- package/dist/esm/plugins/adapters/types.js +1 -1
- package/dist/esm/plugins/apy/ApyPlugin.js +255 -0
- package/dist/esm/plugins/apy/apy-cache.js +86 -0
- package/dist/esm/plugins/apy/apy-parser.js +143 -0
- package/dist/esm/plugins/apy/constants.js +6 -0
- package/dist/esm/plugins/apy/index.js +7 -0
- package/dist/esm/plugins/apy/pool-apy-utils.js +113 -0
- package/dist/esm/rewards/rewards/extra-apy.js +10 -8
- package/dist/esm/sdk/GearboxSDK.js +6 -56
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +17 -328
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -7
- package/dist/esm/sdk/base/TokensMeta.js +45 -32
- package/dist/esm/sdk/base/token-types.js +0 -6
- package/dist/esm/sdk/chain/chains.js +32 -17
- package/dist/esm/sdk/constants/address-provider.js +0 -2
- package/dist/esm/sdk/market/MarketRegister.js +118 -74
- package/dist/esm/sdk/market/MarketSuite.js +0 -3
- package/dist/esm/sdk/market/index.js +0 -1
- package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -11
- package/dist/esm/sdk/market/pool/index.js +0 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
- package/dist/esm/sdk/options.js +1 -7
- package/dist/esm/sdk/pools/PoolService.js +13 -109
- package/dist/esm/sdk/utils/viem/index.js +0 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +41 -2
- package/dist/types/plugins/adapters/types.d.ts +2 -2
- package/dist/types/plugins/apy/ApyPlugin.d.ts +46 -0
- package/dist/types/plugins/apy/apy-cache.d.ts +28 -0
- package/dist/types/plugins/apy/apy-parser.d.ts +5 -0
- package/dist/types/plugins/apy/constants.d.ts +2 -0
- package/dist/types/plugins/apy/index.d.ts +7 -0
- package/dist/types/plugins/apy/pool-apy-types.d.ts +41 -0
- package/dist/types/plugins/apy/pool-apy-utils.d.ts +73 -0
- package/dist/types/plugins/apy/types.d.ts +37 -0
- package/dist/types/rewards/rewards/api.d.ts +10 -1
- package/dist/types/rewards/rewards/common.d.ts +0 -10
- package/dist/types/rewards/rewards/extra-apy.d.ts +4 -6
- package/dist/types/sdk/GearboxSDK.d.ts +0 -7
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +2 -52
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +13 -93
- package/dist/types/sdk/base/TokensMeta.d.ts +3 -14
- package/dist/types/sdk/base/token-types.d.ts +4 -44
- package/dist/types/sdk/base/types.d.ts +11 -116
- package/dist/types/sdk/chain/chains.d.ts +5 -5
- package/dist/types/sdk/constants/address-provider.d.ts +0 -1
- package/dist/types/sdk/market/MarketRegister.d.ts +9 -6
- package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
- package/dist/types/sdk/market/index.d.ts +0 -1
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -3
- package/dist/types/sdk/market/oracle/types.d.ts +10 -3
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
- package/dist/types/sdk/market/pool/index.d.ts +0 -1
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
- package/dist/types/sdk/market/types.d.ts +1 -1
- package/dist/types/sdk/options.d.ts +0 -1
- package/dist/types/sdk/pools/PoolService.d.ts +8 -8
- package/dist/types/sdk/pools/types.d.ts +1 -1
- package/dist/types/sdk/types/state-human.d.ts +0 -2
- package/dist/types/sdk/types/state.d.ts +0 -5
- package/dist/types/sdk/utils/viem/index.d.ts +0 -1
- package/package.json +2 -3
- package/dist/cjs/abi/kyc/iDSRegistryService.js +0 -70
- package/dist/cjs/abi/kyc/iDSToken.js +0 -71
- package/dist/cjs/abi/kyc/iKYCCompressor.js +0 -196
- package/dist/cjs/abi/kyc/iKYCFactory.js +0 -122
- package/dist/cjs/abi/kyc/iKYCUnderlying.js +0 -401
- package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +0 -326
- package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +0 -319
- package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
- package/dist/cjs/plugins/pools-history/index.js +0 -24
- package/dist/cjs/sdk/market/kyc/KYCRegistry.js +0 -269
- package/dist/cjs/sdk/market/kyc/index.js +0 -26
- package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -244
- package/dist/cjs/sdk/market/kyc/types.js +0 -34
- package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +0 -38
- package/dist/esm/abi/kyc/iDSRegistryService.js +0 -46
- package/dist/esm/abi/kyc/iDSToken.js +0 -47
- package/dist/esm/abi/kyc/iKYCCompressor.js +0 -172
- package/dist/esm/abi/kyc/iKYCFactory.js +0 -98
- package/dist/esm/abi/kyc/iKYCUnderlying.js +0 -377
- package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +0 -302
- package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +0 -295
- package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
- package/dist/esm/plugins/pools-history/index.js +0 -2
- package/dist/esm/sdk/market/kyc/KYCRegistry.js +0 -253
- package/dist/esm/sdk/market/kyc/index.js +0 -3
- package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -220
- package/dist/esm/sdk/market/kyc/securitize/constants.js +0 -4
- package/dist/esm/sdk/market/kyc/securitize/index.js +0 -3
- package/dist/esm/sdk/market/kyc/types.js +0 -9
- package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +0 -14
- package/dist/types/abi/kyc/iDSRegistryService.d.ts +0 -71
- package/dist/types/abi/kyc/iDSToken.d.ts +0 -67
- package/dist/types/abi/kyc/iKYCCompressor.d.ts +0 -228
- package/dist/types/abi/kyc/iKYCFactory.d.ts +0 -139
- package/dist/types/abi/kyc/iKYCUnderlying.d.ts +0 -548
- package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +0 -404
- package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +0 -376
- package/dist/types/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
- package/dist/types/plugins/pools-history/index.d.ts +0 -2
- package/dist/types/plugins/pools-history/types.d.ts +0 -9
- package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +0 -52
- package/dist/types/sdk/market/kyc/index.d.ts +0 -3
- package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +0 -428
- package/dist/types/sdk/market/kyc/securitize/constants.d.ts +0 -1
- package/dist/types/sdk/market/kyc/securitize/index.d.ts +0 -3
- package/dist/types/sdk/market/kyc/securitize/types.d.ts +0 -127
- package/dist/types/sdk/market/kyc/types.d.ts +0 -170
- package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +0 -28
- /package/dist/cjs/plugins/{pools-history → apy}/package.json +0 -0
- /package/dist/cjs/plugins/{pools-history → apy}/types.js +0 -0
- /package/dist/esm/plugins/{pools-history → apy}/package.json +0 -0
- /package/dist/esm/plugins/{pools-history/types.js → apy/pool-apy-types.js} +0 -0
- /package/dist/esm/{sdk/market/kyc/securitize → plugins/apy}/types.js +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
class ApyOutputCache {
|
|
3
|
+
static #instances = /* @__PURE__ */ new Map();
|
|
4
|
+
#url;
|
|
5
|
+
#ttlMs;
|
|
6
|
+
#cache;
|
|
7
|
+
#pending;
|
|
8
|
+
#logger;
|
|
9
|
+
constructor(url, ttlMs, logger) {
|
|
10
|
+
this.#url = url;
|
|
11
|
+
this.#ttlMs = ttlMs;
|
|
12
|
+
this.#logger = logger;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns a shared cache instance for the given URL.
|
|
16
|
+
* The same instance is reused across all callers with identical URL.
|
|
17
|
+
*/
|
|
18
|
+
static get(url, ttlMs, logger) {
|
|
19
|
+
let instance = ApyOutputCache.#instances.get(url);
|
|
20
|
+
if (!instance) {
|
|
21
|
+
instance = new ApyOutputCache(url, ttlMs, logger);
|
|
22
|
+
ApyOutputCache.#instances.set(url, instance);
|
|
23
|
+
}
|
|
24
|
+
if (logger) {
|
|
25
|
+
instance.#logger = logger;
|
|
26
|
+
}
|
|
27
|
+
return instance;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns cached Output if fresh, otherwise fetches from the network.
|
|
31
|
+
* Concurrent calls are de-duplicated.
|
|
32
|
+
*/
|
|
33
|
+
async fetch() {
|
|
34
|
+
if (this.#cache && Date.now() - this.#cache.fetchedAt < this.#ttlMs) {
|
|
35
|
+
this.#logger?.debug("apy cache: TTL still valid, returning cached data");
|
|
36
|
+
return this.#cache.data;
|
|
37
|
+
}
|
|
38
|
+
if (this.#pending) {
|
|
39
|
+
this.#logger?.debug("apy cache: request in flight, waiting");
|
|
40
|
+
return this.#pending;
|
|
41
|
+
}
|
|
42
|
+
this.#pending = this.#doFetch();
|
|
43
|
+
try {
|
|
44
|
+
return await this.#pending;
|
|
45
|
+
} finally {
|
|
46
|
+
this.#pending = void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async #doFetch() {
|
|
50
|
+
try {
|
|
51
|
+
const headers = {};
|
|
52
|
+
if (this.#cache?.etag) {
|
|
53
|
+
headers["If-None-Match"] = this.#cache.etag;
|
|
54
|
+
}
|
|
55
|
+
const response = await axios.get(this.#url, {
|
|
56
|
+
headers,
|
|
57
|
+
validateStatus: (status) => status === 200 || status === 304
|
|
58
|
+
});
|
|
59
|
+
if (response.status === 304 && this.#cache) {
|
|
60
|
+
this.#cache.fetchedAt = Date.now();
|
|
61
|
+
this.#logger?.debug("apy cache: 304 Not Modified, extended TTL");
|
|
62
|
+
return this.#cache.data;
|
|
63
|
+
}
|
|
64
|
+
const etag = response.headers["etag"];
|
|
65
|
+
this.#cache = {
|
|
66
|
+
data: response.data,
|
|
67
|
+
etag,
|
|
68
|
+
fetchedAt: Date.now()
|
|
69
|
+
};
|
|
70
|
+
this.#logger?.debug(
|
|
71
|
+
`apy cache: fetched fresh data (timestamp: ${response.data.timestamp})`
|
|
72
|
+
);
|
|
73
|
+
return response.data;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
this.#logger?.error(e, "apy cache: fetch failed");
|
|
76
|
+
return this.#cache?.data;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Evicts all cached entries. Mainly useful for tests. */
|
|
80
|
+
static clearAll() {
|
|
81
|
+
ApyOutputCache.#instances.clear();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
ApyOutputCache
|
|
86
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { PERCENTAGE_FACTOR } from "../../sdk/index.js";
|
|
2
|
+
function numberToAPY(baseApy) {
|
|
3
|
+
return Math.round(baseApy * Number(PERCENTAGE_FACTOR));
|
|
4
|
+
}
|
|
5
|
+
function parseGearStats(output) {
|
|
6
|
+
const d = output.gearApy?.status === "ok" ? output.gearApy.data : void 0;
|
|
7
|
+
if (!d) return null;
|
|
8
|
+
return {
|
|
9
|
+
base: numberToAPY(d.base ?? 0),
|
|
10
|
+
crv: numberToAPY(d.crv ?? 0),
|
|
11
|
+
gear: numberToAPY(d.gear ?? 0),
|
|
12
|
+
gearPrice: d.gearPrice ?? 0
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function parseNetworkApy(apyResp, poolResp) {
|
|
16
|
+
const baseAPYList = {};
|
|
17
|
+
const extraCollateralAPYList = {};
|
|
18
|
+
const basePointsList = {};
|
|
19
|
+
const extraCollateralPointsList = {};
|
|
20
|
+
const tokenExtraRewardsList = {};
|
|
21
|
+
const apyData = apyResp?.status === "ok" ? apyResp.data : void 0;
|
|
22
|
+
for (const d of apyData ?? []) {
|
|
23
|
+
const tokenAddress = d.address.toLowerCase();
|
|
24
|
+
const tokenSymbol = d.symbol;
|
|
25
|
+
const apy = d.rewards.apy?.[0];
|
|
26
|
+
if (apy) {
|
|
27
|
+
baseAPYList[tokenAddress] = numberToAPY(apy.value ?? 0);
|
|
28
|
+
}
|
|
29
|
+
const points = d.rewards.points?.[0];
|
|
30
|
+
if (points) {
|
|
31
|
+
basePointsList[tokenAddress] = {
|
|
32
|
+
address: tokenAddress,
|
|
33
|
+
symbol: tokenSymbol,
|
|
34
|
+
rewards: points.rewards.map((p) => ({
|
|
35
|
+
...p,
|
|
36
|
+
multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
|
|
37
|
+
})),
|
|
38
|
+
debtRewards: points.debtRewards?.map((p) => ({
|
|
39
|
+
...p,
|
|
40
|
+
cm: (p.cm || "").toLowerCase(),
|
|
41
|
+
multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
|
|
42
|
+
}))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const extraRewards = d.rewards.extraRewards;
|
|
46
|
+
if (extraRewards && extraRewards.length > 0) {
|
|
47
|
+
tokenExtraRewardsList[tokenAddress] = extraRewards.map((r) => ({
|
|
48
|
+
address: tokenAddress,
|
|
49
|
+
symbol: r.rewardSymbol,
|
|
50
|
+
rewardToken: r.rewardToken.toLowerCase(),
|
|
51
|
+
rewardSymbol: r.rewardSymbol,
|
|
52
|
+
token: r.rewardToken.toLowerCase(),
|
|
53
|
+
finished: BigInt(r.finished || 0),
|
|
54
|
+
duration: BigInt(r.duration || 0),
|
|
55
|
+
reward: BigInt(r.reward || 0),
|
|
56
|
+
balance: BigInt(r.balance || 0)
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
const ecApy = d.rewards.extraCollateralAPY;
|
|
60
|
+
if (ecApy && ecApy.length > 0) {
|
|
61
|
+
for (const ea of ecApy) {
|
|
62
|
+
const pool = ea.pool.toLowerCase();
|
|
63
|
+
if (!extraCollateralAPYList[pool]) extraCollateralAPYList[pool] = {};
|
|
64
|
+
extraCollateralAPYList[pool][tokenAddress] = {
|
|
65
|
+
...ea,
|
|
66
|
+
address: tokenAddress,
|
|
67
|
+
symbol: tokenSymbol,
|
|
68
|
+
pool,
|
|
69
|
+
value: numberToAPY(ea.value ?? 0)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const ecPoints = d.rewards.extraCollateralPoints;
|
|
74
|
+
if (ecPoints && ecPoints.length > 0) {
|
|
75
|
+
for (const ea of ecPoints) {
|
|
76
|
+
const pool = ea.pool.toLowerCase();
|
|
77
|
+
if (!extraCollateralPointsList[pool])
|
|
78
|
+
extraCollateralPointsList[pool] = {};
|
|
79
|
+
extraCollateralPointsList[pool][tokenAddress] = {
|
|
80
|
+
address: tokenAddress,
|
|
81
|
+
symbol: tokenSymbol,
|
|
82
|
+
rewards: ea.rewards.map((p) => ({
|
|
83
|
+
...p,
|
|
84
|
+
multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
|
|
85
|
+
})),
|
|
86
|
+
debtRewards: ea.debtRewards?.map((p) => ({
|
|
87
|
+
...p,
|
|
88
|
+
cm: (p.cm || "").toLowerCase(),
|
|
89
|
+
multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
|
|
90
|
+
}))
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const poolRewardsList = {};
|
|
96
|
+
const poolExternalAPYList = {};
|
|
97
|
+
const poolExtraAPYList = {};
|
|
98
|
+
const poolData = poolResp?.status === "ok" ? poolResp.data : void 0;
|
|
99
|
+
for (const r of poolData ?? []) {
|
|
100
|
+
const pool = (r.pool || "").toLowerCase();
|
|
101
|
+
const points = r.rewards.points;
|
|
102
|
+
if (points && points.length > 0) {
|
|
103
|
+
poolRewardsList[pool] = points.map((p) => ({
|
|
104
|
+
...p,
|
|
105
|
+
token: p.token.toLowerCase(),
|
|
106
|
+
pool,
|
|
107
|
+
amount: BigInt(p.amount || 0)
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
const externalAPY = r.rewards.externalAPY;
|
|
111
|
+
if (externalAPY && externalAPY.length > 0) {
|
|
112
|
+
poolExternalAPYList[pool] = externalAPY.map((ex) => ({ ...ex, pool }));
|
|
113
|
+
}
|
|
114
|
+
const extraAPY = r.rewards.extraAPY;
|
|
115
|
+
if (extraAPY && extraAPY.length > 0) {
|
|
116
|
+
poolExtraAPYList[extraAPY[0].token.toLowerCase()] = extraAPY.map((ex) => ({
|
|
117
|
+
...ex,
|
|
118
|
+
token: ex.token.toLowerCase(),
|
|
119
|
+
rewardToken: ex.rewardToken.toLowerCase()
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const allResponses = [apyResp, poolResp];
|
|
124
|
+
const allErrors = allResponses.filter((r) => r?.status === "error");
|
|
125
|
+
if (allResponses.length > 0 && allErrors.length === allResponses.length) {
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
apyList: Object.keys(baseAPYList).length > 0 ? baseAPYList : void 0,
|
|
130
|
+
extraCollateralAPYList: Object.keys(extraCollateralAPYList).length > 0 ? extraCollateralAPYList : void 0,
|
|
131
|
+
pointsList: Object.keys(basePointsList).length > 0 ? basePointsList : void 0,
|
|
132
|
+
extraCollateralPointsList: Object.keys(extraCollateralPointsList).length > 0 ? extraCollateralPointsList : void 0,
|
|
133
|
+
poolRewardsList: Object.keys(poolRewardsList).length > 0 ? poolRewardsList : void 0,
|
|
134
|
+
tokenExtraRewardsList: Object.keys(tokenExtraRewardsList).length > 0 ? tokenExtraRewardsList : void 0,
|
|
135
|
+
poolExternalAPYList: Object.keys(poolExternalAPYList).length > 0 ? poolExternalAPYList : void 0,
|
|
136
|
+
poolExtraAPYList: Object.keys(poolExtraAPYList).length > 0 ? poolExtraAPYList : void 0
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
numberToAPY,
|
|
141
|
+
parseGearStats,
|
|
142
|
+
parseNetworkApy
|
|
143
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { PERCENTAGE_FACTOR, RAY } from "../../sdk/constants/index.js";
|
|
2
|
+
import { formatBN, rayToNumber } from "../../sdk/utils/formatter.js";
|
|
3
|
+
const SCALE = 1000000n;
|
|
4
|
+
const WEEKS_PER_YEAR = 54n;
|
|
5
|
+
function getPoolExtraAPY(lookupAddresses, poolExtraAPYList) {
|
|
6
|
+
if (!poolExtraAPYList) return [];
|
|
7
|
+
const result = [];
|
|
8
|
+
for (const addr of lookupAddresses) {
|
|
9
|
+
const extra = poolExtraAPYList[addr.toLowerCase()];
|
|
10
|
+
if (extra) {
|
|
11
|
+
result.push(...extra);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
function calculateSupplyApy7d(currentDieselRate, currentSupplyRate, dieselRate7DAgo) {
|
|
17
|
+
if (dieselRate7DAgo > currentDieselRate) {
|
|
18
|
+
return rayToNumber(currentSupplyRate * SCALE) / Number(PERCENTAGE_FACTOR);
|
|
19
|
+
}
|
|
20
|
+
const apy = (currentDieselRate * RAY / dieselRate7DAgo - RAY) * WEEKS_PER_YEAR;
|
|
21
|
+
return rayToNumber(apy * SCALE) / Number(PERCENTAGE_FACTOR);
|
|
22
|
+
}
|
|
23
|
+
function calculatePoolFullAPY({
|
|
24
|
+
depositAPY,
|
|
25
|
+
underlyingAPY,
|
|
26
|
+
extraAPY,
|
|
27
|
+
currentExternalList
|
|
28
|
+
}) {
|
|
29
|
+
const baseAPY = [
|
|
30
|
+
{ type: "supplyAPY", apy: depositAPY },
|
|
31
|
+
...underlyingAPY > 0 ? [
|
|
32
|
+
{
|
|
33
|
+
type: "tokenYield",
|
|
34
|
+
apy: Number(underlyingAPY) / Number(PERCENTAGE_FACTOR)
|
|
35
|
+
}
|
|
36
|
+
] : []
|
|
37
|
+
];
|
|
38
|
+
const filteredExtra = [...extraAPY ?? []].filter((r) => r.apy > 0);
|
|
39
|
+
const baseAPYTotal = baseAPY.reduce((s, r) => s + (r.apy || 0), 0);
|
|
40
|
+
const extraAPYTotal = filteredExtra.reduce((s, r) => s + (r.apy || 0), 0);
|
|
41
|
+
const total = baseAPYTotal + extraAPYTotal;
|
|
42
|
+
const externalAPY = resolveExternalAPY(currentExternalList, total);
|
|
43
|
+
return {
|
|
44
|
+
totalAPY: total,
|
|
45
|
+
baseAPY,
|
|
46
|
+
extraAPY: filteredExtra,
|
|
47
|
+
extraAPYTotal,
|
|
48
|
+
externalAPY
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function resolveExternalAPY(list, baseTotal) {
|
|
52
|
+
const first = list?.[0];
|
|
53
|
+
if (!first) return void 0;
|
|
54
|
+
return {
|
|
55
|
+
...first,
|
|
56
|
+
totalValue: baseTotal + first.value
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function calculatePoolFullAPY7DAgo({
|
|
60
|
+
supplyAPY7DAgo,
|
|
61
|
+
depositAPY,
|
|
62
|
+
poolAPY
|
|
63
|
+
}) {
|
|
64
|
+
const {
|
|
65
|
+
baseAPY = [],
|
|
66
|
+
extraAPYTotal = 0,
|
|
67
|
+
extraAPY = [],
|
|
68
|
+
externalAPY
|
|
69
|
+
} = poolAPY ?? {};
|
|
70
|
+
const base = [
|
|
71
|
+
{ apy: supplyAPY7DAgo || depositAPY, type: "supplyAPY" },
|
|
72
|
+
...baseAPY.filter((r) => r.type !== "supplyAPY")
|
|
73
|
+
];
|
|
74
|
+
const baseTotal = base.reduce((acc, r) => acc + r.apy, 0);
|
|
75
|
+
const total = baseTotal + extraAPYTotal;
|
|
76
|
+
return {
|
|
77
|
+
totalAPY: total,
|
|
78
|
+
extraAPYTotal,
|
|
79
|
+
baseAPY: base,
|
|
80
|
+
extraAPY,
|
|
81
|
+
externalAPY,
|
|
82
|
+
loading7DAgo: supplyAPY7DAgo === void 0
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function calculatePoolPoints({
|
|
86
|
+
poolTokenSymbol,
|
|
87
|
+
points,
|
|
88
|
+
tokensList
|
|
89
|
+
}) {
|
|
90
|
+
return points?.map(({ info, points: pts }) => {
|
|
91
|
+
const { decimals = 18 } = tokensList.get(info.token) || {};
|
|
92
|
+
const amount = formatBN(pts, decimals);
|
|
93
|
+
const { name = "Points", duration } = info ?? {};
|
|
94
|
+
return {
|
|
95
|
+
reward: info,
|
|
96
|
+
name,
|
|
97
|
+
amount,
|
|
98
|
+
tokenTitle: poolTokenSymbol,
|
|
99
|
+
fullTip: [
|
|
100
|
+
`${amount} ${name}`,
|
|
101
|
+
...duration ? [duration] : [],
|
|
102
|
+
...poolTokenSymbol ? [poolTokenSymbol] : []
|
|
103
|
+
].join(" per ")
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
calculatePoolFullAPY,
|
|
109
|
+
calculatePoolFullAPY7DAgo,
|
|
110
|
+
calculatePoolPoints,
|
|
111
|
+
calculateSupplyApy7d,
|
|
112
|
+
getPoolExtraAPY
|
|
113
|
+
};
|
|
@@ -52,11 +52,13 @@ class PoolPointsAPI {
|
|
|
52
52
|
tokensList
|
|
53
53
|
}) {
|
|
54
54
|
const r = pools.reduce((acc, p) => {
|
|
55
|
-
const
|
|
55
|
+
const poolAddress = p.pool.pool.address.toLowerCase();
|
|
56
|
+
const pointsInfo = poolRewards[poolAddress] || [];
|
|
56
57
|
const poolPointsList = pointsInfo.reduce(
|
|
57
58
|
(acc2, pointsInfo2) => {
|
|
58
|
-
const {
|
|
59
|
-
const
|
|
59
|
+
const { addr: tokenAddress } = tokensList.get(pointsInfo2.token) || {};
|
|
60
|
+
const tokenAddressLower = (tokenAddress || "").toLowerCase();
|
|
61
|
+
const tokenBalance = totalTokenBalances[tokenAddressLower];
|
|
60
62
|
const points = PoolPointsAPI.getPoolTokenPoints(
|
|
61
63
|
tokenBalance,
|
|
62
64
|
p,
|
|
@@ -74,22 +76,22 @@ class PoolPointsAPI {
|
|
|
74
76
|
},
|
|
75
77
|
[]
|
|
76
78
|
);
|
|
77
|
-
acc[
|
|
79
|
+
acc[poolAddress] = poolPointsList;
|
|
78
80
|
return acc;
|
|
79
81
|
}, {});
|
|
80
82
|
return r;
|
|
81
83
|
}
|
|
82
84
|
static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
|
|
83
|
-
if (pool.expectedLiquidity <= 0) return 0n;
|
|
85
|
+
if (pool.pool.pool.expectedLiquidity <= 0) return 0n;
|
|
84
86
|
if (pointsInfo.estimation === "relative" && !tokenBalanceInPool)
|
|
85
87
|
return null;
|
|
86
|
-
const { decimals = 18 } = tokensList
|
|
88
|
+
const { decimals = 18 } = tokensList.get(pointsInfo.token) || {};
|
|
87
89
|
const targetFactor = 10n ** BigInt(decimals);
|
|
88
90
|
const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
|
|
89
91
|
if (pointsInfo.estimation === "absolute") return defaultPoints;
|
|
90
|
-
const { decimals: underlyingDecimals = 18 } = tokensList
|
|
92
|
+
const { decimals: underlyingDecimals = 18 } = tokensList.get(pool.pool.pool.underlying) || {};
|
|
91
93
|
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
92
|
-
const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
94
|
+
const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.pool.pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
93
95
|
return BigIntMath.min(points, defaultPoints);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
VERSION_RANGE_310
|
|
17
17
|
} from "./constants/index.js";
|
|
18
18
|
import { createAddressProvider, hydrateAddressProvider } from "./core/index.js";
|
|
19
|
-
import { KYCRegistry } from "./market/kyc/index.js";
|
|
20
19
|
import { MarketRegister } from "./market/MarketRegister.js";
|
|
21
20
|
import { PriceFeedRegister } from "./market/pricefeeds/index.js";
|
|
22
21
|
import {
|
|
@@ -25,10 +24,7 @@ import {
|
|
|
25
24
|
import { createRouter } from "./router/index.js";
|
|
26
25
|
import { formatTimestamp, TypedObjectUtils, toAddress } from "./utils/index.js";
|
|
27
26
|
import { Hooks } from "./utils/internal/index.js";
|
|
28
|
-
import {
|
|
29
|
-
executeDelegatedMulticalls,
|
|
30
|
-
getLogsSafe
|
|
31
|
-
} from "./utils/viem/index.js";
|
|
27
|
+
import { getLogsSafe } from "./utils/viem/index.js";
|
|
32
28
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
33
29
|
const STATE_VERSION = 1;
|
|
34
30
|
function createClient(opts, network) {
|
|
@@ -81,7 +77,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
81
77
|
#addressProvider;
|
|
82
78
|
#attachConfig;
|
|
83
79
|
#marketRegister;
|
|
84
|
-
#kyc;
|
|
85
80
|
#priceFeeds;
|
|
86
81
|
/**
|
|
87
82
|
* Gas limit applied to read-only `eth_call` requests.
|
|
@@ -126,7 +121,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
126
121
|
ignoreUpdateablePrices,
|
|
127
122
|
ignoreMarkets,
|
|
128
123
|
marketConfigurators: mcs,
|
|
129
|
-
kycFactories: kfs,
|
|
130
124
|
strictContractTypes,
|
|
131
125
|
gasLimit
|
|
132
126
|
} = options;
|
|
@@ -136,7 +130,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
136
130
|
addressProvider = ADDRESS_PROVIDER_V310;
|
|
137
131
|
}
|
|
138
132
|
const marketConfigurators = mcs ?? TypedObjectUtils.keys(client.chain.defaultMarketConfigurators);
|
|
139
|
-
const kycFactories = kfs ?? client.chain.kycFactories;
|
|
140
133
|
return new GearboxSDK({
|
|
141
134
|
client,
|
|
142
135
|
logger,
|
|
@@ -149,7 +142,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
149
142
|
ignoreUpdateablePrices,
|
|
150
143
|
ignoreMarkets,
|
|
151
144
|
marketConfigurators,
|
|
152
|
-
kycFactories,
|
|
153
145
|
redstone,
|
|
154
146
|
pyth
|
|
155
147
|
});
|
|
@@ -189,7 +181,7 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
189
181
|
plugin.sdk = this;
|
|
190
182
|
}
|
|
191
183
|
if (options.gasLimit !== null) {
|
|
192
|
-
this.gasLimit = options.gasLimit ||
|
|
184
|
+
this.gasLimit = options.gasLimit || getChain(this.networkType).gasLimit;
|
|
193
185
|
}
|
|
194
186
|
}
|
|
195
187
|
async #attach(opts) {
|
|
@@ -199,7 +191,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
199
191
|
ignoreUpdateablePrices,
|
|
200
192
|
ignoreMarkets,
|
|
201
193
|
marketConfigurators,
|
|
202
|
-
kycFactories,
|
|
203
194
|
redstone,
|
|
204
195
|
pyth
|
|
205
196
|
} = opts;
|
|
@@ -210,7 +201,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
210
201
|
chainId: this.chainId,
|
|
211
202
|
addressProvider,
|
|
212
203
|
marketConfigurators,
|
|
213
|
-
kycFactories,
|
|
214
204
|
blockNumber,
|
|
215
205
|
ignoreMarkets
|
|
216
206
|
},
|
|
@@ -245,34 +235,10 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
245
235
|
);
|
|
246
236
|
await this.#addressProvider.syncState(this.currentBlock);
|
|
247
237
|
this.#marketRegister = new MarketRegister(this, ignoreMarkets);
|
|
248
|
-
this.#
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
);
|
|
253
|
-
} else {
|
|
254
|
-
const delegated = [
|
|
255
|
-
...this.#marketRegister.getLoadMulticalls(marketConfigurators),
|
|
256
|
-
...this.#kyc.getLoadMulticalls(marketConfigurators, kycFactories)
|
|
257
|
-
];
|
|
258
|
-
let txs = [];
|
|
259
|
-
if (!ignoreUpdateablePrices) {
|
|
260
|
-
const updatables = await this.#priceFeeds.getPartialUpdatablePriceFeeds(
|
|
261
|
-
marketConfigurators
|
|
262
|
-
);
|
|
263
|
-
const updates = await this.#priceFeeds.generatePriceFeedsUpdateTxs(updatables);
|
|
264
|
-
txs = updates.txs;
|
|
265
|
-
}
|
|
266
|
-
this.logger?.debug(
|
|
267
|
-
{ configurators: marketConfigurators },
|
|
268
|
-
`calling getMarkets with ${txs.length} price updates in block ${this.currentBlock}`
|
|
269
|
-
);
|
|
270
|
-
await executeDelegatedMulticalls(this.client, delegated, {
|
|
271
|
-
priceUpdates: txs,
|
|
272
|
-
blockNumber: this.currentBlock,
|
|
273
|
-
gas: this.gasLimit
|
|
274
|
-
});
|
|
275
|
-
}
|
|
238
|
+
await this.#marketRegister.loadMarkets(
|
|
239
|
+
marketConfigurators,
|
|
240
|
+
ignoreUpdateablePrices
|
|
241
|
+
);
|
|
276
242
|
const pluginsList = TypedObjectUtils.entries(this.plugins);
|
|
277
243
|
const pluginResponse = await Promise.allSettled(
|
|
278
244
|
pluginsList.map(([name, plugin]) => {
|
|
@@ -318,15 +284,12 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
318
284
|
);
|
|
319
285
|
this.#marketRegister = new MarketRegister(this, ignoreMarkets);
|
|
320
286
|
this.#marketRegister.hydrate(state.markets);
|
|
321
|
-
this.#kyc = new KYCRegistry(this);
|
|
322
|
-
this.#kyc.setState(state.kyc);
|
|
323
287
|
this.#attachConfig = {
|
|
324
288
|
...opts,
|
|
325
289
|
addressProvider: this.addressProvider.address,
|
|
326
290
|
marketConfigurators: this.marketRegister.marketConfigurators.map(
|
|
327
291
|
(m) => m.address
|
|
328
292
|
),
|
|
329
|
-
kycFactories: this.kyc.factories.map((f) => f.address),
|
|
330
293
|
blockNumber: this.currentBlock
|
|
331
294
|
};
|
|
332
295
|
for (const [name, plugin] of TypedObjectUtils.entries(this.plugins)) {
|
|
@@ -410,7 +373,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
410
373
|
addressProviderV3: this.addressProvider.stateHuman(raw)
|
|
411
374
|
},
|
|
412
375
|
tokens: this.tokensMeta.values(),
|
|
413
|
-
kyc: this.kyc.stateHuman(raw),
|
|
414
376
|
plugins: Object.fromEntries(
|
|
415
377
|
TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [
|
|
416
378
|
name,
|
|
@@ -436,7 +398,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
436
398
|
timestamp: this.timestamp,
|
|
437
399
|
addressProvider: this.addressProvider.state,
|
|
438
400
|
markets: this.marketRegister.state,
|
|
439
|
-
kyc: this.kyc.state,
|
|
440
401
|
plugins: Object.fromEntries(
|
|
441
402
|
TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [
|
|
442
403
|
name,
|
|
@@ -633,17 +594,6 @@ class GearboxSDK extends ChainContractsRegister {
|
|
|
633
594
|
}
|
|
634
595
|
return this.#marketRegister;
|
|
635
596
|
}
|
|
636
|
-
/**
|
|
637
|
-
* KYC register for KYC-wrapped underlying tokens and factories.
|
|
638
|
-
*
|
|
639
|
-
* @throws If the SDK has not been attached or hydrated yet.
|
|
640
|
-
**/
|
|
641
|
-
get kyc() {
|
|
642
|
-
if (this.#kyc === void 0) {
|
|
643
|
-
throw ERR_NOT_ATTACHED;
|
|
644
|
-
}
|
|
645
|
-
return this.#kyc;
|
|
646
|
-
}
|
|
647
597
|
/**
|
|
648
598
|
* Resolves the appropriate router contract for a given credit manager,
|
|
649
599
|
* credit facade, or explicit version range.
|