🔄Azero trading pair

The following page is dedicated for reviewing the source code of the AZERO trading pair smart contract, which facilitate AZERO/PSP22 trading pairs logic.

Users will be able to create their own AZERO/PSP22 trading pairs by creating a liquidity pool and provide AZERO coins and PSP22 tokens as liquidity, the user will also set liquidity pool fee (0.1% - 3%) before initializing the pool.

Users will also be able to transfer and trade liquidity pool share tokens.

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

Errors:

Trading pair contract facilitate all the smart contract errors that might occur during transacting with the smart contract.

CallerInsufficientPSP2Balance

Error that occurs when caller tries to deposit amount of PSP22 that he doesn't own to the liquidity pool and when caller tries to swap amount of PSP22 tokens that he doesn't own.

NotEnoughtAllowance

Error that occurs when caller to swap PSP22 tokens and the contract trading pair contract doesn't have enough to allowance to spend from the caller.

Overflow

Error that occurs when a calculation returns a integer overflow

ZeroSharesGiven

Error that occurs when caller tries to deposit tokens and coins to liquidity pool and the calculated Lp shares are 0

SlippageTolerance

Error that occurs when the estimated shown output has exceed the percentage of difference that the caller has set during execution.

PSP22TransfareFromFailed

Error that occurs when TransferFrom cross contract call fails.

A0TransferFailed

Error that occurs when A0 (Native coin) transfer fails.

CallerInsufficientLPBalance

Error that occurs when caller tries to withdraw liquidity token shares and the caller doesn't have the given amount of LP shares and when the caller wants to approve allowance of LP shares to spender.

ContractOutOfA0

Error that occurs when callers wants to swap using a specific pair and the pair's A0 balance is 0.

ContractOutOfPSP22

Error that occurs when callers wants to swap using a specific pair and the pair's PSP balance is 0.

NotEnoughOwnerLPAllowance

Error that occurs when spender does'nt have enough allowance approved from the owner.

Functions:

new (constuctor)

The function creates a new instance of the TradingPairAzero contract with the initialized variables. The function takes four arguments:

  • psp22_contract: the address of the PSP22 token contract

  • fee: the fee to be charged for LP providers

  • panx_contract: the address of the PANX token contract

  • vault: the address of the vault where traders fees are sent

The function initializes various variables, such as transaction_number, balances, lp_tokens_allowances, total_supply, traders_fee, psp22_lp_fee_vault, azero_lp_fee_vault, contract_overall_generated_psp22_fee, contract_overall_generated_azero_fee, psp22_to_give_in_a_day, account_overall_staking_rewards, account_overall_lp_fee_rewards, last_redeemed, and staking_percentage. Finally, the function returns the new instance of the TradingPairAzero contract with all the initialized variables.

provide_to_pool

The provide_to_pool function is a public function of a smart contract that adds liquidity to a trading pair on a decentralized exchange. It takes in three parameters, namely psp22_deposit_amount, expected_lp_tokens, and slippage. psp22_deposit_amount represents the amount of a certain token (PSP22) that the caller wants to deposit, expected_lp_tokens represents the expected amount of LP tokens that the caller wants to receive in exchange for the PSP22 tokens, and slippage represents the percentage of allowable slippage tolerance.

The function first checks if the caller has enough PSP22 tokens to deposit and if the contract has been granted enough allowance by the caller. If any of these checks fail, the function returns an error. The function then calculates the number of LP tokens to be minted based on the current total supply of LP tokens and the amount of PSP22 tokens being deposited. It then checks if the slippage tolerance is within the acceptable range, and if not, returns an error.

The function then performs a cross-contract call to the PSP22 token contract to transfer the specified amount of PSP22 tokens from the caller to the current contract's account. It checks if the transfer was successful and if not, returns an error. It then updates the LP token balance of the caller by adding the newly calculated shares to the existing LP token balance and increases the total supply of LP tokens. If there are any errors in updating the incentive program for the caller, an error is returned.

Finally, an event is emitted indicating the details of the liquidity pool provision, and the function returns a successful result.

withdraw_specific_amount

The function is a method that allows a user to withdraw a specific number of LP (Liquidity Provider) shares from a liquidity pool. LP shares represent the user's contribution to the pool and are used to earn trading fees. The function takes in the number of LP shares the user wants to withdraw and returns a result that could either be an error or a successful completion of the function.

