@strkfarm/sdk 1.0.62 → 1.0.64
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/index.browser.global.js +660 -372
- package/dist/index.browser.mjs +357 -69
- package/dist/index.d.ts +27 -3
- package/dist/index.js +358 -72
- package/dist/index.mjs +360 -74
- package/package.json +1 -1
- package/src/global.ts +19 -1
- package/src/interfaces/common.tsx +1 -0
- package/src/interfaces/risks.ts +175 -0
- package/src/modules/harvests.ts +4 -2
- package/src/notifs/telegram.ts +3 -3
- package/src/strategies/ekubo-cl-vault.tsx +201 -71
- package/src/strategies/universal-adapters/adapter-utils.ts +3 -1
- package/src/strategies/universal-adapters/common-adapter.ts +57 -1
- package/src/strategies/universal-adapters/vesu-adapter.ts +39 -0
- package/src/strategies/universal-strategy.tsx +78 -5
|
@@ -9,6 +9,7 @@ import { PricerBase } from "@/modules/pricerBase";
|
|
|
9
9
|
import VesuPoolIDs from "@/data/vesu_pools.json";
|
|
10
10
|
import { getAPIUsingHeadlessBrowser } from "@/node/headless";
|
|
11
11
|
import { Global } from "@/global";
|
|
12
|
+
import { VESU_REWARDS_CONTRACT } from "@/modules/harvests";
|
|
12
13
|
|
|
13
14
|
interface VesuPoolsInfo { pools: any[]; isErrorPoolsAPI: boolean };
|
|
14
15
|
|
|
@@ -38,6 +39,11 @@ export interface VesuModifyPositionCallParams {
|
|
|
38
39
|
debtAmount: VesuAmount
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
export interface VesuDefiSpringRewardsCallParams {
|
|
43
|
+
amount: Web3Number,
|
|
44
|
+
proofs: string[],
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
export interface VesuAdapterConfig {
|
|
42
48
|
poolId: ContractAddr,
|
|
43
49
|
collateral: TokenInfo,
|
|
@@ -156,6 +162,39 @@ export class VesuAdapter extends BaseAdapter {
|
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
}
|
|
165
|
+
|
|
166
|
+
getDefispringRewardsAdapter = (id: string): () => AdapterLeafType<VesuDefiSpringRewardsCallParams> => {
|
|
167
|
+
return () => {
|
|
168
|
+
const packedArguments: bigint[] = [];
|
|
169
|
+
const output = {
|
|
170
|
+
id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
|
|
171
|
+
readableId: id,
|
|
172
|
+
data: [
|
|
173
|
+
SIMPLE_SANITIZER.toBigInt(), // sanitizer address
|
|
174
|
+
VESU_REWARDS_CONTRACT.toBigInt(), // contract
|
|
175
|
+
toBigInt(hash.getSelectorFromName("claim")), // method name
|
|
176
|
+
BigInt(packedArguments.length),
|
|
177
|
+
...packedArguments
|
|
178
|
+
]
|
|
179
|
+
};
|
|
180
|
+
return { leaf: output, callConstructor: this.getDefiSpringClaimCall().bind(this) };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getDefiSpringClaimCall = (): GenerateCallFn<VesuDefiSpringRewardsCallParams> => {
|
|
185
|
+
return (params: VesuDefiSpringRewardsCallParams) => ({
|
|
186
|
+
sanitizer: SIMPLE_SANITIZER,
|
|
187
|
+
call: {
|
|
188
|
+
contractAddress: VESU_REWARDS_CONTRACT,
|
|
189
|
+
selector: hash.getSelectorFromName('claim'),
|
|
190
|
+
calldata: [
|
|
191
|
+
BigInt(params.amount.toWei()),
|
|
192
|
+
BigInt(params.proofs.length),
|
|
193
|
+
...params.proofs.map(proof => BigInt(num.hexToDecimalString(proof)))
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
}
|
|
159
198
|
|
|
160
199
|
formatAmountTypeEnum(amountType: VesuAmountType) {
|
|
161
200
|
switch(amountType) {
|
|
@@ -7,9 +7,11 @@ import { VesuRebalanceSettings } from "./vesu-rebalance";
|
|
|
7
7
|
import { assert, LeafData, logger, StandardMerkleTree } from "@/utils";
|
|
8
8
|
import UniversalVaultAbi from '../data/universal-vault.abi.json';
|
|
9
9
|
import ManagerAbi from '../data/vault-manager.abi.json';
|
|
10
|
-
import { ApproveCallParams, BaseAdapter, CommonAdapter, FlashloanCallParams, GenerateCallFn, LeafAdapterFn, ManageCall, VesuAdapter, VesuModifyPositionCallParams, VesuPools } from "./universal-adapters";
|
|
10
|
+
import { ApproveCallParams, AvnuSwapCallParams, BaseAdapter, CommonAdapter, FlashloanCallParams, GenerateCallFn, LeafAdapterFn, ManageCall, VesuAdapter, VesuDefiSpringRewardsCallParams, VesuModifyPositionCallParams, VesuPools } from "./universal-adapters";
|
|
11
11
|
import { Global } from "@/global";
|
|
12
|
-
import { ERC20 } from "@/modules";
|
|
12
|
+
import { AvnuWrapper, ERC20 } from "@/modules";
|
|
13
|
+
import { AVNU_MIDDLEWARE } from "./universal-adapters/adapter-utils";
|
|
14
|
+
import { VesuHarvests } from "@/modules/harvests";
|
|
13
15
|
|
|
14
16
|
export interface UniversalStrategySettings {
|
|
15
17
|
vaultAddress: ContractAddr,
|
|
@@ -312,7 +314,8 @@ export class UniversalStrategy<
|
|
|
312
314
|
|
|
313
315
|
// calculate estimated growth from strk rewards
|
|
314
316
|
const netAPY = await this.netAPY();
|
|
315
|
-
|
|
317
|
+
// account only 80% of value
|
|
318
|
+
const defispringAPY = (netAPY.splits.find(s => s.id === 'defispring')?.apy || 0) * 0.8;
|
|
316
319
|
if (!defispringAPY) throw new Error('DefiSpring APY not found');
|
|
317
320
|
|
|
318
321
|
const timeDiff = (Math.round(Date.now() / 1000) - Number(lastReportTime));
|
|
@@ -605,6 +608,61 @@ export class UniversalStrategy<
|
|
|
605
608
|
return manageCall;
|
|
606
609
|
}
|
|
607
610
|
|
|
611
|
+
async getHarvestCall() {
|
|
612
|
+
const vesuHarvest = new VesuHarvests(this.config);
|
|
613
|
+
const harvestInfo = await vesuHarvest.getUnHarvestedRewards(this.metadata.additionalInfo.vaultAllocator);
|
|
614
|
+
if (harvestInfo.length != 1) {
|
|
615
|
+
throw new Error(`Expected 1 harvest info, got ${harvestInfo.length}`);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const amount = harvestInfo[0].claim.amount;
|
|
619
|
+
const actualReward = harvestInfo[0].actualReward;
|
|
620
|
+
const proofs = harvestInfo[0].proof;
|
|
621
|
+
if (actualReward.isZero()) {
|
|
622
|
+
throw new Error(`Expected non-zero actual reward, got ${harvestInfo[0].actualReward}`);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const manage1Info = this.getProofs<VesuDefiSpringRewardsCallParams>(UNIVERSAL_MANAGE_IDS.DEFISPRING_REWARDS);
|
|
626
|
+
const manageCall1 = manage1Info.callConstructor({
|
|
627
|
+
amount,
|
|
628
|
+
proofs
|
|
629
|
+
});
|
|
630
|
+
const proofIds: string[] = [UNIVERSAL_MANAGE_IDS.DEFISPRING_REWARDS];
|
|
631
|
+
const manageCalls: ManageCall[] = [manageCall1];
|
|
632
|
+
|
|
633
|
+
// swap rewards for underlying
|
|
634
|
+
const STRK = Global.getDefaultTokens().find(t => t.symbol === 'STRK')!;
|
|
635
|
+
if (this.asset().symbol != 'STRK') {
|
|
636
|
+
// approve
|
|
637
|
+
const manage2Info = this.getProofs<ApproveCallParams>(UNIVERSAL_MANAGE_IDS.APPROVE_SWAP_TOKEN1);
|
|
638
|
+
const manageCall2 = manage2Info.callConstructor({
|
|
639
|
+
amount: actualReward
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
// swap
|
|
643
|
+
const avnuModule = new AvnuWrapper();
|
|
644
|
+
const quote = await avnuModule.getQuotes(
|
|
645
|
+
STRK.address.address,
|
|
646
|
+
this.asset().address.address,
|
|
647
|
+
actualReward.toWei(),
|
|
648
|
+
this.address.address
|
|
649
|
+
);
|
|
650
|
+
const swapInfo = await avnuModule.getSwapInfo(quote, this.address.address, 0, this.address.address);
|
|
651
|
+
const manage3Info = this.getProofs<AvnuSwapCallParams>(UNIVERSAL_MANAGE_IDS.AVNU_SWAP_REWARDS);
|
|
652
|
+
const manageCall3 = manage3Info.callConstructor({
|
|
653
|
+
props: swapInfo
|
|
654
|
+
});
|
|
655
|
+
proofIds.push(UNIVERSAL_MANAGE_IDS.APPROVE_SWAP_TOKEN1);
|
|
656
|
+
proofIds.push(UNIVERSAL_MANAGE_IDS.AVNU_SWAP_REWARDS);
|
|
657
|
+
|
|
658
|
+
manageCalls.push(manageCall2);
|
|
659
|
+
manageCalls.push(manageCall3);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const manageCall = this.getManageCall(proofIds, manageCalls);
|
|
663
|
+
return { call: manageCall, reward: actualReward, tokenInfo: STRK };
|
|
664
|
+
}
|
|
665
|
+
|
|
608
666
|
async getRebalanceCall(params: {
|
|
609
667
|
isLeg1toLeg2: boolean,
|
|
610
668
|
amount: Web3Number
|
|
@@ -646,7 +704,14 @@ export enum UNIVERSAL_MANAGE_IDS {
|
|
|
646
704
|
APPROVE_TOKEN1 = 'approve_token1',
|
|
647
705
|
APPROVE_TOKEN2 = 'approve_token2',
|
|
648
706
|
APPROVE_BRING_LIQUIDITY = 'approve_bring_liquidity',
|
|
649
|
-
BRING_LIQUIDITY = 'bring_liquidity'
|
|
707
|
+
BRING_LIQUIDITY = 'bring_liquidity',
|
|
708
|
+
|
|
709
|
+
// defi spring claim
|
|
710
|
+
DEFISPRING_REWARDS = 'defispring_rewards',
|
|
711
|
+
|
|
712
|
+
// avnu swaps
|
|
713
|
+
APPROVE_SWAP_TOKEN1 = 'approve_swap_token1',
|
|
714
|
+
AVNU_SWAP_REWARDS = 'avnu_swap_rewards'
|
|
650
715
|
}
|
|
651
716
|
|
|
652
717
|
export enum UNIVERSAL_ADAPTERS {
|
|
@@ -707,7 +772,15 @@ function getLooperSettings(
|
|
|
707
772
|
// to bridge liquidity back to vault (used by bring_liquidity)
|
|
708
773
|
vaultSettings.leafAdapters.push(commonAdapter.getApproveAdapter(USDCToken.address, vaultSettings.vaultAddress, UNIVERSAL_MANAGE_IDS.APPROVE_BRING_LIQUIDITY).bind(commonAdapter));
|
|
709
774
|
vaultSettings.leafAdapters.push(commonAdapter.getBringLiquidityAdapter(UNIVERSAL_MANAGE_IDS.BRING_LIQUIDITY).bind(commonAdapter));
|
|
710
|
-
|
|
775
|
+
|
|
776
|
+
// claim rewards
|
|
777
|
+
vaultSettings.leafAdapters.push(vesuAdapterUSDCETH.getDefispringRewardsAdapter(UNIVERSAL_MANAGE_IDS.DEFISPRING_REWARDS).bind(vesuAdapterUSDCETH));
|
|
778
|
+
|
|
779
|
+
// avnu swap
|
|
780
|
+
const STRKToken = Global.getDefaultTokens().find(token => token.symbol === 'STRK')!;
|
|
781
|
+
vaultSettings.leafAdapters.push(commonAdapter.getApproveAdapter(STRKToken.address, AVNU_MIDDLEWARE, UNIVERSAL_MANAGE_IDS.APPROVE_SWAP_TOKEN1).bind(commonAdapter));
|
|
782
|
+
vaultSettings.leafAdapters.push(commonAdapter.getAvnuAdapter(STRKToken.address, USDCToken.address, UNIVERSAL_MANAGE_IDS.AVNU_SWAP_REWARDS).bind(commonAdapter));
|
|
783
|
+
return vaultSettings;
|
|
711
784
|
}
|
|
712
785
|
|
|
713
786
|
const _riskFactor: RiskFactor[] = [
|