Skip to content

Commit

Permalink
Merge pull request #17 from VaporFi/test-codesize-fix
Browse files Browse the repository at this point in the history
fix: codesize issue
  • Loading branch information
mejiasd3v authored Apr 11, 2024
2 parents 6fc2cfc + ee6f99f commit 68860ae
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 125 deletions.
24 changes: 18 additions & 6 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ error Token__NonStratosphereNFTHolder();
error Token__BotDetected();

contract Token is ERC20, ERC20Permit, Ownable {
address public deployer;
address public liquidityPool;
address public immutable dexAggregator;
address public immutable dexAdapter;
Expand All @@ -28,14 +29,16 @@ contract Token is ERC20, ERC20Permit, Ownable {
address _owner,
uint256 _tradingStartsAt,
address _dexAggregator,
address _dexAdapter
address _dexAdapter,
address _deployer
) ERC20(_name, _symbol) ERC20Permit(_name) Ownable(_owner) {
stratosphere = IStratosphere(_stratosphereAddress);
_mint(msg.sender, _supply);
maxHoldingAmount = _percentage(_supply, 100); // 1% of total supply
tradingStartsAt = _tradingStartsAt;
dexAggregator = _dexAggregator;
dexAdapter = _dexAdapter;
deployer = _deployer;
}

function setLiquidityPool(address _liquidityPool) external onlyOwner {
Expand All @@ -45,7 +48,7 @@ contract Token is ERC20, ERC20Permit, Ownable {
liquidityPool = _liquidityPool;
}

/// @dev Replacement for _beforeTokenTransfer() since OZ v5
/// @dev Replacement for _beforeTokenTransfer() since OZ v5
function _update(
address from,
address to,
Expand Down Expand Up @@ -75,7 +78,10 @@ contract Token is ERC20, ERC20Permit, Ownable {

if (_secondsSinceTradingStarted < 1 hours) {
_enforceAntiWhale(to, value);
if (!(_isStratosphereMemberOrAdmin(from) && _isStratosphereMemberOrAdmin(to))) {
if (
!(_isStratosphereMemberOrAdmin(from) &&
_isStratosphereMemberOrAdmin(to))
) {
revert Token__NonStratosphereNFTHolder();
}
} else if (_secondsSinceTradingStarted < 24 hours) {
Expand All @@ -92,9 +98,15 @@ contract Token is ERC20, ERC20Permit, Ownable {
}
}

function _isStratosphereMemberOrAdmin(address _address) internal view returns (bool pass) {
if (_address == dexAggregator || _address == dexAdapter || stratosphere.tokenIdOf(_address) != 0 ||
_address == liquidityPool) {
function _isStratosphereMemberOrAdmin(
address _address
) internal view returns (bool pass) {
if (
_address == dexAggregator ||
_address == dexAdapter ||
stratosphere.tokenIdOf(_address) != 0 ||
_address == liquidityPool
) {
pass = true;
}
}
Expand Down
115 changes: 67 additions & 48 deletions contracts/TokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract TokenFactory is Ownable {
event TokenLaunched(
address indexed _tokenAddress,
address indexed _creatorAddress,
uint256 indexed _tokenId
uint256 indexed _streamId
);

event StreamCreated(
Expand Down Expand Up @@ -84,24 +84,13 @@ contract TokenFactory is Ownable {
uint256 public minLiquidityETH;
uint256 public slippage;
uint40 public minLockDuration;
uint256 public tokenCounter;

struct TokenLaunch {
string name;
string symbol;
uint256 tradingStartsAt;
uint256 streamId;
address tokenAddress;
address pairAddress;
address creatorAddress;
bool isLiquidityBurned;
}

mapping(uint256 => TokenLaunch) public tokenLaunches;
mapping(address => address[]) private userToTokens;

// Sablier
ISablierV2LockupLinear private immutable sablier;
// Mapping to store the streamId for each pair and lp owner
// Liquidity Locks

mapping(address => mapping(address => uint256)) private liquidityLocks;

/**
Expand Down Expand Up @@ -287,7 +276,7 @@ contract TokenFactory is Ownable {

// Create the stream
streamId = sablier.createWithDurations(params);
liquidityLocks[msg.sender][_pair] = streamId;
liquidityLocks[msg.sender][_tokenAddress] = streamId;

emit StreamCreated(streamId, msg.sender, _pair);
}
Expand All @@ -300,33 +289,27 @@ contract TokenFactory is Ownable {

_addLiquidityVapeUsdc(); // Uses the balance of VAPE and USDC in the contract

// Step 9: Store the token launch
emit TokenLaunched(_tokenAddress, msg.sender, tokenCounter);
// Step 9: Store the token launch for FETCHING
userToTokens[msg.sender].push(_tokenAddress);

tokenLaunches[tokenCounter] = TokenLaunch(
_name,
_symbol,
_tradingStartsAt,
streamId,
_tokenAddress,
_pair,
msg.sender,
_burnLiquidity
);
tokenCounter++;
// Step 10: Emit TokenLaunched event
emit TokenLaunched(_tokenAddress, msg.sender, streamId);
}

/**
* @dev Unlocks liquidity tokens for the specified pair and recipient.
* @param _pair Address of the token pair.
* @param _tokenAddress Address of the token pair.
* @param _receiver Address of the recipient of unlocked tokens.
* @notice It is recommended to direct the user to Sablier UI for better error handling.
*/
function unlockLiquidityTokens(address _pair, address _receiver) external {
function unlockLiquidityTokens(
address _tokenAddress,
address _receiver
) external {
if (_receiver == address(0)) {
revert TokenFactory__ZeroAddress();
}
uint256 streamId = liquidityLocks[msg.sender][_pair];
uint256 streamId = liquidityLocks[msg.sender][_tokenAddress];

if (streamId == 0) {
revert TokenFactory__Unauthorized();
Expand All @@ -339,16 +322,16 @@ contract TokenFactory is Ownable {

sablier.withdrawMax({streamId: streamId, to: _receiver}); // Other reverts are handled by Sablier

emit LiquidityTokensUnlocked(_pair, _receiver);
emit LiquidityTokensUnlocked(_tokenAddress, _receiver);
}

/**
* @dev Transfers the locked liquidity to the specified recipient for the given pair.
* @param _pair Address of the token pair.
* @param _tokenAddress Address of the token pair.
* @param _to Address of the recipient.
*/
function transferLock(address _pair, address _to) external {
uint256 streamId = liquidityLocks[msg.sender][_pair];
function transferLock(address _tokenAddress, address _to) external {
uint256 streamId = liquidityLocks[msg.sender][_tokenAddress];
if (
streamId == 0 ||
_to == address(0) ||
Expand All @@ -357,12 +340,12 @@ contract TokenFactory is Ownable {
revert TokenFactory__Unauthorized();
}

liquidityLocks[_to][_pair] = streamId;
liquidityLocks[msg.sender][_pair] = 0;
liquidityLocks[_to][_tokenAddress] = streamId;
liquidityLocks[msg.sender][_tokenAddress] = 0;

sablier.transferFrom({from: msg.sender, to: _to, tokenId: streamId}); // Other reverts are handled by Sablier

emit LiquidityTransferred(_pair, _to);
emit LiquidityTransferred(_tokenAddress, _to);
}

/**
Expand Down Expand Up @@ -478,7 +461,8 @@ contract TokenFactory is Ownable {
address(this),
_tradingStartsAt,
dexAggregator,
dexAdapter
dexAdapter,
msg.sender
);
}

Expand Down Expand Up @@ -656,22 +640,57 @@ contract TokenFactory is Ownable {
}

/**
* @dev Returns the liquidity lock for the specified pair and owner.
* @param _pair Address of the token pair.
* @dev Returns the liquidity lock for the specified token and owner.
* @param _tokenAddress Address of the token.
* @param _owner Address of the owner.
* @return uint256 Stream ID for the liquidity lock.
*/

function getLiquidityLock(
address _pair,
address _tokenAddress,
address _owner
) external view returns (uint256) {
return liquidityLocks[_owner][_pair];
return liquidityLocks[_owner][_tokenAddress];
}

/**
* @dev Retrieves the token launch information for a given owner.
* @param _owner The address of the owner.
* @return An array of token addresses associated with the owner.
*/
function getTokenLaunches(
address _owner
) external view returns (address[] memory) {
return userToTokens[_owner];
}

function getTokenLaunch(
uint256 _tokenLaunchId
) external view returns (TokenLaunch memory) {
return tokenLaunches[_tokenLaunchId];
/**
* @dev Retrieves the details of a token.
* @param _token The address of the token.
* @return deployer The address of the token's deployer.
* @return tokenAddress The address of the token.
* @return liquidityPool The address of the token's liquidity pool.
* @return tradingStartsAt The timestamp when trading starts for the token.
* @return streamId The stream ID associated with the token's liquidity lock. Returns 0 if burned.
*/
function getTokenDetails(
address _token
)
public
view
returns (
address deployer,
address tokenAddress,
address liquidityPool,
uint256 tradingStartsAt,
uint256 streamId
)
{
Token token = Token(_token);
deployer = token.deployer();
tokenAddress = address(token);
liquidityPool = token.liquidityPool();
tradingStartsAt = token.tradingStartsAt();
streamId = liquidityLocks[deployer][tokenAddress];
}
}
Loading

0 comments on commit 68860ae

Please sign in to comment.