@gearbox-protocol/sdk 3.0.0-next.259 → 3.0.0-next.260
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/lib/core/assets.d.ts +6 -1
- package/lib/core/assets.js +14 -1
- package/lib/gearboxRewards/apy.d.ts +4 -3
- package/lib/gearboxRewards/apy.js +12 -5
- package/package.json +1 -1
package/lib/core/assets.d.ts
CHANGED
|
@@ -25,9 +25,14 @@ export declare class AssetUtils {
|
|
|
25
25
|
static memoWrap: (unwrappedAddress: Address, wrappedAddress: Address, prices: Record<Address, bigint>, tokensList: Record<Address, TokenData>) => (assets: Array<Asset>) => WrapResult;
|
|
26
26
|
/**
|
|
27
27
|
* Sums the the second assets list into the first assets list
|
|
28
|
-
* Balances cant be negative;
|
|
28
|
+
* Balances cant be negative; creates new assets.
|
|
29
29
|
*/
|
|
30
30
|
static sumAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
|
|
31
|
+
/**
|
|
32
|
+
* Sums the the second assets list into the first assets list
|
|
33
|
+
* Balances cant be negative; doesn't create new assets.
|
|
34
|
+
*/
|
|
35
|
+
static addBalances<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
|
|
31
36
|
/**
|
|
32
37
|
* Subtracts the the second assets list from the first assets list
|
|
33
38
|
* Balances cant be negative; doesn't create new assets.
|
package/lib/core/assets.js
CHANGED
|
@@ -65,7 +65,7 @@ class AssetUtils {
|
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
67
|
* Sums the the second assets list into the first assets list
|
|
68
|
-
* Balances cant be negative;
|
|
68
|
+
* Balances cant be negative; creates new assets.
|
|
69
69
|
*/
|
|
70
70
|
static sumAssets(a, b) {
|
|
71
71
|
const aRecord = AssetUtils.constructAssetRecord(a);
|
|
@@ -82,6 +82,19 @@ class AssetUtils {
|
|
|
82
82
|
}, aRecord);
|
|
83
83
|
return Object.values(resRecord);
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Sums the the second assets list into the first assets list
|
|
87
|
+
* Balances cant be negative; doesn't create new assets.
|
|
88
|
+
*/
|
|
89
|
+
static addBalances(a, b) {
|
|
90
|
+
const bRecord = AssetUtils.constructAssetRecord(b);
|
|
91
|
+
return a.map(asset => {
|
|
92
|
+
const bAsset = bRecord[asset.token];
|
|
93
|
+
const { balance: bAmount = 0n } = bAsset || {};
|
|
94
|
+
const amountSum = (0, math_1.nonNegativeBn)(asset.balance) + (0, math_1.nonNegativeBn)(bAmount);
|
|
95
|
+
return { ...asset, balance: (0, math_1.nonNegativeBn)(amountSum) };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
85
98
|
/**
|
|
86
99
|
* Subtracts the the second assets list from the first assets list
|
|
87
100
|
* Balances cant be negative; doesn't create new assets.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
1
|
+
import { PartialRecord, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { Address } from "viem";
|
|
3
3
|
import { Asset } from "../core/assets";
|
|
4
4
|
import { PoolData } from "../core/pool";
|
|
@@ -19,8 +19,9 @@ interface CalculateV3PoolLmAPYProps {
|
|
|
19
19
|
}
|
|
20
20
|
export interface ExtraRewardApy {
|
|
21
21
|
token: Address;
|
|
22
|
-
|
|
22
|
+
balance: bigint | null;
|
|
23
23
|
apy: number;
|
|
24
|
+
rewardInfo: FarmInfo;
|
|
24
25
|
}
|
|
25
26
|
interface GetPoolExtraAPY_V3Props {
|
|
26
27
|
stakedDieselToken: Address | undefined;
|
|
@@ -35,7 +36,7 @@ interface GetPoolExtraAPY_V3Props {
|
|
|
35
36
|
interface GetCAExtraAPYProps {
|
|
36
37
|
assets: Array<Asset>;
|
|
37
38
|
supply: Record<Address, bigint> | Record<Address, Asset>;
|
|
38
|
-
rewardInfo:
|
|
39
|
+
rewardInfo: PartialRecord<SupportedToken, Array<FarmInfo>>;
|
|
39
40
|
currentTimestamp: number;
|
|
40
41
|
prices: Record<Address, bigint>;
|
|
41
42
|
tokensList: Record<Address, TokenData>;
|
|
@@ -43,7 +43,12 @@ class GearboxRewardsApy {
|
|
|
43
43
|
decimals: rewardDecimals,
|
|
44
44
|
},
|
|
45
45
|
}) / Number(sdk_gov_1.PERCENTAGE_FACTOR);
|
|
46
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
token: stakedDieselToken,
|
|
48
|
+
balance: null,
|
|
49
|
+
apy: r,
|
|
50
|
+
rewardInfo: rewardPoolsInfo,
|
|
51
|
+
};
|
|
47
52
|
}
|
|
48
53
|
static calculateAPY_V3({ info, supply, reward, currentTimestamp, }) {
|
|
49
54
|
const finished = info.finished <= currentTimestamp;
|
|
@@ -64,12 +69,13 @@ class GearboxRewardsApy {
|
|
|
64
69
|
static getCAExtraAPY_V3({ rewardInfo, assets, ...restProps }) {
|
|
65
70
|
const extra = assets.reduce((acc, asset) => {
|
|
66
71
|
const { token } = asset;
|
|
67
|
-
const
|
|
72
|
+
const { symbol } = restProps.tokensList[token] || {};
|
|
73
|
+
const info = rewardInfo[symbol || ""];
|
|
68
74
|
if (!info)
|
|
69
75
|
return acc;
|
|
70
76
|
const extra = info.map(inf => this.getCASingleExtraAPY_V3({
|
|
71
77
|
...restProps,
|
|
72
|
-
|
|
78
|
+
asset,
|
|
73
79
|
rewardInfo: inf,
|
|
74
80
|
}));
|
|
75
81
|
acc.push(...extra);
|
|
@@ -77,7 +83,8 @@ class GearboxRewardsApy {
|
|
|
77
83
|
}, []);
|
|
78
84
|
return extra;
|
|
79
85
|
}
|
|
80
|
-
static getCASingleExtraAPY_V3({
|
|
86
|
+
static getCASingleExtraAPY_V3({ asset, prices, rewardInfo, supply, tokensList, currentTokenData, currentTimestamp, }) {
|
|
87
|
+
const { token, balance } = asset;
|
|
81
88
|
const safeSupply = supply[token] ?? 0n;
|
|
82
89
|
const { decimals: tokenDecimals = 18 } = tokensList[token] || {};
|
|
83
90
|
const tokenPrice = prices[token] ?? 0n;
|
|
@@ -97,7 +104,7 @@ class GearboxRewardsApy {
|
|
|
97
104
|
decimals: rewardDecimals,
|
|
98
105
|
},
|
|
99
106
|
}) / Number(sdk_gov_1.PERCENTAGE_FACTOR);
|
|
100
|
-
return { token
|
|
107
|
+
return { token, balance, rewardInfo, apy: r };
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
110
|
exports.GearboxRewardsApy = GearboxRewardsApy;
|