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

chore(monitor): flowgen skeleton #3050

Merged
merged 1 commit into from
Feb 14, 2025
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
5 changes: 5 additions & 0 deletions lib/tokens/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@ package tokens
type Token struct {
Symbol string
Name string
Decimals uint
CoingeckoID string
}

var (
OMNI = Token{
Symbol: "OMNI",
Name: "Omni Network",
Decimals: 18,
CoingeckoID: "omni-network",
}

ETH = Token{
Symbol: "ETH",
Name: "Ether",
Decimals: 18,
CoingeckoID: "ethereum",
}

STETH = Token{
Symbol: "stETH",
Name: "Lido Staked Ether",
Decimals: 18,
CoingeckoID: "lido-staked-ether",
}

WSTETH = Token{
Symbol: "wstETH",
Name: "Wrapped Staked Ether",
Decimals: 18,
CoingeckoID: "wrapped-steth",
}

Expand Down
26 changes: 26 additions & 0 deletions monitor/flowgen/flowgen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package flowgen

import (
"context"
"time"

"github.com/omni-network/omni/lib/tokens"
)

func Start(ctx context.Context) error {
jobs := []Job{
{
Name: "Symbiotic",
Run: newSymbioticRunner(),
Cadence: 1 * time.Hour,
Spend: spend(tokens.WSTETH, ether1),
},
}

_ = jobs
_ = ctx

// TODO

return nil
}
27 changes: 27 additions & 0 deletions monitor/flowgen/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package flowgen

import (
"context"
"math/big"
"time"

"github.com/omni-network/omni/lib/tokens"
)

type Spend map[tokens.Token]*big.Int

type RunFunc func(context.Context, Spend) error

type Job struct {
// Name is the friendly name of the job
Name string

// Run is the function to run
Run RunFunc

// Cadence is intrerval at which to run the job
Cadence time.Duration

// Spend is spend this job uses on one run (exluding gas)
Spend Spend
}
21 changes: 21 additions & 0 deletions monitor/flowgen/symbiotic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package flowgen

import (
"context"

"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/tokens"
)

func newSymbioticRunner() RunFunc {
return func(_ context.Context, spend Spend) error {
_, ok := spend[tokens.WSTETH]
if !ok {
return errors.New("missing deposit", "token", tokens.WSTETH)
}

// TODO

return nil
}
}
28 changes: 28 additions & 0 deletions monitor/flowgen/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package flowgen

import (
"math"
"math/big"

"github.com/omni-network/omni/lib/tokens"
)

func spend(token tokens.Token, amt *big.Int) Spend { return Spend{token: amt} }

var (
// ether1 is 1 token in wei (18 decimals).
ether1 = dec18(1)
)

func dec18(amt float64) *big.Int {
const unit = 1e18

p := amt * unit

_, dec := math.Modf(p)
if dec != 0 {
panic("amt float64 must be an int multiple of 1e18")
}

return new(big.Int).SetUint64(uint64(p))
}
12 changes: 12 additions & 0 deletions monitor/flowgen/util_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package flowgen

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestUnits(t *testing.T) {
t.Parallel()
require.Equal(t, "1000000000000000000", ether1.String())
}
Loading