Skip to content

Commit

Permalink
MOD: aime creator contract
Browse files Browse the repository at this point in the history
  • Loading branch information
cctv2206 committed Apr 15, 2024
1 parent f9167be commit 0739d9d
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 26 deletions.
104 changes: 104 additions & 0 deletions contracts/aime/AIMeCreator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

interface IAIMeFactory {
function createAIMeVerified(
address creator_,
string memory name_,
string memory avatar_,
string memory bio_,
string memory image_,
string memory socialKey_,
string memory socialId_,
uint256 minPrice_,
uint256 priceIncrement_,
address aimePowerAddress,
bytes memory signature
) external payable;
}

interface IAIMePowerLauncher {
function launchPower(
uint256 _price,
uint256 _amountPerUnits,
uint256 _totalSupply,
uint256 _reservedAmount,
uint256 _deadline,
uint24 _poolFee,
string memory _name,
string memory _symbol
) external returns (address);
}

contract AIMeCreator is Ownable {
IAIMeFactory public factory;
IAIMePowerLauncher public powerLauncher;

struct PowerConfig {
uint256 price;
uint256 amountPerUnits;
uint256 totalSupply;
uint256 reservedAmount;
uint256 deadline;
uint24 poolFee;
}

struct AIMeConfig {
string name;
string avatar;
string bio;
string image;
string socialKey;
string socialId;
uint256 minPrice;
uint256 priceIncrement;
}

constructor() {}

function updateAIMeAddresses(IAIMeFactory _factory, IAIMePowerLauncher _powerLauncher) public onlyOwner {
factory = _factory;
powerLauncher = _powerLauncher;
}

function create(
string memory _name,
string memory _symbol,
PowerConfig memory _powerConfig,
AIMeConfig memory _aimeConfig,
bytes memory signature
) public payable {
address powerAddress = powerLauncher.launchPower(
_powerConfig.price,
_powerConfig.amountPerUnits,
_powerConfig.totalSupply,
_powerConfig.reservedAmount,
_powerConfig.deadline,
_powerConfig.poolFee,
_name,
_symbol
);

bytes memory data = abi.encodeWithSignature(
"createAIMeVerified(address,string,string,string,string,string,string,uint256,uint256,address,bytes)",
msg.sender,
_aimeConfig.name,
_aimeConfig.avatar,
_aimeConfig.bio,
_aimeConfig.image,
_aimeConfig.socialKey,
_aimeConfig.socialId,
_aimeConfig.minPrice,
_aimeConfig.priceIncrement,
powerAddress,
signature
);
(bool success, ) = address(factory).call{value: msg.value}(data);

require(success, "Call failed");
}

receive() external payable {}
}
11 changes: 8 additions & 3 deletions contracts/aime/AIMeFactoryV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract AIMeFactoryV4 is Ownable {
}

