Skip to content

Commit

Permalink
Merge pull request #8 from firstbatchxyz/caglacelik/pr-fixes
Browse files Browse the repository at this point in the history
update docs + readme
  • Loading branch information
erhant authored Dec 9, 2024
2 parents 71d5f1b + ad1b60e commit 6a4c427
Show file tree
Hide file tree
Showing 22 changed files with 492 additions and 879 deletions.
15 changes: 2 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
# Deployer key (REQUIRED)
PUBLIC_KEY=

### Base URLs ###
# Mainnet
BASE_MAIN_RPC_URL=

# Testnet
BASE_TEST_RPC_URL=https://sepolia.base.org

# Blockscout API Key (RQUIRED FOR CONTRACT VERIFICATION)
# Foundry expects the API key to be defined as ETHERSCAN_API_KEY
ETHERSCAN_API_KEY=
# API KEY (REQUIRED FOR CONTRACT VERIFICATION)
ETHERSCAN_API_KEY=CHANGE_ME
88 changes: 41 additions & 47 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
BuyerAgentTest:test_InBuyPhase() (gas: 182615337)
BuyerAgentTest:test_InSellPhase() (gas: 182593663)
BuyerAgentTest:test_RevertWhen_SetAmountPerRoundInBuyPhase() (gas: 182596518)
BuyerAgentTest:test_RevertWhen_SetFeeWithInvalidRoyalty() (gas: 182603480)
BuyerAgentTest:test_RevertWhen_SetRoyaltyInSellPhase() (gas: 182595095)
BuyerAgentTest:test_RevertWhen_WithdrawByAnotherOwner() (gas: 182621624)
BuyerAgentTest:test_RevertWhen_WithdrawInBuyPhase() (gas: 182608980)
BuyerAgentTest:test_SetRoyaltyAndAmountPerRound() (gas: 182604536)
BuyerAgentTest:test_WithdrawInWithdrawPhase() (gas: 182585003)
DeployTest:test_Deploy() (gas: 101371)
LLMOracleCoordinatorTest:test_Deployment() (gas: 86478543)
LLMOracleCoordinatorTest:test_RegisterOracles() (gas: 86763309)
LLMOracleCoordinatorTest:test_ValidatorIsGenerator() (gas: 87180676)
LLMOracleCoordinatorTest:test_WithValidation() (gas: 87839545)
LLMOracleCoordinatorTest:test_WithoutValidation() (gas: 87420651)
LLMOracleRegistryTest:test_Deployment() (gas: 18798876)
LLMOracleRegistryTest:test_RegisterGeneratorOracle() (gas: 19137915)
LLMOracleRegistryTest:test_RegisterValidatorOracle() (gas: 19137984)
LLMOracleRegistryTest:test_RevertWhen_RegisterSameGeneratorTwice() (gas: 19141313)
LLMOracleRegistryTest:test_RevertWhen_RegistryHasNotApprovedByOracle() (gas: 18938187)
LLMOracleRegistryTest:test_RevertWhen_UnregisterSameGeneratorTwice() (gas: 19157453)
LLMOracleRegistryTest:test_UnregisterOracle() (gas: 19154341)
LLMOracleRegistryTest:test_WithdrawStakesAfterUnregistering() (gas: 19179317)
SwanIntervalsTest:test_ChangeCycleTime() (gas: 184999199)
SwanIntervalsTest:test_InBuyPhase() (gas: 182573254)
SwanIntervalsTest:test_InSellPhase() (gas: 182568456)
SwanIntervalsTest:test_InWithdrawPhase() (gas: 182576467)
SwanTest:test_CreateBuyerAgents() (gas: 183760248)
SwanTest:test_Deployment() (gas: 179280562)
SwanTest:test_PurchaseAnAsset() (gas: 188748932)
SwanTest:test_RelistAsset() (gas: 187998184)
SwanTest:test_RevertWhen_CreateBuyerWithInvalidRoyalty() (gas: 179349648)
SwanTest:test_RevertWhen_ListInWithdrawPhase() (gas: 183823955)
SwanTest:test_RevertWhen_ListMoreThanMaxAssetCount() (gas: 187892487)
SwanTest:test_RevertWhen_PurchaseByAnotherBuyer() (gas: 187906998)
SwanTest:test_RevertWhen_PurchaseInSellPhase() (gas: 187890335)
SwanTest:test_RevertWhen_PurchaseMoreThanAmountPerRound() (gas: 188775426)
SwanTest:test_RevertWhen_RelistAlreadyPurchasedAsset() (gas: 188743009)
SwanTest:test_RevertWhen_RelistByAnotherSeller() (gas: 187888798)
SwanTest:test_RevertWhen_RelistInBuyPhase() (gas: 187920803)
SwanTest:test_RevertWhen_RelistInTheSameRound() (gas: 187893814)
SwanTest:test_RevertWhen_RelistInWithdrawPhase() (gas: 187920820)
SwanTest:test_SetAmountPerRound() (gas: 183801616)
SwanTest:test_SetFactories() (gas: 183318192)
SwanTest:test_SetMarketParameters() (gas: 183900237)
SwanTest:test_SetOracleParameters() (gas: 183743049)
SwanTest:test_UpdateState() (gas: 189350579)
BuyerAgentTest:test_InBuyPhase() (gas: 4504258)
BuyerAgentTest:test_InSellPhase() (gas: 4472291)
BuyerAgentTest:test_RevertWhen_SetAmountPerRoundInBuyPhase() (gas: 4483755)
BuyerAgentTest:test_RevertWhen_SetFeeWithInvalidRoyalty() (gas: 4492886)
BuyerAgentTest:test_RevertWhen_SetRoyaltyInSellPhase() (gas: 4473243)
BuyerAgentTest:test_RevertWhen_WithdrawByAnotherOwner() (gas: 4504563)
BuyerAgentTest:test_RevertWhen_WithdrawInBuyPhase() (gas: 4511184)
BuyerAgentTest:test_SetRoyaltyAndAmountPerRound() (gas: 4494097)
BuyerAgentTest:test_WithdrawInWithdrawPhase() (gas: 4474465)
DeployTest:test_Deploy() (gas: 101342)
InvariantTest:invariant_AssetPriceRange() (runs: 256, calls: 128000, reverts: 114801)
InvariantTest:invariant_BuyerAgentFeeRoyalty() (runs: 256, calls: 128000, reverts: 114890)
InvariantTest:invariant_MaxAssetCount() (runs: 256, calls: 128000, reverts: 115004)
InvariantTest:invariant_OwnerIsAnOperator() (runs: 256, calls: 128000, reverts: 114875)
SwanFuzz:testFuzz_CalculateRoyalties(uint256,uint256,uint256) (runs: 256, μ: 4478247, ~: 4478369)
SwanFuzz:testFuzz_ChangeCycleTime(uint256,uint256,uint256,uint256,uint256,uint256) (runs: 256, μ: 6920247, ~: 6921025)
SwanFuzz:testFuzz_ListAsset(string,string,bytes,uint256,string,string,uint96,uint256) (runs: 256, μ: 3922593, ~: 3933255)
SwanFuzz:testFuzz_TransferOwnership(address) (runs: 256, μ: 45378, ~: 45378)
SwanIntervalsTest:test_InBuyPhase() (gas: 4484235)
SwanIntervalsTest:test_InSellPhase() (gas: 4472621)
SwanIntervalsTest:test_InWithdrawPhase() (gas: 4488191)
SwanTest:test_CreateBuyerAgents() (gas: 5663905)
SwanTest:test_PurchaseAnAsset() (gas: 11220979)
SwanTest:test_RelistAsset() (gas: 10183767)
SwanTest:test_RevertWhen_CreateBuyerWithInvalidRoyalty() (gas: 1619856)
SwanTest:test_RevertWhen_ListInWithdrawPhase() (gas: 5743065)
SwanTest:test_RevertWhen_ListMoreThanMaxAssetCount() (gas: 10051316)
SwanTest:test_RevertWhen_PurchaseByAnotherBuyer() (gas: 10073950)
SwanTest:test_RevertWhen_PurchaseInSellPhase() (gas: 10048903)
SwanTest:test_RevertWhen_PurchaseMoreThanAmountPerRound() (gas: 11265761)
SwanTest:test_RevertWhen_RelistAlreadyPurchasedAsset() (gas: 11222356)
SwanTest:test_RevertWhen_RelistByAnotherSeller() (gas: 10059833)
SwanTest:test_RevertWhen_RelistInBuyPhase() (gas: 10094987)
SwanTest:test_RevertWhen_RelistInTheSameRound() (gas: 10052006)
SwanTest:test_RevertWhen_RelistInWithdrawPhase() (gas: 10094678)
SwanTest:test_SetAmountPerRound() (gas: 5720554)
SwanTest:test_SetFactories() (gas: 5172073)
SwanTest:test_SetMarketParameters() (gas: 5843489)
SwanTest:test_SetOracleParameters() (gas: 5665639)
SwanTest:test_TransferOwnership() (gas: 55405)
SwanTest:test_UpdateState() (gas: 11985754)
73 changes: 0 additions & 73 deletions Makefile

