/
types.go
28 lines (24 loc) · 917 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package liquidator
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
type SeizedDebt struct {
Total sdk.Int // Total debt seized from CDPs. Known as Awe in maker.
SentToAuction sdk.Int // Portion of seized debt that has had a (reverse) auction was started for it. Known as Ash in maker.
// SentToAuction should always be < Total
}
// Available gets the seized debt that has not been sent for auction. Known as Woe in maker.
func (sd SeizedDebt) Available() sdk.Int {
return sd.Total.Sub(sd.SentToAuction)
}
func (sd SeizedDebt) Settle(amount sdk.Int) (SeizedDebt, sdk.Error) {
if amount.IsNegative() {
return sd, sdk.ErrInternal("tried to settle a negative amount")
}
if amount.GT(sd.Total) {
return sd, sdk.ErrInternal("tried to settle more debt than exists")
}
sd.Total = sd.Total.Sub(amount)
sd.SentToAuction = sdk.MaxInt(sd.SentToAuction.Sub(amount), sdk.ZeroInt())
return sd, nil
}