Skip to content

Commit

Permalink
hotfix: contract update and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSilva committed May 21, 2024
1 parent 4cd3e15 commit 087f0ba
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 157 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/contracts/token/Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ contract Sale is ISale, RisingTide, ERC165, AccessControl, ReentrancyGuard {
maxTarget = _maxTarget;
startRegistration = _startRegistration;
endRegistration = _endRegistration;
minPrice = 0.2 ether;
maxPrice = 0.4 ether;
minPrice = 0.2 * 1e6;
maxPrice = 0.4 * 1e6;

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(CAP_VALIDATOR_ROLE, msg.sender);
Expand Down
15 changes: 8 additions & 7 deletions packages/contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ contract DeployScript is Script {

uint256 startRegistration = 1715342400;
uint256 endRegistration = 1715860800;
uint256 start = 1715947200;
uint256 end = 1716033600;
uint256 start = 1716289730;
uint256 end = 1716552000;

address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
// address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address USDC = 0x697485a9E004Da9bd9b3204dfB24efc288C04c2c;

Sale sale = new Sale(
USDC,
0.2 ether,
0.2 * 1e6,
start,
end,
2500000 ether,
500000 ether,
1000000 ether,
500000 * 1e6,
1000000 * 1e6,
startRegistration,
endRegistration
);

sale.setMinContribution(500 ether);
sale.setMinContribution(500 * 1e6);

vm.stopBroadcast();
}
Expand Down
120 changes: 62 additions & 58 deletions packages/contracts/test/contracts/token/Sale.d.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ contract SaleTest is Test {
bytes32[] aliceMerkleProof = new bytes32[](2);
bytes32[] bobMerkleProof = new bytes32[](2);

uint256 paymentTokenMultiplier;
uint256 rate;
uint256 minContribution;
uint256 minPrice;

event Purchase(
address indexed from,
uint256 paymentTokenAmount,
Expand Down Expand Up @@ -58,46 +63,59 @@ contract SaleTest is Test {

paymentToken = new MockERC20("USDC", "USDC", 6);
token = new Citizend(owner, end);

paymentTokenMultiplier = 10 ** paymentToken.decimals();
rate = (2 * paymentTokenMultiplier ) / 10;
minContribution = 2 * paymentTokenMultiplier / 10;

sale = new Sale(
address(paymentToken),
0.2 ether,
rate,
start,
end,
10 ether,
5 ether,
15 ether,
5 * 1e6,
15 * 1e6,
startRegistration,
endRegistration
);

sale.setMerkleRoot(merkleRoot);
sale.setToken(address(token));
sale.setMinContribution(0.2 ether);
sale.setMinContribution(minContribution);

token.transfer(address(sale), 1000000 ether);

vm.stopPrank();

vm.startPrank(alice);

paymentToken.mint(alice, 100 ether);
paymentToken.approve(address(sale), 100 ether);
paymentToken.mint(alice, 100 * 1e6);
paymentToken.approve(address(sale), 100 * 1e6);

vm.stopPrank();

vm.startPrank(bob);

paymentToken.mint(bob, 100 ether);
paymentToken.approve(address(sale), 100 ether);
paymentToken.mint(bob, 100 * 1e6);
paymentToken.approve(address(sale), 100 * 1e6);

vm.stopPrank();
}

function test_BuyUSC() public {
vm.startPrank(alice);

require(sale.paymentTokenToToken(1 * 1e6) == 5 ether);

vm.stopPrank();
}

function testConstructor() public view {
require(sale.paymentToken() == address(paymentToken));
require(sale.rate() == 0.2 ether);
require(sale.minPrice() == 0.2 ether);
require(sale.maxPrice() == 0.4 ether);
require(sale.rate() == rate);
require(sale.minPrice() == 2 * paymentTokenMultiplier / 10);
require(sale.maxPrice() == 4 * paymentTokenMultiplier / 10);
require(sale.start() == start);
require(sale.end() == end);
require(sale.hasRole(sale.DEFAULT_ADMIN_ROLE(), owner));
Expand All @@ -107,60 +125,46 @@ contract SaleTest is Test {

function test_PaymentTokenToToken() public view {
require(sale.paymentTokenToToken(0 ether) == 0);
require(sale.paymentTokenToToken(0.2 ether) == 1 ether);
require(sale.paymentTokenToToken(1 ether) == 5 ether);
require(sale.paymentTokenToToken(0.2 * 1e6) == 1 ether);
require(sale.paymentTokenToToken(1 * 1e6) == 5 ether);
}

function test_TokenToPaymentToken() public view {
require(sale.tokenToPaymentToken(0 ether) == 0);
require(sale.tokenToPaymentToken(1 ether) == 0.2 ether);
require(sale.tokenToPaymentToken(5 ether) == 1 ether);
require(sale.tokenToPaymentToken(1 ether) == 0.2 * 1e6);
require(sale.tokenToPaymentToken(5 ether) == 1 * 1e6);
}

function test_Buy() public {
vm.startPrank(alice);

uint256 beforeBalance = paymentToken.balanceOf(alice);
require(beforeBalance == 100 ether);
require(beforeBalance == 100 * 1e6);

vm.expectEmit();

emit Purchase(address(alice), 1 ether, 5 ether);
emit Purchase(address(alice), 1 * 1e6, 5 ether);

sale.buy(sale.paymentTokenToToken(1 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(1 * 1e6), aliceMerkleProof);

uint256 afterBalance = paymentToken.balanceOf(alice);
require(afterBalance == 99 ether);
require(afterBalance == 99 * 1e6);

require(sale.risingTide_totalAllocatedUncapped() == 5 ether);

vm.stopPrank();
}

function test_Buy1000() public {
vm.startPrank(alice);
paymentToken.mint(alice, 900 ether);
paymentToken.approve(address(sale), 5000 ether);

uint256 beforeBalance = paymentToken.balanceOf(alice);
require(beforeBalance == 1000 ether);

emit Purchase(address(alice), 1000 ether, 5000 ether);
sale.buy(5000 ether, aliceMerkleProof);

vm.stopPrank();
}

function test_BuyMultiplePurchasesSameAccount() public {
vm.startPrank(alice);

vm.expectEmit();
emit Purchase(address(alice), 1 ether, 5 ether);
emit Purchase(address(alice), 1 * 1e6, 5 ether);

sale.buy(5 ether, aliceMerkleProof);

vm.expectEmit();
emit Purchase(address(alice), 1 ether, 5 ether);
emit Purchase(address(alice), 1 * 1e6, 5 ether);

sale.buy(5 ether, aliceMerkleProof);

Expand All @@ -171,12 +175,12 @@ contract SaleTest is Test {

function test_BuyRevertsWhenBelowMinimum() public {
vm.prank(owner);
sale.setMinContribution(2 ether);
sale.setMinContribution(2 * 1e6);

vm.startPrank(alice);

vm.expectRevert(bytes("can't be below minimum"));
sale.buy(1 ether, aliceMerkleProof);
sale.buy(1 * 1e6, aliceMerkleProof);
}

function test_BuyRevertsWhenInvalidMerkleProof() public {
Expand Down Expand Up @@ -247,11 +251,11 @@ contract SaleTest is Test {

function test_WithdrawDoesNotWithdrawRefunds() public {
vm.startPrank(alice);
sale.buy(sale.paymentTokenToToken(0.1 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(0.1 * 1e6), aliceMerkleProof);
vm.stopPrank();

vm.startPrank(bob);
sale.buy(sale.paymentTokenToToken(0.1 ether), bobMerkleProof);
sale.buy(sale.paymentTokenToToken(0.1 * 1e6), bobMerkleProof);
vm.stopPrank();

vm.warp(sale.end() + 1000);
Expand All @@ -263,19 +267,19 @@ contract SaleTest is Test {
uint256 aliceRefund = sale.refundAmount(alice);

require(aliceAllocation == 0 ether);
require(aliceRefund == 0.1 ether);
require(aliceRefund == 0.1 * 1e6);

uint256 bobAllocation = sale.allocation(bob);
uint256 bobRefund = sale.refundAmount(bob);
require(bobAllocation == 0 ether);
require(bobRefund == 0.1 ether);
require(bobRefund == 0.1 * 1e6);

sale.withdraw();

vm.stopPrank();

uint256 ownerBalance = paymentToken.balanceOf(owner);
require(ownerBalance == 0.2 ether);
require(ownerBalance == 0.2 * 1e6);
}

function test_SetIndividualCap() public {
Expand Down Expand Up @@ -308,19 +312,19 @@ contract SaleTest is Test {

function test_RefundAmountIsZeroIfAlreadyRefunded() public {
vm.startPrank(alice);
sale.buy(sale.paymentTokenToToken(2 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(2 * 1e6), aliceMerkleProof);
vm.stopPrank();

vm.startPrank(bob);
sale.buy(sale.paymentTokenToToken(2 ether), bobMerkleProof);
sale.buy(sale.paymentTokenToToken(2 * 1e6), bobMerkleProof);
vm.stopPrank();

vm.warp(sale.end() + 1000);

vm.prank(owner);
sale.setIndividualCap(5 ether);

require(sale.refundAmount(alice) == 2 ether);
require(sale.refundAmount(alice) == 2 * 1e6);

vm.prank(alice);
sale.refund(alice);
Expand All @@ -344,11 +348,11 @@ contract SaleTest is Test {

function test_RefundReturnsCorrectAmmount() public {
vm.startPrank(alice);
sale.buy(sale.paymentTokenToToken(2 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(2 * 1e6), aliceMerkleProof);
vm.stopPrank();

vm.startPrank(bob);
sale.buy(sale.paymentTokenToToken(2 ether), bobMerkleProof);
sale.buy(sale.paymentTokenToToken(2 * 1e6), bobMerkleProof);
vm.stopPrank();

vm.warp(sale.end() + 1000);
Expand All @@ -362,7 +366,7 @@ contract SaleTest is Test {
uint256 aliceBalance = paymentToken.balanceOf(alice);
uint256 bobBalance = paymentToken.balanceOf(bob);

require(aliceRefund == 2 ether);
require(aliceRefund == 2 * 1e6);

vm.expectEmit();
emit Refund(alice, aliceRefund);
Expand Down Expand Up @@ -423,36 +427,36 @@ contract SaleTest is Test {

function test_AllocationWhenMaxTargetNotReached() public {
vm.startPrank(owner);
sale.setMinTarget(5 ether);
sale.setMaxTarget(10 ether);
sale.setMinTarget(5 * 1e6);
sale.setMaxTarget(10 * 1e6);
vm.stopPrank();

vm.startPrank(alice);
sale.buy(sale.paymentTokenToToken(6 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(6 * 1e6), aliceMerkleProof);
vm.stopPrank();

vm.warp(sale.end() + 1000);

require(sale.currentTokenPrice() == 0.24 ether);
require(sale.currentTokenPrice() == 0.24 * 1e6);
require(sale.allocation(alice) == 25 ether);
require(
sale.allocation(alice) ==
(6 ether / sale.currentTokenPrice()) * 1 ether
(6 * 1e6 / sale.currentTokenPrice()) * 1 ether
);
}

function test_CurrentPrice() public {
require(sale.currentTokenPrice() == 0.2 ether);
require(sale.currentTokenPrice() == 0.2 * 1e6);

vm.startPrank(owner);
sale.setMinTarget(5 ether);
sale.setMaxTarget(10 ether);
sale.setMinTarget(5 * 1e6);
sale.setMaxTarget(10 * 1e6);
vm.stopPrank();

vm.startPrank(alice);
sale.buy(sale.paymentTokenToToken(7.5 ether), aliceMerkleProof);
sale.buy(sale.paymentTokenToToken(7.5 * 1e6), aliceMerkleProof);
vm.stopPrank();

require(sale.currentTokenPrice() == 0.3 ether);
require(sale.currentTokenPrice() == 0.3 * 1e6);
}
}
2 changes: 1 addition & 1 deletion packages/contracts/wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
Sale: {
1: "0x85b34Aa54fdf8242e4656eA50b711F45340925bC",
31337: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
11155111: "0x7409dfa77bf9974a3e205eacb2b35bb2cff39154",
11155111: "0xe8e1e60a1a7dbd93164d239dd3cbda5e675c4177",
},
},
}),
Expand Down
Loading

0 comments on commit 087f0ba

Please sign in to comment.