Skip to content
1,460 changes: 1,460 additions & 0 deletions cadence/contracts/mocks/FlowTransactionScheduler.cdc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import "FlowYieldVaultsAutoBalancers"

/// Returns both currentValue and valueOfDeposits for the AutoBalancer in a single script call.
/// This reduces script call overhead when both values are needed.
///
/// Returns: [currentValue, valueOfDeposits] or nil if AutoBalancer doesn't exist
///
access(all)
fun main(id: UInt64): [UFix64]? {
if let autoBalancer = FlowYieldVaultsAutoBalancers.borrowAutoBalancer(id: id) {
let currentValue = autoBalancer.currentValue() ?? 0.0
let valueOfDeposits = autoBalancer.valueOfDeposits()
return [currentValue, valueOfDeposits]
}
return nil
}
36 changes: 32 additions & 4 deletions cadence/tests/evm_state_helpers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ access(all) fun setVaultSharePrice(

/* --- Uniswap V3 Pool State Manipulation --- */

/// Set Uniswap V3 pool to a specific price via EVM.store
/// Creates pool if it doesn't exist, then manipulates state
/// Price is specified as UFix128 for high precision (24 decimal places)
/// Set Uniswap V3 pool to a specific price with infinite liquidity (zero slippage).
access(all) fun setPoolToPrice(
factoryAddress: String,
tokenAAddress: String,
Expand All @@ -45,7 +43,37 @@ access(all) fun setPoolToPrice(
code: Test.readFile("transactions/set_uniswap_v3_pool_price.cdc"),
authorizers: [signer.address],
signers: [signer],
arguments: [factoryAddress, tokenAAddress, tokenBAddress, fee, priceTokenBPerTokenA, tokenABalanceSlot, tokenBBalanceSlot]
arguments: [factoryAddress, tokenAAddress, tokenBAddress, fee, priceTokenBPerTokenA, tokenABalanceSlot, tokenBBalanceSlot, 0.0, 0 as Int256, 0.0, 1.0]
)
)
Test.expect(seedResult, Test.beSucceeded())
}

/// Set Uniswap V3 pool to a specific price with finite TVL and concentrated liquidity.
/// tvl: total pool TVL in USD (e.g. 500_000.0)
/// tickRange: ±ticks from current price (e.g. 100 = ±1% for tick_spacing=10)
/// tvlFraction: fraction of TVL placed as liquidity (e.g. 0.95 = 95%)
/// tokenBPriceUSD: USD price of tokenB (1.0 for stablecoins)
access(all) fun setPoolToPriceWithTVL(
factoryAddress: String,
tokenAAddress: String,
tokenBAddress: String,
fee: UInt64,
priceTokenBPerTokenA: UFix128,
tokenABalanceSlot: UInt256,
tokenBBalanceSlot: UInt256,
signer: Test.TestAccount,
tvl: UFix64,
tickRange: Int,
tvlFraction: UFix64,
tokenBPriceUSD: UFix64
) {
let seedResult = Test.executeTransaction(
Test.Transaction(
code: Test.readFile("transactions/set_uniswap_v3_pool_price.cdc"),
authorizers: [signer.address],
signers: [signer],
arguments: [factoryAddress, tokenAAddress, tokenBAddress, fee, priceTokenBPerTokenA, tokenABalanceSlot, tokenBBalanceSlot, tvl, Int256(tickRange), tvlFraction, tokenBPriceUSD]
)
)
Test.expect(seedResult, Test.beSucceeded())
Expand Down
Loading