The function first checks that the user is not trying to withdraw 0 LP shares, and if they are, it returns an error. It then retrieves the user's current LP shares balance from the balances mapping in the contract. If the user does not have enough LP shares to withdraw the specified amount, the function returns an error.

Next, the function calculates the amount of two different types of tokens that the user will receive upon withdrawal. The first type of token is a PSP22 token, and the second type is an A0 token. It also calculates the amount of these tokens that the user earned as a fee from the liquidity pool. These calculations are done using other functions in the contract.

The function then subtracts the specified number of LP shares from the user's LP share balance and updates the balances mapping in the contract. It also subtracts the specified number of LP shares from the total supply of LP shares in the contract.

If the total supply of LP shares becomes zero after the user's withdrawal, the function transfers the remaining PSP22 and A0 tokens in the contract's balance to the user.

The function then updates the user's incentive program claim percentage according to their new LP share balance. It also updates the user's overall rewards earned from the LP fees and subtracts the given amount of PSP22 and A0 tokens from the total vaults of LP fees.

Finally, the function emits an LP withdrawal event and returns a successful result.

get_withdraw_token_amount

This is a function that calculates the amount of A0 and PSP22 tokens that should be given to a user when they withdraw their shares from a trading pair. The function takes in the amount of shares that the user wants to withdraw as input.

First, the function gets the actual balance of A0 tokens and calculates the amount of A0 tokens that should be given to the user based on their shares. It does the same for PSP22 tokens.

Next, the function calculates the amount of A0 and PSP22 tokens that the user earned from LP fees and subtracts these amounts from the previously calculated amounts of A0 and PSP22 tokens to give. Finally, it returns the resulting amounts of A0 and PSP22 tokens as a tuple. If an overflow error occurs during the calculation, the function returns a TradingPairErrors::Overflow error.

get_withdraw_token_amount_with_lp

The get_withdraw_tokens_amount_with_lp function is a public function that returns the amount of A0 and PSP22 tokens that a user will receive when they withdraw a certain amount of liquidity provider (LP) tokens. The function takes in the shares_amount of LP tokens that the user wants to withdraw and returns a Result with a tuple containing the amount of A0 and PSP22 tokens the user will receive if the calculation is successful, or a TradingPairErrors::Overflow error if an overflow occurs during the calculation.

The function first calculates the actual balance of A0 and PSP22 tokens using the get_a0_balance and get_psp22_balance functions. It then multiplies the shares_amount by the actual balance of each token and divides the result by the total supply of LP tokens. This gives the amount of A0 and PSP22 tokens that the user is entitled to receive.

If the calculation is successful, the function returns a tuple containing the amounts of A0 and PSP22 tokens that the user will receive. Otherwise, it returns a TradingPairErrors::Overflow error.

get_psp22_withdraw_tokens_amount

This function calculates the amount of PSP22 tokens that a user can withdraw based on the number of shares they hold in the liquidity pool. The function takes a shares_amount parameter of type Balance, representing the number of shares to calculate the PSP22 tokens for.

The function first retrieves the actual balance of PSP22 tokens held by the contract by calling the get_psp22_balance() function. It then multiplies the shares_amount parameter with the actual PSP22 balance and divides the result by the total_supply of the liquidity pool. The resulting amount is the number of PSP22 tokens to be given to the user when they withdraw.

The function uses the checked_div function to safely perform the division and return a None error if there is an overflow. The calculated amount of PSP22 tokens is then returned as a Result<Balance, TradingPairErrors> with Ok() indicating a successful result and Err() indicating an overflow error.

get_psp22_lp_fee_tokens

The get_psp22_lp_fee_tokens function calculates the amount of PSP22 tokens to give to the caller as a result of the LP fee. It takes in a shares_amount parameter of type Balance, which represents the number of shares the caller wants to withdraw. The function returns a Result type, which contains the calculated amount of PSP22 tokens to give to the caller.

The function first initializes a variable amount_of_psp22_fees_to_give of type Balance to hold the calculated value. It then multiplies the shares_amount parameter by the amount of PSP22 tokens held in the LP fee vault, and divides the result by the total supply of LP tokens. The resulting value represents the share of the LP fee that corresponds to the caller's shares.

If the multiplication and division operation results in an overflow, the function returns an error of type TradingPairErrors::Overflow. Otherwise, the function returns a Result type containing the calculated amount of PSP22 tokens to give to the caller.

