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

Feature/oracle spread #150

Merged
merged 19 commits into from
Jun 4, 2019
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: 20 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/terra-project/core/x/pay"
"github.com/terra-project/core/x/treasury"

"github.com/terra-project/core/types/assets"

tdistr "github.com/terra-project/core/x/distribution"
tslashing "github.com/terra-project/core/x/slashing"
tstaking "github.com/terra-project/core/x/staking"
Expand Down Expand Up @@ -166,20 +168,25 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
app.bankKeeper,
app.feeCollectionKeeper,
)
app.oracleKeeper = oracle.NewKeeper(
app.cdc,
app.keyOracle,
stakingKeeper.GetValidatorSet(),
app.paramsKeeper.Subspace(oracle.DefaultParamspace),
)
app.mintKeeper = mint.NewKeeper(
app.cdc,
app.keyMint,
stakingKeeper,
app.bankKeeper,
app.accountKeeper,
)
app.oracleKeeper = oracle.NewKeeper(
app.cdc,
app.keyOracle,
app.mintKeeper,
app.distrKeeper,
app.feeCollectionKeeper,
stakingKeeper.GetValidatorSet(),
app.paramsKeeper.Subspace(oracle.DefaultParamspace),
)
app.marketKeeper = market.NewKeeper(
app.cdc,
app.keyMarket,
app.oracleKeeper,
app.mintKeeper,
app.paramsKeeper.Subspace(market.DefaultParamspace),
Expand All @@ -190,14 +197,14 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
stakingKeeper.GetValidatorSet(),
app.mintKeeper,
app.marketKeeper,
app.distrKeeper,
app.feeCollectionKeeper,
app.paramsKeeper.Subspace(treasury.DefaultParamspace),
)
app.budgetKeeper = budget.NewKeeper(
app.cdc,
app.keyBudget,
app.marketKeeper,
app.mintKeeper,
app.treasuryKeeper,
stakingKeeper.GetValidatorSet(),
app.paramsKeeper.Subspace(budget.DefaultParamspace),
)
Expand Down Expand Up @@ -318,17 +325,11 @@ func (app *TerraApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) a
func (app *TerraApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates, tags := staking.EndBlocker(ctx, app.stakingKeeper)

oracleClaims, oracleTags := oracle.EndBlocker(ctx, app.oracleKeeper)
oracleTags := oracle.EndBlocker(ctx, app.oracleKeeper)
tags = append(tags, oracleTags...)
for _, oracleClaim := range oracleClaims {
app.treasuryKeeper.AddClaim(ctx, oracleClaim)
}

budgetClaims, budgetTags := budget.EndBlocker(ctx, app.budgetKeeper)
budgetTags := budget.EndBlocker(ctx, app.budgetKeeper)
tags = append(tags, budgetTags...)
for _, budgetClaim := range budgetClaims {
app.treasuryKeeper.AddClaim(ctx, budgetClaim)
}

treasuryTags := treasury.EndBlocker(ctx, app.treasuryKeeper)
tags = append(tags, treasuryTags...)
Expand Down Expand Up @@ -427,6 +428,9 @@ func (app *TerraApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abc
}
}

// GetIssuance needs to be called once to read account balances to the store
app.mintKeeper.GetIssuance(ctx, assets.MicroLunaDenom, sdk.ZeroInt())

