From c70fcc504b329f29aec25efb9ee83e1a5b26fbfc Mon Sep 17 00:00:00 2001 From: erhant Date: Wed, 18 Dec 2024 23:55:31 +0300 Subject: [PATCH] rename `feeRoyalty` to `listingFee` --- docs/src/src/Swan.sol/constants.Swan.md | 2 +- docs/src/src/Swan.sol/contract.Swan.md | 14 +++---- .../src/SwanAgent.sol/contract.SwanAgent.md | 30 +++++++------- .../contract.SwanAgentFactory.md | 4 +- .../SwanArtifact.sol/contract.SwanArtifact.md | 2 +- .../contract.SwanArtifactFactory.md | 2 +- .../SwanManager.sol/abstract.SwanManager.md | 6 +-- .../struct.SwanMarketParameters.md | 2 +- script/Deploy.s.sol | 24 +++++++++++ src/Swan.sol | 22 +++++----- src/SwanAgent.sol | 41 ++++++++++--------- src/SwanManager.sol | 4 +- test/Helper.t.sol | 22 +++++----- test/InvariantTest.t.sol | 9 ++-- test/SwanAgentTest.t.sol | 35 ++++++++-------- test/SwanFuzzTest.t.sol | 10 ++--- test/SwanTest.t.sol | 14 +++---- 17 files changed, 135 insertions(+), 108 deletions(-) diff --git a/docs/src/src/Swan.sol/constants.Swan.md b/docs/src/src/Swan.sol/constants.Swan.md index 2c07fa3..b3e7976 100644 --- a/docs/src/src/Swan.sol/constants.Swan.md +++ b/docs/src/src/Swan.sol/constants.Swan.md @@ -1,5 +1,5 @@ # Constants -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/Swan.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/Swan.sol) ### SwanAgentPurchaseOracleProtocol *Protocol string for Swan Purchase CRONs, checked in the Oracle.* diff --git a/docs/src/src/Swan.sol/contract.Swan.md b/docs/src/src/Swan.sol/contract.Swan.md index a8f7fba..4ebec31 100644 --- a/docs/src/src/Swan.sol/contract.Swan.md +++ b/docs/src/src/Swan.sol/contract.Swan.md @@ -1,5 +1,5 @@ # Swan -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/Swan.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/Swan.sol) **Inherits:** [SwanManager](/src/SwanManager.sol/abstract.SwanManager.md), UUPSUpgradeable @@ -115,7 +115,7 @@ Creates a new agent. ```solidity -function createAgent(string calldata _name, string calldata _description, uint96 _feeRoyalty, uint256 _amountPerRound) +function createAgent(string calldata _name, string calldata _description, uint96 _listingFee, uint256 _amountPerRound) external returns (SwanAgent); ``` @@ -163,13 +163,13 @@ function relist(address _artifact, address _agent, uint256 _price) external; |`_price`|`uint256`|new price of the token.| -### transferRoyalties +### transferListingFees -Function to transfer the royalties to the seller & Dria. +Function to transfer the fees to the seller & Dria. ```solidity -function transferRoyalties(ArtifactListing storage _artifact) internal; +function transferListingFees(ArtifactListing storage _artifact) internal; ``` ### purchase @@ -317,7 +317,7 @@ Holds the listing information. *`createdAt` is the timestamp of the artifact creation.* -*`feeRoyalty` is the royalty fee of the agent.* +*`listingFee` is the listing fee of the agent.* *`price` is the price of the artifact.* @@ -333,7 +333,7 @@ Holds the listing information. ```solidity struct ArtifactListing { uint256 createdAt; - uint96 feeRoyalty; + uint96 listingFee; uint256 price; address seller; address agent; diff --git a/docs/src/src/SwanAgent.sol/contract.SwanAgent.md b/docs/src/src/SwanAgent.sol/contract.SwanAgent.md index 344ad85..fa567c3 100644 --- a/docs/src/src/SwanAgent.sol/contract.SwanAgent.md +++ b/docs/src/src/SwanAgent.sol/contract.SwanAgent.md @@ -1,5 +1,5 @@ # SwanAgent -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanAgent.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanAgent.sol) **Inherits:** Ownable @@ -66,12 +66,14 @@ bytes public state; ``` -### feeRoyalty -Royalty fees for the agent. +### listingFee +Listing fee percentage for the agent. + +*For each listing of X$, the agent will get X * (listingFee / 100).* ```solidity -uint96 public feeRoyalty; +uint96 public listingFee; ``` @@ -155,7 +157,7 @@ modifier onlyAuthorized(); Creates an agent. -*`_feeRoyalty` should be between 1 and max agent fee in the swan market parameters.* +*`_listingFee` should be between 1 and max agent fee in the swan market parameters.* *All tokens are approved to the oracle coordinator of operator.* @@ -164,7 +166,7 @@ Creates an agent. constructor( string memory _name, string memory _description, - uint96 _feeRoyalty, + uint96 _listingFee, uint256 _amountPerRound, address _operator, address _owner @@ -243,7 +245,7 @@ function oraclePurchaseRequest(bytes calldata _input, bytes calldata _models) ex ### updateState -Function to update the AI agent state. +Function to update the agent state. *Works only in `Withdraw` phase.* @@ -290,7 +292,7 @@ function withdraw(uint96 _amount) public onlyAuthorized; ### treasury -Alias to get the token balance of AI agent. +Alias to get the token balance of agent. ```solidity @@ -374,9 +376,9 @@ Function to return the current round, elapsed round and the current phase accord *Each round is composed of three phases in order: Listing, Buy, Withdraw.* -*Internally, it computes the intervals from market parameters at the creation of this AI agent, until now.* +*Internally, it computes the intervals from market parameters at the creation of this agent, until now.* -*If there are many parameter changes throughout the life of this AI agent, this may cost more GAS.* +*If there are many parameter changes throughout the life of this agent, this may cost more GAS.* ```solidity @@ -391,9 +393,9 @@ function getRoundPhase() public view returns (uint256, Phase, uint256); |``|`uint256`|| -### setFeeRoyalty +### setListingFee -Function to set feeRoyalty. +Function to set listingFee. *Only callable by the owner.* @@ -401,13 +403,13 @@ Function to set feeRoyalty. ```solidity -function setFeeRoyalty(uint96 newFeeRoyalty) public onlyOwner; +function setListingFee(uint96 newListingFee) public onlyOwner; ``` **Parameters** |Name|Type|Description| |----|----|-----------| -|`newFeeRoyalty`|`uint96`|must be between 1 and 100.| +|`newListingFee`|`uint96`|must be between 1 and 100.| ### setAmountPerRound diff --git a/docs/src/src/SwanAgent.sol/contract.SwanAgentFactory.md b/docs/src/src/SwanAgent.sol/contract.SwanAgentFactory.md index 7b614c6..851edb9 100644 --- a/docs/src/src/SwanAgent.sol/contract.SwanAgentFactory.md +++ b/docs/src/src/SwanAgent.sol/contract.SwanAgentFactory.md @@ -1,5 +1,5 @@ # SwanAgentFactory -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanAgent.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanAgent.sol) Factory contract to deploy Agent contracts. @@ -14,7 +14,7 @@ Factory contract to deploy Agent contracts. function deploy( string memory _name, string memory _description, - uint96 _feeRoyalty, + uint96 _listingFee, uint256 _amountPerRound, address _owner ) external returns (SwanAgent); diff --git a/docs/src/src/SwanArtifact.sol/contract.SwanArtifact.md b/docs/src/src/SwanArtifact.sol/contract.SwanArtifact.md index 881dbfc..b5ac97d 100644 --- a/docs/src/src/SwanArtifact.sol/contract.SwanArtifact.md +++ b/docs/src/src/SwanArtifact.sol/contract.SwanArtifact.md @@ -1,5 +1,5 @@ # SwanArtifact -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanArtifact.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanArtifact.sol) **Inherits:** ERC721, Ownable diff --git a/docs/src/src/SwanArtifact.sol/contract.SwanArtifactFactory.md b/docs/src/src/SwanArtifact.sol/contract.SwanArtifactFactory.md index 21c8c98..f7cd4ff 100644 --- a/docs/src/src/SwanArtifact.sol/contract.SwanArtifactFactory.md +++ b/docs/src/src/SwanArtifact.sol/contract.SwanArtifactFactory.md @@ -1,5 +1,5 @@ # SwanArtifactFactory -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanArtifact.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanArtifact.sol) Factory contract to deploy Artifact tokens. diff --git a/docs/src/src/SwanManager.sol/abstract.SwanManager.md b/docs/src/src/SwanManager.sol/abstract.SwanManager.md index 3e67e6d..79f5fd5 100644 --- a/docs/src/src/SwanManager.sol/abstract.SwanManager.md +++ b/docs/src/src/SwanManager.sol/abstract.SwanManager.md @@ -1,5 +1,5 @@ # SwanManager -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanManager.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanManager.sol) **Inherits:** OwnableUpgradeable @@ -43,7 +43,7 @@ ERC20 public token; ### isOperator -Operator addresses that can take actions on behalf of AI agents, +Operator addresses that can take actions on behalf of agents, such as calling `purchase`, or `updateState` for them. @@ -132,7 +132,7 @@ function getOracleFee() external view returns (uint256); ### addOperator -Adds an operator that can take actions on behalf of AI agents. +Adds an operator that can take actions on behalf of agents. *Only callable by owner.* diff --git a/docs/src/src/SwanManager.sol/struct.SwanMarketParameters.md b/docs/src/src/SwanManager.sol/struct.SwanMarketParameters.md index b5f3273..49b4911 100644 --- a/docs/src/src/SwanManager.sol/struct.SwanMarketParameters.md +++ b/docs/src/src/SwanManager.sol/struct.SwanMarketParameters.md @@ -1,5 +1,5 @@ # SwanMarketParameters -[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/24e0365940f0434545a9c39573dfdf6b9975fc88/src/SwanManager.sol) +[Git Source](https://github.com/firstbatchxyz/swan-contracts/blob/d9d9060075900e963ed93f2465a5d30c142fcc35/src/SwanManager.sol) Collection of market-related parameters. diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 90ff36b..0451e98 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -7,10 +7,34 @@ import {Script} from "forge-std/Script.sol"; import {Vm} from "forge-std/Vm.sol"; import {HelperConfig} from "./HelperConfig.s.sol"; +import {LLMOracleRegistry} from "@firstbatch/dria-oracle-contracts/LLMOracleRegistry.sol"; +import { + LLMOracleCoordinator, LLMOracleTaskParameters +} from "@firstbatch/dria-oracle-contracts/LLMOracleCoordinator.sol"; import {SwanAgentFactory} from "../src/SwanAgent.sol"; import {SwanArtifactFactory} from "../src/SwanArtifact.sol"; import {Swan, SwanMarketParameters} from "../src/Swan.sol"; +// needed for tests +contract DeployLLMOracleRegistry is Script { + HelperConfig public config; + + function run() external returns (address proxy, address impl) { + config = new HelperConfig(); + (proxy, impl) = config.deployLLMOracleRegistry(); + } +} + +// needed for tests +contract DeployLLMOracleCoordinator is Script { + HelperConfig public config; + + function run() external returns (address proxy, address impl) { + config = new HelperConfig(); + (proxy, impl) = config.deployLLMOracleCoordinator(); + } +} + contract DeploySwanAgentFactory is Script { HelperConfig public config; diff --git a/src/Swan.sol b/src/Swan.sol index cb3f8a2..16e61a9 100644 --- a/src/Swan.sol +++ b/src/Swan.sol @@ -81,7 +81,7 @@ contract Swan is SwanManager, UUPSUpgradeable { /// @notice Holds the listing information. /// @dev `createdAt` is the timestamp of the artifact creation. - /// @dev `feeRoyalty` is the royalty fee of the agent. + /// @dev `listingFee` is the listing fee of the agent. /// @dev `price` is the price of the artifact. /// @dev `seller` is the address of the creator of the artifact. /// @dev `agent` is the address of the agent. @@ -89,7 +89,7 @@ contract Swan is SwanManager, UUPSUpgradeable { /// @dev `status` is the status of the artifact. struct ArtifactListing { uint256 createdAt; - uint96 feeRoyalty; + uint96 listingFee; uint256 price; address seller; // TODO: we can use artifact.owner() instead of seller address agent; @@ -186,10 +186,10 @@ contract Swan is SwanManager, UUPSUpgradeable { function createAgent( string calldata _name, string calldata _description, - uint96 _feeRoyalty, + uint96 _listingFee, uint256 _amountPerRound ) external returns (SwanAgent) { - SwanAgent agent = agentFactory.deploy(_name, _description, _feeRoyalty, _amountPerRound, msg.sender); + SwanAgent agent = agentFactory.deploy(_name, _description, _listingFee, _amountPerRound, msg.sender); emit AgentCreated(msg.sender, address(agent)); return agent; @@ -224,7 +224,7 @@ contract Swan is SwanManager, UUPSUpgradeable { address artifact = address(artifactFactory.deploy(_name, _symbol, _desc, msg.sender)); listings[artifact] = ArtifactListing({ createdAt: block.timestamp, - feeRoyalty: agent.feeRoyalty(), + listingFee: agent.listingFee(), price: _price, seller: msg.sender, status: ArtifactStatus.Listed, @@ -236,7 +236,7 @@ contract Swan is SwanManager, UUPSUpgradeable { artifactsPerAgentRound[_agent][round].push(artifact); // transfer royalties - transferRoyalties(listings[artifact]); + transferListingFees(listings[artifact]); emit ArtifactListed(msg.sender, artifact, _price); } @@ -293,7 +293,7 @@ contract Swan is SwanManager, UUPSUpgradeable { // create listing listings[_artifact] = ArtifactListing({ createdAt: block.timestamp, - feeRoyalty: agent.feeRoyalty(), + listingFee: agent.listingFee(), price: _price, seller: msg.sender, status: ArtifactStatus.Listed, @@ -305,15 +305,15 @@ contract Swan is SwanManager, UUPSUpgradeable { artifactsPerAgentRound[_agent][round].push(_artifact); // transfer royalties - transferRoyalties(listings[_artifact]); + transferListingFees(listings[_artifact]); emit ArtifactRelisted(msg.sender, _agent, _artifact, _price); } - /// @notice Function to transfer the royalties to the seller & Dria. - function transferRoyalties(ArtifactListing storage _artifact) internal { + /// @notice Function to transfer the fees to the seller & Dria. + function transferListingFees(ArtifactListing storage _artifact) internal { // calculate fees - uint256 totalFee = Math.mulDiv(_artifact.price, (_artifact.feeRoyalty * 100), BASIS_POINTS); + uint256 totalFee = Math.mulDiv(_artifact.price, (_artifact.listingFee * 100), BASIS_POINTS); uint256 driaFee = Math.mulDiv(totalFee, (getCurrentMarketParameters().platformFee * 100), BASIS_POINTS); uint256 agentFee = totalFee - driaFee; diff --git a/src/SwanAgent.sol b/src/SwanAgent.sol index f08222d..8ba2027 100644 --- a/src/SwanAgent.sol +++ b/src/SwanAgent.sol @@ -12,11 +12,11 @@ contract SwanAgentFactory { function deploy( string memory _name, string memory _description, - uint96 _feeRoyalty, + uint96 _listingFee, uint256 _amountPerRound, address _owner ) external returns (SwanAgent) { - return new SwanAgent(_name, _description, _feeRoyalty, _amountPerRound, msg.sender, _owner); + return new SwanAgent(_name, _description, _listingFee, _amountPerRound, msg.sender, _owner); } } @@ -90,8 +90,9 @@ contract SwanAgent is Ownable { /// @notice State of the agent. /// @dev Only updated by the oracle via `updateState`. bytes public state; - /// @notice Royalty fees for the agent. - uint96 public feeRoyalty; + /// @notice Listing fee percentage for the agent. + /// @dev For each listing of X$, the agent will get X * (listingFee / 100). + uint96 public listingFee; /// @notice The max amount of money the agent can spend per round. uint256 public amountPerRound; @@ -131,23 +132,23 @@ contract SwanAgent is Ownable { //////////////////////////////////////////////////////////////*/ /// @notice Creates an agent. - /// @dev `_feeRoyalty` should be between 1 and max agent fee in the swan market parameters. + /// @dev `_listingFee` should be between 1 and max agent fee in the swan market parameters. /// @dev All tokens are approved to the oracle coordinator of operator. constructor( string memory _name, string memory _description, - uint96 _feeRoyalty, + uint96 _listingFee, uint256 _amountPerRound, address _operator, address _owner ) Ownable(_owner) { swan = Swan(_operator); - if (_feeRoyalty < 1 || _feeRoyalty > swan.getCurrentMarketParameters().maxAgentFee) { - revert InvalidFee(_feeRoyalty); + if (_listingFee < 1 || _listingFee > swan.getCurrentMarketParameters().maxAgentFee) { + revert InvalidFee(_listingFee); } - feeRoyalty = _feeRoyalty; + listingFee = _listingFee; amountPerRound = _amountPerRound; name = _name; description = _description; @@ -215,7 +216,7 @@ contract SwanAgent is Ownable { emit PurchaseRequest(oraclePurchaseRequests[round], round); } - /// @notice Function to update the AI agent state. + /// @notice Function to update the agent state. /// @dev Works only in `Withdraw` phase. /// @dev Can be called multiple times within a single round, although is not expected to be done so. function updateState() external onlyAuthorized { @@ -297,11 +298,11 @@ contract SwanAgent is Ownable { } } - // transfer the tokens to the owner of AI agent + // transfer the tokens to the owner of agent swan.token().transfer(owner(), _amount); } - /// @notice Alias to get the token balance of AI agent. + /// @notice Alias to get the token balance of agent. /// @return token balance function treasury() public view returns (uint256) { return swan.token().balanceOf(address(this)); @@ -353,8 +354,8 @@ contract SwanAgent is Ownable { /// @notice Function to return the current round, elapsed round and the current phase according to the current time. /// @dev Each round is composed of three phases in order: Listing, Buy, Withdraw. - /// @dev Internally, it computes the intervals from market parameters at the creation of this AI agent, until now. - /// @dev If there are many parameter changes throughout the life of this AI agent, this may cost more GAS. + /// @dev Internally, it computes the intervals from market parameters at the creation of this agent, until now. + /// @dev If there are many parameter changes throughout the life of this agent, this may cost more GAS. /// @return round, phase, time until next phase function getRoundPhase() public view returns (uint256, Phase, uint256) { SwanMarketParameters[] memory marketParams = swan.getMarketParameters(); @@ -397,17 +398,17 @@ contract SwanAgent is Ownable { } } - /// @notice Function to set feeRoyalty. + /// @notice Function to set listingFee. /// @dev Only callable by the owner. /// @dev Only callable in withdraw phase. - /// @param newFeeRoyalty must be between 1 and 100. - function setFeeRoyalty(uint96 newFeeRoyalty) public onlyOwner { + /// @param newListingFee must be between 1 and 100. + function setListingFee(uint96 newListingFee) public onlyOwner { _checkRoundPhase(Phase.Withdraw); - if (newFeeRoyalty < 1 || newFeeRoyalty >= 100) { - revert InvalidFee(newFeeRoyalty); + if (newListingFee < 1 || newListingFee >= 100) { + revert InvalidFee(newListingFee); } - feeRoyalty = newFeeRoyalty; + listingFee = newListingFee; } /// @notice Function to set the amountPerRound. diff --git a/src/SwanManager.sol b/src/SwanManager.sol index 29443ae..ae809c4 100644 --- a/src/SwanManager.sol +++ b/src/SwanManager.sol @@ -46,7 +46,7 @@ abstract contract SwanManager is OwnableUpgradeable { /// @notice The token to be used for fee payments. ERC20 public token; - /// @notice Operator addresses that can take actions on behalf of AI agents, + /// @notice Operator addresses that can take actions on behalf of agents, /// such as calling `purchase`, or `updateState` for them. mapping(address operator => bool) public isOperator; @@ -101,7 +101,7 @@ abstract contract SwanManager is OwnableUpgradeable { OPERATORS //////////////////////////////////////////////////////////////*/ - /// @notice Adds an operator that can take actions on behalf of AI agents. + /// @notice Adds an operator that can take actions on behalf of agents. /// @dev Only callable by owner. /// @dev Has no effect if the operator is already authorized. /// @param _operator new operator address diff --git a/test/Helper.t.sol b/test/Helper.t.sol index 9513f8c..9e76c5f 100644 --- a/test/Helper.t.sol +++ b/test/Helper.t.sol @@ -21,7 +21,7 @@ abstract contract Helper is Test { struct AgentParameters { string name; string description; - uint96 feeRoyalty; + uint96 listingFee; uint256 amountPerRound; } @@ -63,7 +63,7 @@ abstract contract Helper is Test { uint256 artifactPrice = 0.01 ether; uint256 amountPerRound = 0.015 ether; - uint8 feeRoyalty = 2; + uint8 listingFee = 2; /// @dev Default scores for validation uint256[] scores = [1, 5, 70]; @@ -102,8 +102,8 @@ abstract contract Helper is Test { agentParameters.push( AgentParameters({ name: string.concat("SwanAgent", vm.toString(uint256(i))), - description: "description of the AI agent", - feeRoyalty: feeRoyalty, + description: "description of the agent", + listingFee: listingFee, amountPerRound: amountPerRound }) ); @@ -239,10 +239,10 @@ abstract contract Helper is Test { vm.recordLogs(); vm.startPrank(agentOwners[i]); - SwanAgent AIagent = swan.createAgent( + SwanAgent newAgent = swan.createAgent( agentParameters[i].name, agentParameters[i].description, - agentParameters[i].feeRoyalty, + agentParameters[i].listingFee, agentParameters[i].amountPerRound ); @@ -290,8 +290,8 @@ abstract contract Helper is Test { vm.label(address(agents[i]), string.concat("SwanAgent#", vm.toString(i + 1))); // transfer token to agent - token.transfer(address(AIagent), amountPerRound); - assertEq(token.balanceOf(address(AIagent)), amountPerRound); + token.transfer(address(newAgent), amountPerRound); + assertEq(token.balanceOf(address(newAgent)), amountPerRound); vm.stopPrank(); } @@ -342,9 +342,9 @@ abstract contract Helper is Test { // 3. ApprovalForAll // From transferRoyalties() - // 4. Transfer (WETH9: royalty transfer to Swan) - // 5. Transfer (WETH9: royalty transfer to AI Agent) - // 6. Transfer (WETH9: royalty transfer to dria) + // 4. Transfer (WETH9: fee transfer to Swan) + // 5. Transfer (WETH9: fee transfer to Agent) + // 6. Transfer (WETH9: fee transfer to Dria) // From Swan // 7. ArtifactListed diff --git a/test/InvariantTest.t.sol b/test/InvariantTest.t.sol index e90d062..002edd2 100644 --- a/test/InvariantTest.t.sol +++ b/test/InvariantTest.t.sol @@ -41,11 +41,12 @@ contract InvariantTest is Helper { } } - /// @dev Fee royalty of each agent is within an acceptable range - function invariant_AgentFeeRoyalty() public view { + /// @dev Listing fee of each agent is within an acceptable range + function invariant_AgentListingFee() public view { for (uint256 i = 0; i < agents.length; i++) { - uint96 _feeRoyalty = agents[i].feeRoyalty(); - assertTrue(_feeRoyalty >= 0 && _feeRoyalty <= 10000); // Assuming fee royalty is in basis points (0% to 100%) + uint96 fee = agents[i].listingFee(); + // assumes listing fee is in basis points (0% to 100%) + assertTrue(fee >= 0 && fee <= 10000); } } } diff --git a/test/SwanAgentTest.t.sol b/test/SwanAgentTest.t.sol index 859c06d..037ff9a 100644 --- a/test/SwanAgentTest.t.sol +++ b/test/SwanAgentTest.t.sol @@ -20,13 +20,13 @@ contract SwanAgentTest is Helper { assertEq(uint8(_phase), uint8(currPhase)); } - /// @dev Agent owner cannot set feeRoyalty in Listing Phase - function test_RevertWhen_SetRoyaltyInListingPhase() external createAgents { + /// @dev Agent owner cannot set listing fee during the Listing Phase + function test_RevertWhen_SetListingFeeInListingPhase() external createAgents { vm.prank(agentOwner); vm.expectRevert( abi.encodeWithSelector(SwanAgent.InvalidPhase.selector, SwanAgent.Phase.Listing, SwanAgent.Phase.Withdraw) ); - agent.setFeeRoyalty(10); + agent.setListingFee(10); } /// @notice Test that the agent is in Buy Phase @@ -82,9 +82,9 @@ contract SwanAgentTest is Helper { agent.withdraw(1 ether); } - /// @notice Test that the AI agent owner must set feeRoyalty between 1-100 - /// @dev feeRoyalty can be set ONLY in Withdraw Phase by only agent owner - function test_RevertWhen_SetFeeWithInvalidRoyalty() external createAgents { + /// @notice Test that the agent owner must set listingFee between 1-100 + /// @dev listingFee can be set ONLY in Withdraw Phase by only agent owner + function test_RevertWhen_SetInvalidListingFee() external createAgents { increaseTime( agent.createdAt() + marketParameters.listingInterval + marketParameters.buyInterval, agent, @@ -92,20 +92,19 @@ contract SwanAgentTest is Helper { 0 ); - uint96 _biggerRoyalty = 1000; - uint96 _smallerRoyalty = 0; - + uint96 tooBig = 1000; vm.startPrank(agentOwner); - vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, _biggerRoyalty)); - agent.setFeeRoyalty(_biggerRoyalty); + vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, tooBig)); + agent.setListingFee(tooBig); - vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, _smallerRoyalty)); - agent.setFeeRoyalty(_smallerRoyalty); + uint96 tooSmall = 0; + vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, tooSmall)); + agent.setListingFee(tooSmall); vm.stopPrank(); } - /// @notice Test that the AI agent owner can set feeRoyalty and amountPerRound in Withdraw Phase - function test_SetRoyaltyAndAmountPerRound() external createAgents { + /// @notice Agent owner should set listingFee and amountPerRound in Withdraw Phase + function test_SetListingFeeAndAmountPerRound() external createAgents { increaseTime( agent.createdAt() + marketParameters.listingInterval + marketParameters.buyInterval, agent, @@ -113,15 +112,15 @@ contract SwanAgentTest is Helper { 0 ); - uint96 _newFeeRoyalty = 20; + uint96 _newListingFee = 20; uint256 _newAmountPerRound = 0.25 ether; vm.startPrank(agentOwner); - agent.setFeeRoyalty(_newFeeRoyalty); + agent.setListingFee(_newListingFee); agent.setAmountPerRound(_newAmountPerRound); vm.stopPrank(); - assertEq(agent.feeRoyalty(), _newFeeRoyalty); + assertEq(agent.listingFee(), _newListingFee); assertEq(agent.amountPerRound(), _newAmountPerRound); } diff --git a/test/SwanFuzzTest.t.sol b/test/SwanFuzzTest.t.sol index 3087c60..6ac4e1c 100644 --- a/test/SwanFuzzTest.t.sol +++ b/test/SwanFuzzTest.t.sol @@ -139,7 +139,7 @@ contract SwanFuzzTest is Helper { SwanAgent _agentAfterFirstSet = swan.createAgent( agentParameters[1].name, agentParameters[1].description, - agentParameters[1].feeRoyalty, + agentParameters[1].listingFee, agentParameters[1].amountPerRound ); @@ -188,7 +188,7 @@ contract SwanFuzzTest is Helper { uint96 _agentFee, uint256 _amountPerRound ) public fund sellersApproveToSwan { - // Assume the price is within a reasonable range and agenta address is not zero address + // assume the price is within a reasonable range and agent address is not zero address _amountPerRound = bound(_amountPerRound, 0.1 ether, 1 ether); require(_amountPerRound >= 0.1 ether && _amountPerRound <= 1 ether, "Amount per round is not correctly set"); @@ -200,15 +200,15 @@ contract SwanFuzzTest is Helper { _price >= marketParameters.minArtifactPrice && _price <= _amountPerRound - 1, "Price is not correctly set" ); - // Create a AI agent + // create an agent vm.prank(agentOwners[0]); SwanAgent _agent = swan.createAgent(_agentName, _agentDesc, _agentFee, _amountPerRound); - // List the artifact + // list the artifact vm.prank(sellers[0]); swan.list(_name, _symbol, _desc, _price, address(_agent)); - // Check that the artifact is listed + // check that the artifact is listed address artifact = swan.getListedArtifacts(address(_agent), 0)[0]; Swan.ArtifactListing memory listing = swan.getListing(artifact); assertEq(listing.price, _price); diff --git a/test/SwanTest.t.sol b/test/SwanTest.t.sol index 257b62d..e600748 100644 --- a/test/SwanTest.t.sol +++ b/test/SwanTest.t.sol @@ -60,7 +60,7 @@ contract SwanTest is Helper { assertEq(agents.length, agentOwners.length); for (uint256 i = 0; i < agents.length; i++) { - assertEq(agents[i].feeRoyalty(), agentParameters[i].feeRoyalty); + assertEq(agents[i].listingFee(), agentParameters[i].listingFee); assertEq(agents[i].owner(), agentOwners[i]); assertEq(agents[i].amountPerRound(), agentParameters[i].amountPerRound); assertEq(agents[i].name(), agentParameters[i].name); @@ -325,15 +325,15 @@ contract SwanTest is Helper { assertEq(agent.amountPerRound(), _newAmountPerRound); } - /// @notice Agent Owner cannot create agent with invalid royalty - /// @dev feeRoyalty must be between 0 - 100 - function test_RevertWhen_CreateAgentWithInvalidRoyalty() external fund { - uint96 _invalidRoyalty = 150; + /// @notice Agent Owner cannot create agent with invalid listing fee + /// @dev listingFee must be between 0 - 100 + function test_RevertWhen_CreateAgentWithInvalidListingFee() external fund { + uint96 invalidFee = 150; vm.prank(agentOwners[0]); - vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, _invalidRoyalty)); + vm.expectRevert(abi.encodeWithSelector(SwanAgent.InvalidFee.selector, invalidFee)); swan.createAgent( - agentParameters[0].name, agentParameters[0].description, _invalidRoyalty, agentParameters[0].amountPerRound + agentParameters[0].name, agentParameters[0].description, invalidFee, agentParameters[0].amountPerRound ); }