models

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

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

type Router struct {
	Address         *common.Address
	ChainID         uint64
	SupportedTokens []Token
}

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

func (r *Router) GetContractAddress() (*common.Address, error)

GetContractAddress returns the address of the 1inch router that must be trusted to spend funds for the exchange

func (*Router) GetHealthStatus

func (r *Router) GetHealthStatus() error

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

func (r *Router) GetSupportedTokens() ([]Token, error)

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

func (*Router) New

func (r *Router) New(chainID uint64) (*Router, error)

New create a new router instance

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 Token

type Token struct {
	Name     string
	Symbol   string
	Decimals uint64
	Address  *common.Address
}

Token represents the model of a token

type TokenAddressWithBalance

type TokenAddressWithBalance struct {
	Address *common.Address
	Balance *big.Int
}

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

func (w *Wallet) GetMainAccountBalance() (*big.Int, error)

GetMainAccountBalance retrieves the main account balance

func (*Wallet) New

func (w *Wallet) New(address string, privateKey string, chainID uint64) (*Wallet, error)

New creates a new wallet instance

func (*Wallet) RefreshTokenBalances

func (w *Wallet) RefreshTokenBalances(stableTokenContractAddress string, targetTokenContractAddress string) error

RefreshTokenBalance refreshes the specified ERC20 token balance

func (*Wallet) RefreshWalletBalance

func (w *Wallet) RefreshWalletBalance() error

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

Jump to

Keyboard shortcuts

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