Key Functions:
getTokenName() & getParityName(): These return the token name (
BNB
) and parity (BNB/PIRI
).getCommission(): Returns the slippage value (0.03).
swapInitialize(): Initializes the swap by setting up parity data such as asks, bids, last price, and daily volume if the user is the scenario owner.
checkMyBNBDeposit(): Checks the BNB deposit in the user's wallet, withdraws BNB if needed, and updates liquidity.
depositToken(): Allows depositing PIRI tokens into the liquidity pool.
getMyDepositWallet(): Returns the wallet address for depositing BNB.
checkWalletInitialization(): Ensures that the wallet is initialized with liquidity, asks, bids, and volume data.
blockWallet() & unBlockWallet(): Blocks or unblocks a wallet from performing operations based on the scenario owner's authorization.
determineAmountForBid() & determineAmountForAsk(): These functions calculate how much PIRI or BNB can be bought or sold based on current ask and bid orders.
buyToken(): Facilitates buying PIRI with BNB, checks for blocked wallets, verifies liquidity, and processes the swap.
sellToken(): Facilitates selling PIRI for BNB, checks for blocked wallets, verifies liquidity, and processes the swap.
getAllSlippages(): Returns the slippage fee in both crypto and tokens.
faucetToOwnerForTesting(): Provides liquidity to the owner's wallet for testing purposes.
Error Handling:
The script includes robust error handling for situations like insufficient funds, blocked wallets, ongoing transactions, incorrect data formats, and unauthorized actions.
Slippage:
Slippage is handled as part of the swap, ensuring that any fees are deducted accordingly when buying or selling tokens.
Example Use Cases
Initializing Trading for a BNB and PIRI Pair: Users can call the
swapInitialize
function to set up the liquidity and order books for BNB and PIRI coins.Placing and Removing Orders: Users can place bids and asks at a specific level (
level
) and quantity (quantity
), or remove them if needed.Withdrawing Liquidity: Users can withdraw their available BNB or PIRI token balances from the system using
withdrawBnbWallet
orwithdrawToken
functions.
This structure can be used to build a DEX protocol on Pirichain, or enhance existing exchange integrations by providing automated, blockchain-based trading and liquidity management.
Last updated