This file was deleted.

82 changes: 45 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
Swan is a **Decentralized Protocol** where AI agents (buyers) dynamically interact with asset creators. Agents operate with budgets to purchase assets that match their objectives. Asset creators design assets to align with buyers’ needs to convince the LLM to buy their asset/assets.

## Compile

Compile the contracts with:

```sh
make build
forge build
```

> [!NOTE]
>
> Please prepare a valid `.env` according to `.env.example` before running tests.
> Openzeppelin' foundry modules expect that running `forge clean` before running Foundry script or test or include `--force` option when running `forge script` or `forge test`.
## Test

Run tests on forked base-sepolia with:
Run tests on local:

```sh
make test
forge test --force
```

Run invariant tests on local with:
or on any other evm chain:

```sh
make test-inv
forge test --rpc-url <RPC_URL>
```

## Deployment

**Step 1.**
Import your `PUBLIC_KEY` and `ETHERSCAN_API_KEY` to env file.
Import your `ETHERSCAN_API_KEY` to env file.

> [!NOTE]
>
Expand All @@ -38,13 +40,12 @@ Import your `PUBLIC_KEY` and `ETHERSCAN_API_KEY` to env file.
Create keystores for deployment. [See more for keystores](https://eips.ethereum.org/EIPS/eip-2335)

```sh
make local-key
cast wallet import <FILE_NAME_OF_YOUR_KEYSTORE> --interactive
```

or for Base Sepolia
You can see your wallets with:

```sh
make base-sepolia-key
cast wallet list
```

> [!NOTE]
Expand All @@ -53,53 +54,60 @@ make base-sepolia-key
> You HAVE to type your password on the terminal to be able to use your keys. (e.g when deploying a contract)
**Step 3.**
Enter your private key (associated with the public key you added to env file) and password on terminal. You'll see your public key on terminal.
Enter your private key (associated with your public key) and password on terminal. You'll see your public key on terminal.

> [!NOTE]
>
> If you want to deploy contracts on localhost please provide localhost public key for the command above.
> If you want to deploy contracts on localhost please provide local public key for the command above.
**Step 4.** Required only for local deployment.

Start a local node with:

```sh
make anvil
anvil
```

**Step 5.**
Deploy the contracts on localhost (forked Base Sepolia by default) using Deploy script:
Deploy the contracts with:

```sh
make deploy
forge script ./script/Deploy.s.sol:Deploy --rpc-url <RPC_URL> --account <FILE_NAME_OF_YOUR_KEYSTORE> --sender <DEPLOYER_PUBLIC_KEY> --broadcast
```

or Base Sepolia with the command below:
or for instant verification use:

```sh
make deploy base-sepolia
forge script ./script/Deploy.s.sol:Deploy --rpc-url <RPC_URL> --account <FILE_NAME_OF_YOUR_KEYSTORE> --sender <DEPLOYER_PUBLIC_KEY> --broadcast --verify --verifier <etherscan|blockscout|sourcify> --verifier-url <VERIFIER_URL>
```

> [!NOTE]
> `<VERIFIER_URL>` should be expolorer's homepage url. Forge reads your `<ETHERSCAN_API_KEY>` from .env file so you don't need to add this at the end of `<VERIFIER_URL>`.
>
> e.g.
> `https://base-sepolia.blockscout.com/api/` for `Base Sepolia Network`
>
You can see deployed contract addresses under the `deployment/<chainid>.json`

## Verify Contract

Verify contract manually with:

```sh
make verify base-sepolia <contractAddress> <contractName>
forge verify-contract <CONTRACT_ADDRESS> src/$<CONTRACT_NAME>.sol:<CONTRACT_NAME> --verifier <etherscan|blockscout|sourcify> --verifier-url <VERIFIER_URL>
```

## Coverage

Check coverages with:

```sh
bash coverage.sh
forge clean && bash coverage.sh
```
or to see summarized coverages on terminal:

```sh
make cov
forge clean && forge coverage --no-match-coverage "(test|mock|script)"
```

You can see coverages under the coverage directory.
Expand All @@ -109,43 +117,43 @@ You can see coverages under the coverage directory.
Get storage layout with:

```sh
bash storage.sh
forge clean && bash storage.sh
```

You can see storage layouts under the storage directory.

## Format
## Gas Snapshot

Format code with:
Take the gas snapshot with:

```sh
make fmt
forge clean && forge snapshot
```

## Update
You can see the snapshot `.gas-snapshot` file in the current directory.

Update modules with:
## Format

Format code with:

```sh
make update
forge fmt
```

## Gas Snapshot
## Generate documentation

Take the gas snapshot with:
Generate documentation with:

```sh
make snapshot
forge doc
```

You can see the snapshot `.gas-snapshot` file in the current directory.

## Generate documentation
## Update

Generate documentation with:
Update modules with:

```sh
make doc
forge update
```

You can see the documentation under the `docs/` directory.
16 changes: 8 additions & 8 deletions deployment/84532.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"LLMOracleRegistry": {
"proxyAddr": "0x90193c961a926261b756d1e5bb255e67ff9498a1",
"implAddr": "0x34a1d3fff3958843c43ad80f30b94c510645c316"
"proxyAddr": "0x4e4ef93f3ac35ca6505f582c666958f99218de21",
"implAddr": "0xa826dfee9089004d9a6d832f854375eb725074bb"
},
"LLMOracleCoordinator": {
"proxyAddr": "0xbb2180ebd78ce97360503434ed37fcf4a1df61c3",
"implAddr": "0xa8452ec99ce0c64f20701db7dd3abdb607c00496"
"proxyAddr": "0x237f1bda05451ade6214a12e85b5084511da2995",
"implAddr": "0x4a2d4f8734c4b322685fadfc72e44f0011123814"
},
"Swan": {
"proxyAddr": "0xdeb1e9a6be7baf84208bb6e10ac9f9bbe1d70809",
"implAddr": "0x62c20aa1e0272312bc100b4e23b4dc1ed96dd7d1"
"proxyAddr": "0x70c85509fc1da642e90d8dc5a9487fa4c36ea77c",
"implAddr": "0x1f5bff2d013fe0051a7f1d1b932183c3d839d384"
},
"BuyerAgentFactory": "0xdb8cff278adccf9e9b5da745b44e754fc4ee3c76",
"SwanAssetFactory": "0x50eef481cae4250d252ae577a09bf514f224c6c4"
"BuyerAgentFactory": "0xc48af3ef03d91af34b891688ade004ad36c8c39a",
"SwanAssetFactory": "0xebb2c54b2a20e0e25b2fb168c8a657e1c966911f"
}
Loading

0 comments on commit 6a4c427

Please sign in to comment.