Skip to content

Commit

Permalink
wallet: add relayer fee payment
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Feb 26, 2024
1 parent cc4e560 commit 2f68646
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 127 deletions.
28 changes: 14 additions & 14 deletions estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestEstimateSimpleSequenceTransaction(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestEstimateSimpleSequenceTransaction(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestEstimateSimpleSequenceTransactionNonDeployedWallet(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestEstimateSimpleSequenceTransactionNonDeployedWallet(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestEstimateSimpleSequenceTransactionWithStubConfig(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestEstimateSimpleSequenceTransactionWithStubConfig(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestEstimateSimpleSequenceTransactionWithBadNonce(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestEstimateSimpleSequenceTransactionWithBadNonce(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestEstimateBatchSequenceTransaction(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestEstimateBatchSequenceTransaction(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -690,7 +690,7 @@ func TestEstimateSequenceMultipleSigners(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -780,7 +780,7 @@ func TestEstimateSequenceMultipleSigners(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -873,7 +873,7 @@ func TestEstimateSequenceNestedSigners(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down Expand Up @@ -964,7 +964,7 @@ func TestEstimateSequenceNestedSigners(t *testing.T) {
signed, err := wallet.SignTransactions(context.Background(), txs)
assert.NoError(t, err)

_, _, wait, err := wallet.SendTransactions(context.Background(), signed)
_, _, wait, err := wallet.SendTransactions(context.Background(), signed, nil)
assert.NoError(t, err)

receipt, err := wait(context.Background())
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/goware/breaker v0.1.2
github.com/goware/cachestore v0.8.0
github.com/goware/logger v0.3.0
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDO
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
33 changes: 32 additions & 1 deletion relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ type RelayerSimulateResult struct {
GasLimit uint
}

type RelayerFeeTokenType uint32

const (
UNKNOWN RelayerFeeTokenType = iota
ERC20_TOKEN
ERC1155_TOKEN
)

type RelayerFeeToken struct {
ChainID *big.Int
Name string
Symbol string
Type RelayerFeeTokenType
Decimals *uint32
LogoURL string
ContractAddress *common.Address
tokenID *big.Int
}

type RelayerFeeOption struct {
Token RelayerFeeToken
To common.Address
Value *big.Int
GasLimit *big.Int
}

type RelayerFeeQuote string

type Relayer interface {
// ..
GetProvider() *ethrpc.Provider
Expand All @@ -43,7 +71,10 @@ type Relayer interface {
// Relay will submit the Sequence signed meta transaction to the relayer. The method will block until the relayer
// responds with the native transaction hash (*types.Transaction), which means the relayer has submitted the transaction
// request to the network. Clients can use WaitReceipt to wait until the metaTxnID has been mined.
Relay(ctx context.Context, signedTxs *SignedTransactions) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error)
Relay(ctx context.Context, signedTxs *SignedTransactions, quote *RelayerFeeQuote) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error)

//
FeeOptions(ctx context.Context, signedTxs *SignedTransactions) ([]*RelayerFeeOption, *RelayerFeeQuote, error)

// ..
Wait(ctx context.Context, metaTxnID MetaTxnID, optTimeout ...time.Duration) (MetaTxnStatus, *types.Receipt, error)
Expand Down
6 changes: 5 additions & 1 deletion relayer/local_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *LocalRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransac
panic("implement me")
}

func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransactions) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransactions, quote *sequence.RelayerFeeQuote) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
// NOTE: this implementation assumes the wallet is deployed and does not do automatic bundle creation (aka prepending / bundling
// a wallet creation call)

Expand Down Expand Up @@ -231,6 +231,10 @@ func (r *LocalRelayer) Wait(ctx context.Context, metaTxnID sequence.MetaTxnID, o
return status, receipt.Receipt(), nil
}

func (r *LocalRelayer) FeeOptions(ctx context.Context, signedTxs *sequence.SignedTransactions) ([]*sequence.RelayerFeeOption, *sequence.RelayerFeeQuote, error) {
return nil, nil, nil
}

func (r *LocalRelayer) IsDeployTransaction(signedTxs *sequence.SignedTransactions) bool {
for _, txn := range signedTxs.Transactions {
if txn.To == signedTxs.WalletContext.FactoryAddress {
Expand Down
Loading

0 comments on commit 2f68646

Please sign in to comment.