Documentation
¶
Index ¶
- Variables
- func ExactInputSingleSwap(tops *bind.TransactOpts, swapRouter *uniswapv3.SwapRouter02, ...) (tx *types.Transaction, err error)
- func Init(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, ...) (uniswapV3Config UniswapV3Config, poolConfig PoolConfig, err error)
- func PercentageToUniswapFeeTier(p float64) *big.Int
- func Run(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, ...) (start, end time.Time, txHash common.Hash, err error)
- func SetupLiquidityPool(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, ...) error
- type Contract
- type ContractConfig
- type InitParams
- type PoolConfig
- type UniswapV3Addresses
- type UniswapV3Config
Constants ¶
This section is empty.
Variables ¶
var ( // Only a few fee tiers are possible in UniswapV3. They are represented in percentage. // https://uniswapv3book.com/docs/milestone_5/swap-fees/#accruing-swap-fees StableTier feeTier = 0.05 // 500 StandardTier feeTier = 0.3 // 3_000 ExoticTier feeTier = 1 // 10_000 )
var ( // The amount of token to mint when deploying the ERC20 contract. MintAmount = big.NewInt(999_999_999_999_999_999) )
var SwapAmountInput = big.NewInt(1_000)
The amount of inbound token given as swap input.
Functions ¶
func ExactInputSingleSwap ¶
func ExactInputSingleSwap(tops *bind.TransactOpts, swapRouter *uniswapv3.SwapRouter02, poolConfig PoolConfig, amountIn *big.Int, recipient common.Address, nonce uint64) (tx *types.Transaction, err error)
ExactInputSingleSwap performs a UniswapV3 swap using the `ExactInputSingle` method which swaps a fixed amount of one token for a maximum possible amount of another token. The direction of the swap is determined by the nonce value.
func Init ¶
func Init(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts, uniswapAddresses UniswapV3Addresses, recipient common.Address, params InitParams) (uniswapV3Config UniswapV3Config, poolConfig PoolConfig, err error)
Init initializes the UniswapV3 loadtest by deploying contracts and setting up the pool. Returns the UniswapV3 config and pool config needed for running swaps.
func PercentageToUniswapFeeTier ¶
PercentageToUniswapFeeTier takes a percentage and returns the corresponding UniswapV3 fee tier.
func Run ¶
func Run(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, uniswapV3Config UniswapV3Config, poolConfig PoolConfig, swapAmountIn *big.Int, recipient common.Address) (start, end time.Time, txHash common.Hash, err error)
Run performs a single UniswapV3 swap operation. Returns the start time, end time, transaction hash, and any error.
func SetupLiquidityPool ¶
func SetupLiquidityPool(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts, uniswapV3Config UniswapV3Config, poolConfig PoolConfig, recipient common.Address) error
SetupLiquidityPool sets up a UniswapV3 liquidity pool, creating and initializing it if needed, and providing liquidity in case none exists.
Types ¶
type Contract ¶
type Contract interface {
uniswapv3.UniswapV3Factory | uniswapv3.UniswapInterfaceMulticall | uniswapv3.ProxyAdmin | uniswapv3.TickLens | uniswapv3.NFTDescriptor | uniswapv3.NonfungibleTokenPositionDescriptor | uniswapv3.TransparentUpgradeableProxy | uniswapv3.NonfungiblePositionManager | uniswapv3.V3Migrator | uniswapv3.UniswapV3Staker | uniswapv3.QuoterV2 | uniswapv3.SwapRouter02 | uniswapv3.WETH9 | tokens.ERC20
}
Contract represents a UniswapV3 contract (including WETH9 and Swapper).
type ContractConfig ¶
ContractConfig represents a contract and its address.
func DeployERC20 ¶
func DeployERC20(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts, uniswapV3Config UniswapV3Config, tokenName, tokenSymbol string, amount *big.Int, recipient common.Address, tokenKnownAddress common.Address) (tokenConfig ContractConfig[tokens.ERC20], err error)
Deploy an ERC20 token.
type InitParams ¶
type InitParams struct {
// Pre-deployed token addresses (optional - if empty, new tokens are deployed)
PoolToken0Address common.Address
PoolToken1Address common.Address
// Pool configuration (fee tier as *big.Int from PercentageToUniswapFeeTier)
PoolFees *big.Int
}
InitParams holds parameters for initializing the UniswapV3 loadtest.
type PoolConfig ¶
type PoolConfig struct {
Token0, Token1 ContractConfig[tokens.ERC20]
ReserveA, ReserveB *big.Int
Fees *big.Int
}
PoolConfig represents the configuration of a UniswapV3 pool.
func NewPool ¶
func NewPool(token0, token1 ContractConfig[tokens.ERC20], fees *big.Int) *PoolConfig
Create a new `PoolConfig` object.
type UniswapV3Addresses ¶
type UniswapV3Addresses struct {
FactoryV3, Multicall, ProxyAdmin, TickLens, NFTDescriptorLib, NonfungibleTokenPositionDescriptor, TransparentUpgradeableProxy, NonfungiblePositionManager, Migrator, Staker, QuoterV2, SwapRouter02, WETH9 common.Address
}
UniswapV3Addresses is a subset of UniswapV3Config. It represents the addresses of the whole UniswapV3 configuration, including WETH9.
type UniswapV3Config ¶
type UniswapV3Config struct {
FactoryV3 ContractConfig[uniswapv3.UniswapV3Factory]
Multicall ContractConfig[uniswapv3.UniswapInterfaceMulticall]
ProxyAdmin ContractConfig[uniswapv3.ProxyAdmin]
TickLens ContractConfig[uniswapv3.TickLens]
NFTDescriptorLib ContractConfig[uniswapv3.NFTDescriptor]
NonfungibleTokenPositionDescriptor ContractConfig[uniswapv3.NonfungibleTokenPositionDescriptor]
TransparentUpgradeableProxy ContractConfig[uniswapv3.TransparentUpgradeableProxy]
NonfungiblePositionManager ContractConfig[uniswapv3.NonfungiblePositionManager]
Migrator ContractConfig[uniswapv3.V3Migrator]
Staker ContractConfig[uniswapv3.UniswapV3Staker]
QuoterV2 ContractConfig[uniswapv3.QuoterV2]
SwapRouter02 ContractConfig[uniswapv3.SwapRouter02]
WETH9 ContractConfig[uniswapv3.WETH9]
}
UniswapV3Config represents the whole UniswapV3 configuration (contracts and addresses), including WETH9.
func DeployUniswapV3 ¶
func DeployUniswapV3(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, cops *bind.CallOpts, knownAddresses UniswapV3Addresses, ownerAddress common.Address) (config UniswapV3Config, err error)
Deploy the full UniswapV3 contract suite in 15 different steps. Source: https://github.com/Uniswap/deploy-v3
func (*UniswapV3Config) GetAddresses ¶
func (c *UniswapV3Config) GetAddresses() UniswapV3Addresses
Return contracts addresses from the UniswapV3 configuration.