🔼NFT Upgrading

Explanation how Excoms' NFT Upgrading Program works.

If you'd like this program for your project or would like to integrate something similar, we'll be glad if you reach us through Contact.

What it does?

Upgrading allows you to increases a tier of your Excom NFT. The higher the tier, the bigger the staking reward the NFT generates as described in Tokenomics. When upgrading, you send your NFT, together with GENZ upgrade fee, to Upgrading Program. We detect your request, update your NFT (upgrade happens mostly off-chain) and once the update is done, we finalize the operation through Upgrading Program, that sends NFT back to you.

To understand our NFT Upgrading Program, we describe its PDAs first so you see what data the Program stores.

Once you know all the data, you'll see easily how the program works.

PDAs

There are 3 PDA types used in Upgrading Program

Global PDA

This PDA stores global variables the program needs, namely the vault address that receives GENZ when the upgrade operation finishes successfully.

There is just one Global PDA.

vault: Pubkey

Role PDA

There are 2 special roles (described further) in the program. In this PDA the program stores what is a role of a given address.

There are several Role PDAs (one for each address that has some special role).

address: Pubkey      
role:    u64   

Operation PDA

There is one Operation PDA for each ongoing upgrade operation. creator specifies address that has created the operation, excom is mint address of Excom NFT being upgraded, deposit_amount the amount of GENZ that's been paid and enter_time the time when the operation has been created.

The number of Operation PDAs changes. Once the PDA isn't required any more, it's destroyed, so most of the time, the amount of Operation PDAs is zero.

creator:        Pubkey
excom:          Pubkey
deposit_amount: u64
enter_time:     i64

Logic

Some operations cannot be done by everyone. That's why Upgrading Program defines roles

  • Admin (manages Admins, Updaters, sets vault address)

  • Updater (finishes Upgrade operation)

Information on what address has what role is stored in Role PDA, that's being updated by Admin.

What's the role of Updater? It just calls Upgrade Finish once all the dirty work outside the contract is done. Upgrade Finish closes the operation, sending GENZ and NFT where they should be sent, and destroying corresponding Operation PDA.

What's the dirty work outside the Upgrading Program? There are several things that has to be done (it usually takes several minutes to do all of them)

  • operation has to be detected

  • operation validity has to be checked (whether the user paid enough GENZ)

  • new NFT metadata file has to be generated

  • new NFT image file has to be generated

  • both files has to be uploaded to IPFS storage

  • on-chain NFT metadata has to be updated to point to the new off-chain metadata file

  • NFT tier has to be updated on-chain in NFT Staking Program

  • everything has to be validated

All the interaction with NFT Upgrading Program happens in two steps.

Upgrade Init

You send NFT to Upgrading Program together with GENZ (their amount depends on tier you're upgrading) and approx. 0.01 SOL covering rent-exempt and dirty work fees. You create a new Operation PDA with

  • creator being your address

  • excom mint address of your Excom NFT

  • deposit_amount the amount of GENZ you've paid

  • enter_time the time when you've created the operation

Upgrade Finish

Upgrade has happened outside the contract and Updater comes to finish the operation that can be either successful or not.

If successful, the program sends upgraded NFT back to your wallet and GENZ to vault.

If not successful, the program sends both the original NFT and GENZ you've paid back to your wallet.

In both cases, Operation PDA is being destroyed as it's no longer required.

Conclusion

Isn't this beautiful?

Last updated