/
types.go
43 lines (37 loc) · 1.27 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
func NewPosition(signer string, collateral sdk.Coin, leverage sdk.Dec, poolId uint64) *Position {
return &Position{
Address: signer,
Collateral: collateral,
Liabilities: sdk.ZeroInt(),
InterestPaid: sdk.ZeroInt(),
Leverage: leverage,
PositionHealth: sdk.ZeroDec(),
AmmPoolId: poolId,
LeveragedLpAmount: sdk.ZeroInt(),
}
}
func (position Position) Validate() error {
if position.Address == "" {
return errorsmod.Wrap(ErrPositionInvalid, "no address specified")
}
if position.Id == 0 {
return errorsmod.Wrap(ErrPositionInvalid, "no id specified")
}
return nil
}
// Generate a new leveragelp collateral wallet per position
func NewLeveragelpCollateralAddress(positionId uint64) sdk.AccAddress {
key := append([]byte("leveragelp_collateral"), sdk.Uint64ToBigEndian(positionId)...)
return address.Module(ModuleName, key)
}
// Generate a new leveragelp custody wallet per position
func NewLeveragelpCustodyAddress(positionId uint64) sdk.AccAddress {
key := append([]byte("leveragelp_collateral"), sdk.Uint64ToBigEndian(positionId)...)
return address.Module(ModuleName, key)
}