-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add v2.0 upgrade handler (#75)
- Loading branch information
1 parent
0fc5a9b
commit 375912d
Showing
6 changed files
with
190 additions
and
32 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,29 @@ | ||
package v200 | ||
|
||
import ( | ||
"github.com/Lorenzo-Protocol/lorenzo/app/upgrades" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func migrateAgentFromBTCStakingToAgent( | ||
ctx sdk.Context, | ||
app upgrades.AppKeepers, | ||
) error { | ||
btcStakingParams := app.BTCStakingKeeper.GetParams(ctx) | ||
for _, receiver := range btcStakingParams.Receivers { | ||
app.AgentKeeper.AddAgent( | ||
ctx, | ||
receiver.Name, | ||
receiver.Addr, receiver.EthAddr, | ||
"", | ||
"", | ||
) | ||
} | ||
// TODO: Is params.Receiver of btcstaking module removed? | ||
btcStakingParams.Receivers = nil | ||
if err := app.BTCStakingKeeper.SetParams(ctx, btcStakingParams); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,72 @@ | ||
package v200 | ||
|
||
import ( | ||
"github.com/Lorenzo-Protocol/lorenzo/app/upgrades" | ||
"github.com/Lorenzo-Protocol/lorenzo/x/agent" | ||
agenttypes "github.com/Lorenzo-Protocol/lorenzo/x/agent/types" | ||
"github.com/Lorenzo-Protocol/lorenzo/x/plan" | ||
plantypes "github.com/Lorenzo-Protocol/lorenzo/x/plan/types" | ||
"github.com/Lorenzo-Protocol/lorenzo/x/token" | ||
tokentypes "github.com/Lorenzo-Protocol/lorenzo/x/token/types" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal | ||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: "v2.0", | ||
UpgradeHandlerConstructor: upgradeHandlerConstructor, | ||
StoreUpgrades: &storetypes.StoreUpgrades{ | ||
Added: []string{ | ||
agenttypes.StoreKey, | ||
plantypes.StoreKey, | ||
tokentypes.StoreKey, | ||
}, | ||
}, | ||
} | ||
|
||
func upgradeHandlerConstructor( | ||
m *module.Manager, | ||
c module.Configurator, | ||
app upgrades.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
fromVM[agenttypes.ModuleName] = agent.AppModule{}.ConsensusVersion() | ||
fromVM[plantypes.ModuleName] = plan.AppModule{}.ConsensusVersion() | ||
fromVM[tokentypes.ModuleName] = token.AppModule{}.ConsensusVersion() | ||
|
||
// agent module init | ||
// 1. set admin | ||
admin, err := sdk.AccAddressFromBech32("lrz1xa40j022h2rcmnte47gyjg8688grln94pp84lc") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := app.AgentKeeper.SetAdmin(ctx, admin); err != nil { | ||
return nil, err | ||
} | ||
|
||
// 2. set agents | ||
if err := migrateAgentFromBTCStakingToAgent(ctx, app); err != nil { | ||
return nil, err | ||
} | ||
|
||
// plan module init | ||
planParams := plantypes.Params{ | ||
AllowList: []string{"lrz1xa40j022h2rcmnte47gyjg8688grln94pp84lc"}, | ||
} | ||
|
||
if err := app.PlanKeeper.SetParams(ctx, planParams); err != nil { | ||
return nil, err | ||
} | ||
|
||
// 3. set token params | ||
tokenParams := tokentypes.DefaultParams() | ||
app.TokenKeeper.SetParams(ctx, tokenParams) | ||
|
||
return app.ModuleManager.RunMigrations(ctx, c, fromVM) | ||
} | ||
} |
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