Skip to content
Open
22 changes: 11 additions & 11 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,16 +43,17 @@ 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, 0.0, 0.0, 1.0]
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. 10_000_000.0 for $10M)
/// concentration: fraction 0.0-1.0 (e.g. 0.80 for 80% of liquidity in narrow range)
/// tokenBPriceUSD: USD price of tokenB (e.g. 1.0 for stablecoins)
/// 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,
Expand All @@ -63,17 +62,18 @@ access(all) fun setPoolToPriceWithTVL(
priceTokenBPerTokenA: UFix128,
tokenABalanceSlot: UInt256,
tokenBBalanceSlot: UInt256,
signer: Test.TestAccount,
tvl: UFix64,
concentration: UFix64,
tokenBPriceUSD: UFix64,
signer: Test.TestAccount
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, concentration, tokenBPriceUSD]
arguments: [factoryAddress, tokenAAddress, tokenBAddress, fee, priceTokenBPerTokenA, tokenABalanceSlot, tokenBBalanceSlot, tvl, Int256(tickRange), tvlFraction, tokenBPriceUSD]
)
)
Test.expect(seedResult, Test.beSucceeded())
Expand Down
21 changes: 12 additions & 9 deletions cadence/tests/evm_state_helpers_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ fun test_ConcentratedLiquiditySlippage() {
priceTokenBPerTokenA: 1.0,
tokenABalanceSlot: wflowBalanceSlot,
tokenBBalanceSlot: pyusd0BalanceSlot,
signer: testAccount,
tvl: 500_000.0,
concentration: 0.80,
tokenBPriceUSD: 1.0,
signer: testAccount
tickRange: 100,
tvlFraction: 0.80,
tokenBPriceUSD: 1.0
)

let concBefore = getBalance(address: testAccount.address, vaultPublicPath: pyusd0PublicPath)!
Expand Down Expand Up @@ -229,10 +230,11 @@ fun test_ConcentratedLiquiditySlippage() {
priceTokenBPerTokenA: 1.0,
tokenABalanceSlot: wflowBalanceSlot,
tokenBBalanceSlot: pyusd0BalanceSlot,
signer: testAccount,
tvl: 5_000_000.0,
concentration: 0.80,
tokenBPriceUSD: 1.0,
signer: testAccount
tickRange: 100,
tvlFraction: 0.80,
tokenBPriceUSD: 1.0
)

let bigBefore = getBalance(address: testAccount.address, vaultPublicPath: pyusd0PublicPath)!
Expand Down Expand Up @@ -263,10 +265,11 @@ fun test_ConcentratedLiquiditySlippage() {
priceTokenBPerTokenA: 1.0,
tokenABalanceSlot: wflowBalanceSlot,
tokenBBalanceSlot: pyusd0BalanceSlot,
signer: testAccount,
tvl: 500_000.0,
concentration: 0.80,
tokenBPriceUSD: 1.0,
signer: testAccount
tickRange: 100,
tvlFraction: 0.80,
tokenBPriceUSD: 1.0
)

let smallBefore = getBalance(address: testAccount.address, vaultPublicPath: pyusd0PublicPath)!
Expand Down
Loading
Loading