Skip to content

Commit

Permalink
remove RelayV3
Browse files Browse the repository at this point in the history
  • Loading branch information
attente committed Mar 4, 2025
1 parent f923c79 commit 9e1c681
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 225 deletions.
1 change: 0 additions & 1 deletion relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ type Relayer interface {
// 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, quote ...*RelayerFeeQuote) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error)
RelayV3(ctx context.Context, signedTxs *SignedTransactions, quote ...*RelayerFeeQuote) (MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error)

//
FeeOptions(ctx context.Context, signedTxs *SignedTransactions) ([]*RelayerFeeOption, *RelayerFeeQuote, error)
Expand Down
178 changes: 61 additions & 117 deletions relayer/local_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/contracts"
"github.com/0xsequence/go-sequence/core"
v1 "github.com/0xsequence/go-sequence/core/v1"
v2 "github.com/0xsequence/go-sequence/core/v2"
v3 "github.com/0xsequence/go-sequence/core/v3"
"github.com/0xsequence/go-sequence/relayer/proto"
)

Expand Down Expand Up @@ -132,106 +135,33 @@ func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTran

sender := r.Sender

to, execdata, err := sequence.EncodeTransactionsForRelaying(
r,
signedTxs.WalletAddress,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}

if r.IsDeployTransaction(signedTxs) {
to = signedTxs.WalletContext.GuestModuleAddress
} else {
isDeployed, err := sequence.IsWalletDeployed(r.GetProvider(), to)
if err != nil {
return "", nil, nil, err
}

if !isDeployed {
_, factoryAddress, deployData, err := sequence.EncodeWalletDeployment(signedTxs.WalletConfig, signedTxs.WalletContext)
if err != nil {
return "", nil, nil, err
}

txns := sequence.Transactions{
{
RevertOnError: true,
To: factoryAddress,
Data: deployData,
},
{
RevertOnError: true,
To: to,
Data: execdata,
},
}

encodedTxns, err := txns.EncodedTransactions()
if err != nil {
return "", nil, nil, err
}

// TODO: v1 ...? what about others..? I guess since its just for testing locally,
// we can just use v1. But I'd suggest we use v3 format once its ready.
execdata, err = contracts.V1.WalletMainModule.Encode("execute", encodedTxns, big.NewInt(0), []byte{})
if err != nil {
return "", nil, nil, err
}

to = signedTxs.WalletContext.GuestModuleAddress
}
}

walletAddress, err := sequence.AddressFromWalletConfig(signedTxs.WalletConfig, signedTxs.WalletContext)
if err != nil {
return "", nil, nil, err
}

metaTxnID, _, err := sequence.ComputeMetaTxnID(signedTxs.ChainID, walletAddress, signedTxs.Transactions, signedTxs.Nonce, sequence.MetaTxnWalletExec)
if err != nil {
return "", nil, nil, err
}

ntx, err := sender.NewTransaction(ctx, &ethtxn.TransactionRequest{
To: &to, Data: execdata,
})
if err != nil {
return metaTxnID, nil, nil, err
}

signedTx, err := sender.SignTx(ntx, signedTxs.ChainID)
if err != nil {
return metaTxnID, nil, nil, err
}

ntx, waitReceipt, err := sender.SendTransaction(ctx, signedTx)
if err != nil {
return metaTxnID, nil, nil, err
var to common.Address
var execdata []byte
var err error
switch signedTxs.WalletConfig.(type) {
case *v1.WalletConfig, *v2.WalletConfig:
to, execdata, err = sequence.EncodeTransactionsForRelaying(
r,
signedTxs.WalletAddress,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Nonce,
signedTxs.Signature,
)
case *v3.WalletConfig:
to, execdata, err = sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
}

return metaTxnID, ntx, waitReceipt, nil
}

func (r *LocalRelayer) RelayV3(ctx context.Context, signedTxs *sequence.SignedTransactions, quote ...*sequence.RelayerFeeQuote) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
sender := r.Sender

to, execdata, err := sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}
Expand Down Expand Up @@ -263,24 +193,38 @@ func (r *LocalRelayer) RelayV3(ctx context.Context, signedTxs *sequence.SignedTr
},
}

_, execdata, err = sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
txns,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}

execdata, err = contracts.V3.WalletStage1Module.Encode("execute", execdata, []byte{})
if err != nil {
return "", nil, nil, err
switch signedTxs.WalletConfig.(type) {
case *v1.WalletConfig, *v2.WalletConfig:
encodedTxns, err := txns.EncodedTransactions()
if err != nil {
return "", nil, nil, err
}

execdata, err = contracts.V1.WalletMainModule.Encode("execute", encodedTxns, big.NewInt(0), []byte{})
if err != nil {
return "", nil, nil, err
}

case *v3.WalletConfig:
_, execdata, err = sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
txns,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}

execdata, err = contracts.V3.WalletStage1Module.Encode("execute", execdata, []byte{})
if err != nil {
return "", nil, nil, err
}
}

to = signedTxs.WalletContext.GuestModuleAddress
Expand Down
99 changes: 28 additions & 71 deletions relayer/rpc_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/0xsequence/ethkit/go-ethereum/core/types"
"github.com/0xsequence/go-sequence"
"github.com/0xsequence/go-sequence/core"
v1 "github.com/0xsequence/go-sequence/core/v1"
v2 "github.com/0xsequence/go-sequence/core/v2"
v3 "github.com/0xsequence/go-sequence/core/v3"
"github.com/0xsequence/go-sequence/relayer/proto"
)

Expand Down Expand Up @@ -155,78 +158,32 @@ func (r *RpcRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransa
}
}