get_psp22_difference_by_percentage

This function calculates the percentage difference between the amount of PSP22 tokens a caller would receive with and without fees, based on the caller's LP shares.

First, it obtains the caller's address and the total LP shares the caller has. It then calls the get_psp22_lp_fee_tokens function to calculate the amount of PSP22 fees the caller is entitled to based on their LP shares. The result of this calculation is stored in the amount_of_psp22_fees variable.

The function then calls get_psp22_withdraw_tokens_amount to calculate the amount of PSP22 tokens the caller would receive without fees, based on their LP shares. The result is stored in psp22_amount_without_fees.

Next, the function calculates the amount of PSP22 tokens the caller would receive with fees by adding the psp22_amount_without_fees and amount_of_psp22_fees variables together. The result is stored in psp22_amount_with_fees.

The function then calls the check_difference function to calculate the percentage difference between psp22_amount_without_fees and psp22_amount_with_fees. The result is stored in percentage_diff.

Finally, the function returns the percentage_diff variable as the result of the function call. If any errors occur during the calculations, such as overflow errors, the function returns a TradingPairErrors error.

get_a0_withdraw_tokens_amount

This is a function that calculates the amount of A0 tokens that a user can withdraw from the liquidity pool.

The function takes one argument: the number of LP shares the user wishes to withdraw. It then calculates the actual A0 balance available in the liquidity pool and uses it to calculate the amount of A0 tokens to give to the caller by multiplying the number of LP shares with the actual A0 balance and dividing the result by the total supply of LP shares.

If the calculated result is within the range of the Balance data type, it returns the amount of A0 tokens to give to the caller wrapped in a Result type with an Ok variant. If the result overflows the Balance data type, it returns an error wrapped in a Result type with a TradingPairErrors::Overflow variant.

get_a0_lp_fee_tokens

This function calculates the amount of A0 tokens that should be given to the caller as a liquidity provider fee based on the number of LP (liquidity provider) shares they hold.

The function takes in a shares_amount parameter that represents the number of LP shares that the caller wishes to withdraw. The function then calculates the amount of A0 token fees to give to the caller by multiplying the number of shares by the azero_lp_fee_vault, which is the percentage fee charged by the contract for providing liquidity in A0 tokens.

The result of the multiplication is then divided by the total_supply of LP shares to get the amount of A0 tokens that should be given to the caller. If the result is valid, it is returned to the caller in a Result object as an Ok value. If the result overflows, the function returns an error in a Result object as an Err value of the TradingPairErrors::Overflow type.

get_a0_difference_by_percentage

The function get_a0_difference_by_percentage calculates the difference in percentage between the amount of A0 tokens that a caller would receive if they withdrew their LP tokens without paying the LP fees, and the amount they would receive if they paid the LP fees.

To calculate this, the function first obtains the caller's address and their total LP shares. It then calculates the amount of A0 LP fees that the caller needs to pay using the get_a0_lp_fee_tokens function.

The function then calculates the amount of A0 tokens that the caller would receive without paying the LP fees using the get_a0_withdraw_tokens_amount function. It then adds the LP fees to this amount to get the total amount of A0 tokens the caller would receive if they paid the LP fees.

The function then calculates the percentage difference between the two amounts using the check_difference function, which takes in two Balance arguments and returns the percentage difference between them as a Balance.

Finally, the function returns the percentage difference as a Result<Balance, TradingPairErrors> where TradingPairErrors is an error enum that contains the possible errors that can occur during the function's execution.

get_account_locked_tokens

The get_account_locked_tokens function takes an AccountId as input and returns the amount of locked A0 and PSP22 tokens for that account. It starts by getting the caller's LP tokens amount from the balances mapping. If the caller doesn't have any LP tokens, the function returns 0 for both A0 and PSP22.

Next, it gets the actual A0 balance of the contract by calling get_a0_balance. Then, it calculates the amount of A0 to give to the caller based on their LP tokens amount. This is done by multiplying the caller's LP tokens with the actual A0 balance and dividing the result by the total supply of LP tokens.

The function then gets the actual PSP22 balance of the contract by calling get_psp22_balance, and divides it by 10^12 to get the actual amount of PSP22 tokens. It then calculates the amount of PSP22 tokens to give to the caller in a similar way as A0 tokens, using the caller's LP tokens amount, actual PSP22 balance, and total supply of LP tokens.