// assert runtime invariants
app.assertRuntimeInvariants()

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ You can edit your validator's public description. This info is to identify your
The `--identity` can be used as to verify identity with systems like Keybase or UPort. When using with Keybase `--identity` should be populated with a 16-digit string that is generated with a [keybase.io](https://keybase.io) account. It's a cryptographically secure method of verifying your identity across multiple online networks. The Keybase API allows us to retrieve your Keybase avatar. This is how you can add a logo to your validator profile.

```bash
terracli tx staking edit-validator
terracli tx staking edit-validator \
--moniker="choose a moniker" \
--website="https://terra.money" \
--identity=6A0D65E29A4CBC8E \
Expand Down
32 changes: 2 additions & 30 deletions types/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,26 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// ClaimClass is used to categorize type of Claim
type ClaimClass byte

const (
// OracleClaimClass represents oracle claim type
OracleClaimClass ClaimClass = iota
// BudgetClaimClass represents budget claim type
BudgetClaimClass
)

//------------------------------------
//------------------------------------
//------------------------------------

// Claim is an interface that directs its rewards to an attached bank account.
type Claim struct {
Class ClaimClass `json:"class"`
Weight sdk.Int `json:"weight"`
Recipient sdk.AccAddress `json:"recipient"`
}

// NewClaim generates a Claim instance.
func NewClaim(class ClaimClass, weight sdk.Int, recipient sdk.AccAddress) Claim {
func NewClaim(weight sdk.Int, recipient sdk.AccAddress) Claim {
return Claim{
Class: class,
Weight: weight,
Recipient: recipient,
}
}

// ID returns the id of the claim
func (c Claim) ID() string {
return fmt.Sprintf("%d:%s", c.Class, c.Recipient.String())
}

func (c Claim) getClassString() string {
switch c.Class {
case OracleClaimClass:
return "oracle"
case BudgetClaimClass:
return "budget"
}
return "unknown"
}

func (c Claim) String() string {
return fmt.Sprintf(`Claim
Class: %v
Weight: %v
Recipient: %v`, c.getClassString(), c.Weight, c.Recipient)
Recipient: %v`, c.Weight, c.Recipient)
}
4 changes: 3 additions & 1 deletion types/claimpool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "fmt"
import (
"fmt"
)

