-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] added bedrock distribution for master wallet (#1390)
* [feat] added bedrock distribution for master wallet * [feat] registered upgrade in app * [fix] updated naming convention for upgrades * [new] added readme in upgrade * [fix] minnor fix readme.md upgrade
- Loading branch information
1 parent
f70432c
commit 8eff3b5
Showing
7 changed files
with
237 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Pylons Upgrades | ||
|
||
This folder contains sub-folders for every pylons upgrade. It also defines upgrade structs, | ||
that each upgrade implements. These then get included in the application | ||
`app.go` to run the upgrade. | ||
|
||
## Version History | ||
|
||
- v3 - migration to cosmos SDK v46 | ||
- v4 - Pre-Mainnet Upgrade | ||
- v5 - Mainnet Upgrade | ||
|
||
## Upgrade types | ||
|
||
Upgrade defines a struct containing necessary fields that a `SoftwareUpgradeProposal` | ||
must have written, in order for the state migration to go smoothly. | ||
An upgrade must implement this `upgrade struct`, and then set it in the `app.go`. | ||
The `app.go` will then define the `upgrade handler`. | ||
|
||
```go | ||
type Upgrade struct { | ||
// Upgrade version name, for the upgrade handler, e.g. `v7` | ||
UpgradeName string | ||
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. | ||
StoreUpgrades storetypes.StoreUpgrades | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package v5 | ||
|
||
import ( | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/Pylons-tech/pylons/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName is the shared upgrade plan name for mainnet and testnet | ||
UpgradeName = "v1.1.0" | ||
) | ||
|
||
// TODO: Update StoreUpgrades | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{}, | ||
Deleted: []string{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package v5 | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
"github.com/Pylons-tech/pylons/x/pylons/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"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" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
const ( | ||
// Master Wallet address | ||
MasterWallet = "pylo1vnwhaymaazugzz9ln2sznddveyed6shz3x8xwl" | ||
) | ||
|
||
var ( | ||
TotalUbedrock = math.NewIntFromUint64(1_000_000_000_000_000) // 1 bedrock = 1_000_000 ubedrock | ||
MasterWalletbalance = math.NewIntFromUint64(1e15) | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
bankKeeper bankkeeper.Keeper, | ||
accKeeper *authkeeper.AccountKeeper, | ||
staking *stakingkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
// logger := ctx.Logger() | ||
|
||
if types.IsMainnet(ctx.ChainID()) { | ||
|
||
bankBaseKeeper, _ := bankKeeper.(bankkeeper.BaseKeeper) | ||
BurnToken(ctx, accKeeper, &bankBaseKeeper, staking) | ||
MintUbedrockForInitialAccount(ctx, &bankBaseKeeper, staking) | ||
} | ||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} | ||
|
||
// Burn stripeUSD denom token | ||
func BurnToken(ctx sdk.Context, accKeeper *authkeeper.AccountKeeper, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) { | ||
// only burn stripe usd token | ||
denom := types.StripeCoinDenom | ||
// Get all account balances | ||
accs := bank.GetAccountsBalances(ctx) | ||
for _, acc := range accs { | ||
balance := acc.Coins.AmountOf(denom) | ||
// Check if denom token amount GT 0 | ||
if balance.GT(math.ZeroInt()) { | ||
amount := sdk.NewCoin(denom, balance) | ||
// Send denom token to module | ||
err := bank.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32(acc.Address), types.PaymentsProcessorName, sdk.NewCoins(amount)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// Burn denom token in module | ||
err = bank.BurnCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(amount)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Mint ubedrock for master wallet | ||
func MintUbedrockForInitialAccount(ctx sdk.Context, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) { | ||
// Get currect balance of master wallet address | ||
balance := bank.GetBalance(ctx, sdk.MustAccAddressFromBech32(MasterWallet), types.StakingCoinDenom) | ||
|
||
// check difference in amount to add | ||
toAdd := MasterWalletbalance.Sub(balance.Amount) | ||
|
||
// Mint coin for module | ||
err := bank.MintCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd))) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// Send coin required to meet master wallet balance from module to account | ||
err = bank.SendCoinsFromModuleToAccount( | ||
ctx, | ||
types.PaymentsProcessorName, | ||
sdk.MustAccAddressFromBech32(MasterWallet), | ||
sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd)), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package v5_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
"github.com/Pylons-tech/pylons/app/apptesting" | ||
v5 "github.com/Pylons-tech/pylons/app/upgrades/v5" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
var ( | ||
stakingCoinDenom string = "ubedrock" | ||
stripeCoinDenom string = "ustripeusd" | ||
defaultAcctFundsStripeCoin sdk.Coins = sdk.NewCoins( | ||
sdk.NewCoin(stripeCoinDenom, sdk.NewInt(10_000_000)), | ||
) | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
s := new(UpgradeTestSuite) | ||
suite.Run(t, s) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestBurnToken_Ustripeusd() { | ||
suite.Setup() | ||
// Fund Ustripeusd to test account | ||
for _, acc := range suite.TestAccs { | ||
suite.FundAcc(acc, defaultAcctFundsStripeCoin) | ||
} | ||
// Get Ustripeusd total supply | ||
totalAmount := suite.App.BankKeeper.GetSupply(suite.Ctx, stripeCoinDenom) | ||
suite.Require().Equal(totalAmount.Amount, math.NewInt(30_000_000)) | ||
// Burn Ustripeusd | ||
bankBaseKeeper, _ := suite.App.BankKeeper.(bankkeeper.BaseKeeper) | ||
v5.BurnToken(suite.Ctx, &suite.App.AccountKeeper, &bankBaseKeeper, &suite.App.StakingKeeper) | ||
// Check Ustripeusd total supply (should equal 0) | ||
totalAmount = suite.App.BankKeeper.GetSupply(suite.Ctx, stripeCoinDenom) | ||
suite.Require().Equal(totalAmount.Amount, math.ZeroInt()) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestMintUbedrockForInitialAccount() { | ||
suite.Setup() | ||
// Burn ubedrock | ||
bankBaseKeeper, _ := suite.App.BankKeeper.(bankkeeper.BaseKeeper) | ||
// Mint ubedrock for initial account | ||
v5.MintUbedrockForInitialAccount(suite.Ctx, &bankBaseKeeper, &suite.App.StakingKeeper) | ||
// Check token in all initial account | ||
accAmount := suite.App.BankKeeper.GetBalance(suite.Ctx, sdk.MustAccAddressFromBech32(v5.MasterWallet), stakingCoinDenom) | ||
suite.Require().Equal(accAmount.Amount, v5.MasterWalletbalance) | ||
} |