Skip to content

Feat/project 69 #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,375 changes: 1,375 additions & 0 deletions .openzeppelin/base-sepolia.json

Large diffs are not rendered by default.

50 changes: 14 additions & 36 deletions contracts/genesis/FGenesis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,29 @@ contract FGenesis is Initializable, AccessControlUpgradeable {

function _setParams(Params memory p) internal {
require(
p.virtualToken != address(0) &&
p.feeAddr != address(0) &&
p.tbaImpl != address(0) &&
p.agentFactory != address(0),
"Invalid addr"
p.virtualToken != address(0) && p.feeAddr != address(0) &&
p.tbaImpl != address(0) && p.agentFactory != address(0),
"Zero addr"
);

require(
p.reserve > 0 && p.maxContribution > 0 && p.feeAmt > 0,
"Invalid amt"
);

require(
p.duration > 0 &&
p.agentTokenTotalSupply > 0 &&
p.agentTokenLpSupply > 0 &&
p.agentTokenTotalSupply >= p.agentTokenLpSupply,
p.reserve > 0 && p.maxContribution > 0 && p.feeAmt > 0 &&
p.duration > 0 && p.agentTokenTotalSupply > 0 &&
p.agentTokenLpSupply > 0 && p.agentTokenTotalSupply >= p.agentTokenLpSupply,
"Invalid amt"
);

params = p;
}

function createGenesis(
GenesisCreationParams memory gParams
GenesisCreationParams memory gParams,
bool noLpStake
) external returns (address) {
require(
IERC20(params.virtualToken).transferFrom(
msg.sender,
params.feeAddr,
params.feeAmt
),
"transfer createGenesis fee failed"
IERC20(params.virtualToken).transferFrom(
msg.sender,
params.feeAddr,
params.feeAmt
);

gParams.endTime = gParams.startTime + params.duration;
Expand All @@ -106,7 +96,8 @@ contract FGenesis is Initializable, AccessControlUpgradeable {
params.reserve,
params.maxContribution,
params.agentTokenTotalSupply,
params.agentTokenLpSupply
params.agentTokenLpSupply,
noLpStake
);

IAccessControl(params.agentFactory).grantRole(
Expand All @@ -125,19 +116,6 @@ contract FGenesis is Initializable, AccessControlUpgradeable {
return Genesis(addr);
}

function onGenesisSuccess(
uint256 id,
SuccessParams calldata p
) external onlyRole(OPERATION_ROLE) returns (address) {
return
_getGenesis(id).onGenesisSuccess(
p.refundAddresses,
p.refundAmounts,
p.distributeAddresses,
p.distributeAmounts,
p.creator
);
}

function onGenesisSuccessSalt(
uint256 id,
Expand Down
94 changes: 29 additions & 65 deletions contracts/genesis/Genesis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./FGenesis.sol";
import "../virtualPersona/IAgentFactoryV3.sol";
import "../virtualPersona/IAgentFactoryV5.sol";
// import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./GenesisTypes.sol";
Expand Down Expand Up @@ -45,6 +45,8 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
address public agentTokenAddress;
bool public isFailed;
bool public isCancelled;
bool public noLpStake;
uint256 public totalClaimableAgentTokensLeft;

event AssetsWithdrawn(
uint256 indexed genesisID,
Expand Down Expand Up @@ -99,6 +101,8 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
"End time must be after start time";
string private constant ERR_TOKEN_LAUNCHED = "Agent token already launched";
string private constant ERR_TOKEN_NOT_LAUNCHED = "Agent token not launched";
string private constant ERR_ZERO_ADD = "Address cannot be empty";
string private constant ERR_INVALID_PARAM = "Invalid value for parameter";

// Common validation modifiers
modifier whenNotStarted() {
Expand Down Expand Up @@ -169,46 +173,24 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
) external initializer {
__AccessControl_init();

require(params.genesisID > 0, "Invalid genesis ID");
require(params.factory != address(0), "Invalid factory address");
require(params.genesisID > 0, "Invalid ID");
require(params.factory != address(0) && params.tbaImplementation != address(0)
&& params.agentFactoryAddress != address(0) && params.virtualTokenAddress != address(0), ERR_ZERO_ADD);
_validateTime(params.startTime, params.endTime);
require(bytes(params.genesisName).length > 0, "Invalid genesis name");
require(bytes(params.genesisName).length > 0, "Invalid name");
require(
bytes(params.genesisTicker).length > 0,
"Invalid genesis ticker"
"Invalid ticker"
);
require(params.genesisCores.length > 0, "Invalid genesis cores");
require(params.genesisCores.length > 0, "Invalid cores");
require(
params.tbaImplementation != address(0),
"Invalid TBA implementation address"
);
require(
params.agentFactoryAddress != address(0),
"Invalid agent factory address"
);
require(
params.virtualTokenAddress != address(0),
"Invalid virtual token address"
);
require(
params.reserveAmount > 0,
"Reserve amount must be greater than 0"
);
require(
params.maxContributionVirtualAmount > 0,
"Max contribution must be greater than 0"
);
require(
params.agentTokenTotalSupply > 0,
"Agent token total supply must be greater than 0"
);
require(
params.agentTokenLpSupply > 0,
"Agent token lp supply must be greater than 0"
params.reserveAmount > 0 && params.maxContributionVirtualAmount > 0
&& params.agentTokenTotalSupply > 0 && params.agentTokenLpSupply > 0,
ERR_INVALID_PARAM
);
require(
params.agentTokenTotalSupply >= params.agentTokenLpSupply,
"Agent token total supply must be greater than agent token lp supply"
"Agent token total supply must be > agent token lp supply"
);

genesisId = params.genesisID;
Expand All @@ -228,6 +210,7 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
maxContributionVirtualAmount = params.maxContributionVirtualAmount;
agentTokenTotalSupply = params.agentTokenTotalSupply;
agentTokenLpSupply = params.agentTokenLpSupply;
noLpStake = params.noLpStake;

_grantRole(DEFAULT_ADMIN_ROLE, params.factory);
_grantRole(FACTORY_ROLE, params.factory);
Expand All @@ -237,8 +220,8 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
uint256 pointAmt,
uint256 virtualsAmt
) external nonReentrant whenActive {
require(pointAmt > 0, "Point amount must be greater than 0");
require(virtualsAmt > 0, "Virtuals must be greater than 0");
require(pointAmt > 0, "Point amount must be > 0");
require(virtualsAmt > 0, "Virtuals must be > 0");

// Check single submission upper limit
require(
Expand All @@ -263,31 +246,6 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
emit Participated(genesisId, msg.sender, pointAmt, virtualsAmt);
}

function onGenesisSuccess(
address[] calldata refundVirtualsTokenUserAddresses,
uint256[] calldata refundVirtualsTokenUserAmounts,
address[] calldata distributeAgentTokenUserAddresses,
uint256[] calldata distributeAgentTokenUserAmounts,
address creator
)
external
onlyRole(FACTORY_ROLE)
nonReentrant
whenNotCancelled
whenEnded
returns (address)
{
return
_onGenesisSuccessSalt(
refundVirtualsTokenUserAddresses,
refundVirtualsTokenUserAmounts,
distributeAgentTokenUserAddresses,
distributeAgentTokenUserAmounts,
creator,
keccak256(abi.encodePacked(msg.sender, block.timestamp))
);
}

function onGenesisSuccessSalt(
address[] calldata refundVirtualsTokenUserAddresses,
uint256[] calldata refundVirtualsTokenUserAmounts,
Expand Down Expand Up @@ -350,7 +308,7 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
);

// Call initFromBondingCurve and executeBondingCurveApplication
uint256 id = IAgentFactoryV3(agentFactoryAddress)
uint256 id = IAgentFactoryV5(agentFactoryAddress)
.initFromBondingCurve(
string.concat(genesisName, " by Virtuals"),
genesisTicker,
Expand All @@ -363,16 +321,17 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
creator
);

address agentToken = IAgentFactoryV3(agentFactoryAddress)
address agentToken = IAgentFactoryV5(agentFactoryAddress)
.executeBondingCurveApplicationSalt(
id,
agentTokenTotalSupply,
agentTokenLpSupply,
address(this), // vault
salt
salt,
noLpStake
);

require(agentToken != address(0), "Agent token creation failed");
require(agentToken != address(0), ERR_ZERO_ADD);

// Store the created agent token address
agentTokenAddress = agentToken;
Expand Down Expand Up @@ -410,9 +369,13 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {

// save the amount of agent tokens to claim
for (uint256 i = 0; i < distributeAgentTokenUserAddresses.length; i++) {
totalClaimableAgentTokensLeft -= claimableAgentTokens[
distributeAgentTokenUserAddresses[i]
]; // because here is replace update, so we need to minus the old amount
claimableAgentTokens[
distributeAgentTokenUserAddresses[i]
] = distributeAgentTokenUserAmounts[i];
totalClaimableAgentTokensLeft += distributeAgentTokenUserAmounts[i];
}

emit GenesisSucceeded(genesisId);
Expand All @@ -425,6 +388,7 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
require(amount > 0, "No tokens to claim");

// set the amount of claimable agent tokens to 0, to prevent duplicate claims
totalClaimableAgentTokensLeft -= amount;
claimableAgentTokens[userAddress] = 0;

// transfer the agent token
Expand Down Expand Up @@ -597,7 +561,7 @@ contract Genesis is ReentrancyGuard, AccessControlUpgradeable {
whenEnded
whenFinalized
{
require(token != address(0), "Invalid token address");
require(token != address(0), ERR_ZERO_ADD);
require(
amount <= IERC20(token).balanceOf(address(this)),
"Insufficient balance to withdraw"
Expand Down
6 changes: 4 additions & 2 deletions contracts/genesis/GenesisLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ library GenesisLib {
uint256 reserve,
uint256 maxContribution,
uint256 agentTokenTotalSupply,
uint256 agentTokenLpSupply
uint256 agentTokenLpSupply,
bool noLpStake
) internal returns (address) {
require(
bytes(params.genesisName).length > 0 &&
Expand Down Expand Up @@ -47,7 +48,8 @@ library GenesisLib {
reserveAmount: reserve,
maxContributionVirtualAmount: maxContribution,
agentTokenTotalSupply: agentTokenTotalSupply,
agentTokenLpSupply: agentTokenLpSupply
agentTokenLpSupply: agentTokenLpSupply,
noLpStake: noLpStake
});

newGenesis.initialize(initParams);
Expand Down
1 change: 1 addition & 0 deletions contracts/genesis/GenesisTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ struct GenesisInitParams {
uint256 maxContributionVirtualAmount;
uint256 agentTokenTotalSupply;
uint256 agentTokenLpSupply;
bool noLpStake;
}
Loading