ammcmd

package
v1.21.43 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ERC20 ABI
	ERC20ABI = `` /* 1110-byte string literal not displayed */

	// Uniswap V2 Router ABI (minimal)
	V2RouterABI = `` /* 1950-byte string literal not displayed */

	// Uniswap V2 Factory ABI (minimal)
	V2FactoryABI = `` /* 616-byte string literal not displayed */

	// Uniswap V2 Pair ABI (minimal)
	V2PairABI = `` /* 536-byte string literal not displayed */

	// Uniswap V3 SwapRouter ABI (minimal)
	V3RouterABI = `` /* 920-byte string literal not displayed */

	// Quoter ABI (minimal)
	QuoterABI = `` /* 485-byte string literal not displayed */

	// Uniswap V3 Pool ABI (minimal)
	V3PoolABI = `` /* 804-byte string literal not displayed */

	// Uniswap V3 Factory ABI (minimal)
	V3FactoryABI = `` /* 324-byte string literal not displayed */

)

ABI strings for contract interactions

Variables

View Source
var (
	// Lux Mainnet (C-Chain)
	LuxMainnet = NetworkConfig{
		ChainID:     96369,
		RPC:         "http://localhost:8545",
		Name:        "Lux Mainnet",
		V2Factory:   common.HexToAddress("0xD173926A10A0C4eCd3A51B1422270b65Df0551c1"),
		V2Router:    common.HexToAddress("0xAe2cf1E403aAFE6C05A5b8Ef63EB19ba591d8511"),
		V3Factory:   common.HexToAddress("0x80bBc7C4C7a59C899D1B37BC14539A22D5830a84"),
		V3Router:    common.HexToAddress("0x939bC0Bca6F9B9c52E6e3AD8A3C590b5d9B9D10E"),
		Multicall:   common.HexToAddress("0xd25F88CBdAe3c2CCA3Bb75FC4E723b44C0Ea362F"),
		Quoter:      common.HexToAddress("0x12e2B76FaF4dDA5a173a4532916bb6Bfa3645275"),
		WETH:        common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		NFTPosition: common.HexToAddress("0x7a4C48B9dae0b7c396569b34042fcA604150Ee28"),
		TickLens:    common.HexToAddress("0x57A22965AdA0e52D785A9Aa155beF423D573b879"),
	}

	// Zoo Mainnet
	ZooMainnet = NetworkConfig{
		ChainID:     200200,
		RPC:         "http://localhost:8546",
		Name:        "Zoo Mainnet",
		V2Factory:   common.HexToAddress("0xD173926A10A0C4eCd3A51B1422270b65Df0551c1"),
		V2Router:    common.HexToAddress("0xAe2cf1E403aAFE6C05A5b8Ef63EB19ba591d8511"),
		V3Factory:   common.HexToAddress("0x80bBc7C4C7a59C899D1B37BC14539A22D5830a84"),
		V3Router:    common.HexToAddress("0x939bC0Bca6F9B9c52E6e3AD8A3C590b5d9B9D10E"),
		Multicall:   common.HexToAddress("0xd25F88CBdAe3c2CCA3Bb75FC4E723b44C0Ea362F"),
		Quoter:      common.HexToAddress("0x12e2B76FaF4dDA5a173a4532916bb6Bfa3645275"),
		WETH:        common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		NFTPosition: common.HexToAddress("0x7a4C48B9dae0b7c396569b34042fcA604150Ee28"),
		TickLens:    common.HexToAddress("0x57A22965AdA0e52D785A9Aa155beF423D573b879"),
	}

	// Lux Testnet
	LuxTestnet = NetworkConfig{
		ChainID:     96368,
		RPC:         "http://localhost:8547",
		Name:        "Lux Testnet",
		V2Factory:   common.HexToAddress("0xD173926A10A0C4eCd3A51B1422270b65Df0551c1"),
		V2Router:    common.HexToAddress("0xAe2cf1E403aAFE6C05A5b8Ef63EB19ba591d8511"),
		V3Factory:   common.HexToAddress("0x80bBc7C4C7a59C899D1B37BC14539A22D5830a84"),
		V3Router:    common.HexToAddress("0x939bC0Bca6F9B9c52E6e3AD8A3C590b5d9B9D10E"),
		Multicall:   common.HexToAddress("0xd25F88CBdAe3c2CCA3Bb75FC4E723b44C0Ea362F"),
		Quoter:      common.HexToAddress("0x12e2B76FaF4dDA5a173a4532916bb6Bfa3645275"),
		WETH:        common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		NFTPosition: common.HexToAddress("0x7a4C48B9dae0b7c396569b34042fcA604150Ee28"),
		TickLens:    common.HexToAddress("0x57A22965AdA0e52D785A9Aa155beF423D573b879"),
	}

	// Zoo Testnet (local testnet deployment)
	ZooTestnet = NetworkConfig{
		ChainID:     200201,
		RPC:         "http://localhost:9640/ext/bc/zoo-testnet/rpc",
		Name:        "Zoo Testnet",
		V2Factory:   common.HexToAddress("0xD173926A10A0C4eCd3A51B1422270b65Df0551c1"),
		V2Router:    common.HexToAddress("0xAe2cf1E403aAFE6C05A5b8Ef63EB19ba591d8511"),
		V3Factory:   common.HexToAddress("0x80bBc7C4C7a59C899D1B37BC14539A22D5830a84"),
		V3Router:    common.HexToAddress("0x939bC0Bca6F9B9c52E6e3AD8A3C590b5d9B9D10E"),
		Multicall:   common.HexToAddress("0xd25F88CBdAe3c2CCA3Bb75FC4E723b44C0Ea362F"),
		Quoter:      common.HexToAddress("0x12e2B76FaF4dDA5a173a4532916bb6Bfa3645275"),
		WETH:        common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		NFTPosition: common.HexToAddress("0x7a4C48B9dae0b7c396569b34042fcA604150Ee28"),
		TickLens:    common.HexToAddress("0x57A22965AdA0e52D785A9Aa155beF423D573b879"),
	}

	// Lux Local (Anvil dev network)
	LuxLocal = NetworkConfig{
		ChainID:   96369,
		RPC:       "http://localhost:8545",
		Name:      "Lux Local",
		V2Factory: common.HexToAddress("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"),
		V2Router:  common.HexToAddress("0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"),
		WETH:      common.HexToAddress("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"),
	}

	// Zoo chain tokens (chainId 200200)
	ZooTokens = map[string]common.Address{
		"WZOO":  common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		"ZETH":  common.HexToAddress("0x60E0a8167FC13dE89348978860466C9ceC24B9ba"),
		"ZBTC":  common.HexToAddress("0x1E48D32a4F5e9f08DB9aE4959163300FaF8A6C8e"),
		"ZUSD":  common.HexToAddress("0x848Cff46eb323f323b6Bbe1Df274E40793d7f2c2"),
		"ZLUX":  common.HexToAddress("0x5E5290f350352768bD2bfC59c2DA15DD04A7cB88"),
		"ZSOL":  common.HexToAddress("0x26B40f650156C7EbF9e087Dd0dca181Fe87625B7"),
		"ZBNB":  common.HexToAddress("0x6EdcF3645DeF09DB45050638c41157D8B9FEa1cf"),
		"ZPOL":  common.HexToAddress("0x28BfC5DD4B7E15659e41190983e5fE3df1132bB9"),
		"ZCELO": common.HexToAddress("0x3078847F879A33994cDa2Ec1540ca52b5E0eE2e5"),
		"ZFTM":  common.HexToAddress("0x8B982132d639527E8a0eAAD385f97719af8f5e04"),
		"ZTON":  common.HexToAddress("0x3141b94b89691009b950c96e97Bff48e0C543E3C"),
	}

	// Lux chain tokens (chainId 96369)
	LuxTokens = map[string]common.Address{
		"WLUX": common.HexToAddress("0x4888E4a2Ee0F03051c72D2BD3ACf755eD3498B3E"),
		"LETH": common.HexToAddress("0x60E0a8167FC13dE89348978860466C9ceC24B9ba"),
		"LBTC": common.HexToAddress("0x1E48D32a4F5e9f08DB9aE4959163300FaF8A6C8e"),
		"LUSD": common.HexToAddress("0x848Cff46eb323f323b6Bbe1Df274E40793d7f2c2"),
		"LZOO": common.HexToAddress("0x5E5290f350352768bD2bfC59c2DA15DD04A7cB88"),
		"LSOL": common.HexToAddress("0x26B40f650156C7EbF9e087Dd0dca181Fe87625B7"),
		"LBNB": common.HexToAddress("0x6EdcF3645DeF09DB45050638c41157D8B9FEa1cf"),
		"LPOL": common.HexToAddress("0x28BfC5DD4B7E15659e41190983e5fE3df1132bB9"),
	}

	// Network lookup by chain ID
	Networks = map[int64]*NetworkConfig{
		96369:  &LuxMainnet,
		200200: &ZooMainnet,
		200201: &ZooTestnet,
		96368:  &LuxTestnet,
	}

	// Network lookup by name
	NetworksByName = map[string]*NetworkConfig{
		"lux":         &LuxMainnet,
		"lux-mainnet": &LuxMainnet,
		"zoo":         &ZooMainnet,
		"zoo-mainnet": &ZooMainnet,
		"zoo-testnet": &ZooTestnet,
		"lux-testnet": &LuxTestnet,
		"testnet":     &LuxTestnet,
		"local":       &LuxLocal,
		"lux-local":   &LuxLocal,
	}
)