Lastly, the function multiplies the calculated amount of PSP22 tokens with 10^12 to get the actual amount of PSP22 tokens (since it was divided by 10^12 earlier), and returns a tuple of (actual_amount_of_psp22_to_give,amount_of_a0_to_give) where actual_amount_of_psp22_to_give is the actual amount of PSP22 tokens to give to the caller and amount_of_a0_to_give is the calculated amount of A0 tokens to give to the caller.

get_expected_lp_token_amount

This function calculates the amount of LP tokens to be issued to a user who deposits a certain amount of A0 tokens into the liquidity pool. If this is the first LP deposit for the trading pair, the function will issue a fixed amount of 1000 LP tokens. Otherwise, the function will calculate the number of LP tokens to be issued based on the proportion of A0 tokens being deposited compared to the current total supply of A0 tokens in the liquidity pool. The function calculates this by multiplying the A0 deposit amount with the current total supply of LP tokens and dividing the result by the current A0 balance in the liquidity pool. The resulting value is the number of LP tokens to be issued to the user. If there is an overflow error during the calculation, the function returns a TradingPairErrors::Overflow error. The resulting LP token amount is returned as a Balance value.

get_price_for_one_psp22

The function get_price_for_one_psp22 calculates the estimated price of one PSP22 token in terms of A0 tokens. It does this by calling the get_est_price_psp22_to_a0 function with an input of 1 PSP22 token represented in the smallest unit (10^12) and returns the resulting estimated price of that amount in A0 tokens.

get_est_price_psp22_to_a0

This function calculates the estimated price of one A0 token in terms of PSP22 tokens based on the input amount of PSP22 tokens. It first fetches the caller's current PSP22 balance, calculates the actual LP fee, and subtracts it from the input PSP22 amount. If the caller has more than 3500 PANX, it may be eligible for the incentive program, and the LP fee reduction may be adjusted accordingly. Then, the function calculates the final A0 amount to transfer to the caller based on the remaining PSP22 amount and the A0 and PSP22 token balances of the contract. If the calculations result in an overflow, the function returns an error.

get_est_price_a0_to_psp22_for_swap

This function calculates the estimated price for a swap between two tokens: A0 and PSP22. It takes in the amount of A0 tokens to be swapped and returns the estimated amount of PSP22 tokens that the caller will receive. The function first calculates the A0 contract reserve before the transaction, then subtracts the LP fee from the A0 amount in and calculates the actual LP fee. If the caller has more than 3500 PANX tokens and the LP fee is less than or equal to 1.4%, half of the LP fee is subtracted from the A0 amount in, otherwise, (LP fee - 1) of the LP fee is subtracted. Finally, it calculates the final PSP22 amount to transfer to the caller based on the A0 and PSP22 reserves and the amount of A0 tokens being swapped. The function returns a Result type indicating success or error with the estimated PSP22 amount or a TradingPairErrors enum if there is an overflow during the calculation.

get_est_price_a0_to_psp22

This is a function in Rust programming language that calculates the estimated price of a PSP22 token based on the amount of A0 tokens a user wants to trade. It takes in the amount of A0 tokens as input, checks the current balance of the caller's PSP22 tokens, and calculates the LP (Liquidity Provider) fee for the trade. If the caller has more than 3500 PANX tokens and the LP fee is less than 1.4%, the LP fee is halved, otherwise, it is reduced by 1. After calculating the LP fee, the function calculates the final amount of PSP22 tokens to transfer to the caller based on the A0-PSP22 exchange rate and the LP fee. If any arithmetic overflow occurs during these calculations, an error of TradingPairErrors::Overflow is returned. Finally, the function returns the estimated amount of PSP22 tokens that the caller will receive if they make the trade.

get_price_impact_psp22_to_a0

The function get_price_impact_psp22_to_a0 calculates the price impact of swapping a given amount of PSP22 tokens to A0 tokens. It first calculates the actual LP fee, then fetches the estimated amount of A0 tokens the caller would get if they were to perform the swap, and reduces the LP fee from the PSP22 amount in. Finally, it calculates the final future A0 amount to transfer to the caller by taking into account the reduction in the PSP22 balance and the increase in the A0 balance due to the swap, and returns it.

get_price_impact_a0_to_psp22

