Skip to content
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
31 changes: 23 additions & 8 deletions frontend/src/hooks/useCreateCampaign.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import {BigNumber, ethers} from "ethers";
import {useSigner} from "wagmi";
import {L2CampaingFactory} from "../contracts";
import { BigNumber, ethers } from "ethers";
import { useSigner } from "wagmi";
import { L2CampaingFactory } from "../contracts";

export const useCreateCampaign = () => {
const {data: signer} = useSigner();
const { data: signer } = useSigner();

const deployCampaign = async (commision: BigNumber, target: string, deadline: BigNumber, totalReward: BigNumber, signature: string) => {
const deployCampaign = async (
commision: BigNumber,
target: string,
deadline: BigNumber,
totalReward: BigNumber,
signature: string,
activityCost: BigNumber
) => {
const contract = new ethers.Contract(
L2CampaingFactory,
["function deployCampaign(uint256 _commission,address _target,uint256 _deadline, string memory _signature) external payable"],
[
"function deployCampaign(uint256 _commission,address _target,uint256 _deadline, string memory _signature) external payable",
],
signer!
);

const deployRes = await contract.deployCampaign(commision, target, deadline, signature, {value: totalReward});
const deployRes = await contract.deployCampaign(
commision,
target,
deadline,
signature,
{ value: totalReward }
);
console.log("deployRes", deployRes);
};

return {deployCampaign};
return { deployCampaign };
};
84 changes: 74 additions & 10 deletions frontend/src/views/createCampaign/CreateCampaign.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Box, Button, Flex, Heading, Input, Select, Text } from "@chakra-ui/react";
import {
Box,
Button,
Flex,
Heading,
Input,
Select,
Text,
} from "@chakra-ui/react";
import { SingleDatepicker } from "chakra-dayzed-datepicker";
import { BigNumber, ethers } from "ethers";
import { useState } from "react";
Expand All @@ -10,25 +18,39 @@ export const CreateCampaign = () => {
const { deployCampaign } = useCreateCampaign();

const onCreateCampaign = async () => {
await deployCampaign(ethers.utils.parseEther(commision), target, BigNumber.from(date.getTime() * 2), ethers.utils.parseEther(totalReward), signature);
await deployCampaign(
ethers.utils.parseEther(commision),
target,
BigNumber.from(date.getTime() * 2),
ethers.utils.parseEther(totalReward),
signature,
ethers.utils.parseEther(activityCost)
);
};

const [target, setTarget] = useState<string>(BAYC);
const [signature, setSignature] = useState<string>("mintApe(uint256)");
const [commision, setCommision] = useState<string>("0.00001");
const [totalReward, setTotalReward] = useState<string>("0.001");
const [activityCost, setActivityCost] = useState<string>("0.8");

const [date, setDate] = useState(new Date());
return (
<Box background="#F7F5F6" minH="100vh" px="2rem" pt="1rem">
<Header />
<Flex alignItems="center" direction="column">
<Box pt="16" w="100%" maxW="1200px">
<Heading textAlign="center">Create Campaign</Heading>
<Box pt="16" w="100%" maxW="1200px">
<Heading textAlign="center">Create Campaign</Heading>
<Box pt="8" />
<Box>
<Text>Specifiy advertised Contract</Text>
<Input backgroundColor="white" value={target} onChange={(e) => setTarget(e.target.value)} type="text" placeholder="" />
<Input
backgroundColor="white"
value={target}
onChange={(e) => setTarget(e.target.value)}
type="text"
placeholder=""
/>
</Box>
<Box h="4" />
<Box>
Expand All @@ -40,13 +62,40 @@ export const CreateCampaign = () => {
<Box h="4" />
<Box>
<Text>Function signature</Text>
<Input backgroundColor="white" value={signature} onChange={(e) => setSignature(e.target.value)} type="text" placeholder="" />
<Input
backgroundColor="white"
value={signature}
onChange={(e) => setSignature(e.target.value)}
type="text"
placeholder=""
/>
</Box>
<Box h="4" />
<Box>
<Text>Activity cost</Text>
<Flex>
<Input
backgroundColor="white"
value={activityCost}
onChange={(e) => setActivityCost(e.target.value)}
type="text"
placeholder=""
/>
<Box w="4" />
<Text alignSelf="center">ETH</Text>
</Flex>
</Box>
<Box h="4" />
<Box>
<Text>User aquision Reward</Text>
<Flex>
<Input backgroundColor="white" value={commision} onChange={(e) => setCommision(e.target.value)} type="number" placeholder="0x..." />
<Input
backgroundColor="white"
value={commision}
onChange={(e) => setCommision(e.target.value)}
type="number"
placeholder="0x..."
/>
<Box w="4" />
<Text alignSelf="center">ETH</Text>
</Flex>
Expand All @@ -55,7 +104,13 @@ export const CreateCampaign = () => {
<Box>
<Text>Total reward amount</Text>
<Flex>
<Input backgroundColor="white" value={totalReward} onChange={(e) => setTotalReward(e.target.value)} type="number" placeholder="0x..." />
<Input
backgroundColor="white"
value={totalReward}
onChange={(e) => setTotalReward(e.target.value)}
type="number"
placeholder="0x..."
/>
<Box w="4" />
<Text alignSelf="center">ETH</Text>
</Flex>
Expand All @@ -64,11 +119,20 @@ export const CreateCampaign = () => {
<Box h="4" />
<Text>Deadline</Text>
<Box w="50%">
<SingleDatepicker name="date-input" date={date} onDateChange={setDate} />
<SingleDatepicker
name="date-input"
date={date}
onDateChange={setDate}
/>
</Box>
</Box>
<Box h="8" />
<Button w="100%" textColor="white" background="black" onClick={onCreateCampaign}>
<Button
w="100%"
textColor="white"
background="black"
onClick={onCreateCampaign}
>
Deploy
</Button>
</Box>
Expand Down
27 changes: 15 additions & 12 deletions src/crosschainAdvertiser/l2/L2CampaignFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ contract L2CampaignFactory is Ownable {
address campaign,
uint256 commission,
uint256 totalReward,
string signature
string signature,
uint256 activityCost
);

constructor(address _l1Caller, address _connext, uint32 _originDomain) {
Expand All @@ -32,28 +33,30 @@ contract L2CampaignFactory is Ownable {
}

function deployCampaign(
uint256 _commission,
address _target,
uint256 _deadline,
string memory _signature
uint256 commission,
address target,
uint256 deadline,
string memory signature,
uint256 activityCost
) external payable {
L2Campaign campaign = new L2Campaign{value: msg.value}(
_commission,
_target,
_deadline,
commission,
target,
deadline,
l1Caller,
connext,
originDomain,
bytes4(keccak256(bytes(_signature)))
bytes4(keccak256(bytes(signature)))
);

emit CampaignCreated(
_target,
target,
msg.sender,
address(campaign),
_commission,
commission,
msg.value,
_signature
signature,
activityCost
);
}
}