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 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
36 changes: 34 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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"
)

Expand Down Expand Up @@ -50,9 +51,40 @@
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())

Check warning on line 64 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L64

Added line #L64 was not covered by tests

// update leverage and metoken params to include burn auction fee share.
lparams := app.LeverageKeeper.GetParams(ctx)
lparams.RewardsAuctionFee = sdk.MustNewDecFromStr("0.01")
if err := app.LeverageKeeper.SetParams(ctx, lparams); err != nil {
return nil, err

Check warning on line 70 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L67-L70

Added lines #L67 - L70 were not covered by tests
}

mekeeper := app.MetokenKeeperB.Keeper(&ctx)
meparams := mekeeper.GetParams()
meparams.RewardsAuctionFeeFactor = 10000 // 100% of fees goes to rewards auction
if err := mekeeper.SetParams(meparams); err != nil {
return nil, err

Check warning on line 77 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L73-L77

Added lines #L73 - L77 were not covered by tests
}

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

Check warning on line 80 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L80

Added line #L80 was not covered by tests
},
)

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

func (app *UmeeApp) registerUpgrade6_4(upgradeInfo upgradetypes.Plan) {
Expand Down
5 changes: 3 additions & 2 deletions proto/umee/leverage/v1/leverage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"direct_liquidation_fee\""
];
// Rewards Auction Factor determines the portion of interest accrued on
// Rewards Auction Fee determines the interest increase that will be accrued on
// borrows that is sent to the auction module for the rewards auction.
// So, 2% means, that there is additional 2% per year fee collected.
// Valid values: 0-1.
string rewards_auction_factor = 7 [
string rewards_auction_fee = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"oracle_reward_factor\""
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. 2% means that 2% of collected fees will go to
// the rewards auction. Note: this is different than x/leverage Params.rewards_auction_fee.
// 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
64 changes: 43 additions & 21 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,15 +1111,18 @@ paths:
uTokens as liquidation rewards.

Valid values: 0-1.
rewards_auction_factor:
rewards_auction_fee:
type: string
description: >-
Rewards Auction Factor determines the portion of interest
accrued on
Rewards Auction Fee determines the interest increase that
will be accrued on

borrows that is sent to the auction module for the rewards
auction.

So, 2% means, that there is additional 2% per year fee
collected.

Valid values: 0-1.
description: Params defines the parameters for the leverage module.
description: >-
Expand Down Expand Up @@ -5870,14 +5873,18 @@ 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. 2% means that
2% of collected fees will go to

auction module for the rewards auction.
the rewards auction. Note: this is different than
x/leverage Params.rewards_auction_fee.

Valid values: 0-10000 (in basis points, 2000 = 20%).
description: Params defines the parameters for the metoken module.
Expand Down Expand Up @@ -6599,11 +6606,16 @@ definitions:
uTokens as liquidation rewards.

Valid values: 0-1.
rewards_auction_factor:
rewards_auction_fee:
type: string
description: |-
Rewards Auction Factor determines the portion of interest accrued on
description: >-
Rewards Auction Fee determines the interest increase that will be
accrued on

borrows that is sent to the auction module for the rewards auction.

So, 2% means, that there is additional 2% per year fee collected.

Valid values: 0-1.
description: Params defines the parameters for the leverage module.
umee.leverage.v1.QueryAccountBalancesResponse:
Expand Down Expand Up @@ -7265,15 +7277,17 @@ definitions:
uTokens as liquidation rewards.

Valid values: 0-1.
rewards_auction_factor:
rewards_auction_fee:
type: string
description: >-
Rewards Auction Factor determines the portion of interest accrued
on
Rewards Auction Fee determines the interest increase that will be
accrued on

borrows that is sent to the auction module for the rewards
auction.

So, 2% means, that there is additional 2% per year fee collected.

Valid values: 0-1.
description: Params defines the parameters for the leverage module.
description: |-
Expand Down Expand Up @@ -10548,14 +10562,18 @@ 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. 2% means that 2% of
collected fees will go to

the rewards auction. Note: this is different than x/leverage
Params.rewards_auction_fee.

Valid values: 0-10000 (in basis points, 2000 = 20%).
description: Params defines the parameters for the metoken module.
Expand Down Expand Up @@ -10895,14 +10913,18 @@ 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. 2% means that 2% of
collected fees will go to

auction module for the rewards auction.
the rewards auction. Note: this is different than x/leverage
Params.rewards_auction_fee.

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/fixtures/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Params() types.Params {
CompleteLiquidationThreshold: sdk.MustNewDecFromStr("0.1"),
MinimumCloseFactor: sdk.MustNewDecFromStr("0.01"),
OracleRewardFactor: sdk.MustNewDecFromStr("0.01"),
RewardsAuctionFactor: sdk.MustNewDecFromStr("0.02"),
RewardsAuctionFee: sdk.MustNewDecFromStr("0.02"),
SmallLiquidationSize: sdk.MustNewDecFromStr("100.00"),
DirectLiquidationFee: sdk.MustNewDecFromStr("0.1"),
}
Expand Down
4 changes: 2 additions & 2 deletions x/leverage/keeper/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (k Keeper) DeriveSupplyAPY(ctx sdk.Context, denom string) sdk.Dec {
borrowRate := k.DeriveBorrowAPY(ctx, denom)
utilization := k.SupplyUtilization(ctx, denom)
params := k.GetParams(ctx)
reduction := params.OracleRewardFactor.Add(params.RewardsAuctionFactor).Add(token.ReserveFactor)
reduction := params.OracleRewardFactor.Add(params.RewardsAuctionFee).Add(token.ReserveFactor)

// supply APY = borrow APY * utilization, reduced by reserve factor and oracle reward factor
return borrowRate.Mul(utilization).Mul(sdk.OneDec().Sub(reduction))
Expand Down Expand Up @@ -156,7 +156,7 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {
))
auctionRewards = auctionRewards.Add(sdk.NewCoin(
token.BaseDenom,
interestAccrued.Mul(params.RewardsAuctionFactor).TruncateInt(),
interestAccrued.Mul(params.RewardsAuctionFee).TruncateInt(),
))
}

Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/interest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *IntegrationTestSuite) TestAccrueZeroInterest() {
require.Equal(sdk.MustNewDecFromStr("0.03"), borrowAPY)

// supply APY when borrow APY is 3%
// and utilization is 4%, and reserve factor=20%, OracleRewardFactor=1% RewardsAuctionFactor=2%
// and utilization is 4%, and reserve factor=20%, OracleRewardFactor=1% RewardsAuctionFee=2%
// 0.03 * 0.04 * (1 - 0.2 - 0.01 - 0.02)
supplyAPY := app.LeverageKeeper.DeriveSupplyAPY(ctx, appparams.BondDenom)
require.Equal(sdk.MustNewDecFromStr("0.000924"), supplyAPY)
Expand Down
Loading
Loading