Skip to content

Commit

Permalink
min burn amount by chain
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Feb 15, 2024
1 parent e6d21ae commit 17bfa3f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 6 deletions.
20 changes: 17 additions & 3 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
cctptypes "github.com/circlefin/noble-cctp/x/cctp/types"
"github.com/spf13/cobra"
"github.com/strangelove-ventures/noble-cctp-relayer/circle"
"github.com/strangelove-ventures/noble-cctp-relayer/ethereum"
"github.com/strangelove-ventures/noble-cctp-relayer/noble"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
)

Expand Down Expand Up @@ -194,13 +196,25 @@ func filterLowTransfers(cfg *types.Config, logger log.Logger, msg *types.Message
return true
}

if bm.Amount.LT(math.NewIntFromUint64(cfg.MinAmount)) {
var minBurnAmount uint64
if msg.DestDomain == types.Domain(4) {
minBurnAmount = cfg.Chains["noble"].(*noble.ChainConfig).MinAmount
} else {
for _, chain := range cfg.Chains {
c := chain.(*ethereum.ChainConfig)
if c.Domain == msg.DestDomain {
minBurnAmount = c.MinAmount
}
}
}

if bm.Amount.LT(math.NewIntFromUint64(minBurnAmount)) {
logger.Info(
"Filtered tx because the transfer amount is less than the minimum allowed amount",
"source_domain", msg.SourceDomain,
"source_tx", msg.SourceTxHash,
"amount", bm.Amount,
"min_amount", cfg.MinAmount,
"min_amount", minBurnAmount,
)
return true
}
Expand All @@ -210,7 +224,7 @@ func filterLowTransfers(cfg *types.Config, logger log.Logger, msg *types.Message
"source_domain", msg.SourceDomain,
"source_tx", msg.SourceTxHash,
"amount", bm.Amount.Uint64(),
"min_amount", cfg.MinAmount,
"min_amount", minBurnAmount,
)

return false
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func Parse(file string) (*types.Config, error) {
ProcessorWorkerCount: cfg.ProcessorWorkerCount,
Api: cfg.Api,
Chains: make(map[string]types.ChainConfig),
MinAmount: cfg.MinAmount,
}

for name, chain := range cfg.Chains {
Expand Down
4 changes: 4 additions & 0 deletions config/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ chains:
broadcast-retries: 5 # number of times to attempt the broadcast
broadcast-retry-interval: 10 # time between retries in seconds

min-amount: 10

minter-private-key: # private key


Expand All @@ -30,6 +32,8 @@ chains:

block-queue-channel-size: 1000000 # 1000000 is a safe default, increase number if starting from a very early block

min-amount: 0

minter-private-key: # hex encoded privateKey

# source domain id -> destination domain id
Expand Down
3 changes: 3 additions & 0 deletions ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Ethereum struct {
minterAddress string
maxRetries int
retryIntervalSeconds int
minAmount uint64

mu sync.Mutex
}
Expand All @@ -45,6 +46,7 @@ func NewChain(
privateKey string,
maxRetries int,
retryIntervalSeconds int,
minAmount uint64,
) (*Ethereum, error) {
privEcdsaKey, ethereumAddress, err := GetEcdsaKeyAddress(privateKey)
if err != nil {
Expand All @@ -63,6 +65,7 @@ func NewChain(
minterAddress: ethereumAddress,
maxRetries: maxRetries,
retryIntervalSeconds: retryIntervalSeconds,
minAmount: minAmount,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ChainConfig struct {
BroadcastRetries int `yaml:"broadcast-retries"`
BroadcastRetryInterval int `yaml:"broadcast-retry-interval"`

MinAmount uint64 `yaml:"min-amount"`

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}
Expand All @@ -36,5 +38,6 @@ func (c *ChainConfig) Chain(name string) (types.Chain, error) {
c.MinterPrivateKey,
c.BroadcastRetries,
c.BroadcastRetryInterval,
c.MinAmount,
)
}
3 changes: 3 additions & 0 deletions noble/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Noble struct {
maxRetries int
retryIntervalSeconds int
blockQueueChannelSize uint64
minamount uint64

mu sync.Mutex
}
Expand All @@ -51,6 +52,7 @@ func NewChain(
maxRetries int,
retryIntervalSeconds int,
blockQueueChannelSize uint64,
minAmount uint64,
) (*Noble, error) {
cc, err := cosmos.NewProvider(rpcURL)
if err != nil {
Expand Down Expand Up @@ -80,6 +82,7 @@ func NewChain(
maxRetries: maxRetries,
retryIntervalSeconds: retryIntervalSeconds,
blockQueueChannelSize: blockQueueChannelSize,
minamount: minAmount,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions noble/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ChainConfig struct {

BlockQueueChannelSize uint64 `yaml:"block-queue-channel-size"`

MinAmount uint64 `yaml:"min-amount"`

// TODO move to keyring
MinterPrivateKey string `yaml:"minter-private-key"`
}
Expand All @@ -38,5 +40,6 @@ func (c *ChainConfig) Chain(name string) (types.Chain, error) {
c.BroadcastRetries,
c.BroadcastRetryInterval,
c.BlockQueueChannelSize,
c.MinAmount,
)
}
2 changes: 0 additions & 2 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type Config struct {
Api struct {
TrustedProxies []string `yaml:"trusted-proxies"`
} `yaml:"api"`
MinAmount uint64 `yaml:"min-amount"`
}

type ConfigWrapper struct {
Expand All @@ -27,7 +26,6 @@ type ConfigWrapper struct {
Api struct {
TrustedProxies []string `yaml:"trusted-proxies"`
} `yaml:"api"`
MinAmount uint64 `yaml:"min-amount"`
}

type ChainConfig interface {
Expand Down

0 comments on commit 17bfa3f

Please sign in to comment.