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

Metacall utility func + contracts getters #1

Merged
merged 2 commits into from
Aug 19, 2024
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: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,5 @@ jobs:
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install build-essential

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Build
run: CGO_ENABLED=0 GOOS=linux go build -o ./atlas-sdk-go

- name: Test
run: make test
59 changes: 59 additions & 0 deletions core/atlas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package core

import (
"errors"

"github.com/FastLane-Labs/atlas-sdk-go/contract/atlas"
"github.com/FastLane-Labs/atlas-sdk-go/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethTypes "github.com/ethereum/go-ethereum/core/types"
)

func (sdk *AtlasSdk) Metacall(chainId uint64, transactOpts *bind.TransactOpts, userOp *types.UserOperation, solverOps types.SolverOperations, dAppOp *types.DAppOperation) (*gethTypes.Transaction, error) {
contract, ok := sdk.atlasContract[chainId]
if !ok {
return nil, errors.New("atlas contract not found")
}

userOp.Sanitize()
solverOps.Sanitize()
dAppOp.Sanitize()

_dAppOp := atlas.DAppOperation{
From: dAppOp.From,
To: dAppOp.To,
Nonce: dAppOp.Nonce,
Deadline: dAppOp.Deadline,
Control: dAppOp.Control,
Bundler: dAppOp.Bundler,
UserOpHash: dAppOp.UserOpHash,
CallChainHash: dAppOp.CallChainHash,
Signature: dAppOp.Signature,
}

_solverOps := make([]atlas.SolverOperation, len(solverOps))
for i, solverOp := range solverOps {
_solverOps[i] = atlas.SolverOperation{
From: solverOp.From,
To: solverOp.To,
Value: solverOp.Value,
Gas: solverOp.Gas,
MaxFeePerGas: solverOp.MaxFeePerGas,
Deadline: solverOp.Deadline,
Solver: solverOp.Solver,
Control: solverOp.Control,
UserOpHash: solverOp.UserOpHash,
BidToken: solverOp.BidToken,
BidAmount: solverOp.BidAmount,
Data: solverOp.Data,
Signature: solverOp.Signature,
}
}

tx, err := contract.Metacall(transactOpts, atlas.UserOperation(*userOp), _solverOps, _dAppOp)
if err != nil {
return nil, err
}

return tx, nil
}
36 changes: 36 additions & 0 deletions core/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,39 @@ func (sdk *AtlasSdk) getEthClient(chainId uint64) (*ethclient.Client, error) {

return client, nil
}

func (sdk *AtlasSdk) GetAtlasContract(chainId uint64) (*atlas.Atlas, error) {
contract, ok := sdk.atlasContract[chainId]
if !ok {
return nil, fmt.Errorf("atlas contract not found for chain id %d", chainId)
}

return contract, nil
}

func (sdk *AtlasSdk) GetAtlasVerificationContract(chainId uint64) (*atlasverification.AtlasVerification, error) {
contract, ok := sdk.atlasVerificationContract[chainId]
if !ok {
return nil, fmt.Errorf("atlas verification contract not found for chain id %d", chainId)
}

return contract, nil
}

func (sdk *AtlasSdk) GetSimulatorContract(chainId uint64) (*simulator.Simulator, error) {
contract, ok := sdk.simulatorContract[chainId]
if !ok {
return nil, fmt.Errorf("simulator contract not found for chain id %d", chainId)
}

return contract, nil
}

func (sdk *AtlasSdk) GetSorterContract(chainId uint64) (*sorter.Sorter, error) {
contract, ok := sdk.sorterContract[chainId]
if !ok {
return nil, fmt.Errorf("sorter contract not found for chain id %d", chainId)
}

return contract, nil
}
6 changes: 6 additions & 0 deletions types/solver_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ func (s SolverOperations) EncodeToRaw() SolverOperationsRaw {
return solverOps
}

func (s SolverOperations) Sanitize() {
for _, solverOp := range s {
solverOp.Sanitize()
}
}

func (s SolverOperationsRaw) Decode() SolverOperations {
solverOps := make([]*SolverOperation, len(s))
for i, solverOp := range s {
Expand Down
Loading