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

feat(auction): upgrade handler and params #2526

Merged
merged 9 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
37 changes: 35 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (

appparams "github.com/umee-network/umee/v6/app/params"
"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/x/auction"
leveragetypes "github.com/umee-network/umee/v6/x/leverage/types"
"github.com/umee-network/umee/v6/x/metoken"
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
)

// RegisterUpgradeHandlersregisters upgrade handlers.
Expand Down Expand Up @@ -50,9 +52,40 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
app.registerOutdatedPlaceholderUpgrade("v6.1")
app.registerOutdatedPlaceholderUpgrade("v6.2")
app.registerUpgrade("v6.3", upgradeInfo, nil, nil, nil)

app.registerUpgrade6_4(upgradeInfo)
app.registerUpgrade("v6.5", upgradeInfo, nil, []string{crisistypes.ModuleName}, nil)

app.registerUpgrade6_5(upgradeInfo)
}

func (app *UmeeApp) registerUpgrade6_5(upgradeInfo upgradetypes.Plan) {
planName := "v6.5"

app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
printPlanName(planName, ctx.Logger())

// update leverage and metoken params to include burn auction fee share.
lparams := app.LeverageKeeper.GetParams(ctx)
lparams.RewardsAuctionFactor = leveragetypes.DefaultParams().RewardsAuctionFactor
if err := app.LeverageKeeper.SetParams(ctx, lparams); err != nil {
return nil, err
}

mekeeper := app.MetokenKeeperB.Keeper(&ctx)
meparams := mekeeper.GetParams()
meparams.RewardsAuctionFeeFactor = metoken.DefaultParams().RewardsAuctionFeeFactor
if err := mekeeper.SetParams(meparams); err != nil {
return nil, err
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)

app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{auction.ModuleName},
Deleted: []string{crisistypes.ModuleName},
})
}

