@strkfarm/sdk 1.0.21 → 1.0.23
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/cli.js +53 -28
- package/dist/cli.mjs +53 -28
- package/dist/index.browser.global.js +60 -38
- package/dist/index.browser.mjs +60 -38
- package/dist/index.d.ts +4 -2
- package/dist/index.js +60 -38
- package/dist/index.mjs +60 -38
- package/package.json +2 -1
- package/src/dataTypes/_bignumber.ts +11 -7
- package/src/interfaces/common.ts +2 -1
- package/src/strategies/ekubo-cl-vault.ts +2 -1
- package/src/strategies/vesu-rebalance.ts +48 -31
package/dist/index.browser.mjs
CHANGED
|
@@ -15,26 +15,26 @@ var _Web3Number = class extends BigNumber {
|
|
|
15
15
|
return this.mul(10 ** this.decimals).toFixed(0);
|
|
16
16
|
}
|
|
17
17
|
multipliedBy(value) {
|
|
18
|
-
let _value = Number(value).toFixed(
|
|
18
|
+
let _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
19
19
|
return this.construct(this.mul(_value).toString(), this.decimals);
|
|
20
20
|
}
|
|
21
21
|
dividedBy(value) {
|
|
22
|
-
let _value = Number(value).toFixed(
|
|
22
|
+
let _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
23
23
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
24
24
|
}
|
|
25
25
|
plus(value) {
|
|
26
|
-
const _value = Number(value).toFixed(
|
|
26
|
+
const _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
27
27
|
return this.construct(this.add(_value).toString(), this.decimals);
|
|
28
28
|
}
|
|
29
29
|
minus(n, base) {
|
|
30
|
-
const _value = Number(n).toFixed(
|
|
30
|
+
const _value = Number(n).toFixed(this.maxToFixedDecimals());
|
|
31
31
|
return this.construct(super.minus(_value, base).toString(), this.decimals);
|
|
32
32
|
}
|
|
33
33
|
construct(value, decimals) {
|
|
34
34
|
return new this.constructor(value, decimals);
|
|
35
35
|
}
|
|
36
|
-
toString(
|
|
37
|
-
return super.
|
|
36
|
+
toString(decimals = this.maxToFixedDecimals()) {
|
|
37
|
+
return super.toFixed(decimals);
|
|
38
38
|
}
|
|
39
39
|
toJSON() {
|
|
40
40
|
return this.toString();
|
|
@@ -42,6 +42,9 @@ var _Web3Number = class extends BigNumber {
|
|
|
42
42
|
valueOf() {
|
|
43
43
|
return this.toString();
|
|
44
44
|
}
|
|
45
|
+
maxToFixedDecimals() {
|
|
46
|
+
return Math.min(this.decimals, 13);
|
|
47
|
+
}
|
|
45
48
|
};
|
|
46
49
|
BigNumber.config({ DECIMAL_PLACES: 18 });
|
|
47
50
|
_Web3Number.config({ DECIMAL_PLACES: 18 });
|
|
@@ -3710,7 +3713,9 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3710
3713
|
const totalAssets = (await this.getTVL()).amount;
|
|
3711
3714
|
const info = allowedPools.map(async (p) => {
|
|
3712
3715
|
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num2.getDecimalString(p.pool_id.address.toString()));
|
|
3713
|
-
const pool = pools.find((d) =>
|
|
3716
|
+
const pool = pools.find((d) => {
|
|
3717
|
+
return d.id == num2.getDecimalString(p.pool_id.address.toString());
|
|
3718
|
+
});
|
|
3714
3719
|
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3715
3720
|
let vTokenContract = new Contract4(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3716
3721
|
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
@@ -3758,11 +3763,13 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3758
3763
|
* Calculates the weighted average APY across all pools based on USD value.
|
|
3759
3764
|
* @returns {Promise<number>} The weighted average APY across all pools
|
|
3760
3765
|
*/
|
|
3761
|
-
netAPYGivenPools(pools) {
|
|
3762
|
-
const
|
|
3766
|
+
async netAPYGivenPools(pools) {
|
|
3767
|
+
const weightedApyNumerator = pools.reduce((acc, curr) => {
|
|
3763
3768
|
const weight = curr.current_weight;
|
|
3764
|
-
return acc + curr.APY.netApy *
|
|
3769
|
+
return acc + curr.APY.netApy * Number(curr.amount.toString());
|
|
3765
3770
|
}, 0);
|
|
3771
|
+
const totalAssets = (await this.getTVL()).amount;
|
|
3772
|
+
const weightedApy = weightedApyNumerator / Number(totalAssets.toString());
|
|
3766
3773
|
return weightedApy * (1 - this.metadata.additionalInfo.feeBps / 1e4);
|
|
3767
3774
|
}
|
|
3768
3775
|
/**
|
|
@@ -3791,14 +3798,21 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3791
3798
|
finalPools: []
|
|
3792
3799
|
};
|
|
3793
3800
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3794
|
-
|
|
3801
|
+
logger.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
3802
|
+
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
3803
|
+
assert(sumPools.lte(totalAssets.multipliedBy(1.00001).toString()), "Sum of pools.amount must be less than or equal to totalAssets");
|
|
3795
3804
|
const sortedPools = [...pools].sort((a, b) => b.APY.netApy - a.APY.netApy);
|
|
3796
3805
|
const targetAmounts = {};
|
|
3797
3806
|
let remainingAssets = totalAssets;
|
|
3807
|
+
logger.verbose(`Remaining assets: ${remainingAssets.toString()}`);
|
|
3798
3808
|
let isAnyPoolOverMaxWeight = false;
|
|
3799
3809
|
for (const pool of sortedPools) {
|
|
3800
|
-
const maxAmount = totalAssets.multipliedBy(pool.max_weight * 0.
|
|
3810
|
+
const maxAmount = totalAssets.multipliedBy(pool.max_weight * 0.98);
|
|
3801
3811
|
const targetAmount = remainingAssets.gte(maxAmount) ? maxAmount : remainingAssets;
|
|
3812
|
+
logger.verbose(`Target amount: ${targetAmount.toString()}`);
|
|
3813
|
+
logger.verbose(`Remaining assets: ${remainingAssets.toString()}`);
|
|
3814
|
+
logger.verbose(`Max amount: ${maxAmount.toString()}`);
|
|
3815
|
+
logger.verbose(`pool.max_weight: ${pool.max_weight}`);
|
|
3802
3816
|
targetAmounts[pool.pool_id.address.toString()] = targetAmount;
|
|
3803
3817
|
remainingAssets = remainingAssets.minus(targetAmount.toString());
|
|
3804
3818
|
if (pool.current_weight > pool.max_weight) {
|
|
@@ -3816,11 +3830,15 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3816
3830
|
isDeposit: change.gt(0)
|
|
3817
3831
|
};
|
|
3818
3832
|
});
|
|
3833
|
+
logger.verbose(`Changes: ${JSON.stringify(changes)}`);
|
|
3819
3834
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3820
3835
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3821
3836
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
3822
3837
|
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
3823
|
-
|
|
3838
|
+
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
3839
|
+
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
3840
|
+
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
3841
|
+
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
3824
3842
|
if (!hasChanges) throw new Error("No changes required");
|
|
3825
3843
|
const finalPools = pools.map((p) => {
|
|
3826
3844
|
const target = targetAmounts[p.pool_id.address.toString()] || Web3Number.fromWei("0", this.decimals());
|
|
@@ -3844,13 +3862,12 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3844
3862
|
async getRebalanceCall(pools, isOverWeightAdjustment) {
|
|
3845
3863
|
const actions = [];
|
|
3846
3864
|
pools.sort((a, b) => b.isDeposit ? -1 : 1);
|
|
3847
|
-
console.log("pools", pools);
|
|
3848
3865
|
pools.forEach((p) => {
|
|
3849
3866
|
if (p.changeAmt.eq(0)) return null;
|
|
3850
3867
|
actions.push({
|
|
3851
3868
|
pool_id: p.pool_id.address,
|
|
3852
3869
|
feature: new CairoCustomEnum(p.isDeposit ? { DEPOSIT: {} } : { WITHDRAW: {} }),
|
|
3853
|
-
token: this.asset().address,
|
|
3870
|
+
token: this.asset().address.address,
|
|
3854
3871
|
amount: uint2563.bnToUint256(p.changeAmt.multipliedBy(p.isDeposit ? 1 : -1).toWei())
|
|
3855
3872
|
});
|
|
3856
3873
|
});
|
|
@@ -3861,7 +3878,7 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3861
3878
|
return this.contract.populate("rebalance", [actions]);
|
|
3862
3879
|
}
|
|
3863
3880
|
async getInvestmentFlows(pools) {
|
|
3864
|
-
const netYield = this.netAPYGivenPools(pools);
|
|
3881
|
+
const netYield = await this.netAPYGivenPools(pools);
|
|
3865
3882
|
const baseFlow = {
|
|
3866
3883
|
title: "Your Deposit",
|
|
3867
3884
|
subItems: [{ key: `Net yield`, value: `${(netYield * 100).toFixed(2)}%` }],
|
|
@@ -3896,7 +3913,7 @@ var AUDIT_URL = "https://assets.strkfarm.com/strkfarm/audit_report_vesu_and_ekub
|
|
|
3896
3913
|
var VesuRebalanceStrategies = [{
|
|
3897
3914
|
name: "Vesu Fusion STRK",
|
|
3898
3915
|
description: _description.replace("{{TOKEN}}", "STRK"),
|
|
3899
|
-
address: ContractAddr.from("
|
|
3916
|
+
address: ContractAddr.from("0x7fb5bcb8525954a60fde4e8fb8220477696ce7117ef264775a1770e23571929"),
|
|
3900
3917
|
type: "ERC4626",
|
|
3901
3918
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "STRK")],
|
|
3902
3919
|
protocols: [_protocol],
|
|
@@ -3904,7 +3921,8 @@ var VesuRebalanceStrategies = [{
|
|
|
3904
3921
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
3905
3922
|
risk: {
|
|
3906
3923
|
riskFactor: _riskFactor,
|
|
3907
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
3924
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
3925
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
3908
3926
|
},
|
|
3909
3927
|
additionalInfo: {
|
|
3910
3928
|
feeBps: 1e3
|
|
@@ -3912,7 +3930,7 @@ var VesuRebalanceStrategies = [{
|
|
|
3912
3930
|
}, {
|
|
3913
3931
|
name: "Vesu Fusion ETH",
|
|
3914
3932
|
description: _description.replace("{{TOKEN}}", "ETH"),
|
|
3915
|
-
address: ContractAddr.from("
|
|
3933
|
+
address: ContractAddr.from("0x5eaf5ee75231cecf79921ff8ded4b5ffe96be718bcb3daf206690ad1a9ad0ca"),
|
|
3916
3934
|
type: "ERC4626",
|
|
3917
3935
|
auditUrl: AUDIT_URL,
|
|
3918
3936
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "ETH")],
|
|
@@ -3920,7 +3938,8 @@ var VesuRebalanceStrategies = [{
|
|
|
3920
3938
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
3921
3939
|
risk: {
|
|
3922
3940
|
riskFactor: _riskFactor,
|
|
3923
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
3941
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
3942
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
3924
3943
|
},
|
|
3925
3944
|
additionalInfo: {
|
|
3926
3945
|
feeBps: 1e3
|
|
@@ -3928,7 +3947,7 @@ var VesuRebalanceStrategies = [{
|
|
|
3928
3947
|
}, {
|
|
3929
3948
|
name: "Vesu Fusion USDC",
|
|
3930
3949
|
description: _description.replace("{{TOKEN}}", "USDC"),
|
|
3931
|
-
address: ContractAddr.from("
|
|
3950
|
+
address: ContractAddr.from("0xa858c97e9454f407d1bd7c57472fc8d8d8449a777c822b41d18e387816f29c"),
|
|
3932
3951
|
type: "ERC4626",
|
|
3933
3952
|
auditUrl: AUDIT_URL,
|
|
3934
3953
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "USDC")],
|
|
@@ -3936,26 +3955,28 @@ var VesuRebalanceStrategies = [{
|
|
|
3936
3955
|
maxTVL: Web3Number.fromWei("0", 6),
|
|
3937
3956
|
risk: {
|
|
3938
3957
|
riskFactor: _riskFactor,
|
|
3939
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
3958
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
3959
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
3960
|
+
},
|
|
3961
|
+
additionalInfo: {
|
|
3962
|
+
feeBps: 1e3
|
|
3963
|
+
}
|
|
3964
|
+
}, {
|
|
3965
|
+
name: "Vesu Fusion USDT",
|
|
3966
|
+
description: _description.replace("{{TOKEN}}", "USDT"),
|
|
3967
|
+
address: ContractAddr.from("0x115e94e722cfc4c77a2f15c4aefb0928c1c0029e5a57570df24c650cb7cec2c"),
|
|
3968
|
+
type: "ERC4626",
|
|
3969
|
+
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "USDT")],
|
|
3970
|
+
protocols: [_protocol],
|
|
3971
|
+
maxTVL: Web3Number.fromWei("0", 6),
|
|
3972
|
+
risk: {
|
|
3973
|
+
riskFactor: _riskFactor,
|
|
3974
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
3975
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
3940
3976
|
},
|
|
3941
3977
|
additionalInfo: {
|
|
3942
3978
|
feeBps: 1e3
|
|
3943
3979
|
}
|
|
3944
|
-
// }, {
|
|
3945
|
-
// name: 'Vesu Fusion USDT',
|
|
3946
|
-
// description: _description.replace('{{TOKEN}}', 'USDT'),
|
|
3947
|
-
// address: ContractAddr.from('0x778007f8136a5b827325d21613803e796bda4d676fbe1e34aeab0b2a2ec027f'),
|
|
3948
|
-
// type: 'ERC4626',
|
|
3949
|
-
// depositTokens: [Global.getDefaultTokens().find(t => t.symbol === 'USDT')!],
|
|
3950
|
-
// protocols: [_protocol],
|
|
3951
|
-
// maxTVL: Web3Number.fromWei('0', 6),
|
|
3952
|
-
// risk: {
|
|
3953
|
-
// riskFactor: _riskFactor,
|
|
3954
|
-
// netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
3955
|
-
// },
|
|
3956
|
-
// additionalInfo: {
|
|
3957
|
-
// feeBps: 1000,
|
|
3958
|
-
// },
|
|
3959
3980
|
// }, {
|
|
3960
3981
|
// name: 'Vesu Fusion WBTC',
|
|
3961
3982
|
// description: _description.replace('{{TOKEN}}', 'WBTC'),
|
|
@@ -9254,7 +9275,8 @@ var EkuboCLVaultStrategies = [{
|
|
|
9254
9275
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
9255
9276
|
risk: {
|
|
9256
9277
|
riskFactor: _riskFactor2,
|
|
9257
|
-
netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0)
|
|
9278
|
+
netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
|
|
9279
|
+
notARisks: getNoRiskTags(_riskFactor2)
|
|
9258
9280
|
},
|
|
9259
9281
|
additionalInfo: {
|
|
9260
9282
|
newBounds: {
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,10 @@ declare class _Web3Number<T extends _Web3Number<T>> extends BigNumber {
|
|
|
14
14
|
plus(value: string | number | T): T;
|
|
15
15
|
minus(n: number | string | T, base?: number): T;
|
|
16
16
|
protected construct(value: string | number, decimals: number): T;
|
|
17
|
-
toString(
|
|
17
|
+
toString(decimals?: number | undefined): string;
|
|
18
18
|
toJSON(): string;
|
|
19
19
|
valueOf(): string;
|
|
20
|
+
private maxToFixedDecimals;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
declare class Web3Number extends _Web3Number<Web3Number> {
|
|
@@ -97,6 +98,7 @@ interface IStrategyMetadata<T> {
|
|
|
97
98
|
risk: {
|
|
98
99
|
riskFactor: RiskFactor[];
|
|
99
100
|
netRisk: number;
|
|
101
|
+
notARisks: string[];
|
|
100
102
|
};
|
|
101
103
|
additionalInfo: T;
|
|
102
104
|
}
|
|
@@ -529,7 +531,7 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
|
|
|
529
531
|
* Calculates the weighted average APY across all pools based on USD value.
|
|
530
532
|
* @returns {Promise<number>} The weighted average APY across all pools
|
|
531
533
|
*/
|
|
532
|
-
netAPYGivenPools(pools: PoolInfoFull[]): number
|
|
534
|
+
netAPYGivenPools(pools: PoolInfoFull[]): Promise<number>;
|
|
533
535
|
/**
|
|
534
536
|
* Calculates optimal position changes to maximize APY while respecting max weights.
|
|
535
537
|
* The algorithm:
|
package/dist/index.js
CHANGED
|
@@ -86,26 +86,26 @@ var _Web3Number = class extends import_bignumber.default {
|
|
|
86
86
|
return this.mul(10 ** this.decimals).toFixed(0);
|
|
87
87
|
}
|
|
88
88
|
multipliedBy(value) {
|
|
89
|
-
let _value = Number(value).toFixed(
|
|
89
|
+
let _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
90
90
|
return this.construct(this.mul(_value).toString(), this.decimals);
|
|
91
91
|
}
|
|
92
92
|
dividedBy(value) {
|
|
93
|
-
let _value = Number(value).toFixed(
|
|
93
|
+
let _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
94
94
|
return this.construct(this.div(_value).toString(), this.decimals);
|
|
95
95
|
}
|
|
96
96
|
plus(value) {
|
|
97
|
-
const _value = Number(value).toFixed(
|
|
97
|
+
const _value = Number(value).toFixed(this.maxToFixedDecimals());
|
|
98
98
|
return this.construct(this.add(_value).toString(), this.decimals);
|
|
99
99
|
}
|
|
100
100
|
minus(n, base) {
|
|
101
|
-
const _value = Number(n).toFixed(
|
|
101
|
+
const _value = Number(n).toFixed(this.maxToFixedDecimals());
|
|
102
102
|
return this.construct(super.minus(_value, base).toString(), this.decimals);
|
|
103
103
|
}
|
|
104
104
|
construct(value, decimals) {
|
|
105
105
|
return new this.constructor(value, decimals);
|
|
106
106
|
}
|
|
107
|
-
toString(
|
|
108
|
-
return super.
|
|
107
|
+
toString(decimals = this.maxToFixedDecimals()) {
|
|
108
|
+
return super.toFixed(decimals);
|
|
109
109
|
}
|
|
110
110
|
toJSON() {
|
|
111
111
|
return this.toString();
|
|
@@ -113,6 +113,9 @@ var _Web3Number = class extends import_bignumber.default {
|
|
|
113
113
|
valueOf() {
|
|
114
114
|
return this.toString();
|
|
115
115
|
}
|
|
116
|
+
maxToFixedDecimals() {
|
|
117
|
+
return Math.min(this.decimals, 13);
|
|
118
|
+
}
|
|
116
119
|
};
|
|
117
120
|
import_bignumber.default.config({ DECIMAL_PLACES: 18 });
|
|
118
121
|
_Web3Number.config({ DECIMAL_PLACES: 18 });
|
|
@@ -3798,7 +3801,9 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3798
3801
|
const totalAssets = (await this.getTVL()).amount;
|
|
3799
3802
|
const info = allowedPools.map(async (p) => {
|
|
3800
3803
|
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === import_starknet7.num.getDecimalString(p.pool_id.address.toString()));
|
|
3801
|
-
const pool = pools.find((d) =>
|
|
3804
|
+
const pool = pools.find((d) => {
|
|
3805
|
+
return d.id == import_starknet7.num.getDecimalString(p.pool_id.address.toString());
|
|
3806
|
+
});
|
|
3802
3807
|
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3803
3808
|
let vTokenContract = new import_starknet7.Contract(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3804
3809
|
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
@@ -3846,11 +3851,13 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3846
3851
|
* Calculates the weighted average APY across all pools based on USD value.
|
|
3847
3852
|
* @returns {Promise<number>} The weighted average APY across all pools
|
|
3848
3853
|
*/
|
|
3849
|
-
netAPYGivenPools(pools) {
|
|
3850
|
-
const
|
|
3854
|
+
async netAPYGivenPools(pools) {
|
|
3855
|
+
const weightedApyNumerator = pools.reduce((acc, curr) => {
|
|
3851
3856
|
const weight = curr.current_weight;
|
|
3852
|
-
return acc + curr.APY.netApy *
|
|
3857
|
+
return acc + curr.APY.netApy * Number(curr.amount.toString());
|
|
3853
3858
|
}, 0);
|
|
3859
|
+
const totalAssets = (await this.getTVL()).amount;
|
|
3860
|
+
const weightedApy = weightedApyNumerator / Number(totalAssets.toString());
|
|
3854
3861
|
return weightedApy * (1 - this.metadata.additionalInfo.feeBps / 1e4);
|
|
3855
3862
|
}
|
|
3856
3863
|
/**
|
|
@@ -3879,14 +3886,21 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3879
3886
|
finalPools: []
|
|
3880
3887
|
};
|
|
3881
3888
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3882
|
-
|
|
3889
|
+
logger.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
3890
|
+
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
3891
|
+
assert(sumPools.lte(totalAssets.multipliedBy(1.00001).toString()), "Sum of pools.amount must be less than or equal to totalAssets");
|
|
3883
3892
|
const sortedPools = [...pools].sort((a, b) => b.APY.netApy - a.APY.netApy);
|
|
3884
3893
|
const targetAmounts = {};
|
|
3885
3894
|
let remainingAssets = totalAssets;
|
|
3895
|
+
logger.verbose(`Remaining assets: ${remainingAssets.toString()}`);
|
|
3886
3896
|
let isAnyPoolOverMaxWeight = false;
|
|
3887
3897
|
for (const pool of sortedPools) {
|
|
3888
|
-
const maxAmount = totalAssets.multipliedBy(pool.max_weight * 0.
|
|
3898
|
+
const maxAmount = totalAssets.multipliedBy(pool.max_weight * 0.98);
|
|
3889
3899
|
const targetAmount = remainingAssets.gte(maxAmount) ? maxAmount : remainingAssets;
|
|
3900
|
+
logger.verbose(`Target amount: ${targetAmount.toString()}`);
|
|
3901
|
+
logger.verbose(`Remaining assets: ${remainingAssets.toString()}`);
|
|
3902
|
+
logger.verbose(`Max amount: ${maxAmount.toString()}`);
|
|
3903
|
+
logger.verbose(`pool.max_weight: ${pool.max_weight}`);
|
|
3890
3904
|
targetAmounts[pool.pool_id.address.toString()] = targetAmount;
|
|
3891
3905
|
remainingAssets = remainingAssets.minus(targetAmount.toString());
|
|
3892
3906
|
if (pool.current_weight > pool.max_weight) {
|
|
@@ -3904,11 +3918,15 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3904
3918
|
isDeposit: change.gt(0)
|
|
3905
3919
|
};
|
|
3906
3920
|
});
|
|
3921
|
+
logger.verbose(`Changes: ${JSON.stringify(changes)}`);
|
|
3907
3922
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3908
3923
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
3909
3924
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
3910
3925
|
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
3911
|
-
|
|
3926
|
+
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
3927
|
+
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
3928
|
+
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
3929
|
+
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
3912
3930
|
if (!hasChanges) throw new Error("No changes required");
|
|
3913
3931
|
const finalPools = pools.map((p) => {
|
|
3914
3932
|
const target = targetAmounts[p.pool_id.address.toString()] || Web3Number.fromWei("0", this.decimals());
|
|
@@ -3932,13 +3950,12 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3932
3950
|
async getRebalanceCall(pools, isOverWeightAdjustment) {
|
|
3933
3951
|
const actions = [];
|
|
3934
3952
|
pools.sort((a, b) => b.isDeposit ? -1 : 1);
|
|
3935
|
-
console.log("pools", pools);
|
|
3936
3953
|
pools.forEach((p) => {
|
|
3937
3954
|
if (p.changeAmt.eq(0)) return null;
|
|
3938
3955
|
actions.push({
|
|
3939
3956
|
pool_id: p.pool_id.address,
|
|
3940
3957
|
feature: new import_starknet7.CairoCustomEnum(p.isDeposit ? { DEPOSIT: {} } : { WITHDRAW: {} }),
|
|
3941
|
-
token: this.asset().address,
|
|
3958
|
+
token: this.asset().address.address,
|
|
3942
3959
|
amount: import_starknet7.uint256.bnToUint256(p.changeAmt.multipliedBy(p.isDeposit ? 1 : -1).toWei())
|
|
3943
3960
|
});
|
|
3944
3961
|
});
|
|
@@ -3949,7 +3966,7 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3949
3966
|
return this.contract.populate("rebalance", [actions]);
|
|
3950
3967
|
}
|
|
3951
3968
|
async getInvestmentFlows(pools) {
|
|
3952
|
-
const netYield = this.netAPYGivenPools(pools);
|
|
3969
|
+
const netYield = await this.netAPYGivenPools(pools);
|
|
3953
3970
|
const baseFlow = {
|
|
3954
3971
|
title: "Your Deposit",
|
|
3955
3972
|
subItems: [{ key: `Net yield`, value: `${(netYield * 100).toFixed(2)}%` }],
|
|
@@ -3984,7 +4001,7 @@ var AUDIT_URL = "https://assets.strkfarm.com/strkfarm/audit_report_vesu_and_ekub
|
|
|
3984
4001
|
var VesuRebalanceStrategies = [{
|
|
3985
4002
|
name: "Vesu Fusion STRK",
|
|
3986
4003
|
description: _description.replace("{{TOKEN}}", "STRK"),
|
|
3987
|
-
address: ContractAddr.from("
|
|
4004
|
+
address: ContractAddr.from("0x7fb5bcb8525954a60fde4e8fb8220477696ce7117ef264775a1770e23571929"),
|
|
3988
4005
|
type: "ERC4626",
|
|
3989
4006
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "STRK")],
|
|
3990
4007
|
protocols: [_protocol],
|
|
@@ -3992,7 +4009,8 @@ var VesuRebalanceStrategies = [{
|
|
|
3992
4009
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
3993
4010
|
risk: {
|
|
3994
4011
|
riskFactor: _riskFactor,
|
|
3995
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
4012
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
4013
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
3996
4014
|
},
|
|
3997
4015
|
additionalInfo: {
|
|
3998
4016
|
feeBps: 1e3
|
|
@@ -4000,7 +4018,7 @@ var VesuRebalanceStrategies = [{
|
|
|
4000
4018
|
}, {
|
|
4001
4019
|
name: "Vesu Fusion ETH",
|
|
4002
4020
|
description: _description.replace("{{TOKEN}}", "ETH"),
|
|
4003
|
-
address: ContractAddr.from("
|
|
4021
|
+
address: ContractAddr.from("0x5eaf5ee75231cecf79921ff8ded4b5ffe96be718bcb3daf206690ad1a9ad0ca"),
|
|
4004
4022
|
type: "ERC4626",
|
|
4005
4023
|
auditUrl: AUDIT_URL,
|
|
4006
4024
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "ETH")],
|
|
@@ -4008,7 +4026,8 @@ var VesuRebalanceStrategies = [{
|
|
|
4008
4026
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
4009
4027
|
risk: {
|
|
4010
4028
|
riskFactor: _riskFactor,
|
|
4011
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
4029
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
4030
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
4012
4031
|
},
|
|
4013
4032
|
additionalInfo: {
|
|
4014
4033
|
feeBps: 1e3
|
|
@@ -4016,7 +4035,7 @@ var VesuRebalanceStrategies = [{
|
|
|
4016
4035
|
}, {
|
|
4017
4036
|
name: "Vesu Fusion USDC",
|
|
4018
4037
|
description: _description.replace("{{TOKEN}}", "USDC"),
|
|
4019
|
-
address: ContractAddr.from("
|
|
4038
|
+
address: ContractAddr.from("0xa858c97e9454f407d1bd7c57472fc8d8d8449a777c822b41d18e387816f29c"),
|
|
4020
4039
|
type: "ERC4626",
|
|
4021
4040
|
auditUrl: AUDIT_URL,
|
|
4022
4041
|
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "USDC")],
|
|
@@ -4024,26 +4043,28 @@ var VesuRebalanceStrategies = [{
|
|
|
4024
4043
|
maxTVL: Web3Number.fromWei("0", 6),
|
|
4025
4044
|
risk: {
|
|
4026
4045
|
riskFactor: _riskFactor,
|
|
4027
|
-
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0)
|
|
4046
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
4047
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
4048
|
+
},
|
|
4049
|
+
additionalInfo: {
|
|
4050
|
+
feeBps: 1e3
|
|
4051
|
+
}
|
|
4052
|
+
}, {
|
|
4053
|
+
name: "Vesu Fusion USDT",
|
|
4054
|
+
description: _description.replace("{{TOKEN}}", "USDT"),
|
|
4055
|
+
address: ContractAddr.from("0x115e94e722cfc4c77a2f15c4aefb0928c1c0029e5a57570df24c650cb7cec2c"),
|
|
4056
|
+
type: "ERC4626",
|
|
4057
|
+
depositTokens: [Global.getDefaultTokens().find((t) => t.symbol === "USDT")],
|
|
4058
|
+
protocols: [_protocol],
|
|
4059
|
+
maxTVL: Web3Number.fromWei("0", 6),
|
|
4060
|
+
risk: {
|
|
4061
|
+
riskFactor: _riskFactor,
|
|
4062
|
+
netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
4063
|
+
notARisks: getNoRiskTags(_riskFactor)
|
|
4028
4064
|
},
|
|
4029
4065
|
additionalInfo: {
|
|
4030
4066
|
feeBps: 1e3
|
|
4031
4067
|
}
|
|
4032
|
-
// }, {
|
|
4033
|
-
// name: 'Vesu Fusion USDT',
|
|
4034
|
-
// description: _description.replace('{{TOKEN}}', 'USDT'),
|
|
4035
|
-
// address: ContractAddr.from('0x778007f8136a5b827325d21613803e796bda4d676fbe1e34aeab0b2a2ec027f'),
|
|
4036
|
-
// type: 'ERC4626',
|
|
4037
|
-
// depositTokens: [Global.getDefaultTokens().find(t => t.symbol === 'USDT')!],
|
|
4038
|
-
// protocols: [_protocol],
|
|
4039
|
-
// maxTVL: Web3Number.fromWei('0', 6),
|
|
4040
|
-
// risk: {
|
|
4041
|
-
// riskFactor: _riskFactor,
|
|
4042
|
-
// netRisk: _riskFactor.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor.reduce((acc, curr) => acc + curr.weight, 0),
|
|
4043
|
-
// },
|
|
4044
|
-
// additionalInfo: {
|
|
4045
|
-
// feeBps: 1000,
|
|
4046
|
-
// },
|
|
4047
4068
|
// }, {
|
|
4048
4069
|
// name: 'Vesu Fusion WBTC',
|
|
4049
4070
|
// description: _description.replace('{{TOKEN}}', 'WBTC'),
|
|
@@ -9342,7 +9363,8 @@ var EkuboCLVaultStrategies = [{
|
|
|
9342
9363
|
maxTVL: Web3Number.fromWei("0", 18),
|
|
9343
9364
|
risk: {
|
|
9344
9365
|
riskFactor: _riskFactor2,
|
|
9345
|
-
netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0)
|
|
9366
|
+
netRisk: _riskFactor2.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor2.reduce((acc, curr) => acc + curr.weight, 0),
|
|
9367
|
+
notARisks: getNoRiskTags(_riskFactor2)
|
|
9346
9368
|
},
|
|
9347
9369
|
additionalInfo: {
|
|
9348
9370
|
newBounds: {
|