Skip to content

Commit 0aa282b

Browse files
authored
Add support for reconciliation on testnet (#360)
1 parent a063eb8 commit 0aa282b

File tree

2 files changed

+53
-36
lines changed

2 files changed

+53
-36
lines changed

cmd/fetchd/cmd/genesis-asi-upgrade.go

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
ibccore "github.com/cosmos/ibc-go/v3/modules/core/24-host"
2424
"github.com/spf13/cobra"
2525
"github.com/tendermint/tendermint/types"
26-
"log"
2726
"regexp"
2827
"strconv"
2928
"strings"
@@ -68,30 +67,39 @@ var (
6867

6968
var ReconciliationTargetAddr = "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x"
7069

70+
//go:embed reconciliation_data.csv
71+
var reconciliationData []byte
72+
73+
//go:embed reconciliation_data_testnet.csv
74+
var reconciliationDataTestnet []byte
75+
7176
var networkInfos = map[string]NetworkConfig{
7277
"fetchhub-4": {
7378
NewChainID: "asi-1",
74-
NewDescription: "ASI token", // TODO(JS): confirm this
79+
NewDescription: "ASI token",
7580
DenomInfo: DenomInfo{
7681
NewBaseDenom: "asi",
7782
NewDenom: "aasi",
7883
OldDenom: "afet",
7984
},
8085
SupplyInfo: SupplyInfo{
81-
SupplyToMint: "0", // TODO(JS): likely amend this
82-
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
86+
SupplyToMint: "0",
87+
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw",
88+
},
89+
IbcTargetAddr: "fetch1zydegef0z6lz4gamamzlnu52ethe8xnm0xe5fkyrgwumsh9pplus5he63f",
90+
Reconciliation: &Reconciliation{
91+
TargetAddress: "fetch1tynmzk68pq6kzawqffrqdhquq475gw9ccmlf9gk24mxjjy6ugl3q70aeyd",
92+
InputCSVRecords: readInputReconciliationData(reconciliationData),
8393
},
84-
IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
85-
ReconciliationTargetAddr: &ReconciliationTargetAddr, // TODO(JS): amend this
8694
Contracts: &Contracts{
8795
Almanac: &Almanac{
88-
StagingAddr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y", // mainnet STAGING contract,
96+
StagingAddr: "fetch1mezzhfj7qgveewzwzdk6lz5sae4dunpmmsjr9u7z0tpmdsae8zmquq3y0y",
8997
},
9098
AName: &AName{
91-
StagingAddr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q", // mainnet STAGING contract,
99+
StagingAddr: "fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q",
92100
},
93101
MobixStaking: &MobixStaking{
94-
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e", // TODO(JS): amend this
102+
Addr: "fetch1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3szdul6e",
95103
},
96104
TokenBridge: &TokenBridge{
97105
Addr: "fetch1qxxlalvsdjd07p07y3rc5fu6ll8k4tmetpha8n",
@@ -109,10 +117,14 @@ var networkInfos = map[string]NetworkConfig{
109117
OldDenom: "atestfet",
110118
},
111119
SupplyInfo: SupplyInfo{
112-
SupplyToMint: "0", // TODO(JS): likely amend this
113-
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw", // TODO(JS): likely amend this
120+
SupplyToMint: "0",
121+
UpdatedSupplyOverflowAddr: "fetch15p3rl5aavw9rtu86tna5lgxfkz67zzr6ed4yhw",
122+
},
123+
IbcTargetAddr: "fetch18rlg4hs2p03yuvvdu389pe65qa789asmyqsfftdxsh2qjfwmt94qmrf7g0",
124+
Reconciliation: &Reconciliation{
125+
TargetAddress: "fetch1g5ur2wc5xnlc7sw9wd895lw7mmxz04r5syj3s6ew8md6pvwuweqqavkgt0",
126+
InputCSVRecords: readInputReconciliationData(reconciliationDataTestnet),
114127
},
115-
//IbcTargetAddr: "fetch1rhrlzsx9z865dqen8t4v47r99dw6y4va4uph0x", // TODO(JS): amend this
116128
Contracts: &Contracts{
117129
Almanac: &Almanac{
118130
StagingAddr: "fetch1tjagw8g8nn4cwuw00cf0m5tl4l6wfw9c0ue507fhx9e3yrsck8zs0l3q4w", // testnet STAGING contract,
@@ -139,9 +151,6 @@ var networkInfos = map[string]NetworkConfig{
139151
},
140152
}
141153

142-
//go:embed reconciliation_data.csv
143-
var reconciliationData []byte
144-
145154
// ASIGenesisUpgradeCmd returns replace-genesis-values cobra Command.
146155
func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
147156
cmd := &cobra.Command{
@@ -760,42 +769,33 @@ func getGenesisAccountSequenceMap(accounts []interface{}) *map[string]int {
760769
}
761770

762771
func ASIGenesisUpgradeWithdrawReconciliationBalances(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
763-
if networkInfo.ReconciliationTargetAddr == nil {
772+
if networkInfo.Reconciliation == nil {
764773
return
765774
}
766775

767776
bank := jsonData[banktypes.ModuleName].(map[string]interface{})
768777
balances := bank["balances"].([]interface{})
769-
reconciliationWithdrawAddress := networkInfo.ReconciliationTargetAddr
778+
reconciliationWithdrawAddress := networkInfo.Reconciliation.TargetAddress
770779

771780
balanceMap := getGenesisBalancesMap(balances)
772781

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

777-
fileData := reconciliationData
778-
r := csv.NewReader(bytes.NewReader(fileData))
779-
items, err := r.ReadAll()
780-
if err != nil {
781-
log.Fatalf("Error reading reconciliation data: %s", err)
782-
}
783-
784-
reconciliationBalanceIdx, ok := (*balanceMap)[*reconciliationWithdrawAddress]
786+
reconciliationBalanceIdx, ok := (*balanceMap)[reconciliationWithdrawAddress]
785787
if !ok {
786788
panic("no match in genesis for reconciliation withdraw address")
787789
}
788790

789791
manifest.Reconciliation = &ASIUpgradeTransfers{
790792
Transfer: []ASIUpgradeTransfer{},
791-
To: *reconciliationWithdrawAddress,
793+
To: reconciliationWithdrawAddress,
792794
}
793795

794-
for _, row := range items {
796+
for _, row := range networkInfo.Reconciliation.InputCSVRecords {
795797
addr := row[2]
796798

797-
//_ = row[3] balance from CSV
798-
799799
accSequence, ok := (*accountSequenceMap)[addr]
800800
if !ok {
801801
panic("no match in genesis for reconciliation address")
@@ -965,14 +965,28 @@ func getInterfaceSliceFromCoins(coins sdk.Coins) []interface{} {
965965
return balance
966966
}
967967

968+
func readInputReconciliationData(csvData []byte) [][]string {
969+
r := csv.NewReader(bytes.NewReader(csvData))
970+
records, err := r.ReadAll()
971+
if err != nil {
972+
panic(fmt.Sprintf("error reading reconciliation data: %v", err))
973+
}
974+
return records
975+
}
976+
968977
type NetworkConfig struct {
969-
NewChainID string
970-
NewDescription string
971-
IbcTargetAddr string
972-
ReconciliationTargetAddr *string
973-
SupplyInfo SupplyInfo
974-
DenomInfo DenomInfo
975-
Contracts *Contracts
978+
NewChainID string
979+
NewDescription string
980+
IbcTargetAddr string
981+
Reconciliation *Reconciliation
982+
SupplyInfo SupplyInfo
983+
DenomInfo DenomInfo
984+
Contracts *Contracts
985+
}
986+
987+
type Reconciliation struct {
988+
TargetAddress string
989+
InputCSVRecords [][]string
976990
}
977991

978992
type SupplyInfo struct {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
,,fetch1uvye96zkp86egcwrnsff22ama3c0m8h2aemmsd,,,
2+
,,fetch1kydzrk0ylc60zt34m00qttev5h3dgz72scl79d,,,
3+
,,fetch1753h55um54pnskd77x0pfpv3le2e4cdhf3dhqc,,,

0 commit comments

Comments
 (0)