Skip to content

Commit

Permalink
feat: contribute contract function
Browse files Browse the repository at this point in the history
  • Loading branch information
onyedikachi-david committed Oct 19, 2023
1 parent fcb3731 commit c7d5735
Show file tree
Hide file tree
Showing 7 changed files with 606 additions and 18 deletions.
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@
- 🔥 **Burner Wallet & Local Faucet**: Quickly test your application with a burner wallet and local faucet.
- 🔐 **Integration with Wallet Providers**: Connect to different wallet providers and interact with the Ethereum network.

## Token (eth main net)

- 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 USDC
- 0xdAC17F958D2ee523a2206206994597C13D831ec7 USDT
- 0x6B175474E89094C44Da98b954EedeAC495271d0F DAI
- 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 WBTC

## Contents

- [Requirements](#requirements)
- [Quickstart](#quickstart)
- [Deploying your Smart Contracts to a Live Network](#deploying-your-smart-contracts-to-a-live-network)
- [Deploying your NextJS App](#deploying-your-nextjs-app)
- [Interacting with your Smart Contracts: SE-2 Custom Hooks](#interacting-with-your-smart-contracts-se-2-custom-hooks)
- [Disabling Type & Linting Error Checks](#disabling-type-and-linting-error-checks)
- [Disabling commit checks](#disabling-commit-checks)
- [Deploying to Vercel without any checks](#deploying-to-vercel-without-any-checks)
- [Disabling Github Workflow](#disabling-github-workflow)
- [Contributing to Scaffold-ETH 2](#contributing-to-scaffold-eth-2)
- [🏗 Scaffold-ETH 2](#-scaffold-eth-2)
- [Token (eth main net)](#token-eth-main-net)
- [Contents](#contents)
- [Requirements](#requirements)
- [Quickstart](#quickstart)
- [Deploying your Smart Contracts to a Live Network](#deploying-your-smart-contracts-to-a-live-network)
- [Deploying your NextJS App](#deploying-your-nextjs-app)
- [Interacting with your Smart Contracts: SE-2 Custom Hooks](#interacting-with-your-smart-contracts-se-2-custom-hooks)
- [useScaffoldContractRead:](#usescaffoldcontractread)
- [useScaffoldContractWrite:](#usescaffoldcontractwrite)
- [useScaffoldEventSubscriber:](#usescaffoldeventsubscriber)
- [useScaffoldEventHistory:](#usescaffoldeventhistory)
- [useDeployedContractInfo:](#usedeployedcontractinfo)
- [useScaffoldContract:](#usescaffoldcontract)
- [Disabling type and linting error checks](#disabling-type-and-linting-error-checks)
- [Disabling commit checks](#disabling-commit-checks)
- [Deploying to Vercel without any checks](#deploying-to-vercel-without-any-checks)
- [Disabling Github Workflow](#disabling-github-workflow)
- [Contributing to Scaffold-ETH 2](#contributing-to-scaffold-eth-2)

## Requirements

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","id":83,"result":"0x11878c7"}
52 changes: 50 additions & 2 deletions packages/hardhat/contracts/AjoDAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract AjoDAO is IERC721Receiver {
VRFCoordinatorV2Interface COORDINATOR;
LinkTokenInterface LINKTOKEN;
address public i_priceFeedToken;
uint contributedCount;

// Chainlink PriceFeeds - (token / USD)
AggregatorV3Interface private immutable i_priceFeedNative;
Expand Down Expand Up @@ -104,7 +105,7 @@ contract AjoDAO is IERC721Receiver {
// Additional parameters
address[] contributors;
mapping(address => uint256) contributorAmounts;
mapping(uint256 => CycleData) cycleHistory;
mapping(uint256 => CycleData) cycleHistory; // Timestamp -> CycleData
mapping(address => bool) hasPaidPenalty;
}

Expand All @@ -117,6 +118,7 @@ contract AjoDAO is IERC721Receiver {
}

mapping(address => bool) public isParticipant;
mapping(address => bool) public hasContributed;

// Fee collection
uint256 public ServiceFeePurse;
Expand All @@ -135,7 +137,8 @@ contract AjoDAO is IERC721Receiver {
OPEN,
CLOSED,
PAYMENT_IN_PROGRESS,
COMPLETED
COMPLETED,
CONTRIBUTING
}

// Events:
Expand All @@ -155,6 +158,7 @@ contract AjoDAO is IERC721Receiver {

event ParticipantJoined(address indexed participant);
event StateChanged(TANDA_STATE newState);
event ParticipantContributed(address indexed, uint amount);

// Errors
/// Function cannot be called at this time.
Expand Down Expand Up @@ -342,10 +346,54 @@ contract AjoDAO is IERC721Receiver {
if (s.maxParticipants == s.contributors.length) {
s.t_state = TANDA_STATE.PAYMENT_IN_PROGRESS;
}

// CycleData memory newCycle;

// newCycle.cycleNumber = s.cycleHistory.length + 1;
// newCycle.cycleStartTime = block.timestamp;

// s.cycleHistory[newCycle.cycleNumber] = newCycle;

// Emit change of state
emit StateChanged(s.t_state);
}

// Make contribution
function contribute(uint256 _amount) external payable {
AjoDAOData storage s = s_ajoDao;
// Check that the user is participant
require(
isParticipant[msg.sender],
"You must join club before contributing"
);
require(s.t_state == TANDA_STATE.CONTRIBUTING, "Wrong state");

require(_amount == s.contributionAmount, "Wrong amount");

// Check allowance, even for those functions above.

if (s.token == address(0)) {
require(msg.value == s.contributionAmount, "Wrong amount");
AjoDAOPurseBalance += msg.value;
} else {
require(_amount == s.contributionAmount, "Wrong amount");
IERC20(s.token).safeTransferFrom(
msg.sender,
address(this),
_amount
);

AjoDAOPurseTokenBalance[s.token] += _amount;
}

emit ParticipantContributed(msg.sender, _amount);
contributedCount++;

if (contributedCount == s.maxParticipants) {
s.t_state = TANDA_STATE.PAYMENT_IN_PROGRESS;
}
}

/**
* Function that allows the contract to receive ETH
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
30,
ethers.utils.parseEther("1"),
ethers.utils.parseEther("0.5"),
10,
1,
"AjoDAO Alpha",
"First AjoDAO test cycle",
],
Expand Down
4 changes: 3 additions & 1 deletion packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const config: HardhatUserConfig = {
},
},
},
defaultNetwork: "localhost",
defaultNetwork: "localhost", // localhost
namedAccounts: {
deployer: {
// By default, it will take the first Hardhat account as the deployer
Expand All @@ -39,8 +39,10 @@ const config: HardhatUserConfig = {
hardhat: {
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`,
//url: ,`https://polygon-mainnet.g.alchemy.com/v2/${providerApiKey}`
enabled: process.env.MAINNET_FORKING_ENABLED === "true",
},
chainId: 1,
},
mainnet: {
url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`,
Expand Down
Loading

0 comments on commit c7d5735

Please sign in to comment.