Skip to content

Conversation

@nazreen
Copy link
Contributor

@nazreen nazreen commented Jan 3, 2025

NOTE: we will not merge this to main as the new instruction is only needed for OFTs that were created before the createOFT script was updated to immediately renounce the Freeze Authority. Else, it will just be bloat as it's an instruction that's never needed and not usable by current OFTs.

Motivation

This is for already created OFTs that were deployed with --only-oft-store true before #1141 , meaning the Freeze Authority was set to the multisig address, but the intention is to have the Freeze Authority renounced.

Changes introduced:

  1. created new instruction implementation file at programs/oft/src/instructions/renounce_freeze.rs
  2. updated OFT program (lib.rs) to 'register' the new instruction:
    pub fn renounce_freeze(ctx: Context<RenounceFreezeAuthority>) -> Result<()> {
        RenounceFreezeAuthority::apply(ctx)
    }
  1. Added new script at tasks/solana/renounceFreeze.ts
  2. Also, removed usage of program_id_from_env in programs/oft/src/lib.rs since it's not used. The removal of this enables anchor keys sync to auto-replace the program id here, thereby removing the manual step we currently require for devs to replace the program id in this file.

How to test

Init a new repo with this branch's examples

LZ_ENABLE_SOLANA_OFT_EXAMPLE=1 LAYERZERO_EXAMPLES_REPOSITORY_REF=#nazreen/oft-solana/renounce-freeze npx create-lz-oapp@latest

Build and Deploy program as usual.

To simulate previous case of Freeze Authority being set to the multisig even when in onlyOftStore mode, make the following edit in createOFT.ts:

            if (!isMABA) {
                let txBuilder = transactionBuilder()
                    .add(
                        setAuthority(umi, {
                            owned: mint.publicKey,
                            owner: umiWalletSigner,
                            newAuthority: fromWeb3JsPublicKey(mintAuthorityPublicKey),
                            authorityType: AuthorityType.MintTokens,
                        })
                    )
                    .add(
                        setAuthority(umi, {
                            owned: mint.publicKey,
                            owner: umiWalletSigner,
                            newAuthority: fromWeb3JsPublicKey(mintAuthorityPublicKey),  // <- use this instead
                            // newAuthority: onlyOftStore ? null : fromWeb3JsPublicKey(mintAuthorityPublicKey), // comment this line out
                            authorityType: AuthorityType.FreezeAccount,
                        })
                    )

Then, run the create script with --only-oft-store true

pnpm hardhat lz:oft:solana:create --eid 40168 --program-id <PROGRAM_ID> --only-oft-store true

Finally, run the new script:

npx hardhat lz:oft:solana:renounce-freeze --eid <ENDPOINT_ID> --program-id <PROGRAM_ID> --oft-store <OFT_STORE_ADDRESS> 

TODOS

  • support case where admin is a multisig
  • compute unit price scalar factor, use it

Next Step: updating the oft export in @layerzerolabs/oft-v2-solana-sdk

  • update apps/oft/v2/solana/sdk/src/oft.ts in monorepo to support new renounce freeze instruction, allowing us to just use something like below:
import { oft } from "@layerzerolabs/oft-v2-solana-sdk";

//...
let txBuilder = transactionBuilder().add(
                oft.renounceFreeze(
          {
            payer: payer,
            programs: programsRepo,
        },
        {
            // accounts
            oftStore: oftStore,
// the rest of the accounts object

Notes:

  • <MULTISIG_ADDRESS> should be mintAuthority the in OFT.json deployment file
  • need web3jsKeypair to be exported from deriveConnection()

ziming-zung
ziming-zung previously approved these changes Jan 9, 2025
@ziming-zung
Copy link
Contributor

The changes in the anchor program look good to me.

@nazreen
Copy link
Contributor Author

nazreen commented Jan 9, 2025

Latest Commit Changes:

  • Program updated to remove unnecessary mut instances and to make use of the constraint macro to validate the freeze authority
  • Simplified script to not require manual passing of: token escrow, mint address, multisig address. All these can be obtained from the OFT Store account.

PR body has been updated.

@nazreen nazreen force-pushed the nazreen/oft-solana/renounce-freeze branch from 1b9b8eb to 81a98bf Compare January 11, 2025 14:51
@nazreen nazreen requested a review from HansonYip January 11, 2025 14:53
@shankars99
Copy link
Collaborator

would this be ready to merge if the conflicts are resolved?

@nazreen
Copy link
Contributor Author

nazreen commented May 3, 2025

@shankars99 we will not merge this to main as the new instruction is only needed for OFTs that were created before the createOFT script was updated to immediately renounce the Freeze Authority. Else, it will just be bloat as it's an instruction that's never needed and not usable by current OFTs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants