Skip to content

Commit 329182b

Browse files
committed
Store to address
1 parent 8cc36f6 commit 329182b

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"regexp"
89

910
"github.com/Masterminds/semver/v3"
1011
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -679,8 +680,22 @@ func CreateTokenMultisig(e cldf.Environment, cfg CreateTokenMultisigConfig) (cld
679680
return cldf.ChangesetOutput{}, err
680681
}
681682
newMultisig, err := createMultisig(e, tokenPoolSignerPDA, cfg.CustomerMintAuthorities, tokenProgramId)
682-
e.Logger.Info("created multisig", "newMultisig", newMultisig)
683-
return cldf.ChangesetOutput{}, nil
683+
if err != nil {
684+
return cldf.ChangesetOutput{}, err
685+
}
686+
newAddresses := cldf.NewMemoryAddressBook()
687+
tv := cldf.NewTypeAndVersion("TokenMultisig", deployment.Version1_0_0)
688+
tv.AddLabel(cfg.Metadata)
689+
tv.AddLabel(cfg.TokenMint.String())
690+
err = newAddresses.Save(cfg.ChainSelector, newMultisig.String(), tv)
691+
if err != nil {
692+
e.Logger.Errorw("Failed to save new token multisig", "chain", solChainState, "err", err)
693+
return cldf.ChangesetOutput{}, err
694+
}
695+
e.Logger.Infow("Created multisig", "TokenMultisigAddress", newMultisig, "TokenMint", cfg.TokenMint, "Signers 1 of", tokenPoolSignerPDA, cfg.CustomerMintAuthorities)
696+
return cldf.ChangesetOutput{
697+
AddressBook: newAddresses,
698+
}, nil
684699
}
685700

686701
func createMultisig(e cldf.Environment, tokenPoolSignerPDA solana.PublicKey, customerMintAuthorities []solana.PublicKey, tokenProgramId solana.PublicKey) (solana.PublicKey, error) {
@@ -698,9 +713,25 @@ func createMultisig(e cldf.Environment, tokenPoolSignerPDA solana.PublicKey, cus
698713
e.Logger.Debugw("spl-token create-multisig error", "error", err)
699714
return solana.PublicKey{}, fmt.Errorf("error spl-token create-multisig: %w", err)
700715
}
716+
multisigAddress, err := parseMultisigAddress(output)
717+
if err != nil {
718+
e.Logger.Debugw("spl-token create-multisig error", "error", err)
719+
}
701720
e.Logger.Infow("Created Token Multisig ", "tokenProgramId", tokenProgramId)
702-
// TODO: return output, nil
703-
return solana.PublicKey{}, nil
721+
return solana.MustPublicKeyFromBase58(multisigAddress), nil
722+
}
723+
724+
// ParseMultisigAddress extracts the created multisig address from either a JSON blob
725+
// with an "output" field or from raw text. It returns the first match it finds.
726+
func parseMultisigAddress(text string) (string, error) {
727+
// Regex: captures a Solana base58 address between "multisig" and "under program".
728+
// Solana addresses are base58 (no 0, O, I, l) and typically 32–44 chars.
729+
re := regexp.MustCompile(`(?i)Creating\s+\d+/\d+\s+multisig\s+([1-9A-HJ-NP-Za-km-z]{32,44})\s+under\s+program`)
730+
m := re.FindStringSubmatch(text)
731+
if len(m) < 2 {
732+
return "", errors.New("multisig address not found")
733+
}
734+
return m[1], nil
704735
}
705736

706737
func ModifyMintAuthority(e cldf.Environment, cfg NewMintTokenPoolConfig) (cldf.ChangesetOutput, error) {

deployment/ccip/changeset/solana_v0_1_1/cs_token_pool_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,16 @@ func TestPartnerTokenPools(t *testing.T) {
614614
func TestCreatingMultisig(t *testing.T) {
615615
tenv, _ := testhelpers.NewMemoryEnvironment(t, testhelpers.WithSolChains(1), testhelpers.WithCCIPSolanaContractVersion(ccipChangesetSolana.SolanaContractV0_1_1))
616616
solChain := tenv.Env.BlockChains.ListChainSelectors(cldf_chain.WithFamily(chain_selectors.FamilySolana))[0]
617-
617+
deployerKey := tenv.Env.BlockChains.SolanaChains()[solChain].DeployerKey.PublicKey()
618+
e, newTokenAddress, err := deployTokenAndMint(t, tenv.Env, solChain, []string{deployerKey.String()}, "TEST_TOKEN")
619+
require.NoError(t, err)
618620
burnMintTokenPoolType := solTestTokenPool.BurnAndMint_PoolType
619-
_, _, err := commonchangeset.ApplyChangesets(t, tenv.Env, []commonchangeset.ConfiguredChangeSet{
621+
_, _, err = commonchangeset.ApplyChangesets(t, e, []commonchangeset.ConfiguredChangeSet{
620622
commonchangeset.Configure(
621623
cldf.CreateLegacyChangeSet(ccipChangesetSolana.CreateTokenMultisig),
622624
ccipChangesetSolana.CreateTokenMultisigConfig{
623625
ChainSelector: solChain,
624-
TokenMint: solana.MustPublicKeyFromBase58("DzBixyQHeQHCBqCTqe1tW5hz8AJUGbfWHxuzUp8T8Dhr"),
626+
TokenMint: newTokenAddress,
625627
PoolType: &burnMintTokenPoolType,
626628
Metadata: shared.CLLMetadata,
627629
CustomerMintAuthorities: []solana.PublicKey{solana.MustPublicKeyFromBase58("9o9vS5dHHQLaZLv8gHuNu6k6J5HjisF9ravgRZigiDkb")},

0 commit comments

Comments
 (0)