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 7 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 @@

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"

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / Run govulncheck

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-app-non-determinism

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

"github.com/umee-network/umee/v6/x/metoken" imported and not used (typecheck)

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

"github.com/umee-network/umee/v6/x/metoken" imported and not used) (typecheck)

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

"github.com/umee-network/umee/v6/x/metoken" imported and not used) (typecheck)

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / umeed darwin-amd64

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / umeed linux-amd64

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / umeed darwin-arm64

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / umeed linux-arm64

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used

Check failure on line 27 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

"github.com/umee-network/umee/v6/x/metoken" imported and not used
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
)

// RegisterUpgradeHandlersregisters upgrade handlers.
Expand Down Expand Up @@ -50,9 +52,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())

// 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
}

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
}

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