APE Staking

This documentation aims to summarize all the related APE staking contract interfaces and their roles.

APE staking at Parallel is offered in multiple forms:

  1. APE only staking with AutoCompounding (cAPE)

  2. Staking APE with a supplied collateral (BAYC/MAYC) with or without a paired BAKC

  3. P2P APE staking matching APE and BAYC/MAYC/BAKC listings

APE only staking with AutoCompounding (cAPE)

To stake APE only in the auto compounding pool, user will use the AutoCompoundApe smart contract to deposit their APE. In return, the user will be minted cAPE token shares, which will represented their staking position.

Interfaces

function deposit(address onBehalf, uint256 amount) external

This interface allows users to deposit their APE tokens into the auto-compounding pool. The onBehalf parameter can be used to deposit tokens on behalf of another address. The amount parameter specifies the amount of APE tokens to deposit.

function convertApeCoinToPCApe(uint256 amount) external 

To deposit APE into AutoCompounding pool and supply the cAPE to the money market in one transaction, we have developed a contract called HelperContract that has the function mentioned above.

function convertPCApeToApeCoin(uint256 amount) external

This function is to withdraw the pcAPE (supplied cAPE ino the money market) back to APE. Which is also in the HelperContract

function withdraw(uint256 amount) external

This interface allows users to withdraw their deposited APE tokens from the auto-compounding pool. The amount parameter specifies the amount of cAPE tokens to withdraw, which will be burned upon withdrawal and the corresponding amount of APE tokens will be transferred back to the user.

    function getShareByPooledApe(uint256 amount)
        external
        view
        returns (uint256);

The getShareByPooledApe interface can be used to get the amount of shares that corresponds to a specified amount of protocol-controlled APE.

This is useful when a user wants to know how many cAPE token shares they will receive for a certain amount of APE tokens before depositing them into the auto-compounding pool.

    function getPooledApeByShares(uint256 sharesAmount)
        external
        view
        returns (uint256);

For more test cases and examples, checkout our github repo

Staking APE with a supplied collateral (BAYC/MAYC) with or without a paired BAKC

After supplying their BAYC/MAYC, users can then stake any amount of APE with their supplied collateral. The contract used for all collateral staking is the Parallel’s main Pool contract.

Interfaces

/**
     * @notice Deposit ape coin to BAYC/MAYC pool or BAKC pool
     * @param stakingInfo Detail info of the staking
     * @param _nfts Array of BAYC/MAYC NFT's with staked amounts
     * @param _nftPairs Array of Paired BAYC/MAYC NFT's with staked amounts
     * @dev Need check User health factor > 1.
     */
    function borrowApeAndStake(
        StakingInfo calldata stakingInfo,
        ApeCoinStaking.SingleNft[] calldata _nfts,
        ApeCoinStaking.PairNftDepositWithAmount[] calldata _nftPairs
    ) external;

    struct StakingInfo {
        // Contract address of BAYC/MAYC
        address nftAsset;
        // address of borrowing asset, can be Ape or cApe
        address borrowAsset;
        // Borrow amount of Ape from lending pool
        uint256 borrowAmount;
        // Cash amount of Ape from user wallet
        uint256 cashAmount;
    }

This interface can be used to stake APE specific supplied collaterals. The APE to be staked can be either provided directly from the user wallet, borrowed from Parallel or a combination of both. this can be specified in the stakingInfo param as outlined above. example of staking info can be:

// borrow 50 APE from Parallel and provide 10 APE directly from user wallet
await pool.borrowApeAndStake(
        {
          nftAsset: bayc.address,
          borrowAsset: ape.address,
          borrowAmount: 50000000000000000000,
          cashAmount: 10000000000000000000,
        },
        [{tokenId: 0, amount: 60000000000000000000}],
        []
      )
// don't borrow APE from Parallel and provide 60 APE directly from user wallet
await pool.borrowApeAndStake(
        {
          nftAsset: bayc.address,
          borrowAsset: ape.address,
          borrowAmount: 0,
          cashAmount: 60000000000000000000,
        },
        [{tokenId: 0, amount: 60000000000000000000}],
        []
      )
// borrow 60 APE from Parallel and don't provide any APE from user wallet
await pool.borrowApeAndStake(
        {
          nftAsset: bayc.address,
          borrowAsset: ape.address,
          borrowAmount: 60000000000000000000,
          cashAmount: 0,
        },
        [{tokenId: 0, amount: 60000000000000000000}],
        []
      )

    function withdrawApeCoin(
        address nftAsset,
        ApeCoinStaking.SingleNft[] calldata _nfts
    ) external;

The withdrawApeCoin interface can be used to withdraw staked ApeCoin from the BAYC/MAYC pool. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the _nfts parameter is an array of BAYC/MAYC NFT's with staked amounts. A user needs to have a health factor greater than 1 after the withdraw in order to withdraw their staked ApeCoin successfully.


    function claimApeCoin(address nftAsset, uint256[] calldata _nfts) external;

The claimApeCoin interface can be used to claim rewards for an array of tokenIds from the BAYC/MAYC pool. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the _nfts parameter is an array of NFTs owned and committed by the msg.sender. A user needs to have a health factor greater than 1 after the claim in order to successfully claim their rewards.


    function withdrawBAKC(
        address nftAsset,
        ApeCoinStaking.PairNftWithdrawWithAmount[] memory _nftPairs
    ) external;

The withdrawBAKC interface can be used to withdraw staked BAKC from the BAYC/MAYC pool. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the _nftPairs parameter is an array of paired BAYC/MAYC NFT's with staked amounts. A user needs to have a health factor greater than 1 after the withdraw in order to withdraw their staked BAKC successfully.


    function claimBAKC(
        address nftAsset,
        ApeCoinStaking.PairNft[] calldata _nftPairs
    ) external;

The claimBAKC interface can be used to claim rewards for an array of paired BAYC/MAYC NFT's from the BAYC/MAYC pool. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the _nftPairs parameter is an array of paired BAYC/MAYC NFT's. A user needs to have a health factor greater than 1 after the claim in order to successfully claim their rewards.

function unstakeApePositionAndRepay(address nftAsset, uint256 tokenId)
        external;

The unstakeApePositionAndRepay interface allows users to unstake their ApeCoin staking position and repay their debt. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the tokenId parameter specifies the token id of the ape staking position. The position owner can call this at anytime. However, anyone can also call this function if the owner’s HF us below 1.

function claimApeAndCompound(
        address nftAsset,
        address[] calldata users,
        uint256[][] calldata tokenIds
    ) external;

The claimApeAndCompound interface can be used to claim user Ape coin rewards and deposit them to ape compound to get cApe, then deposit cApe to lending pool for users. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the users and tokenIds parameters are arrays of user addresses and user tokenId arrays, respectively.

 function claimPairedApeAndCompound(
        address nftAsset,
        address[] calldata users,
        ApeCoinStaking.PairNft[][] calldata _nftPairs
    ) external;

This interface can be used to claim user BAYC/MAYC paired Ape coin rewards and deposit them to ape compound to get cApe, then deposit cApe to lending pool for users. The nftAsset parameter specifies the contract address of BAYC/MAYC, while the users and _nftPairs parameters are arrays of user addresses and paired BAYC/MAYC NFT's arrays, respectively.

For more test cases and examples, checkout our github repo

P2P APE staking matching APE and BAYC/MAYC/BAKC listings

Data Structures

enum StakingType {
    BAYCStaking,
    MAYCStaking,
    BAKCPairStaking
}

enum ListingOrderStatus {
    Pending,
    Matched,
    Cancelled
}

struct ListingOrder {
    StakingType stakingType;
    address offerer;
    address token;
    uint32 tokenId;
    uint32 share;
    uint256 startTime;
    uint256 endTime;
    uint8 v;
    bytes32 r;
    bytes32 s;
}

struct MatchedOrder {
    StakingType stakingType;
    address apeToken;
    uint32 apeTokenId;
    uint32 apeShare;
    uint32 bakcTokenId;
    uint32 bakcShare;
    address apeCoinOfferer;
    uint32 apeCoinShare;
    uint256 apePrincipleAmount;
    bytes32 apeCoinListingOrderHash;
}

Interfaces


    function matchPairStakingList(
        ListingOrder calldata apeOrder,
        ListingOrder calldata apeCoinOrder
    ) external returns (bytes32 orderHash);

The matchPairStakingList interface can be used to match an apeOrder(BAYC/MAYC) with an apeCoinOrder (APE) to pair staking. The apeOrder parameter specifies the BAYC/MAYC owner's listing order, while the apeCoinOrder parameter specifies the APE Coin owner's listing order. The function returns a matched order hash.


    function matchBAKCPairStakingList(
        ListingOrder calldata apeOrder,
        ListingOrder calldata bakcOrder,
        ListingOrder calldata apeCoinOrder
    ) external returns (bytes32 orderHash);

The matchBAKCPairStakingList interface can be used to match an apeOrder(BAYC/MAYC) and a bakcOrder(BAKC) with an apeCoinOrder (APE) to pair staking. The apeOrder parameter specifies the BAYC/MAYC owner's listing order, while the bakcOrder parameter specifies the BAKC owner's listing order. The apeCoinOrder parameter specifies the APE Coin owner's listing order. The function returns a matched order hash.


    function cancelListing(ListingOrder calldata listingOrder) external;

The cancelListing interface allows users to cancel a listing order, which cannot be matched after it has been canceled. The listingOrder parameter specifies the details of the order to be canceled.


    function breakUpMatchedOrder(bytes32 orderHash) external;

The breakUpMatchedOrder interface allows a participant of a matched pair staking order to break it up. The orderHash parameter specifies the hash of the matched order to be broken up. Once broken up, the staking positions will be returned to their original owners.

/**
     * @notice claim pending reward for matched pair staking orders and deposit as cApe for user to compound.
     * @param orderHashes the hash of the matched orders to be break up
     */
    function claimForMatchedOrderAndCompound(bytes32[] calldata orderHashes)
        external;

The claimForMatchedOrderAndCompound interface can be used to claim pending rewards for matched pair staking orders and deposit them as cApe for users to compound. The orderHashes parameter is an array of the hash of the matched orders to be claimed.


    function claimCApeReward(address receiver) external;

The claimCApeReward interface can be used to claim user compounded cApe. The receiver parameter specifies the address of the cApe receiver. This function can be used to claim cApe rewards that have been compounded from user's APE rewards from staking APE with supplied collateral.


    function pendingCApeReward(address user)
        external
        view
        returns (uint256 amount);

The pendingCApeReward interface can be used to check the pending cAPE reward owned by a user. The user parameter specifies the address of the user, while the function returns the amount of cAPE owned by the user that has not yet been claimed. This function can be useful for users who want to keep track of their pending rewards before claiming them.

For more test cases and examples, checkout our github repo

Last updated