The get_price_impact_a0_to_psp22 function takes an input amount of token A0 and returns the price impact in token PSP22 that would occur if the input amount were swapped for PSP22. The function first calculates the actual LP fee and subtracts it from the input A0 amount. Then, it estimates the current amount of PSP22 that the caller would receive if they swapped the input A0 amount, and calculates the final future PSP22 amount to transfer to the caller. Finally, the function returns the price impact in PSP22.

swap_psp22

The swap_psp22 function swaps PSP22 tokens for A0 coins, with fees applied to each transfer. The function first checks that the contract has enough PSP22 tokens and A0 coins, and that the caller has enough PSP22 tokens and the contract has sufficient allowance to proceed with the transfer. It then calculates the amount of A0 coins that will be given to the caller after reducing the trader and LP fees, and calculates the amounts of A0 coins and PSP22 tokens to allocate to the vault and LP vault. Finally, the function transfers the PSP22 tokens from the caller to the contract, and allocates the A0 coins and PSP22 tokens to the appropriate accounts.

swap_a0

The swap_a0 function is a smart contract function that swaps A0 coins for PSP22 tokens and allocates fees to various accounts. The function receives as input the amount of PSP22 tokens to validate, and the allowed slippage. The function checks that the contract has enough PSP22 tokens and A0 coins, calculates the amount of PSP22 tokens to give to the caller after traders fee and slippage is subtracted, calculates the amount of PSP22 tokens to allocate to the vault and the lp vault, and calculates the amount of A0 coins to allocate to the vault account. Finally, the function calls the PSP22 contract to transfer the tokens and returns an error if the transfer failed.

transfer_lp_tokens

The function transfer_lp_tokens takes two parameters: a recipient's AccountId and the number of LP tokens to transfer as a Balance type. The function transfers LP tokens from the caller's account to the recipient's account, and updates their respective balances in the contract's state.

The function first checks if the caller has sufficient LP tokens to transfer, and if not, returns an error. It then calculates the new LP token balance of the caller and recipient after the transfer, and updates their balances in the contract's state. If any overflow occurs during the balance calculation, the function returns an error of type TradingPairErrors::Overflow. Finally, the function returns Ok(()) to indicate a successful execution.

approve_lp_tokens

The approve_lp_tokens is function that allows the caller to approve a specific amount of LP tokens to be spent by a given spender account. It first checks if the caller has enough LP tokens to approve the given amount and returns an error if not. It then checks for any overflow and returns an error if the given amount exceeds the maximum value. Finally, it updates the allowance for the spender account and returns Ok(()).

transfer_lp_tokens_from_to

The transfer_lp_tokens_from_to function transfers LP tokens from one account to another, where the caller must be an approved spender of the LP tokens. The function checks if the owner has enough LP tokens to transfer and if the spender has enough allowance to transfer on behalf of the owner. If the checks pass, the function transfers the LP tokens, updates the balances of the accounts, and the allowance of the spender. If there is an overflow during the calculation, it returns an error.

update_incentive_program

This function updates the incentive program for a given caller. It calculates the amount of PSP22 tokens to give to the caller without LP fee, then calculates the amount of PSP22 tokens to give to the user per day based on the staking percentage. It then inserts the daily amount of PSP22 tokens and AZERO to give to the caller, as well as updates the timestamp of the last redeemed tokens.

get__psp22_redeemable_amount

This is a function that calculates the amount of PSP22 tokens that a user can redeem based on the time that has passed since their last redemption. It first retrieves the user's account balance, locked PSP22 balance, last redemption timestamp, and daily PSP22 amount to give. It then calculates the number of days between the current timestamp and the last redemption timestamp and uses this to determine the total PSP22 tokens that the user is eligible to redeem. It also includes error handling to ensure that the user has sufficient balances and that the division does not result in overflow. Finally, it returns the PSP22 tokens that the user is eligible to redeem.

redeem_redeemable_amount

This is a function for redeeming PSP22 tokens that have been accrued by staking LP tokens. It calculates the amount of PSP22 tokens that the caller is eligible to redeem, based on the number of days since their last redemption, and transfers the tokens to the caller's address via a cross-contract call to the PSP22 contract. The function also updates the caller's overall staking rewards and sets their last redemption timestamp to the current time. If the transfer of PSP22 tokens fails, an error is returned.

remove_lp

The remove_lp function removes liquidity from the trading pair by reducing the LP share balance. If the new share balance is zero, the caller is rewarded with their staking rewards. If the new share balance is greater than zero, the caller's staking rewards are redeemed and a new daily amount of PSP22 tokens to be given to the user is calculated based on their new locked PSP22 balance with the LP fee. The function returns Ok(()) if the operation is successful, or an error of TradingPairErrors if any issues arise during the process.

