Skip to content

Commit 8eff3b5

Browse files
[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
1 parent f70432c commit 8eff3b5

7 files changed

Lines changed: 237 additions & 31 deletions

File tree

app/app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Pylons-tech/pylons/app/upgrades"
1313
v3 "github.com/Pylons-tech/pylons/app/upgrades/v3"
1414
v4 "github.com/Pylons-tech/pylons/app/upgrades/v4"
15+
v5 "github.com/Pylons-tech/pylons/app/upgrades/v5"
1516

1617
storetypes "github.com/cosmos/cosmos-sdk/store/types"
1718
"github.com/cosmos/cosmos-sdk/version"
@@ -821,6 +822,11 @@ func (app *PylonsApp) setupUpgradeHandlers() {
821822
v4.UpgradeName,
822823
v4.CreateUpgradeHandler(app.mm, app.configurator, app.BankKeeper, &app.AccountKeeper, &app.StakingKeeper, &app.PylonsKeeper),
823824
)
825+
// v1.1.0 mainnet upgrade handler
826+
app.UpgradeKeeper.SetUpgradeHandler(
827+
v5.UpgradeName,
828+
v5.CreateUpgradeHandler(app.mm, app.configurator, app.BankKeeper, &app.AccountKeeper, &app.StakingKeeper),
829+
)
824830
}
825831

826832
func (app *PylonsApp) setupUpgradeStoreLoaders() {

app/apptesting/test_suite.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package apptesting
22

33
import (
4+
"fmt"
5+
"strconv"
46
"time"
57

68
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -18,6 +20,7 @@ import (
1820
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
1921

2022
"github.com/Pylons-tech/pylons/app"
23+
"github.com/Pylons-tech/pylons/x/pylons/types"
2124
)
2225

2326
type KeeperTestHelper struct {
@@ -115,3 +118,28 @@ func CreateRandomAccounts(numAccts int) []sdk.AccAddress {
115118

116119
return testAddrs
117120
}
121+
122+
// set up googleIAPOder
123+
func (s *KeeperTestHelper) SetUpGoogleIAPOrder(ctx sdk.Context, n int, productID string) []types.GoogleInAppPurchaseOrder {
124+
items := make([]types.GoogleInAppPurchaseOrder, n)
125+
creators := types.GenTestBech32List(n)
126+
for i := range items {
127+
items[i].Creator = creators[i]
128+
items[i].PurchaseToken = strconv.Itoa(i)
129+
items[i].ProductId = productID
130+
s.App.PylonsKeeper.AppendGoogleIAPOrder(ctx, items[i])
131+
}
132+
return items
133+
}
134+
135+
// set up test addresses
136+
func (s *KeeperTestHelper) SetUpTestAddrs(n int) []sdk.AccAddress {
137+
testAddrs := make([]sdk.AccAddress, n)
138+
for id := range testAddrs {
139+
testAcc := types.GenTestBech32FromString(fmt.Sprint(id))
140+
testAddr, err := sdk.AccAddressFromBech32(testAcc)
141+
s.Require().NoError(err)
142+
testAddrs[id] = testAddr
143+
}
144+
return testAddrs
145+
}

app/upgrades/Readme.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Pylons Upgrades
2+
3+
This folder contains sub-folders for every pylons upgrade. It also defines upgrade structs,
4+
that each upgrade implements. These then get included in the application
5+
`app.go` to run the upgrade.
6+
7+
## Version History
8+
9+
- v3 - migration to cosmos SDK v46
10+
- v4 - Pre-Mainnet Upgrade
11+
- v5 - Mainnet Upgrade
12+
13+
## Upgrade types
14+
15+
Upgrade defines a struct containing necessary fields that a `SoftwareUpgradeProposal`
16+
must have written, in order for the state migration to go smoothly.
17+
An upgrade must implement this `upgrade struct`, and then set it in the `app.go`.
18+
The `app.go` will then define the `upgrade handler`.
19+
20+
```go
21+
type Upgrade struct {
22+
// Upgrade version name, for the upgrade handler, e.g. `v7`
23+
UpgradeName string
24+
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
25+
StoreUpgrades storetypes.StoreUpgrades
26+
}
27+
```

app/upgrades/v4/upgrades_test.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v4_test
22

33
import (
44
"fmt"
5-
"strconv"
65
"testing"
76

87
"cosmossdk.io/math"
@@ -135,8 +134,8 @@ func (suite *UpgradeTestSuite) TestCleanUpylons() {
135134
amountOfCoinsTest := sdk.NewCoins(sdk.NewCoin(types.PylonsCoinDenom, sdk.NewInt(10_000_000)))
136135

137136
//create Google IAP order and test addresses
138-
items := suite.setUpGoogleIAPOrder(suite.Ctx, 2, productID)
139-
testAddrs := suite.setUpTestAddrs(5)
137+
items := suite.SetUpGoogleIAPOrder(suite.Ctx, 2, productID)
138+
testAddrs := suite.SetUpTestAddrs(5)
140139

141140
for _, tc := range []struct {
142141
desc string
@@ -186,40 +185,15 @@ func (suite *UpgradeTestSuite) TestCleanUpylons() {
186185
}
187186
}
188187

189-
// set up googleIAPOder
190-
func (suite *UpgradeTestSuite) setUpGoogleIAPOrder(ctx sdk.Context, n int, productID string) []types.GoogleInAppPurchaseOrder {
191-
items := make([]types.GoogleInAppPurchaseOrder, n)
192-
creators := types.GenTestBech32List(n)
193-
for i := range items {
194-
items[i].Creator = creators[i]
195-
items[i].PurchaseToken = strconv.Itoa(i)
196-
items[i].ProductId = productID
197-
suite.App.PylonsKeeper.AppendGoogleIAPOrder(ctx, items[i])
198-
}
199-
return items
200-
}
201-
202-
// set up test addresses
203-
func (suite *UpgradeTestSuite) setUpTestAddrs(n int) []sdk.AccAddress {
204-
testAddrs := make([]sdk.AccAddress, n)
205-
for id := range testAddrs {
206-
testAcc := types.GenTestBech32FromString(fmt.Sprint(id))
207-
testAddr, err := sdk.AccAddressFromBech32(testAcc)
208-
suite.Require().NoError(err)
209-
testAddrs[id] = testAddr
210-
}
211-
return testAddrs
212-
}
213-
214188
func (suite *UpgradeTestSuite) TestRefundIAPNFTBUY() {
215189
// run iap nft buy refund
216190
suite.Setup()
217191
productID := "pylons_10"
218192
amountValid := 10_000_000
219193
amountOfCoinsTest := sdk.NewCoins(sdk.NewCoin(types.PylonsCoinDenom, sdk.NewInt(10_000_000)))
220194
// create Google IAP order and test addresses
221-
items := suite.setUpGoogleIAPOrder(suite.Ctx, 2, productID)
222-
testAddrs := suite.setUpTestAddrs(5)
195+
items := suite.SetUpGoogleIAPOrder(suite.Ctx, 2, productID)
196+
testAddrs := suite.SetUpTestAddrs(5)
223197

224198
// create a cookbook
225199
creator := testAddrs[0]
@@ -358,7 +332,7 @@ func (suite *UpgradeTestSuite) TestRefundIAPNFTBUY() {
358332
func (suite *UpgradeTestSuite) TestRefundLuxFloralis() {
359333
suite.Setup()
360334
// Make recipe executions records
361-
testAddrs := suite.setUpTestAddrs(5)
335+
testAddrs := suite.SetUpTestAddrs(5)
362336
creator := testAddrs[0]
363337
amountValid := int64(10_000_000)
364338

app/upgrades/v5/constants.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package v5
2+
3+
import (
4+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
5+
6+
"github.com/Pylons-tech/pylons/app/upgrades"
7+
)
8+
9+
const (
10+
// UpgradeName is the shared upgrade plan name for mainnet and testnet
11+
UpgradeName = "v1.1.0"
12+
)
13+
14+
// TODO: Update StoreUpgrades
15+
16+
var Upgrade = upgrades.Upgrade{
17+
UpgradeName: UpgradeName,
18+
StoreUpgrades: storetypes.StoreUpgrades{
19+
Added: []string{},
20+
Deleted: []string{},
21+
},
22+
}

app/upgrades/v5/upgrades.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package v5
2+
3+
import (
4+
"cosmossdk.io/math"
5+
"github.com/Pylons-tech/pylons/x/pylons/types"
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/cosmos/cosmos-sdk/types/module"
8+
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
9+
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
10+
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
11+
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
12+
)
13+
14+
const (
15+
// Master Wallet address
16+
MasterWallet = "pylo1vnwhaymaazugzz9ln2sznddveyed6shz3x8xwl"
17+
)
18+
19+
var (
20+
TotalUbedrock = math.NewIntFromUint64(1_000_000_000_000_000) // 1 bedrock = 1_000_000 ubedrock
21+
MasterWalletbalance = math.NewIntFromUint64(1e15)
22+
)
23+
24+
func CreateUpgradeHandler(
25+
mm *module.Manager,
26+
configurator module.Configurator,
27+
bankKeeper bankkeeper.Keeper,
28+
accKeeper *authkeeper.AccountKeeper,
29+
staking *stakingkeeper.Keeper,
30+
) upgradetypes.UpgradeHandler {
31+
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
32+
// logger := ctx.Logger()
33+
34+
if types.IsMainnet(ctx.ChainID()) {
35+
36+
bankBaseKeeper, _ := bankKeeper.(bankkeeper.BaseKeeper)
37+
BurnToken(ctx, accKeeper, &bankBaseKeeper, staking)
38+
MintUbedrockForInitialAccount(ctx, &bankBaseKeeper, staking)
39+
}
40+
return mm.RunMigrations(ctx, configurator, fromVM)
41+
}
42+
}
43+
44+
// Burn stripeUSD denom token
45+
func BurnToken(ctx sdk.Context, accKeeper *authkeeper.AccountKeeper, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) {
46+
// only burn stripe usd token
47+
denom := types.StripeCoinDenom
48+
// Get all account balances
49+
accs := bank.GetAccountsBalances(ctx)
50+
for _, acc := range accs {
51+
balance := acc.Coins.AmountOf(denom)
52+
// Check if denom token amount GT 0
53+
if balance.GT(math.ZeroInt()) {
54+
amount := sdk.NewCoin(denom, balance)
55+
// Send denom token to module
56+
err := bank.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32(acc.Address), types.PaymentsProcessorName, sdk.NewCoins(amount))
57+
if err != nil {
58+
panic(err)
59+
}
60+
// Burn denom token in module
61+
err = bank.BurnCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(amount))
62+
if err != nil {
63+
panic(err)
64+
}
65+
}
66+
}
67+
}
68+
69+
// Mint ubedrock for master wallet
70+
func MintUbedrockForInitialAccount(ctx sdk.Context, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) {
71+
// Get currect balance of master wallet address
72+
balance := bank.GetBalance(ctx, sdk.MustAccAddressFromBech32(MasterWallet), types.StakingCoinDenom)
73+
74+
// check difference in amount to add
75+
toAdd := MasterWalletbalance.Sub(balance.Amount)
76+
77+
// Mint coin for module
78+
err := bank.MintCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd)))
79+
if err != nil {
80+
panic(err)
81+
}
82+
// Send coin required to meet master wallet balance from module to account
83+
err = bank.SendCoinsFromModuleToAccount(
84+
ctx,
85+
types.PaymentsProcessorName,
86+
sdk.MustAccAddressFromBech32(MasterWallet),
87+
sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd)),
88+
)
89+
if err != nil {
90+
panic(err)
91+
}
92+
}

