Skip to content

Commit

Permalink
cmt8888
Browse files Browse the repository at this point in the history
  • Loading branch information
xthet committed Jun 5, 2023
1 parent 4cd31cb commit 5d71838
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 89 deletions.
44 changes: 22 additions & 22 deletions contracts/Campaign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ contract Campaign is KeeperCompatibleInterface, ReentrancyGuard{
(bool success, ) = rewards[msg.value].call(abi.encodeWithSignature("addDonator(address)", _donator));
if(!success){revert();}
entDonations[_donator].push(msg.value);
}
}else{revert();}
}
aggrDonations[_donator] = aggrDonations[_donator] + msg.value;
emit FundingRecieved(_donator, msg.value, currentBalance);
Expand Down Expand Up @@ -169,8 +169,8 @@ contract Campaign is KeeperCompatibleInterface, ReentrancyGuard{


function refund(address _donator) external nonReentrant{
console.log("currBal");
console.log(currentBalance);
// console.log("currBal");
// console.log(currentBalance);
_refP = refunder_pckg(currentBalance, c_state);
RefunderLib.refund(i_crf, _refP, rewards, aggrDonations, entDonations, _donator);
// if(msg.sender != i_crf){revert();}
Expand Down Expand Up @@ -199,10 +199,10 @@ contract Campaign is KeeperCompatibleInterface, ReentrancyGuard{
}

function makeReward(RewardFactory.rwdInput memory _rwd) external isCreator {
if(rewards[_rwd.price] != address(0)){revert();}
rKeys.push(_rwd.price);
if(rewards[_rwd._price] != address(0)){revert();}
rKeys.push(_rwd._price);
address newReward = RewardFactory(i_rwdFactory).createReward(address(this), i_creator, _rwd);
rewards[_rwd.price] = newReward;
rewards[_rwd._price] = newReward;
}

function endCampaign() external isCreator {
Expand Down Expand Up @@ -231,20 +231,20 @@ contract Campaign is KeeperCompatibleInterface, ReentrancyGuard{
return reward.getRewardDetails();
}

// function getCampaignDetails() external view returns(CampaignObject memory) {
// return CampaignObject(
// i_creator,
// s_title,
// s_description,
// s_category,
// s_tags,
// goalAmount,
// duration,
// currentBalance,
// c_state,
// s_imageURI,
// s_campaignURI,
// deadline
// );
// }
function getCampaignDetails() external view returns(CampaignObject memory) {
return CampaignObject(
i_creator,
s_title,
s_description,
s_category,
s_tags,
goalAmount,
duration,
currentBalance,
c_state,
s_imageURI,
s_campaignURI,
deadline
);
}
}
7 changes: 5 additions & 2 deletions contracts/factories/RewardFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
pragma solidity ^0.8.11;

import { Reward } from "../Reward.sol";
import "../../node_modules/hardhat/console.sol";


contract RewardFactory {
struct rwdInput {
uint256 price;
uint256 _price;
string _title;
string _description;
string _rpic;
Expand All @@ -17,10 +19,11 @@ contract RewardFactory {
}

function createReward(address _cmpAddress, address _creator, rwdInput memory _rwd) public returns (address) {
// console.log("over");
Reward rwd = new Reward(
_cmpAddress,
_creator,
_rwd.price,
_rwd._price,
_rwd._title,
_rwd._description,
_rwd._rpic,
Expand Down
4 changes: 0 additions & 4 deletions contracts/libraries/campaign/RefunderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ library RefunderLib {
mapping (address => uint256[]) storage _entDons,
address _donator
) external {
console.log("here");
if(msg.sender != _i_crf){revert();}
if(_refP.c_state == Campaign.C_State.Expired){revert();}
if(_aggrDons[_donator] == 0 ){revert();}
console.log("there");

uint256 amountToRefund = _aggrDons[_donator];
console.log(_refP.currentBalance);

if(_refP.currentBalance < amountToRefund){revert();}
console.log("where");
_refP.currentBalance = _refP.currentBalance - amountToRefund;

(bool success, ) = payable(_donator).call{value: amountToRefund}("");
Expand All @@ -41,6 +38,5 @@ library RefunderLib {
}

delete _entDons[_donator];
console.log("zhere");
}
}
20 changes: 12 additions & 8 deletions deploy/01-deploy-campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ const deployCampaign: DeployFunction = async function (hre: HardhatRuntimeEnviro
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
const waitBlockConfirmations = chainId?.toString() == "31337" ? 1 : 5
await deployments.fixture(["crowdfunder"])
const crowdfunder = await ethers.getContract("CrowdFunder", deployer)
const refunderLib = await ethers.getContract("RefunderLib", deployer)
const rewardFactory = await ethers.getContract("RewardFactory", deployer)

log("==========================")
const refunderLib = await deploy("RefunderLib", {
from: deployer,
args: [],
log: true,
waitConfirmations: waitBlockConfirmations
})
// const refunderLib = await deploy("RefunderLib", {
// from: deployer,
// args: [],
// log: true,
// waitConfirmations: waitBlockConfirmations
// })

const args:any[] = [
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
crowdfunder.address, // i_crf from console
deployer,
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
rewardFactory.address, // i_rwdFactory
"Piratopia: Raiders of Pirate Bay",
"A P2E masterpiece on the AVAX chain",
"P2E",
Expand Down
48 changes: 25 additions & 23 deletions gas-report.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
·--------------------------------------|---------------------------|-------------|-----------------------------·
| Solc version: 0.8.11 · Optimizer enabled: true · Runs: 200 · Block limit: 30000000 gas │
·······································|···························|·············|······························
| Methods · 71 gwei/gas · 1854.72 usd/eth │
················|······················|·············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
················|······················|·············|·············|·············|···············|··············
| CrowdFunder · addCampaign · - · - · 2010758 · 2 · 264.79 │
················|······················|·············|·············|·············|···············|··············
| CrowdFunder · donateToCampaign · - · - · 91669 · 2 · 12.07 │
················|······················|·············|·············|·············|···············|··············
| CrowdFunder · refundFromCampaign · - · - · 74972 · 2 · 9.87 │
················|······················|·············|·············|·············|···············|··············
| Deployments · · % of limit · │
·······································|·············|·············|·············|···············|··············
| CampaignFactory · - · - · 2522232 · 8.4 % · 332.14 │
·······································|·············|·············|·············|···············|··············
| CrowdFunder · - · - · 1185276 · 4 % · 156.08 │
·······································|·············|·············|·············|···············|··············
| RefunderLib · - · - · 415431 · 1.4 % · 54.71 │
·······································|·············|·············|·············|···············|··············
| RewardFactory · - · - · 1840819 · 6.1 % · 242.41 │
·--------------------------------------|-------------|-------------|-------------|---------------|-------------·
·---------------------------|---------------------------|-------------|-----------------------------·
| Solc version: 0.8.11 · Optimizer enabled: true · Runs: 200 · Block limit: 30000000 gas │
····························|···························|·············|······························
| Methods · 37 gwei/gas · 1808.22 usd/eth │
·············|··············|·············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
·············|··············|·············|·············|·············|···············|··············
| Campaign · donate · - · - · 192682 · 2 · 12.89 │
·············|··············|·············|·············|·············|···············|··············
| Campaign · makeReward · - · - · 1351432 · 2 · 90.42 │
·············|··············|·············|·············|·············|···············|··············
| Campaign · refund · - · - · 71674 · 2 · 4.80 │
·············|··············|·············|·············|·············|···············|··············
| Deployments · · % of limit · │
····························|·············|·············|·············|···············|··············
| Campaign · - · - · 2528285 · 8.4 % · 169.15 │
····························|·············|·············|·············|···············|··············
| CampaignFactory · - · - · 2781452 · 9.3 % · 186.09 │
····························|·············|·············|·············|···············|··············
| CrowdFunder · - · - · 1185276 · 4 % · 79.30 │
····························|·············|·············|·············|···············|··············
| RefunderLib · - · - · 338263 · 1.1 % · 22.63 │
····························|·············|·············|·············|···············|··············
| RewardFactory · - · - · 1840819 · 6.1 % · 123.16 │
·---------------------------|-------------|-------------|-------------|---------------|-------------·
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const config: HardhatUserConfig =
contractSizer: {
alphaSort: true,
disambiguatePaths: false,
runOnCompile: true,
runOnCompile: false,
strict: true,
// only: [":ERC20$"],
unit: "kB"
Expand Down
60 changes: 33 additions & 27 deletions test/unit/test-campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,17 @@ import { Campaign } from "../../typechain-types"
it("successfully creates rewards", async ()=>{
const getDeadline = await campaign.deadline()
const addRwdTx = campaign.makeReward(
ethers.utils.parseEther("0.022"),
"Digital Copy with OST",
"A digital copy of the game for STEAM (PC/MAC).",
"ipfs://",
["Digital Artbook", "Original Soundtrack"],
getDeadline,
100,
true,
["_NW"] // digital
{
_price: ethers.utils.parseEther("0.022"),
_title: "Digital Copy with OST",
_description: "A digital copy of the game for STEAM (PC/MAC).",
_rpic: "ipfs://",
_perks: ["mochas and biggs"],
_deadline: getDeadline,
_quantity: 100,
_infinite: true,
_shipsTo: ["_NW"]
}
)

const addRwdTxR = (await addRwdTx).wait(1)
Expand Down Expand Up @@ -308,28 +310,32 @@ import { Campaign } from "../../typechain-types"
it("fails on rwd edit", async ()=>{
const getDeadline = await campaign.deadline()
const addRwdTx = campaign.makeReward(
ethers.utils.parseEther("0.025"),
"Digital Copy with OST",
"A digital copy of the game for STEAM (PC/MAC).",
"ipfs://",
["Digital Artbook", "Original Soundtrack"],
getDeadline,
100,
true,
["_NW"] // digital
{
_price: ethers.utils.parseEther("0.022"),
_title: "Digital Copy with OST",
_description: "A digital copy of the game for STEAM (PC/MAC).",
_rpic: "ipfs://",
_perks: ["mochas and biggs"],
_deadline: getDeadline,
_quantity: 100,
_infinite: true,
_shipsTo: ["_NW"]
}
)
const addRwdTxR = (await addRwdTx).wait(1)

await expect( campaign.makeReward(
ethers.utils.parseEther("0.025"),
"Digital Copy with OST",
"A physical copy of the game for STEAM (PC/MAC).",
"ipfs://",
["Digital Artbook", "Original Soundtrack"],
getDeadline,
100,
true,
["_NW"] // digital
{
_price: ethers.utils.parseEther("0.022"),
_title: "Digital Copy with OST",
_description: "A digital copy of the game for STEAM (PC/MAC).",
_rpic: "ipfs://",
_perks: ["mochas and biggs"],
_deadline: getDeadline,
_quantity: 100,
_infinite: true,
_shipsTo: ["_NW"]
}
)).to.be.reverted
})
})
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"resolveJsonModule": true
"resolveJsonModule": true,
"rootDirs": ["./src", "./scripts", "./test"]
},
"include": ["./scripts", "./test", "./deploy", "./deploy-helpers", "deploy/03-deploy-crowdFunder.ts", "test/unit/test-crowdFunder.ts", "./**/*.json"],
"exclude": ["node_modules", "dist"],
"include": ["./scripts", "./test", "./deploy"],
"files": ["./hardhat.config.ts", "./helper-hardhat-config.ts"]
}

0 comments on commit 5d71838

Please sign in to comment.