/
routable_stableswap_pool.go
81 lines (63 loc) · 2.67 KB
/
routable_stableswap_pool.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package pools
import (
"fmt"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v21/ingest/sqs/domain"
"github.com/osmosis-labs/osmosis/v21/x/poolmanager"
poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types"
"github.com/osmosis-labs/osmosis/v21/x/gamm/pool-models/stableswap"
)
var _ domain.RoutablePool = &routableStableswapPoolImpl{}
type routableStableswapPoolImpl struct {
ChainPool *stableswap.Pool "json:\"pool\""
TokenOutDenom string "json:\"token_out_denom\""
TakerFee osmomath.Dec "json:\"taker_fee\""
}
// CalculateTokenOutByTokenIn implements RoutablePool.
func (r *routableStableswapPoolImpl) CalculateTokenOutByTokenIn(tokenIn sdk.Coin) (sdk.Coin, error) {
tokenOut, err := r.ChainPool.CalcOutAmtGivenIn(sdk.Context{}, sdk.NewCoins(tokenIn), r.TokenOutDenom, r.GetSpreadFactor())
if err != nil {
return sdk.Coin{}, err
}
return tokenOut, nil
}
// GetTokenOutDenom implements RoutablePool.
func (r *routableStableswapPoolImpl) GetTokenOutDenom() string {
return r.TokenOutDenom
}
// String implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) String() string {
return fmt.Sprintf("pool (%d), pool type (%d), pool denoms (%v), token out (%s)", r.ChainPool.Id, poolmanagertypes.Balancer, r.ChainPool.GetPoolDenoms(sdk.Context{}), r.TokenOutDenom)
}
// ChargeTakerFee implements domain.RoutablePool.
// Charges the taker fee for the given token in and returns the token in after the fee has been charged.
func (r *routableStableswapPoolImpl) ChargeTakerFeeExactIn(tokenIn sdk.Coin) (tokenInAfterFee sdk.Coin) {
tokenInAfterTakerFee, _ := poolmanager.CalcTakerFeeExactIn(tokenIn, r.TakerFee)
return tokenInAfterTakerFee
}
// GetTakerFee implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) GetTakerFee() math.LegacyDec {
return r.TakerFee
}
// SetTokenOutDenom implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) SetTokenOutDenom(tokenOutDenom string) {
r.TokenOutDenom = tokenOutDenom
}
// GetSpreadFactor implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) GetSpreadFactor() math.LegacyDec {
return r.ChainPool.GetSpreadFactor(sdk.Context{})
}
// GetId implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) GetId() uint64 {
return r.ChainPool.Id
}
// GetPoolDenoms implements domain.RoutablePool.
func (r *routableStableswapPoolImpl) GetPoolDenoms() []string {
return r.ChainPool.GetPoolDenoms(sdk.Context{})
}
// GetType implements domain.RoutablePool.
func (*routableStableswapPoolImpl) GetType() poolmanagertypes.PoolType {
return poolmanagertypes.Balancer
}