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
16 changes: 8 additions & 8 deletions contracts/solidity/NFTXV1Buyout.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IV1Token is IERC20Upgradeable {

contract NFTXV1Buyout is PausableUpgradeable, ReentrancyGuardUpgradeable {
uint256 constant BASE = 10*18;
mapping(address => uint256) public ethAvailiable;
mapping(address => uint256) public ethAvailable;

event TokenBuyout(address tokenAddress, uint256 totalEth);
event BuyoutComplete(address tokenAddress);
Expand All @@ -28,28 +28,28 @@ contract NFTXV1Buyout is PausableUpgradeable, ReentrancyGuardUpgradeable {
}

function clearBuyout(address v1TokenAddr) external onlyOwner {
ethAvailiable[v1TokenAddr] = 0;
ethAvailable[v1TokenAddr] = 0;
emit BuyoutComplete(v1TokenAddr);
}

function addBuyout(address v1TokenAddr) external payable onlyOwner {
require(msg.value > 0, "Cannot pair with 0 ETH");
ethAvailiable[v1TokenAddr] += msg.value;
ethAvailable[v1TokenAddr] += msg.value;

emit TokenBuyout(v1TokenAddr, msg.value);
}

function removeBuyout(address v1TokenAddr) external onlyOwner {
uint256 amount = ethAvailiable[v1TokenAddr];
uint256 amount = ethAvailable[v1TokenAddr];
require(amount > 0, "Cannot remove 0");
ethAvailiable[v1TokenAddr] = 0;
ethAvailable[v1TokenAddr] = 0;
sendValue(payable(msg.sender), amount);
emit BuyoutComplete(v1TokenAddr);
}

function claimETH(address v1TokenAddr) external nonReentrant {
onlyOwnerIfPaused(0);
uint256 ethAvail = ethAvailiable[v1TokenAddr];
uint256 ethAvail = ethAvailable[v1TokenAddr];
require(ethAvail > 0, "Not a valid buyout token");

uint256 userBal = IV1Token(v1TokenAddr).balanceOf(msg.sender);
Expand All @@ -58,11 +58,11 @@ contract NFTXV1Buyout is PausableUpgradeable, ReentrancyGuardUpgradeable {
IV1Token(v1TokenAddr).burnFrom(msg.sender, userBal);
uint256 ethToSend = (ethAvail * userBal)/totalSupply;
ethToSend = ethToSend > ethAvail ? ethAvail : ethToSend;
ethAvailiable[v1TokenAddr] -= ethToSend;
ethAvailable[v1TokenAddr] -= ethToSend;
(bool success, ) = msg.sender.call{ value: ethToSend }("");
require(success, "Address: unable to send value, recipient may have reverted");

if (ethAvailiable[v1TokenAddr] == 0) {
if (ethAvailable[v1TokenAddr] == 0) {
emit BuyoutComplete(v1TokenAddr);
}
}
Expand Down
38 changes: 19 additions & 19 deletions test/v1-buyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("V1 Buyout", function () {
"Cannot pair with 0 ETH"
);
});

it("Should not initiailzie again", async () => {
await expectException(
buyout.__NFTXV1Buyout_init(),
Expand All @@ -65,8 +65,8 @@ describe("V1 Buyout", function () {
});

it("Should allow the owner to set a buyout with 4 eth", async () => {
await buyout.addBuyout(xToken.address, {value: ethers.utils.parseEther("4")})
expect(await buyout.ethAvailiable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
await buyout.addBuyout(xToken.address, { value: ethers.utils.parseEther("4") })
expect(await buyout.ethAvailable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
expect(await ethers.provider.getBalance(buyout.address)).to.equal(ethers.utils.parseEther("4"))
});

Expand All @@ -76,14 +76,14 @@ describe("V1 Buyout", function () {
let newBal = await ethers.provider.getBalance(primary.address);
expect(await ethers.provider.getBalance(buyout.address)).to.equal("0")
expect(newBal).to.gt(oldBal.add(ethers.utils.parseEther("4")).sub(ethers.utils.parseEther("0.1")))
expect(await buyout.ethAvailiable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
expect(await buyout.ethAvailable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
await buyout.clearBuyout(xToken.address);
expect(await buyout.ethAvailiable(xToken.address)).to.equal("0")
expect(await buyout.ethAvailable(xToken.address)).to.equal("0")
})

it("Should allow the owner to add back a buyout with 4 eth", async () => {
await buyout.addBuyout(xToken.address, {value: ethers.utils.parseEther("4")})
expect(await buyout.ethAvailiable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
await buyout.addBuyout(xToken.address, { value: ethers.utils.parseEther("4") })
expect(await buyout.ethAvailable(xToken.address)).to.equal(ethers.utils.parseEther("4"))
expect(await ethers.provider.getBalance(buyout.address)).to.equal(ethers.utils.parseEther("4"))
});

Expand Down Expand Up @@ -127,15 +127,15 @@ describe("V1 Buyout", function () {
})

it("Should allow the owner to set a buyout with 10 eth", async () => {
await buyout.addBuyout(xToken2.address, {value: ethers.utils.parseEther("10")})
expect(await buyout.ethAvailiable(xToken2.address)).to.equal(ethers.utils.parseEther("10"))
await buyout.addBuyout(xToken2.address, { value: ethers.utils.parseEther("10") })
expect(await buyout.ethAvailable(xToken2.address)).to.equal(ethers.utils.parseEther("10"))
expect(await ethers.provider.getBalance(buyout.address)).to.equal(ethers.utils.parseEther("10"))
});

it("Should mint fractions of tokens for everyone", async () => {
await xToken2.connect(alice).mint(await alice.getAddress(), ethers.utils.parseEther("2.5"));
await xToken2.connect(bob).mint(await bob.getAddress(), ethers.utils.parseEther("3.33"));
await xToken2.connect(charlie).mint(await charlie.getAddress(), ethers.utils.parseEther((10-2.5-3.33).toString()));
await xToken2.connect(charlie).mint(await charlie.getAddress(), ethers.utils.parseEther((10 - 2.5 - 3.33).toString()));
});

it("Should be able to claim a 1/3rd of eth for 1/3rd of tokens", async () => {
Expand All @@ -151,8 +151,8 @@ describe("V1 Buyout", function () {

it("Should allow the owner to set another concurrent buyout with 10 eth", async () => {
let oldBuyoutBal = await ethers.provider.getBalance(buyout.address);
await buyout.addBuyout(xToken3.address, {value: ethers.utils.parseEther("10")})
expect(await buyout.ethAvailiable(xToken3.address)).to.equal(ethers.utils.parseEther("10"))
await buyout.addBuyout(xToken3.address, { value: ethers.utils.parseEther("10") })
expect(await buyout.ethAvailable(xToken3.address)).to.equal(ethers.utils.parseEther("10"))
expect(await ethers.provider.getBalance(buyout.address)).to.equal(oldBuyoutBal.add(ethers.utils.parseEther("10")))
});

Expand All @@ -163,25 +163,25 @@ describe("V1 Buyout", function () {
});

it("Should be able to claim a portion of eth for a portion of tokens", async () => {
await xToken2.connect(charlie).approve(buyout.address, ethers.utils.parseEther((10-2.5-3.33).toString()));
await xToken2.connect(charlie).approve(buyout.address, ethers.utils.parseEther((10 - 2.5 - 3.33).toString()));
let oldBal = await ethers.provider.getBalance(charlie.address);
let oldBuyoutBal = await ethers.provider.getBalance(buyout.address);
await buyout.connect(charlie).claimETH(xToken2.address)
let newBal = await ethers.provider.getBalance(charlie.address);
let newBuyoutBal = await ethers.provider.getBalance(buyout.address);
expect(newBal).to.be.gt(oldBal.add(ethers.utils.parseEther((10-2.5-3.33).toString()).sub(ethers.utils.parseEther("0.1"))))
expect(newBuyoutBal).to.equal(oldBuyoutBal.sub(ethers.utils.parseEther((10-2.5-3.33).toString())))
expect(newBal).to.be.gt(oldBal.add(ethers.utils.parseEther((10 - 2.5 - 3.33).toString()).sub(ethers.utils.parseEther("0.1"))))
expect(newBuyoutBal).to.equal(oldBuyoutBal.sub(ethers.utils.parseEther((10 - 2.5 - 3.33).toString())))
});

it("Should allow the owner to remove a buyout and receive proper amount of eth", async () => {
let oldBal = await ethers.provider.getBalance(primary.address);
let oldBuyoutBal = await ethers.provider.getBalance(buyout.address);
let oldEth = await buyout.ethAvailiable(xToken2.address);
let oldEth = await buyout.ethAvailable(xToken2.address);
await buyout.removeBuyout(xToken2.address)
let newBal = await ethers.provider.getBalance(primary.address);
let newBuyoutBal = await ethers.provider.getBalance(buyout.address);
expect(await buyout.ethAvailiable(xToken2.address)).to.equal("0")
expect(await buyout.ethAvailiable(xToken3.address)).to.equal(ethers.utils.parseEther("10"))
expect(await buyout.ethAvailable(xToken2.address)).to.equal("0")
expect(await buyout.ethAvailable(xToken3.address)).to.equal(ethers.utils.parseEther("10"))
expect(newBuyoutBal).to.equal(oldBuyoutBal.sub(oldEth))
expect(newBal).to.be.gt(oldBal.add(oldEth).sub(ethers.utils.parseEther("0.15")))
});
Expand All @@ -194,7 +194,7 @@ describe("V1 Buyout", function () {
let newBal = await ethers.provider.getBalance(alice.address);
let newBuyoutBal = await ethers.provider.getBalance(buyout.address);
expect(await ethers.provider.getBalance(buyout.address)).to.equal(ethers.utils.parseEther("7.5"))
expect(await buyout.ethAvailiable(xToken3.address)).to.equal(ethers.utils.parseEther("7.5"))
expect(await buyout.ethAvailable(xToken3.address)).to.equal(ethers.utils.parseEther("7.5"))
expect(newBal).to.be.gt(oldBal.add(ethers.utils.parseEther("2.5").sub(ethers.utils.parseEther("0.1"))))
expect(newBuyoutBal).to.equal(oldBuyoutBal.sub(ethers.utils.parseEther("2.5")))
});
Expand Down