Skip to content

Commit

Permalink
chore(solver/app): prep v2 (#2766)
Browse files Browse the repository at this point in the history
Prep solver v2.

Update types and names. Stub functions that need changing.

Changes include:
- use v2 bindings (`SolverNetInbox` and `SolverNetOutbox`)
- removing targets, v2 will be token based
- match ERC7683 language:
  - request -> order
  - fulfilled -> filled 
  - requested -> opened


issue: none
  • Loading branch information
kevinhalliday authored Jan 10, 2025
1 parent d764d1c commit 6f4aa1b
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 316 deletions.
36 changes: 18 additions & 18 deletions contracts/bindings/solvernetinbox.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/solve/src/ERC7683/SolverNetInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract SolverNetInbox is OwnableRoles, ReentrancyGuard, Initializable, Deploye
function getOrder(bytes32 id)
external
view
returns (ResolvedCrossChainOrder memory order, OrderState memory state, StatusUpdate[] memory history)
returns (ResolvedCrossChainOrder memory resolved, OrderState memory state, StatusUpdate[] memory history)
{
return (_orders[id], _orderState[id], _orderHistory[id]);
}
Expand Down
30 changes: 12 additions & 18 deletions solver/app/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ func Run(ctx context.Context, cfg Config) error {
return err
}

// Log target apps
for _, app := range targetsByNetwork[network.ID] {
app.LogMetadata(ctx)
}
// TODO: log supported tokens / balances

if cfg.SolverPrivKey == "" {
return errors.New("private key not set")
Expand All @@ -75,9 +72,10 @@ func Run(ctx context.Context, cfg Config) error {
return err
}

if err := maybeStartLoadGen(ctx, cfg, network.ID, backends); err != nil {
return err
}
// This starts devapp loadgen, currently written for v1 inbox / outbox.
// if err := maybeStartLoadGen(ctx, cfg, network.ID, backends); err != nil {
// return err
// }

xprov := xprovider.New(network, backends.Clients(), nil)

Expand Down Expand Up @@ -173,7 +171,7 @@ func startEventStreams(
return errors.Wrap(err, "detect inbox chains")
}

inboxContracts := make(map[uint64]*bindings.SolveInbox)
inboxContracts := make(map[uint64]*bindings.SolverNetInbox)
for _, chain := range inboxChains {
name := network.ChainName(chain)
chainVer := chainVerFromID(chain)
Expand All @@ -184,7 +182,7 @@ func startEventStreams(
return err
}

inbox, err := bindings.NewSolveInbox(addrs.SolveInbox, backend)
inbox, err := bindings.NewSolverNetInbox(addrs.SolveInbox, backend)
if err != nil {
return errors.Wrap(err, "create inbox contract", "chain", name)
}
Expand Down Expand Up @@ -235,22 +233,18 @@ func startEventStreams(
return cursors.Set(ctx, chainVerFromID(chainID), height)
}

targetNamer := func(req bindings.SolveRequest) string {
target, err := getTarget(network.ID, req.Call)
if err != nil {
return unknown
}

return target.Name()
targetNamer := func(_ Order) string {
// TODO: Return name for known targets.
return unknown
}

deps := procDeps{
ParseID: newIDParser(inboxContracts),
GetRequest: newRequestGetter(inboxContracts),
GetOrder: newOrderGetter(inboxContracts),
ShouldReject: newShouldRejector(network.ID),
Accept: newAcceptor(inboxContracts, backends, solverAddr),
Reject: newRejector(inboxContracts, backends, solverAddr),
Fulfill: newFulfiller(network.ID, outboxContracts, backends, solverAddr, addrs.SolveOutbox),
Fill: newFiller(network.ID, outboxContracts, backends, solverAddr, addrs.SolveOutbox),
Claim: newClaimer(inboxContracts, backends, solverAddr),
SetCursor: cursorSetter,
ChainName: network.ChainName,
Expand Down
75 changes: 37 additions & 38 deletions solver/app/v2/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package appv2
import (
"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/lib/errors"
stypes "github.com/omni-network/omni/solver/types"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -12,40 +11,40 @@ import (
)

const (
statusInvalid uint8 = 0
statusPending uint8 = 1
statusAccepted uint8 = 2
statusRejected uint8 = 3
statusReverted uint8 = 4
statusFulfilled uint8 = 5
statusClaimed uint8 = 6
statusInvalid uint8 = 0
statusPending uint8 = 1
statusAccepted uint8 = 2
statusRejected uint8 = 3
statusReverted uint8 = 4
statusFilled uint8 = 5
statusClaimed uint8 = 6
)

var (
inboxABI = mustGetABI(bindings.SolveInboxMetaData)
inboxABI = mustGetABI(bindings.SolverNetInboxMetaData)

// Event log topics (common.Hash).
topicRequested = mustGetEventTopic(inboxABI, "Requested")
topicAccepted = mustGetEventTopic(inboxABI, "Accepted")
topicRejected = mustGetEventTopic(inboxABI, "Rejected")
topicReverted = mustGetEventTopic(inboxABI, "Reverted")
topicFulfilled = mustGetEventTopic(inboxABI, "Fulfilled")
topicClaimed = mustGetEventTopic(inboxABI, "Claimed")
topicOpened = mustGetEventTopic(inboxABI, "Open")
topicAccepted = mustGetEventTopic(inboxABI, "Accepted")
topicRejected = mustGetEventTopic(inboxABI, "Rejected")
topicReverted = mustGetEventTopic(inboxABI, "Reverted")
topicFilled = mustGetEventTopic(inboxABI, "Filled")
topicClaimed = mustGetEventTopic(inboxABI, "Claimed")
)

// eventMeta contains metadata about an event.
type eventMeta struct {
Topic common.Hash
Status uint8
ParseID func(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error)
ParseID func(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error)
}

var (
allEvents = []eventMeta{
{
Topic: topicRequested,
Topic: topicOpened,
Status: statusPending,
ParseID: parseRequested,
ParseID: parseOpened,
},
{
Topic: topicAccepted,
Expand All @@ -63,9 +62,9 @@ var (
ParseID: parseReverted,
},
{
Topic: topicFulfilled,
Status: statusFulfilled,
ParseID: parseFulfilled,
Topic: topicFilled,
Status: statusFilled,
ParseID: parseFilled,
},
{
Topic: topicClaimed,
Expand Down Expand Up @@ -106,64 +105,64 @@ func statusString(status uint8) string {
return "rejected"
case statusReverted:
return "reverted"
case statusFulfilled:
return "fulfilled"
case statusFilled:
return "filled"
case statusClaimed:
return "claimed"
default:
return unknown
}
}

func parseRequested(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
e, err := contract.ParseRequested(log)
func parseOpened(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseOpen(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse requested")
return OrderID{}, errors.Wrap(err, "parse opened")
}

return e.Id, nil
return e.OrderId, nil
}

func parseAccepted(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
func parseAccepted(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseAccepted(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse accepted")
return OrderID{}, errors.Wrap(err, "parse accepted")
}

return e.Id, nil
}

func parseRejected(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
func parseRejected(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseRejected(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse rejected")
return OrderID{}, errors.Wrap(err, "parse rejected")
}

return e.Id, nil
}

func parseReverted(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
func parseReverted(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseReverted(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse reverted")
return OrderID{}, errors.Wrap(err, "parse reverted")
}

return e.Id, nil
}

func parseFulfilled(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
e, err := contract.ParseFulfilled(log)
func parseFilled(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseFilled(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse fulfilled")
return OrderID{}, errors.Wrap(err, "parse filled")
}

return e.Id, nil
}

func parseClaimed(contract bindings.SolveInboxFilterer, log types.Log) (stypes.ReqID, error) {
func parseClaimed(contract bindings.SolverNetInboxFilterer, log types.Log) (OrderID, error) {
e, err := contract.ParseClaimed(log)
if err != nil {
return stypes.ReqID{}, errors.Wrap(err, "parse claimed")
return OrderID{}, errors.Wrap(err, "parse claimed")
}

return e.Id, nil
Expand Down
2 changes: 1 addition & 1 deletion solver/app/v2/config.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ network = "{{ .Network }}"
### Solver Options ###
#######################################################################

# Path to the ethereum private key used to for inbox and outbox request state transitions.
# Path to the ethereum private key used to for inbox and outbox order state transitions.
private-key = "{{ .SolverPrivKey }}"

# Path to the ethereum private key used to generate deposit load on ephemeral networks only.
Expand Down
1 change: 1 addition & 0 deletions solver/app/v2/ephemeral.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:unused // This package is a work in progress.
package appv2

import (
Expand Down
Loading

0 comments on commit 6f4aa1b

Please sign in to comment.