to, execdata, err := sequence.EncodeTransactionsForRelaying(
r,
signedTxs.WalletAddress,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}

if r.IsDeployTransaction(signedTxs) {
to = signedTxs.WalletContext.GuestModuleAddress
}

call := &proto.MetaTxn{
Contract: to.Hex(),
Input: hexutil.Encode(execdata),
WalletAddress: walletAddress.Hex(),
}

var txQuote *string
if len(quote) > 0 {
txQuote = (*string)(quote[0])
}

// TODO: check contents of Contract and input, if empty, lets not even bother asking the server..

ok, metaTxnID, err := r.Service.SendMetaTxn(ctx, call, txQuote, nil)
if err != nil {
return sequence.MetaTxnID(metaTxnID), nil, nil, err
var to common.Address
var execdata []byte
switch signedTxs.WalletConfig.(type) {
case *v1.WalletConfig, *v2.WalletConfig:
to, execdata, err = sequence.EncodeTransactionsForRelaying(
r,
signedTxs.WalletAddress,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Nonce,
signedTxs.Signature,
)
case *v3.WalletConfig:
to, execdata, err = sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
}
if !ok {
return sequence.MetaTxnID(metaTxnID), nil, nil, fmt.Errorf("failed to relay meta transaction: unknown reason")
}
if metaTxnID == "" {
return "", nil, nil, fmt.Errorf("failed to relay meta transaction: server returned empty metaTxnID")
}

waitReceipt := func(ctx context.Context) (*types.Receipt, error) {
// NOTE: to timeout the request, pass a ctx from context.WithTimeout
_, receipt, err := r.Wait(ctx, sequence.MetaTxnID(metaTxnID))
return receipt, err
}

return sequence.MetaTxnID(metaTxnID), nil, waitReceipt, nil
}

func (r *RpcRelayer) RelayV3(ctx context.Context, signedTxs *sequence.SignedTransactions, quote ...*sequence.RelayerFeeQuote) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) {
walletAddress := signedTxs.WalletAddress
var err error

if walletAddress == (common.Address{}) {
walletAddress, err = sequence.AddressFromWalletConfig(signedTxs.WalletConfig, signedTxs.WalletContext)
if err != nil {
return "", nil, nil, err
}
}

to, execdata, err := sequence.EncodeTransactionsForRelayingV3(
r,
signedTxs.WalletAddress,
signedTxs.ChainID,
signedTxs.WalletConfig,
signedTxs.WalletContext,
signedTxs.Transactions,
signedTxs.Space,
signedTxs.Nonce,
signedTxs.Signature,
)
if err != nil {
return "", nil, nil, err
}
Expand Down
41 changes: 5 additions & 36 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,8 @@ func (w *Wallet[C]) SignTransactions(ctx context.Context, txns Transactions) (*S
}
}

// Check if the config is v1, v2, or v3
_, isV1 := core.WalletConfig(w.config).(*v1.WalletConfig)
_, isV2 := core.WalletConfig(w.config).(*v2.WalletConfig)
_, isV3 := core.WalletConfig(w.config).(*v3.WalletConfig)

// If the config is v1 or v2, encode the transactions in a legacy behavior
if isV1 || isV2 {
switch core.WalletConfig(w.config).(type) {
case *v1.WalletConfig, *v2.WalletConfig:
bundle := Transaction{
Transactions: txns,
Nonce: nonce,
Expand Down Expand Up @@ -693,10 +688,8 @@ func (w *Wallet[C]) SignTransactions(ctx context.Context, txns Transactions) (*S
Digest: digest,
Signature: sig,
}, nil
}

// If the config is v3, encode the transactions as a v3 transaction
if isV3 {
case *v3.WalletConfig:
// TODO: Hardcode nonce space to 0 for now
space := big.NewInt(0)

Expand Down Expand Up @@ -738,19 +731,7 @@ func (w *Wallet[C]) SendTransactions(ctx context.Context, signedTxns *SignedTran
return "", nil, nil, ErrRelayerNotSet
}

_, isV1 := core.WalletConfig(w.config).(*v1.WalletConfig)
_, isV2 := core.WalletConfig(w.config).(*v2.WalletConfig)
_, isV3 := core.WalletConfig(w.config).(*v3.WalletConfig)

if isV1 || isV2 {
return w.relayer.Relay(ctx, signedTxns, feeQuote...)
}

if isV3 {
return w.relayer.RelayV3(ctx, signedTxns, feeQuote...)
}

return "", nil, nil, fmt.Errorf("unknown wallet config type")
return w.relayer.Relay(ctx, signedTxns, feeQuote...)
}

func (w *Wallet[C]) FeeOptions(ctx context.Context, txs Transactions) ([]*RelayerFeeOption, *RelayerFeeQuote, error) {
Expand Down Expand Up @@ -854,19 +835,7 @@ func (w *Wallet[C]) Deploy(ctx context.Context) (MetaTxnID, *types.Transaction,
return "", nil, nil, err
}

_, isV1 := core.WalletConfig(w.config).(*v1.WalletConfig)
_, isV2 := core.WalletConfig(w.config).(*v2.WalletConfig)
_, isV3 := core.WalletConfig(w.config).(*v3.WalletConfig)

if isV1 || isV2 {
return w.relayer.Relay(ctx, signerTxn)
}

if isV3 {
return w.relayer.RelayV3(ctx, signerTxn)
}

return "", nil, nil, fmt.Errorf("unknown wallet config type")
return w.relayer.Relay(ctx, signerTxn)
}

// func (w *Wallet) UpdateConfig() // TODO in future
Expand Down

0 comments on commit 9e1c681

Please sign in to comment.