Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrow and stake support pcape #413

Merged
merged 8 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ upgrade-pool-marketplace:
upgrade-pool-ape-staking:
make TASK_NAME=upgrade:pool-ape-staking run-task

.PHONY: upgrade-borrow_ape_and_stake
upgrade-borrow_ape_and_stake:
make TASK_NAME=upgrade:borrow-ape-and-stake run-task

.PHONY: upgrade-pool-parameters
upgrade-pool-parameters:
make TASK_NAME=upgrade:pool-parameters run-task
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IPoolParameters} from "./IPoolParameters.sol";
import {IParaProxyInterfaces} from "./IParaProxyInterfaces.sol";
import {IPoolPositionMover} from "./IPoolPositionMover.sol";
import "./IPoolApeStaking.sol";
import "./IPoolBorrowAndStake.sol";

/**
* @title IPool
Expand All @@ -19,7 +20,8 @@ interface IPool is
IPoolParameters,
IPoolApeStaking,
IParaProxyInterfaces,
IPoolPositionMover
IPoolPositionMover,
IPoolBorrowAndStake
{

}
6 changes: 4 additions & 2 deletions contracts/interfaces/IPoolApeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ interface IPoolApeStaking {
* @param tokenId Token id of the ape staking position on
* @dev Need check User health factor > 1.
*/
function unstakeApePositionAndRepay(address nftAsset, uint256 tokenId)
external;
function unstakeApePositionAndRepay(
address nftAsset,
uint256 tokenId
) external;

/**
* @notice repay asset and supply asset for user
Expand Down
36 changes: 36 additions & 0 deletions contracts/interfaces/IPoolBorrowAndStake.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import "../dependencies/yoga-labs/ApeCoinStaking.sol";

/**
* @title IPoolBorrowAndStake
*
* @notice Defines the basic interface for an ParaSpace Ape Staking Pool.
**/
interface IPoolBorrowAndStake {
struct StakingInfoV2 {
// 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;
address cashAsset;
// Cash amount of Ape from user wallet
uint256 cashAmount;
}

/**
* @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 borrowApeAndStakeV2(
StakingInfoV2 calldata stakingInfo,
ApeCoinStaking.SingleNft[] calldata _nfts,
ApeCoinStaking.PairNftDepositWithAmount[] calldata _nftPairs
) external;
}
53 changes: 25 additions & 28 deletions contracts/protocol/pool/PoolApeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ contract PoolApeStaking is
}

/// @inheritdoc IPoolApeStaking
function claimApeCoin(address nftAsset, uint256[] calldata _nfts)
external
nonReentrant
{
function claimApeCoin(
address nftAsset,
uint256[] calldata _nfts
) external nonReentrant {
DataTypes.PoolStorage storage ps = poolStorage();
_checkSApeIsNotPaused(ps);

Expand Down Expand Up @@ -182,8 +182,8 @@ contract PoolApeStaking is
localVar.bakcNToken
) {
localVar.transferredTokenOwners[
actualTransferAmount
] = _validateBAKCOwnerAndTransfer(
actualTransferAmount
] = _validateBAKCOwnerAndTransfer(
localVar,
_nftPairs[index].bakcTokenId,
msg.sender
Expand Down Expand Up @@ -341,8 +341,8 @@ contract PoolApeStaking is
);

localVar.transferredTokenOwners[
index
] = _validateBAKCOwnerAndTransfer(
index
] = _validateBAKCOwnerAndTransfer(
localVar,
_nftPairs[index].bakcTokenId,
msg.sender
Expand Down Expand Up @@ -405,10 +405,10 @@ contract PoolApeStaking is
}

/// @inheritdoc IPoolApeStaking
function unstakeApePositionAndRepay(address nftAsset, uint256 tokenId)
external
nonReentrant
{
function unstakeApePositionAndRepay(
address nftAsset,
uint256 tokenId
) external nonReentrant {
DataTypes.PoolStorage storage ps = poolStorage();
DataTypes.ReserveData storage nftReserve = ps._reserves[nftAsset];
address xTokenAddress = nftReserve.xTokenAddress;
Expand Down Expand Up @@ -522,8 +522,8 @@ contract PoolApeStaking is
);

localVar.transferredTokenOwners[
j
] = _validateBAKCOwnerAndTransfer(
j
] = _validateBAKCOwnerAndTransfer(
localVar,
_nftPairs[i][j].bakcTokenId,
users[i]
Expand All @@ -549,11 +549,10 @@ contract PoolApeStaking is
_compoundForUsers(ps, localVar, users);
}

function _generalCache(DataTypes.PoolStorage storage ps, address nftAsset)
internal
view
returns (ApeStakingLocalVars memory localVar)
{
function _generalCache(
DataTypes.PoolStorage storage ps,
address nftAsset
) internal view returns (ApeStakingLocalVars memory localVar) {
localVar.xTokenAddress = ps._reserves[nftAsset].xTokenAddress;
localVar.bakcContract = INTokenApeStaking(localVar.xTokenAddress)
.getBAKC();
Expand Down Expand Up @@ -645,10 +644,9 @@ contract PoolApeStaking is
}
}

function _checkSApeIsNotPaused(DataTypes.PoolStorage storage ps)
internal
view
{
function _checkSApeIsNotPaused(
DataTypes.PoolStorage storage ps
) internal view {
DataTypes.ReserveData storage reserve = ps._reserves[
DataTypes.SApeAddress
];
Expand Down Expand Up @@ -746,11 +744,10 @@ contract PoolApeStaking is
_supplyForUser(ps, tokenOut, address(this), user, amountOut);
}

function _getApeRelativePrice(address tokenOut, uint256 tokenOutUnit)
internal
view
returns (uint256)
{
function _getApeRelativePrice(
address tokenOut,
uint256 tokenOutUnit
) internal view returns (uint256) {
IPriceOracleGetter oracle = IPriceOracleGetter(
ADDRESSES_PROVIDER.getPriceOracle()
);
Expand Down
Loading