periphery

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const INCENTIVE_KEY_ABI = "tuple(address rewardToken, address pool, uint256 startTime, uint256 endTime, address refundee)"

Variables

View Source
var (
	ErrZeroLiquidity = errors.New("zero liquidity")
	ErrNoWETH        = errors.New("no WETH")
	ErrCannotBurn    = errors.New("cannot burn")
)
View Source
var (
	ErrTokenInDiff        = errors.New("TOKEN_IN_DIFF")
	ErrTokenOutDiff       = errors.New("TOKEN_OUT_DIFF")
	ErrNonTokenPermit     = errors.New("NON_TOKEN_PERMIT")
	ErrMultiHopPriceLimit = errors.New("MULTIHOP_PRICE_LIMIT")
)
View Source
var (
	ErrInvalidOptions = errors.New("invalid options")
)
View Source
var ErrMultihopPriceLimit = errors.New("MULTIHOP_PRICE_LIMIT")
View Source
var MaxUint128 = new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(128), nil), big.NewInt(1))

Functions

func AddCallParameters

func AddCallParameters(position *entities.Position, opts *AddLiquidityOptions) (*utils.MethodParameters, error)

func CollectCallParameters

func CollectCallParameters(opts *CollectOptions) (*utils.MethodParameters, error)

func CollectRewards added in v0.4.0

func CollectRewards(incentiveKeys []*IncentiveKey, options *ClaimOptions) (*utils.MethodParameters, error)

*

*
* Note:  A `tokenId` can be staked in many programs but to claim rewards and continue the program you must unstake, claim, and then restake.
* @param incentiveKeys An IncentiveKey or array of IncentiveKeys that `tokenId` is staked in.
* Input an array of IncentiveKeys to claim rewards for each program.
* @param options ClaimOptions to specify tokenId, recipient, and amount wanting to collect.
* Note that you can only specify one amount and one recipient across the various programs if you are collecting from multiple programs at once.
* @returns

func CreateCallParameters

func CreateCallParameters(pool *entities.Pool) (*utils.MethodParameters, error)

func EncodeAllowedPermit

func EncodeAllowedPermit(token *entities.Token, options *AllowedPermitArguments) ([]byte, error)

func EncodeClaim added in v0.4.0

func EncodeClaim(incentiveKey *IncentiveKey, options *ClaimOptions) ([][]byte, error)

* * To claim rewards, must unstake and then claim. * @param incentiveKey The unique identifier of a staking program. * @param options Options for producing the calldata to claim. Can't claim unless you unstake. * @returns The calldatas for 'unstakeToken' and 'claimReward'.

func EncodeDeposit added in v0.4.0

func EncodeDeposit(incentiveKeys []*IncentiveKey) ([]byte, error)

*

*
* @param incentiveKeys A single IncentiveKey or array of IncentiveKeys to be encoded and used in the data parameter in `safeTransferFrom`
* @returns An IncentiveKey as a string
*

func EncodeMulticall

func EncodeMulticall(calldatas [][]byte) ([]byte, error)

func EncodePermit

func EncodePermit(token *entities.Token, options *PermitOptions) ([]byte, error)

func EncodeRefundETH

func EncodeRefundETH() []byte

func EncodeRouteToPath added in v0.4.0

func EncodeRouteToPath(route *entities.Route, exactOutput bool) ([]byte, error)

*

  • Converts a route to a hex encoded path
  • @param route the v3 path to convert to an encoded path
  • @param exactOutput whether the route should be encoded in reverse, for making exact output swaps

func EncodeStandardPermit

func EncodeStandardPermit(token *entities.Token, options *StandardPermitArguments) ([]byte, error)

func EncodeSweepToken

func EncodeSweepToken(token *entities.Token, amountMinimum *big.Int, recipient common.Address, feeOptions *FeeOptions) ([]byte, error)

func EncodeUnwrapWETH9

func EncodeUnwrapWETH9(amountMinimum *big.Int, recipient common.Address, feeOptions *FeeOptions) ([]byte, error)

func GetABI added in v0.4.0

func GetABI(abi []byte) abi.ABI

func PutUint24 added in v0.4.0

func PutUint24(i uint64) []byte

PutUint24 put bigendian uint24

func QuoteCallParameters added in v0.4.0

func QuoteCallParameters(
	route *entities.Route,
	amount *core.CurrencyAmount,
	tradeType core.TradeType,
	options *QuoteOptions,
) (*utils.MethodParameters, error)

*

  • Produces the on-chain method name of the appropriate function within QuoterV2,
  • and the relevant hex encoded parameters.
  • @template TInput The input token, either Ether or an ERC-20
  • @template TOutput The output token, either Ether or an ERC-20
  • @param route The swap route, a list of pools through which a swap can occur
  • @param amount The amount of the quote, either an amount in, or an amount out
  • @param tradeType The trade type, either exact input or exact output
  • @returns The formatted calldata

func RemoveCallParameters

func RemoveCallParameters(position *entities.Position, opts *RemoveLiquidityOptions) (*utils.MethodParameters, error)

*

  • Produces the calldata for completely or partially exiting a position
  • @param position The position to exit
  • @param options Additional information necessary for generating the calldata
  • @returns The call parameters

func SafeTransferFromParameters

func SafeTransferFromParameters(opts *SafeTransferOptions) (*utils.MethodParameters, error)

func SwapCallParameters added in v0.4.0

func SwapCallParameters(trades []*entities.Trade, options *SwapOptions) (*utils.MethodParameters, error)

*

  • Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
  • @param trade to produce call parameters for
  • @param options options for the call parameters

func WithdrawToken added in v0.4.0

func WithdrawToken(incentiveKeys []*IncentiveKey, withdrawOptions *FullWithdrawOptions) (*utils.MethodParameters, error)

*

*
* @param incentiveKeys A list of incentiveKeys to unstake from. Should include all incentiveKeys (unique staking programs) that `options.tokenId` is staked in.
* @param withdrawOptions Options for producing claim calldata and withdraw calldata. Can't withdraw without unstaking all programs for `tokenId`.
* @returns Calldata for unstaking, claiming, and withdrawing.

Types

type AllowedPermitArguments

type AllowedPermitArguments struct {
	V      uint8
	R      [32]byte
	S      [32]byte
	Nonce  *big.Int
	Expiry *big.Int
}

type ClaimOptions added in v0.4.0

type ClaimOptions struct {
	TokenID   *big.Int       // The id of the NFT
	Recipient common.Address // Address to send rewards to.
	Amount    *big.Int       // The amount of `rewardToken` to claim. 0 claims all.
}

Options to specify when claiming rewards.

type CollectOptions

type CollectOptions struct {
	TokenID               *big.Int             // Indicates the ID of the position to collect for
	ExpectedCurrencyOwed0 *core.CurrencyAmount // Expected value of tokensOwed0, including as-of-yet-unaccounted-for fees/liquidity value to be burned
	ExpectedCurrencyOwed1 *core.CurrencyAmount // Expected value of tokensOwed1, including as-of-yet-unaccounted-for fees/liquidity value to be burned
	ExpectedTokenOwed0    core.Currency
	ExpectedTokenOwed1    core.Currency
	Recipient             common.Address // The account that should receive the tokens
}

type CollectParams

type CollectParams struct {
	TokenId    *big.Int
	Recipient  common.Address
	Amount0Max *big.Int
	Amount1Max *big.Int
}

type CommonAddLiquidityOptions

type CommonAddLiquidityOptions struct {
	SlippageTolerance *core.Percent  // How much the pool price is allowed to move
	Deadline          *big.Int       // When the transaction expires, in epoch seconds
	UseNative         *core.Ether    // Whether to spend ether. If true, one of the pool tokens must be WETH, by default false
	Token0Permit      *PermitOptions // The optional permit parameters for spending token0
	Token1Permit      *PermitOptions // The optional permit parameters for spending token1
}

Options for producing the calldata to add liquidity

type DecreaseLiquidityParams

type DecreaseLiquidityParams struct {
	TokenId    *big.Int
	Liquidity  *big.Int
	Amount0Min *big.Int
	Amount1Min *big.Int
	Deadline   *big.Int
}

type ExactInputParams added in v0.4.0

type ExactInputParams struct {
	Path             []byte
	Recipient        common.Address
	Deadline         *big.Int
	AmountIn         *big.Int
	AmountOutMinimum *big.Int
}

type ExactInputSingleParams added in v0.4.0

type ExactInputSingleParams struct {
	TokenIn           common.Address
	TokenOut          common.Address
	Fee               *big.Int
	Recipient         common.Address
	Deadline          *big.Int
	AmountIn          *big.Int
	AmountOutMinimum  *big.Int
	SqrtPriceLimitX96 *big.Int
}

type ExactOutputParams added in v0.4.0

type ExactOutputParams struct {
	Path            []byte
	Recipient       common.Address
	Deadline        *big.Int
	AmountOut       *big.Int
	AmountInMaximum *big.Int
}

type ExactOutputSingleParams added in v0.4.0

type ExactOutputSingleParams struct {
	TokenIn           common.Address
	TokenOut          common.Address
	Fee               *big.Int
	Recipient         common.Address
	Deadline          *big.Int
	AmountOut         *big.Int
	AmountInMaximum   *big.Int
	SqrtPriceLimitX96 *big.Int
}

type FeeOptions

type FeeOptions struct {
	Fee       *entities.Percent // The percent of the output that will be taken as a fee.
	Recipient common.Address    // The recipient of the fee.

}

type FullWithdrawOptions added in v0.4.0

type FullWithdrawOptions struct {
	ClaimOptions
	WithdrawOptions
}

type IncentiveKey added in v0.4.0

type IncentiveKey struct {
	RewardToken *core.Token    // The token rewarded for participating in the staking program.
	Pool        *entities.Pool // The pool that the staked positions must provide in.
	StartTime   *big.Int       // The time when the incentive program begins.
	EndTime     *big.Int       // The time that the incentive program ends.
	Refundee    common.Address // The address which receives any remaining reward tokens at `endTime`.
}

Represents a unique staking program.

type IncentiveKeyParams added in v0.4.0

type IncentiveKeyParams struct {
	RewardToken common.Address
	Pool        common.Address
	StartTime   *big.Int
	EndTime     *big.Int
	Refundee    common.Address
}

type IncreaseLiquidityParams

type IncreaseLiquidityParams struct {
	TokenId        *big.Int
	Amount0Desired *big.Int
	Amount1Desired *big.Int
	Amount0Min     *big.Int
	Amount1Min     *big.Int
	Deadline       *big.Int
}

type IncreaseOptions

type IncreaseOptions struct {
	*CommonAddLiquidityOptions
	*IncreaseSpecificOptions
}

type IncreaseSpecificOptions

type IncreaseSpecificOptions struct {
	TokenID *big.Int // Indicates the ID of the position to increase liquidity for
}

type MintOptions

type MintOptions struct {
	*CommonAddLiquidityOptions
	*MintSpecificOptions
}

type MintParams

type MintParams struct {
	Token0         common.Address
	Token1         common.Address
	Fee            *big.Int
	TickLower      *big.Int
	TickUpper      *big.Int
	Amount0Desired *big.Int
	Amount1Desired *big.Int
	Amount0Min     *big.Int
	Amount1Min     *big.Int
	Recipient      common.Address
	Deadline       *big.Int
}

type MintSpecificOptions

type MintSpecificOptions struct {
	Recipient  common.Address // The account that should receive the minted NFT
	CreatePool bool           // Creates pool if not initialized before mint
}

type NFTPermitOptions

type NFTPermitOptions struct {
	V        uint
	R        string
	S        string
	Deadline *big.Int
	Spender  string
}

type PermitOptions

type PermitOptions struct {
	*StandardPermitArguments
	*AllowedPermitArguments
}

type QuoteOptions added in v0.4.0

type QuoteOptions struct {
	SqrtPriceLimitX96 *big.Int // The optional price limit for the trade.
}

Optional arguments to send to the quoter.

type RemoveLiquidityOptions

type RemoveLiquidityOptions struct {
	TokenID             *big.Int          // The ID of the token to exit
	LiquidityPercentage *core.Percent     // The percentage of position liquidity to exit
	SlippageTolerance   *core.Percent     // How much the pool price is allowed to move
	Deadline            *big.Int          // When the transaction expires, in epoch seconds.
	BurnToken           bool              // Whether the NFT should be burned if the entire position is being exited, by default false
	Permit              *NFTPermitOptions // The optional permit of the token ID being exited, in case the exit transaction is being sent by an account that does not own the NFT
	CollectOptions      *CollectOptions   // Parameters to be passed on to collect
}

Options for producing the calldata to exit a position

type SafeTransferOptions

type SafeTransferOptions struct {
	Sender    common.Address // The account sending the NFT
	Recipient common.Address // The account that should receive the NFT
	TokenID   *big.Int       //  The id of the token being sent
	Data      []byte         // The optional parameter that passes data to the `onERC721Received` call for the staker
}

type StandardPermitArguments

type StandardPermitArguments struct {
	V        uint8
	R        [32]byte
	S        [32]byte
	Amount   *big.Int
	Deadline *big.Int
}

type SwapOptions added in v0.4.0

type SwapOptions struct {
	SlippageTolerance *core.Percent  // How much the execution price is allowed to move unfavorably from the trade execution price.
	Recipient         common.Address // The account that should receive the output.
	Deadline          *big.Int       // When the transaction expires, in epoch seconds.
	InputTokenPermit  *PermitOptions // The optional permit parameters for spending the input.
	SqrtPriceLimitX96 *big.Int       // The optional price limit for the trade.
	Fee               *FeeOptions    // Optional information for taking a fee on output.
}

Options for producing the arguments to send calls to the router.

type WithdrawOptions added in v0.4.0

type WithdrawOptions struct {
	Owner common.Address // Set when withdrawing. The position will be sent to `owner` on withdraw.
	Data  []byte         // Set when withdrawing. `data` is passed to `safeTransferFrom` when transferring the position from contract back to owner.
}

Options to specify when withdrawing a position.

type WrappedABI

type WrappedABI struct {
	ABI abi.ABI `json:"abi"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL