11import { AnchorProvider , Program } from '@coral-xyz/anchor'
22import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'
3- import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
4- import { PublicKey } from '@solana/web3.js'
3+ import { TOKEN_PROGRAM_ID , getMint } from '@solana/spl-token'
54import { task } from 'hardhat/config'
65
6+ import { types } from '@layerzerolabs/devtools-evm-hardhat'
77import { EndpointId } from '@layerzerolabs/lz-definitions'
88
99import { deriveConnection , getExplorerTxLink } from './index'
@@ -12,79 +12,65 @@ interface Args {
1212 eid : EndpointId
1313 programId : string
1414 oftStore : string
15- tokenEscrow : string
16- tokenMint : string
17- tokenProgram : string
18- multisig : string
1915 computeUnitPriceScaleFactor : number
2016}
2117
2218// TODO: no need to pass in oft store? since we can derive
2319task ( 'lz:oft:solana:renounce-freeze' , 'Renounce freeze authority for an OFT token' )
2420 . addParam ( 'eid' , 'The endpoint ID' , undefined , types . eid )
2521 . addParam ( 'programId' , 'The OFT program ID' , undefined , types . string )
26- . addParam ( 'tokenEscrow' , 'The OFT token escrow public key' , undefined , types . string )
2722 . addParam ( 'oftStore' , 'The OFT Store public key' , undefined , types . string )
28- . addParam ( 'tokenMint' , 'The OFT token mint public key' , undefined , types . string )
29- . addParam ( 'multisig' , 'The multisig public key' , undefined , types . string )
3023 . addParam ( 'computeUnitPriceScaleFactor' , 'The compute unit price scale factor' , 4 , types . float , true )
31- . setAction (
32- async ( {
33- eid,
34- programId : programIdStr ,
35- oftStore : oftStoreStr ,
36- tokenEscrow : tokenEscrowStr ,
37- tokenMint : tokenMintStr ,
38- multisig : multiSigStr ,
39- computeUnitPriceScaleFactor,
40- } : Args ) => {
41- const { connection, umi, umiWalletSigner, web3JsKeypair } = await deriveConnection ( eid )
24+ . setAction ( async ( { eid, programId : programIdStr , oftStore : oftStoreStr , computeUnitPriceScaleFactor } : Args ) => {
25+ const { connection, umiWalletSigner, web3JsKeypair } = await deriveConnection ( eid )
4226
43- // TODO: clean up below block
44- const wallet = new NodeWallet ( web3JsKeypair )
45- const provider = new AnchorProvider ( connection , wallet , {
46- commitment : 'processed' ,
47- } )
27+ // TODO: clean up below block
28+ const wallet = new NodeWallet ( web3JsKeypair )
29+ const provider = new AnchorProvider ( connection , wallet , {
30+ commitment : 'processed' ,
31+ } )
4832
49- const IDL = await import ( '../../target/idl/oft.json' ) . then ( ( module ) => module . default )
50- const anchorTypes = await import ( '../../target/types/oft' ) . then ( ( module ) => module )
33+ const IDL = await import ( '../../target/idl/oft.json' ) . then ( ( module ) => module . default )
34+ const types = await import ( '../../target/types/oft' ) . then ( ( module ) => module )
5135
52- // @ts -ignore we can ignore the IDL type error, which is a quirk of Anchor
53- const program = new Program < typeof anchorTypes . IDL > ( IDL , programIdStr , provider )
36+ // @ts -expect-error we can ignore the IDL type error, which is a quick or Anchor
37+ const program = new Program < typeof types . IDL > ( IDL , programIdStr , provider )
5438
55- const [ oftStorePda , oftStoreBump ] = PublicKey . findProgramAddressSync (
56- [ Buffer . from ( 'OFT' ) , new PublicKey ( tokenEscrowStr ) . toBuffer ( ) ] ,
57- program . programId
58- )
59- if ( oftStorePda . toString ( ) != oftStoreStr ) {
60- throw new Error ( 'Mismatch between Token Escrow address and derived OFT Store PDA' )
61- }
39+ const oftStoreAccount = await program . account . oftStore . fetch ( oftStoreStr )
40+ const tokenMint = oftStoreAccount . tokenMint
6241
63- const oftStoreAccountData = await program . account . oftStore . fetch ( oftStoreStr )
42+ const mintAccount = await getMint ( connection , tokenMint ) // to support Token-2022, pass in program ID as third param here
6443
65- const signerIsAdmin = umiWalletSigner . publicKey . toString ( ) == oftStoreAccountData . admin . toString ( )
66- if ( ! signerIsAdmin ) {
67- throw new Error ( 'Your keypair is not the OFT Store admin.' )
68- }
44+ // we assume that the mint authority is set to the multisig
45+ const multisig = mintAccount . mintAuthority
6946
70- // Call the method
71- try {
72- const tx = await program . methods
73- . renounceFreeze ( ) // Method name
74- . accounts ( {
75- signer : umiWalletSigner . publicKey ,
76- oftStore : oftStorePda ,
77- tokenEscrow : tokenEscrowStr ,
78- tokenMint : tokenMintStr ,
79- currentAuthority : multiSigStr ,
80- tokenProgram : TOKEN_PROGRAM_ID . toBase58 ( ) , // currently only supports SPL Token standard
81- } )
82- . signers ( [ web3JsKeypair ] )
83- . rpc ( )
47+ if ( ! multisig ) {
48+ throw new Error ( 'Mint authority is not set.' )
49+ }
50+
51+ const oftStoreAccountData = await program . account . oftStore . fetch ( oftStoreStr )
52+
53+ const signerIsAdmin = umiWalletSigner . publicKey . toString ( ) == oftStoreAccountData . admin . toString ( )
54+ if ( ! signerIsAdmin ) {
55+ throw new Error ( 'Your keypair is not the OFT Store admin.' )
56+ }
57+
58+ // Call the method
59+ try {
60+ const tx = await program . methods
61+ . renounceFreeze ( ) // Method name
62+ . accounts ( {
63+ signer : umiWalletSigner . publicKey ,
64+ oftStore : oftStoreStr ,
65+ tokenMint : tokenMint ,
66+ currentAuthority : multisig ,
67+ tokenProgram : TOKEN_PROGRAM_ID . toBase58 ( ) , // currently only supports SPL Token standard
68+ } )
69+ . signers ( [ web3JsKeypair ] )
70+ . rpc ( )
8471
85- console . log ( 'Transaction successful:' , getExplorerTxLink ( tx , eid == EndpointId . SOLANA_V2_TESTNET ) )
86- } catch ( err ) {
87- console . error ( 'Transaction failed:' , err )
88- }
72+ console . log ( 'Transaction successful:' , getExplorerTxLink ( tx , eid == EndpointId . SOLANA_V2_TESTNET ) )
73+ } catch ( err ) {
74+ console . error ( 'Transaction failed:' , err )
8975 }
90- )
76+ } )
0 commit comments