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

Refactor spotlight token #14

Merged
merged 3 commits into from
Jan 23, 2025
Merged
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
2 changes: 1 addition & 1 deletion script/DeployTokenFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract Deploy is Script {
// @dev deploy spotlight token factory proxy contract
TransparentUpgradeableProxy factoryProxy =
new TransparentUpgradeableProxy(address(factoryImpl), _SPOTLIGHT_TOKEN_FACTORY_OWNER, "");
SpotlightTokenFactory(address(factoryProxy)).initialize(
SpotlightTokenFactory(payable(address(factoryProxy))).initialize(
_SPOTLIGHT_TOKEN_FACTORY_OWNER, // owner_
0.1 ether, // creationFee: 0.1 ether
address(tokenIpCollection), // tokenIpCollection_
Expand Down
22 changes: 11 additions & 11 deletions src/spotlight-protocol-rewards/ISpotlightProtocolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@ interface ISpotlightProtocolRewards {
* - The caller provides ETH value to deposit as rewards.
* - Emits a Deposit event.
*
* @param ipaId The IPA identifier address to deposit rewards for.
* @param ipAccount The IPAccount address to deposit rewards for.
*/
function deposit(address ipaId) external payable;
function deposit(address ipAccount) external payable;

/**
* @dev Withdraws rewards for a specific IPA.
* - Only the IPA owner can withdraw.
* - Only the IPAccount owner can withdraw.
* - Requires withdraw functionality to be enabled.
* - Emits a Withdraw event.
*
* @param ipaId The IPA identifier address to withdraw rewards from.
* @param ipAccount The IPAccount address to withdraw rewards from.
*/
function withdraw(address ipaId) external;
function withdraw(address ipAccount) external;

/**
* @dev Withdraws rewards for multiple IPAs at once.
* - Only IPA owners can withdraw their respective rewards.
* - Only IPAccount owners can withdraw their respective rewards.
* - Requires withdraw functionality to be enabled.
* - Emits a Withdraw event with total amount.
*
* @param ipaIds Array of IPA identifier addresses to withdraw rewards from.
* @param ipAccounts Array of IPAccount addresses to withdraw rewards from.
*/
function withdrawAll(address[] calldata ipaIds) external;
function withdrawAll(address[] calldata ipAccounts) external;

/**
* @dev Returns the pending rewards for an IPA.
* @dev Returns the pending rewards for an IPAccount.
*
* @param ipaId The IPA identifier address to check rewards for.
* @param ipAccount The IPAccount address to check rewards for.
* @return The amount of pending rewards.
*/
function rewardsOf(address ipaId) external view returns (uint256);
function rewardsOf(address ipAccount) external view returns (uint256);

/**
* @dev Returns the total rewards held in the contract.
Expand Down
56 changes: 30 additions & 26 deletions src/spotlight-protocol-rewards/SpotlightProtocolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {
error TransferFailed();
error TokenCallFailed();
error WithdrawDisabled();
error IpaIdsEmpty();
error IPAccountsEmpty();

modifier onlyWithdrawEnabled() {
if (!_withdrawEnabled) revert WithdrawDisabled();
Expand All @@ -41,14 +41,14 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {
/*
* @dev Deposit protocol rewards
*
* @param ipaId The IpaId to deposit rewards for
* @param ipAccount The IPAccount to deposit rewards for
*/
function deposit(address ipaId) external payable {
if (ipaId == address(0)) revert AddressZero();
function deposit(address ipAccount) external payable {
if (ipAccount == address(0)) revert AddressZero();
uint256 amount = msg.value;
if (amount == 0) revert AmountZero();

(, address tokenContract, uint256 tokenId) = _getToken(ipaId);
(, address tokenContract, uint256 tokenId) = _getToken(ipAccount);
_rewards[tokenContract][tokenId] += amount;

emit Deposit(tokenContract, tokenId, amount);
Expand All @@ -57,12 +57,12 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {
/*
* @dev Withdraw protocol rewards
*
* @param ipaId The IpaId to withdraw rewards from
* @param ipAccount The IPAccount to withdraw rewards from
*/
function withdraw(address ipaId) external onlyWithdrawEnabled {
if (ipaId == address(0)) revert AddressZero();
function withdraw(address ipAccount) external onlyWithdrawEnabled {
if (ipAccount == address(0)) revert AddressZero();

(, address tokenContract, uint256 tokenId) = _getToken(ipaId);
(, address tokenContract, uint256 tokenId) = _getToken(ipAccount);
if (!_checkIsOwner(tokenContract, tokenId)) revert InvalidWithdraw();

uint256 ownerRewards = this.rewardsOf(tokenContract, tokenId);
Expand All @@ -79,19 +79,19 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {
/*
* @dev Withdraw protocol rewards
*
* @param ipaIds Array of IpaIds to withdraw rewards from
* @param ipAccounts Array of IPAccounts to withdraw rewards from
*/
function withdrawAll(address[] calldata ipaIds) external onlyWithdrawEnabled {
if (ipaIds.length == 0) revert IpaIdsEmpty();
function withdrawAll(address[] calldata ipAccounts) external onlyWithdrawEnabled {
if (ipAccounts.length == 0) revert IPAccountsEmpty();

uint256 totalAmount;
WithdrawInfo[] memory withdrawals = new WithdrawInfo[](ipaIds.length);
WithdrawInfo[] memory withdrawals = new WithdrawInfo[](ipAccounts.length);

for (uint256 i = 0; i < ipaIds.length; i++) {
address ipaId = ipaIds[i];
if (ipaId == address(0)) revert AddressZero();
for (uint256 i = 0; i < ipAccounts.length; i++) {
address ipAccount = ipAccounts[i];
if (ipAccount == address(0)) revert AddressZero();

(, address tokenContract, uint256 tokenId) = _getToken(ipaId);
(, address tokenContract, uint256 tokenId) = _getToken(ipAccount);
if (!_checkIsOwner(tokenContract, tokenId)) {
revert InvalidWithdraw();
}
Expand Down Expand Up @@ -130,16 +130,16 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {
}

/*
* @dev Get the specific rewards for an IpaId
* @dev Get the specific rewards for an IPAccount
*
* @param ipaId The address to check the rewards for
* @param ipAccount The address to check the rewards for
*
* @return uint256 The specific rewards for the IpaId
* @return uint256 The specific rewards for the IPAccount
*/
function rewardsOf(address ipaId) external view returns (uint256) {
if (ipaId == address(0)) revert AddressZero();
function rewardsOf(address ipAccount) external view returns (uint256) {
if (ipAccount == address(0)) revert AddressZero();

(, address tokenContract, uint256 tokenId) = _getToken(ipaId);
(, address tokenContract, uint256 tokenId) = _getToken(ipAccount);
return this.rewardsOf(tokenContract, tokenId);
}

Expand All @@ -159,14 +159,18 @@ contract SpotlightProtocolRewards is ISpotlightProtocolRewards, Ownable {

/*
* @dev Internal function to get token info using low level call
* @param ipaId The address of the contract to call
* @param ipAccount The address of the contract to call
*
* @return chainId The EIP-155 ID of the chain the token exists on
* @return tokenContract The contract address of the token
* @return tokenId The ID of the token
*/
function _getToken(address ipaId) internal view returns (uint256 chainId, address tokenContract, uint256 tokenId) {
(chainId, tokenContract, tokenId) = IMinimalIPAccount(ipaId).token();
function _getToken(address ipAccount)
internal
view
returns (uint256 chainId, address tokenContract, uint256 tokenId)
{
(chainId, tokenContract, tokenId) = IMinimalIPAccount(ipAccount).token();
if (tokenContract == address(0)) revert AddressZero();
}

Expand Down
18 changes: 9 additions & 9 deletions src/spotlight-token-factory/SpotlightTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ contract SpotlightTokenFactory is SpotlightTokenFactoryStorage, ISpotlightTokenF
require(success, "SpotlightTokenFactory: Failed to claim fee");
}

receive() external payable {}

// @dev - private functions
function _checkIsInitialized() internal view {
if (!isInitialized()) {
Expand All @@ -237,23 +239,21 @@ contract SpotlightTokenFactory is SpotlightTokenFactoryStorage, ISpotlightTokenF
return keccak256(abi.encodePacked(account, numberOfTokensCreated(account)));
}

function _deploySpotlightToken(TokenCreationData memory tokenCreationData, address creator, address specificAddress)
function _deploySpotlightToken(TokenCreationData memory tokenCreationData, address creator, address ipAccount)
internal
returns (address)
{
address tokenAddress = Clones.cloneDeterministic(_tokenImplementation, _salt(creator));
ISpotlightToken(tokenAddress).initialize(
owner(),
creator,
_bondingCurve,
_baseToken,
owner(),
tokenCreationData.tokenName,
tokenCreationData.tokenSymbol,
creator,
_bondingCurve,
address(this),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info: transfer protocol trading fee to token factory

ipAccount,
_protocolRewards,
_piperXRouter,
_piperXFactory,
specificAddress,
_protocolRewards
_piperXFactory
);
if (tokenAddress != tokenCreationData.predeployedTokenAddress) {
revert("The address of the created token does not match the predeployed address");
Expand Down
43 changes: 22 additions & 21 deletions src/spotlight-token/ISpotlightToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,26 @@ interface ISpotlightToken {
/**
* @dev Initializes the token.
*
* @param owner_ The address of the token owner.
* @param tokenName_ The name of the token.
* @param tokenSymbol_ The symbol of the token.
* @param tokenCreator_ The address of the token creator.
* @param bondingCurve_ The address of the bonding curve.
* @param baseToken_ The address of the base token.
* @param protocolFeeRecipient_ The address of the protocol fee recipient.
* @param tokenName_ The name of the token.
* @param tokenSymbol_ The symbol of the token.
* @param ipAccount_ The address of the ipAccount.
* @param _rewardsVault The address of the reward vault.
* @param piperXRouter_ The address of the piperX router.
* @param piperXFactory_ The address of the piperX factory.
* @param specificAddress_ The address of the specific address.
* @param protocolRewards_ The address of the protocol rewards.
*/
function initialize(
address owner_,
string memory tokenName_,
string memory tokenSymbol_,
address tokenCreator_,
address bondingCurve_,
address baseToken_,
address protocolFeeRecipient_,
string memory tokenName_,
string memory tokenSymbol_,
address ipAccount_,
address _rewardsVault,
address piperXRouter_,
address piperXFactory_,
address specificAddress_,
address protocolRewards_
address piperXFactory_
) external;

/**
Expand All @@ -111,29 +107,34 @@ interface ISpotlightToken {
function isInitialized() external view returns (bool);

/**
* @dev Returns the address of the token owner.
* @dev Returns the address of the token creator.
*/
function owner() external view returns (address);
function tokenCreator() external view returns (address);

/**
* @dev Returns the address of the token creator.
* @dev Returns the address of the bonding curve.
*/
function tokenCreator() external view returns (address);
function bondingCurve() external view returns (address);

/**
* @dev Returns the address of the protocol fee recipient.
*/
function protocolFeeRecipient() external view returns (address);

/**
* @dev Sets the address of the protocol fee recipient.
* @dev Returns the address of the rewards vault.
*/
function setProtocolFeeRecipient(address newRecipient) external;
function rewardsVault() external view returns (address);

/**
* @dev Returns the address of the bonding curve.
* @dev Returns the address of the piperX router.
*/
function bondingCurve() external view returns (address);
function piperXRouter() external view returns (address);

/**
* @dev Returns the address of the piperX factory.
*/
function piperXFactory() external view returns (address);

/**
* @dev Returns the current market state.
Expand Down
19 changes: 0 additions & 19 deletions src/spotlight-token/InitializableERC20.sol

This file was deleted.

41 changes: 0 additions & 41 deletions src/spotlight-token/ReentrancyGuard.sol

This file was deleted.

Loading
Loading