function createAIMeVerified(
address creator_,
string memory name_,
string memory avatar_,
string memory bio_,
Expand All @@ -41,7 +42,7 @@ contract AIMeFactoryV4 is Ownable {
bytes32 _msgHash = ECDSA.toEthSignedMessageHash(
keccak256(
abi.encodePacked(
msg.sender,
creator_,
name_,
avatar_,
bio_,
Expand All @@ -51,7 +52,7 @@ contract AIMeFactoryV4 is Ownable {
socialId_,
minPrice_,
priceIncrement_,
aimePowerAddress,
// aimePowerAddress,
addressNonce[msg.sender]
)
)
Expand All @@ -64,6 +65,7 @@ contract AIMeFactoryV4 is Ownable {
addressNonce[msg.sender] += 1;

address aimeAddress = _createAIME(
creator_,
name_,
avatar_,
bio_,
Expand All @@ -87,6 +89,7 @@ contract AIMeFactoryV4 is Ownable {
}

function createAIME(
address creator_,
string memory name_,
string memory avatar_,
string memory bio_,
Expand All @@ -97,6 +100,7 @@ contract AIMeFactoryV4 is Ownable {
address aimePowerAddress
) public payable {
_createAIME(
creator_,
name_,
avatar_,
bio_,
Expand All @@ -109,6 +113,7 @@ contract AIMeFactoryV4 is Ownable {
}

function _createAIME(
address creator_,
string memory name_,
string memory avatar_,
string memory bio_,
Expand All @@ -135,7 +140,7 @@ contract AIMeFactoryV4 is Ownable {
aimeAddresses[name_] = aimeAddress;
aimeSigners[aimeAddress] = aimeSigner;

emit AIMeCreated(msg.sender, address(aime));
emit AIMeCreated(creator_, address(aime));
return aimeAddress;
}

Expand Down
26 changes: 11 additions & 15 deletions contracts/aime/AIMePowerFairLaunchV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ contract AIMePowerFairLaunchV2 is ERC20, ReentrancyGuard, IERC721Receiver {
uint256 amount,
uint256 ethAmount
);
event AIMePowerFairLaunched(
uint256 amount0,
uint256 amount1
);
event AIMePowerFairLaunched(uint256 amount0, uint256 amount1);

constructor(
uint256 _price,
Expand Down Expand Up @@ -99,15 +96,10 @@ contract AIMePowerFairLaunchV2 is ERC20, ReentrancyGuard, IERC721Receiver {
}

receive() external payable {
// todo: require value != 0?
if (msg.sender != launcher) {
if (block.timestamp > deadline || minted == mintLimit) {
start();
} else {
mint();
}
} else {
if (block.timestamp > deadline || minted == mintLimit) {
start();
} else {
mint();
}
}

Expand Down Expand Up @@ -224,7 +216,7 @@ contract AIMePowerFairLaunchV2 is ERC20, ReentrancyGuard, IERC721Receiver {
int24 tickSpacing = IUniswapV3Pool(pool).tickSpacing();
(, int24 tick, , , , , ) = IUniswapV3Pool(pool).slot0();

int24 tickUpper = TickMath.MAX_TICK / tickSpacing * tickSpacing;
int24 tickUpper = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;

// todo: calculate tick lower and upper
INonfungiblePositionManager.MintParams
Expand All @@ -242,8 +234,12 @@ contract AIMePowerFairLaunchV2 is ERC20, ReentrancyGuard, IERC721Receiver {
deadline: block.timestamp
});

(uint256 tokenId, uint256 liquidity, uint256 amount0, uint256 amount1) = nonfungiblePositionManager
.mint(params);
(
uint256 tokenId,
uint256 liquidity,
uint256 amount0,
uint256 amount1
) = nonfungiblePositionManager.mint(params);

positionTokenId = tokenId;

Expand Down
6 changes: 4 additions & 2 deletions contracts/aime/AIMePowerLauncher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract AIMePowerLauncher {
uint24 _poolFee,
string memory _name,
string memory _symbol
) external {
) external returns (address) {
AIMePowerFairLaunchV2 power = new AIMePowerFairLaunchV2(
_price,
_amountPerUnits,
Expand All @@ -38,9 +38,10 @@ contract AIMePowerLauncher {
);

emit PowerLaunched(address(power), msg.sender);
return address(power);
}

function launchPowerSimple(string memory _name) external {
function launchPowerSimple(string memory _name) external returns (address) {
AIMePowerFairLaunchV2 power = new AIMePowerFairLaunchV2(
1000000000000000, // 0.001 eth
50000000000000000000000, // 5w
Expand All @@ -56,5 +57,6 @@ contract AIMePowerLauncher {
);

emit PowerLaunched(address(power), msg.sender);
return address(power);
}
}
42 changes: 38 additions & 4 deletions scripts/aime/deploy_aime.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
import { ethers } from "hardhat";
import { AIMeFactoryV4 } from "../../typechain";
import { AIMeFactoryV4, AIMePowerLauncher, AIMeCreator } from "../../typechain";

async function deployAIMeForTest(): Promise<AIMeFactoryV4> {
async function deployAIMeContracts() {
const contractFactory = await ethers.getContractFactory("AIMeFactoryV4");
const instance = await contractFactory.deploy();
await instance.deployed();

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

return instance;
const powerLauncherContractFactory = await ethers.getContractFactory(
"AIMePowerLauncher"
);
const powerLauncher = await powerLauncherContractFactory.deploy();
await powerLauncher.deployed();

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

const aimeCreatorContractFactory = await ethers.getContractFactory(
"AIMeCreator"
);
const aimeCreator = await aimeCreatorContractFactory.deploy();
await aimeCreator.deployed();

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

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

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

async function deployAIMeCreatorLauncher() {
const aimeCreatorContractFactory = await ethers.getContractFactory(
"AIMeCreator"
);
const aimeCreator = await aimeCreatorContractFactory.deploy();
await aimeCreator.deployed();

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

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

0 comments on commit 0739d9d

Please sign in to comment.