Predefined network configurations

View Source
var V3FeeTiers = []uint32{100, 500, 3000, 10000}

Common V3 fee tiers

Functions

func NewCmd

func NewCmd(injectedApp *application.Lux) *cobra.Command

NewCmd creates a new amm command

Types

type AMM

type AMM struct {
	// contains filtered or unexported fields
}

AMM represents an AMM client for interacting with Uniswap-style DEX

func NewAMM

func NewAMM(config *NetworkConfig) (*AMM, error)

NewAMM creates a new AMM client for the specified network

func (*AMM) ApproveToken

func (a *AMM) ApproveToken(ctx context.Context, tokenAddr common.Address, amount *big.Int) (*types.Transaction, error)

ApproveToken approves a token for spending by the router

func (*AMM) ApproveTokenForV3

func (a *AMM) ApproveTokenForV3(ctx context.Context, tokenAddr common.Address, amount *big.Int) (*types.Transaction, error)

ApproveTokenForV3 approves a token for V3 router

func (*AMM) Close

func (a *AMM) Close()

Close closes the client connection

func (*AMM) FindBestV3Pool

func (a *AMM) FindBestV3Pool(ctx context.Context, tokenIn, tokenOut common.Address, amountIn *big.Int) (uint32, *big.Int, error)

FindBestV3Pool finds the best V3 pool (highest liquidity) for a token pair

