-
Notifications
You must be signed in to change notification settings - Fork 44
/
new_balancer_pool.go
49 lines (41 loc) · 1.39 KB
/
new_balancer_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
package types
import (
"time"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewPool returns a weighted CPMM pool with the provided parameters, and initial assets.
// Invariants that are assumed to be satisfied and not checked:
// (This is handled in ValidateBasic)
// * 2 <= len(assets) <= 8
// * FutureGovernor is valid
// * poolID doesn't already exist
func NewBalancerPool(poolId uint64, balancerPoolParams PoolParams, assets []PoolAsset, blockTime time.Time) (Pool, error) {
poolAddr := NewPoolAddress(poolId)
poolRebalanceTreasuryAddr := NewPoolRebalanceTreasury(poolId)
// pool thats created up to ensuring the assets and params are valid.
// We assume that FuturePoolGovernor is valid.
pool := &Pool{
PoolId: poolId,
Address: poolAddr.String(),
RebalanceTreasury: poolRebalanceTreasuryAddr.String(),
PoolParams: PoolParams{},
TotalWeight: math.ZeroInt(),
TotalShares: sdk.NewCoin(GetPoolShareDenom(poolId), InitPoolSharesSupply),
PoolAssets: nil,
}
err := pool.SetInitialPoolAssets(assets)
if err != nil {
return Pool{}, err
}
sortedPoolAssets := pool.GetAllPoolAssets()
err = balancerPoolParams.Validate(sortedPoolAssets)
if err != nil {
return Pool{}, err
}
err = pool.setInitialPoolParams(balancerPoolParams, sortedPoolAssets, blockTime)
if err != nil {
return Pool{}, err
}
return *pool, nil
}