@strkfarm/sdk 1.0.34 → 1.0.36
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 +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.browser.global.js +65 -5
- package/dist/index.browser.mjs +65 -5
- package/dist/index.d.ts +10 -1
- package/dist/index.js +65 -5
- package/dist/index.mjs +65 -5
- package/package.json +1 -1
- package/src/global.ts +1 -1
- package/src/strategies/vesu-rebalance.tsx +78 -4
package/dist/cli.js
CHANGED
|
@@ -240,7 +240,7 @@ var defaultTokens = [{
|
|
|
240
240
|
}, {
|
|
241
241
|
name: "USDT",
|
|
242
242
|
symbol: "USDT",
|
|
243
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
243
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
244
244
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
245
245
|
decimals: 6,
|
|
246
246
|
coingeckId: void 0,
|
package/dist/cli.mjs
CHANGED
|
@@ -217,7 +217,7 @@ var defaultTokens = [{
|
|
|
217
217
|
}, {
|
|
218
218
|
name: "USDT",
|
|
219
219
|
symbol: "USDT",
|
|
220
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
220
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
221
221
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
222
222
|
decimals: 6,
|
|
223
223
|
coingeckId: void 0,
|
|
@@ -28480,7 +28480,7 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
28480
28480
|
}, {
|
|
28481
28481
|
name: "USDT",
|
|
28482
28482
|
symbol: "USDT",
|
|
28483
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
28483
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
28484
28484
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
28485
28485
|
decimals: 6,
|
|
28486
28486
|
coingeckId: void 0,
|
|
@@ -41584,13 +41584,30 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
41584
41584
|
* - finalPools: Array of pool information after rebalance
|
|
41585
41585
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
41586
41586
|
*/
|
|
41587
|
-
async getRebalancedPositions() {
|
|
41588
|
-
|
|
41589
|
-
|
|
41587
|
+
async getRebalancedPositions(_pools) {
|
|
41588
|
+
logger2.verbose(`VesuRebalance: getRebalancedPositions`);
|
|
41589
|
+
if (!_pools) {
|
|
41590
|
+
const { data: _pools2 } = await this.getPools();
|
|
41591
|
+
_pools = _pools2;
|
|
41592
|
+
}
|
|
41593
|
+
const feeDeductions = await this.getFee(_pools);
|
|
41594
|
+
logger2.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
|
|
41595
|
+
const pools = _pools.map((p) => {
|
|
41596
|
+
const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
|
|
41597
|
+
logger2.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
|
|
41598
|
+
return {
|
|
41599
|
+
...p,
|
|
41600
|
+
amount: p.amount.minus(fee)
|
|
41601
|
+
};
|
|
41602
|
+
});
|
|
41603
|
+
let totalAssets = (await this.getTVL()).amount;
|
|
41590
41604
|
if (totalAssets.eq(0)) return {
|
|
41591
41605
|
changes: [],
|
|
41592
41606
|
finalPools: []
|
|
41593
41607
|
};
|
|
41608
|
+
feeDeductions.forEach((f) => {
|
|
41609
|
+
totalAssets = totalAssets.minus(f.fee);
|
|
41610
|
+
});
|
|
41594
41611
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
41595
41612
|
logger2.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
41596
41613
|
logger2.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
@@ -41628,8 +41645,8 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
41628
41645
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
41629
41646
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
41630
41647
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
41631
|
-
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
41632
41648
|
logger2.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
41649
|
+
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
41633
41650
|
logger2.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
41634
41651
|
logger2.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
41635
41652
|
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
@@ -41733,6 +41750,49 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
41733
41750
|
])
|
|
41734
41751
|
];
|
|
41735
41752
|
}
|
|
41753
|
+
/**
|
|
41754
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
41755
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
41756
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
41757
|
+
*/
|
|
41758
|
+
async getFee(allowedPools) {
|
|
41759
|
+
const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
|
|
41760
|
+
const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
|
|
41761
|
+
const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
|
|
41762
|
+
const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
|
|
41763
|
+
logger2.verbose(`Previous index: ${prevIndex.toString()}`);
|
|
41764
|
+
logger2.verbose(`Assets: ${assets.toString()}`);
|
|
41765
|
+
logger2.verbose(`Total supply: ${totalSupply.toString()}`);
|
|
41766
|
+
logger2.verbose(`Current index: ${currIndex.toNumber()}`);
|
|
41767
|
+
if (currIndex.lt(prevIndex)) {
|
|
41768
|
+
logger2.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
|
|
41769
|
+
return [];
|
|
41770
|
+
}
|
|
41771
|
+
const indexDiff = currIndex.minus(prevIndex);
|
|
41772
|
+
logger2.verbose(`Index diff: ${indexDiff.toString()}`);
|
|
41773
|
+
const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
|
|
41774
|
+
const denominator = 1e4;
|
|
41775
|
+
let fee = numerator.dividedBy(denominator);
|
|
41776
|
+
logger2.verbose(`Fee: ${fee.toString()}`);
|
|
41777
|
+
if (fee.lte(0)) {
|
|
41778
|
+
return [];
|
|
41779
|
+
}
|
|
41780
|
+
const fees = [];
|
|
41781
|
+
let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
|
|
41782
|
+
for (const pool of allowedPools) {
|
|
41783
|
+
const vToken = pool.v_token;
|
|
41784
|
+
const balance = pool.amount;
|
|
41785
|
+
if (remainingFee.lte(balance)) {
|
|
41786
|
+
fees.push({ vToken, fee: remainingFee });
|
|
41787
|
+
break;
|
|
41788
|
+
} else {
|
|
41789
|
+
fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
|
|
41790
|
+
remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
|
|
41791
|
+
}
|
|
41792
|
+
}
|
|
41793
|
+
logger2.verbose(`Fees: ${JSON.stringify(fees)}`);
|
|
41794
|
+
return fees;
|
|
41795
|
+
}
|
|
41736
41796
|
};
|
|
41737
41797
|
var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
|
|
41738
41798
|
var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
|
package/dist/index.browser.mjs
CHANGED
|
@@ -145,7 +145,7 @@ var defaultTokens = [{
|
|
|
145
145
|
}, {
|
|
146
146
|
name: "USDT",
|
|
147
147
|
symbol: "USDT",
|
|
148
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
148
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
149
149
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
150
150
|
decimals: 6,
|
|
151
151
|
coingeckId: void 0,
|
|
@@ -12954,13 +12954,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
12954
12954
|
* - finalPools: Array of pool information after rebalance
|
|
12955
12955
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
12956
12956
|
*/
|
|
12957
|
-
async getRebalancedPositions() {
|
|
12958
|
-
|
|
12959
|
-
|
|
12957
|
+
async getRebalancedPositions(_pools) {
|
|
12958
|
+
logger.verbose(`VesuRebalance: getRebalancedPositions`);
|
|
12959
|
+
if (!_pools) {
|
|
12960
|
+
const { data: _pools2 } = await this.getPools();
|
|
12961
|
+
_pools = _pools2;
|
|
12962
|
+
}
|
|
12963
|
+
const feeDeductions = await this.getFee(_pools);
|
|
12964
|
+
logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
|
|
12965
|
+
const pools = _pools.map((p) => {
|
|
12966
|
+
const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
|
|
12967
|
+
logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
|
|
12968
|
+
return {
|
|
12969
|
+
...p,
|
|
12970
|
+
amount: p.amount.minus(fee)
|
|
12971
|
+
};
|
|
12972
|
+
});
|
|
12973
|
+
let totalAssets = (await this.getTVL()).amount;
|
|
12960
12974
|
if (totalAssets.eq(0)) return {
|
|
12961
12975
|
changes: [],
|
|
12962
12976
|
finalPools: []
|
|
12963
12977
|
};
|
|
12978
|
+
feeDeductions.forEach((f) => {
|
|
12979
|
+
totalAssets = totalAssets.minus(f.fee);
|
|
12980
|
+
});
|
|
12964
12981
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
12965
12982
|
logger.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
12966
12983
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
@@ -12998,8 +13015,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
12998
13015
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
12999
13016
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13000
13017
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
13001
|
-
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13002
13018
|
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
13019
|
+
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13003
13020
|
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
13004
13021
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
13005
13022
|
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
@@ -13103,6 +13120,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13103
13120
|
])
|
|
13104
13121
|
];
|
|
13105
13122
|
}
|
|
13123
|
+
/**
|
|
13124
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
13125
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
13126
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
13127
|
+
*/
|
|
13128
|
+
async getFee(allowedPools) {
|
|
13129
|
+
const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
|
|
13130
|
+
const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
|
|
13131
|
+
const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
|
|
13132
|
+
const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
|
|
13133
|
+
logger.verbose(`Previous index: ${prevIndex.toString()}`);
|
|
13134
|
+
logger.verbose(`Assets: ${assets.toString()}`);
|
|
13135
|
+
logger.verbose(`Total supply: ${totalSupply.toString()}`);
|
|
13136
|
+
logger.verbose(`Current index: ${currIndex.toNumber()}`);
|
|
13137
|
+
if (currIndex.lt(prevIndex)) {
|
|
13138
|
+
logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
|
|
13139
|
+
return [];
|
|
13140
|
+
}
|
|
13141
|
+
const indexDiff = currIndex.minus(prevIndex);
|
|
13142
|
+
logger.verbose(`Index diff: ${indexDiff.toString()}`);
|
|
13143
|
+
const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
|
|
13144
|
+
const denominator = 1e4;
|
|
13145
|
+
let fee = numerator.dividedBy(denominator);
|
|
13146
|
+
logger.verbose(`Fee: ${fee.toString()}`);
|
|
13147
|
+
if (fee.lte(0)) {
|
|
13148
|
+
return [];
|
|
13149
|
+
}
|
|
13150
|
+
const fees = [];
|
|
13151
|
+
let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
|
|
13152
|
+
for (const pool of allowedPools) {
|
|
13153
|
+
const vToken = pool.v_token;
|
|
13154
|
+
const balance = pool.amount;
|
|
13155
|
+
if (remainingFee.lte(balance)) {
|
|
13156
|
+
fees.push({ vToken, fee: remainingFee });
|
|
13157
|
+
break;
|
|
13158
|
+
} else {
|
|
13159
|
+
fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
|
|
13160
|
+
remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
|
|
13161
|
+
}
|
|
13162
|
+
}
|
|
13163
|
+
logger.verbose(`Fees: ${JSON.stringify(fees)}`);
|
|
13164
|
+
return fees;
|
|
13165
|
+
}
|
|
13106
13166
|
};
|
|
13107
13167
|
var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
|
|
13108
13168
|
var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
|
package/dist/index.d.ts
CHANGED
|
@@ -580,7 +580,7 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
|
|
|
580
580
|
* - finalPools: Array of pool information after rebalance
|
|
581
581
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
582
582
|
*/
|
|
583
|
-
getRebalancedPositions(): Promise<{
|
|
583
|
+
getRebalancedPositions(_pools?: PoolInfoFull[]): Promise<{
|
|
584
584
|
changes: never[];
|
|
585
585
|
finalPools: never[];
|
|
586
586
|
isAnyPoolOverMaxWeight?: undefined;
|
|
@@ -597,6 +597,15 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
|
|
|
597
597
|
getRebalanceCall(pools: Awaited<ReturnType<typeof this.getRebalancedPositions>>['changes'], isOverWeightAdjustment: boolean): Promise<starknet.Call | null>;
|
|
598
598
|
getInvestmentFlows(pools: PoolInfoFull[]): Promise<IInvestmentFlow[]>;
|
|
599
599
|
harvest(acc: Account): Promise<starknet.Call[]>;
|
|
600
|
+
/**
|
|
601
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
602
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
603
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
604
|
+
*/
|
|
605
|
+
getFee(allowedPools: Array<PoolInfoFull>): Promise<Array<{
|
|
606
|
+
vToken: ContractAddr;
|
|
607
|
+
fee: Web3Number;
|
|
608
|
+
}>>;
|
|
600
609
|
}
|
|
601
610
|
/**
|
|
602
611
|
* Represents the Vesu Rebalance Strategies.
|
package/dist/index.js
CHANGED
|
@@ -226,7 +226,7 @@ var defaultTokens = [{
|
|
|
226
226
|
}, {
|
|
227
227
|
name: "USDT",
|
|
228
228
|
symbol: "USDT",
|
|
229
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
229
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
230
230
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
231
231
|
decimals: 6,
|
|
232
232
|
coingeckId: void 0,
|
|
@@ -13043,13 +13043,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13043
13043
|
* - finalPools: Array of pool information after rebalance
|
|
13044
13044
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
13045
13045
|
*/
|
|
13046
|
-
async getRebalancedPositions() {
|
|
13047
|
-
|
|
13048
|
-
|
|
13046
|
+
async getRebalancedPositions(_pools) {
|
|
13047
|
+
logger.verbose(`VesuRebalance: getRebalancedPositions`);
|
|
13048
|
+
if (!_pools) {
|
|
13049
|
+
const { data: _pools2 } = await this.getPools();
|
|
13050
|
+
_pools = _pools2;
|
|
13051
|
+
}
|
|
13052
|
+
const feeDeductions = await this.getFee(_pools);
|
|
13053
|
+
logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
|
|
13054
|
+
const pools = _pools.map((p) => {
|
|
13055
|
+
const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
|
|
13056
|
+
logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
|
|
13057
|
+
return {
|
|
13058
|
+
...p,
|
|
13059
|
+
amount: p.amount.minus(fee)
|
|
13060
|
+
};
|
|
13061
|
+
});
|
|
13062
|
+
let totalAssets = (await this.getTVL()).amount;
|
|
13049
13063
|
if (totalAssets.eq(0)) return {
|
|
13050
13064
|
changes: [],
|
|
13051
13065
|
finalPools: []
|
|
13052
13066
|
};
|
|
13067
|
+
feeDeductions.forEach((f) => {
|
|
13068
|
+
totalAssets = totalAssets.minus(f.fee);
|
|
13069
|
+
});
|
|
13053
13070
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13054
13071
|
logger.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
13055
13072
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
@@ -13087,8 +13104,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13087
13104
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13088
13105
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13089
13106
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
13090
|
-
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13091
13107
|
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
13108
|
+
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13092
13109
|
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
13093
13110
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
13094
13111
|
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
@@ -13192,6 +13209,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13192
13209
|
])
|
|
13193
13210
|
];
|
|
13194
13211
|
}
|
|
13212
|
+
/**
|
|
13213
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
13214
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
13215
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
13216
|
+
*/
|
|
13217
|
+
async getFee(allowedPools) {
|
|
13218
|
+
const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
|
|
13219
|
+
const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
|
|
13220
|
+
const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
|
|
13221
|
+
const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
|
|
13222
|
+
logger.verbose(`Previous index: ${prevIndex.toString()}`);
|
|
13223
|
+
logger.verbose(`Assets: ${assets.toString()}`);
|
|
13224
|
+
logger.verbose(`Total supply: ${totalSupply.toString()}`);
|
|
13225
|
+
logger.verbose(`Current index: ${currIndex.toNumber()}`);
|
|
13226
|
+
if (currIndex.lt(prevIndex)) {
|
|
13227
|
+
logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
|
|
13228
|
+
return [];
|
|
13229
|
+
}
|
|
13230
|
+
const indexDiff = currIndex.minus(prevIndex);
|
|
13231
|
+
logger.verbose(`Index diff: ${indexDiff.toString()}`);
|
|
13232
|
+
const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
|
|
13233
|
+
const denominator = 1e4;
|
|
13234
|
+
let fee = numerator.dividedBy(denominator);
|
|
13235
|
+
logger.verbose(`Fee: ${fee.toString()}`);
|
|
13236
|
+
if (fee.lte(0)) {
|
|
13237
|
+
return [];
|
|
13238
|
+
}
|
|
13239
|
+
const fees = [];
|
|
13240
|
+
let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
|
|
13241
|
+
for (const pool of allowedPools) {
|
|
13242
|
+
const vToken = pool.v_token;
|
|
13243
|
+
const balance = pool.amount;
|
|
13244
|
+
if (remainingFee.lte(balance)) {
|
|
13245
|
+
fees.push({ vToken, fee: remainingFee });
|
|
13246
|
+
break;
|
|
13247
|
+
} else {
|
|
13248
|
+
fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
|
|
13249
|
+
remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
|
|
13250
|
+
}
|
|
13251
|
+
}
|
|
13252
|
+
logger.verbose(`Fees: ${JSON.stringify(fees)}`);
|
|
13253
|
+
return fees;
|
|
13254
|
+
}
|
|
13195
13255
|
};
|
|
13196
13256
|
var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
|
|
13197
13257
|
var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
|
package/dist/index.mjs
CHANGED
|
@@ -157,7 +157,7 @@ var defaultTokens = [{
|
|
|
157
157
|
}, {
|
|
158
158
|
name: "USDT",
|
|
159
159
|
symbol: "USDT",
|
|
160
|
-
logo: "https://assets.strkfarm.com/integrations/tokens/
|
|
160
|
+
logo: "https://assets.strkfarm.com/integrations/tokens/usdt.svg",
|
|
161
161
|
address: ContractAddr.from("0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"),
|
|
162
162
|
decimals: 6,
|
|
163
163
|
coingeckId: void 0,
|
|
@@ -12974,13 +12974,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
12974
12974
|
* - finalPools: Array of pool information after rebalance
|
|
12975
12975
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
12976
12976
|
*/
|
|
12977
|
-
async getRebalancedPositions() {
|
|
12978
|
-
|
|
12979
|
-
|
|
12977
|
+
async getRebalancedPositions(_pools) {
|
|
12978
|
+
logger.verbose(`VesuRebalance: getRebalancedPositions`);
|
|
12979
|
+
if (!_pools) {
|
|
12980
|
+
const { data: _pools2 } = await this.getPools();
|
|
12981
|
+
_pools = _pools2;
|
|
12982
|
+
}
|
|
12983
|
+
const feeDeductions = await this.getFee(_pools);
|
|
12984
|
+
logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
|
|
12985
|
+
const pools = _pools.map((p) => {
|
|
12986
|
+
const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
|
|
12987
|
+
logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
|
|
12988
|
+
return {
|
|
12989
|
+
...p,
|
|
12990
|
+
amount: p.amount.minus(fee)
|
|
12991
|
+
};
|
|
12992
|
+
});
|
|
12993
|
+
let totalAssets = (await this.getTVL()).amount;
|
|
12980
12994
|
if (totalAssets.eq(0)) return {
|
|
12981
12995
|
changes: [],
|
|
12982
12996
|
finalPools: []
|
|
12983
12997
|
};
|
|
12998
|
+
feeDeductions.forEach((f) => {
|
|
12999
|
+
totalAssets = totalAssets.minus(f.fee);
|
|
13000
|
+
});
|
|
12984
13001
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
12985
13002
|
logger.verbose(`Sum of pools: ${sumPools.toString()}`);
|
|
12986
13003
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
@@ -13018,8 +13035,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13018
13035
|
const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13019
13036
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
13020
13037
|
const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
|
|
13021
|
-
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13022
13038
|
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
13039
|
+
if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
|
|
13023
13040
|
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
13024
13041
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
13025
13042
|
if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
|
|
@@ -13123,6 +13140,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
13123
13140
|
])
|
|
13124
13141
|
];
|
|
13125
13142
|
}
|
|
13143
|
+
/**
|
|
13144
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
13145
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
13146
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
13147
|
+
*/
|
|
13148
|
+
async getFee(allowedPools) {
|
|
13149
|
+
const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
|
|
13150
|
+
const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
|
|
13151
|
+
const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
|
|
13152
|
+
const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
|
|
13153
|
+
logger.verbose(`Previous index: ${prevIndex.toString()}`);
|
|
13154
|
+
logger.verbose(`Assets: ${assets.toString()}`);
|
|
13155
|
+
logger.verbose(`Total supply: ${totalSupply.toString()}`);
|
|
13156
|
+
logger.verbose(`Current index: ${currIndex.toNumber()}`);
|
|
13157
|
+
if (currIndex.lt(prevIndex)) {
|
|
13158
|
+
logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
|
|
13159
|
+
return [];
|
|
13160
|
+
}
|
|
13161
|
+
const indexDiff = currIndex.minus(prevIndex);
|
|
13162
|
+
logger.verbose(`Index diff: ${indexDiff.toString()}`);
|
|
13163
|
+
const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
|
|
13164
|
+
const denominator = 1e4;
|
|
13165
|
+
let fee = numerator.dividedBy(denominator);
|
|
13166
|
+
logger.verbose(`Fee: ${fee.toString()}`);
|
|
13167
|
+
if (fee.lte(0)) {
|
|
13168
|
+
return [];
|
|
13169
|
+
}
|
|
13170
|
+
const fees = [];
|
|
13171
|
+
let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
|
|
13172
|
+
for (const pool of allowedPools) {
|
|
13173
|
+
const vToken = pool.v_token;
|
|
13174
|
+
const balance = pool.amount;
|
|
13175
|
+
if (remainingFee.lte(balance)) {
|
|
13176
|
+
fees.push({ vToken, fee: remainingFee });
|
|
13177
|
+
break;
|
|
13178
|
+
} else {
|
|
13179
|
+
fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
|
|
13180
|
+
remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13183
|
+
logger.verbose(`Fees: ${JSON.stringify(fees)}`);
|
|
13184
|
+
return fees;
|
|
13185
|
+
}
|
|
13126
13186
|
};
|
|
13127
13187
|
var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
|
|
13128
13188
|
var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
|
package/package.json
CHANGED
package/src/global.ts
CHANGED
|
@@ -81,7 +81,7 @@ const defaultTokens: TokenInfo[] = [{
|
|
|
81
81
|
}, {
|
|
82
82
|
name: 'USDT',
|
|
83
83
|
symbol: 'USDT',
|
|
84
|
-
logo: 'https://assets.strkfarm.com/integrations/tokens/
|
|
84
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/usdt.svg',
|
|
85
85
|
address: ContractAddr.from('0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8'),
|
|
86
86
|
decimals: 6,
|
|
87
87
|
coingeckId: undefined,
|
|
@@ -393,13 +393,34 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
|
|
|
393
393
|
* - finalPools: Array of pool information after rebalance
|
|
394
394
|
* @throws Error if rebalance is not possible while maintaining constraints
|
|
395
395
|
*/
|
|
396
|
-
async getRebalancedPositions() {
|
|
397
|
-
|
|
398
|
-
|
|
396
|
+
async getRebalancedPositions(_pools?: PoolInfoFull[]) {
|
|
397
|
+
logger.verbose(`VesuRebalance: getRebalancedPositions`);
|
|
398
|
+
if (!_pools) {
|
|
399
|
+
const { data: _pools2 } = await this.getPools();
|
|
400
|
+
_pools = _pools2;
|
|
401
|
+
}
|
|
402
|
+
const feeDeductions = await this.getFee(_pools);
|
|
403
|
+
logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
|
|
404
|
+
|
|
405
|
+
// remove fee from pools
|
|
406
|
+
const pools = _pools.map((p) => {
|
|
407
|
+
const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
|
|
408
|
+
logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
|
|
409
|
+
return {
|
|
410
|
+
...p,
|
|
411
|
+
amount: p.amount.minus(fee),
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
let totalAssets = (await this.getTVL()).amount;
|
|
399
415
|
if (totalAssets.eq(0)) return {
|
|
400
416
|
changes: [],
|
|
401
417
|
finalPools: [],
|
|
402
418
|
}
|
|
419
|
+
// deduct fee from total assets
|
|
420
|
+
feeDeductions.forEach((f) => {
|
|
421
|
+
totalAssets = totalAssets.minus(f.fee);
|
|
422
|
+
});
|
|
423
|
+
|
|
403
424
|
|
|
404
425
|
// assert sum of pools.amount <= totalAssets
|
|
405
426
|
const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
@@ -449,8 +470,8 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
|
|
|
449
470
|
const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
|
|
450
471
|
const hasChanges = changes.some(c => !c.changeAmt.eq(0));
|
|
451
472
|
|
|
452
|
-
if (!sumChanges.eq(0)) throw new Error('Sum of changes must be zero');
|
|
453
473
|
logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
|
|
474
|
+
if (!sumChanges.eq(0)) throw new Error('Sum of changes must be zero');
|
|
454
475
|
logger.verbose(`Sum of final: ${sumFinal.toString()}`);
|
|
455
476
|
logger.verbose(`Total assets: ${totalAssets.toString()}`);
|
|
456
477
|
if (!sumFinal.eq(totalAssets.toString())) throw new Error('Sum of final amounts must equal total assets');
|
|
@@ -565,6 +586,59 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
|
|
|
565
586
|
])
|
|
566
587
|
]
|
|
567
588
|
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Calculates the fees deducted in different vTokens based on the current and previous state.
|
|
592
|
+
* @param previousTotalSupply - The total supply of the strategy token before the transaction
|
|
593
|
+
* @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
|
|
594
|
+
*/
|
|
595
|
+
async getFee(allowedPools: Array<PoolInfoFull>): Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>> {
|
|
596
|
+
const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
|
|
597
|
+
const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
|
|
598
|
+
const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
|
|
599
|
+
const currIndex = (new Web3Number(1, 18)).multipliedBy(assets).dividedBy(totalSupply);
|
|
600
|
+
|
|
601
|
+
logger.verbose(`Previous index: ${prevIndex.toString()}`);
|
|
602
|
+
logger.verbose(`Assets: ${assets.toString()}`);
|
|
603
|
+
logger.verbose(`Total supply: ${totalSupply.toString()}`);
|
|
604
|
+
logger.verbose(`Current index: ${currIndex.toNumber()}`);
|
|
605
|
+
|
|
606
|
+
if (currIndex.lt(prevIndex)) {
|
|
607
|
+
logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
|
|
608
|
+
return [];
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const indexDiff = currIndex.minus(prevIndex);
|
|
612
|
+
logger.verbose(`Index diff: ${indexDiff.toString()}`);
|
|
613
|
+
const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
|
|
614
|
+
const denominator = 10000;
|
|
615
|
+
let fee = numerator.dividedBy(denominator);
|
|
616
|
+
logger.verbose(`Fee: ${fee.toString()}`);
|
|
617
|
+
|
|
618
|
+
if (fee.lte(0)) {
|
|
619
|
+
return [];
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const fees: Array<{ vToken: ContractAddr, fee: Web3Number }> = [];
|
|
623
|
+
let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
|
|
624
|
+
|
|
625
|
+
for (const pool of allowedPools) {
|
|
626
|
+
const vToken = pool.v_token;
|
|
627
|
+
const balance = pool.amount;
|
|
628
|
+
|
|
629
|
+
if (remainingFee.lte(balance)) {
|
|
630
|
+
fees.push({ vToken, fee: remainingFee });
|
|
631
|
+
break;
|
|
632
|
+
} else {
|
|
633
|
+
fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
|
|
634
|
+
remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
logger.verbose(`Fees: ${JSON.stringify(fees)}`);
|
|
639
|
+
|
|
640
|
+
return fees;
|
|
641
|
+
}
|
|
568
642
|
}
|
|
569
643
|
|
|
570
644
|
const _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well."
|