Skip to content

Commit

Permalink
rename feeRoyalty to listingFee
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 18, 2024
1 parent d9d9060 commit c70fcc5
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 108 deletions.
2 changes: 1 addition & 1 deletion docs/src/src/Swan.sol/constants.Swan.md
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
14 changes: 7 additions & 7 deletions docs/src/src/Swan.sol/contract.Swan.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
```
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.*

Expand All @@ -333,7 +333,7 @@ Holds the listing information.
```solidity
struct ArtifactListing {
uint256 createdAt;
uint96 feeRoyalty;
uint96 listingFee;
uint256 price;
address seller;
address agent;
Expand Down
30 changes: 16 additions & 14 deletions docs/src/src/SwanAgent.sol/contract.SwanAgent.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
```


Expand Down Expand Up @@ -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.*

Expand All @@ -164,7 +166,7 @@ Creates an agent.
constructor(
string memory _name,
string memory _description,
uint96 _feeRoyalty,
uint96 _listingFee,
uint256 _amountPerRound,
address _operator,
address _owner
Expand Down Expand Up @@ -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.*

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -391,23 +393,23 @@ function getRoundPhase() public view returns (uint256, Phase, uint256);
|`<none>`|`uint256`||


### setFeeRoyalty
### setListingFee

Function to set feeRoyalty.
Function to set listingFee.

*Only callable by the owner.*

*Only callable in withdraw phase.*


```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
Expand Down
4 changes: 2 additions & 2 deletions docs/src/src/SwanAgent.sol/contract.SwanAgentFactory.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/SwanArtifact.sol/contract.SwanArtifact.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
6 changes: 3 additions & 3 deletions docs/src/src/SwanManager.sol/abstract.SwanManager.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.


Expand Down Expand Up @@ -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.*

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
24 changes: 24 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 11 additions & 11 deletions src/Swan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ 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.
/// @dev `round` is the round in which the artifact is created.
/// @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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down
Loading

0 comments on commit c70fcc5

Please sign in to comment.