Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions contracts/interfaces/external/IRamsesV3Factory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the Ramses V3 Factory
/// @notice The Ramses V3 Factory facilitates creation of Ramses V3 pools and control over the protocol fees
interface IRamsesV3Factory {
error IT();
/// @dev Fee Too Large
error FTL();
error A0();
error F0();
error PE();

/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);

/// @notice Emitted when a new tickspacing amount is enabled for pool creation via the factory
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param fee The fee, denominated in hundredths of a bip
event TickSpacingEnabled(int24 indexed tickSpacing, uint24 indexed fee);

/// @notice Emitted when the protocol fee is changed
/// @param feeProtocolOld The previous value of the protocol fee
/// @param feeProtocolNew The updated value of the protocol fee
event SetFeeProtocol(uint8 feeProtocolOld, uint8 feeProtocolNew);

/// @notice Emitted when the protocol fee is changed
/// @param pool The pool address
/// @param feeProtocolOld The previous value of the protocol fee
/// @param feeProtocolNew The updated value of the protocol fee
event SetPoolFeeProtocol(address pool, uint8 feeProtocolOld, uint8 feeProtocolNew);

/// @notice Emitted when a pool's fee is changed
/// @param pool The pool address
/// @param newFee The updated value of the protocol fee
event FeeAdjustment(address pool, uint24 newFee);

/// @notice Emitted when the fee collector is changed
/// @param oldFeeCollector The previous implementation
/// @param newFeeCollector The new implementation
event FeeCollectorChanged(address indexed oldFeeCollector, address indexed newFeeCollector);

/// @notice Returns the PoolDeployer address
/// @return The address of the PoolDeployer contract
function ramsesV3PoolDeployer() external returns (address);

/// @notice Returns the fee amount for a given tickSpacing, if enabled, or 0 if not enabled
/// @dev A tickSpacing can never be removed, so this value should be hard coded or cached in the calling context
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @param tickSpacing The enabled tickSpacing. Returns 0 in case of unenabled tickSpacing
/// @return initialFee The initial fee
function tickSpacingInitialFee(int24 tickSpacing) external view returns (uint24 initialFee);

/// @notice Returns the pool address for a given pair of tokens and a tickSpacing, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param tickSpacing The tickSpacing of the pool
/// @return pool The pool address
function getPool(address tokenA, address tokenB, int24 tickSpacing) external view returns (address pool);

/// @notice Creates a pool for the given two tokens and fee
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param tickSpacing The desired tickSpacing for the pool
/// @param sqrtPriceX96 initial sqrtPriceX96 of the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0.
/// @dev The call will revert if the pool already exists, the tickSpacing is invalid, or the token arguments are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
int24 tickSpacing,
uint160 sqrtPriceX96
) external returns (address pool);

/// @notice Enables a tickSpacing with the given initialFee amount
/// @dev unlike UniswapV3, we map via the tickSpacing rather than the fee tier
/// @dev tickSpacings may never be removed once enabled
/// @param tickSpacing The spacing between ticks to be enforced for all pools created
/// @param initialFee The initial fee amount, denominated in hundredths of a bip (i.e. 1e-6)
function enableTickSpacing(int24 tickSpacing, uint24 initialFee) external;

/// @notice returns the default protocol fee.
/// @return _feeProtocol the default feeProtocol
function feeProtocol() external view returns (uint8 _feeProtocol);

/// @notice returns the % of fees directed to governance
/// @dev if the fee is 0, or the pool is uninitialized this will return the Factory's default feeProtocol
/// @param pool the address of the pool
/// @return _feeProtocol the feeProtocol for the pool
function poolFeeProtocol(address pool) external view returns (uint8 _feeProtocol);

/// @notice Sets the default protocol's % share of the fees
/// @param _feeProtocol new default protocol fee for token0 and token1
function setFeeProtocol(uint8 _feeProtocol) external;

/// @notice Get the parameters to be used in constructing the pool, set transiently during pool creation.
/// @dev Called by the pool constructor to fetch the parameters of the pool
/// @return factory The factory address
/// @return token0 The first token of the pool by address sort order
/// @return token1 The second token of the pool by address sort order
/// @return fee The initialized feetier of the pool, denominated in hundredths of a bip
/// @return tickSpacing The minimum number of ticks between initialized ticks
function parameters()
external
view
returns (address factory, address token0, address token1, uint24 fee, int24 tickSpacing);

