Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: advertiser sig add #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
interfaces/=lib/interfaces/
openzeppelin-contracts/=lib/openzeppelin-contracts/
@openzeppelin/=lib/openzeppelin-contracts/
solmate/=lib/solmate/src/
6 changes: 4 additions & 2 deletions src/crosschainAdvertiser/l1/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ contract AdForwarder {
// The domain the campain contract is deployed
uint32 destinationDomain,
// The relayerFee that needs to be paid to the connext relayer
uint256 relayerFee
uint256 relayerFee,
// Signature of the advertiser
bytes32 signature
) external payable {
(bool success, bytes memory result) = target.call{value: msg.value - relayerFee}(_calldata);
require(success, "tx failed");
Expand All @@ -52,7 +54,7 @@ contract AdForwarder {
msg.sender, // _delegate: address that can revert or forceLocal on destination
0, // _amount: 0 because no funds are being transferred
0, // _slippage: can be anything between 0-10000 because no funds are being transferred
abi.encode(adHash, advertiser) // _callData: the encoded calldata to send
abi.encode(adHash, advertiser, signature) // _callData: the encoded calldata to send
);

// getting selector from calldata
Expand Down
33 changes: 31 additions & 2 deletions src/crosschainAdvertiser/l2/L2Campaign.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.8.15;

import {getAdHash} from "../AdHash.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

contract L2Campaign {
// The amount an advertiser will receive for a successful ad
Expand All @@ -18,9 +19,14 @@ contract L2Campaign {
// Deadline after which the owner can withdraw the funds
uint256 public immutable deadline;

mapping (address advertiser => bytes32 agreement) public agreements;

mapping(bytes32 => address) claims;

uint public claimableRewards;

using ECDSA for bytes32;

constructor(
uint256 _commission,
address _target,
Expand Down Expand Up @@ -71,14 +77,37 @@ contract L2Campaign {
uint32 _origin,
bytes memory _callData
) external onlySource(_originSender, _origin) returns (bytes memory) {
(bytes32 adHash, address advertiser) = abi.decode(
(bytes32 adHash, address advertiser, bytes32 signature) = abi.decode(
_callData,
(bytes32, address)
(bytes32, address, bytes32)
);
// TODO: Will relayer keep retrying if this fails?
// What if tx will never succeed?
require(
agreements[advertiser] == signature,
"Advertiser did not apply for this campaign"
);
claims[adHash] = advertiser;
claimableRewards += commission;
}

function applyTo(bytes memory signature) external payable {
require(
msg.value >= commission,
"Payment cannot be less than commission"
);
// TODO: return extra funds
require(
agreements[msg.sender] == 0x0,
"Advertiser already applied for this campaign"
);
require(
keccak256(abi.encodePacked(target, msg.sender)).toEthSignedMessageHash().recover(signature) == msg.sender,
"Signature is not valid"
);
agreements[msg.sender] = abi.encodePacked(signature);
}

function withdraw() external onlyOwner onlyAfter(deadline) {
require(
address(this).balance > claimableRewards,
Expand Down