Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/gorilla/m…
Browse files Browse the repository at this point in the history
…ux-1.8.1
  • Loading branch information
k-yang authored Nov 15, 2023
2 parents e360062 + 6fcf929 commit eee777f
Show file tree
Hide file tree
Showing 68 changed files with 1,845 additions and 1,215 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/changelog-deps.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
name: "Automatically update changelog with dependabot"
on:
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
changelog-update:
runs-on: ubuntu-latest

# TODO: feat: try to use author of the commit(s) to see if it's dependabot
# ${{ any(contains(commit.author.username, 'dependabot') for commit in github.event.commits) }}
if: contains(github.event.pull_request.labels.*.name, 'dependabot')
# TODO: feat: try to use author of the commit(s) to see if it's dependabot
# ${{ any(contains(commit.author.username, 'dependabot') for commit in github.event.commits) }}
steps:

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.NIBIRU_PM }}
token: ${{ secrets.NIBIBOT_GIT_TOKEN }}
# to avoid checking out the repo in a detached state
ref: ${{ github.head_ref }}
# Helps keep your repository up-to-date when Dependabot updates your dependencies.
# This step updates adds a line to the "## Unreleased" section
- uses: dangoslen/dependabot-changelog-helper@v3
with:
activationLabel: 'dependabot'
changelogPath: './CHANGELOG.md'
activationLabel: "dependabot"
changelogPath: "./CHANGELOG.md"

- uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v4
# - uses: bufbuild/buf-setup-action@v1.27.2
# - uses: bufbuild/buf-setup-action@v1.28.0
# - uses: bufbuild/buf-lint-action@v1
# with:
# input: "proto"
Expand All @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1.27.2
- uses: bufbuild/buf-setup-action@v1.28.0
with:
github_token: ${{ github.token }}
- uses: bufbuild/buf-breaking-action@v1
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1620](https://github.com/NibiruChain/nibiru/pull/1620) - Token factory transaction messages for Mint and Burn
* [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price
* [#1632](https://github.com/NibiruChain/nibiru/pull/1632) - feat(perp): Add settle position transaction
* [#1656](https://github.com/NibiruChain/nibiru/pull/1656) - feat(perp): Make the collateral denom a stateful collections.Item
* [#1670](https://github.com/NibiruChain/nibiru/pull/1670) - feat(inflation): Make inflation polynomial

### State Machine Breaking

Expand All @@ -71,7 +73,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Dependencies
- Bump `github.com/prometheus/client_golang` from 1.16.0 to 1.17.0 ([#1605](https://github.com/NibiruChain/nibiru/pull/1605))
- Bump `bufbuild/buf-setup-action` from 1.26.1 to 1.27.2 ([#1624](https://github.com/NibiruChain/nibiru/pull/1624), [#1641](https://github.com/NibiruChain/nibiru/pull/1641), [#1654](https://github.com/NibiruChain/nibiru/pull/1654))
- Bump `bufbuild/buf-setup-action` from 1.26.1 to 1.28.0 ([#1624](https://github.com/NibiruChain/nibiru/pull/1624), [#1641](https://github.com/NibiruChain/nibiru/pull/1641), [#1654](https://github.com/NibiruChain/nibiru/pull/1654), [#1671](https://github.com/NibiruChain/nibiru/pull/1671))
- Bump `stefanzweifel/git-auto-commit-action` from 4 to 5 ([#1625](https://github.com/NibiruChain/nibiru/pull/1625))
- Bump `github.com/CosmWasm/wasmvm` from 1.4.0 to 1.5.0 ([#1629](https://github.com/NibiruChain/nibiru/pull/1629), [#1657](https://github.com/NibiruChain/nibiru/pull/1657))
- Bump `google.golang.org/grpc` from 1.58.2 to 1.59.0 ([#1633](https://github.com/NibiruChain/nibiru/pull/1633), [#1643](https://github.com/NibiruChain/nibiru/pull/1643))
Expand Down Expand Up @@ -784,4 +786,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Testing

* [#695](https://github.com/NibiruChain/nibiru/pull/695) Add `OpenPosition` integration tests.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
9 changes: 5 additions & 4 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,14 @@ func (app *NibiruApp) InitKeepers(
appCodec, keys[epochstypes.StoreKey],
)

app.SudoKeeper = keeper.NewKeeper(
appCodec, keys[sudotypes.StoreKey],
)

app.PerpKeeperV2 = perpkeeper.NewKeeper(
appCodec, keys[perptypes.StoreKey],
app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.EpochsKeeper,
)

app.SudoKeeper = keeper.NewKeeper(
appCodec, keys[sudotypes.StoreKey],
app.SudoKeeper,
)

app.InflationKeeper = inflationkeeper.NewKeeper(
Expand Down
15 changes: 12 additions & 3 deletions proto/nibiru/inflation/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ message Params {
// inflation_enabled is the parameter that enables inflation and halts
// increasing the skipped_epochs
bool inflation_enabled = 1;
// exponential_calculation takes in the variables to calculate exponential
// polynomial_factors takes in the variables to calculate polynomial
// inflation
ExponentialCalculation exponential_calculation = 2
[ (gogoproto.nullable) = false ];
repeated string polynomial_factors = 2[
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// inflation_distribution of the minted denom
InflationDistribution inflation_distribution = 3
[ (gogoproto.nullable) = false ];
// epochs_per_period is the number of epochs that must pass before a new
// period is created
uint64 epochs_per_period = 4;

// periods_per_year is the number of periods that occur in a year
uint64 periods_per_year = 5;

// max_period is the maximum number of periods that have inflation being
// paid off. After this period, inflation will be disabled.
uint64 max_period = 6;
}
22 changes: 0 additions & 22 deletions proto/nibiru/inflation/v1/inflation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,3 @@ message InflationDistribution {
(gogoproto.nullable) = false
];
}

// ExponentialCalculation holds factors to calculate exponential inflation on
// each period. Calculation reference:
// periodProvision = exponentialDecay
// f(x) = a * (1 - r) ^ x + c
message ExponentialCalculation {
// a defines the initial value
string a = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// r defines the reduction factor
string r = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// c defines the parameter for long term inflation
string c = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
9 changes: 6 additions & 3 deletions proto/nibiru/perp/v2/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";

package nibiru.perp.v2;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "nibiru/perp/v2/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/perp/v2/types";
Expand Down Expand Up @@ -33,6 +33,9 @@ message GenesisState {
];
}

// For testing purposes, we allow the collateral to be set at genesis
string collateral_denom = 11;

repeated TraderVolume trader_volumes = 7 [ (gogoproto.nullable) = false ];

message Discount {
Expand Down Expand Up @@ -81,4 +84,4 @@ message GenesisPosition {
uint64 version = 2;

Position position = 3 [ (gogoproto.nullable) = false ];
}
}
14 changes: 14 additions & 0 deletions proto/nibiru/perp/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ service Msg {

rpc DonateToEcosystemFund(MsgDonateToEcosystemFund)
returns (MsgDonateToEcosystemFundResponse) {}

rpc ChangeCollateralDenom(MsgChangeCollateralDenom)
returns (MsgChangeCollateralDenomResponse) {}
}

// -------------------------- Settle Position --------------------------
Expand Down Expand Up @@ -328,3 +331,14 @@ message MsgDonateToEcosystemFund {
}

message MsgDonateToEcosystemFundResponse {}

// ----------------------- MsgChangeCollateralDenom -----------------------

// MsgChangeCollateralDenom: Changes the collateral denom for the module.
// [Admin] Only callable by sudoers.
message MsgChangeCollateralDenom {
string sender = 1;
string new_denom = 2;
}

message MsgChangeCollateralDenomResponse {}
12 changes: 7 additions & 5 deletions wasmbinding/exec_perp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *TestSuitePerpExecutor) SetupSuite() {
})
coins := sdk.NewCoins(
sdk.NewCoin(denoms.NIBI, sdk.NewInt(1_000_000)),
sdk.NewCoin(denoms.NUSD, sdk.NewInt(420_000*69)),
sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420_000*69)),
sdk.NewCoin(denoms.USDT, sdk.NewInt(420_000*69)),
)
s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins))
Expand All @@ -66,6 +66,7 @@ func (s *TestSuitePerpExecutor) SetupSuite() {
s.exec = &wasmbinding.ExecutorPerp{
PerpV2: nibiru.PerpKeeperV2,
}
s.nibiru.PerpKeeperV2.Collateral.Set(s.ctx, perpv2types.TestingCollateralDenomNUSD)
s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, s.contractPerp, coins))

s.OnSetupEnd()
Expand All @@ -79,7 +80,8 @@ func (s *TestSuitePerpExecutor) OnSetupEnd() {
// Happy path coverage of MarketOrder, AddMargin, RemoveMargin, and ClosePosition
func (s *TestSuitePerpExecutor) TestOpenAddRemoveClose() {
pair := asset.MustNewPair(s.happyFields.Pair)
margin := sdk.NewCoin(denoms.NUSD, sdk.NewInt(69))

margin := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69))
incorrectMargin := sdk.NewCoin(denoms.USDT, sdk.NewInt(69))

for _, err := range []error{
Expand Down Expand Up @@ -243,7 +245,7 @@ func (s *TestSuitePerpExecutor) DoInsuranceFundWithdrawTest(
s.nibiru.BankKeeper,
s.ctx,
perpv2types.PerpEFModuleAccount,
sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(420))),
sdk.NewCoins(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420))),
)
s.NoError(err)

Expand Down Expand Up @@ -330,7 +332,7 @@ func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest(
}

func (s *TestSuitePerpExecutor) TestSadPath_InsuranceFundWithdraw() {
fundsToWithdraw := sdk.NewCoin(denoms.NUSD, sdk.NewInt(69_000))
fundsToWithdraw := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69_000))

err := s.DoInsuranceFundWithdrawTest(fundsToWithdraw.Amount, s.contractDeployer)
s.Error(err)
Expand All @@ -339,7 +341,7 @@ func (s *TestSuitePerpExecutor) TestSadPath_InsuranceFundWithdraw() {
func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() {
sadPair := asset.Pair("ftt:ust:doge")
pair := sadPair
margin := sdk.NewCoin(denoms.NUSD, sdk.NewInt(69))
margin := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69))

for _, err := range []error{
s.DoMarketOrderTest(pair),
Expand Down
11 changes: 7 additions & 4 deletions wasmbinding/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ func (s *TestSuiteExecutor) SetupSuite() {
ChainID: "nibiru-wasmnet-1",
Time: time.Now().UTC(),
})
nibiru.PerpKeeperV2.Collateral.Set(ctx, perpv2types.TestingCollateralDenomNUSD)

coins := sdk.NewCoins(
sdk.NewCoin(denoms.NIBI, sdk.NewInt(10_000_000)),
sdk.NewCoin(denoms.NUSD, sdk.NewInt(420_000*69)),
sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420_000*69)),
)

s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins))
Expand All @@ -110,6 +112,7 @@ func (s *TestSuiteExecutor) SetupSuite() {
s.ctx = ctx
s.keeper = TestOnlySudoKeeper{Keeper: s.nibiru.SudoKeeper}
s.wasmKeeper = wasmkeeper.NewDefaultPermissionKeeper(nibiru.WasmKeeper)
s.nibiru.PerpKeeperV2.Collateral.Set(s.ctx, perpv2types.TestingCollateralDenomNUSD)

s.contractPerp = ContractMap[wasmbin.WasmKeyPerpBinding]
s.contractController = ContractMap[wasmbin.WasmKeyController]
Expand All @@ -126,10 +129,10 @@ func (s *TestSuiteExecutor) OnSetupEnd() {

func (s *TestSuiteExecutor) TestOpenAddRemoveClose() {
pair := asset.MustNewPair(s.happyFields.Pair)
margin := sdk.NewCoin(denoms.NUSD, sdk.NewInt(69))
margin := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69))

coins := sdk.NewCoins(
margin.Add(sdk.NewCoin(denoms.NUSD, sdk.NewInt(1_000))),
margin.Add(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(1_000))),
)
s.NoError(testapp.FundAccount(s.nibiru.BankKeeper, s.ctx, s.contractPerp, coins))

Expand Down Expand Up @@ -466,7 +469,7 @@ func (s *TestSuiteExecutor) TestInsuranceFundWithdraw() {
s.nibiru.BankKeeper,
s.ctx,
perpv2types.PerpEFModuleAccount,
sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(420))),
sdk.NewCoins(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420))),
)
s.NoError(err)
s.keeper.SetSudoContracts(
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/querier_perp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *TestSuitePerpQuerier) SetupSuite() {
})
coins := sdk.NewCoins(
sdk.NewCoin(denoms.NIBI, sdk.NewInt(10_000_000)),
sdk.NewCoin(denoms.NUSD, sdk.NewInt(1_420_000)),
sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(1_420_000)),
)
s.NoError(testapp.FundAccount(nibiru.BankKeeper, ctx, sender, coins))