/// @notice Sets the fee collector address
/// @param _feeCollector the fee collector address
function setFeeCollector(address _feeCollector) external;

/// @notice sets the swap fee for a specific pool
/// @param _pool address of the pool
/// @param _fee the fee to be assigned to the pool, scaled to 1_000_000 = 100%
function setFee(address _pool, uint24 _fee) external;

/// @notice Returns the address of the fee collector contract
/// @dev Fee collector decides where the protocol fees go (fee distributor, treasury, etc.)
function feeCollector() external view returns (address);

/// @notice sets the feeProtocol of a specific pool
/// @param pool address of the pool
/// @param _feeProtocol the fee protocol to assign
function setPoolFeeProtocol(address pool, uint8 _feeProtocol) external;

/// @notice sets the feeProtocol upon a gauge's creation
/// @param pool address of the pool
function gaugeFeeSplitEnable(address pool) external;

/// @notice sets the the voter address
/// @param _voter the address of the voter
function setVoter(address _voter) external;

function initialize(address poolDeployer) external;
}
27 changes: 27 additions & 0 deletions contracts/interfaces/external/IRamsesV3Pool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IRamsesV3PoolImmutables} from './shadow-cl/IRamsesV3PoolImmutables.sol';
import {IRamsesV3PoolState} from './shadow-cl/IRamsesV3PoolState.sol';
import {IRamsesV3PoolDerivedState} from './shadow-cl/IRamsesV3PoolDerivedState.sol';
import {IRamsesV3PoolActions} from './shadow-cl/IRamsesV3PoolActions.sol';
import {IRamsesV3PoolOwnerActions} from './shadow-cl/IRamsesV3PoolOwnerActions.sol';
import {IRamsesV3PoolErrors} from './shadow-cl/IRamsesV3PoolErrors.sol';
import {IRamsesV3PoolEvents} from './shadow-cl/IRamsesV3PoolEvents.sol';

/// @title The interface for a Ramses V3 Pool
/// @notice A Ramses pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IRamsesV3Pool is
IRamsesV3PoolImmutables,
IRamsesV3PoolState,
IRamsesV3PoolDerivedState,
IRamsesV3PoolActions,
IRamsesV3PoolOwnerActions,
IRamsesV3PoolErrors,
IRamsesV3PoolEvents
{
/// @notice if a new period, advance on interaction
function _advancePeriod() external;
}
111 changes: 111 additions & 0 deletions contracts/interfaces/external/shadow-cl/IRamsesV3PoolActions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IRamsesV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;

/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param index The index for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
uint256 index,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);

/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param index The index of the position to be collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
uint256 index,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);

/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param index The index for which the liquidity will be burned
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
uint256 index,
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);

/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);


/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;


/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
29 changes: 29 additions & 0 deletions contracts/interfaces/external/shadow-cl/IRamsesV3PoolDeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title An interface for a contract that is capable of deploying Ramses V3 Pools
/// @notice A contract that constructs a pool must implement this to pass arguments to the pool
/// @dev This is used to avoid having constructor arguments in the pool contract, which results in the init code hash
/// of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain
interface IRamsesV3PoolDeployer {
/// @notice Get the parameters to be used in constructing the pool, set transiently during pool creation.
/// @dev Called by the pool constructor to fetch the parameters of the pool
/// Returns factory The factory address
/// Returns token0 The first token of the pool by address sort order
/// Returns token1 The second token of the pool by address sort order
/// Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// Returns tickSpacing The minimum number of ticks between initialized ticks
function parameters()
external
view
returns (address factory, address token0, address token1, uint24 fee, int24 tickSpacing);

/// @dev Deploys a pool with the given parameters by transiently setting the parameters storage slot and then
/// clearing it after deploying the pool.
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param tickSpacing The tickSpacing of the pool
function deploy(address token0, address token1, int24 tickSpacing) external returns (address pool);

function RamsesV3Factory() external view returns (address factory);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IRamsesV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(
uint32[] calldata secondsAgos
) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(
int24 tickLower,
int24 tickUpper
) external view returns (int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside);
}
Loading