Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relayer simulate #103

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ import (
"github.com/0xsequence/go-sequence/core"
)

type RelayerSimulateResult struct {
Executed bool
Succeeded bool
Result *string
Reason *string
GasUsed uint
GasLimit uint
}

type Relayer interface {
// ..
GetProvider() *ethrpc.Provider

// ..
EstimateGasLimits(ctx context.Context, walletConfig core.WalletConfig, walletContext WalletContext, txns Transactions) (Transactions, error)

// ..
Simulate(ctx context.Context, txs *SignedTransactions) ([]*RelayerSimulateResult, error)

// NOTE: nonce space is 160 bits wide
GetNonce(ctx context.Context, walletConfig core.WalletConfig, walletContext WalletContext, space *big.Int, blockNum *big.Int) (*big.Int, error)

Expand Down
5 changes: 5 additions & 0 deletions relayer/local_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (r *LocalRelayer) GetNonce(ctx context.Context, walletConfig core.WalletCon
return sequence.GetWalletNonce(r.GetProvider(), walletConfig, walletContext, space, blockNum)
}

func (r *LocalRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*sequence.RelayerSimulateResult, error) {
//TODO implement me
panic("implement me")
Comment on lines +121 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we don't need to implement this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for now. If we want to use it locally then probably yes.

}

func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTransactions) (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
20 changes: 18 additions & 2 deletions relayer/rpc_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *RpcRelayer) GetNonce(ctx context.Context, walletConfig core.WalletConfi
return &nonce, nil
}

func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*proto.SimulateResult, error) {
func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransactions) ([]*sequence.RelayerSimulateResult, error) {
to, execdata, err := sequence.EncodeTransactionsForRelaying(
r,
txs.WalletAddress,
Expand All @@ -122,7 +122,23 @@ func (r *RpcRelayer) Simulate(ctx context.Context, txs *sequence.SignedTransacti
return nil, err
}

return r.Service.Simulate(ctx, to.String(), "0x"+common.Bytes2Hex(execdata))
res, err := r.Service.Simulate(ctx, to.String(), "0x"+common.Bytes2Hex(execdata))
if err != nil {
return nil, err
}

var results []*sequence.RelayerSimulateResult
for _, r := range res {
results = append(results, &sequence.RelayerSimulateResult{
Executed: r.Executed,
Succeeded: r.Succeeded,
Result: r.Result,
Reason: r.Reason,
GasUsed: r.GasUsed,
GasLimit: r.GasLimit,
})
}
return results, nil
}

// Relay will submit the Sequence signed meta transaction to the relayer. The method will block until the relayer
Expand Down
Loading