Skip to content
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

Fix/zenith #56

Open
wants to merge 12 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
51 changes: 42 additions & 9 deletions contracts/fun/Bonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ contract Bonding is
purchaseAmount > fee,
"Purchase amount must be greater than fee"
);

require(cores.length > 0, "Cores must be provided");

address assetToken = router.assetToken();
require(
IERC20(assetToken).balanceOf(msg.sender) >= purchaseAmount,
Expand All @@ -211,7 +214,12 @@ contract Bonding is
initialPurchase
);

FERC20 token = new FERC20(string.concat("fun ", _name), _ticker, initialSupply, maxTx);
FERC20 token = new FERC20(
string.concat("fun ", _name),
_ticker,
initialSupply,
maxTx
);
uint256 supply = token.totalSupply();

address _pair = factory.createPair(address(token), assetToken);
Expand Down Expand Up @@ -279,17 +287,26 @@ contract Bonding is

// Make initial purchase
IERC20(assetToken).forceApprove(address(router), initialPurchase);
router.buy(initialPurchase, address(token), address(this));
_buy(
address(this),
initialPurchase,
address(token),
0,
block.timestamp + 300
);
token.transfer(msg.sender, token.balanceOf(address(this)));

return (address(token), _pair, n);
}

function sell(
uint256 amountIn,
address tokenAddress
address tokenAddress,
uint256 amountOutMin,
uint256 deadline
) public returns (bool) {
require(tokenInfo[tokenAddress].trading, "Token not trading");
require(block.timestamp <= deadline, "Deadline exceeded");

address pairAddress = factory.getPair(
tokenAddress,
Expand All @@ -305,6 +322,7 @@ contract Bonding is
tokenAddress,
msg.sender
);
require(amount1Out >= amountOutMin, "Slippage too high");

uint256 newReserveA = reserveA + amount0In;
uint256 newReserveB = reserveB - amount1Out;
Expand Down Expand Up @@ -338,12 +356,14 @@ contract Bonding is
return true;
}

