📦Airdrop

In this page, we will go over, explain and review the INK! smart contract that associated with the airdrop program and all of its functions.

the following smart contract defines an Airdrop contract that allows users to claim tokens from an airdrop. It includes functionality to collect 50 tokens or 500 tokens from the airdrop, keeping track of the collected status for each account. The contract also provides methods to retrieve the PANX reserve of the airdrop contract and check the airdrop collection status of an account.

Github repository: https://github.com/RottenKiwi/Panorama-Swap-INK-SC/tree/main/airdrop_contract

Errors:

CallerRedeemedAirdrop

This error occurs when the caller has already redeemed their airdrop. It indicates that the user has already claimed tokens from the airdrop and is trying to claim them again, which is not allowed.

Overflow

This error occurs when an overflow condition happens during a calculation. It typically happens when the result of a mathematical operation exceeds the maximum value that can be represented by the data type being used.

PSP22TransferFailed

This error occurs when the transfer of tokens from the PSP22 contract fails. It indicates that there was an issue with transferring tokens from the contract responsible for holding the tokens to the caller's account. This failure could be due to various reasons, such as insufficient token balance or a failed transfer transaction.

Functions:

new (constructor)

The constructor function new is used to initialize a new instance of the AirdropContract struct. It takes an AccountId parameter named panx_contract, representing the PANX PSP22 contract. Inside the constructor, the value of panx_contract is assigned to the panx_psp22 field, and the collected_airdrop field is initialized using the Mapping::default() function. Finally, a new instance of AirdropContract is created with the initialized fields and returned.

collect_50_tokens

The function collect_50_tokens is a message function that allows an account to collect 50 tokens from the airdrop. It takes a mutable reference to self and returns a Result indicating success or an AirDropErrors error.

collect_500_tokens

The function collect_500_tokens is a message function that allows an account to collect 500 tokens from the airdrop. It takes a mutable reference to self and returns a Result indicating success or an AirDropErrors error.

get_airdrop_contract_panx_reserve

The function get_airdrop_contract_panx_reserve is a message function that retrieves the PANX reserve of the airdrop contract. It takes an immutable reference to self and returns the balance of PANX tokens as a Balance value.

user_airdrop_collection_status

The function user_airdrop_collection_status is a message function that retrieves the airdrop collection status of a specific account. It takes a mutable reference to self, an AccountId parameter representing the account for which the collection status is checked, and returns the collection status as an i64 value.

Last updated