Skip to content
Open
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
14 changes: 11 additions & 3 deletions contracts/NFTSingleStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ pragma solidity 0.8.13;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

// Basic NFT staking contract
// Each account can only stake one NFT at a time
contract NFTSingleStaking is Ownable, IERC721Receiver {
contract NFTSingleStaking is IERC721Receiver {

// NFT used for staking
IERC721 public nft;
Expand All @@ -27,7 +26,6 @@ contract NFTSingleStaking is Ownable, IERC721Receiver {

constructor(IERC721 _nft) {
nft = _nft;
Ownable(msg.sender);
}

/// Emitted when an account stakes
Expand All @@ -39,6 +37,11 @@ contract NFTSingleStaking is Ownable, IERC721Receiver {
/// Stake NFT with `tokenId` and tranfer to this contract
/// Sender must approve transfer before calling this function
function stake(uint256 tokenId) external {
_stake(tokenId);
}

/// Internal staking logic
function _stake(uint256 tokenId) internal {
require(!isStaked[msg.sender], "Sender is already staked.");
require(nft.ownerOf(tokenId) == msg.sender, "Sender is not owner of token.");

Expand All @@ -54,6 +57,11 @@ contract NFTSingleStaking is Ownable, IERC721Receiver {

/// Unstake NFT and transfer back to sender
function unstake() external {
_unstake();
}

/// Unstake logic
function _unstake() internal {
require(isStaked[msg.sender], "Sender is not staked");

// get token ID
Expand Down
13 changes: 13 additions & 0 deletions test/NFTPair.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.13;

import {Pair, NFTSingleStaking} from "./";

// TODO: make contracts abstract
// TODO: add mocks
contract NFTPair is NFTSingleStaking, Pair {

constructor() {
}
}
4 changes: 0 additions & 4 deletions test/NFTSingleStaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ describe('NFTSingleStaking', () => {
})

describe('setup', () => {
it('owner is deployer', async () => {
expect(await staking.owner()).to.equal(owner.address)
})

it('nft address is set correctly', async () => {
expect(await staking.nft()).to.equal(nft.address)
})
Expand Down