Expand Down
11 changes: 11 additions & 0 deletions x/common/address.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"github.com/NibiruChain/collections"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -20,3 +21,13 @@ func StringsToAddrs(strs ...string) []sdk.AccAddress {
}
return addrs
}

// TODO: (realu) Move to collections library
var StringValueEncoder collections.ValueEncoder[string] = stringValueEncoder{}

type stringValueEncoder struct{}

func (a stringValueEncoder) Encode(value string) []byte { return []byte(value) }
func (a stringValueEncoder) Decode(b []byte) string { return string(b) }
func (a stringValueEncoder) Stringify(value string) string { return value }
func (a stringValueEncoder) Name() string { return "string" }
23 changes: 23 additions & 0 deletions x/common/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common_test
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/NibiruChain/nibiru/x/common"
Expand All @@ -17,3 +18,25 @@ func TestAddress(t *testing.T) {
require.EqualValues(t, addrs, addrsOut)
})
}

func TestStringValueEncoder(t *testing.T) {
encoder := common.StringValueEncoder
tests := []struct {
given string
}{
{"hello"},
{"12345"},
{""},
{testutil.AccAddress().String()},
}

for _, tc := range tests {
t.Run(tc.given, func(t *testing.T) {
want := tc.given
encoded := encoder.Encode(tc.given)
got := encoder.Decode(encoded)
assert.Equal(t, want, got)
assert.Equal(t, want, encoder.Stringify(got))
})
}
}
8 changes: 8 additions & 0 deletions x/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package common

import sdk "github.com/cosmos/cosmos-sdk/types"

const (
TreasuryPoolModuleAccount = "treasury_pool"
// TO_MICRO: multiplier for converting between units and micro-units.
TO_MICRO = int64(1_000_000)

NibiruTeam = "nibi1l8dxzwz9d4peazcqjclnkj2mhvtj7mpnkqx85mg0ndrlhwrnh7gskkzg0v"
)

func NibiruTeamAddr() sdk.AccAddress {
return sdk.MustAccAddressFromBech32(NibiruTeam)
}
Loading

0 comments on commit eee777f

Please sign in to comment.