Skip to content

Commit

Permalink
Merge pull request #37 from chain4energy/dkruk/tokenomy-master
Browse files Browse the repository at this point in the history
Tokenomy update
  • Loading branch information
pawel-borecki authored Feb 19, 2024
2 parents 9fcc0e5 + 194ff23 commit b70330a
Show file tree
Hide file tree
Showing 25 changed files with 1,836 additions and 379 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Misc Improvements

## [v1.3.1](https://github.com/chain4energy/c4e-chain/releases/tag/v1.3.1) - 2024-02-20

**Adjustments and Financial Operations**

- decreased the vesting pool "Strategic reserve short term round pool" by 20 million C4E.
- transferred 10M C4E from the account `c4e1hcfjejmxzl8d95xka5j8cjegmf32u2lee3q422` to `c4e16n7yweagu3fxfzvay6cz035hddda7z3ntdxq3l`.
- burned all tokens in the account `c4e1hcfjejmxzl8d95xka5j8cjegmf32u2lee3q422` to leave 50M C4E remaining.

**Vesting Parameters Modification**

- modified the vesting parameters of Valdiator round pool and VC round pool from free 5%, lockup 18 months, and vesting 18 months to free 8%, lockup 4 months, and vesting 10 months.
- modified the vesting parameters of Early-bird (private) round pool lockup none, and vesting 9 months to lockup 2 months, and vesting 7 months.
- modified the vesting parameters of Public round pool lockup none, and vesting 6 months to lockup 1 month, and vesting 5 months.

**Community Pool Reduction**

- decreased the community pool from 100M C4E to 40M C4E.

## [v1.3.0](https://github.com/chain4energy/c4e-chain/releases/tag/v1.3.0) - 2023-08-21

**Upgrades**
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test-all:
$(MAKE) test-simulation-import-export SIM_NUM_BLOCKS=500 > $(RESULTS_DIR)/simulation_tests.log
@echo "--> Building docker images"
$(MAKE) docker-build-debug
$(MAKE) docker-build-v1.2.0-chain
$(MAKE) docker-build-v1.3.0-chain
@echo "--> Running e2e tests"
$(MAKE) test-e2e > $(RESULTS_DIR)/e2e_tests.log

Expand Down Expand Up @@ -163,7 +163,7 @@ open-memory-profiler-result:

PACKAGES_E2E=./tests/e2e
BUILDDIR ?= $(CURDIR)/build
E2E_UPGRADE_VERSION="v1.3.0"
E2E_UPGRADE_VERSION="v1.3.1"
E2E_SCRIPT_NAME=chain
C4E_E2E_SIGN_MODE = "direct"

Expand All @@ -185,7 +185,10 @@ test-e2e-params-change: e2e-setup
@VERSION=$(VERSION) C4E_E2E_SIGN_MODE=$(C4E_E2E_SIGN_MODE) C4E_E2E_UPGRADE_VERSION=$(E2E_UPGRADE_VERSION) C4E_E2E_DEBUG_LOG=True go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -run TestParamsChangeSuite

test-e2e-migration: e2e-setup
@VERSION=$(VERSION) C4E_E2E_SKIP_CLEANUP=True C4E_E2E_SIGN_MODE=$(C4E_E2E_SIGN_MODE) C4E_E2E_UPGRADE_VERSION=$(E2E_UPGRADE_VERSION) C4E_E2E_DEBUG_LOG=True go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -run "Test.*MainnetMigrationSuite"
@VERSION=$(VERSION) C4E_E2E_SKIP_CLEANUP=True C4E_E2E_SIGN_MODE=$(C4E_E2E_SIGN_MODE) C4E_E2E_UPGRADE_VERSION=$(E2E_UPGRADE_VERSION) C4E_E2E_DEBUG_LOG=True go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -run TestMainnetMigrationSuite

