编译器
0.8.17+commit.8df45f5f
文件 1 的 5:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 5:IPool.sol
pragma solidity ^0.8.4;
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
interface IiAI {
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
interface I9022 {
function balanceOf(address account) external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
}
contract IPool is ReentrancyGuard, Ownable {
IiAI public iAI;
I9022 public nft9022;
struct Pool {
uint256 amount;
uint256 apr;
uint256 timestamp;
string poolType;
}
string public poolType;
uint256 public apr;
uint256 public nftThreshold;
uint256 public tokenThreshold;
uint256 public minPoolPeriod;
uint256 public withdrawPenalty = 25;
bool public poolActive = true;
mapping(address => Pool[]) internal poolData;
mapping(address => uint256) internal poolBalance;
mapping(address => uint256) internal lastClaimTime;
event Pooled(address indexed from, uint256 amount);
event Unpooled(address indexed to, uint256 amount, uint256 poolPeriod);
event Penalty(address indexed to, uint256 amount);
event RewardClaimed(address indexed to, uint256 amount);
event Received(address, uint);
constructor(address iAITokenAddress, address nftTokenAddress) Ownable() {
iAI = IiAI(iAITokenAddress);
nft9022 = I9022(nftTokenAddress);
}
receive() external payable {
emit Received(msg.sender, msg.value);
}
function setPoolState() external onlyOwner {
poolActive = !poolActive;
}
function setIAIToken(address _tokenAddress) external onlyOwner {
iAI = IiAI(_tokenAddress);
}
function setNftToken(address _tokenAddress) external onlyOwner {
nft9022 = I9022(_tokenAddress);
}
function setTokenThreshold(uint256 _amount) external onlyOwner {
require(_amount > 0, 'Amount can not be 0');
tokenThreshold = _amount;
}
function setNftThreshold(uint256 _amount) external onlyOwner {
require(_amount > 0, 'Amount can not be 0');
nftThreshold = _amount;
}
function setARP(uint256 _arp) external onlyOwner {
require(_arp > 0, 'Amount can not be zero');
apr = _arp;
}
function setMinPoolingPeriod(uint256 _minstakingPeriod) external onlyOwner {
require(_minstakingPeriod > 0, "Amount cann't be zero");
minPoolPeriod = _minstakingPeriod;
}
function setWithdrawPenalty(uint256 _withdrawPenalty) external onlyOwner {
require(_withdrawPenalty > 0, "Amount cann't be zero");
withdrawPenalty = _withdrawPenalty;
}
function poolPostions(address _staker) public view returns (uint256) {
return poolBalance[_staker];
}
function poolPostionDetails(address _staker, uint256 _index) public view returns (Pool memory) {
return poolData[_staker][_index];
}
function lastclaimtime(address _staker) public view returns (uint256) {
return lastClaimTime[_staker];
}
function allPooled(address _staker) public view returns (Pool[] memory) {
return poolData[_staker];
}
function widthdrawIAI(address _address, uint256 _amount) external onlyOwner {
iAI.transfer(_address, _amount);
}
function withdraw(address _address) external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, 'Amount is too high');
payable(_address).transfer(balance);
}
function getUserTokens(address _address) public view returns (uint256[] memory) {
uint256 totalTokens = nft9022.balanceOf(_address);
uint256[] memory tokenIds = new uint256[](totalTokens);
for (uint256 i = 0; i < totalTokens; i++) {
tokenIds[i] = nft9022.tokenOfOwnerByIndex(_address, i);
}
return tokenIds;
}
}
文件 3 的 5:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 4 的 5:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 5 的 5:iAIPoolDI.sol
pragma solidity ^0.8.4;
import './IPool.sol';
contract iAIPoolDI is IPool {
mapping(uint256 => bool) public DiIds;
constructor(address iAITokenAddress, address nftTokenAddress) IPool(iAITokenAddress, nftTokenAddress) {
poolType = 'Pool Destination Inheritance';
apr = 1200;
nftThreshold = 1;
tokenThreshold = 300000 ether;
minPoolPeriod = 365 days;
}
function setDiIds(uint256[] memory keys, bool[] memory values) external onlyOwner {
require(keys.length == values.length, 'Arrays length mismatch');
for (uint256 i = 0; i < keys.length; i++) {
DiIds[keys[i]] = values[i];
}
}
function determineDI(address _address) public view returns (bool) {
uint256 totalTokens = nft9022.balanceOf(_address);
uint256 tokenId;
for (uint256 i = 0; i < totalTokens; i++) {
tokenId = nft9022.tokenOfOwnerByIndex(_address, i);
if (DiIds[tokenId]) {
return true;
}
}
return false;
}
function pool(uint256 _amount) external payable {
require(poolActive, 'Pool is not currently active');
require(determineDI(msg.sender), 'Wallet does not own any Destination Inheritance 9022 NFTs');
require(iAI.balanceOf(msg.sender) >= _amount, 'Insufficient $iAI balance');
require(_amount >= tokenThreshold, '$iAI threshold not met');
iAI.transferFrom(msg.sender, address(this), _amount);
poolBalance[msg.sender] += _amount;
poolData[msg.sender].push(Pool(_amount, apr, block.timestamp, poolType));
emit Pooled(msg.sender, _amount);
}
function unPool(uint256 _index) external nonReentrant {
require(poolActive, 'Pool is not currently active');
require(poolData[msg.sender].length > 0, 'No stakes found for the address');
require(poolData[msg.sender].length >= _index + 1, 'Stake does not exist');
uint256 lastStakeIndex = _index;
Pool memory lastStake = poolData[msg.sender][lastStakeIndex];
uint256 timeStaked = block.timestamp - lastStake.timestamp;
require(timeStaked >= minPoolPeriod, 'Minimum pooling period not reached');
uint256 latestStake = lastStake.amount;
uint256 reward = (latestStake * apr) / 10000;
uint256 payout = latestStake + reward;
for (uint256 i = _index; i < poolData[msg.sender].length - 1; i++) {
poolData[msg.sender][i] = poolData[msg.sender][i + 1];
}
poolData[msg.sender].pop();
poolBalance[msg.sender] -= latestStake;
lastClaimTime[msg.sender] = block.timestamp;
iAI.transfer(msg.sender, payout);
emit Unpooled(msg.sender, payout, timeStaked);
}
function withdrawPosition(uint256 _index) external nonReentrant {
require(poolActive, 'Pool is not currently active');
require(poolData[msg.sender].length > 0, 'No stakes found for the address');
require(poolData[msg.sender].length >= _index + 1, 'Stake does not exist');
uint256 lastStakeIndex = _index;
Pool memory lastStake = poolData[msg.sender][lastStakeIndex];
uint256 timeStaked = block.timestamp - lastStake.timestamp;
uint256 latestStake = lastStake.amount;
require(timeStaked <= minPoolPeriod, 'Withdraw with penalty time exceed you can now unstake token ');
uint256 penalty = (latestStake * withdrawPenalty) / 100;
for (uint256 i = _index; i < poolData[msg.sender].length - 1; i++) {
poolData[msg.sender][i] = poolData[msg.sender][i + 1];
}
poolData[msg.sender].pop();
poolBalance[msg.sender] -= latestStake;
lastClaimTime[msg.sender] = block.timestamp;
uint256 payout = latestStake - penalty;
iAI.transfer(msg.sender, payout);
emit Penalty(msg.sender, payout);
}
function claimReward() external nonReentrant {
require(poolActive, 'Pool is not currently active');
require(poolData[msg.sender].length > 0, 'No stakes found for the address');
uint256 totalStaked = poolBalance[msg.sender];
uint256 lastClaim = lastClaimTime[msg.sender];
uint256 timeElapsed = block.timestamp - lastClaim;
require(timeElapsed > 0, 'No rewards to claim');
uint256 reward = (totalStaked * (apr / 365) * (timeElapsed / 1 days)) / 100;
require(reward > 0, 'Not Eligible for reward');
lastClaimTime[msg.sender] = block.timestamp;
iAI.transfer(msg.sender, reward);
emit RewardClaimed(msg.sender, reward);
}
}
{
"compilationTarget": {
"contracts/iAIPoolDI.sol": "iAIPoolDI"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"iAITokenAddress","type":"address"},{"internalType":"address","name":"nftTokenAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Penalty","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Pooled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"poolPeriod","type":"uint256"}],"name":"Unpooled","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"DiIds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"}],"name":"allPooled","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"apr","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"string","name":"poolType","type":"string"}],"internalType":"struct IPool.Pool[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"apr","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"determineDI","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getUserTokens","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"iAI","outputs":[{"internalType":"contract IiAI","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"}],"name":"lastclaimtime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minPoolPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nft9022","outputs":[{"internalType":"contract I9022","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"pool","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"poolActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"poolPostionDetails","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"apr","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"string","name":"poolType","type":"string"}],"internalType":"struct IPool.Pool","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_staker","type":"address"}],"name":"poolPostions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolType","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_arp","type":"uint256"}],"name":"setARP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"keys","type":"uint256[]"},{"internalType":"bool[]","name":"values","type":"bool[]"}],"name":"setDiIds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"setIAIToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minstakingPeriod","type":"uint256"}],"name":"setMinPoolingPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"setNftThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"setNftToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setPoolState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"setTokenThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_withdrawPenalty","type":"uint256"}],"name":"setWithdrawPenalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tokenThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"unPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"widthdrawIAI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawPenalty","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"withdrawPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]