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

feat: atomic ntoken #326

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions contracts/protocol/tokenization/NToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
_setSymbol(nTokenSymbol);

require(underlyingAsset != address(0), Errors.ZERO_ADDRESS_NOT_VALID);
_underlyingAsset = underlyingAsset;
_ERC721Data.underlyingAsset = underlyingAsset;
_ERC721Data.rewardController = incentivesController;

emit Initialized(
Expand Down Expand Up @@ -104,7 +104,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {

if (receiverOfUnderlying != address(this)) {
for (uint256 index = 0; index < tokenIds.length; index++) {
IERC721(_underlyingAsset).safeTransferFrom(
IERC721(_ERC721Data.underlyingAsset).safeTransferFrom(
address(this),
receiverOfUnderlying,
tokenIds[index]
Expand Down Expand Up @@ -139,7 +139,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
uint256[] calldata ids
) external override onlyPoolAdmin {
require(
token != _underlyingAsset,
token != _ERC721Data.underlyingAsset,
Errors.UNDERLYING_ASSET_CAN_NOT_BE_TRANSFERRED
);
for (uint256 i = 0; i < ids.length; i++) {
Expand Down Expand Up @@ -192,7 +192,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
override
returns (address)
{
return _underlyingAsset;
return _ERC721Data.underlyingAsset;
}

/// @inheritdoc INToken
Expand All @@ -203,7 +203,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
onlyPool
nonReentrant
{
IERC721(_underlyingAsset).safeTransferFrom(
IERC721(_ERC721Data.underlyingAsset).safeTransferFrom(
address(this),
target,
tokenId
Expand Down Expand Up @@ -235,7 +235,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
uint256 tokenId,
bool validate
) internal virtual {
address underlyingAsset = _underlyingAsset;
address underlyingAsset = _ERC721Data.underlyingAsset;

uint256 fromBalanceBefore;
if (validate) {
Expand Down Expand Up @@ -318,7 +318,7 @@ contract NToken is VersionedInitializable, MintableIncentivizedERC721, INToken {
override
returns (string memory)
{
return IERC721Metadata(_underlyingAsset).tokenURI(tokenId);
return IERC721Metadata(_ERC721Data.underlyingAsset).tokenURI(tokenId);
}

function getXTokenType()
Expand Down
6 changes: 3 additions & 3 deletions contracts/protocol/tokenization/NTokenApeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract contract NTokenApeStaking is NToken, INTokenApeStaking {
ApeStakingLogic.UnstakeAndRepayParams({
POOL: POOL,
_apeCoinStaking: _apeCoinStaking,
_underlyingAsset: _underlyingAsset,
_underlyingAsset: _ERC721Data.underlyingAsset,
poolId: POOL_ID(),
tokenId: tokenId,
incentiveReceiver: address(0),
Expand All @@ -119,7 +119,7 @@ abstract contract NTokenApeStaking is NToken, INTokenApeStaking {
ApeStakingLogic.UnstakeAndRepayParams({
POOL: POOL,
_apeCoinStaking: _apeCoinStaking,
_underlyingAsset: _underlyingAsset,
_underlyingAsset: _ERC721Data.underlyingAsset,
poolId: POOL_ID(),
tokenId: tokenIds[index],
incentiveReceiver: address(0),
Expand Down Expand Up @@ -183,7 +183,7 @@ abstract contract NTokenApeStaking is NToken, INTokenApeStaking {
ApeStakingLogic.UnstakeAndRepayParams({
POOL: POOL,
_apeCoinStaking: _apeCoinStaking,
_underlyingAsset: _underlyingAsset,
_underlyingAsset: _ERC721Data.underlyingAsset,
poolId: POOL_ID(),
tokenId: tokenId,
incentiveReceiver: incentiveReceiver,
Expand Down
24 changes: 14 additions & 10 deletions contracts/protocol/tokenization/NTokenMoonBirds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ contract NTokenMoonBirds is NToken, IMoonBirdBase {

if (receiverOfUnderlying != address(this)) {
for (uint256 index = 0; index < tokenIds.length; index++) {
IMoonBird(_underlyingAsset).safeTransferWhileNesting(
address(this),
receiverOfUnderlying,
tokenIds[index]
);
IMoonBird(_ERC721Data.underlyingAsset).safeTransferWhileNesting(
address(this),
receiverOfUnderlying,
tokenIds[index]
);
}
}

Expand All @@ -72,7 +72,7 @@ contract NTokenMoonBirds is NToken, IMoonBirdBase {
return this.onERC721Received.selector;
}

if (msg.sender == _underlyingAsset) {
if (msg.sender == _ERC721Data.underlyingAsset) {
// supply the received token to the pool and set it as collateral
DataTypes.ERC721SupplyParams[]
memory tokenData = new DataTypes.ERC721SupplyParams[](1);
Expand All @@ -82,7 +82,11 @@ contract NTokenMoonBirds is NToken, IMoonBirdBase {
useAsCollateral: true
});

POOL.supplyERC721FromNToken(_underlyingAsset, tokenData, from);
POOL.supplyERC721FromNToken(
_ERC721Data.underlyingAsset,
tokenData,
from
);
}

return this.onERC721Received.selector;
Expand All @@ -100,7 +104,7 @@ contract NTokenMoonBirds is NToken, IMoonBirdBase {
);
}

IMoonBird(_underlyingAsset).toggleNesting(tokenIds);
IMoonBird(_ERC721Data.underlyingAsset).toggleNesting(tokenIds);
}

/**
Expand All @@ -116,14 +120,14 @@ contract NTokenMoonBirds is NToken, IMoonBirdBase {
uint256 total
)
{
return IMoonBird(_underlyingAsset).nestingPeriod(tokenId);
return IMoonBird(_ERC721Data.underlyingAsset).nestingPeriod(tokenId);
}

/**
@dev an additional function that is custom to MoonBirds reserve.
This function check if nesting is open for the underlying tokens
*/
function nestingOpen() external view returns (bool) {
return IMoonBird(_underlyingAsset).nestingOpen();
return IMoonBird(_ERC721Data.underlyingAsset).nestingOpen();
}
}
14 changes: 8 additions & 6 deletions contracts/protocol/tokenization/NTokenUniswapV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 {
deadline: block.timestamp
});

INonfungiblePositionManager(_underlyingAsset).decreaseLiquidity(
params
);
INonfungiblePositionManager(_ERC721Data.underlyingAsset)
.decreaseLiquidity(params);
}

(
Expand All @@ -87,7 +86,9 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 {
,
,

) = INonfungiblePositionManager(_underlyingAsset).positions(tokenId);
) = INonfungiblePositionManager(_ERC721Data.underlyingAsset).positions(
tokenId
);

address weth = _addressesProvider.getWETH();
receiveEthAsWeth = (receiveEthAsWeth &&
Expand All @@ -101,8 +102,9 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 {
amount1Max: type(uint128).max
});

(amount0, amount1) = INonfungiblePositionManager(_underlyingAsset)
.collect(collectParams);
(amount0, amount1) = INonfungiblePositionManager(
_ERC721Data.underlyingAsset
).collect(collectParams);

if (receiveEthAsWeth) {
uint256 balanceWeth = IERC20(weth).balanceOf(address(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ abstract contract MintableIncentivizedERC721 is
IPool public immutable POOL;
bool public immutable ATOMIC_PRICING;

address internal _underlyingAsset;

/**
* @dev Constructor.
* @param pool The reference to the main Pool contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct MintableERC721Data {
uint64 balanceLimit;
mapping(uint256 => bool) isUsedAsCollateral;
mapping(uint256 => DataTypes.Auction) auctions;
address underlyingAsset;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should still take the same slot 67

// Mapping from owner to list of owned atomic token IDs
mapping(address => mapping(uint256 => uint256)) ownedAtomicTokens;
GopherJ marked this conversation as resolved.
Show resolved Hide resolved
// Mapping from token ID to index of the owned atomic tokens list
Expand Down