function buy(
function _buy(
address buyer,
uint256 amountIn,
address tokenAddress
) public payable returns (bool) {
require(tokenInfo[tokenAddress].trading, "Token not trading");

address tokenAddress,
uint256 amountOutMin,
uint256 deadline
) internal {
require(block.timestamp <= deadline, "Deadline exceeded");
address pairAddress = factory.getPair(
tokenAddress,
router.assetToken()
Expand All @@ -356,9 +376,11 @@ contract Bonding is
(uint256 amount1In, uint256 amount0Out) = router.buy(
amountIn,
tokenAddress,
msg.sender
buyer
);

require(amount0Out >= amountOutMin, "Slippage too high");

uint256 newReserveA = reserveA - amount0Out;
uint256 newReserveB = reserveB + amount1In;
uint256 duration = block.timestamp -
Expand Down Expand Up @@ -391,6 +413,17 @@ contract Bonding is
if (newReserveA <= gradThreshold && tokenInfo[tokenAddress].trading) {
_openTradingOnUniswap(tokenAddress);
}
}

function buy(
uint256 amountIn,
address tokenAddress,
uint256 amountOutMin,
uint256 deadline
) public payable returns (bool) {
require(tokenInfo[tokenAddress].trading, "Token not trading");

_buy(msg.sender, amountIn, tokenAddress, amountOutMin, deadline);

return true;
}
Expand Down
1 change: 0 additions & 1 deletion contracts/fun/FERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ contract FERC20 is Context, IERC20, Ownable {
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");

if (!isExcludedFromMaxTx[from]) {
require(amount <= _maxTxAmount, "Exceeds MaxTx");
Expand Down
4 changes: 1 addition & 3 deletions contracts/tax/BondingTax.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ contract BondingTax is
function swapForAsset() public onlyBondingRouter returns (bool, uint256) {
uint256 amount = IERC20(taxToken).balanceOf(address(this));

require(amount > 0, "Nothing to be swapped");

if (amount < minSwapThreshold) {
if (amount < minSwapThreshold || amount == 0) {
return (false, 0);
}

Expand Down
12 changes: 12 additions & 0 deletions contracts/token/Airdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ contract Airdrop {
uint256[] calldata _amounts,
uint256 _total
) external {
// Ensure arrays have same length
require(_recipients.length == _amounts.length, "Length mismatch");

// Calculate sum of amounts
uint256 sum;
for(uint256 i = 0; i < _amounts.length; i++) {
sum += _amounts[i];
}

// Verify sum equals total
require(sum == _total, "Sum != total");

// bytes selector for transferFrom(address,address,uint256)
bytes4 transferFrom = 0x23b872dd;
// bytes selector for transfer(address,uint256)
Expand Down
7 changes: 7 additions & 0 deletions contracts/virtualPersona/AgentFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ contract AgentFactoryV2 is
uint256 botProtectionDurationInSeconds,
address vault
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require((lpSupply + vaultSupply) <= maxSupply, "Invalid supply");
_tokenSupplyParams = abi.encode(
maxSupply,
lpSupply,
Expand All @@ -452,6 +453,12 @@ contract AgentFactoryV2 is
uint256 taxSwapThresholdBasisPoints,
address projectTaxRecipient
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require(
projectBuyTaxBasisPoints <= 10000 &&
projectSellTaxBasisPoints <= 10000 &&
taxSwapThresholdBasisPoints <= 10000,
"Invalid tax params"
);
_tokenTaxParams = abi.encode(
projectBuyTaxBasisPoints,
projectSellTaxBasisPoints,
Expand Down
7 changes: 7 additions & 0 deletions contracts/virtualPersona/AgentFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ contract AgentFactoryV3 is
uint256 botProtectionDurationInSeconds,
address vault
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require((lpSupply + vaultSupply) <= maxSupply, "Invalid supply");
_tokenSupplyParams = abi.encode(
maxSupply,
lpSupply,
Expand All @@ -468,6 +469,12 @@ contract AgentFactoryV3 is
uint256 taxSwapThresholdBasisPoints,
address projectTaxRecipient
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require(
projectBuyTaxBasisPoints <= 10000 &&
projectSellTaxBasisPoints <= 10000 &&
taxSwapThresholdBasisPoints <= 10000,
"Invalid tax params"
);
_tokenTaxParams = abi.encode(
projectBuyTaxBasisPoints,
projectSellTaxBasisPoints,
Expand Down
10 changes: 9 additions & 1 deletion contracts/virtualPersona/AgentFactoryV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ contract AgentFactoryV4 is
uint256 botProtectionDurationInSeconds,
address vault
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require((lpSupply + vaultSupply) <= maxSupply, "Invalid supply");
_tokenSupplyParams = abi.encode(
maxSupply,
lpSupply,
Expand All @@ -495,6 +496,12 @@ contract AgentFactoryV4 is
uint256 taxSwapThresholdBasisPoints,
address projectTaxRecipient
) public onlyRole(DEFAULT_ADMIN_ROLE) {
require(
projectBuyTaxBasisPoints <= 10000 &&
projectSellTaxBasisPoints <= 10000 &&
taxSwapThresholdBasisPoints <= 10000,
"Invalid tax params"
);
_tokenTaxParams = abi.encode(
projectBuyTaxBasisPoints,
projectSellTaxBasisPoints,
Expand Down Expand Up @@ -556,6 +563,8 @@ contract AgentFactoryV4 is

require(isCompatibleToken(tokenAddr), "Unsupported token");

require(tokenAddr != assetToken, "Asset token cannot be used");

require(
IERC20(assetToken).balanceOf(sender) >= applicationThreshold,
"Insufficient asset token"
Expand Down Expand Up @@ -657,7 +666,6 @@ contract AgentFactoryV4 is
function _createPair(
address tokenAddr
) internal returns (address uniswapV2Pair_) {

IUniswapV2Factory factory = IUniswapV2Factory(
IUniswapV2Router02(_uniswapRouter).factory()
);
Expand Down
9 changes: 8 additions & 1 deletion contracts/virtualPersona/AgentMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ contract AgentMigrator is Ownable, Pausable {
uint256 botProtectionDurationInSeconds,
address vault
) public onlyOwner {
require((lpSupply + vaultSupply) <= maxSupply, "Invalid supply");
_tokenSupplyParams = abi.encode(
maxSupply,
lpSupply,
Expand All @@ -89,6 +90,12 @@ contract AgentMigrator is Ownable, Pausable {
uint256 taxSwapThresholdBasisPoints,
address projectTaxRecipient
) public onlyOwner {
require(
projectBuyTaxBasisPoints <= 10000 &&
projectSellTaxBasisPoints <= 10000 &&
taxSwapThresholdBasisPoints <= 10000,
"Invalid tax params"
);
_tokenTaxParams = abi.encode(
projectBuyTaxBasisPoints,
projectSellTaxBasisPoints,
Expand All @@ -112,7 +119,7 @@ contract AgentMigrator is Ownable, Pausable {
string memory name,
string memory symbol,
bool canStake
) external noReentrant {
) external noReentrant whenNotPaused {
require(!migratedAgents[id], "Agent already migrated");

IAgentNft.VirtualInfo memory virtualInfo = _nft.virtualInfo(id);
Expand Down
31 changes: 19 additions & 12 deletions contracts/virtualPersona/AgentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../pool/IUniswapV2Router02.sol";
import "../pool/IUniswapV2Factory.sol";
import "../pool/IUniswapV2Pair.sol";
import "./IAgentToken.sol";
import "./IAgentFactory.sol";

Expand Down Expand Up @@ -276,17 +277,19 @@ contract AgentToken is
_approve(address(this), address(_uniswapRouter), type(uint256).max);
IERC20(pairToken).approve(address(_uniswapRouter), type(uint256).max);
// Add the liquidity:
(uint256 amountA, uint256 amountB, uint256 lpTokens) = _uniswapRouter
.addLiquidity(
address(this),
pairToken,
balanceOf(address(this)),
IERC20(pairToken).balanceOf(address(this)),
0,
0,
address(this),
block.timestamp
);

address pairAddr = IUniswapV2Factory(_uniswapRouter.factory()).getPair(
address(this),
pairToken
);

uint256 amountA = balanceOf(address(this));
uint256 amountB = IERC20(pairToken).balanceOf(address(this));

transfer(pairAddr, amountA);
IERC20(pairToken).transfer(pairAddr, amountB);

uint256 lpTokens = IUniswapV2Pair(pairAddr).mint(address(this));

emit InitialLiquidityAdded(amountA, amountB, lpTokens);

Expand Down Expand Up @@ -473,6 +476,9 @@ contract AgentToken is
projectBuyTaxBasisPoints = newProjectBuyTaxBasisPoints_;
projectSellTaxBasisPoints = newProjectSellTaxBasisPoints_;

_tokenHasTax =
(projectBuyTaxBasisPoints + projectSellTaxBasisPoints) > 0;

emit ProjectTaxBasisPointsChanged(
oldBuyTaxBasisPoints,
newProjectBuyTaxBasisPoints_,
Expand Down Expand Up @@ -876,7 +882,8 @@ contract AgentToken is
!_autoSwapInProgress &&
!isLiquidityPool(from_) &&
from_ != address(_uniswapRouter) &&
to_ != address(_uniswapRouter));
to_ != address(_uniswapRouter) &&
from_ != address(this));
}

/**
Expand Down