Skip to content

Commit

Permalink
Update somm_proto and prost build
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Jul 17, 2024
1 parent 701aee6 commit 5aa0439
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 74 deletions.
5 changes: 3 additions & 2 deletions prost_build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ fn compile_protos(out_dir: &Path, tmp_dir: &Path) {
.type_attribute("ScheduledCorkProposal", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("AxelarScheduledCorkProposal", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("AddPublisherProposal", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("AddManagedCellarIDsProposal", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("CellarIdSet", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("AddManagedCellarIDsProposalWithDeposit", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("AddAxelarManagedCellarIDsProposalWithDeposit", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute("axelar_cork::CellarIdSet", "#[derive(serde::Deserialize, serde::Serialize)]")
.compile_protos(&protos, &proto_include_paths)
.unwrap();

Expand Down
6 changes: 6 additions & 0 deletions proto/auction/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ message Params {
(gogoproto.nullable) = false
];
uint64 minimum_auction_height = 6;
// value between 0 and 1 the determines the % of somm received from bids that
// gets burned
string somm_burn_ratio = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
8 changes: 4 additions & 4 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
commit: 04467658e59e44bbb22fe568206e1f70
digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
Expand All @@ -19,5 +19,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 4ed3bc159a8b4ac68fe253218760d035
digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13
commit: f0e53af8f2fc4556b94f482688b57223
digest: shake256:de26a277fc28b8b411ecf58729d78d32fcf15090ffd998a4469225b17889bfb51442eaab04bb7a8d88d203ecdf0a9febd4ffd52c18ed1c2229160c7bd353ca95
2 changes: 0 additions & 2 deletions proto/cork/v2/cork.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax = "proto3";
package cork.v2;

import "gogoproto/gogo.proto";

option go_package = "github.com/peggyjv/sommelier/v7/x/cork/types/v2";

message Cork {
Expand Down
4 changes: 2 additions & 2 deletions somm_proto/src/prost/axelarcork.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct AxelarCorkResults {
#[prost(message, repeated, tag = "1")]
pub cork_results: ::prost::alloc::vec::Vec<AxelarCorkResult>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
pub struct CellarIdSet {
#[prost(uint64, tag = "1")]
pub chain_id: u64,
Expand Down Expand Up @@ -768,7 +768,7 @@ pub struct AddAxelarManagedCellarIDsProposal {
pub publisher_domain: ::prost::alloc::string::String,
}
/// AddAxelarManagedCellarIDsProposalWithDeposit is a specific definition for CLI commands
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
pub struct AddAxelarManagedCellarIDsProposalWithDeposit {
#[prost(string, tag = "1")]
pub title: ::prost::alloc::string::String,
Expand Down
4 changes: 2 additions & 2 deletions somm_proto/src/prost/cork.v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub mod query_client {
}
}
}
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AddManagedCellarIDsProposal {
#[prost(string, tag = "1")]
pub title: ::prost::alloc::string::String,
Expand All @@ -402,7 +402,7 @@ pub struct AddManagedCellarIDsProposal {
pub publisher_domain: ::prost::alloc::string::String,
}
/// AddManagedCellarIDsProposalWithDeposit is a specific definition for CLI commands
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
pub struct AddManagedCellarIDsProposalWithDeposit {
#[prost(string, tag = "1")]
pub title: ::prost::alloc::string::String,
Expand Down
42 changes: 41 additions & 1 deletion x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"encoding/binary"

sdkmath "cosmossdk.io/math"

errorsmod "cosmossdk.io/errors"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -325,10 +327,25 @@ func (k Keeper) FinishAuction(ctx sdk.Context, auction *types.Auction) error {
usommProceeds = usommProceeds.Add(bid.TotalUsommPaid.Amount)
}

usommProceedsCoin := sdk.NewCoin(params.BaseCoinUnit, usommProceeds)
var burnAmount sdkmath.Int

// Send proceeds to their appropriate destination module
if usommProceeds.IsPositive() {
// Burn a portion of the proceeds if the param is not 0
burnRatio := k.GetParamSet(ctx).SommBurnRatio
if burnRatio.GT(sdk.ZeroDec()) {
decProceeds := sdk.NewDecFromInt(usommProceeds)
burnAmount = decProceeds.Mul(burnRatio).TruncateInt()
burnAmountCoins := sdk.NewCoin(params.BaseCoinUnit, burnAmount)
usommProceeds = usommProceeds.Sub(burnAmount)
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, types.DefaultNullAddress, sdk.NewCoins(burnAmountCoins)); err != nil {
return err
}
}

remainingProceeds := usommProceeds.Sub(burnAmount)
usommProceedsCoin := sdk.NewCoin(params.BaseCoinUnit, remainingProceeds)

if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, auction.ProceedsModuleAccount, sdk.Coins{usommProceedsCoin}); err != nil {
return err
}
Expand Down Expand Up @@ -555,3 +572,26 @@ func (k Keeper) GetLastBidID(ctx sdk.Context) uint64 {
func (k Keeper) GetAuctionAccount(ctx sdk.Context) authtypes.ModuleAccountI {
return k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
}

func (k Keeper) BurnPortionOfProceeds(ctx sdk.Context, auction types.Auction, proceedsAmount sdkmath.Int) (burned sdkmath.Int, remaining sdkmath.Int, error error) {
remaining, burned = proceedsAmount, sdkmath.NewInt(0)
burnRatio := k.GetParamSet(ctx).SommBurnRatio
if burnRatio.GT(sdk.ZeroDec()) {
decProceeds := sdk.NewDecFromInt(proceedsAmount)
burned = decProceeds.Mul(burnRatio).TruncateInt()
burnAmountCoins := sdk.NewCoin(params.BaseCoinUnit, burned)
remaining = proceedsAmount.Sub(burned)

if error = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, types.DefaultNullAddress, sdk.NewCoins(burnAmountCoins)); error != nil {
return
}
}

proceedsCoin := sdk.NewCoin(params.BaseCoinUnit, remaining)

if error = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, auction.ProceedsModuleAccount, sdk.Coins{proceedsCoin}); error != nil {
return
}

return
}
24 changes: 24 additions & 0 deletions x/auction/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,27 @@ func (suite *KeeperTestSuite) TestUnhappyPathsForBeginAuction() {
})
}
}

func (suite *KeeperTestSuite) TestBurnPortionOfProceeds(t *testing.T) {
ctx, auctionKeeper := suite.ctx, suite.auctionKeeper
require := suite.Require()

auctionParams := auctionTypes.DefaultParams()
auctionKeeper.setParams(ctx, auctionParams)


// Mock bank keeper balance and transfers
proceedsAmount := sdk.NewCoin(params.BaseCoinUnit, sdk.NewInt(10000))
params := auctionTypes.DefaultParams()
params.SommBurnRatio = sdk.MustNewDecFromStr("0.1")
auctionKeeper.setParams(ctx, params)

suite.mockGetBalance(ctx, authtypes.NewModuleAddress(auctionTypes.ModuleName), params.BaseCoinUnit, proceedsAmount)

Check failure on line 473 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

params.BaseCoinUnit undefined (type "github.com/peggyjv/sommelier/v7/x/auction/types".Params has no field or method BaseCoinUnit)

Check failure on line 473 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

params.BaseCoinUnit undefined (type "github.com/peggyjv/sommelier/v7/x/auction/types".Params has no field or method BaseCoinUnit)

// Mock bank keeper burn coins
suite.mockBurnCoins(ctx, proceedsAmount)

Check failure on line 476 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

suite.mockBurnCoins undefined (type *KeeperTestSuite has no field or method mockBurnCoins)

Check failure on line 476 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

suite.mockBurnCoins undefined (type *KeeperTestSuite has no field or method mockBurnCoins)

// Burn proceeds
err := auctionKeeper.BurnPortionOfProceeds(ctx, proceedsAmount)

Check failure on line 479 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

assignment mismatch: 1 variable but auctionKeeper.BurnPortionOfProceeds returns 3 values

Check failure on line 479 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / test (1.22, ubuntu-latest)

not enough arguments in call to auctionKeeper.BurnPortionOfProceeds

Check failure on line 479 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

assignment mismatch: 1 variable but auctionKeeper.BurnPortionOfProceeds returns 3 values

Check failure on line 479 in x/auction/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

not enough arguments in call to auctionKeeper.BurnPortionOfProceeds
require.Nil(t, err)
}
1 change: 1 addition & 0 deletions x/auction/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ var (
ErrAuctionBelowMinimumUSDValue = errorsmod.Register(ModuleName, 45, "auction USD value below minimum")
ErrInvalidMinimumAuctionHeightParam = errorsmod.Register(ModuleName, 46, "invalid minimum auction height param")
ErrAuctionBelowMinimumHeight = errorsmod.Register(ModuleName, 47, "auction block height below minimum")
ErrInvalidSommBurnRatio = errorsmod.Register(ModuleName, 48, "invalid somm burn ratio")
)
121 changes: 86 additions & 35 deletions x/auction/types/genesis.pb.go

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

23 changes: 23 additions & 0 deletions x/auction/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var (
KeyAuctionMaxBlockAge = []byte("AuctionMaxBlockAge")
KeyAuctionPriceDecreaseAccelerationRate = []byte("AuctionPriceDecreaseAccelerationRate")
KeyMinimumAuctionHeight = []byte("MinimumAuctionHeight")
KeySommBurnRatio = []byte("SommBurnRatio")

// Zero address for burning
DefaultNullAddress = sdk.AccAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
)

var _ paramtypes.ParamSet = &Params{}
Expand All @@ -32,6 +36,7 @@ func DefaultParams() Params {
AuctionMaxBlockAge: 864000, // roughly 60 days based on 6 second blocks
AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.001"), // 0.1%
MinimumAuctionHeight: 0, // do not run auctions before this block height
SommBurnRatio: sdk.MustNewDecFromStr("0.0"),
}
}

Expand All @@ -44,6 +49,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyAuctionMaxBlockAge, &p.AuctionMaxBlockAge, validateAuctionMaxBlockAge),
paramtypes.NewParamSetPair(KeyAuctionPriceDecreaseAccelerationRate, &p.AuctionPriceDecreaseAccelerationRate, validateAuctionPriceDecreaseAccelerationRate),
paramtypes.NewParamSetPair(KeyMinimumAuctionHeight, &p.MinimumAuctionHeight, validateMinimumAuctionHeight),
paramtypes.NewParamSetPair(KeySommBurnRatio, &p.SommBurnRatio, validateSommBurnRatio),
}
}

Expand All @@ -69,6 +75,10 @@ func (p *Params) ValidateBasic() error {
return err
}

if err := validateSommBurnRatio(p.SommBurnRatio); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -139,3 +149,16 @@ func validateMinimumAuctionHeight(i interface{}) error {

return nil
}

func validateSommBurnRatio(i interface{}) error {
sommBurnRatio, ok := i.(sdk.Dec)
if !ok {
return errorsmod.Wrapf(ErrInvalidSommBurnRatio, "invalid somm burn ratio parameter type: %T", i)
}

if sommBurnRatio.LT(sdk.MustNewDecFromStr("0.0")) || sommBurnRatio.GT(sdk.MustNewDecFromStr("1.0")) {
return errorsmod.Wrapf(ErrInvalidSommBurnRatio, "somm burn ratio must be between 0 and 1 inclusive (0%% to 100%%)")
}

return nil
}
Loading

0 comments on commit 5aa0439

Please sign in to comment.