Skip to content

Commit

Permalink
ADD: tests and mod
Browse files Browse the repository at this point in the history
  • Loading branch information
cctv2206 committed Jun 12, 2024
1 parent 6f229df commit 692d7e8
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 198 deletions.
2 changes: 1 addition & 1 deletion contracts/aime/AIMeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract AIMeFactory is IAIMeFactory {
AIMeParams memory params
) public returns (address) {
AIMeNFT aime = new AIMeNFT(
string(abi.encodePacked("AIME:", params.name)),
string(abi.encodePacked("EMIA:", params.name)),
params.name,
params.avatar,
params.bio,
Expand Down
17 changes: 16 additions & 1 deletion contracts/aime/AIMeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,22 @@ contract AIMeManager is Ownable {
uint256 amount,
bytes memory signature
) public {
// todo: check sig
bytes32 _msgHash = ECDSA.toEthSignedMessageHash(
keccak256(
abi.encodePacked(
msg.sender,
aimeAddress,
aimePowerAddress,
amount,
addressNonce[msg.sender]
)
)
);
require(
ECDSA.recover(_msgHash, signature) == _signer,
"Invalid signature"
);
addressNonce[msg.sender] += 1;

IAIMeNFT(aimeAddress).claimReward(aimePowerAddress, amount, msg.sender);
}
Expand Down
1 change: 0 additions & 1 deletion contracts/aime/AIMePowerLauncher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.s
import "./AIMePowerToken.sol";

interface IAIMePowerLauncher {
// todo: change this
function launchPower(
string memory _name,
string memory _symbol,
Expand Down
65 changes: 60 additions & 5 deletions contracts/aime/AIMePowerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
using SafeMath for uint256;

mapping(address => uint256) private _balances;
uint256 private _totalSupply;

uint256 public maxGasPrice = 1 * 10 ** 18; // todo: value
uint256 public duration = 7 days;
Expand All @@ -45,7 +46,6 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
uint256 total;
uint256 released;
uint256 startTime;
uint256 updateTime;
}

mapping(address => uint) public vestCursor;
Expand Down Expand Up @@ -83,6 +83,13 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
_mint(_aimeAddress, _initTokenBalance);
}

/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}

/**
* @dev See {IERC20-balanceOf}.
*/
Expand All @@ -107,9 +114,7 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
}
released += info.released;
total += info.total;
if (block.timestamp <= info.updateTime) {
canRelease += info.total - info.released;
} else if (block.timestamp >= info.startTime + duration) {
if (block.timestamp >= info.startTime + duration) {
canRelease += info.total - info.released;
} else {
uint temp = (info.total * (block.timestamp - info.startTime)) /
Expand All @@ -119,6 +124,56 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
}
}


/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual override {
require(account != address(0), "ERC20: mint to the zero address");

_beforeTokenTransfer(address(0), account, amount);

_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);

_afterTokenTransfer(address(0), account, amount);
}

/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual override {
require(account != address(0), "ERC20: burn from the zero address");

_beforeTokenTransfer(account, address(0), amount);

uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;

emit Transfer(account, address(0), amount);

_afterTokenTransfer(account, address(0), amount);
}

function _transfer(
address from,
address to,
Expand Down Expand Up @@ -185,7 +240,6 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
} else {
toInfo.total += amount;
}
toInfo.updateTime = block.timestamp;
}

