Documentation ¶
Overview ¶
Package eth implements methods to work with ethereum swap contracts and transactions. The LGPL is a more restrictive license that may be more of a burden for closed source software.
Index ¶
- Constants
- Variables
- func ChainConfig(net dex.Network) (c *params.ChainConfig, err error)
- func CreateEVMWallet(chainID int64, createWalletParams *asset.CreateWalletParams, ...) error
- func ETHConfig(net dex.Network) (c ethconfig.Config, err error)
- type Balance
- type CompatibilityData
- type Driver
- func (d *Driver) Create(cfg *asset.CreateWalletParams) error
- func (d *Driver) DecodeCoinID(coinID []byte) (string, error)
- func (d *Driver) Exists(walletType, dataDir string, settings map[string]string, net dex.Network) (bool, error)
- func (d *Driver) Info() *asset.WalletInfo
- func (d *Driver) Open(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network) (asset.Wallet, error)
- type ETHWallet
- func (w ETHWallet) AuditContract(coinID, contract, serializedTx dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
- func (w ETHWallet) Balance() (*asset.Balance, error)
- func (w *ETHWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, _ uint64) (*asset.ConfirmRedemptionStatus, error)
- func (w *ETHWallet) Connect(ctx context.Context) (_ *sync.WaitGroup, err error)
- func (w ETHWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
- func (eth ETHWallet) DynamicRedemptionFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
- func (eth ETHWallet) DynamicSwapFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
- func (w *ETHWallet) EstimateSendTxFee(addr string, value, _ uint64, _, maxWithdraw bool) (uint64, bool, error)
- func (w ETHWallet) FindRedemption(ctx context.Context, _, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (w *ETHWallet) FundMultiOrder(ord *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
- func (w *ETHWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uint64, error)
- func (w *ETHWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (w ETHWallet) Info() *asset.WalletInfo
- func (eth *ETHWallet) Lock() error
- func (w ETHWallet) LockTimeExpired(ctx context.Context, lockTime time.Time) (bool, error)
- func (eth *ETHWallet) Locked() bool
- func (w *ETHWallet) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
- func (w *ETHWallet) OpenTokenWallet(tokenCfg *asset.TokenConfig) (asset.Wallet, error)
- func (w ETHWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
- func (w *ETHWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
- func (w *ETHWallet) ReReserveRedemption(req uint64) error
- func (w *ETHWallet) ReReserveRefund(req uint64) error
- func (w *ETHWallet) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
- func (w *ETHWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
- func (w ETHWallet) Refund(_, contract dex.Bytes, feeRate uint64) (dex.Bytes, error)
- func (w *ETHWallet) ReserveNRedemptions(n uint64, ver uint32, maxFeeRate uint64) (uint64, error)
- func (w *ETHWallet) ReserveNRefunds(n uint64, ver uint32, maxFeeRate uint64) (uint64, error)
- func (w *ETHWallet) RestorationInfo(seed []byte) ([]*asset.WalletRestoration, error)
- func (w *ETHWallet) ReturnCoins(coins asset.Coins) error
- func (w *ETHWallet) Send(addr string, value, _ uint64) (asset.Coin, error)
- func (w ETHWallet) SingleLotRedeemFees(version uint32, feeSuggestion uint64) (fees uint64, err error)
- func (w ETHWallet) SingleLotSwapRefundFees(version uint32, feeSuggestion uint64, _ bool) (swapFees uint64, refundFees uint64, err error)
- func (w *ETHWallet) StandardSendFee(feeRate uint64) uint64
- func (w *ETHWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
- func (w ETHWallet) SwapConfirmations(ctx context.Context, coinID dex.Bytes, contract dex.Bytes, _ time.Time) (confs uint32, spent bool, err error)
- func (w ETHWallet) TakeAction(actionID string, actionB []byte) error
- func (w *ETHWallet) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (eth *ETHWallet) Unlock(pw []byte) error
- func (w *ETHWallet) UnlockRedemptionReserves(reserves uint64)
- func (w *ETHWallet) UnlockRefundReserves(reserves uint64)
- func (w *ETHWallet) ValidateAddress(address string) bool
- func (w *ETHWallet) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- type EVMWalletConfig
- type GetGasWalletParams
- type TokenWallet
- func (w *TokenWallet) ApprovalFee(assetVer uint32, approve bool) (uint64, error)
- func (w *TokenWallet) ApprovalStatus() map[uint32]asset.ApprovalStatus
- func (w *TokenWallet) ApproveToken(assetVer uint32, onConfirm func()) (string, error)
- func (w TokenWallet) AuditContract(coinID, contract, serializedTx dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
- func (w TokenWallet) Balance() (*asset.Balance, error)
- func (w *TokenWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, _ uint64) (*asset.ConfirmRedemptionStatus, error)
- func (w *TokenWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (w TokenWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
- func (eth TokenWallet) DynamicRedemptionFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
- func (eth TokenWallet) DynamicSwapFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
- func (w *TokenWallet) EstimateSendTxFee(addr string, value, _ uint64, _, maxWithdraw bool) (fee uint64, isValidAddress bool, err error)
- func (w TokenWallet) FindRedemption(ctx context.Context, _, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
- func (w *TokenWallet) FundMultiOrder(ord *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
- func (w *TokenWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uint64, error)
- func (w *TokenWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error)
- func (w TokenWallet) Info() *asset.WalletInfo
- func (w TokenWallet) LockTimeExpired(ctx context.Context, lockTime time.Time) (bool, error)
- func (w *TokenWallet) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
- func (w TokenWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
- func (w *TokenWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
- func (w *TokenWallet) ReReserveRedemption(req uint64) error
- func (w *TokenWallet) ReReserveRefund(req uint64) error
- func (w *TokenWallet) Reconfigure(context.Context, *asset.WalletConfig, string) (bool, error)
- func (w *TokenWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
- func (w TokenWallet) Refund(_, contract dex.Bytes, feeRate uint64) (dex.Bytes, error)
- func (w *TokenWallet) ReserveNRedemptions(n uint64, ver uint32, maxFeeRate uint64) (uint64, error)
- func (w *TokenWallet) ReserveNRefunds(n uint64, ver uint32, maxFeeRate uint64) (uint64, error)
- func (w *TokenWallet) ReturnCoins(coins asset.Coins) error
- func (w *TokenWallet) Send(addr string, value, _ uint64) (asset.Coin, error)
- func (w TokenWallet) SingleLotRedeemFees(version uint32, feeSuggestion uint64) (fees uint64, err error)
- func (w TokenWallet) SingleLotSwapRefundFees(version uint32, feeSuggestion uint64, _ bool) (swapFees uint64, refundFees uint64, err error)
- func (w *TokenWallet) StandardSendFee(feeRate uint64) uint64
- func (w *TokenWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint64, error)
- func (w TokenWallet) SwapConfirmations(ctx context.Context, coinID dex.Bytes, contract dex.Bytes, _ time.Time) (confs uint32, spent bool, err error)
- func (w TokenWallet) TakeAction(actionID string, actionB []byte) error
- func (w *TokenWallet) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
- func (w *TokenWallet) UnapproveToken(assetVer uint32, onConfirm func()) (string, error)
- func (w *TokenWallet) UnlockRedemptionReserves(reserves uint64)
- func (w *TokenWallet) UnlockRefundReserves(reserves uint64)
- func (w *TokenWallet) ValidateAddress(address string) bool
- func (w *TokenWallet) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
- type TransactionActionNote
- type WalletConfig
Constants ¶
const ( // BipID is the BIP-0044 asset ID for Ethereum. BipID = 60 LiveEstimateFailedError = dex.ErrorKind("live gas estimate failed") )
Variables ¶
var ( RPCOpts = []*asset.ConfigOption{ { Key: providersKey, DisplayName: "RPC Provider", Description: "Specify one or more RPC providers. For infrastructure " + "providers, prefer using wss address. Only url-based authentication " + "is supported. For a local node, use the filepath to an IPC file.", Repeatable: providerDelimiter, RepeatN: 2, DefaultValue: "", }, } // WalletInfo defines some general information about a Ethereum wallet. WalletInfo = asset.WalletInfo{ Name: "Ethereum", SupportedVersions: []uint32{0}, UnitInfo: dexeth.UnitInfo, AvailableWallets: []*asset.WalletDefinition{ { Type: walletTypeRPC, Tab: "RPC", Description: "Infrastructure providers (e.g. Infura) or local nodes", ConfigOpts: append(RPCOpts, walletOpts...), Seeded: true, GuideLink: "https://github.com/decred/dcrdex/blob/master/docs/wiki/Ethereum.md", }, }, IsAccountBased: true, } )
var ContractDeployer contractDeployer
var GetGas getGas
GetGas provides access to the gas estimation utilities.
Functions ¶
func ChainConfig ¶ added in v1.0.0
func ChainConfig(net dex.Network) (c *params.ChainConfig, err error)
ChainConfig returns the core configuration for the blockchain.
func CreateEVMWallet ¶ added in v1.0.0
func CreateEVMWallet(chainID int64, createWalletParams *asset.CreateWalletParams, compat *CompatibilityData, skipConnect bool) error
Types ¶
type CompatibilityData ¶ added in v1.0.0
type CompatibilityData struct { Addr common.Address TokenAddr common.Address TxHash common.Hash BlockHash common.Hash }
CompatibilityData is some addresses and hashes used for validating an RPC APIs compatibility with trading.
func NetworkCompatibilityData ¶ added in v1.0.0
func NetworkCompatibilityData(net dex.Network) (c CompatibilityData, err error)
NetworkCompatibilityData returns the CompatibilityData for the specified network. If using simnet, make sure the simnet harness is running.
type Driver ¶
type Driver struct{}
Driver implements asset.Driver.
func (*Driver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Ethereum. These are supported coin ID formats:
- A transaction hash. 32 bytes
- An encoded ETH funding coin id which includes the account address and amount. 20 + 8 = 28 bytes
- An encoded token funding coin id which includes the account address, a token value, and fees. 20 + 8 + 8 = 36 bytes
- A byte encoded string of the account address. 40 or 42 (with 0x) bytes
- A byte encoded string which represents specific case where Taker found Maker redemption on his own (while Maker failed to notify him about it first). 26 (`TakerFoundMakerRedemption:` prefix) + 42 (Maker address with 0x) bytes
func (*Driver) Exists ¶
func (d *Driver) Exists(walletType, dataDir string, settings map[string]string, net dex.Network) (bool, error)
Exists checks the existence of the wallet.
func (*Driver) Info ¶
func (d *Driver) Info() *asset.WalletInfo
Info returns basic information about the wallet and asset.
type ETHWallet ¶
type ETHWallet struct {
// contains filtered or unexported fields
}
ETHWallet implements some Ethereum-specific methods.
func NewEVMWallet ¶ added in v1.0.0
func NewEVMWallet(cfg *EVMWalletConfig) (w *ETHWallet, err error)
func (ETHWallet) AuditContract ¶
func (w ETHWallet) AuditContract(coinID, contract, serializedTx dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
AuditContract retrieves information about a swap contract on the blockchain. This would be used to verify the counter-party's contract during a swap. coinID is expected to be the transaction id, and must be the same as the hash of serializedTx. contract is expected to be (contractVersion|secretHash) where the secretHash uniquely keys the swap.
func (*ETHWallet) ConfirmRedemption ¶
func (w *ETHWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, _ uint64) (*asset.ConfirmRedemptionStatus, error)
ConfirmRedemption checks the status of a redemption. If a transaction has been fee-replaced, the caller is notified of this by having a different coinID in the returned asset.ConfirmRedemptionStatus as was used to call the function. Fee argument is ignored since it is calculated from the best header.
func (ETHWallet) ContractLockTimeExpired ¶
func (w ETHWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
ContractLockTimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.
func (ETHWallet) DynamicRedemptionFeesPaid ¶
func (eth ETHWallet) DynamicRedemptionFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
DynamicRedemptionFeesPaid returns fees for redemption transactions. Part of the asset.DynamicSwapper interface.
func (ETHWallet) DynamicSwapFeesPaid ¶
func (eth ETHWallet) DynamicSwapFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
DynamicSwapFeesPaid returns fees for initiation transactions. Part of the asset.DynamicSwapper interface.
func (*ETHWallet) EstimateSendTxFee ¶
func (w *ETHWallet) EstimateSendTxFee(addr string, value, _ uint64, _, maxWithdraw bool) (uint64, bool, error)
EstimateSendTxFee returns a tx fee estimate for a send tx. The provided fee rate is ignored since all sends will use an internally derived fee rate. If an address is provided, it will ensure wallet has enough to cover total spend.
func (ETHWallet) FindRedemption ¶
func (w ETHWallet) FindRedemption(ctx context.Context, _, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
FindRedemption checks the contract for a redemption. If the swap is initiated but un-redeemed and un-refunded, FindRedemption will block until a redemption is seen.
func (*ETHWallet) FundMultiOrder ¶ added in v1.0.0
func (w *ETHWallet) FundMultiOrder(ord *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
FundMultiOrder funds multiple orders in one shot. No special handling is required for ETH as ETH does not over-lock during funding.
func (*ETHWallet) FundingCoins ¶
FundingCoins gets funding coins for the coin IDs. The coins are locked. This method might be called to reinitialize an order from data stored externally.
func (ETHWallet) Info ¶
func (w ETHWallet) Info() *asset.WalletInfo
Info returns basic information about the wallet and asset.
func (ETHWallet) LockTimeExpired ¶
LockTimeExpired returns true if the specified locktime has expired, making it possible to redeem the locked coins.
func (*ETHWallet) MaxOrder ¶
func (w *ETHWallet) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
MaxOrder generates information about the maximum order size and associated fees that the wallet can support for the given DEX configuration. The fees are an estimate based on current network conditions, and will be <= the fees associated with nfo.MaxFeeRate. For quote assets, the caller will have to calculate lotSize based on a rate conversion from the base asset's lot size.
func (*ETHWallet) OpenTokenWallet ¶
OpenTokenWallet creates a new TokenWallet.
func (ETHWallet) PreRedeem ¶
func (w ETHWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
PreRedeem generates an estimate of the range of redemption fees that could be assessed.
func (*ETHWallet) PreSwap ¶
PreSwap gets order estimates based on the available funds and the wallet configuration.
func (*ETHWallet) ReReserveRedemption ¶
ReReserveRedemption checks out an amount for redemptions. Use ReReserveRedemption after initializing a new asset.Wallet. Part of the AccountLocker interface.
func (*ETHWallet) ReReserveRefund ¶
ReReserveRefund checks out an amount for doing refunds. Use ReReserveRefund after initializing a new assetWallet. Part of the AccountLocker interface.
func (*ETHWallet) Reconfigure ¶
func (w *ETHWallet) Reconfigure(ctx context.Context, cfg *asset.WalletConfig, currentAddress string) (restart bool, err error)
Reconfigure attempts to reconfigure the wallet.
func (*ETHWallet) Redeem ¶
Redeem sends the redemption transaction, which may contain more than one redemption. All redemptions must be for the same contract version because the current API requires a single transaction reported (asset.Coin output), but conceptually a batch of redeems could be processed for any number of different contract addresses with multiple transactions. (buck: what would the difference from calling Redeem repeatedly?)
func (ETHWallet) Refund ¶
Refund refunds a contract. This can only be used after the time lock has expired.
func (*ETHWallet) ReserveNRedemptions ¶
ReserveNRedemptions locks funds for redemption. It is an error if there is insufficient spendable balance. Part of the AccountLocker interface.
func (*ETHWallet) ReserveNRefunds ¶
ReserveNRefunds locks funds for doing refunds. It is an error if there is insufficient spendable balance. Part of the AccountLocker interface.
func (*ETHWallet) RestorationInfo ¶
func (w *ETHWallet) RestorationInfo(seed []byte) ([]*asset.WalletRestoration, error)
RestorationInfo returns information about how to restore the wallet in various external wallets.
func (*ETHWallet) ReturnCoins ¶
ReturnCoins unlocks coins. This would be necessary in the case of a canceled order.
func (*ETHWallet) Send ¶
Send sends the exact value to the specified address. The provided fee rate is ignored since all sends will use an internally derived fee rate.
func (ETHWallet) SingleLotRedeemFees ¶
func (w ETHWallet) SingleLotRedeemFees(version uint32, feeSuggestion uint64) (fees uint64, err error)
SingleLotRedeemFees returns the fees for a redeem transaction for a single lot.
func (ETHWallet) SingleLotSwapRefundFees ¶ added in v1.0.0
func (w ETHWallet) SingleLotSwapRefundFees(version uint32, feeSuggestion uint64, _ bool) (swapFees uint64, refundFees uint64, err error)
SingleLotSwapRefundFees returns the fees for a swap transaction for a single lot.
func (*ETHWallet) StandardSendFee ¶ added in v1.0.0
StandardSendFees returns the fees for a simple send tx.
func (*ETHWallet) Swap ¶
Swap sends the swaps in a single transaction. The fees used returned are the max fees that will possibly be used, since in ethereum with EIP-1559 we cannot know exactly how much fees will be used.
func (ETHWallet) SwapConfirmations ¶
func (w ETHWallet) SwapConfirmations(ctx context.Context, coinID dex.Bytes, contract dex.Bytes, _ time.Time) (confs uint32, spent bool, err error)
SwapConfirmations gets the number of confirmations and the spend status for the specified swap.
func (ETHWallet) TakeAction ¶ added in v1.0.0
TakeAction satisfies asset.ActionTaker. This handles responses from the user for an ActionRequired request, usually for a stuck tx or otherwise abnormal condition.
func (*ETHWallet) TxHistory ¶ added in v1.0.0
TxHistory returns all the transactions the wallet has made. This includes the ETH wallet and all token wallets. If refID is nil, then transactions starting from the most recent are returned (past is ignored). If past is true, the transactions prior to the refID are returned, otherwise the transactions after the refID are returned. n is the number of transactions to return. If n is <= 0, all the transactions will be returned.
func (*ETHWallet) UnlockRedemptionReserves ¶
UnlockRedemptionReserves unlocks the specified amount from redemption reserves. Part of the AccountLocker interface.
func (*ETHWallet) UnlockRefundReserves ¶
UnlockRefundReserves unlocks the specified amount from refund reserves. Part of the AccountLocker interface.
func (*ETHWallet) ValidateAddress ¶
ValidateAddress checks whether the provided address is a valid hex-encoded Ethereum address.
func (*ETHWallet) WalletTransaction ¶ added in v1.0.0
func (w *ETHWallet) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
WalletTransaction returns a transaction that either the wallet has made or one in which the wallet has received funds.
type EVMWalletConfig ¶ added in v1.0.0
type EVMWalletConfig struct { BaseChainID uint32 ChainCfg *params.ChainConfig AssetCfg *asset.WalletConfig CompatData *CompatibilityData VersionedGases map[uint32]*dexeth.Gases Tokens map[uint32]*dexeth.Token FinalizeConfs uint64 Logger dex.Logger BaseChainContracts map[uint32]common.Address DefaultProviders []string MultiBalAddress common.Address // If empty, separate calls for N tokens + 1 WalletInfo asset.WalletInfo Net dex.Network }
EVMWalletConfig is the configuration for an evm-compatible wallet.
type GetGasWalletParams ¶ added in v1.0.0
type GetGasWalletParams struct { ChainCfg *params.ChainConfig Gas *dexeth.Gases Token *dexeth.Token UnitInfo *dex.UnitInfo BaseUnitInfo *dex.UnitInfo Compat *CompatibilityData ContractAddr common.Address // Base chain contract addr. }
GetGasWalletParams are the configuration parameters required to estimate swap contract gas usage.
type TokenWallet ¶
type TokenWallet struct {
// contains filtered or unexported fields
}
TokenWallet implements some token-specific methods.
func (*TokenWallet) ApprovalFee ¶ added in v1.0.0
func (w *TokenWallet) ApprovalFee(assetVer uint32, approve bool) (uint64, error)
ApprovalFee returns the estimated fee for an approval transaction.
func (*TokenWallet) ApprovalStatus ¶ added in v1.0.0
func (w *TokenWallet) ApprovalStatus() map[uint32]asset.ApprovalStatus
ApprovalStatus returns the approval status for each version of the token's swap contract.
func (*TokenWallet) ApproveToken ¶ added in v1.0.0
func (w *TokenWallet) ApproveToken(assetVer uint32, onConfirm func()) (string, error)
ApproveToken sends an approval transaction for a specific version of the token's swap contract. An error is returned if an approval has already been done or is pending. The onConfirm callback is called when the approval transaction is confirmed.
func (TokenWallet) AuditContract ¶
func (w TokenWallet) AuditContract(coinID, contract, serializedTx dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error)
AuditContract retrieves information about a swap contract on the blockchain. This would be used to verify the counter-party's contract during a swap. coinID is expected to be the transaction id, and must be the same as the hash of serializedTx. contract is expected to be (contractVersion|secretHash) where the secretHash uniquely keys the swap.
func (*TokenWallet) ConfirmRedemption ¶
func (w *TokenWallet) ConfirmRedemption(coinID dex.Bytes, redemption *asset.Redemption, _ uint64) (*asset.ConfirmRedemptionStatus, error)
ConfirmRedemption checks the status of a redemption. If a transaction has been fee-replaced, the caller is notified of this by having a different coinID in the returned asset.ConfirmRedemptionStatus as was used to call the function. Fee argument is ignored since it is calculated from the best header.
func (*TokenWallet) Connect ¶
Connect waits for context cancellation and closes the WaitGroup. Satisfies dex.Connector.
func (TokenWallet) ContractLockTimeExpired ¶
func (w TokenWallet) ContractLockTimeExpired(ctx context.Context, contract dex.Bytes) (bool, time.Time, error)
ContractLockTimeExpired returns true if the specified contract's locktime has expired, making it possible to issue a Refund.
func (TokenWallet) DynamicRedemptionFeesPaid ¶
func (eth TokenWallet) DynamicRedemptionFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
DynamicRedemptionFeesPaid returns fees for redemption transactions. Part of the asset.DynamicSwapper interface.
func (TokenWallet) DynamicSwapFeesPaid ¶
func (eth TokenWallet) DynamicSwapFeesPaid(ctx context.Context, coinID, contractData dex.Bytes) (fee uint64, secretHashes [][]byte, err error)
DynamicSwapFeesPaid returns fees for initiation transactions. Part of the asset.DynamicSwapper interface.
func (*TokenWallet) EstimateSendTxFee ¶
func (w *TokenWallet) EstimateSendTxFee(addr string, value, _ uint64, _, maxWithdraw bool) (fee uint64, isValidAddress bool, err error)
EstimateSendTxFee returns a tx fee estimate for a send tx. The provided fee rate is ignored since all sends will use an internally derived fee rate. If an address is provided, it will ensure wallet has enough to cover total spend.
func (TokenWallet) FindRedemption ¶
func (w TokenWallet) FindRedemption(ctx context.Context, _, contract dex.Bytes) (redemptionCoin, secret dex.Bytes, err error)
FindRedemption checks the contract for a redemption. If the swap is initiated but un-redeemed and un-refunded, FindRedemption will block until a redemption is seen.
func (*TokenWallet) FundMultiOrder ¶ added in v1.0.0
func (w *TokenWallet) FundMultiOrder(ord *asset.MultiOrder, maxLock uint64) ([]asset.Coins, [][]dex.Bytes, uint64, error)
FundMultiOrder funds multiple orders in one shot. No special handling is required for ETH as ETH does not over-lock during funding.
func (*TokenWallet) FundingCoins ¶
FundingCoins gets funding coins for the coin IDs. The coins are locked. This method might be called to reinitialize an order from data stored externally.
func (TokenWallet) Info ¶
func (w TokenWallet) Info() *asset.WalletInfo
Info returns basic information about the wallet and asset.
func (TokenWallet) LockTimeExpired ¶
LockTimeExpired returns true if the specified locktime has expired, making it possible to redeem the locked coins.
func (*TokenWallet) MaxOrder ¶
func (w *TokenWallet) MaxOrder(ord *asset.MaxOrderForm) (*asset.SwapEstimate, error)
MaxOrder generates information about the maximum order size and associated fees that the wallet can support for the given DEX configuration.
func (TokenWallet) PreRedeem ¶
func (w TokenWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error)
PreRedeem generates an estimate of the range of redemption fees that could be assessed.
func (*TokenWallet) PreSwap ¶
func (w *TokenWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, error)
PreSwap gets order estimates based on the available funds and the wallet configuration.
func (*TokenWallet) ReReserveRedemption ¶
func (w *TokenWallet) ReReserveRedemption(req uint64) error
ReReserveRedemption checks out an amount for redemptions. Use ReReserveRedemption after initializing a new asset.Wallet. Part of the AccountLocker interface.
func (*TokenWallet) ReReserveRefund ¶
func (w *TokenWallet) ReReserveRefund(req uint64) error
ReReserveRefund checks out an amount for doing refunds. Use ReReserveRefund after initializing a new assetWallet. Part of the AccountLocker interface.
func (*TokenWallet) Reconfigure ¶
func (w *TokenWallet) Reconfigure(context.Context, *asset.WalletConfig, string) (bool, error)
Reconfigure attempts to reconfigure the wallet. The token wallet has no configurations.
func (*TokenWallet) Redeem ¶
func (w *TokenWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Coin, uint64, error)
Redeem sends the redemption transaction, which may contain more than one redemption.
func (TokenWallet) Refund ¶
Refund refunds a contract. This can only be used after the time lock has expired.
func (*TokenWallet) ReserveNRedemptions ¶
ReserveNRedemptions locks funds for redemption. It is an error if there is insufficient spendable balance. Part of the AccountLocker interface.
func (*TokenWallet) ReserveNRefunds ¶
ReserveNRefunds locks funds for doing refunds. It is an error if there is insufficient spendable balance. Part of the AccountLocker interface.
func (*TokenWallet) ReturnCoins ¶
func (w *TokenWallet) ReturnCoins(coins asset.Coins) error
ReturnCoins unlocks coins. This would be necessary in the case of a canceled order.
func (*TokenWallet) Send ¶
Send sends the exact value to the specified address. Fees are taken from the parent wallet. The provided fee rate is ignored since all sends will use an internally derived fee rate.
func (TokenWallet) SingleLotRedeemFees ¶
func (w TokenWallet) SingleLotRedeemFees(version uint32, feeSuggestion uint64) (fees uint64, err error)
SingleLotRedeemFees returns the fees for a redeem transaction for a single lot.
func (TokenWallet) SingleLotSwapRefundFees ¶ added in v1.0.0
func (w TokenWallet) SingleLotSwapRefundFees(version uint32, feeSuggestion uint64, _ bool) (swapFees uint64, refundFees uint64, err error)
SingleLotSwapRefundFees returns the fees for a swap transaction for a single lot.
func (*TokenWallet) StandardSendFee ¶ added in v1.0.0
func (w *TokenWallet) StandardSendFee(feeRate uint64) uint64
StandardSendFees returns the fees for a simple send tx.
func (*TokenWallet) Swap ¶
Swap sends the swaps in a single transaction. The fees used returned are the max fees that will possibly be used, since in ethereum with EIP-1559 we cannot know exactly how much fees will be used.
func (TokenWallet) SwapConfirmations ¶
func (w TokenWallet) SwapConfirmations(ctx context.Context, coinID dex.Bytes, contract dex.Bytes, _ time.Time) (confs uint32, spent bool, err error)
SwapConfirmations gets the number of confirmations and the spend status for the specified swap.
func (TokenWallet) TakeAction ¶ added in v1.0.0
TakeAction satisfies asset.ActionTaker. This handles responses from the user for an ActionRequired request, usually for a stuck tx or otherwise abnormal condition.
func (*TokenWallet) TxHistory ¶ added in v1.0.0
func (w *TokenWallet) TxHistory(n int, refID *string, past bool) ([]*asset.WalletTransaction, error)
TxHistory returns all the transactions the token wallet has made. If refID is nil, then transactions starting from the most recent are returned (past is ignored). If past is true, the transactions prior to the refID are returned, otherwise the transactions after the refID are returned. n is the number of transactions to return. If n is <= 0, all the transactions will be returned.
func (*TokenWallet) UnapproveToken ¶ added in v1.0.0
func (w *TokenWallet) UnapproveToken(assetVer uint32, onConfirm func()) (string, error)
UnapproveToken removes the approval for a specific version of the token's swap contract.
func (*TokenWallet) UnlockRedemptionReserves ¶
func (w *TokenWallet) UnlockRedemptionReserves(reserves uint64)
UnlockRedemptionReserves unlocks the specified amount from redemption reserves. Part of the AccountLocker interface.
func (*TokenWallet) UnlockRefundReserves ¶
func (w *TokenWallet) UnlockRefundReserves(reserves uint64)
UnlockRefundReserves unlocks the specified amount from refund reserves. Part of the AccountLocker interface.
func (*TokenWallet) ValidateAddress ¶
func (w *TokenWallet) ValidateAddress(address string) bool
ValidateAddress checks whether the provided address is a valid hex-encoded Ethereum address.
func (*TokenWallet) WalletTransaction ¶ added in v1.0.0
func (w *TokenWallet) WalletTransaction(ctx context.Context, txID string) (*asset.WalletTransaction, error)
type TransactionActionNote ¶ added in v1.0.0
type TransactionActionNote struct { Tx *asset.WalletTransaction `json:"tx"` Nonce uint64 `json:"nonce,omitempty"` NewFees uint64 `json:"newFees,omitempty"` }
TransactionActionNote is used to request user action on transactions in abnormal states.
type WalletConfig ¶
type WalletConfig struct {
GasFeeLimit uint64 `ini:"gasfeelimit"`
}
WalletConfig are wallet-level configuration settings.