test-e2e-no-data-migration: e2e-setup
@VERSION=$(VERSION) C4E_E2E_SKIP_CLEANUP=True C4E_E2E_SIGN_MODE=$(C4E_E2E_SIGN_MODE) C4E_E2E_UPGRADE_VERSION=$(E2E_UPGRADE_VERSION) C4E_E2E_DEBUG_LOG=True go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -run TestNonMainnetMigrationSuite

test-e2e-migration-chaining: e2e-setup
@VERSION=$(VERSION) C4E_E2E_SKIP_CLEANUP=True C4E_E2E_SIGN_MODE=$(C4E_E2E_SIGN_MODE) C4E_E2E_UPGRADE_VERSION=$(E2E_UPGRADE_VERSION) C4E_E2E_DEBUG_LOG=True go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -run "Test.*MainnetMigrationChainingSuite"
Expand Down Expand Up @@ -213,6 +216,10 @@ build-e2e-script:
docker-build-debug:
@docker build -t chain4energy:debug --build-arg BASE_IMG_TAG=debug -f dockerfiles/Dockerfile .

docker-build-v1.3.0-chain:
@docker build -t chain4energy-old-chain-init:v1.3.0 --build-arg E2E_SCRIPT_NAME=chain -f dockerfiles/v1.3.0.init.Dockerfile .
@docker build -t chain4energy-old-dev:v1.3.0 --build-arg BASE_IMG_TAG=debug -f dockerfiles/v1.3.0.Dockerfile .

docker-build-v1.2.0-chain:
@docker build -t chain4energy-old-chain-init:v1.2.0 --build-arg E2E_SCRIPT_NAME=chain -f dockerfiles/v1.2.0.init.Dockerfile .
@docker build -t chain4energy-old-dev:v1.2.0 --build-arg BASE_IMG_TAG=debug -f dockerfiles/v1.2.0.Dockerfile .
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"fmt"
v130 "github.com/chain4energy/c4e-chain/app/upgrades/v130"
v131 "github.com/chain4energy/c4e-chain/app/upgrades/v131"
cfeclaimmodulekeeper "github.com/chain4energy/c4e-chain/x/cfeclaim/keeper"
cfeclaimmoduletypes "github.com/chain4energy/c4e-chain/x/cfeclaim/types"
"io"
Expand Down Expand Up @@ -207,7 +208,7 @@ var (
_ servertypes.Application = (*App)(nil)
_ simapp.App = (*App)(nil)

Upgrades = []upgrades.Upgrade{v110.Upgrade, v120.Upgrade, v130.Upgrade}
Upgrades = []upgrades.Upgrade{v110.Upgrade, v120.Upgrade, v130.Upgrade, v131.Upgrade}
)

func init() {
Expand Down
5 changes: 5 additions & 0 deletions app/app_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
cfevestingkeeper "github.com/chain4energy/c4e-chain/x/cfevesting/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
)

Expand All @@ -23,6 +24,10 @@ func (app *App) GetC4eVestingKeeper() *cfevestingkeeper.Keeper {
return &app.CfevestingKeeper
}

func (app *App) GetDistributionKeeper() *distrkeeper.Keeper {
return &app.DistrKeeper
}

func (app *App) GetParamKeeper() *paramskeeper.Keeper {
return &app.ParamsKeeper
}
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -19,6 +20,7 @@ type AppKeepers interface {
GetParamKeeper() *paramsKeeper.Keeper
GetC4eVestingKeeper() *cfevestingkeeper.Keeper
GetC4eClaimKeeper() *cfeclaimkeeper.Keeper
GetDistributionKeeper() *distributionkeeper.Keeper
}

// BaseAppParamManager defines an interrace that BaseApp is expected to fullfil
Expand Down
168 changes: 168 additions & 0 deletions app/upgrades/v131/accounts_upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package v131