func (app *UmeeApp) registerUpgrade6_4(upgradeInfo upgradetypes.Plan) {
Expand Down
7 changes: 4 additions & 3 deletions proto/umee/metoken/v1/metoken.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ message Params {
// leverage module
int64 claiming_frequency = 2;

// Rewards Auction Factor determines the portion of swap and redeem fee that is sent to the
// auction module for the rewards auction.
// Rewards Auction Fee Factor determines the portion of total fees collected by the metoken
// module that will go for the rewards auction. Note: this is different than x/leverage
// Params.rewards_auction_factor.
// Valid values: 0-10000 (in basis points, 2000 = 20%).
uint32 rewards_auction_factor = 3 [
uint32 rewards_auction_fee_factor = 3 [
(gogoproto.customtype) = "github.com/umee-network/umee/v6/util/bpmath.FixedBP",
(gogoproto.nullable) = false
];
Expand Down
33 changes: 21 additions & 12 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5870,14 +5870,17 @@ paths:
often metoken module will claim accrued interest from

leverage module
rewards_auction_factor:
rewards_auction_fee_factor:
type: integer
format: int64
description: >-
Rewards Auction Factor determines the portion of swap and
redeem fee that is sent to the
Rewards Auction Fee Factor determines the portion of total
fees collected by the metoken

module that will go for the rewards auction. Note: this is
different than x/leverage

auction module for the rewards auction.
Params.rewards_auction_factor.

Valid values: 0-10000 (in basis points, 2000 = 20%).
description: Params defines the parameters for the metoken module.
Expand Down Expand Up @@ -10548,14 +10551,17 @@ definitions:
module will claim accrued interest from

leverage module
rewards_auction_factor:
rewards_auction_fee_factor:
type: integer
format: int64
description: >-
Rewards Auction Factor determines the portion of swap and redeem fee
that is sent to the
Rewards Auction Fee Factor determines the portion of total fees
collected by the metoken

auction module for the rewards auction.
module that will go for the rewards auction. Note: this is different
than x/leverage

Params.rewards_auction_factor.

Valid values: 0-10000 (in basis points, 2000 = 20%).
description: Params defines the parameters for the metoken module.
Expand Down Expand Up @@ -10895,14 +10901,17 @@ definitions:
metoken module will claim accrued interest from

leverage module
rewards_auction_factor:
rewards_auction_fee_factor:
type: integer
format: int64
description: >-
Rewards Auction Factor determines the portion of swap and redeem
fee that is sent to the
Rewards Auction Fee Factor determines the portion of total fees
collected by the metoken

module that will go for the rewards auction. Note: this is
different than x/leverage

auction module for the rewards auction.
Params.rewards_auction_factor.

Valid values: 0-10000 (in basis points, 2000 = 20%).
description: Params defines the parameters for the metoken module.
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func DefaultParams() Params {
CompleteLiquidationThreshold: sdk.MustNewDecFromStr("0.4"),
MinimumCloseFactor: sdk.MustNewDecFromStr("0.05"),
OracleRewardFactor: sdk.MustNewDecFromStr("0.01"),
RewardsAuctionFactor: sdk.MustNewDecFromStr("0.02"),
RewardsAuctionFactor: sdk.MustNewDecFromStr("0.20"),
SmallLiquidationSize: sdk.MustNewDecFromStr("500.00"),
DirectLiquidationFee: sdk.MustNewDecFromStr("0.05"),
}
Expand Down
4 changes: 2 additions & 2 deletions x/metoken/keeper/intest/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func verifySwap(

// totalfee = feeRate * amount
totalFee := sdk.NewCoin(denom, feeRate.MulInt(tc.asset.Amount).TruncateInt())
feeToAuction := params.RewardsAuctionFactor.Mul(totalFee.Amount)
feeToAuction := params.RewardsAuctionFeeFactor.Mul(totalFee.Amount)
feeToReserve := totalFee.Amount.Sub(feeToAuction)

// amount_to_swap = swap_amount - fee
Expand Down Expand Up @@ -1718,7 +1718,7 @@ func verifyRedeem(

// totalfee = feeRate * amount_to_redeem
totalFee := sdk.NewCoin(tc.denom, feeRate.MulInt(amountToWithdraw).TruncateInt())
feeToAuction := params.RewardsAuctionFactor.Mul(totalFee.Amount)
feeToAuction := params.RewardsAuctionFeeFactor.Mul(totalFee.Amount)
feeToReserve := totalFee.Amount.Sub(feeToAuction)

amountToRedeem := amountToWithdraw.Sub(totalFee.Amount)
Expand Down
2 changes: 1 addition & 1 deletion x/metoken/keeper/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (k Keeper) availableToSupply(denom string) (bool, sdkmath.Int, error) {
// breakFee calculates the protocol fee for the burn auction and the reminder
func (k Keeper) breakFee(fee sdkmath.Int) (sdkmath.Int, sdkmath.Int) {
p := k.GetParams()
toAuction := p.RewardsAuctionFactor.Mul(fee)
toAuction := p.RewardsAuctionFeeFactor.Mul(fee)
return toAuction, fee.Sub(toAuction)
}

Expand Down
4 changes: 2 additions & 2 deletions x/metoken/keeper/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestSwap_Valid(t *testing.T) {
usdBal2, n := indexBal2.AssetBalance(tenUSDT.Denom)
assert.GreaterOrEqual(n, 0)
usdBal1, _ := indexBal1.AssetBalance(tenUSDT.Denom)
toAuction := params.RewardsAuctionFactor.Mul(resp.fee.Amount)
toAuction := params.RewardsAuctionFeeFactor.Mul(resp.fee.Amount)
assert.Equal(usdBal2.Fees.Sub(usdBal1.Fees), resp.fee.Amount.Sub(toAuction))

// exchange_rate = coin_price / metoken_price
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestBreakFees(t *testing.T) {
assert := assert.New(t)
k := initMeUSDNoopKeper(t)
p := k.GetParams()
assert.EqualValues(p.RewardsAuctionFactor, 1000)
assert.EqualValues(p.RewardsAuctionFeeFactor, 1000)

amount := sdkmath.NewInt(2_000)
toAuction, toRevenue := k.breakFee(amount)
Expand Down
115 changes: 58 additions & 57 deletions x/metoken/metoken.pb.go

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

2 changes: 1 addition & 1 deletion x/metoken/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ func DefaultParams() Params {
return Params{
RebalancingFrequency: 60 * 60 * 12, // 12h
ClaimingFrequency: 60 * 60 * 24 * 7, // 7d
RewardsAuctionFactor: 1000, // 10% of fees goes to rewards auction
RewardsAuctionFeeFactor: 2000, // 20% of fees goes to rewards auction
}
}
Loading