Implement a maximum transaction limit on a smart contract deployed on the Polygon Network. This will limit the maximum amount of tokens bought or sold in a single transaction, preventing large transactions that could potentially manipulate the market.
Maximum Transaction Limit
A maximum transaction limit should be added to the smart contract. The maximum amount of tokens bought or sold in a single transaction should be set to a reasonable value, such as 1% of the total supply of tokens.
Code Example
The following code snippet shows how to implement a maximum transaction limit on a smart contract deployed on the Polygon Network:
contract MyContract is ERC20 {
uint256 public maxTransactionAmount;
constructor() {
maxTransactionAmount = totalSupply() / 100; // Set max transaction amount to 1% of total supply
}
function setMaxTransactionAmount(uint256 _maxTransactionAmount) external onlyOwner {
maxTransactionAmount = _maxTransactionAmount;
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
require(amount <= maxTransactionAmount, "Amount exceeds max transaction limit");
_transfer(_msgSender(), recipient, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
require(amount <= maxTransactionAmount, "Amount exceeds max transaction limit");
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance(sender, _msgSender()) - amount);
return true;
}
}
In this code example, the maxTransactionAmount variable is set to 1% of the total supply of tokens in the constructor. The setMaxTransactionAmount function allows the contract owner to update the maximum transaction amount. The transfer and transferFrom functions have a required statement that checks whether the transferred amount is less than or equal to the maximum transaction amount. If the amount exceeds the maximum transaction amount, the transaction will be reverted.
🎯 Acceptance Criteria
[ ] The smart contract should add a maximum transaction limit.
[ ] The maximum amount of tokens bought or sold in a single transaction should be set to a reasonable value, such as 1% of the total supply of tokens.
[ ] Transactions that exceed the maximum transaction limit should be reverted.
📝 Issue Description
Implement a maximum transaction limit on a smart contract deployed on the Polygon Network. This will limit the maximum amount of tokens bought or sold in a single transaction, preventing large transactions that could potentially manipulate the market.
Maximum Transaction Limit
A maximum transaction limit should be added to the smart contract. The maximum amount of tokens bought or sold in a single transaction should be set to a reasonable value, such as 1% of the total supply of tokens.
Code Example
The following code snippet shows how to implement a maximum transaction limit on a smart contract deployed on the Polygon Network:
In this code example, the maxTransactionAmount variable is set to 1% of the total supply of tokens in the constructor. The setMaxTransactionAmount function allows the contract owner to update the maximum transaction amount. The transfer and transferFrom functions have a required statement that checks whether the transferred amount is less than or equal to the maximum transaction amount. If the amount exceeds the maximum transaction amount, the transaction will be reverted.
🎯 Acceptance Criteria