Skip to content

Commit

Permalink
feat(billboard): use ERC-20 token instead of native token
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Dec 21, 2023
1 parent ee3395f commit e47370a
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 126 deletions.
62 changes: 31 additions & 31 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testAddToWhitelist() (gas: 35114)
BillboardTest:testApproveAndTransfer() (gas: 162512)
BillboardTest:testCalculateTax() (gas: 21782)
BillboardTest:testCannnotWithdrawTaxIfSmallAmount(uint8) (runs: 256, μ: 418269, ~: 424925)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 379035)
BillboardTest:testCalculateTax() (gas: 21760)
BillboardTest:testCannnotWithdrawTaxIfSmallAmount(uint8) (runs: 256, μ: 519606, ~: 524472)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 490270)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 9037)
BillboardTest:testCannotApproveByAttacker() (gas: 130271)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 579292)
BillboardTest:testCannotApproveByAttacker() (gas: 130304)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 699798)
BillboardTest:testCannotClearAuctionOnNewBoard() (gas: 136253)
BillboardTest:testCannotMintBoardByAttacker() (gas: 13321)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 138273)
BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 623750, ~: 630370)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 246276)
BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 749693, ~: 754800)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 9104)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 127438)
BillboardTest:testCannotSetBoardProprtiesByAttacker() (gas: 157292)
Expand All @@ -29,35 +29,35 @@ BillboardTest:testCannotSetTaxRateByAttacker() (gas: 9006)
BillboardTest:testCannotTransferByOperator() (gas: 132771)
BillboardTest:testCannotTransferToZeroAddress() (gas: 128258)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9128)
BillboardTest:testCannotWithBidTwice(uint96) (runs: 256, μ: 901993, ~: 901993)
BillboardTest:testCannotWithdrawBidIfAuctionNotCleared(uint96) (runs: 256, μ: 742413, ~: 742413)
BillboardTest:testCannotWithdrawBidIfAuctionNotEnded(uint96) (runs: 256, μ: 618541, ~: 618541)
BillboardTest:testCannotWithdrawBidIfNotFound() (gas: 414332)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 710358, ~: 710358)
BillboardTest:testCannotWithBidTwice(uint96) (runs: 256, μ: 1079596, ~: 1079596)
BillboardTest:testCannotWithdrawBidIfAuctionNotCleared(uint96) (runs: 256, μ: 910976, ~: 910976)
BillboardTest:testCannotWithdrawBidIfAuctionNotEnded(uint96) (runs: 256, μ: 725647, ~: 725647)
BillboardTest:testCannotWithdrawBidIfNotFound() (gas: 428057)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 833971, ~: 833971)
BillboardTest:testCannotWithdrawTaxByAttacker() (gas: 16677)
BillboardTest:testClearAuctionIfAuctionEnded() (gas: 623626)
BillboardTest:testClearAuctionsIfAuctionEnded() (gas: 1156359)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 2878685, ~: 1412103)
BillboardTest:testGetTokenURI() (gas: 154980)
BillboardTest:testClearAuctionIfAuctionEnded() (gas: 743933)
BillboardTest:testClearAuctionsIfAuctionEnded() (gas: 1376419)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 4716997, ~: 2077258)
BillboardTest:testGetTokenURI() (gas: 154936)
BillboardTest:testMintBoard() (gas: 225541)
BillboardTest:testMintBoardByWhitelist() (gas: 154942)
BillboardTest:testMintBoardIfOpened() (gas: 145715)
BillboardTest:testPlaceBidByWhitelist() (gas: 461646)
BillboardTest:testPlaceBidIfAuctionEnded() (gas: 905458)
BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 510257, ~: 521365)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 736177, ~: 744573)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 735897, ~: 748506)
BillboardTest:testPlaceBidZeroPrice() (gas: 355447)
BillboardTest:testPlaceBidByWhitelist() (gas: 579075)
BillboardTest:testPlaceBidIfAuctionEnded() (gas: 1090505)
BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 619050, ~: 635095)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 904667, ~: 913141)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 907776, ~: 917960)
BillboardTest:testPlaceBidZeroPrice() (gas: 376910)
BillboardTest:testRemoveToWhitelist() (gas: 23207)
BillboardTest:testSafeTransferByOperator() (gas: 141237)
BillboardTest:testSetBoardProperties() (gas: 305883)
BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 335509)
BillboardTest:testSetBoardProperties() (gas: 305950)
BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 335477)
BillboardTest:testSetIsOpened() (gas: 22661)
BillboardTest:testSetTaxRate() (gas: 22909)
BillboardTest:testSomethin() (gas: 1624285)
BillboardTest:testUpgradeRegistry() (gas: 2935587)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 903495, ~: 903495)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 500488, ~: 500488)
BillboardTest:testSetTaxRate() (gas: 22887)
BillboardTest:testSomethin() (gas: 1672218)
BillboardTest:testUpgradeRegistry() (gas: 3038450)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1081104, ~: 1081104)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 597534, ~: 597534)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
CurationTest:testCannotCurateERC20IfNotApproval() (gas: 21624)
Expand All @@ -71,8 +71,8 @@ CurationTest:testCannotCurateNativeTokenZeroAddress() (gas: 16488)
CurationTest:testERC20Curation() (gas: 59908)
CurationTest:testNativeTokenCuration() (gas: 60085)
CurationTest:testNativeTokenCurationToContractAcceptor() (gas: 37466)
DistributionTest:testCannotDropIfInsufficientAllowance(uint256) (runs: 256, μ: 158669, ~: 158683)
DistributionTest:testCannotDropIfInsufficientBalance(uint256) (runs: 256, μ: 160867, ~: 161105)
DistributionTest:testCannotDropIfInsufficientAllowance(uint256) (runs: 256, μ: 158670, ~: 158683)
DistributionTest:testCannotDropIfInsufficientBalance(uint256) (runs: 256, μ: 160868, ~: 161107)
DistributionTest:testCannotSetAdminByAdmin() (gas: 17364)
DistributionTest:testCannotSetAdminByAttacker() (gas: 11111)
DistributionTest:testClaim() (gas: 402817)
Expand Down
15 changes: 5 additions & 10 deletions src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "./BillboardRegistry.sol";
import "./IBillboard.sol";
import "./IBillboardRegistry.sol";
Expand All @@ -13,6 +15,7 @@ contract Billboard is IBillboard {
bool public isOpened = false;

constructor(
address token_,
address payable registry_,
uint256 taxRate_,
uint64 leaseTerm_,
Expand All @@ -28,7 +31,7 @@ contract Billboard is IBillboard {
}
// deploy operator and registry
else {
registry = new BillboardRegistry(address(this), taxRate_, leaseTerm_, name_, symbol_);
registry = new BillboardRegistry(token_, address(this), taxRate_, leaseTerm_, name_, symbol_);
}
}

Expand Down Expand Up @@ -260,15 +263,7 @@ contract Billboard is IBillboard {

function _lockBidPriceAndTax(uint256 amount_) private {
// transfer bid price and tax to the registry
(bool _success, ) = address(registry).call{value: amount_}("");
require(_success, "Transfer failed");

// refund if overpaid
uint256 _overpaid = msg.value - amount_;
if (_overpaid > 0) {
(bool _refundSuccess, ) = msg.sender.call{value: _overpaid}("");
require(_refundSuccess, "Transfer failed");
}
SafeERC20.safeTransferFrom(registry.token(), msg.sender, address(registry), amount_);
}

/// @inheritdoc IBillboard
Expand Down
10 changes: 8 additions & 2 deletions src/Billboard/BillboardRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

Expand All @@ -14,6 +15,7 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {

Counters.Counter public lastTokenId;

IERC20 public immutable token;
uint256 public taxRate;
uint64 public leaseTerm;

Expand All @@ -36,13 +38,17 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
mapping(address => TaxTreasury) public taxTreasury;

constructor(
address token_,
address operator_,
uint256 taxRate_,
uint64 leaseTerm_,
string memory name_,
string memory symbol_
) ERC721(name_, symbol_) {
require(operator_ != address(0), "Zero address");
require(token_ != address(0), "Zero address");

token = IERC20(token_);
operator = operator_;
taxRate = taxRate_;
leaseTerm = leaseTerm_;
Expand Down Expand Up @@ -229,8 +235,8 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
/// @inheritdoc IBillboardRegistry
function transferAmount(address to_, uint256 amount_) external isFromOperator {
require(to_ != address(0), "Zero address");
(bool _success, ) = to_.call{value: amount_}("");
require(_success, "transfer failed");

require(token.transfer(to_, amount_), "Failed token transfer");
}

//////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/Billboard/Distribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ contract Distribution is IDistribution, Ownable {
function sweep(uint256 treeId_, address target_) external isFromAdmin {
uint256 _balance = balances[treeId_];

require(_balance > 0, "zero balance");

// Transfer
require(IERC20(token).transfer(target_, _balance), "failed token transfer");

Expand Down
Loading

0 comments on commit e47370a

Please sign in to comment.