Skip to content

Commit

Permalink
Add support for reconciliation on testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
pbukva committed May 30, 2024
1 parent 99a70d8 commit 9ab8529
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
86 changes: 50 additions & 36 deletions cmd/fetchd/cmd/genesis-asi-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
ibccore "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
"log"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -68,30 +67,39 @@ var (

var ReconciliationTargetAddr = "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x"

//go:embed reconciliation_data.csv
var reconciliationData []byte

//go:embed reconciliation_data_testnet.csv
var reconciliationDataTestnet []byte

var networkInfos = map[string]NetworkConfig{
"fetchhub-4": {
NewChainID: "asi-1",
NewDescription: "ASI token", // TODO(JS): confirm this
NewDescription: "ASI token",
DenomInfo: DenomInfo{
NewBaseDenom: "asi",
NewDenom: "aasi",
OldDenom: "afet",
},
SupplyInfo: SupplyInfo{
SupplyToMint: "0", // TODO(JS): likely amend this
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
SupplyToMint: "0",
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw",
},
IbcTargetAddr: "fetch1zydegef0z6lz4gamamzlnu52ethe8xnm0xe5fkyrgwumsh9pplus5he63f",
Reconciliation: &Reconciliation{
TargetAddress: "fetch1tynmzk68pq6kzawqffrqdhquq475gw9ccmlf9gk24mxjjy6ugl3q70aeyd",
InputCSVRecords: readInputReconciliationData(reconciliationData),
},
IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
ReconciliationTargetAddr: &ReconciliationTargetAddr, // TODO(JS): amend this
Contracts: &Contracts{
Almanac: &Almanac{
StagingAddr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y", // mainnet STAGING contract,
StagingAddr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y",
},
AName: &AName{
StagingAddr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q", // mainnet STAGING contract,
StagingAddr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q",
},
MobixStaking: &MobixStaking{
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e", // TODO(JS): amend this
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e",
},
TokenBridge: &TokenBridge{
Addr: "fetch1qxxlalvsdjd07p07y3rc5fu6ll8k4tmetpha8n",
Expand All @@ -109,10 +117,14 @@ var networkInfos = map[string]NetworkConfig{
OldDenom: "atestfet",
},
SupplyInfo: SupplyInfo{
SupplyToMint: "0", // TODO(JS): likely amend this
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
SupplyToMint: "0",
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw",
},
IbcTargetAddr: "fetch18rlg4hs2p03yuvvdu389pe65qa789asmyqsfftdxsh2qjfwmt94qmrf7g0",
Reconciliation: &Reconciliation{
TargetAddress: "fetch1g5ur2wc5xnlc7sw9wd895lw7mmxz04r5syj3s6ew8md6pvwuweqqavkgt0",
InputCSVRecords: readInputReconciliationData(reconciliationDataTestnet),
},
//IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
Contracts: &Contracts{
Almanac: &Almanac{
StagingAddr: "fetch1tjagw8g8nn4cwuw00cf0m5tl4l6wfw9c0ue507fhx9e3yrsck8zs0l3q4w", // testnet STAGING contract,
Expand All @@ -139,9 +151,6 @@ var networkInfos = map[string]NetworkConfig{
},
}

//go:embed reconciliation_data.csv
var reconciliationData []byte

// ASIGenesisUpgradeCmd returns replace-genesis-values cobra Command.
func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -760,42 +769,33 @@ func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
}

func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
if networkInfo.ReconciliationTargetAddr == nil {
if networkInfo.Reconciliation == nil {
return
}

bank := jsonData[banktypes.ModuleName].(map[string]interface{})
balances := bank["balances"].([]interface{})
reconciliationWithdrawAddress := networkInfo.ReconciliationTargetAddr
reconciliationWithdrawAddress := networkInfo.Reconciliation.TargetAddress

balanceMap := getGenesisBalancesMap(balances)

auth := jsonData[authtypes.ModuleName].(map[string]interface{})
accounts := auth["accounts"].([]interface{})
accountSequenceMap := getGenesisAccountSequenceMap(accounts)

fileData := reconciliationData
r := csv.NewReader(bytes.NewReader(fileData))
items, err := r.ReadAll()
if err != nil {
log.Fatalf("Error reading reconciliation data: %s", err)
}

reconciliationBalanceIdx, ok := (*balanceMap)[*reconciliationWithdrawAddress]
reconciliationBalanceIdx, ok := (*balanceMap)[reconciliationWithdrawAddress]
if !ok {
panic("no match in genesis for reconciliation withdraw address")
}

manifest.Reconciliation = &ASIUpgradeTransfers{
Transfer: []ASIUpgradeTransfer{},
To: *reconciliationWithdrawAddress,
To: reconciliationWithdrawAddress,
}

for _, row := range items {
for _, row := range networkInfo.Reconciliation.InputCSVRecords {
addr := row[2]

//_ = row[3] balance from CSV

accSequence, ok := (*accountSequenceMap)[addr]
if !ok {
panic("no match in genesis for reconciliation address")
Expand Down Expand Up @@ -965,14 +965,28 @@ func getInterfaceSliceFromCoins(coins sdk.Coins) []interface{} {
return balance
}

func readInputReconciliationData(csvData []byte) [][]string {
r := csv.NewReader(bytes.NewReader(csvData))
records, err := r.ReadAll()
if err != nil {
panic(fmt.Sprintf("error reading reconciliation data: %v", err))
}
return records
}

type NetworkConfig struct {
NewChainID string
NewDescription string
IbcTargetAddr string
ReconciliationTargetAddr *string
SupplyInfo SupplyInfo
DenomInfo DenomInfo
Contracts *Contracts
NewChainID string
NewDescription string
IbcTargetAddr string
Reconciliation *Reconciliation
SupplyInfo SupplyInfo
DenomInfo DenomInfo
Contracts *Contracts
}

type Reconciliation struct {
TargetAddress string
InputCSVRecords [][]string
}

type SupplyInfo struct {
Expand Down
3 changes: 3 additions & 0 deletions cmd/fetchd/cmd/reconciliation_data_testnet.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,,fetch1uvye96zkp86egcwrnsff22ama3c0m8h2aemmsd,,,
,,fetch1kydzrk0ylc60zt34m00qttev5h3dgz72scl79d,,,
,,fetch1753h55um54pnskd77x0pfpv3le2e4cdhf3dhqc,,,

0 comments on commit 9ab8529

Please sign in to comment.