// ClaimPool is a list of Claims
type ClaimPool []Claim
Expand Down
2 changes: 1 addition & 1 deletion types/util/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// nolint
const (
BlocksPerMinute = int64(12)
BlocksPerMinute = int64(10)
BlocksPerHour = BlocksPerMinute * 60
BlocksPerDay = BlocksPerHour * 24
BlocksPerWeek = BlocksPerDay * 7
Expand Down
81 changes: 50 additions & 31 deletions x/bench/bench_test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bench

import (
"github.com/terra-project/core/types/assets"
"github.com/terra-project/core/types/mock"
"github.com/terra-project/core/x/budget"
"github.com/terra-project/core/x/market"
"github.com/terra-project/core/x/mint"
Expand All @@ -14,6 +13,7 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -34,6 +34,9 @@ var (
pubKeys [numOfValidators]crypto.PubKey
addrs [numOfValidators]sdk.AccAddress

valConsPubKeys [numOfValidators]crypto.PubKey
valConsAddrs [numOfValidators]sdk.ConsAddress

uLunaAmt = sdk.NewInt(10000000000).MulRaw(assets.MicroUnit)
uSDRAmt = sdk.NewInt(10000000000).MulRaw(assets.MicroUnit)
)
Expand Down Expand Up @@ -66,6 +69,7 @@ func createTestInput() testInput {
keyAcc := sdk.NewKVStoreKey(auth.StoreKey)
keyParams := sdk.NewKVStoreKey(params.StoreKey)
tKeyParams := sdk.NewTransientStoreKey(params.TStoreKey)
keyMarket := sdk.NewKVStoreKey(market.StoreKey)
keyMint := sdk.NewKVStoreKey(mint.StoreKey)
keyFee := sdk.NewKVStoreKey(auth.FeeStoreKey)
keyBudget := sdk.NewKVStoreKey(budget.StoreKey)
Expand All @@ -84,6 +88,7 @@ func createTestInput() testInput {
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tKeyParams, sdk.StoreTypeTransient, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyMarket, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyMint, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyBudget, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyOracle, sdk.StoreTypeIAVL, db)
Expand Down Expand Up @@ -120,7 +125,18 @@ func createTestInput() testInput {
)

stakingKeeper.SetPool(ctx, staking.InitialPool())
stakingKeeper.SetParams(ctx, staking.DefaultParams())
stakingParams := staking.DefaultParams()
stakingParams.BondDenom = assets.MicroLunaDenom
stakingKeeper.SetParams(ctx, stakingParams)

feeKeeper := auth.NewFeeCollectionKeeper(
cdc, keyFee,
)

distrKeeper := distr.NewKeeper(
cdc, keyDistr, paramsKeeper.Subspace(distr.DefaultParamspace),
bankKeeper, stakingKeeper, feeKeeper, distr.DefaultCodespace,
)

mintKeeper := mint.NewKeeper(
cdc,
Expand All @@ -130,60 +146,63 @@ func createTestInput() testInput {
accKeeper,
)

valset := mock.NewMockValSet()
sh := staking.NewHandler(stakingKeeper)
for i := 0; i < 100; i++ {
pubKeys[i] = secp256k1.GenPrivKey().PubKey()
addrs[i] = sdk.AccAddress(pubKeys[i].Address())

err := mintKeeper.Mint(ctx, addrs[i], sdk.NewCoin(assets.MicroLunaDenom, uLunaAmt))
if err != nil {
panic(err)
}
valConsPubKeys[i] = ed25519.GenPrivKey().PubKey()
valConsAddrs[i] = sdk.ConsAddress(valConsPubKeys[i].Address())

err = mintKeeper.Mint(ctx, addrs[i], sdk.NewCoin(assets.MicroSDRDenom, uSDRAmt))
if err != nil {
panic(err)
err2 := mintKeeper.Mint(ctx, addrs[i], sdk.NewCoin(assets.MicroLunaDenom, uLunaAmt.MulRaw(3)))
if err2 != nil {
panic(err2)
}

// Add validators
validator := mock.NewMockValidator(sdk.ValAddress(addrs[i].Bytes()), uLunaAmt)
valset.Validators = append(valset.Validators, validator)
}
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(sdk.ValAddress(addrs[i]), valConsPubKeys[i],
sdk.NewCoin(assets.MicroLunaDenom, uLunaAmt), staking.Description{}, commission, sdk.OneInt())
res := sh(ctx, msg)
if !res.IsOK() {
panic(res.Log)
}

budgetKeeper := budget.NewKeeper(
cdc, keyBudget, mintKeeper, valset,
paramsKeeper.Subspace(budget.DefaultParamspace),
)
distrKeeper.Hooks().AfterValidatorCreated(ctx, sdk.ValAddress(addrs[i]))
staking.EndBlocker(ctx, stakingKeeper)
}

oracleKeeper := oracle.NewKeeper(
cdc,
keyOracle,
valset,
mintKeeper,
distrKeeper,
feeKeeper,
stakingKeeper.GetValidatorSet(),
paramsKeeper.Subspace(oracle.DefaultParamspace),
)

marketKeeper := market.NewKeeper(oracleKeeper, mintKeeper, paramsKeeper.Subspace(market.DefaultParamspace))

feeKeeper := auth.NewFeeCollectionKeeper(
cdc, keyFee,
)

distrKeeper := distr.NewKeeper(
cdc, keyDistr, paramsKeeper.Subspace(distr.DefaultParamspace),
bankKeeper, stakingKeeper, feeKeeper, distr.DefaultCodespace,
)
marketKeeper := market.NewKeeper(
cdc,
keyMarket,
oracleKeeper,
mintKeeper,
paramsKeeper.Subspace(market.DefaultParamspace))

treasuryKeeper := treasury.NewKeeper(
cdc,
keyTreasury,
valset,
stakingKeeper.GetValidatorSet(),
mintKeeper,
marketKeeper,
distrKeeper,
feeKeeper,
paramsKeeper.Subspace(treasury.DefaultParamspace),
)

budgetKeeper := budget.NewKeeper(
cdc, keyBudget, marketKeeper, mintKeeper, treasuryKeeper, stakingKeeper.GetValidatorSet(),
paramsKeeper.Subspace(budget.DefaultParamspace),
)

budget.InitGenesis(ctx, budgetKeeper, budget.DefaultGenesisState())
oracle.InitGenesis(ctx, oracleKeeper, oracle.DefaultGenesisState())
treasury.InitGenesis(ctx, treasuryKeeper, treasury.DefaultGenesisState())
Expand Down
2 changes: 1 addition & 1 deletion x/bench/treasury_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func BenchmarkTreasuryUpdatePerEpoch(b *testing.B) {
for i := int64(0); i < int64(b.N)+probationEpoch; i++ {

input.ctx = input.ctx.WithBlockHeight(i*util.BlocksPerEpoch - 1)
input.mintKeeper.AddSeigniorage(input.ctx, uLunaAmt)
input.mintKeeper.Mint(input.ctx, addrs[0], sdk.NewCoin(assets.MicroLunaDenom, uLunaAmt))

input.treasuryKeeper.RecordTaxProceeds(input.ctx, sdk.Coins{
sdk.NewCoin(assets.MicroSDRDenom, taxAmount),
Expand Down
Loading