get_lp_tokens_allowance

This is a public get_lp_tokens_allowance function that takes in two parameters owner and spender, both of type AccountId and returns the LP tokens allowance approved by the owner to the spender. It does this by retrieving the allowance from the lp_tokens_allowances mapping and returning the value, or returning 0 if the mapping does not contain the key.

get_amount_to_give_each_day_to_caller

This function retrieves the amount of PSP22 tokens to be given each day to a specified account holder caller. It retrieves this amount from a psp22_to_give_in_a_day mapping that stores the daily amount of PSP22 and AZERO tokens to give to each LP. If there is no daily amount set for the specified caller, it returns 0.

get_generated_lp_fees

The get_generated_lp_fees function returns a tuple containing the amount of PSP22 and AZERO tokens generated from the LP fees. The function retrieves the values stored in the psp22_lp_fee_vault and azero_lp_fee_vault variables, which represent the total amount of PSP22 and AZERO tokens generated from the LP fees, respectively. These values are returned as a tuple.

get_account_overall_staking_rewards

The get_account_overall_staking_rewards function is a public function that takes an owner account ID as input and returns the overall amount of PSP22 staking rewards earned by the owner. It retrieves the staking rewards amount associated with the provided owner from the account_overall_staking_rewards storage map, or returns 0 if there are no rewards associated with that account. The function then returns the retrieved value.

get_account_overall_lp_fee_rewards

The get_account_overall_staking_rewards function is a public function that takes an owner account ID as input and returns the overall amount of PSP22 staking rewards earned by the owner. It retrieves the staking rewards amount associated with the provided owner from the account_overall_staking_rewards storage map, or returns 0 if there are no rewards associated with that account. The function then returns the retrieved value.

get_contract_overall_generated_fee

The get_contract_overall_generated_fee function returns a tuple of two balances representing the overall generated PSP22 and AZERO fees by the contract. These values are fetched from self.contract_overall_generated_psp22_fee and self.contract_overall_generated_azero_fee fields respectively.

get_account_id

The get_account_id function is a public function that returns the account ID of the contract, which is the address where the contract is deployed. It simply calls the static env() function provided by the ink library, which gives access to the environment of the contract, and then calls the account_id() function on that environment to get the account ID.

get_current_price

The get_current_price function returns the current price of the PSP22 token in terms of AZERO token. It does so by calling the get_est_price_psp22_to_a0 function with an argument of 1 trillion units of PSP22, and then returning the resulting price. This price is an estimate based on the current state of the contract and the amount of liquidity available for each token.

get_total_supply

This function returns the total supply of LP shares, which is a representation of the total number of LP tokens that have been issued by the contract. The function simply returns the total_supply field of the contract.

get_a0_balance

This function returns the current balance of the contract's account, denominated in the contract's native token A0. The balance is obtained using the env().balance() function provided by the ink! framework, which returns the current balance of the contract's account in units of the contract's native token. The function then returns this balance as a Balance type.

get_lp_token_of

The get_lp_token_of function is a public message that takes an AccountId parameter and returns the balance of LP tokens held by that account. It does so by looking up the account's balance in the balances storage map and returning it. If the account is not found in the map, it returns zero.

get_psp22_balance

The function get_psp22_balance is a public function that returns the balance of the PSP22 token in the current contract account. The balance is obtained by calling the balance_of function of the PSP22Ref smart pointer, passing as arguments the reference to the PSP22 token and the current contract account ID. The resulting balance is returned as a Balance value.

get_fee

The get_fee function is a public function that returns the value of the LP fee set in the contract. It retrieves the value of the fee from the fee variable defined in the contract and returns it. The fee is a configurable parameter set by the contract owner that is charged on every transaction made in the contract.

get_transactions_num

This function returns the number of transactions that have been processed by the smart contract. The function simply retrieves the transasction_number variable and returns it as an i64 integer.

check_diffrenece

This function takes two Balance values as input and calculates the percentage difference between them. It then returns the percentage difference as a Balance. The function first calculates the absolute difference between the two values and then calculates the percentage difference as the absolute difference divided by the average of the two values, multiplied by 100. If the calculation of the percentage difference overflows, an error of type TradingPairErrors::Overflow is returned.

Last updated