app/upgrades/v5/upgrades_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package v5_test
2+
3+
import (
4+
"testing"
5+
6+
"cosmossdk.io/math"
7+
"github.com/Pylons-tech/pylons/app/apptesting"
8+
v5 "github.com/Pylons-tech/pylons/app/upgrades/v5"
9+
sdk "github.com/cosmos/cosmos-sdk/types"
10+
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
11+
"github.com/stretchr/testify/suite"
12+
)
13+
14+
var (
15+
stakingCoinDenom string = "ubedrock"
16+
stripeCoinDenom string = "ustripeusd"
17+
defaultAcctFundsStripeCoin sdk.Coins = sdk.NewCoins(
18+
sdk.NewCoin(stripeCoinDenom, sdk.NewInt(10_000_000)),
19+
)
20+
)
21+
22+
type UpgradeTestSuite struct {
23+
apptesting.KeeperTestHelper
24+
}
25+
26+
func TestUpgradeTestSuite(t *testing.T) {
27+
s := new(UpgradeTestSuite)
28+
suite.Run(t, s)
29+
}
30+
31+
func (suite *UpgradeTestSuite) TestBurnToken_Ustripeusd() {
32+
suite.Setup()
33+
// Fund Ustripeusd to test account
34+
for _, acc := range suite.TestAccs {
35+
suite.FundAcc(acc, defaultAcctFundsStripeCoin)
36+
}
37+
// Get Ustripeusd total supply
38+
totalAmount := suite.App.BankKeeper.GetSupply(suite.Ctx, stripeCoinDenom)
39+
suite.Require().Equal(totalAmount.Amount, math.NewInt(30_000_000))
40+
// Burn Ustripeusd
41+
bankBaseKeeper, _ := suite.App.BankKeeper.(bankkeeper.BaseKeeper)
42+
v5.BurnToken(suite.Ctx, &suite.App.AccountKeeper, &bankBaseKeeper, &suite.App.StakingKeeper)
43+
// Check Ustripeusd total supply (should equal 0)
44+
totalAmount = suite.App.BankKeeper.GetSupply(suite.Ctx, stripeCoinDenom)
45+
suite.Require().Equal(totalAmount.Amount, math.ZeroInt())
46+
}
47+
48+
func (suite *UpgradeTestSuite) TestMintUbedrockForInitialAccount() {
49+
suite.Setup()
50+
// Burn ubedrock
51+
bankBaseKeeper, _ := suite.App.BankKeeper.(bankkeeper.BaseKeeper)
52+
// Mint ubedrock for initial account
53+
v5.MintUbedrockForInitialAccount(suite.Ctx, &bankBaseKeeper, &suite.App.StakingKeeper)
54+
// Check token in all initial account
55+
accAmount := suite.App.BankKeeper.GetBalance(suite.Ctx, sdk.MustAccAddressFromBech32(v5.MasterWallet), stakingCoinDenom)
56+
suite.Require().Equal(accAmount.Amount, v5.MasterWalletbalance)
57+
}

0 commit comments

Comments
 (0)