import (
"cosmossdk.io/math"
cfeupgradetypes "github.com/chain4energy/c4e-chain/app/upgrades"
cfemintertypes "github.com/chain4energy/c4e-chain/x/cfeminter/types"
cfevestingtypes "github.com/chain4energy/c4e-chain/x/cfevesting/types"
sdk "github.com/cosmos/cosmos-sdk/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

const (
StrategicReservceShortTermPoolAccount = "c4e1p0smw03cwhqn05fkalfpcr0ngqv5jrpnx2cp54"
StrategicReservceShortTermPool = "Strategic reserve short term round pool"

StrategicReserveAccount = "c4e1hcfjejmxzl8d95xka5j8cjegmf32u2lee3q422"
LiquidityPoolOwner = "c4e16n7yweagu3fxfzvay6cz035hddda7z3ntdxq3l"
)

var (
liquidityPoolOwnerAccountAddress, _ = sdk.AccAddressFromBech32(LiquidityPoolOwner)
strategicReserveAccountAddress, _ = sdk.AccAddressFromBech32(StrategicReserveAccount)
)

var (
AmountToBurnFromStrategicReservePool = math.NewInt(20_000_000_000_000)

AmountToBurnFromCommunityPool = math.NewInt(60_000_000_000_000)

AmountToUnlockFromStrategicReserveAccount = math.NewInt(30_000_000_000_000)
AmountToSendToLiquidtyPoolOwner = math.NewInt(10_000_000_000_000)
AmountToBurnFromStrategicReserveAccount = math.NewInt(20_000_000_000_000)
)

func UpdateStrategicReserveShortTermPool(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers) error {
ctx.Logger().Info("updating strategic reserve short term pool")

accountVestingPools, found := appKeepers.GetC4eVestingKeeper().GetAccountVestingPools(ctx, StrategicReservceShortTermPoolAccount)
if !found {
ctx.Logger().Info("account vesting pools not found for StrategicReservceShortTermPoolAccount", "owner", StrategicReservceShortTermPoolAccount)
return nil
}

for _, pool := range accountVestingPools.VestingPools {
if pool.Name == StrategicReservceShortTermPool {
if pool.GetLockedNotReserved().Sub(AmountToBurnFromStrategicReservePool).IsNegative() {
ctx.Logger().Info("after substracting amount to burn from strategic reserve pool initially currently locked amount is negative")
return nil
}

pool.InitiallyLocked = pool.InitiallyLocked.Sub(AmountToBurnFromStrategicReservePool)

if err := burnCoinsFromAnyModule(ctx, appKeepers, cfevestingtypes.ModuleName, AmountToBurnFromStrategicReservePool); err != nil {
ctx.Logger().Error("send and burn coins from module error", "err", err)
return err
}

appKeepers.GetC4eVestingKeeper().SetAccountVestingPools(ctx, accountVestingPools)
ctx.Logger().Info("strategic reserve short term pool updated")
return nil
}
}

ctx.Logger().Info("strategic reserve short term pool not found", "owner", StrategicReservceShortTermPoolAccount)
return nil
}

func UpdateStrategicReserveAccount(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers) error {
ctx.Logger().Info("updating strategic reserve account")

strategicReserveAccount := appKeepers.GetAccountKeeper().GetAccount(ctx, strategicReserveAccountAddress)
if strategicReserveAccount == nil {
ctx.Logger().Info("strategic reserve account not found", "address", strategicReserveAccountAddress)
return nil
}

vestingAccount, ok := strategicReserveAccount.(*vestingtypes.ContinuousVestingAccount)
if !ok {
ctx.Logger().Info("strategic reserve account is not of *vestingtypes.ContinuousVestingAccount type")
return nil
}

denom := appKeepers.GetC4eVestingKeeper().Denom(ctx)
coinsToUnlockFromStrategicReserveAccount := sdk.NewCoins(sdk.NewCoin(denom, AmountToUnlockFromStrategicReserveAccount))
lockedCoins := vestingAccount.LockedCoins(ctx.BlockTime())
if !coinsToUnlockFromStrategicReserveAccount.IsAllLTE(lockedCoins) {
ctx.Logger().Debug("unlock unbonded continuous vesting account coins - not enough to unlock", "lockedCoins", lockedCoins, "coinsToUnlockFromStrategicReserveAccount", coinsToUnlockFromStrategicReserveAccount)
return nil
}

_, err := appKeepers.GetC4eVestingKeeper().UnlockUnbondedContinuousVestingAccountCoins(ctx,
strategicReserveAccountAddress,
coinsToUnlockFromStrategicReserveAccount,
)
if err != nil {
ctx.Logger().Error("unlock unbonded continuous vesting account coins error", "err", err)
return err
}

coinsToSendToLiquidityPoolOwner := sdk.NewCoins(sdk.NewCoin(denom, AmountToSendToLiquidtyPoolOwner))
err = bankkeeper.Keeper.SendCoins(*appKeepers.GetBankKeeper(), ctx, strategicReserveAccountAddress, liquidityPoolOwnerAccountAddress, coinsToSendToLiquidityPoolOwner)
if err != nil {
ctx.Logger().Error("send coins error", "err", err)
return err
}

coinsToBurnFromStrategicReserveAccount := sdk.NewCoins(sdk.NewCoin(denom, AmountToBurnFromStrategicReserveAccount))
if err = bankkeeper.Keeper.SendCoinsFromAccountToModule(
*appKeepers.GetBankKeeper(),
ctx,
strategicReserveAccountAddress,
cfemintertypes.ModuleName,
coinsToBurnFromStrategicReserveAccount,
); err != nil {
ctx.Logger().Error("send coins from account to module error", "err", err)
return err
}

return bankkeeper.Keeper.BurnCoins(*appKeepers.GetBankKeeper(), ctx, cfemintertypes.ModuleName, coinsToBurnFromStrategicReserveAccount)
}

func UpdateCommunityPool(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers) error {
ctx.Logger().Info("updating community pool")
feePool := appKeepers.GetDistributionKeeper().GetFeePool(ctx)
communityPoolBefore := feePool.CommunityPool

denom := appKeepers.GetC4eVestingKeeper().Denom(ctx)

if communityPoolBefore.AmountOf(denom).LTE(sdk.NewDecFromInt(AmountToBurnFromCommunityPool)) {
ctx.Logger().Info("community pool amount before migration was lower or equal to community pool new amount")
return nil
}

coinsToBurnFromCommunityPool := sdk.NewCoins(sdk.NewCoin(appKeepers.GetC4eVestingKeeper().Denom(ctx), AmountToBurnFromCommunityPool))
if err := appKeepers.GetDistributionKeeper().DistributeFromFeePool(ctx, coinsToBurnFromCommunityPool, liquidityPoolOwnerAccountAddress); err != nil {
ctx.Logger().Error("distribute from fee pool error", "err", err)
return err
}

if err := bankkeeper.Keeper.SendCoinsFromAccountToModule(
*appKeepers.GetBankKeeper(),
ctx,
liquidityPoolOwnerAccountAddress,
cfemintertypes.ModuleName,
coinsToBurnFromCommunityPool,
); err != nil {
ctx.Logger().Error("send coins from account to module error", "err", err)
return err
}

return bankkeeper.Keeper.BurnCoins(*appKeepers.GetBankKeeper(), ctx, cfemintertypes.ModuleName, coinsToBurnFromCommunityPool)
}

func burnCoinsFromAnyModule(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers, fromModule string, amount math.Int) error {
denom := appKeepers.GetC4eVestingKeeper().Denom(ctx)
coins := sdk.NewCoins(sdk.NewCoin(denom, amount))

if err := bankkeeper.Keeper.SendCoinsFromModuleToModule(*appKeepers.GetBankKeeper(), ctx, fromModule, cfemintertypes.ModuleName, coins); err != nil {
ctx.Logger().Error("send coins from module to module error", "err", err)
return err
}
if err := bankkeeper.Keeper.BurnCoins(*appKeepers.GetBankKeeper(), ctx, cfemintertypes.ModuleName, coins); err != nil {
ctx.Logger().Error("burn coins error", "err", err)
return err
}
return nil
}
Loading

0 comments on commit b70330a

Please sign in to comment.