wen-community / wen-program-library

Apache License 2.0
90 stars 21 forks source link

Implemented Freeze, Thaw & Burn for Issue #26. Needs testing before merge #36

Closed L0STE closed 8 months ago

L0STE commented 8 months ago

Thaw & Freeze Instruction

Keeping in mind the potential applications for this feature, I followed the very clever and optimized approach from Metaplex.
With this instruction, we prioritize checks on the delegate rather than solely focusing on the NFT Account owner. This choice aims to craft an instruction that prevents users from unstaking their NFTs without the delegate's intervention. The delegate should be a Program Derived Address (PDA) of the Staking program where it will be used.

We start with a first assertion to check that the freeze_authorithy is the manager PDA:

fn assert_freeze_authority(&self) -> Result<()> {
        require!(self.mint.freeze_authority == COption::Some(self.manager.key()), MintErrors::InvalidFreezeAuthority);

        Ok(())
}

Then we leverage the way that the Token Account & FreezeAccount instruction work since:

To finish off this instruction we then use the Freeze instruction to freeze the NFT in place:

let cpi_accounts = FreezeAccount {
            account: self.mint_token_account.to_account_info(),
            mint: self.mint.to_account_info(),
            authority: self.manager.to_account_info(),
};
let cpi_ctx = CpiContext::new_with_signer(self.token_program.to_account_info(), cpi_accounts, signer_seeds);
freeze_account(cpi_ctx)?; 

The only way this NFT can be unfrozen will be if the current delegate of the Token Account uses the Thaw instruction.

Burn

We decided to add a burn instruction because the authority of the CloseMintAccount Extension is the Manager PDA. So to close it forever we need to CPI inside the WNS program.

This instruction:

In the future, once we add a collection_auth as the group extension authority we should be able to decrease the amount of NFT in a group.

balmy-gazebo commented 8 months ago

Can you add unit tests to the e2e test file in clients

balmy-gazebo commented 8 months ago

@L0STE