From f286a7480cbc4edb5fc7afaf93b6917eb16e99c3 Mon Sep 17 00:00:00 2001 From: Dylan Moreland Date: Tue, 8 Oct 2024 17:49:20 -0400 Subject: [PATCH] Contract? --- script/Counter.s.sol | 19 ------------------- src/Counter.sol | 14 -------------- src/WeekPool.sol | 15 +++++++++++++-- test/Counter.t.sol | 24 ------------------------ 4 files changed, 13 insertions(+), 59 deletions(-) delete mode 100644 script/Counter.s.sol delete mode 100644 src/Counter.sol delete mode 100644 test/Counter.t.sol diff --git a/script/Counter.s.sol b/script/Counter.s.sol deleted file mode 100644 index cdc1fe9..0000000 --- a/script/Counter.s.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterScript is Script { - Counter public counter; - - function setUp() public {} - - function run() public { - vm.startBroadcast(); - - counter = new Counter(); - - vm.stopBroadcast(); - } -} diff --git a/src/Counter.sol b/src/Counter.sol deleted file mode 100644 index aded799..0000000 --- a/src/Counter.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -contract Counter { - uint256 public number; - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } -} diff --git a/src/WeekPool.sol b/src/WeekPool.sol index b236e61..5352a47 100644 --- a/src/WeekPool.sol +++ b/src/WeekPool.sol @@ -2,11 +2,13 @@ pragma solidity ^0.8.13; import {Token} from "./Token.sol"; +import {ECDSA} from "solady/utils/ECDSA.sol"; contract WeekPool { uint256 private _week; uint256 private _totalPoints; Token private _token; + uint256 private _tokens; address private _signer; @@ -16,11 +18,12 @@ contract WeekPool { bytes32 private constant SOME_TYPE_HASH = keccak256("BaselineRequest(uint256 vehicleId,address owner,uint256 week,uint256 points)"); - constructor(address token, uint256 week, uint256 totalPoints, address signer) { + constructor(address token, uint256 week, uint256 totalPoints, address signer, uint256 tokens) { _token = Token(token); _week = week; _totalPoints = totalPoints; _signer = signer; + _tokens = tokens; } function claim(bytes calldata data) external { @@ -34,8 +37,16 @@ contract WeekPool { (uint256 vehicleId, address owner, uint256 week, uint256 points, bytes memory signature) = abi.decode(data, (uint256, address, uint256, uint256, bytes)); + require(!_claimed[vehicleId], "Already claimed"); + require(_week == week, "Wrong week"); + bytes32 structHash = keccak256(abi.encode(SOME_TYPE_HASH, vehicleId, owner, week, points)); bytes32 fullHash = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, structHash)); - + + require(ECDSA.recover(fullHash, signature) == _signer, "Wrong signer"); + + _claimed[vehicleId] = true; + + require(_token.transfer(owner, (_tokens * points) / _totalPoints), "Transfer failed"); } } diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index 54b724f..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -}