Documentation ¶
Index ¶
- type ApproveAllowanceParamsDto
- type ApproveAllowanceResponseDto
- type ApproveCalldataParamsDto
- type ApproveCalldataResponseDto
- type ApproveSpenderResponseDto
- type QuoteParamsDto
- type QuoteResponseDto
- type Router
- func (r *Router) DoSwap(w *Wallet, fromTokenContractAddress string, fromTokenBalance *big.Int, ...) error
- func (r *Router) GetApproveAllowanceData(tokenAddress string, amount string) (*ApproveCalldataResponseDto, error)
- func (r *Router) GetApprovedAllowance(chainID uint64, tokenAddress string, walletAddress string) (*ApproveAllowanceResponseDto, error)
- func (r *Router) GetContractAddress() (*common.Address, error)
- func (r *Router) GetHealthStatus() error
- func (r *Router) GetQuote(chainID uint64, params *QuoteParamsDto) (*QuoteResponseDto, error)
- func (r *Router) GetSupportedTokens() ([]Token, error)
- func (r *Router) GetSwapData(chainID uint64, params *SwapParamsDto) (*SwapResponseDto, error)
- func (r *Router) New(chainID uint64) (*Router, error)
- type SwapParamsDto
- type SwapResponseDto
- type Token
- type TokenAddressWithBalance
- type TokensResponseDto
- type TransactionDto
- type Wallet
- func (w *Wallet) GetMainAccountBalance() (*big.Int, error)
- func (w *Wallet) New(address string, privateKey string, chainID uint64) (*Wallet, error)
- func (w *Wallet) RefreshTokenBalances(stableTokenContractAddress string, targetTokenContractAddress string) error
- func (w *Wallet) RefreshWalletBalance() error
- func (w *Wallet) SendTransaction(toAddress *common.Address, tx *types.LegacyTx) (*types.Transaction, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApproveAllowanceParamsDto ¶
type ApproveAllowanceParamsDto struct { TokenAddress string `json:"tokenAddress,omitempty" url:"tokenAddress,omitempty"` WalletAddress string `json:"walletAddress,omitempty" url:"walletAddress,omitempty"` }
ApproveAllowanceParamsDto schema
type ApproveAllowanceResponseDto ¶
type ApproveAllowanceResponseDto struct {
Allowance string `json:"allowance,omitempty"`
}
ApproveAllowanceResponseDto schema
type ApproveCalldataParamsDto ¶
type ApproveCalldataParamsDto struct { TokenAddress string `json:"tokenAddress,omitempty" url:"tokenAddress,omitempty"` Amount string `json:"amount,omitempty" url:"amount,omitempty"` }
ApproveCalldataParamsDto schema
type ApproveCalldataResponseDto ¶
type ApproveCalldataResponseDto struct { // The encoded data to call the approve method on the swapped token contract Data string `json:"data,omitempty"` // Gas price for fast transaction processing GasPrice string `json:"gasPrice,omitempty"` // Token address that will be allowed to exchange through 1inch router To string `json:"to,omitempty"` // Native token value in WEI (for approve is always 0) Value string `json:"value,omitempty"` }
ApproveCalldataResponseDto schema
type ApproveSpenderResponseDto ¶
type ApproveSpenderResponseDto struct { // Address of the 1inch router that must be trusted to spend funds for the exchange Address string `json:"address,omitempty"` }
ApproveSpenderResponseDto schema
type QuoteParamsDto ¶
type QuoteParamsDto struct { FromTokenAddress string `json:"fromTokenAddress,omitempty" url:"fromTokenAddress,omitempty"` ToTokenAddress string `json:"toTokenAddress,omitempty" url:"toTokenAddress,omitempty"` Amount string `json:"amount,omitempty" url:"amount,omitempty"` }
QuoteParamsDto schema
type QuoteResponseDto ¶
type QuoteResponseDto struct { FromToken Token `json:"fromToken,omitempty"` ToToken Token `json:"toToken,omitempty"` FromTokenAmount string `json:"fromTokenAmount,omitempty"` ToTokenAmount string `json:"toTokenAmount,omitempty"` EstimatedGas uint64 `json:"estimatedGas,omitempty"` }
QuoteResponseDto schema
type Router ¶
Router represents the model for the swap router
func (*Router) DoSwap ¶
func (r *Router) DoSwap(w *Wallet, fromTokenContractAddress string, fromTokenBalance *big.Int, toTokenContractAddress string, mode string) error
DoSwap prepares for a swap, waits for admin confirmation and proceeds for a swap
func (*Router) GetApproveAllowanceData ¶
func (r *Router) GetApproveAllowanceData(tokenAddress string, amount string) (*ApproveCalldataResponseDto, error)
GetApproveAllowanceData generates transaction body to allow the exchange with the 1inch router
func (*Router) GetApprovedAllowance ¶
func (r *Router) GetApprovedAllowance(chainID uint64, tokenAddress string, walletAddress string) (*ApproveAllowanceResponseDto, error)
GetApprovedAllowance returns the number of tokens that the 1inch router is allowed to spend
func (*Router) GetContractAddress ¶
GetContractAddress returns the address of the 1inch router that must be trusted to spend funds for the exchange
func (*Router) GetHealthStatus ¶
GetHealthStatus checks the status of the 1inch router
func (*Router) GetQuote ¶
func (r *Router) GetQuote(chainID uint64, params *QuoteParamsDto) (*QuoteResponseDto, error)
GetQuote returns the best quote to exchange via 1inch router
func (*Router) GetSupportedTokens ¶
GetSupportedTokens returns the list of tokens that are available for swap in the 1inch Aggregation protocol
func (*Router) GetSwapData ¶
func (r *Router) GetSwapData(chainID uint64, params *SwapParamsDto) (*SwapResponseDto, error)
GetSwapData returns the data for calling the 1inch router for exchange
type SwapParamsDto ¶
type SwapParamsDto struct { FromTokenAddress string `json:"fromTokenAddress,omitempty" url:"fromTokenAddress,omitempty"` ToTokenAddress string `json:"toTokenAddress,omitempty" url:"toTokenAddress,omitempty"` Amount string `json:"amount,omitempty" url:"amount,omitempty"` FromAddress string `json:"fromAddress,omitempty" url:"fromAddress,omitempty"` Slippage string `json:"slippage,omitempty" url:"slippage,omitempty"` DisableEstimate bool `json:"disableEstimate,omitempty" url:"disableEstimate"` }
SwapParamsDto schema
type SwapResponseDto ¶
type SwapResponseDto struct { FromToken Token `json:"fromToken,omitempty"` ToToken Token `json:"toToken,omitempty"` FromTokenAmount string `json:"fromTokenAmount,omitempty"` ToTokenAmount string `json:"toTokenAmount,omitempty"` Tx TransactionDto `json:"tx,omitempty"` }
SwapResponseDto schema
type TokenAddressWithBalance ¶
TokenAddressWithBalance represents the model of a token address with its balance
type TokensResponseDto ¶
type TokensResponseDto struct { // List of supported tokens Tokens map[string]Token `json:"tokens,omitempty"` }
TokensResponseDto schema
type TransactionDto ¶
type TransactionDto struct { From string `json:"from,omitempty"` To string `json:"to,omitempty"` Data string `json:"data,omitempty"` Value string `json:"value,omitempty"` GasPrice string `json:"gasPrice,omitempty"` Gas uint64 `json:"gas,omitempty"` }
TransactionDto schema
type Wallet ¶
type Wallet struct { ChainID uint64 Address *common.Address PrivateKey *ecdsa.PrivateKey MainAccountBalance *big.Int StableCoinBalance *big.Int TargetCoinBalance *big.Int }
Wallet refers to the crypto wallet
func (*Wallet) GetMainAccountBalance ¶
GetMainAccountBalance retrieves the main account balance
func (*Wallet) RefreshTokenBalances ¶
func (w *Wallet) RefreshTokenBalances(stableTokenContractAddress string, targetTokenContractAddress string) error
RefreshTokenBalance refreshes the specified ERC20 token balance
func (*Wallet) RefreshWalletBalance ¶
RefreshWalletBalance refreshes the wallet balance
func (*Wallet) SendTransaction ¶
func (w *Wallet) SendTransaction(toAddress *common.Address, tx *types.LegacyTx) (*types.Transaction, error)
SendTransaction creates and broadcasts a transaction to the blockchain after signing the payload