@strkfarm/sdk 2.0.0-dev.13 → 2.0.0-dev.14

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.
@@ -28550,6 +28550,21 @@ var calculateAmountDepositOnExtendedWhenIncurringLosses = async (client) => {
28550
28550
  return null;
28551
28551
  }
28552
28552
  };
28553
+ var calculateWBTCAmountToMaintainLTV = (collateralAmount, debtAmount, debtPrice, maxLtv = MAX_LIQUIDATION_RATIO, collateralPrice, targetHF = TARGET_HF) => {
28554
+ try {
28555
+ const numerator1 = collateralAmount.multipliedBy(collateralPrice).multipliedBy(maxLtv);
28556
+ const numerator2 = debtAmount.multipliedBy(debtPrice).multipliedBy(targetHF);
28557
+ const denominator = maxLtv;
28558
+ const collateralAmountToMaintainLTV = numerator2.minus(numerator1).dividedBy(denominator);
28559
+ let deltaCollateralAmountUnits = new Web3Number(
28560
+ collateralAmountToMaintainLTV.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS),
28561
+ WBTC_TOKEN_DECIMALS
28562
+ );
28563
+ return { deltaCollateralAmountUnits };
28564
+ } catch (err) {
28565
+ return { deltaCollateralAmountUnits: null };
28566
+ }
28567
+ };
28553
28568
  var calculateExposureDelta = (exposure_extended, exposure_vesu) => {
28554
28569
  const exposure_delta = new Web3Number(exposure_extended - exposure_vesu, 2);
28555
28570
  return exposure_delta.absoluteValue().toNumber();
@@ -30478,519 +30493,604 @@ var UnusedBalanceAdapter = class _UnusedBalanceAdapter extends BaseAdapter {
30478
30493
  }
30479
30494
  };
30480
30495
 
