Skip to content

Contract that is integrated with Pancakeswap to exchange any tokens for POOLX DelayVault NFT

License

Notifications You must be signed in to change notification settings

The-Poolz/TokenNFTConnector

Repository files navigation

TokenNFTConnector

Build and Test codecov CodeFactor

Contract that is integrated with Pancakeswap to exchange any tokens for POOLX DelayVault NFT.

Audit report

The audit report is available here: Audit Report

Navigation

Installation

Install the packages:

npm i
yarn

Compile contracts:

npx hardhat compile

Run tests:

npx hardhat test

Run coverage:

npx hardhat coverage

Deploy:

truffle dashboard
npx hardhat run ./scripts/deploy.ts --network truffleDashboard

How it works?

The TokenNFTConnector contract operates in the following steps:

  1. Token Swap:

    • Users call the createLeaderboard function, providing the amount of tokens they want to swap and an array of SwapParams specifying the tokens to swap through and their.
    • The contract uses PancakeSwap's router (ISwapRouter) to execute the token swap. It calculates the path based on the provided swap parameters and swaps the tokens, considering the pool fees.
  2. Fee Deduction:

    • The contract calculates the remaining amount after deducting the project owner fee using the calcMinusFee function.
  3. DelayVault Creation:

    • The remaining amount after fees is then approved for the DelayVaultProvider contract.
    • The contract calls createNewDelayVault on the DelayVaultProvider, associating the newly created DelayVault with the user.
  4. Result:

    • Users receive a POOLX DelayVault NFT associated with the POOLX tokens.

Functionality

Swap tokens

function createLeaderboard(uint256 amountIn, SwapParams[] calldata poolsData) external
    struct SwapParams {
        address token;
        uint24 fee;
    }

Swaps the specified amount of tokens for POOLX DelayVault NFTs. Users provide the amount of tokens to swap and an array of SwapParams specifying the token swap details. The contract concatenates the provided path array with a predefined swap path, where the last path element is always from the paired token to the ERC-20 token (USDT -> POOLX). SwapParams can be empty, which means that the exchange is being used in one path.

tx example

Utility

function getBytes(SwapParams[] calldata data) public view returns (bytes memory result)

Utility function that returns paths in bytes.

Admin

function pause() external onlyOwner

Pauses the contract, preventing further token swaps.

function unpause() external onlyOwner

Unpauses the contract, allowing token swaps to resume.

function withdrawFee() external onlyOwner

Allows the contract owner to withdraw accumulated fees in the form of tokens.

function calcMinusFee(uint256 amount) public view returns (uint256 leftAmount)

Calculates the remaining amount after deducting the project owner fee from the given amount.

function setProjectOwnerFee(uint24 fee) external onlyOwner

Allows the contract owner to set the project owner fee, ensuring it is a valid percentage. Where 10000 is 100%.

Contracts UML

classDiagram

License

The-Poolz Contracts is released under the MIT License.

About

Contract that is integrated with Pancakeswap to exchange any tokens for POOLX DelayVault NFT

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •