Skip to content

Commit

Permalink
withdraw eth
Browse files Browse the repository at this point in the history
  • Loading branch information
0xoc committed Dec 4, 2022
1 parent a7060ad commit 06b4af3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Unitap Pass

Unitap Passes are a VIP pass for Unitap. Normal users have to re-link their BrightID every period and manually choose up to 5 offerings from gas tap, token tap, and prize tap. Addresses holding a Unitap Pass are pre-verified (since they already went through Aura verification) and never have to re-link their BrightID.
A Genesis Pass holder doesn’t even have to visit Unitap to have prize tap offerings delivered to them. The Unitap team will select and deliver a prize tap offering to each holder’s wallet address each period for each Genesis Pass they hold, with no gas or interaction needed.
The more Genesis Passes someone holds, the more prize tap offerings they will have automatically delivered–one offering per Genesis Pass.
Genesis Passes are minted on Eth mainnet, but we can deliver offerings to the same address on other networks. If a non-compatible address is used on another network, we can have the user sign a message (gasless) specifying their preferred delivery address on that network.
Unitap Passes are a VIP pass for Unitap. Normal users have to re-link their BrightID every period and manually choose up to 5 offerings from gas tap, token tap, and prize tap.


# What's in this repo
Expand Down
16 changes: 16 additions & 0 deletions contracts/UnitapPassBatchSale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ struct Batch {

contract UnitapPassBatchSale is Ownable {
uint32 public constant MAX_SALE_COUNT = 2000;

address unitapPass;

uint32 public totalSoldCount;
uint256 public totalSoldValue;

Batch[] public batches;

constructor(address unitapPass_) Ownable() {
Expand All @@ -22,6 +26,7 @@ contract UnitapPassBatchSale is Ownable {

event StartBatch(uint32 batchSize, uint256 price, uint256 batchIndex);
event MultiMint(uint256 batchIndex, address to, uint32 count);
event WithdrawETH(uint256 amount, address to);

error InvalidBatchSize();
error CurrentBatchNotSoldOut();
Expand Down Expand Up @@ -58,7 +63,18 @@ contract UnitapPassBatchSale is Ownable {

batch.soldCount += count;
totalSoldCount += count;
totalSoldValue += batch.price * count;

// refund extra ETH
if (msg.value > batch.price * count) {
payable(msg.sender).transfer(msg.value - batch.price * count);
}

emit MultiMint(batches.length - 1, to, count);
}

function withdrawETH(uint256 amount, address to) public onlyOwner {
payable(to).transfer(amount);
emit WithdrawETH(amount, to);
}
}
29 changes: 29 additions & 0 deletions test/batchSale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,33 @@ describe("Batch Sale", async () => {
expect(await unitapPass.balanceOf(user1.address)).to.equal(190);
expect(await unitapPassBatchSale.totalSoldCount()).to.equal(200);
});

it("should get total sold value", async () => {
expect(await unitapPassBatchSale.totalSoldValue()).to.equal(
ethers.utils.parseEther("2")
);
});

it("should be able to withdraw funds", async () => {
const adminBalanceBefore = await ethers.provider.getBalance(
adminUnitapPassBatchSale.address
);
// withdraw funds
await unitapPassBatchSale
.connect(adminUnitapPassBatchSale)
.withdrawETH(
ethers.utils.parseEther("2"),
adminUnitapPassBatchSale.address
);

// get balance of admin after withdraw
const adminBalanceAfter = await ethers.provider.getBalance(
adminUnitapPassBatchSale.address
);

// check that admin balance increased
expect(adminBalanceAfter).to.be.gt(
adminBalanceBefore.add(ethers.utils.parseEther("1.99"))
);
});
});

0 comments on commit 06b4af3

Please sign in to comment.