30481
- // src/strategies/universal-strategy.tsx
30482
- var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
30483
- AUMTypes2["FINALISED"] = "finalised";
30484
- AUMTypes2["DEFISPRING"] = "defispring";
30485
- return AUMTypes2;
30486
- })(AUMTypes || {});
30487
- var PositionTypeAvnuExtended = /* @__PURE__ */ ((PositionTypeAvnuExtended2) => {
30488
- PositionTypeAvnuExtended2["OPEN"] = "open";
30489
- PositionTypeAvnuExtended2["CLOSE"] = "close";
30490
- return PositionTypeAvnuExtended2;
30491
- })(PositionTypeAvnuExtended || {});
30492
- var UNIVERSAL_MANAGE_IDS = /* @__PURE__ */ ((UNIVERSAL_MANAGE_IDS2) => {
30493
- UNIVERSAL_MANAGE_IDS2["FLASH_LOAN"] = "flash_loan_init";
30494
- UNIVERSAL_MANAGE_IDS2["VESU_LEG1"] = "vesu_leg1";
30495
- UNIVERSAL_MANAGE_IDS2["VESU_LEG2"] = "vesu_leg2";
30496
- UNIVERSAL_MANAGE_IDS2["APPROVE_TOKEN1"] = "approve_token1";
30497
- UNIVERSAL_MANAGE_IDS2["APPROVE_TOKEN2"] = "approve_token2";
30498
- UNIVERSAL_MANAGE_IDS2["APPROVE_BRING_LIQUIDITY"] = "approve_bring_liquidity";
30499
- UNIVERSAL_MANAGE_IDS2["BRING_LIQUIDITY"] = "bring_liquidity";
30500
- UNIVERSAL_MANAGE_IDS2["DEFISPRING_REWARDS"] = "defispring_rewards";
30501
- UNIVERSAL_MANAGE_IDS2["APPROVE_SWAP_TOKEN1"] = "approve_swap_token1";
30502
- UNIVERSAL_MANAGE_IDS2["AVNU_SWAP_REWARDS"] = "avnu_swap_rewards";
30503
- return UNIVERSAL_MANAGE_IDS2;
30504
- })(UNIVERSAL_MANAGE_IDS || {});
30505
- function getContractDetails(settings) {
30506
- const contracts = [
30507
- { address: settings.vaultAddress, name: "Vault" },
30508
- { address: settings.manager, name: "Vault Manager" },
30509
- { address: settings.vaultAllocator, name: "Vault Allocator" },
30510
- { address: settings.redeemRequestNFT, name: "Redeem Request NFT" }
30511
- ];
30512
- if (settings.aumOracle) {
30513
- contracts.push({ address: settings.aumOracle, name: "AUM Oracle" });
30496
+ // src/strategies/universal-adapters/avnu-adapter.ts
30497
+ import { hash as hash7, uint256 as uint25614 } from "starknet";
30498
+ import axios10 from "axios";
30499
+ var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
30500
+ constructor(config) {
30501
+ super(config, _AvnuAdapter.name, Protocols.AVNU);
30502
+ this.config = config;
30503
+ this.avnuWrapper = new AvnuWrapper();
30514
30504
  }
30515
- return contracts;
30516
- }
30517
-
30518
- // src/strategies/svk-strategy.ts
30519
- import { Contract as Contract13, num as num10 } from "starknet";
30520
-
30521
- // src/data/universal-vault.abi.json
30522
- var universal_vault_abi_default = [
30523
- {
30524
- type: "impl",
30525
- name: "UpgradeableImpl",
30526
- interface_name: "openzeppelin_interfaces::upgrades::IUpgradeable"
30527
- },
30528
- {
30529
- type: "interface",
30530
- name: "openzeppelin_interfaces::upgrades::IUpgradeable",
30531
- items: [
30505
+ //abstract means the method has no implementation in this class; instead, child classes must implement it.
30506
+ async getAPY(supportedPosition) {
30507
+ return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
30508
+ }
30509
+ async getPosition(supportedPosition) {
30510
+ return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
30511
+ }
30512
+ async maxDeposit(amount) {
30513
+ return Promise.resolve({
30514
+ tokenInfo: this.config.baseToken,
30515
+ amount: new Web3Number(0, 0),
30516
+ usdValue: 0,
30517
+ apy: { apy: 0, type: "base" /* BASE */ },
30518
+ protocol: Protocols.AVNU,
30519
+ remarks: ""
30520
+ });
30521
+ }
30522
+ async maxWithdraw() {
30523
+ return Promise.resolve({
30524
+ tokenInfo: this.config.baseToken,
30525
+ amount: new Web3Number(0, 0),
30526
+ usdValue: 0,
30527
+ apy: { apy: 0, type: "base" /* BASE */ },
30528
+ protocol: Protocols.AVNU,
30529
+ remarks: ""
30530
+ });
30531
+ }
30532
+ _getDepositLeaf() {
30533
+ const vaultAllocator = ContractAddr.from(
30534
+ this.config.vaultAllocator.address
30535
+ );
30536
+ return [
30532
30537
  {
30533
- type: "function",
30534
- name: "upgrade",
30535
- inputs: [
30536
- {
30537
- name: "new_class_hash",
30538
- type: "core::starknet::class_hash::ClassHash"
30539
- }
30538
+ target: this.config.supportedPositions[0].asset.address,
30539
+ method: "approve",
30540
+ packedArguments: [
30541
+ AVNU_EXCHANGE.toBigInt()
30540
30542
  ],
30541
- outputs: [],
30542
- state_mutability: "external"
30543
- }
30544
- ]
30545
- },
30546
- {
30547
- type: "impl",
30548
- name: "VaultMetadataImpl",
30549
- interface_name: "openzeppelin_interfaces::token::erc20::IERC20Metadata"
30550
- },
30551
- {
30552
- type: "struct",
30553
- name: "core::byte_array::ByteArray",
30554
- members: [
30555
- {
30556
- name: "data",
30557
- type: "core::array::Array::<core::bytes_31::bytes31>"
30558
- },
30559
- {
30560
- name: "pending_word",
30561
- type: "core::felt252"
30543
+ sanitizer: SIMPLE_SANITIZER,
30544
+ id: `approve_${this.config.supportedPositions[0].asset.symbol}`
30562
30545
  },
30563
30546
  {
30564
- name: "pending_word_len",
30565
- type: "core::integer::u32"
30566
- }
30567
- ]
30568
- },
30569
- {
30570
- type: "interface",
30571
- name: "openzeppelin_interfaces::token::erc20::IERC20Metadata",
30572
- items: [
30573
- {
30574
- type: "function",
30575
- name: "name",
30576
- inputs: [],
30577
- outputs: [
30578
- {
30579
- type: "core::byte_array::ByteArray"
30580
- }
30547
+ target: AVNU_EXCHANGE,
30548
+ method: "multi_route_swap",
30549
+ packedArguments: [
30550
+ this.config.supportedPositions[0].asset.address.toBigInt(),
30551
+ //usdc
30552
+ this.config.supportedPositions[1].asset.address.toBigInt(),
30553
+ //wbtc
30554
+ vaultAllocator.toBigInt()
30581
30555
  ],
30582
- state_mutability: "view"
30583
- },
30556
+ sanitizer: SIMPLE_SANITIZER,
30557
+ id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
30558
+ }
30559
+ ];
30560
+ }
30561
+ _getWithdrawLeaf() {
30562
+ const vaultAllocator = ContractAddr.from(
30563
+ this.config.vaultAllocator.address
30564
+ );
30565
+ const toToken = this.config.supportedPositions[0].asset;
30566
+ const fromToken = this.config.supportedPositions[1].asset;
30567
+ return [
30584
30568
  {
30585
- type: "function",
30586
- name: "symbol",
30587
- inputs: [],
30588
- outputs: [
30589
- {
30590
- type: "core::byte_array::ByteArray"
30591
- }
30569
+ target: fromToken.address,
30570
+ method: "approve",
30571
+ packedArguments: [
30572
+ AVNU_EXCHANGE.toBigInt()
30592
30573
  ],
30593
- state_mutability: "view"
30574
+ sanitizer: SIMPLE_SANITIZER,
30575
+ id: `approve_${fromToken.symbol}`
30594
30576
  },
30595
30577
  {
30596
- type: "function",
30597
- name: "decimals",
30598
- inputs: [],
30599
- outputs: [
30600
- {
30601
- type: "core::integer::u8"
30602
- }
30578
+ target: AVNU_EXCHANGE,
30579
+ method: "multi_route_swap",
30580
+ packedArguments: [
30581
+ fromToken.address.toBigInt(),
30582
+ //wbtc
30583
+ toToken.address.toBigInt(),
30584
+ //usdc
30585
+ vaultAllocator.toBigInt()
30603
30586
  ],
30604
- state_mutability: "view"
30587
+ sanitizer: SIMPLE_SANITIZER,
30588
+ id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
30605
30589
  }
30606
- ]
30607
- },
30608
- {
30609
- type: "impl",
30610
- name: "VaultImpl",
30611
- interface_name: "vault::vault::interface::IVault"
30612
- },
30613
- {
30614
- type: "struct",
30615
- name: "core::integer::u256",
30616
- members: [
30617
- {
30618
- name: "low",
30619
- type: "core::integer::u128"
30620
- },
30621
- {
30622
- name: "high",
30623
- type: "core::integer::u128"
30590
+ ];
30591
+ }
30592
+ _getLegacySwapLeaf() {
30593
+ return [];
30594
+ }
30595
+ async getDepositCall(params) {
30596
+ try {
30597
+ const fromToken = this.config.supportedPositions[0].asset;
30598
+ const toToken = this.config.supportedPositions[1].asset;
30599
+ const vaultAllocator = ContractAddr.from(
30600
+ this.config.vaultAllocator.address
30601
+ );
30602
+ const quote = await this.getQuotesAvnu(
30603
+ fromToken.address.toString(),
30604
+ toToken.address.toString(),
30605
+ params.amount.toNumber(),
30606
+ vaultAllocator.address.toString(),
30607
+ toToken.decimals,
30608
+ true
30609
+ );
30610
+ if (!quote) {
30611
+ logger.error("error getting quote from avnu");
30612
+ return [];
30624
30613
  }
30625
- ]
30626
- },
30627
- {
30628
- type: "interface",
30629
- name: "vault::vault::interface::IVault",
30630
- items: [
30631
- {
30632
- type: "function",
30633
- name: "register_redeem_request",
30634
- inputs: [
30635
- {
30636
- name: "redeem_request",
30637
- type: "core::starknet::contract_address::ContractAddress"
30638
- }
30639
- ],
30640
- outputs: [],
30641
- state_mutability: "external"
30642
- },
30643
- {
30644
- type: "function",
30645
- name: "register_vault_allocator",
30646
- inputs: [
30647
- {
30648
- name: "vault_allocator",
30649
- type: "core::starknet::contract_address::ContractAddress"
30650
- }
30651
- ],
30652
- outputs: [],
30653
- state_mutability: "external"
30654
- },
30655
- {
30656
- type: "function",
30657
- name: "request_redeem",
30658
- inputs: [
30659
- {
30660
- name: "shares",
30661
- type: "core::integer::u256"
30662
- },
30663
- {
30664
- name: "receiver",
30665
- type: "core::starknet::contract_address::ContractAddress"
30666
- },
30667
- {
30668
- name: "owner",
30669
- type: "core::starknet::contract_address::ContractAddress"
30670
- }
30671
- ],
30672
- outputs: [
30673
- {
30674
- type: "core::integer::u256"
30675
- }
30676
- ],
30677
- state_mutability: "external"
30678
- },
30679
- {
30680
- type: "function",
30681
- name: "claim_redeem",
30682
- inputs: [
30683
- {
30684
- name: "id",
30685
- type: "core::integer::u256"
30686
- }
30687
- ],
30688
- outputs: [
30689
- {
30690
- type: "core::integer::u256"
30691
- }
30692
- ],
30693
- state_mutability: "external"
30694
- },
30695
- {
30696
- type: "function",
30697
- name: "set_fees_config",
30698
- inputs: [
30699
- {
30700
- name: "fees_recipient",
30701
- type: "core::starknet::contract_address::ContractAddress"
30702
- },
30703
- {
30704
- name: "redeem_fees",
30705
- type: "core::integer::u256"
30706
- },
30707
- {
30708
- name: "management_fees",
30709
- type: "core::integer::u256"
30710
- },
30711
- {
30712
- name: "performance_fees",
30713
- type: "core::integer::u256"
30714
- }
30715
- ],
30716
- outputs: [],
30717
- state_mutability: "external"
30718
- },
30719
- {
30720
- type: "function",
30721
- name: "set_report_delay",
30722
- inputs: [
30723
- {
30724
- name: "report_delay",
30725
- type: "core::integer::u64"
30726
- }
30727
- ],
30728
- outputs: [],
30729
- state_mutability: "external"
30730
- },
30731
- {
30732
- type: "function",
30733
- name: "set_max_delta",
30734
- inputs: [
30735
- {
30736
- name: "max_delta",
30737
- type: "core::integer::u256"
30738
- }
30739
- ],
30740
- outputs: [],
30741
- state_mutability: "external"
30742
- },
30743
- {
30744
- type: "function",
30745
- name: "report",
30746
- inputs: [
30747
- {
30748
- name: "new_aum",
30749
- type: "core::integer::u256"
30750
- }
30751
- ],
30752
- outputs: [],
30753
- state_mutability: "external"
30754
- },
30755
- {
30756
- type: "function",
30757
- name: "bring_liquidity",
30758
- inputs: [
30759
- {
30760
- name: "amount",
30761
- type: "core::integer::u256"
30614
+ const getCalldata = await this.avnuWrapper.getSwapCallData(
30615
+ quote,
30616
+ vaultAllocator.address
30617
+ );
30618
+ const swapCallData = getCalldata[0];
30619
+ const amount = uint25614.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
30620
+ return [
30621
+ {
30622
+ sanitizer: SIMPLE_SANITIZER,
30623
+ call: {
30624
+ contractAddress: fromToken.address,
30625
+ selector: hash7.getSelectorFromName("approve"),
30626
+ calldata: [
30627
+ AVNU_EXCHANGE.toBigInt(),
30628
+ toBigInt(amount.low.toString()),
30629
+ // amount low
30630
+ toBigInt(amount.high.toString())
30631
+ // amount high
30632
+ ]
30762
30633
  }
30763
- ],
30764
- outputs: [],
30765
- state_mutability: "external"
30766
- },
30767
- {
30768
- type: "function",
30769
- name: "pause",
30770
- inputs: [],
30771
- outputs: [],
30772
- state_mutability: "external"
30773
- },
30774
- {
30775
- type: "function",
30776
- name: "unpause",
30777
- inputs: [],
30778
- outputs: [],
30779
- state_mutability: "external"
30780
- },
30781
- {
30782
- type: "function",
30783
- name: "epoch",
30784
- inputs: [],
30785
- outputs: [
30786
- {
30787
- type: "core::integer::u256"
30634
+ },
30635
+ {
30636
+ sanitizer: SIMPLE_SANITIZER,
30637
+ call: {
30638
+ contractAddress: AVNU_EXCHANGE,
30639
+ selector: hash7.getSelectorFromName("multi_route_swap"),
30640
+ calldata: swapCallData
30788
30641
  }
30789
- ],
30790
- state_mutability: "view"
30791
- },
30792
- {
30793
- type: "function",
30794
- name: "handled_epoch_len",
30795
- inputs: [],
30796
- outputs: [
30797
- {
30798
- type: "core::integer::u256"
30642
+ }
30643
+ ];
30644
+ } catch (error) {
30645
+ logger.error(`Error getting Avnu quote: ${error}`);
30646
+ return [];
30647
+ }
30648
+ }
30649
+ //Swap wbtc to usdc
30650
+ async getWithdrawCall(params) {
30651
+ try {
30652
+ const toToken = this.config.supportedPositions[0].asset;
30653
+ const fromToken = this.config.supportedPositions[1].asset;
30654
+ const vaultAllocator = ContractAddr.from(
30655
+ this.config.vaultAllocator.address
30656
+ );
30657
+ const quote = await this.getQuotesAvnu(
30658
+ fromToken.address.toString(),
30659
+ toToken.address.toString(),
30660
+ params.amount.toNumber(),
30661
+ vaultAllocator.address.toString(),
30662
+ fromToken.decimals,
30663
+ false
30664
+ );
30665
+ if (!quote) {
30666
+ logger.error("No quotes available for this swap, error in quotes avnu");
30667
+ return [];
30668
+ }
30669
+ const getCalldata = await this.avnuWrapper.getSwapCallData(
30670
+ quote,
30671
+ vaultAllocator.address
30672
+ );
30673
+ const swapCallData = getCalldata[0];
30674
+ const amount = uint25614.bnToUint256(params.amount.toWei());
30675
+ return [
30676
+ {
30677
+ sanitizer: SIMPLE_SANITIZER,
30678
+ call: {
30679
+ contractAddress: fromToken.address,
30680
+ selector: hash7.getSelectorFromName("approve"),
30681
+ calldata: [
30682
+ AVNU_EXCHANGE.toBigInt(),
30683
+ toBigInt(amount.low.toString()),
30684
+ // amount low
30685
+ toBigInt(amount.high.toString())
30686
+ // amount high
30687
+ ]
30799
30688
  }
30800
- ],
30801
- state_mutability: "view"
30802
- },
30803
- {
30804
- type: "function",
30805
- name: "buffer",
30806
- inputs: [],
30807
- outputs: [
30808
- {
30809
- type: "core::integer::u256"
30689
+ },
30690
+ {
30691
+ sanitizer: SIMPLE_SANITIZER,
30692
+ call: {
30693
+ contractAddress: AVNU_EXCHANGE,
30694
+ selector: hash7.getSelectorFromName("multi_route_swap"),
30695
+ calldata: swapCallData
30810
30696
  }
30811
- ],
30812
- state_mutability: "view"
30813
- },
30814
- {
30815
- type: "function",
30816
- name: "aum",
30817
- inputs: [],
30818
- outputs: [
30819
- {
30820
- type: "core::integer::u256"
30821
- }
30822
- ],
30823
- state_mutability: "view"
30824
- },
30697
+ }
30698
+ ];
30699
+ } catch (error) {
30700
+ logger.error(`Error getting Avnu quote: ${error}`);
30701
+ return [];
30702
+ }
30703
+ }
30704
+ async getSwapCallData(quote) {
30705
+ return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
30706
+ }
30707
+ async getHealthFactor() {
30708
+ return Promise.resolve(1);
30709
+ }
30710
+ async fetchQuoteWithRetry(params, retries = 5) {
30711
+ for (let attempt = 0; attempt < retries; attempt++) {
30712
+ try {
30713
+ const response = await axios10.get(this.config.baseUrl, { params });
30714
+ if (response.data && response.data.length > 0) {
30715
+ return response;
30716
+ }
30717
+ throw new Error("Empty response data");
30718
+ } catch (err) {
30719
+ logger.error(`Error fetching quote with retry: ${err}`);
30720
+ if (attempt === retries - 1) {
30721
+ throw err;
30722
+ }
30723
+ await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
30724
+ }
30725
+ }
30726
+ throw new Error("Failed to fetch quote after retries");
30727
+ }
30728
+ async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
30729
+ try {
30730
+ const fromToken = this.config.supportedPositions[0].asset;
30731
+ const toToken = this.config.supportedPositions[1].asset;
30732
+ if (!usdcToBtc) {
30733
+ const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
30734
+ const params2 = {
30735
+ sellTokenAddress: from_token_address,
30736
+ buyTokenAddress: to_token_address,
30737
+ takerAddress,
30738
+ sellAmount: sellAmount2
30739
+ };
30740
+ const finalQuote2 = await this.fetchQuoteWithRetry(params2);
30741
+ if (!finalQuote2.data.length) {
30742
+ logger.error("No quotes available for this swap, error in quotes avnu");
30743
+ return null;
30744
+ }
30745
+ const dataObject2 = finalQuote2.data[0];
30746
+ return dataObject2;
30747
+ }
30748
+ const btcPrice = await this.getPriceOfToken(toToken.address.toString());
30749
+ if (!btcPrice) {
30750
+ logger.error(`error getting btc price: ${btcPrice}`);
30751
+ return null;
30752
+ }
30753
+ const estimatedUsdcAmount = Math.floor(amount * btcPrice);
30754
+ const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
30755
+ let low = BigInt(
30756
+ Math.floor(
30757
+ estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
30758
+ )
30759
+ );
30760
+ let high = BigInt(
30761
+ Math.floor(
30762
+ estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
30763
+ )
30764
+ );
30765
+ let mid = 0n;
30766
+ for (let i = 0; i < maxIterations; i++) {
30767
+ mid = (low + high) / 2n;
30768
+ const sellAmount2 = returnFormattedAmount(Number(mid), 0);
30769
+ const quote = await this.fetchQuoteWithRetry({
30770
+ sellTokenAddress: from_token_address,
30771
+ buyTokenAddress: to_token_address,
30772
+ takerAddress,
30773
+ sellAmount: sellAmount2
30774
+ });
30775
+ const gotBtc = BigInt(quote.data[0].buyAmount);
30776
+ if (gotBtc === targetBtcBig) return quote.data[0];
30777
+ if (gotBtc > targetBtcBig) {
30778
+ high = mid;
30779
+ } else {
30780
+ low = mid;
30781
+ }
30782
+ if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
30783
+ return quote.data[0];
30784
+ }
30785
+ }
30786
+ let sellAmount = returnFormattedAmount(
30787
+ Number(mid),
30788
+ 0
30789
+ );
30790
+ const params = {
30791
+ sellTokenAddress: from_token_address,
30792
+ buyTokenAddress: to_token_address,
30793
+ takerAddress,
30794
+ sellAmount
30795
+ };
30796
+ const finalQuote = await this.fetchQuoteWithRetry(params);
30797
+ if (!finalQuote.data.length) {
30798
+ logger.error("No quotes available for this swap, error in quotes avnu");
30799
+ return null;
30800
+ }
30801
+ const dataObject = finalQuote.data[0];
30802
+ return dataObject;
30803
+ } catch (err) {
30804
+ logger.error(`No quotes available for this swap: ${err}`);
30805
+ return null;
30806
+ }
30807
+ }
30808
+ async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
30809
+ try {
30810
+ const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
30811
+ const response = await axios10.get(url);
30812
+ const length = response.data.length;
30813
+ return response.data[length - 1].value;
30814
+ } catch (err) {
30815
+ if (retries > 0) {
30816
+ await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
30817
+ return this.getPriceOfToken(tokenAddress, retries - 1);
30818
+ } else {
30819
+ logger.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
30820
+ return null;
30821
+ }
30822
+ }
30823
+ }
30824
+ };
30825
+
30826
+ // src/strategies/universal-strategy.tsx
30827
+ var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
30828
+ AUMTypes2["FINALISED"] = "finalised";
30829
+ AUMTypes2["DEFISPRING"] = "defispring";
30830
+ return AUMTypes2;
30831
+ })(AUMTypes || {});
30832
+ var PositionTypeAvnuExtended = /* @__PURE__ */ ((PositionTypeAvnuExtended2) => {
30833
+ PositionTypeAvnuExtended2["OPEN"] = "open";
30834
+ PositionTypeAvnuExtended2["CLOSE"] = "close";
30835
+ return PositionTypeAvnuExtended2;
30836
+ })(PositionTypeAvnuExtended || {});
30837
+ var UNIVERSAL_MANAGE_IDS = /* @__PURE__ */ ((UNIVERSAL_MANAGE_IDS2) => {
30838
+ UNIVERSAL_MANAGE_IDS2["FLASH_LOAN"] = "flash_loan_init";
30839
+ UNIVERSAL_MANAGE_IDS2["VESU_LEG1"] = "vesu_leg1";
30840
+ UNIVERSAL_MANAGE_IDS2["VESU_LEG2"] = "vesu_leg2";
30841
+ UNIVERSAL_MANAGE_IDS2["APPROVE_TOKEN1"] = "approve_token1";
30842
+ UNIVERSAL_MANAGE_IDS2["APPROVE_TOKEN2"] = "approve_token2";
30843
+ UNIVERSAL_MANAGE_IDS2["APPROVE_BRING_LIQUIDITY"] = "approve_bring_liquidity";
30844
+ UNIVERSAL_MANAGE_IDS2["BRING_LIQUIDITY"] = "bring_liquidity";
30845
+ UNIVERSAL_MANAGE_IDS2["DEFISPRING_REWARDS"] = "defispring_rewards";
30846
+ UNIVERSAL_MANAGE_IDS2["APPROVE_SWAP_TOKEN1"] = "approve_swap_token1";
30847
+ UNIVERSAL_MANAGE_IDS2["AVNU_SWAP_REWARDS"] = "avnu_swap_rewards";
30848
+ return UNIVERSAL_MANAGE_IDS2;
30849
+ })(UNIVERSAL_MANAGE_IDS || {});
30850
+ function getContractDetails(settings) {
30851
+ const contracts = [
30852
+ { address: settings.vaultAddress, name: "Vault" },
30853
+ { address: settings.manager, name: "Vault Manager" },
30854
+ { address: settings.vaultAllocator, name: "Vault Allocator" },
30855
+ { address: settings.redeemRequestNFT, name: "Redeem Request NFT" }
30856
+ ];
30857
+ if (settings.aumOracle) {
30858
+ contracts.push({ address: settings.aumOracle, name: "AUM Oracle" });
30859
+ }
30860
+ return contracts;
30861
+ }
30862
+
30863
+ // src/strategies/svk-strategy.ts
30864
+ import { Contract as Contract13, num as num10 } from "starknet";
30865
+
30866
+ // src/data/universal-vault.abi.json
30867
+ var universal_vault_abi_default = [
30868
+ {
30869
+ type: "impl",
30870
+ name: "UpgradeableImpl",
30871
+ interface_name: "openzeppelin_interfaces::upgrades::IUpgradeable"
30872
+ },
30873
+ {
30874
+ type: "interface",
30875
+ name: "openzeppelin_interfaces::upgrades::IUpgradeable",
30876
+ items: [
30825
30877
  {
30826
30878
  type: "function",
30827
- name: "redeem_assets",
30879
+ name: "upgrade",
30828
30880
  inputs: [
30829
30881
  {
30830
- name: "epoch",
30831
- type: "core::integer::u256"
30832
- }
30833
- ],
30834
- outputs: [
30835
- {
30836
- type: "core::integer::u256"
30882
+ name: "new_class_hash",
30883
+ type: "core::starknet::class_hash::ClassHash"
30837
30884
  }
30838
30885
  ],
30839
- state_mutability: "view"
30886
+ outputs: [],
30887
+ state_mutability: "external"
30888
+ }
30889
+ ]
30890
+ },
30891
+ {
30892
+ type: "impl",
30893
+ name: "VaultMetadataImpl",
30894
+ interface_name: "openzeppelin_interfaces::token::erc20::IERC20Metadata"
30895
+ },
30896
+ {
30897
+ type: "struct",
30898
+ name: "core::byte_array::ByteArray",
30899
+ members: [
30900
+ {
30901
+ name: "data",
30902
+ type: "core::array::Array::<core::bytes_31::bytes31>"
30840
30903
  },
30841
30904
  {
30842
- type: "function",
30843
- name: "redeem_nominal",
30844
- inputs: [
30845
- {
30846
- name: "epoch",
30847
- type: "core::integer::u256"
30848
- }
30849
- ],
30850
- outputs: [
30851
- {
30852
- type: "core::integer::u256"
30853
- }
30854
- ],
30855
- state_mutability: "view"
30905
+ name: "pending_word",
30906
+ type: "core::felt252"
30856
30907
  },
30908
+ {
30909
+ name: "pending_word_len",
30910
+ type: "core::integer::u32"
30911
+ }
30912
+ ]
30913
+ },
30914
+ {
30915
+ type: "interface",
30916
+ name: "openzeppelin_interfaces::token::erc20::IERC20Metadata",
30917
+ items: [
30857
30918
  {
30858
30919
  type: "function",
30859
- name: "fees_recipient",
30920
+ name: "name",
30860
30921
  inputs: [],
30861
30922
  outputs: [
30862
30923
  {
30863
- type: "core::starknet::contract_address::ContractAddress"
30924
+ type: "core::byte_array::ByteArray"
30864
30925
  }
30865
30926
  ],
30866
30927
  state_mutability: "view"
30867
30928
  },
30868
30929
  {
30869
30930
  type: "function",
30870
- name: "redeem_fees",
30931
+ name: "symbol",
30871
30932
  inputs: [],
30872
30933
  outputs: [
30873
30934
  {
30874
- type: "core::integer::u256"
30935
+ type: "core::byte_array::ByteArray"
30875
30936
  }
30876
30937
  ],
30877
30938
  state_mutability: "view"
30878
30939
  },
30879
30940
  {
30880
30941
  type: "function",
30881
- name: "management_fees",
30942
+ name: "decimals",
30882
30943
  inputs: [],
30883
30944
  outputs: [
30884
30945
  {
30885
- type: "core::integer::u256"
30886
- }
30887
- ],
30888
- state_mutability: "view"
30889
- },
30890
- {
30891
- type: "function",
30892
- name: "performance_fees",
30893
- inputs: [],
30894
- outputs: [
30895
- {
30896
- type: "core::integer::u256"
30946
+ type: "core::integer::u8"
30897
30947
  }
30898
30948
  ],
30899
30949
  state_mutability: "view"
30950
+ }
30951
+ ]
30952
+ },
30953
+ {
30954
+ type: "impl",
30955
+ name: "VaultImpl",
30956
+ interface_name: "vault::vault::interface::IVault"
30957
+ },
30958
+ {
30959
+ type: "struct",
30960
+ name: "core::integer::u256",
30961
+ members: [
30962
+ {
30963
+ name: "low",
30964
+ type: "core::integer::u128"
30900
30965
  },
30966
+ {
30967
+ name: "high",
30968
+ type: "core::integer::u128"
30969
+ }
30970
+ ]
30971
+ },
30972
+ {
30973
+ type: "interface",
30974
+ name: "vault::vault::interface::IVault",
30975
+ items: [
30901
30976
  {
30902
30977
  type: "function",
30903
- name: "redeem_request",
30904
- inputs: [],
30905
- outputs: [
30978
+ name: "register_redeem_request",
30979
+ inputs: [
30906
30980
  {
30981
+ name: "redeem_request",
30907
30982
  type: "core::starknet::contract_address::ContractAddress"
30908
30983
  }
30909
30984
  ],
30910
- state_mutability: "view"
30985
+ outputs: [],
30986
+ state_mutability: "external"
30911
30987
  },
30912
30988
  {
30913
30989
  type: "function",
30914
- name: "report_delay",
30915
- inputs: [],
30916
- outputs: [
30990
+ name: "register_vault_allocator",
30991
+ inputs: [
30917
30992
  {
30918
- type: "core::integer::u64"
30993
+ name: "vault_allocator",
30994
+ type: "core::starknet::contract_address::ContractAddress"
30919
30995
  }
30920
30996
  ],
30921
- state_mutability: "view"
30997
+ outputs: [],
30998
+ state_mutability: "external"
30922
30999
  },
30923
31000
  {
30924
31001
  type: "function",
30925
- name: "vault_allocator",
30926
- inputs: [],
30927
- outputs: [
31002
+ name: "request_redeem",
31003
+ inputs: [
31004
+ {
31005
+ name: "shares",
31006
+ type: "core::integer::u256"
31007
+ },
31008
+ {
31009
+ name: "receiver",
31010
+ type: "core::starknet::contract_address::ContractAddress"
31011
+ },
30928
31012
  {
31013
+ name: "owner",
30929
31014
  type: "core::starknet::contract_address::ContractAddress"
30930
31015
  }
30931
31016
  ],
30932
- state_mutability: "view"
30933
- },
30934
- {
30935
- type: "function",
30936
- name: "last_report_timestamp",
30937
- inputs: [],
30938
31017
  outputs: [
30939
31018
  {
30940
- type: "core::integer::u64"
31019
+ type: "core::integer::u256"
30941
31020
  }
30942
31021
  ],
30943
- state_mutability: "view"
31022
+ state_mutability: "external"
30944
31023
  },
30945
31024
  {
30946
31025
  type: "function",
30947
- name: "max_delta",
30948
- inputs: [],
31026
+ name: "claim_redeem",
31027
+ inputs: [
31028
+ {
31029
+ name: "id",
31030
+ type: "core::integer::u256"
31031
+ }
31032
+ ],
30949
31033
  outputs: [
30950
31034
  {
30951
31035
  type: "core::integer::u256"
30952
31036
  }
30953
31037
  ],
30954
- state_mutability: "view"
31038
+ state_mutability: "external"
30955
31039
  },
30956
31040
  {
30957
31041
  type: "function",
30958
- name: "due_assets_from_id",
31042
+ name: "set_fees_config",
30959
31043
  inputs: [
30960
31044
  {
30961
- name: "id",
31045
+ name: "fees_recipient",
31046
+ type: "core::starknet::contract_address::ContractAddress"
31047
+ },
31048
+ {
31049
+ name: "redeem_fees",
30962
31050
  type: "core::integer::u256"
30963
- }
30964
- ],
30965
- outputs: [
31051
+ },
31052
+ {
31053
+ name: "management_fees",
31054
+ type: "core::integer::u256"
31055
+ },
30966
31056
  {
31057
+ name: "performance_fees",
30967
31058
  type: "core::integer::u256"
30968
31059
  }
30969
31060
  ],
30970
- state_mutability: "view"
31061
+ outputs: [],
31062
+ state_mutability: "external"
30971
31063
  },
30972
31064
  {
30973
31065
  type: "function",
30974
- name: "due_assets_from_owner",
31066
+ name: "set_report_delay",
30975
31067
  inputs: [
30976
31068
  {
30977
- name: "owner",
30978
- type: "core::starknet::contract_address::ContractAddress"
31069
+ name: "report_delay",
31070
+ type: "core::integer::u64"
30979
31071
  }
30980
31072
  ],
30981
- outputs: [
31073
+ outputs: [],
31074
+ state_mutability: "external"
31075
+ },
31076
+ {
31077
+ type: "function",
31078
+ name: "set_max_delta",
31079
+ inputs: [
30982
31080
  {
31081
+ name: "max_delta",
30983
31082
  type: "core::integer::u256"
30984
31083
  }
30985
31084
  ],
30986
- state_mutability: "view"
31085
+ outputs: [],
31086
+ state_mutability: "external"
30987
31087
  },
30988
31088
  {
30989
31089
  type: "function",
30990
- name: "set_deposit_limit",
31090
+ name: "report",
30991
31091
  inputs: [
30992
31092
  {
30993
- name: "limit",
31093
+ name: "new_aum",
30994
31094
  type: "core::integer::u256"
30995
31095
  }
30996
31096
  ],
@@ -30999,10 +31099,10 @@ var universal_vault_abi_default = [
30999
31099
  },
31000
31100
  {
31001
31101
  type: "function",
31002
- name: "set_mint_limit",
31102
+ name: "bring_liquidity",
31003
31103
  inputs: [
31004
31104
  {
31005
- name: "limit",
31105
+ name: "amount",
31006
31106
  type: "core::integer::u256"
31007
31107
  }
31008
31108
  ],
@@ -31011,7 +31111,21 @@ var universal_vault_abi_default = [
31011
31111
  },
31012
31112
  {
31013
31113
  type: "function",
31014
- name: "get_deposit_limit",
31114
+ name: "pause",
31115
+ inputs: [],
31116
+ outputs: [],
31117
+ state_mutability: "external"
31118
+ },
31119
+ {
31120
+ type: "function",
31121
+ name: "unpause",
31122
+ inputs: [],
31123
+ outputs: [],
31124
+ state_mutability: "external"
31125
+ },
31126
+ {
31127
+ type: "function",
31128
+ name: "epoch",
31015
31129
  inputs: [],
31016
31130
  outputs: [
31017
31131
  {
@@ -31022,7 +31136,7 @@ var universal_vault_abi_default = [
31022
31136
  },
31023
31137
  {
31024
31138
  type: "function",
31025
- name: "get_mint_limit",
31139
+ name: "handled_epoch_len",
31026
31140
  inputs: [],
31027
31141
  outputs: [
31028
31142
  {
@@ -31030,32 +31144,21 @@ var universal_vault_abi_default = [
31030
31144
  }
31031
31145
  ],
31032
31146
  state_mutability: "view"
31033
- }
31034
- ]
31035
- },
31036
- {
31037
- type: "impl",
31038
- name: "ERC4626Impl",
31039
- interface_name: "openzeppelin_interfaces::token::erc4626::IERC4626"
31040
- },
31041
- {
31042
- type: "interface",
31043
- name: "openzeppelin_interfaces::token::erc4626::IERC4626",
31044
- items: [
31147
+ },
31045
31148
  {
31046
31149
  type: "function",
31047
- name: "asset",
31150
+ name: "buffer",
31048
31151
  inputs: [],
31049
31152
  outputs: [
31050
31153
  {
31051
- type: "core::starknet::contract_address::ContractAddress"
31154
+ type: "core::integer::u256"
31052
31155
  }
31053
31156
  ],
31054
31157
  state_mutability: "view"
31055
31158
  },
31056
31159
  {
31057
31160
  type: "function",
31058
- name: "total_assets",
31161
+ name: "aum",
31059
31162
  inputs: [],
31060
31163
  outputs: [
31061
31164
  {
@@ -31066,10 +31169,10 @@ var universal_vault_abi_default = [
31066
31169
  },
31067
31170
  {
31068
31171
  type: "function",
31069
- name: "convert_to_shares",
31172
+ name: "redeem_assets",
31070
31173
  inputs: [
31071
31174
  {
31072
- name: "assets",
31175
+ name: "epoch",
31073
31176
  type: "core::integer::u256"
31074
31177
  }
31075
31178
  ],
@@ -31082,10 +31185,10 @@ var universal_vault_abi_default = [
31082
31185
  },
31083
31186
  {
31084
31187
  type: "function",
31085
- name: "convert_to_assets",
31188
+ name: "redeem_nominal",
31086
31189
  inputs: [
31087
31190
  {
31088
- name: "shares",
31191
+ name: "epoch",
31089
31192
  type: "core::integer::u256"
31090
31193
  }
31091
31194
  ],
@@ -31098,13 +31201,19 @@ var universal_vault_abi_default = [
31098
31201
  },
31099
31202
  {
31100
31203
  type: "function",
31101
- name: "max_deposit",
31102
- inputs: [
31204
+ name: "fees_recipient",
31205
+ inputs: [],
31206
+ outputs: [
31103
31207
  {
31104
- name: "receiver",
31105
31208
  type: "core::starknet::contract_address::ContractAddress"
31106
31209
  }
31107
31210
  ],
31211
+ state_mutability: "view"
31212
+ },
31213
+ {
31214
+ type: "function",
31215
+ name: "redeem_fees",
31216
+ inputs: [],
31108
31217
  outputs: [
31109
31218
  {
31110
31219
  type: "core::integer::u256"
@@ -31114,13 +31223,19 @@ var universal_vault_abi_default = [
31114
31223
  },
31115
31224
  {
31116
31225
  type: "function",
31117
- name: "preview_deposit",
31118
- inputs: [
31226
+ name: "management_fees",
31227
+ inputs: [],
31228
+ outputs: [
31119
31229
  {
31120
- name: "assets",
31121
31230
  type: "core::integer::u256"
31122
31231
  }
31123
31232
  ],
31233
+ state_mutability: "view"
31234
+ },
31235
+ {
31236
+ type: "function",
31237
+ name: "performance_fees",
31238
+ inputs: [],
31124
31239
  outputs: [
31125
31240
  {
31126
31241
  type: "core::integer::u256"
@@ -31130,49 +31245,52 @@ var universal_vault_abi_default = [
31130
31245
  },
31131
31246
  {
31132
31247
  type: "function",
31133
- name: "deposit",
31134
- inputs: [
31135
- {
31136
- name: "assets",
31137
- type: "core::integer::u256"
31138
- },
31248
+ name: "redeem_request",
31249
+ inputs: [],
31250
+ outputs: [
31139
31251
  {
31140
- name: "receiver",
31141
31252
  type: "core::starknet::contract_address::ContractAddress"
31142
31253
  }
31143
31254
  ],
31255
+ state_mutability: "view"
31256
+ },
31257
+ {
31258
+ type: "function",
31259
+ name: "report_delay",
31260
+ inputs: [],
31144
31261
  outputs: [
31145
31262
  {
31146
- type: "core::integer::u256"
31263
+ type: "core::integer::u64"
31147
31264
  }
31148
31265
  ],
31149
- state_mutability: "external"
31266
+ state_mutability: "view"
31150
31267
  },
31151
31268
  {
31152
31269
  type: "function",
31153
- name: "max_mint",
31154
- inputs: [
31270
+ name: "vault_allocator",
31271
+ inputs: [],
31272
+ outputs: [
31155
31273
  {
31156
- name: "receiver",
31157
31274
  type: "core::starknet::contract_address::ContractAddress"
31158
31275
  }
31159
31276
  ],
31277
+ state_mutability: "view"
31278
+ },
31279
+ {
31280
+ type: "function",
31281
+ name: "last_report_timestamp",
31282
+ inputs: [],
31160
31283
  outputs: [
31161
31284
  {
31162
- type: "core::integer::u256"
31285
+ type: "core::integer::u64"
31163
31286
  }
31164
31287
  ],
31165
31288
  state_mutability: "view"
31166
31289
  },
31167
31290
  {
31168
31291
  type: "function",
31169
- name: "preview_mint",
31170
- inputs: [
31171
- {
31172
- name: "shares",
31173
- type: "core::integer::u256"
31174
- }
31175
- ],
31292
+ name: "max_delta",
31293
+ inputs: [],
31176
31294
  outputs: [
31177
31295
  {
31178
31296
  type: "core::integer::u256"
@@ -31182,15 +31300,11 @@ var universal_vault_abi_default = [
31182
31300
  },
31183
31301
  {
31184
31302
  type: "function",
31185
- name: "mint",
31303
+ name: "due_assets_from_id",
31186
31304
  inputs: [
31187
31305
  {
31188
- name: "shares",
31306
+ name: "id",
31189
31307
  type: "core::integer::u256"
31190
- },
31191
- {
31192
- name: "receiver",
31193
- type: "core::starknet::contract_address::ContractAddress"
31194
31308
  }
31195
31309
  ],
31196
31310
  outputs: [
@@ -31198,11 +31312,242 @@ var universal_vault_abi_default = [
31198
31312
  type: "core::integer::u256"
31199
31313
  }
31200
31314
  ],
31201
- state_mutability: "external"
31315
+ state_mutability: "view"
31202
31316
  },
31203
31317
  {
31204
31318
  type: "function",
31205
- name: "max_withdraw",
31319
+ name: "due_assets_from_owner",
31320
+ inputs: [
31321
+ {
31322
+ name: "owner",
31323
+ type: "core::starknet::contract_address::ContractAddress"
31324
+ }
31325
+ ],
31326
+ outputs: [
31327
+ {
31328
+ type: "core::integer::u256"
31329
+ }
31330
+ ],
31331
+ state_mutability: "view"
31332
+ },
31333
+ {
31334
+ type: "function",
31335
+ name: "set_deposit_limit",
31336
+ inputs: [
31337
+ {
31338
+ name: "limit",
31339
+ type: "core::integer::u256"
31340
+ }
31341
+ ],
31342
+ outputs: [],
31343
+ state_mutability: "external"
31344
+ },
31345
+ {
31346
+ type: "function",
31347
+ name: "set_mint_limit",
31348
+ inputs: [
31349
+ {
31350
+ name: "limit",
31351
+ type: "core::integer::u256"
31352
+ }
31353
+ ],
31354
+ outputs: [],
31355
+ state_mutability: "external"
31356
+ },
31357
+ {
31358
+ type: "function",
31359
+ name: "get_deposit_limit",
31360
+ inputs: [],
31361
+ outputs: [
31362
+ {
31363
+ type: "core::integer::u256"
31364
+ }
31365
+ ],
31366
+ state_mutability: "view"
31367
+ },
31368
+ {
31369
+ type: "function",
31370
+ name: "get_mint_limit",
31371
+ inputs: [],
31372
+ outputs: [
31373
+ {
31374
+ type: "core::integer::u256"
31375
+ }
31376
+ ],
31377
+ state_mutability: "view"
31378
+ }
31379
+ ]
31380
+ },
31381
+ {
31382
+ type: "impl",
31383
+ name: "ERC4626Impl",
31384
+ interface_name: "openzeppelin_interfaces::token::erc4626::IERC4626"
31385
+ },
31386
+ {
31387
+ type: "interface",
31388
+ name: "openzeppelin_interfaces::token::erc4626::IERC4626",
31389
+ items: [
31390
+ {
31391
+ type: "function",
31392
+ name: "asset",
31393
+ inputs: [],
31394
+ outputs: [
31395
+ {
31396
+ type: "core::starknet::contract_address::ContractAddress"
31397
+ }
31398
+ ],
31399
+ state_mutability: "view"
31400
+ },
31401
+ {
31402
+ type: "function",
31403
+ name: "total_assets",
31404
+ inputs: [],
31405
+ outputs: [
31406
+ {
31407
+ type: "core::integer::u256"
31408
+ }
31409
+ ],
31410
+ state_mutability: "view"
31411
+ },
31412
+ {
31413
+ type: "function",
31414
+ name: "convert_to_shares",
31415
+ inputs: [
31416
+ {
31417
+ name: "assets",
31418
+ type: "core::integer::u256"
31419
+ }
31420
+ ],
31421
+ outputs: [
31422
+ {
31423
+ type: "core::integer::u256"
31424
+ }
31425
+ ],
31426
+ state_mutability: "view"
31427
+ },
31428
+ {
31429
+ type: "function",
31430
+ name: "convert_to_assets",
31431
+ inputs: [
31432
+ {
31433
+ name: "shares",
31434
+ type: "core::integer::u256"
31435
+ }
31436
+ ],
31437
+ outputs: [
31438
+ {
31439
+ type: "core::integer::u256"
31440
+ }
31441
+ ],
31442
+ state_mutability: "view"
31443
+ },
31444
+ {
31445
+ type: "function",
31446
+ name: "max_deposit",
31447
+ inputs: [
31448
+ {
31449
+ name: "receiver",
31450
+ type: "core::starknet::contract_address::ContractAddress"
31451
+ }
31452
+ ],
31453
+ outputs: [
31454
+ {
31455
+ type: "core::integer::u256"
31456
+ }
31457
+ ],
31458
+ state_mutability: "view"
31459
+ },
31460
+ {
31461
+ type: "function",
31462
+ name: "preview_deposit",
31463
+ inputs: [
31464
+ {
31465
+ name: "assets",
31466
+ type: "core::integer::u256"
31467
+ }
31468
+ ],
31469
+ outputs: [
31470
+ {
31471
+ type: "core::integer::u256"
31472
+ }
31473
+ ],
31474
+ state_mutability: "view"
31475
+ },
31476
+ {
31477
+ type: "function",
31478
+ name: "deposit",
31479
+ inputs: [
31480
+ {
31481
+ name: "assets",
31482
+ type: "core::integer::u256"
31483
+ },
31484
+ {
31485
+ name: "receiver",
31486
+ type: "core::starknet::contract_address::ContractAddress"
31487
+ }
31488
+ ],
31489
+ outputs: [
31490
+ {
31491
+ type: "core::integer::u256"
31492
+ }
31493
+ ],
31494
+ state_mutability: "external"
31495
+ },
31496
+ {
31497
+ type: "function",
31498
+ name: "max_mint",
31499
+ inputs: [
31500
+ {
31501
+ name: "receiver",
31502
+ type: "core::starknet::contract_address::ContractAddress"
31503
+ }
31504
+ ],
31505
+ outputs: [
31506
+ {
31507
+ type: "core::integer::u256"
31508
+ }
31509
+ ],
31510
+ state_mutability: "view"
31511
+ },
31512
+ {
31513
+ type: "function",
31514
+ name: "preview_mint",
31515
+ inputs: [
31516
+ {
31517
+ name: "shares",
31518
+ type: "core::integer::u256"
31519
+ }
31520
+ ],
31521
+ outputs: [
31522
+ {
31523
+ type: "core::integer::u256"
31524
+ }
31525
+ ],
31526
+ state_mutability: "view"
31527
+ },
31528
+ {
31529
+ type: "function",
31530
+ name: "mint",
31531
+ inputs: [
31532
+ {
31533
+ name: "shares",
31534
+ type: "core::integer::u256"
31535
+ },
31536
+ {
31537
+ name: "receiver",
31538
+ type: "core::starknet::contract_address::ContractAddress"
31539
+ }
31540
+ ],
31541
+ outputs: [
31542
+ {
31543
+ type: "core::integer::u256"
31544
+ }
31545
+ ],
31546
+ state_mutability: "external"
31547
+ },
31548
+ {
31549
+ type: "function",
31550
+ name: "max_withdraw",
31206
31551
  inputs: [
31207
31552
  {
31208
31553
  name: "owner",
@@ -33899,336 +34244,6 @@ var HyperLSTStrategies = [
33899
34244
  getStrategySettings("mRe7YIELD", "mRe7YIELD", hypermRe7YIELD, false, false)
33900
34245
  ];
33901
34246
 
33902
- // src/strategies/universal-adapters/avnu-adapter.ts
33903
- import { hash as hash7, uint256 as uint25614 } from "starknet";
33904
- import axios10 from "axios";
33905
- var AvnuAdapter = class _AvnuAdapter extends BaseAdapter {
33906
- constructor(config) {
33907
- super(config, _AvnuAdapter.name, Protocols.AVNU);
33908
- this.config = config;
33909
- this.avnuWrapper = new AvnuWrapper();
33910
- }
33911
- //abstract means the method has no implementation in this class; instead, child classes must implement it.
33912
- async getAPY(supportedPosition) {
33913
- return Promise.resolve({ apy: 0, type: "base" /* BASE */ });
33914
- }
33915
- async getPosition(supportedPosition) {
33916
- return Promise.resolve({ amount: new Web3Number(0, 0), remarks: "" });
33917
- }
33918
- async maxDeposit(amount) {
33919
- return Promise.resolve({
33920
- tokenInfo: this.config.baseToken,
33921
- amount: new Web3Number(0, 0),
33922
- usdValue: 0,
33923
- apy: { apy: 0, type: "base" /* BASE */ },
33924
- protocol: Protocols.AVNU,
33925
- remarks: ""
33926
- });
33927
- }
33928
- async maxWithdraw() {
33929
- return Promise.resolve({
33930
- tokenInfo: this.config.baseToken,
33931
- amount: new Web3Number(0, 0),
33932
- usdValue: 0,
33933
- apy: { apy: 0, type: "base" /* BASE */ },
33934
- protocol: Protocols.AVNU,
33935
- remarks: ""
33936
- });
33937
- }
33938
- _getDepositLeaf() {
33939
- const vaultAllocator = ContractAddr.from(
33940
- this.config.vaultAllocator.address
33941
- );
33942
- return [
33943
- {
33944
- target: this.config.supportedPositions[0].asset.address,
33945
- method: "approve",
33946
- packedArguments: [
33947
- AVNU_EXCHANGE.toBigInt()
33948
- ],
33949
- sanitizer: SIMPLE_SANITIZER,
33950
- id: `approve_${this.config.supportedPositions[0].asset.symbol}`
33951
- },
33952
- {
33953
- target: AVNU_EXCHANGE,
33954
- method: "multi_route_swap",
33955
- packedArguments: [
33956
- this.config.supportedPositions[0].asset.address.toBigInt(),
33957
- //usdc
33958
- this.config.supportedPositions[1].asset.address.toBigInt(),
33959
- //wbtc
33960
- vaultAllocator.toBigInt()
33961
- ],
33962
- sanitizer: SIMPLE_SANITIZER,
33963
- id: `asutb_${this.config.supportedPositions[0].asset.symbol}_${this.config.supportedPositions[1].asset.symbol}`
33964
- }
33965
- ];
33966
- }
33967
- _getWithdrawLeaf() {
33968
- const vaultAllocator = ContractAddr.from(
33969
- this.config.vaultAllocator.address
33970
- );
33971
- const toToken = this.config.supportedPositions[0].asset;
33972
- const fromToken = this.config.supportedPositions[1].asset;
33973
- return [
33974
- {
33975
- target: fromToken.address,
33976
- method: "approve",
33977
- packedArguments: [
33978
- AVNU_EXCHANGE.toBigInt()
33979
- ],
33980
- sanitizer: SIMPLE_SANITIZER,
33981
- id: `approve_${fromToken.symbol}`
33982
- },
33983
- {
33984
- target: AVNU_EXCHANGE,
33985
- method: "multi_route_swap",
33986
- packedArguments: [
33987
- fromToken.address.toBigInt(),
33988
- //wbtc
33989
- toToken.address.toBigInt(),
33990
- //usdc
33991
- vaultAllocator.toBigInt()
33992
- ],
33993
- sanitizer: SIMPLE_SANITIZER,
33994
- id: `asbtu_${fromToken.symbol}_${fromToken.symbol}`
33995
- }
33996
- ];
33997
- }
33998
- _getLegacySwapLeaf() {
33999
- return [];
34000
- }
34001
- async getDepositCall(params) {
34002
- try {
34003
- const fromToken = this.config.supportedPositions[0].asset;
34004
- const toToken = this.config.supportedPositions[1].asset;
34005
- const vaultAllocator = ContractAddr.from(
34006
- this.config.vaultAllocator.address
34007
- );
34008
- const quote = await this.getQuotesAvnu(
34009
- fromToken.address.toString(),
34010
- toToken.address.toString(),
34011
- params.amount.toNumber(),
34012
- vaultAllocator.address.toString(),
34013
- toToken.decimals,
34014
- true
34015
- );
34016
- if (!quote) {
34017
- logger.error("error getting quote from avnu");
34018
- return [];
34019
- }
34020
- const getCalldata = await this.avnuWrapper.getSwapCallData(
34021
- quote,
34022
- vaultAllocator.address
34023
- );
34024
- const swapCallData = getCalldata[0];
34025
- const amount = uint25614.bnToUint256(quote.sellAmountInUsd * 10 ** 7);
34026
- return [
34027
- {
34028
- sanitizer: SIMPLE_SANITIZER,
34029
- call: {
34030
- contractAddress: fromToken.address,
34031
- selector: hash7.getSelectorFromName("approve"),
34032
- calldata: [
34033
- AVNU_EXCHANGE.toBigInt(),
34034
- toBigInt(amount.low.toString()),
34035
- // amount low
34036
- toBigInt(amount.high.toString())
34037
- // amount high
34038
- ]
34039
- }
34040
- },
34041
- {
34042
- sanitizer: SIMPLE_SANITIZER,
34043
- call: {
34044
- contractAddress: AVNU_EXCHANGE,
34045
- selector: hash7.getSelectorFromName("multi_route_swap"),
34046
- calldata: swapCallData
34047
- }
34048
- }
34049
- ];
34050
- } catch (error) {
34051
- logger.error(`Error getting Avnu quote: ${error}`);
34052
- return [];
34053
- }
34054
- }
34055
- //Swap wbtc to usdc
34056
- async getWithdrawCall(params) {
34057
- try {
34058
- const toToken = this.config.supportedPositions[0].asset;
34059
- const fromToken = this.config.supportedPositions[1].asset;
34060
- const vaultAllocator = ContractAddr.from(
34061
- this.config.vaultAllocator.address
34062
- );
34063
- const quote = await this.getQuotesAvnu(
34064
- fromToken.address.toString(),
34065
- toToken.address.toString(),
34066
- params.amount.toNumber(),
34067
- vaultAllocator.address.toString(),
34068
- fromToken.decimals,
34069
- false
34070
- );
34071
- if (!quote) {
34072
- logger.error("No quotes available for this swap, error in quotes avnu");
34073
- return [];
34074
- }
34075
- const getCalldata = await this.avnuWrapper.getSwapCallData(
34076
- quote,
34077
- vaultAllocator.address
34078
- );
34079
- const swapCallData = getCalldata[0];
34080
- const amount = uint25614.bnToUint256(params.amount.toWei());
34081
- return [
34082
- {
34083
- sanitizer: SIMPLE_SANITIZER,
34084
- call: {
34085
- contractAddress: fromToken.address,
34086
- selector: hash7.getSelectorFromName("approve"),
34087
- calldata: [
34088
- AVNU_EXCHANGE.toBigInt(),
34089
- toBigInt(amount.low.toString()),
34090
- // amount low
34091
- toBigInt(amount.high.toString())
34092
- // amount high
34093
- ]
34094
- }
34095
- },
34096
- {
34097
- sanitizer: SIMPLE_SANITIZER,
34098
- call: {
34099
- contractAddress: AVNU_EXCHANGE,
34100
- selector: hash7.getSelectorFromName("multi_route_swap"),
34101
- calldata: swapCallData
34102
- }
34103
- }
34104
- ];
34105
- } catch (error) {
34106
- logger.error(`Error getting Avnu quote: ${error}`);
34107
- return [];
34108
- }
34109
- }
34110
- async getSwapCallData(quote) {
34111
- return await this.avnuWrapper.getSwapCallData(quote, this.config.vaultAllocator.address);
34112
- }
34113
- async getHealthFactor() {
34114
- return Promise.resolve(1);
34115
- }
34116
- async fetchQuoteWithRetry(params, retries = 5) {
34117
- for (let attempt = 0; attempt < retries; attempt++) {
34118
- try {
34119
- const response = await axios10.get(this.config.baseUrl, { params });
34120
- if (response.data && response.data.length > 0) {
34121
- return response;
34122
- }
34123
- throw new Error("Empty response data");
34124
- } catch (err) {
34125
- logger.error(`Error fetching quote with retry: ${err}`);
34126
- if (attempt === retries - 1) {
34127
- throw err;
34128
- }
34129
- await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
34130
- }
34131
- }
34132
- throw new Error("Failed to fetch quote after retries");
34133
- }
34134
- async getQuotesAvnu(from_token_address, to_token_address, amount, takerAddress, toTokenDecimals, usdcToBtc, maxIterations = 5, tolerance = 5e3) {
34135
- try {
34136
- const fromToken = this.config.supportedPositions[0].asset;
34137
- const toToken = this.config.supportedPositions[1].asset;
34138
- if (!usdcToBtc) {
34139
- const sellAmount2 = returnFormattedAmount(amount, toTokenDecimals);
34140
- const params2 = {
34141
- sellTokenAddress: from_token_address,
34142
- buyTokenAddress: to_token_address,
34143
- takerAddress,
34144
- sellAmount: sellAmount2
34145
- };
34146
- const finalQuote2 = await this.fetchQuoteWithRetry(params2);
34147
- if (!finalQuote2.data.length) {
34148
- logger.error("No quotes available for this swap, error in quotes avnu");
34149
- return null;
34150
- }
34151
- const dataObject2 = finalQuote2.data[0];
34152
- return dataObject2;
34153
- }
34154
- const btcPrice = await this.getPriceOfToken(toToken.address.toString());
34155
- if (!btcPrice) {
34156
- logger.error(`error getting btc price: ${btcPrice}`);
34157
- return null;
34158
- }
34159
- const estimatedUsdcAmount = Math.floor(amount * btcPrice);
34160
- const targetBtcBig = BigInt(returnFormattedAmount(amount, toTokenDecimals));
34161
- let low = BigInt(
34162
- Math.floor(
34163
- estimatedUsdcAmount * 10 ** fromToken.decimals * 0.9
34164
- )
34165
- );
34166
- let high = BigInt(
34167
- Math.floor(
34168
- estimatedUsdcAmount * 10 ** fromToken.decimals * 1.1
34169
- )
34170
- );
34171
- let mid = 0n;
34172
- for (let i = 0; i < maxIterations; i++) {
34173
- mid = (low + high) / 2n;
34174
- const sellAmount2 = returnFormattedAmount(Number(mid), 0);
34175
- const quote = await this.fetchQuoteWithRetry({
34176
- sellTokenAddress: from_token_address,
34177
- buyTokenAddress: to_token_address,
34178
- takerAddress,
34179
- sellAmount: sellAmount2
34180
- });
34181
- const gotBtc = BigInt(quote.data[0].buyAmount);
34182
- if (gotBtc === targetBtcBig) return quote.data[0];
34183
- if (gotBtc > targetBtcBig) {
34184
- high = mid;
34185
- } else {
34186
- low = mid;
34187
- }
34188
- if (gotBtc >= targetBtcBig && gotBtc <= targetBtcBig + BigInt(tolerance)) {
34189
- return quote.data[0];
34190
- }
34191
- }
34192
- let sellAmount = returnFormattedAmount(
34193
- Number(mid),
34194
- 0
34195
- );
34196
- const params = {
34197
- sellTokenAddress: from_token_address,
34198
- buyTokenAddress: to_token_address,
34199
- takerAddress,
34200
- sellAmount
34201
- };
34202
- const finalQuote = await this.fetchQuoteWithRetry(params);
34203
- if (!finalQuote.data.length) {
34204
- logger.error("No quotes available for this swap, error in quotes avnu");
34205
- return null;
34206
- }
34207
- const dataObject = finalQuote.data[0];
34208
- return dataObject;
34209
- } catch (err) {
34210
- logger.error(`No quotes available for this swap: ${err}`);
34211
- return null;
34212
- }
34213
- }
34214
- async getPriceOfToken(tokenAddress, retries = MAX_RETRIES) {
34215
- try {
34216
- const url = `https://starknet.impulse.avnu.fi/v1/tokens/${tokenAddress}/prices/line`;
34217
- const response = await axios10.get(url);
34218
- const length = response.data.length;
34219
- return response.data[length - 1].value;
34220
- } catch (err) {
34221
- if (retries > 0) {
34222
- await new Promise((resolve) => setTimeout(resolve, MAX_DELAY));
34223
- return this.getPriceOfToken(tokenAddress, retries - 1);
34224
- } else {
34225
- logger.error(`Failed to fetch price for ${tokenAddress} after ${MAX_RETRIES} attempts`);
34226
- return null;
34227
- }
34228
- }
34229
- }
34230
- };
34231
-
34232
34247
  // src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx
34233
34248
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
34234
34249
  var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy extends SVKStrategy {
@@ -39087,6 +39102,7 @@ export {
39087
39102
  AssetOperationStatus,
39088
39103
  AssetOperationType,
39089
39104
  AutoCompounderSTRK,
39105
+ AvnuAdapter,
39090
39106
  AvnuWrapper,
39091
39107
  BaseAdapter,
39092
39108
  BaseStrategy,
@@ -39162,6 +39178,7 @@ export {
39162
39178
  calculateExtendedLevergae,
39163
39179
  calculateVesUPositionSizeGivenExtended,
39164
39180
  calculateVesuLeverage,
39181
+ calculateWBTCAmountToMaintainLTV,
39165
39182
  extensionMap,
39166
39183
  getContractDetails,
39167
39184
  getFAQs,