Skip to content

Commit ae5ec0e

Browse files
authored
CCIP-6889: Adding token's mint authority check (#19108)
* CCIP-6889: Adding token's mint authority check * more clean up * use method from chain itself * add case and fix issue
1 parent 99cc7b2 commit ae5ec0e

2 files changed

Lines changed: 56 additions & 20 deletions

File tree

‎deployment/ccip/changeset/solana_v0_1_0/cs_token_pool.go‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/gagliardetto/solana-go"
13+
solToken "github.com/gagliardetto/solana-go/programs/token"
1314

1415
cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana"
1516

@@ -233,19 +234,36 @@ func AddTokenPoolAndLookupTable(e cldf.Environment, cfg AddTokenPoolAndLookupTab
233234

234235
instructions = append(instructions, poolInitI)
235236

237+
// fetch current token mint authority
238+
var tokenMint solToken.Mint
239+
err = chain.GetAccountDataBorshInto(context.Background(), tokenPubKey, &tokenMint)
240+
if err != nil {
241+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to get token mint account data: %w", err)
242+
}
243+
236244
// make pool mint_authority for token
237245
if tokenPoolCfg.PoolType == shared.BurnMintTokenPool && tokenPubKey != solana.SolMint {
238-
authI, err := solTokenUtil.SetTokenMintAuthority(
239-
tokenprogramID,
240-
poolSigner,
241-
tokenPubKey,
242-
chain.DeployerKey.PublicKey(),
243-
)
244-
if err != nil {
245-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err)
246+
if tokenMint.MintAuthority != nil && tokenMint.MintAuthority.String() == chain.DeployerKey.PublicKey().String() {
247+
authI, err := solTokenUtil.SetTokenMintAuthority(
248+
tokenprogramID,
249+
poolSigner,
250+
tokenPubKey,
251+
chain.DeployerKey.PublicKey(),
252+
)
253+
if err != nil {
254+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err)
255+
}
256+
instructions = append(instructions, authI)
257+
e.Logger.Infow("Setting mint authority", "poolSigner", poolSigner.String())
258+
} else {
259+
e.Logger.Warnw("Token's mint authority is not with deployer key, skipping setting poolSigner as mint authority",
260+
"poolType", tokenPoolCfg.PoolType, "mintAuthority", tokenMint.MintAuthority.String(),
261+
"deployer", chain.DeployerKey.PublicKey().String(), "poolSigner", poolSigner.String())
246262
}
247-
instructions = append(instructions, authI)
248-
e.Logger.Infow("Setting mint authority", "poolSigner", poolSigner.String())
263+
} else {
264+
e.Logger.Warnw("PoolType is not a BurnMintTokenPool, skipping setting poolSigner as mint authority",
265+
"poolType", tokenPoolCfg.PoolType, "mintAuthority", tokenMint.MintAuthority.String(),
266+
"deployer", chain.DeployerKey.PublicKey().String(), "poolSigner", poolSigner.String())
249267
}
250268

251269
// confirm instructions

‎deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1414
"github.com/ethereum/go-ethereum/common"
1515
"github.com/gagliardetto/solana-go"
16+
solToken "github.com/gagliardetto/solana-go/programs/token"
1617

1718
cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana"
1819

@@ -289,19 +290,36 @@ func AddTokenPoolAndLookupTable(e cldf.Environment, cfg AddTokenPoolAndLookupTab
289290

290291
instructions = append(instructions, poolInitI)
291292

293+
// fetch current token mint authority
294+
var tokenMint solToken.Mint
295+
err = chain.GetAccountDataBorshInto(context.Background(), tokenPubKey, &tokenMint)
296+
if err != nil {
297+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to get token mint account data: %w", err)
298+
}
299+
292300
// make pool mint_authority for token
293301
if tokenPoolCfg.PoolType == shared.BurnMintTokenPool && tokenPubKey != solana.SolMint {
294-
authI, err := solTokenUtil.SetTokenMintAuthority(
295-
tokenprogramID,
296-
poolSigner,
297-
tokenPubKey,
298-
chain.DeployerKey.PublicKey(),
299-
)
300-
if err != nil {
301-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err)
302+
if tokenMint.MintAuthority != nil && tokenMint.MintAuthority.String() == chain.DeployerKey.PublicKey().String() {
303+
authI, err := solTokenUtil.SetTokenMintAuthority(
304+
tokenprogramID,
305+
poolSigner,
306+
tokenPubKey,
307+
chain.DeployerKey.PublicKey(),
308+
)
309+
if err != nil {
310+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err)
311+
}
312+
instructions = append(instructions, authI)
313+
e.Logger.Infow("Setting mint authority", "poolSigner", poolSigner.String())
314+
} else {
315+
e.Logger.Warnw("Token's mint authority is not with deployer key, skipping setting poolSigner as mint authority",
316+
"poolType", tokenPoolCfg.PoolType, "mintAuthority", tokenMint.MintAuthority.String(),
317+
"deployer", chain.DeployerKey.PublicKey().String(), "poolSigner", poolSigner.String())
302318
}
303-
instructions = append(instructions, authI)
304-
e.Logger.Infow("Setting mint authority", "poolSigner", poolSigner.String())
319+
} else {
320+
e.Logger.Warnw("PoolType is not a BurnMintTokenPool, skipping setting poolSigner as mint authority",
321+
"poolType", tokenPoolCfg.PoolType, "mintAuthority", tokenMint.MintAuthority.String(),
322+
"deployer", chain.DeployerKey.PublicKey().String(), "poolSigner", poolSigner.String())
305323
}
306324

307325
// confirm instructions

0 commit comments

Comments
 (0)