-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Miscellaneous small fixes to superfluid logic (#865)
* WIP: superfluid spec * Make unified method for severe errors * Fix immediate epoch number problem * Refactor updateEpochTwap into its own function * More function moves, add epoch item to spec * List the flow of whats expected to happen at epoch end * Reorder epoch end order of operations * Restore prior functionality of serializing twap at the new epoch numberf * basic twap docs * companion to prior commit * Move TWAP calculation into its own spot
- Loading branch information
1 parent
e4e97a3
commit 9b977f3
Showing
17 changed files
with
189 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/x/superfluid/types" | ||
) | ||
|
||
func (k Keeper) HandleSetSuperfluidAssetsProposal(ctx sdk.Context, p *types.SetSuperfluidAssetsProposal) error { | ||
for _, asset := range p.Assets { | ||
k.SetSuperfluidAsset(ctx, asset) | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.TypeEvtSetSuperfluidAsset, | ||
sdk.NewAttribute(types.AttributeDenom, asset.Denom), | ||
sdk.NewAttribute(types.AttributeSuperfluidAssetType, asset.AssetType.String()), | ||
), | ||
}) | ||
event := sdk.NewEvent( | ||
types.TypeEvtSetSuperfluidAsset, | ||
sdk.NewAttribute(types.AttributeDenom, asset.Denom), | ||
sdk.NewAttribute(types.AttributeSuperfluidAssetType, asset.AssetType.String()), | ||
) | ||
ctx.EventManager().EmitEvent(event) | ||
} | ||
return nil | ||
} | ||
|
||
func (k Keeper) HandleRemoveSuperfluidAssetsProposal(ctx sdk.Context, p *types.RemoveSuperfluidAssetsProposal) error { | ||
for _, denom := range p.SuperfluidAssetDenoms { | ||
k.SetEpochOsmoEquivalentTWAP(ctx, 0, denom, sdk.ZeroDec()) | ||
k.DeleteSuperfluidAsset(ctx, denom) | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.TypeEvtRemoveSuperfluidAsset, | ||
sdk.NewAttribute(types.AttributeDenom, denom), | ||
), | ||
}) | ||
asset := k.GetSuperfluidAsset(ctx, denom) | ||
dummyAsset := types.SuperfluidAsset{} | ||
if asset == dummyAsset { | ||
return fmt.Errorf("superfluid asset %s doesn't exist", denom) | ||
} | ||
k.BeginUnwindSuperfluidAsset(ctx, 0, asset) | ||
event := sdk.NewEvent( | ||
types.TypeEvtRemoveSuperfluidAsset, | ||
sdk.NewAttribute(types.AttributeDenom, denom), | ||
) | ||
ctx.EventManager().EmitEvent(event) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/x/superfluid/types" | ||
) | ||
|
||
// BeginUnwindSuperfluidAsset starts the deletion process for a superfluid asset. | ||
// This current method is a stub, but is called when: | ||
// * Governance removes a superfluid asset | ||
// * A severe error in gamm occurs | ||
// | ||
// It should eventually begin unwinding all of the synthetic lockups for that asset | ||
// and queue them for deletion. | ||
// See https://github.com/osmosis-labs/osmosis/issues/864 | ||
func (k Keeper) BeginUnwindSuperfluidAsset(ctx sdk.Context, epochNum int64, asset types.SuperfluidAsset) { | ||
// Right now set the TWAP to 0, and delete the asset. | ||
k.SetEpochOsmoEquivalentTWAP(ctx, epochNum, asset.Denom, sdk.ZeroDec()) | ||
k.DeleteSuperfluidAsset(ctx, asset.Denom) | ||
} | ||
|
||
func (k Keeper) GetRiskAdjustedOsmoValue(ctx sdk.Context, asset types.SuperfluidAsset, amount sdk.Int) sdk.Int { | ||
// TODO: we need to figure out how to do this later. | ||
minRiskFactor := k.GetParams(ctx).MinimumRiskFactor | ||
return amount.Sub(amount.ToDec().Mul(minRiskFactor).RoundInt()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- | ||
order: 4 | ||
--> | ||
|
||
# Epochs | ||
|
||
At the Osmosis rewards distribution epoch time, all superfluid staking rewards get distributed. | ||
The envisioned flow of how this works is as follows: | ||
|
||
* (Epochs) AfterEpochEnd hook runs for epoch N | ||
* (Mint) distributes rewards to all stakers at the epoch that just endeds prices | ||
* (Superfluid) Claim all staking rewards to every intermediary module accounts | ||
* (Superfluid) Update all TWAP values [updateEpochEnd][./../keeper/hooks.go] | ||
* Here we are setting the TWAP value for epoch N+1, as the TWAP from the duration of epoch N. | ||
* (Superfluid) Update all the intermediary accounts staked amounts. (Mint/Burn coins as needed as well) |
2 changes: 1 addition & 1 deletion
2
x/superfluid/spec/04_events.md → x/superfluid/spec/05_events.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- | ||
order: 4 | ||
order: 5 | ||
--> | ||
|
||
# Events |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.