Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concept for capping ustc #357

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions proto/terra/market/v1beta1/market.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
bytes min_ustc_stability_spread = 4 [
(gogoproto.moretags) = "yaml:\"min_ustc_stability_spread\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
6 changes: 3 additions & 3 deletions proto/terra/wasm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ message Model {
// Code struct encompasses CodeInfo and CodeBytes
message Code {
LegacyCodeInfo code_info = 1 [(gogoproto.nullable) = false];
bytes code_bytes = 2;
bytes code_bytes = 2;
}

// Contract struct encompasses ContractAddress, ContractInfo, and ContractState
message Contract {
LegacyContractInfo contract_info = 1 [(gogoproto.nullable) = false];
repeated Model contract_store = 2 [(gogoproto.nullable) = false];
LegacyContractInfo contract_info = 1 [(gogoproto.nullable) = false];
repeated Model contract_store = 2 [(gogoproto.nullable) = false];
}
6 changes: 6 additions & 0 deletions x/market/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func (k Keeper) MinStabilitySpread(ctx sdk.Context) (res sdk.Dec) {
return
}

// MinTerraStabilitySpread is the minimum spread applied to swaps to / from Terra.
func (k Keeper) MinUstcStabilitySpread(ctx sdk.Context) (res sdk.Dec) {
k.paramSpace.Get(ctx, types.KeyMinUstcStabilitySpread, &res)
return
}

// PoolRecoveryPeriod is the period required to recover Terra&Luna Pools to the MintBasePool & BurnBasePool
func (k Keeper) PoolRecoveryPeriod(ctx sdk.Context) (res uint64) {
k.paramSpace.Get(ctx, types.KeyPoolRecoveryPeriod, &res)
Expand Down
6 changes: 6 additions & 0 deletions x/market/keeper/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func (k Keeper) ComputeSwap(ctx sdk.Context, offerCoin sdk.Coin, askDenom string
}

spread = tobinTax

// applied min ustc stability spread for swapping into ustc denom
if askDenom == core.MicroUSDDenom && spread.LT(k.MinUstcStabilitySpread(ctx)) {
spread = k.MinUstcStabilitySpread(ctx)
}

return retDecCoin, spread, nil
}

Expand Down
102 changes: 77 additions & 25 deletions x/market/types/market.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 28 additions & 6 deletions x/market/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@ var (
KeyPoolRecoveryPeriod = []byte("PoolRecoveryPeriod")
// Min spread
KeyMinStabilitySpread = []byte("MinStabilitySpread")
// Min spread for USTC denom
KeyMinUstcStabilitySpread = []byte("MinUSTCStabilitySpread")
)

// Default parameter values
var (
DefaultBasePool = sdk.NewDec(1000000 * core.MicroUnit) // 1000,000sdr = 1000,000,000,000usdr
DefaultPoolRecoveryPeriod = core.BlocksPerDay // 14,400
DefaultMinStabilitySpread = sdk.NewDecWithPrec(2, 2) // 2%
DefaultBasePool = sdk.NewDec(1000000 * core.MicroUnit) // 1000,000sdr = 1000,000,000,000usdr
DefaultPoolRecoveryPeriod = core.BlocksPerDay // 14,400
DefaultMinStabilitySpread = sdk.NewDecWithPrec(2, 2) // 2%
DefaultMinUstcStabilitySpread = sdk.ZeroDec() // 0%
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the prop this would need to be 100%

)

var _ paramstypes.ParamSet = &Params{}

// DefaultParams creates default market module parameters
func DefaultParams() Params {
return Params{
BasePool: DefaultBasePool,
PoolRecoveryPeriod: DefaultPoolRecoveryPeriod,
MinStabilitySpread: DefaultMinStabilitySpread,
BasePool: DefaultBasePool,
PoolRecoveryPeriod: DefaultPoolRecoveryPeriod,
MinStabilitySpread: DefaultMinStabilitySpread,
MinUstcStabilitySpread: DefaultMinUstcStabilitySpread,
}
}

Expand All @@ -57,6 +61,7 @@ func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
paramstypes.NewParamSetPair(KeyBasePool, &p.BasePool, validateBasePool),
paramstypes.NewParamSetPair(KeyPoolRecoveryPeriod, &p.PoolRecoveryPeriod, validatePoolRecoveryPeriod),
paramstypes.NewParamSetPair(KeyMinStabilitySpread, &p.MinStabilitySpread, validateMinStabilitySpread),
paramstypes.NewParamSetPair(KeyMinUstcStabilitySpread, &p.MinUstcStabilitySpread, validateMinUstcStabilitySpread),
}
}

Expand Down Expand Up @@ -117,3 +122,20 @@ func validateMinStabilitySpread(i interface{}) error {

return nil
}

func validateMinUstcStabilitySpread(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNegative() {
return fmt.Errorf("min spread must be positive or zero: %s", v)
}

if v.GT(sdk.OneDec()) {
return fmt.Errorf("min spread is too large: %s", v)
}

return nil
}
Loading