Documentation ¶
Index ¶
- Constants
- Variables
- func DiscoverFactoryAddress(chainID int64) (currentFactory common.Address, legacyFactories []common.Address, found bool)
- func RecoverCheque(cheque *SignedCheque, chaindID int64) (common.Address, error)
- type CashChequeResult
- type CashoutService
- type CashoutStatus
- type Cheque
- type ChequeSigner
- type ChequeStore
- type Factory
- type LastCashout
- type RecoverChequeFunc
- type SendChequeFunc
- type Service
- type SignedCheque
Constants ¶
const (
ChequebookDeploymentKey = "swap_chequebook_transaction_deployment"
)
Variables ¶
var ( // ErrOutOfFunds is the error when the chequebook has not enough free funds for a cheque ErrOutOfFunds = errors.New("chequebook out of funds") // ErrInsufficientFunds is the error when the chequebook has not enough free funds for a user action ErrInsufficientFunds = errors.New("insufficient token balance") )
var ( // ErrNoCheque is the error returned if there is no prior cheque for a chequebook or beneficiary. ErrNoCheque = errors.New("no cheque") // ErrChequeNotIncreasing is the error returned if the cheque amount is the same or lower. ErrChequeNotIncreasing = errors.New("cheque cumulativePayout is not increasing") // ErrChequeInvalid is the error returned if the cheque itself is invalid. ErrChequeInvalid = errors.New("invalid cheque") // ErrWrongBeneficiary is the error returned if the cheque has the wrong beneficiary. ErrWrongBeneficiary = errors.New("wrong beneficiary") // ErrBouncingCheque is the error returned if the chequebook is demonstrably illiquid. ErrBouncingCheque = errors.New("bouncing cheque") )
var ( ErrInvalidFactory = errors.New("not a valid factory contract") ErrNotDeployedByFactory = errors.New("chequebook not deployed by factory") )
var ChequeTypes = eip712.Types{ "EIP712Domain": eip712.EIP712DomainType, "Cheque": []eip712.Type{ { Name: "chequebook", Type: "address", }, { Name: "beneficiary", Type: "address", }, { Name: "cumulativePayout", Type: "uint256", }, }, }
ChequeTypes are the needed type descriptions for cheque signing
var ( // ErrNoCashout is the error if there has not been any cashout action for the chequebook ErrNoCashout = errors.New("no prior cashout") )
Functions ¶
func DiscoverFactoryAddress ¶
func DiscoverFactoryAddress(chainID int64) (currentFactory common.Address, legacyFactories []common.Address, found bool)
DiscoverFactoryAddress returns the canonical factory for this chainID
func RecoverCheque ¶
func RecoverCheque(cheque *SignedCheque, chaindID int64) (common.Address, error)
RecoverCheque recovers the issuer ethereum address from a signed cheque
Types ¶
type CashChequeResult ¶
type CashChequeResult struct { Beneficiary common.Address // beneficiary of the cheque Recipient common.Address // address which received the funds Caller common.Address // caller of cashCheque TotalPayout *big.Int // total amount that was paid out in this call CumulativePayout *big.Int // cumulative payout of the cheque that was cashed CallerPayout *big.Int // payout for the caller of cashCheque Bounced bool // indicates wether parts of the cheque bounced }
CashChequeResult summarizes the result of a CashCheque or CashChequeBeneficiary call
func (*CashChequeResult) Equal ¶
func (r *CashChequeResult) Equal(o *CashChequeResult) bool
Equal compares to CashChequeResults
type CashoutService ¶
type CashoutService interface { // CashCheque sends a cashing transaction for the last cheque of the chequebook CashCheque(ctx context.Context, chequebook common.Address, recipient common.Address) (common.Hash, error) // CashoutStatus gets the status of the latest cashout transaction for the chequebook CashoutStatus(ctx context.Context, chequebookAddress common.Address) (*CashoutStatus, error) }
CashoutService is the service responsible for managing cashout actions
func NewCashoutService ¶
func NewCashoutService( store storage.StateStorer, backend transaction.Backend, transactionService transaction.Service, chequeStore ChequeStore, ) CashoutService
NewCashoutService creates a new CashoutService
type CashoutStatus ¶
type CashoutStatus struct { Last *LastCashout // last cashout for a chequebook UncashedAmount *big.Int // amount not yet cashed out }
CashoutStatus is information about the last cashout and uncashed amounts
type Cheque ¶
type Cheque struct { Chequebook common.Address Beneficiary common.Address CumulativePayout *big.Int }
Cheque represents a cheque for a SimpleSwap chequebook
type ChequeSigner ¶
ChequeSigner signs cheque
func NewChequeSigner ¶
func NewChequeSigner(signer crypto.Signer, chainID int64) ChequeSigner
NewChequeSigner creates a new cheque signer for the given chainID.
type ChequeStore ¶
type ChequeStore interface { // ReceiveCheque verifies and stores a cheque. It returns the total amount earned. ReceiveCheque(ctx context.Context, cheque *SignedCheque) (*big.Int, error) // LastCheque returns the last cheque we received from a specific chequebook. LastCheque(chequebook common.Address) (*SignedCheque, error) // LastCheques returns the last received cheques from every known chequebook. LastCheques() (map[common.Address]*SignedCheque, error) }
ChequeStore handles the verification and storage of received cheques
func NewChequeStore ¶
func NewChequeStore( store storage.StateStorer, factory Factory, chainID int64, beneficiary common.Address, transactionService transaction.Service, recoverChequeFunc RecoverChequeFunc) ChequeStore
NewChequeStore creates new ChequeStore
type Factory ¶
type Factory interface { // ERC20Address returns the token for which this factory deploys chequebooks. ERC20Address(ctx context.Context) (common.Address, error) // Deploy deploys a new chequebook and returns once the transaction has been submitted. Deploy(ctx context.Context, issuer common.Address, defaultHardDepositTimeoutDuration *big.Int, nonce common.Hash) (common.Hash, error) // WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address WaitDeployed(ctx context.Context, txHash common.Hash) (common.Address, error) // VerifyBytecode checks that the factory is valid. VerifyBytecode(ctx context.Context) error // VerifyChequebook checks that the supplied chequebook has been deployed by this factory. VerifyChequebook(ctx context.Context, chequebook common.Address) error }
Factory is the main interface for interacting with the chequebook factory.
func NewFactory ¶
func NewFactory(backend transaction.Backend, transactionService transaction.Service, address common.Address, legacyAddresses []common.Address) Factory
NewFactory creates a new factory service for the provided factory contract.
type LastCashout ¶ added in v0.6.0
type LastCashout struct { TxHash common.Hash Cheque SignedCheque // the cheque that was used to cashout which may be different from the latest cheque Result *CashChequeResult Reverted bool }
LastCashout contains information about the last cashout
type RecoverChequeFunc ¶
type RecoverChequeFunc func(cheque *SignedCheque, chainID int64) (common.Address, error)
type SendChequeFunc ¶
type SendChequeFunc func(cheque *SignedCheque) error
SendChequeFunc is a function to send cheques.
type Service ¶
type Service interface { // Deposit starts depositing erc20 token into the chequebook. This returns once the transactions has been broadcast. Deposit(ctx context.Context, amount *big.Int) (hash common.Hash, err error) // Withdraw starts withdrawing erc20 token from the chequebook. This returns once the transactions has been broadcast. Withdraw(ctx context.Context, amount *big.Int) (hash common.Hash, err error) // WaitForDeposit waits for the deposit transaction to confirm and verifies the result. WaitForDeposit(ctx context.Context, txHash common.Hash) error // Balance returns the token balance of the chequebook. Balance(ctx context.Context) (*big.Int, error) // AvailableBalance returns the token balance of the chequebook which is not yet used for uncashed cheques. AvailableBalance(ctx context.Context) (*big.Int, error) // Address returns the address of the used chequebook contract. Address() common.Address // Issue a new cheque for the beneficiary with an cumulativePayout amount higher than the last. Issue(ctx context.Context, beneficiary common.Address, amount *big.Int, sendChequeFunc SendChequeFunc) (*big.Int, error) // LastCheque returns the last cheque we issued for the beneficiary. LastCheque(beneficiary common.Address) (*SignedCheque, error) // LastCheque returns the last cheques for all beneficiaries. LastCheques() (map[common.Address]*SignedCheque, error) }
Service is the main interface for interacting with the nodes chequebook.
func Init ¶
func Init( ctx context.Context, chequebookFactory Factory, stateStore storage.StateStorer, logger logging.Logger, swapInitialDeposit *big.Int, transactionService transaction.Service, swapBackend transaction.Backend, chainId int64, overlayEthAddress common.Address, chequeSigner ChequeSigner, ) (chequebookService Service, err error)
Init initialises the chequebook service.
func New ¶
func New(transactionService transaction.Service, address, ownerAddress common.Address, store storage.StateStorer, chequeSigner ChequeSigner, erc20Service erc20.Service) (Service, error)
New creates a new chequebook service for the provided chequebook contract.
type SignedCheque ¶
SignedCheque represents a cheque together with its signature
func (*SignedCheque) Equal ¶
func (cheque *SignedCheque) Equal(other *SignedCheque) bool