The Ideal Thrift 🚧👷 Under Heavy Construction👷🚧
- MATIC/USD: 0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada
- USDC/USD: 0x572dDec9087154dC5dfBB1546Bb62713147e0Ab0
- USDT/USD: 0x92C09849638959196E976289418e5973CC96d645
- DAI/USD: 0x0FCAa9c899EC5A91eBc3D5Dd869De833b06fB046
- BTC/USD: 0x007A22900a3B98143368Bd5906f8E17e9867581b
-
USDCAddress: 0x0FA8781a83E46826621b3BC094Ea2A0212e71B23
-
USDTAddress: 0xA02f6adc7926efeBBd59Fd43A84f4E0c0c91e832
-
DAIAddress: 0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F
-
WBTCAddress: 0x0d787a4a1548f673ed375445535a6c7A1EE56180
-
link: 0x326C977E6efc84E512bB9C30f76E30c160eD06FB
-
registrar: 0x57A4a13b35d25EE78e084168aBaC5ad360252467
-
ThriftClubFactory Deployed address (current): 0x11277e0BEACe37deBEF8578619A2afC3F66ab4F1
-
ThriftClubFactory Deployed addresses (before): 0x25BeBb3a758262b5A640f2f9011b420419eacE69,0x5d88b06E942e9AbB9470e80384d7E28ACb743511
This markdown document describes the features of a DAO-based thrift decentralized application (DApp) implemented as a smart contract in Solidity.
The ThriftClub
contract implements the following features:
-
Membership Management:
- Allow participants to join the thrift club by paying a penalty fee.
- Mint an NFT for each participant.
- Track participants and prevent duplicate entries.
- Only allow participants who have paid the penalty fee to join the club.
-
Cycle Management:
- Start a new cycle when the maximum number of participants is reached.
- Determine the winner of the thrift pot using a Chainlink contract.
- Distribute the thrift pot to the winner.
-
DAO Integration:
- Integrate with a DAO contract to manage membership size, penalty fee, and contribution amount.
- Allow DAO members to vote on changes to the membership size, penalty fee, and contribution amount.
-
Price Conversion and Fee Collection:
- Convert token prices to USD using Chainlink price feeds.
- Collect service fees in both Ether and tokens.
- Track balances for the service fee purse and thrift purse.
- Collect penalty fees in both Ether and tokens.
- Track balances for the thrift purse penalty.
-
Chainlink VRF Integration:
- Integrate with Chainlink VRF (Verifiable Random Function) for generating random numbers.
- Request random words from Chainlink VRF.
- Perform actions when the payment period is over using random words.
-
Upkeep Functionality:
- Implement an upkeep function to check and perform necessary actions based on the current state and timestamp.
The contract is structured as follows:
-
Libraries and Interfaces:
- OpenZeppelin ERC20 and ERC721 libraries.
- IERC721 and IERC721Receiver interfaces.
- Chainlink interfaces for AggregatorV3, VRFCoordinatorV2, and LinkToken.
-
Structs and Enums:
ThriftClubData
struct to store thrift club data, including token, cycle duration, contribution amount, penalty, max participants, name, description, NFT contract, DAO contract, state, and last update timestamp.TANDA_STATE
enum to represent the different states of the thrift club (OPEN, CLOSED, PAYMENT_IN_PROGRESS, COMPLETED).
-
Contract Variables:
- Storage variables for the thrift club data, paid participants count, VRF coordinator and link token contracts, key hash, callback gas limit, request confirmations, number of random words, random words storage, request ID, subscription ID, owner address, price feed interfaces, token addresses, maximum fee in USD, isParticipant mapping, participants array, hasPaidPenalty mapping, NFT contract, DAO contract, and service fee and thrift balances.
-
Constructor:
- Initializes the contract with the provided thrift club data, VRF coordinator, link token, and price feed interfaces.
- Sets the price feed token based on the provided token address.
-
Fee Collection Functions:
payPenaltyFee
: Allows participants to pay the penalty fee in Ether or tokens.joinThriftClub
: Allows participants to join the thrift club by paying the required amount and minting an NFT.startCycle
: Starts a new cycle when the maximum number of participants is reached.
-
Chainlink Integration Functions:
requestRandomWords
: Requests random words from Chainlink VRF.fulfillRandomWords
: Callback function to store the random words returned by Chainlink VRF.
-
Upkeep Functions:
checkPaymentPeriod
: Checks if the payment period is over and performs necessary actions using random words.
-
DAO Integration Functions:
setMembershipSize
: Allows DAO members to vote and set the membership size.setPenaltyFee
: Allows DAO members to vote and set the penalty fee.setContributionAmount
: Allows DAO members to vote and set the contribution amount.