@@ -2,6 +2,7 @@ package keeper
22
33import (
44 "context"
5+ "fmt"
56
67 errorsmod "cosmossdk.io/errors"
78 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -12,7 +13,7 @@ import (
1213)
1314
1415// UpdatePoolParams updates the pool params
15- func (k Keeper ) UpdatePoolParams (ctx sdk.Context , poolId uint64 , poolParams types.PoolParams ) (uint64 , types.PoolParams , error ) {
16+ func (k Keeper ) UpdatePoolParams (ctx sdk.Context , poolId uint64 , newPoolParams types.PoolParams ) (uint64 , types.PoolParams , error ) {
1617 pool , found := k .GetPool (ctx , poolId )
1718 if ! found {
1819 return 0 , types.PoolParams {}, types .ErrPoolNotFound
@@ -24,11 +25,41 @@ func (k Keeper) UpdatePoolParams(ctx sdk.Context, poolId uint64, poolParams type
2425 }
2526
2627 // If the fee denom is empty, set it to the base currency
27- if poolParams .FeeDenom == "" {
28- poolParams .FeeDenom = baseCurrency
28+ if newPoolParams .FeeDenom == "" {
29+ newPoolParams .FeeDenom = baseCurrency
2930 }
3031
31- pool .PoolParams = poolParams
32+ // changing from non-oracle pool to oracle pool
33+ if ! pool .PoolParams .UseOracle && newPoolParams .UseOracle {
34+
35+ nonBaseCurrencyDenom := ""
36+ usdcDenomFound := false
37+
38+ for _ , asset := range pool .PoolAssets {
39+ if asset .Token .Denom != baseCurrency {
40+ nonBaseCurrencyDenom = asset .Token .Denom
41+ }
42+ if asset .Token .Denom == baseCurrency {
43+ usdcDenomFound = true
44+ }
45+ }
46+ if ! usdcDenomFound {
47+ return 0 , types.PoolParams {}, fmt .Errorf ("no usdc denom in the amm pool %d" , poolId )
48+ }
49+ if nonBaseCurrencyDenom == "" {
50+ return 0 , types.PoolParams {}, fmt .Errorf ("no non-usdc denom in the amm pool %d" , poolId )
51+ }
52+
53+ entry , found := k .assetProfileKeeper .GetEntryByDenom (ctx , nonBaseCurrencyDenom )
54+ if ! found {
55+ return 0 , types.PoolParams {}, fmt .Errorf ("asset profile for %s not found" , nonBaseCurrencyDenom )
56+ }
57+ _ , found = k .oracleKeeper .GetAssetPrice (ctx , entry .DisplayName )
58+ if ! found {
59+ return 0 , types.PoolParams {}, fmt .Errorf ("oracle price for %s not found" , entry .DisplayName )
60+ }
61+ }
62+ pool .PoolParams = newPoolParams
3263 k .SetPool (ctx , pool )
3364 return pool .PoolId , pool .PoolParams , nil
3465}
0 commit comments