-
Notifications
You must be signed in to change notification settings - Fork 0
/
participation.go
47 lines (43 loc) · 1.64 KB
/
participation.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
yaml "gopkg.in/yaml.v2"
)
// NewOrderBookParticipation creates a new book participation object
//
//nolint:interfacer
func NewOrderBookParticipation(
index uint64, orderBookUID string, participantAddress string,
exposuresNotFilled uint64, isModuleAccount bool,
liquidity, currentRoundLiquidity, totalBetAmount, currentRoundTotalBetAmount, maxLoss, currentRoundMaxLoss sdk.Int,
currentRoundMaxLossOddsUID string, actualProfit sdk.Int,
) OrderBookParticipation {
return OrderBookParticipation{
Index: index,
OrderBookUID: orderBookUID,
ParticipantAddress: participantAddress,
IsModuleAccount: isModuleAccount,
Liquidity: liquidity,
CurrentRoundLiquidity: currentRoundLiquidity,
ExposuresNotFilled: exposuresNotFilled,
TotalBetAmount: totalBetAmount,
CurrentRoundTotalBetAmount: currentRoundTotalBetAmount,
MaxLoss: maxLoss,
CurrentRoundMaxLoss: currentRoundMaxLoss,
CurrentRoundMaxLossOddsUID: currentRoundMaxLossOddsUID,
ActualProfit: actualProfit,
}
}
// String returns a human readable string representation of a BookParticipation.
func (bp OrderBookParticipation) String() string {
out, err := yaml.Marshal(bp)
if err != nil {
panic(err)
}
return string(out)
}
// CalculateMaxLoss calculates the maxixmum amount of the tokens expected to be the
// loss of the participation according to the bet amount
func (bp OrderBookParticipation) CalculateMaxLoss(betAmount sdk.Int) sdk.Int {
return bp.CurrentRoundMaxLoss.Sub(betAmount)
}