function claimRelease(address account) public {
Expand Down Expand Up @@ -285,6 +339,7 @@ contract AIMePowerToken is ERC20, BancorFormula, ReentrancyGuard, IERC721Receive
require(!launched, "Cannot sell after launch");
uint256 reimbursement = calculateSellTokenReturn(_amount);
poolBalance = poolBalance.sub(reimbursement);
claimRelease(msg.sender);
_burn(msg.sender, _amount);

(bool success, ) = payable(msg.sender).call{value: reimbursement}("");
Expand Down
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ const config = {
: [],
},
base: {
url: 'https://mainnet.base.org',
url: "https://mainnet.base.org",
chainId: 8453,
accounts:
process.env.TESTNET_PRIVATE_KEY !== undefined
? [process.env.TESTNET_PRIVATE_KEY]
: [],
},
baseProd: {
url: 'https://mainnet.base.org',
url: "https://mainnet.base.org",
chainId: 8453,
accounts:
process.env.BASE_MAINNET_PRIVATE_KEY !== undefined
Expand Down
95 changes: 53 additions & 42 deletions scripts/aime/deploy_aime.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,98 @@
import { ethers } from "hardhat";
import { AIMeFactoryV4, AIMePowerLauncher, AIMePowerLauncherSepolia, AIMeCreator } from "../../typechain";

const NonfungiblePositionManager = "0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1"; // on base
const SwapRouterAddress = "0x2626664c2603336E57B271c5C0b26F421741e481"; // swap router2 on base

async function deployAIMeContractsAll() {
const contractFactory = await ethers.getContractFactory("AIMeFactoryV4");
const instance = await contractFactory.deploy();
await instance.deployed();
// power launcher
const powerLauncherAddress = await deployAIMePowerLauncher();

console.log("AIMeFactory V4 contract deployed to", instance.address);
// aime factory
const factoryAddress = await deployAIMeFactory();

const powerLauncherContractFactory = await ethers.getContractFactory(
"AIMePowerLauncher"
// manager
const managerAddress = await deployAIMeManager();

const aimeManagerContractFactory = await ethers.getContractFactory(
"AIMeManager"
);
const powerLauncher = await powerLauncherContractFactory.deploy();
await powerLauncher.deployed();
const managerContract = aimeManagerContractFactory.attach(managerAddress);

console.log("powerLauncher contract deployed to", powerLauncher.address);
const tx1 = await managerContract.updateAIMeFactory(factoryAddress);
await tx1.wait();

const aimeCreatorContractFactory = await ethers.getContractFactory(
"AIMeCreator"
const tx2 = await managerContract.updateAIMePowerLauncher(
powerLauncherAddress
);
const aimeCreator = await aimeCreatorContractFactory.deploy();
await aimeCreator.deployed();
await tx2.wait();

console.log("aimeCreator contract deployed to", aimeCreator.address);
console.log("Power launcher and fatory updated in manager contract");
}

async function deployAIMeFactoryV4() {
const contractFactory = await ethers.getContractFactory("AIMeFactoryV4");
const instance = await contractFactory.deploy();
await instance.deployed();
// async function deployAIMeFactoryV4() {
// const contractFactory = await ethers.getContractFactory("AIMeFactoryV4");
// const instance = await contractFactory.deploy();
// await instance.deployed();

console.log("AIMeFactory V4 contract deployed to", instance.address);
}
// console.log("AIMeFactory V4 contract deployed to", instance.address);
// }

async function deployAIMeFactoryBeta() {
const contractFactory = await ethers.getContractFactory("AIMeFactoryBeta");
const instance = await contractFactory.deploy();
await instance.deployed();
// async function deployAIMeFactoryBeta() {
// const contractFactory = await ethers.getContractFactory("AIMeFactoryBeta");
// const instance = await contractFactory.deploy();
// await instance.deployed();

console.log("AIMeFactory [Beta] contract deployed to", instance.address);
}
// console.log("AIMeFactory [Beta] contract deployed to", instance.address);
// }

async function deployAIMeFactory() {
const contractFactory = await ethers.getContractFactory("AIMeFactory");
const instance = await contractFactory.deploy();
await instance.deployed();

console.log("AIMeFactory contract deployed to", instance.address);
return instance.address;
}

async function deployAIMePowerLauncher() {
const powerLauncherContractFactory = await ethers.getContractFactory(
"AIMePowerLauncher"
);
const powerLauncher = await powerLauncherContractFactory.deploy();
const powerLauncher = await powerLauncherContractFactory.deploy(
NonfungiblePositionManager,
SwapRouterAddress
);
await powerLauncher.deployed();

console.log("powerLauncher contract deployed to", powerLauncher.address);
return powerLauncher.address;
}

async function deployAIMePowerLauncherSepolia() {
const powerLauncherContractFactory = await ethers.getContractFactory(
"AIMePowerLauncherSepolia"
);
const powerLauncher = await powerLauncherContractFactory.deploy();
await powerLauncher.deployed();
// async function deployAIMePowerLauncherSepolia() {
// const powerLauncherContractFactory = await ethers.getContractFactory(
// "AIMePowerLauncherSepolia"
// );
// const powerLauncher = await powerLauncherContractFactory.deploy();
// await powerLauncher.deployed();

console.log("powerLauncher sepolia contract deployed to", powerLauncher.address);
}
// console.log("powerLauncher sepolia contract deployed to", powerLauncher.address);
// }

async function deployAIMeCreator() {
const aimeCreatorContractFactory = await ethers.getContractFactory(
"AIMeCreator"
async function deployAIMeManager() {
const aimeManagerContractFactory = await ethers.getContractFactory(
"AIMeManager"
);
const aimeCreator = await aimeCreatorContractFactory.deploy();
await aimeCreator.deployed();
const aimeManager = await aimeManagerContractFactory.deploy();
await aimeManager.deployed();

console.log("aimeCreator contract deployed to", aimeCreator.address);
console.log("aimeManager contract deployed to", aimeManager.address);
return aimeManager.address;
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
deployAIMeFactory().catch((error) => {
deployAIMeContractsAll().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Loading

0 comments on commit 692d7e8

Please sign in to comment.