func (*AMM) GetAddress

func (a *AMM) GetAddress() common.Address

GetAddress returns the wallet address

func (*AMM) GetAllowance

func (a *AMM) GetAllowance(ctx context.Context, tokenAddr common.Address) (*big.Int, error)

GetAllowance returns the allowance of a token for the router

func (*AMM) GetAmountsOut

func (a *AMM) GetAmountsOut(ctx context.Context, amountIn *big.Int, path []common.Address) ([]*big.Int, error)

GetAmountsOut returns expected output amounts for a swap path

func (*AMM) GetBalance

func (a *AMM) GetBalance(ctx context.Context) (*big.Int, error)

GetBalance returns the native token balance

func (*AMM) GetPair

func (a *AMM) GetPair(ctx context.Context, token0, token1 common.Address) (common.Address, error)

GetPair returns the pair address for two tokens

func (*AMM) GetPoolCount

func (a *AMM) GetPoolCount(ctx context.Context) (uint64, error)

GetPoolCount returns the total number of pools

func (*AMM) GetTokenInfo

func (a *AMM) GetTokenInfo(ctx context.Context, tokenAddr common.Address) (*TokenInfo, error)

GetTokenInfo returns information about an ERC20 token

func (*AMM) GetV3Allowance

func (a *AMM) GetV3Allowance(ctx context.Context, tokenAddr common.Address) (*big.Int, error)

GetV3Allowance returns the allowance of a token for the V3 router

func (*AMM) GetV3Pool

func (a *AMM) GetV3Pool(ctx context.Context, token0, token1 common.Address, fee uint32) (common.Address, error)

GetV3Pool returns the V3 pool address for a token pair and fee tier

func (*AMM) GetV3Quote

func (a *AMM) GetV3Quote(ctx context.Context, tokenIn, tokenOut common.Address, fee uint32, amountIn *big.Int) (*big.Int, error)

GetV3Quote returns expected output for a V3 swap

func (*AMM) LoadWallet

func (a *AMM) LoadWallet() error

LoadWallet loads wallet from private key or mnemonic Priority: privateKey param > LUX_PRIVATE_KEY env > LUX_MNEMONIC env

func (*AMM) LoadWalletWithKey

func (a *AMM) LoadWalletWithKey(privateKey string) error

LoadWalletWithKey loads wallet with optional private key parameter

func (*AMM) SwapExactInputSingleV3

func (a *AMM) SwapExactInputSingleV3(ctx context.Context, tokenIn, tokenOut common.Address, fee uint32, amountIn, amountOutMin *big.Int, deadline time.Time) (*types.Transaction, error)

SwapExactInputSingleV3 executes a V3 single-hop swap

func (*AMM) SwapExactTokensForTokens

func (a *AMM) SwapExactTokensForTokens(ctx context.Context, amountIn, amountOutMin *big.Int, path []common.Address, deadline time.Time) (*types.Transaction, error)

SwapExactTokensForTokens executes a token-to-token swap

func (*AMM) WaitForTx

func (a *AMM) WaitForTx(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)

WaitForTx waits for a transaction to be mined

type NetworkConfig

type NetworkConfig struct {
	ChainID     int64
	RPC         string
	Name        string
	V2Factory   common.Address
	V2Router    common.Address
	V3Factory   common.Address
	V3Router    common.Address
	Multicall   common.Address
	Quoter      common.Address
	WETH        common.Address
	NFTPosition common.Address
	TickLens    common.Address
}

NetworkConfig holds AMM contract addresses for a specific network

func GetNetwork

func GetNetwork(nameOrID string) *NetworkConfig

GetNetwork returns network config by name or chain ID

func GetNetworkByChainID

func GetNetworkByChainID(chainID int64) *NetworkConfig

GetNetworkByChainID returns network config by chain ID

type PoolInfo

type PoolInfo struct {
	Address  common.Address
	Token0   common.Address
	Token1   common.Address
	Reserve0 *big.Int
	Reserve1 *big.Int
	TVL      *big.Float
}

PoolInfo holds liquidity pool information

type TokenInfo

type TokenInfo struct {
	Address  common.Address
	Name     string
	Symbol   string
	Decimals uint8
	Balance  *big.Int
}

TokenInfo holds ERC20 token information

Jump to

Keyboard shortcuts

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