- Ninad Agrawal
- Aryan Saluja
- Abhishek Johi
- Vansh Gupta
- Om Mishra
It inherits from the OpenZeppelin ERC20 and ERC20Burnable contracts to create a custom token called "XYZToken" with the symbol "XYZT."
This is the constructor of the customToken contract. It initializes the token with the name "DiscountToken" and the symbol "DIST." It also mints 10,000 tokens and approves the deployer's address for spending those tokens.
approve(address spender, uint256 value): This function allows the company's account to approve another address (spender) to spend a specified amount of tokens. It calls the internal _approve function provided by the ERC20 contract.
transferFrom(address from, address to, uint256 value): This function allows the company's account (spender) to transfer tokens from one address (from) to another (to). It first checks the allowance using the _spendAllowance function, transfers the tokens using the _transfer function, and returns a boolean value indicating success.
burnFrom(address account, uint256 value): This function enables the company's account to burn a specified amount of tokens from another address (account). It first checks the allowance using the _spendAllowance function and then calls the _burn function to destroy the tokens.
- 5 tokens : 5% discount
- 10 tokens : 10% discount
- 15 tokens : 15% discount
- 20 tokens : 20% discount
- 25 tokens : 25% discount
A public variable representing the XYZToken contract. It is used for handling token transfers and accessing the burn function to apply discounts.
An address variable representing the administrator of the store. This address is set to the deployer's address and is payable.
Constants representing token balance thresholds for different discount levels, including TEN_TOKENS, TWENTY_TOKENS, THIRDTY_TOKENS, FOURTY_TOKENS, and FIFTY_TOKENS.
A mapping that tracks which customers have been validated by the administrator.
The constructor of the XYZStore contract accepts the address of the XYZToken contract during deployment. It initializes the XYZToken contract instance and assigns the deployer's address as the admin. It is also marked as payable, allowing the contract to receive Ether.
A modifier that restricts access to functions for the admin, ensuring that only the admin can execute certain operations.
The receive function allows the contract to receive Ether. It is used to top up the store's balance with Ether.
The fallback function also allows the contract to receive Ether, providing flexibility for receiving payments.
This function is used by the admin to validate a customer. It approves the customer to spend 5 XYZTokens and updates the validatedcustomers mapping. It returns the approved token allowance.
Customers use this function to buy products. They can specify whether they want a discount. The function checks if the customer has enough Ether balance, is validated by the admin, and calculates the discount if requested. It then transfers Ether and XYZTokens accordingly. The return value is the updated customer balance.
This internal function calculates the discount amount based on the customer's XYZToken balance and the predefined discount thresholds. The function determines the discount, applies it by burning XYZTokens, and returns the calculated discount amount.
To use the XYZStore contract, follow these steps:
- Deploy the XYZStore contract, providing the address of the XYZToken contract during deployment.
- As the admin, validate customers using the validateCustomer function, allowing them to spend tokens.
- Customers can call the buyProduct function to purchase products with or without discounts.
- If eligible for a discount, the function will apply it by burning XYZTokens and transfer Ether and tokens accordingly. The function will deduct tokens from a customer's account according to the discount appliedand will give the remiaing tokens back to the customer as a sort of " Cashback" on the discounted payment.