Skip to content

Commit

Permalink
client/eth: PreRedeem
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Oct 3, 2021
1 parent d9611e5 commit 659a665
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@ func (eth *ExchangeWallet) estimateSwap(lots, lotSize, feeSuggestion uint64, nfo
// PreRedeem generates an estimate of the range of redemption fees that could
// be assessed.
func (*ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error) {
return nil, asset.ErrNotImplemented
return &asset.PreRedeem{
Estimate: &asset.RedeemEstimate{
RealisticBestCase: RedeemGas * req.FeeSuggestion,
RealisticWorstCase: RedeemGas * req.FeeSuggestion * req.Lots,
},
}, nil
}

// FundOrder selects coins for use in an order. The coins will be locked, and
Expand Down
24 changes: 24 additions & 0 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,30 @@ func TestPreSwap(t *testing.T) {
}
}

func TestPreRedeem(t *testing.T) {
node := &testNode{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
eth := &ExchangeWallet{
node: node,
ctx: ctx,
log: tLogger,
acct: new(accounts.Account),
}
preRedeem, err := eth.PreRedeem(&asset.PreRedeemForm{
LotSize: 123456,
Lots: 5,
FeeSuggestion: 100,
})
if err != nil {
t.Fatalf("unexpected PreRedeem error: %v", err)
}

if preRedeem.Estimate.RealisticBestCase >= preRedeem.Estimate.RealisticWorstCase {
t.Fatalf("best case > worst case")
}
}

func TestMaxOrder(t *testing.T) {
ethToGwei := func(eth uint64) uint64 {
return eth * dexeth.GweiFactor
Expand Down

0 comments on commit 659a665

Please sign in to comment.