Skip to content

Commit

Permalink
add set mint authority
Browse files Browse the repository at this point in the history
  • Loading branch information
asilenced committed Dec 14, 2023
1 parent 8a2750a commit 61363c3
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
13 changes: 13 additions & 0 deletions cmd/soltool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
&setSupportChainIdCommand,
&setFeeReceiverCommand,
&setFeeAmountCommand,
&setMintAuthorityCommand,
}

}
Expand Down Expand Up @@ -85,6 +86,14 @@ var setFeeReceiverCommand = cli.Command{
Flags: cliFlags,
}

var setMintAuthorityCommand = cli.Command{
Name: "setMintAuthority",
Usage: "set mint authority",
Description: "The setMintAuthority command is used to set mint authority",
Action: setMintAuthority,
Flags: cliFlags,
}

var setFeeAmountCommand = cli.Command{
Name: "setFeeAmount",
Usage: "set fee amount",
Expand Down Expand Up @@ -114,6 +123,10 @@ type PoolAccounts struct {
ResourceIdToMint map[string]string `json:"resourceIdToMint"`
FeeReceiverAccount string `json:"feeReceiverAccount"` //need private key
FeeAmounts map[string]uint64 `json:"feeAmounts"`

StakePool string `json:"stakePool"`
BridgeSigner string `json:"bridgeSigner"`
RSolMint string `json:"rsolMint"`
}

func loadConfig(file string, config *PoolAccounts) (err error) {
Expand Down
110 changes: 110 additions & 0 deletions cmd/soltool/set_mint_authority.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"context"
"fmt"
"time"

"github.com/stafiprotocol/chainbridge/shared/solana/vault"
"github.com/stafiprotocol/solana-go-sdk/bridgeprog"
solClient "github.com/stafiprotocol/solana-go-sdk/client"
solCommon "github.com/stafiprotocol/solana-go-sdk/common"
solTypes "github.com/stafiprotocol/solana-go-sdk/types"
"github.com/urfave/cli/v2"
)

func setMintAuthority(ctx *cli.Context) error {
path := ctx.String(configFlag.Name)
pc := PoolAccounts{}
err := loadConfig(path, &pc)
if err != nil {
return err
}
if len(pc.StakePool) == 0 {
return fmt.Errorf("stakepool empty")
}
fmt.Printf("\naccounts info:\n %+v\n", pc)
v, err := vault.NewVaultFromWalletFile(pc.KeystorePath)
if err != nil {
return err
}
boxer, err := vault.SecretBoxerForType(v.SecretBoxWrap)
if err != nil {
return fmt.Errorf("secret boxer: %w", err)
}

if err := v.Open(boxer); err != nil {
return fmt.Errorf("opening: %w", err)
}

privKeyMap := make(map[string]vault.PrivateKey)
for _, privKey := range v.KeyBag {
privKeyMap[privKey.PublicKey().String()] = privKey
}

FeeAccount := solTypes.AccountFromPrivateKeyBytes(privKeyMap[pc.FeeAccount])
BridgeAccount := solTypes.AccountFromPrivateKeyBytes(privKeyMap[pc.BridgeAccount])
AdminAccount := solTypes.AccountFromPrivateKeyBytes(privKeyMap[pc.AdminAccountPubkey])
BridgeProgramId := solCommon.PublicKeyFromString(pc.BridgeProgramId)

owners := make([]solCommon.PublicKey, 0)
owners = append(owners, FeeAccount.PublicKey)
for _, account := range pc.OtherFeeAccountPubkey {
a := solTypes.AccountFromPrivateKeyBytes(privKeyMap[account])
owners = append(owners, a.PublicKey)
}
if len(owners) < int(pc.Threshold) {
return fmt.Errorf("owner len < threshold")
}

//start inter with solana chain
c := solClient.NewClient([]string{pc.Endpoint})
//check if exist
bridgeInfo, err := c.GetBridgeAccountInfo(context.Background(), BridgeAccount.PublicKey.ToBase58())
if err != nil {
return fmt.Errorf("\nbridge account not exist:\n %+v", bridgeInfo)
}

res, err := c.GetLatestBlockhash(context.Background(), solClient.GetLatestBlockhashConfig{
Commitment: solClient.CommitmentConfirmed,
})
if err != nil {
return err
}

fmt.Printf("bridgeAccount %s\n", BridgeAccount.PublicKey.ToBase58())
fmt.Printf("owners %+v\n", owners)
fmt.Printf("supportChainIds %+v\n", pc.SupportChainIds)
fmt.Printf("feeReceiver %+v\n", pc.FeeReceiverAccount)
fmt.Printf("stakePool %+v\n", solCommon.PublicKeyFromString(pc.StakePool).ToBase58())
fmt.Printf("bridgeSigner %+v\n", pc.BridgeSigner)

time.Sleep(3 * time.Second)

//create bridge account
rawTx, err := solTypes.CreateRawTransaction(solTypes.CreateRawTransactionParam{
Instructions: []solTypes.Instruction{
bridgeprog.SetMintAuthority(
BridgeProgramId,
BridgeAccount.PublicKey,
AdminAccount.PublicKey,
solCommon.PublicKeyFromString(pc.BridgeSigner),
solCommon.PublicKeyFromString(pc.RSolMint),
solCommon.PublicKeyFromString(pc.StakePool),
),
},
Signers: []solTypes.Account{FeeAccount, AdminAccount},
FeePayer: FeeAccount.PublicKey,
RecentBlockHash: res.Blockhash,
})
if err != nil {
return fmt.Errorf("generate tx error, err: %v", err)
}
txHash, err := c.SendRawTransaction(context.Background(), rawTx)
if err != nil {
return fmt.Errorf("send tx error, err: %v", err)
}
fmt.Println("SetMintAuthority txHash:", txHash)

return nil
}
5 changes: 4 additions & 1 deletion example_sol_create_bridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"feeReceiverAccount": "9Riwnxn53S4wmy5h5nbQN1gxTCm1EvgqB4Gc5aKDAPyc",
"feeAmounts": {
"1": 50000
}
},
"stakePool": "",
"bridgeSigner": "",
"rsolMint": ""
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/stafihub/stafi-hub-relay-sdk v1.7.0
github.com/stafihub/stafihub v0.1.0
github.com/stafiprotocol/go-substrate-rpc-client v1.2.1
github.com/stafiprotocol/solana-go-sdk v1.3.0
github.com/stafiprotocol/solana-go-sdk v1.4.0
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.10.2
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,8 @@ github.com/stafihub/stafihub v0.1.0 h1:3EMn615R8mEg6eskZgok+67wKC11rD0sfIM+iRF8E
github.com/stafihub/stafihub v0.1.0/go.mod h1:xY155chryZY5plerYGnk/KKdex2LkGlQ93bSEEDOJJY=
github.com/stafiprotocol/go-substrate-rpc-client v1.2.1 h1:dOViH/pvHoAxhTkIwg/7NESTd6TsHgN7w/qNjtmlVLk=
github.com/stafiprotocol/go-substrate-rpc-client v1.2.1/go.mod h1:iVtW5HNDMp68AEEpL3XDuC6iE3amtkz+t26bdblYW18=
github.com/stafiprotocol/solana-go-sdk v1.3.0 h1:hOpO+YsquFI4oEgdv5hb4UJMaMGLloZE9BT9g9wlUaw=
github.com/stafiprotocol/solana-go-sdk v1.3.0/go.mod h1:/0nE9JnF+mhWxwJPhyyTsUHNKC41VsxZ2uKpyEWb+bM=
github.com/stafiprotocol/solana-go-sdk v1.4.0 h1:8Ihuunrf8gB0KFNsBfI3cKfqQgSWaIxlYP2SQnl9GgI=
github.com/stafiprotocol/solana-go-sdk v1.4.0/go.mod h1:/0nE9JnF+mhWxwJPhyyTsUHNKC41VsxZ2uKpyEWb+bM=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57NRNuZ2d3rmvB3pcmbu7O1RS3m8WRx7ilrg=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I=
Expand Down

0 comments on commit 61363c3

Please sign in to comment.