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

feat: ASI genesis update cmd #341

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
459bf08
feat: initial empty command
Jonathansumner Apr 16, 2024
7f4f616
feat: chain-id replacement
Jonathansumner Apr 16, 2024
9e5b0fa
chore: add placeholder for bridge admin replacement func
Jonathansumner Apr 18, 2024
8811a9f
fix: use correct bech32 charset
Jonathansumner Apr 18, 2024
22f1b62
feat: asi address replacement (#343)
Jonathansumner Apr 18, 2024
2730a94
feat: asi denom replacement (#342)
Jonathansumner Apr 18, 2024
4f5840e
feat: asi bridge admin replacement (#346)
Jonathansumner Apr 19, 2024
07ff5ac
feat: asi ibc transfer (#345)
Jonathansumner Apr 19, 2024
56c43a1
feat: asi reconcilliation transfer (#344)
Jonathansumner Apr 19, 2024
a8bec75
chore:: add reconciliation data
Jonathansumner Apr 19, 2024
f1548fd
chore: tidying
Jonathansumner Apr 19, 2024
a6aa152
fix: update denom_metadata after general denom replacement
Jonathansumner Apr 22, 2024
35171c0
Merge branch 'master' into feat/aasi-merger-cmd
pbukva May 15, 2024
bfbf0a8
feat: testnet support (#349)
Jonathansumner May 16, 2024
99c8d7d
feat: ASI upgrade manifest (#350)
pbukva May 16, 2024
abd5375
fix: initial fixes from merge
Jonathansumner May 16, 2024
1efe7db
feat: ASI supply replacement (#347)
Jonathansumner May 17, 2024
35e4419
feat: ASI alamanac state replacement (#352)
Jonathansumner May 20, 2024
3e6b6a7
feat: ASI manifest (#353)
Jonathansumner May 22, 2024
76a6d67
feat: ASI mobix staking replacement (#348)
Jonathansumner May 22, 2024
e5b4eb4
feat: replace FCC cw20 states (#357)
Jonathansumner May 24, 2024
fd3bb91
feat: ASI replace FCC issuance contract state (#356)
Jonathansumner May 24, 2024
942d2ea
fix: replace contract state properly
Jonathansumner May 28, 2024
99a70d8
fix: ASI test tweaks (#359)
Jonathansumner May 29, 2024
a063eb8
Merge branch 'master' into feat/aasi-merger-cmd
pbukva May 31, 2024
0aa282b
Add support for reconciliation on testnet (#360)
pbukva May 31, 2024
beea039
feat: ASI reconciliation contract replacement (#361)
Jonathansumner May 31, 2024
cf72086
Mobix staking - support for multiple contracts (#362)
pbukva May 31, 2024
483789e
feat: implement the genesis-time flag (#363)
Jonathansumner Jun 6, 2024
cac7411
Reconciliation: Support for contract admin update (#364)
pbukva Jun 6, 2024
f6f9920
chore: add network parameters to manifest file (#367)
Jonathansumner Jun 7, 2024
fe9f811
Reconciliation contract: Full state instantiation (#365)
pbukva Jun 11, 2024
bdfc0b6
chore: asi manifest restructure (#368)
Jonathansumner Jun 13, 2024
00bbb69
Merge branch 'master' into feat/aasi-merger-cmd
pbukva Jun 14, 2024
5e93edd
Merge branch 'master' into feat/aasi-merger-cmd
pbukva Jun 14, 2024
d47452c
Merge branch 'master' into feat/aasi-merger-cmd
pbukva Jun 14, 2024
1bc7ecf
feat: Removing unnecessary software upgrade handlers (#370)
pbukva Jun 17, 2024
e2e058e
Use RFC3339Nano timestamp format in manifest mains section (#373)
pbukva Jun 17, 2024
7dd075e
Removing legacy reconciliation code (#379)
pbukva Jun 28, 2024
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
90 changes: 1 addition & 89 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func New(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)

Expand Down Expand Up @@ -719,94 +719,6 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
}

func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
const municipalInflationTargetAddress = "fetch1n8d5466h8he33uedc0vsgtahal0mrz55glre03"

// NOTE(pb): The `fetchd-v0.10.7` upgrade handler *MUST* be present due to the mainnent, where this is the *LAST*
// executed upgrade. Presence of this handler is enforced by the `x/upgrade/abci.go#L31-L40` (see the
// https://github.com/fetchai/cosmos-sdk/blob/09cf7baf4297a30acd8d09d9db7dd97d79ffe008/x/upgrade/abci.go#L31-L40).
app.UpgradeKeeper.SetUpgradeHandler("fetchd-v0.10.7", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, cfg, fromVM)
})

// NOTE(pb): The `v0.11.2` upgrade handler *MUST* be present due to Dorado-1 testnet, where this is the *LAST*
// executed upgrade. Please see the details in the NOTE above.
app.UpgradeKeeper.SetUpgradeHandler("v0.11.2", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
mobixInfl, err := sdk.NewDecFromStr("0.03")
if err != nil {
return module.VersionMap{}, err
}
minter := app.MintKeeper.GetMinter(ctx)
minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{
{Denom: "nanomobx", Inflation: minttypes.NewMunicipalInflation(municipalInflationTargetAddress, mobixInfl)},
}

app.MintKeeper.SetMinter(ctx, minter)

return app.mm.RunMigrations(ctx, cfg, fromVM)
})

app.UpgradeKeeper.SetUpgradeHandler("v0.11.3", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Introducing the NOMX token **IF** it does not exist yet:
const nomxDenom = "nanonomx"
const nomxName = "NOMX"
const nomxSupply = 1000000000000000000 // = 10^18 < 2^63 (max(int64))
if !app.BankKeeper.HasSupply(ctx, nomxDenom) {
coinsToMint := sdk.NewCoins(sdk.NewInt64Coin(nomxDenom, nomxSupply))
app.MintKeeper.MintCoins(ctx, coinsToMint)

acc, err := sdk.AccAddressFromBech32(municipalInflationTargetAddress)
if err != nil {
panic(err)
}

err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc, coinsToMint)
if err != nil {
panic(err)
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
minttypes.EventTypeMunicipalMint,
sdk.NewAttribute(minttypes.AttributeKeyDenom, nomxDenom),
sdk.NewAttribute(minttypes.AttributeKeyTargetAddr, municipalInflationTargetAddress),
sdk.NewAttribute(sdk.AttributeKeyAmount, coinsToMint.String()),
),
)

nomxMetadata := banktypes.Metadata{
Base: nomxDenom,
Name: nomxName,
Symbol: nomxName,
Display: nomxName,
Description: nomxName + " token",
DenomUnits: []*banktypes.DenomUnit{
{Denom: nomxName, Exponent: 9, Aliases: nil},
{Denom: "mnomx", Exponent: 6, Aliases: nil},
{Denom: "unomx", Exponent: 3, Aliases: nil},
{Denom: nomxDenom, Exponent: 0, Aliases: nil},
},
}

app.BankKeeper.SetDenomMetaData(ctx, nomxMetadata)
}

// Municipal Inflation for MOBX & NOMX tokens:
inflation, err := sdk.NewDecFromStr("0.03")
if err != nil {
return module.VersionMap{}, err
}

minter := app.MintKeeper.GetMinter(ctx)
municipalInflation := minttypes.NewMunicipalInflation(municipalInflationTargetAddress, inflation)
minter.MunicipalInflation = []*minttypes.MunicipalInflationPair{
{Denom: "nanomobx", Inflation: municipalInflation},
{Denom: nomxDenom, Inflation: municipalInflation},
}

app.MintKeeper.SetMinter(ctx, minter)

return app.mm.RunMigrations(ctx, cfg, fromVM)
})
}

// RegisterAPIRoutes registers all application module routes with the provided
Expand Down
2 changes: 1 addition & 1 deletion app/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
AccountAddressPrefix = "fetch"
AccountAddressPrefix = "asi"
)

var (
Expand Down
118 changes: 118 additions & 0 deletions cmd/fetchd/cmd/gen_asi_upgrade_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package cmd

import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/types"
config2 "github.com/tendermint/tendermint/config"
"os"
"path"
)

type ASIUpgradeIBCTransfer struct {
From string `json:"from"`
ChannelID string `json:"channel_id"`
Amount types.Coins `json:"amount"`
}

type ASIUpgradeIBCTransfers struct {
Transfers []ASIUpgradeIBCTransfer `json:"transfer"`
To string `json:"to"`
AggregatedTransferredAmount types.Coins `json:"aggregated_transferred_amount"`
NumberOfTransfers int `json:"number_of_transfers"`
}

type ASIUpgradeReconciliationTransfer struct {
From string `json:"from"`
EthAddr string `json:"eth_addr"`
Amount types.Coins `json:"amount"`
}

type ASIUpgradeReconciliationTransfers struct {
Transfers []ASIUpgradeReconciliationTransfer `json:"transfers"`
To string `json:"to"`
AggregatedTransferredAmount types.Coins `json:"aggregated_transferred_amount"`
NumberOfTransfers int `json:"number_of_transfers"`
}

type ASIUpgradeReconciliationContractStateBalanceRecord struct {
EthAddr string `json:"eth_addr"`
Balances types.Coins `json:"balances"`
}

type ASIUpgradeReconciliationContractState struct {
Balances []ASIUpgradeReconciliationContractStateBalanceRecord `json:"balances"`
AggregatedBalancesAmount types.Coins `json:"aggregated_balances_amount"`
NumberOfBalanceRecords int `json:"number_of_balance_records"`
}

func NewASIUpgradeReconciliationContractState() *ASIUpgradeReconciliationContractState {
return &ASIUpgradeReconciliationContractState{
Balances: make([]ASIUpgradeReconciliationContractStateBalanceRecord, 0),
}
}

type ASIUpgradeReconciliation struct {
Transfers ASIUpgradeReconciliationTransfers `json:"transfers"`
ContractState *ASIUpgradeReconciliationContractState `json:"contract_state"`
}

type ASIUpgradeSupply struct {
LandingAddress string `json:"landing_address"`
MintedAmount types.Coins `json:"minted_amount"`
ResultingTotalSupply types.Coins `json:"resulting_total_supply"`
}

type ContractValueUpdate struct {
Address string `json:"address"`
From string `json:"from"`
To string `json:"to"`
}

type ValueUpdate struct {
From string `json:"from"`
To string `json:"to"`
}

type NetworkParams struct {
GenesisTime *ValueUpdate `json:"genesis_time,omitempty"`
ChainID *ValueUpdate `json:"chain_id,omitempty"`
AddressPrefix *ValueUpdate `json:"address_prefix,omitempty"`
Supply *ASIUpgradeSupply `json:"supply,omitempty"`
}

type Contracts struct {
StateCleaned []string `json:"contracts_state_cleaned,omitempty"`
AdminUpdated []ContractValueUpdate `json:"contracts_admin_updated,omitempty"`
LabelUpdated []ContractValueUpdate `json:"contracts_label_updated,omitempty"`
}

type ASIUpgradeManifest struct {
Network *NetworkParams `json:"network,omitempty"`
IBC *ASIUpgradeIBCTransfers `json:"ibc,omitempty"`
Reconciliation *ASIUpgradeReconciliation `json:"reconciliation,omitempty"`
Contracts *Contracts `json:"contracts,omitempty"`
}

func SaveASIManifest(manifest *ASIUpgradeManifest, config *config2.Config) error {
var serialisedManifest []byte
var err error
if serialisedManifest, err = json.MarshalIndent(manifest, "", "\t"); err != nil {
return fmt.Errorf("failed to marshal manifest: %w", err)
}

var f *os.File
const manifestFilename = "asi_upgrade_manifest.json"
genesisFilePath := config.GenesisFile()
manifestFilePath := path.Join(path.Dir(genesisFilePath), manifestFilename)
if f, err = os.Create(manifestFilePath); err != nil {
return fmt.Errorf("failed to create file \"%s\": %w", manifestFilePath, err)
}
defer f.Close()

if _, err = f.Write(serialisedManifest); err != nil {
return fmt.Errorf("failed to write manifest to the \"%s\" file : %w", manifestFilePath, err)
}

return nil
}
Loading