Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oft-solana): create new instruction for renouncing freeze authority #1144

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nazreen
Copy link
Contributor

@nazreen nazreen commented Jan 3, 2025

WARNING: do not use this code yet as it is unreviewed and unaudited

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> --token-mint <MINT_ADDRESS> --token-escrow <TOKEN_ESCROW_ADDRESS> --multisig <MULTISIG_ADDRESS>

TODOS

  • support case where admin is a multisig
  • compute unit price scalar factor, use it
  • maybe remove need to pass in oftStore since we can derive that based on the tokenEscrow address

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()

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.

1 participant