@rev-net/core-v6 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/SKILLS.md +1 -1
  2. package/docs/book.toml +1 -1
  3. package/docs/src/README.md +151 -54
  4. package/docs/src/SUMMARY.md +0 -2
  5. package/docs/src/src/REVDeployer.sol/contract.REVDeployer.md +148 -117
  6. package/docs/src/src/REVLoans.sol/contract.REVLoans.md +120 -59
  7. package/docs/src/src/interfaces/IREVDeployer.sol/interface.IREVDeployer.md +296 -14
  8. package/docs/src/src/interfaces/IREVLoans.sol/interface.IREVLoans.md +318 -16
  9. package/docs/src/src/structs/README.md +0 -2
  10. package/docs/src/src/structs/REVAutoIssuance.sol/struct.REVAutoIssuance.md +4 -4
  11. package/docs/src/src/structs/REVConfig.sol/struct.REVConfig.md +5 -17
  12. package/docs/src/src/structs/REVCroptopAllowedPost.sol/struct.REVCroptopAllowedPost.md +10 -6
  13. package/docs/src/src/structs/REVDeploy721TiersHookConfig.sol/struct.REVDeploy721TiersHookConfig.md +7 -7
  14. package/docs/src/src/structs/REVDescription.sol/struct.REVDescription.md +5 -5
  15. package/docs/src/src/structs/REVLoan.sol/struct.REVLoan.md +7 -7
  16. package/docs/src/src/structs/REVLoanSource.sol/struct.REVLoanSource.md +3 -3
  17. package/docs/src/src/structs/REVStageConfig.sol/struct.REVStageConfig.md +10 -10
  18. package/docs/src/src/structs/REVSuckerDeploymentConfig.sol/struct.REVSuckerDeploymentConfig.md +3 -3
  19. package/package.json +6 -6
  20. package/slither-ci.config.json +1 -1
  21. package/src/REVLoans.sol +20 -9
  22. package/src/interfaces/IREVDeployer.sol +0 -2
  23. package/src/interfaces/IREVLoans.sol +10 -4
  24. package/test/TestPR27_CEIPattern.t.sol +2 -2
  25. package/test/TestPR32_MixedFixes.t.sol +1 -1
  26. package/test/regression/TestI20_CumulativeLoanCounter.t.sol +303 -0
  27. package/test/regression/TestL27_LiquidateGapHandling.t.sol +334 -0
package/SKILLS.md CHANGED
@@ -128,7 +128,7 @@ Deploy and manage Revnets -- autonomous, unowned Juicebox projects with staged i
128
128
  | Mapping | Type | Purpose |
129
129
  |---------|------|---------|
130
130
  | `isLoanSourceOf` | `revnetId => terminal => token => bool` | Is this (terminal, token) pair used for loans? |
131
- | `numberOfLoansFor` | `revnetId => uint256` | Counter for loan numbering |
131
+ | `totalLoansBorrowedFor` | `revnetId => uint256` | Counter for loan numbering |
132
132
  | `totalBorrowedFrom` | `revnetId => terminal => token => uint256` | Tracks debt per loan source |
133
133
  | `totalCollateralOf` | `revnetId => uint256` | Sum of all burned collateral |
134
134
  | `_loanOf` | `loanId => REVLoan` | Per-loan state |
package/docs/book.toml CHANGED
@@ -7,7 +7,7 @@ no-section-label = true
7
7
  additional-js = ["solidity.min.js"]
8
8
  additional-css = ["book.css"]
9
9
  mathjax-support = true
10
- git-repository-url = "https://github.com/rev-net/revnet-core-v5"
10
+ git-repository-url = "https://github.com/rev-net/revnet-core-v6"
11
11
 
12
12
  [output.html.fold]
13
13
  enable = true
@@ -1,88 +1,185 @@
1
- # Revnet
1
+ # Revnet Core
2
2
 
3
- This repo provides tools for deploying Revnets: Retailistic networks, using the Juicebox and Uniswap protocols for its implementation.
3
+ Deploy and operate Revnets: unowned Juicebox projects that run autonomously according to predefined stages, with built-in token-collateralized loans.
4
4
 
5
- For a Retailism TLDR, see https://jango.eth.sucks/9E01E72C-6028-48B7-AD04-F25393307132/.
5
+ [Docs](https://docs.juicebox.money) | [Discord](https://discord.gg/nT3XqbzNEr)
6
6
 
7
- For more Retailism information, see:
7
+ ## What is a Revnet?
8
8
 
9
- A Retailistic View on CAC and LTV
10
- https://jango.eth.limo/572BD957-0331-4977-8B2D-35F84D693276/
9
+ A Revnet is a treasury-backed token that runs itself. No owners, no governors, no multisigs. Once deployed, a revnet follows its predefined stages forever, backed by the Juicebox and Uniswap protocols.
11
10
 
12
- Modeling Retailism
13
- https://jango.eth.limo/B762F3CC-AEFE-4DE0-B08C-7C16400AF718/
11
+ ## Conceptual Overview
14
12
 
15
- Retailism for Devs, Investors, and Customers
16
- https://jango.eth.limo/3EB05292-0376-4B7D-AFCF-042B70673C3D/
13
+ Revnets are autonomous Juicebox projects with predetermined economic stages. Each stage defines issuance rates, decay schedules, cash-out taxes, reserved splits, and auto-issuance allocations. Once deployed, these parameters cannot be changed -- the revnet operates on its own forever.
17
14
 
18
- Observations: Network dynamics similar between atoms, cells, organisms, groups, dance parties.
19
- https://jango.eth.limo/CF40F5D2-7BFE-43A3-9C15-1C6547FBD15C/
15
+ ### Stage-Based Lifecycle
20
16
 
21
- Join the conversation here: https://discord.gg/nT3XqbzNEr
17
+ ```
18
+ 1. Deploy revnet with stage configurations
19
+ → REVDeployer.deployFor(revnetId=0, config, terminals, ...)
20
+ → Creates Juicebox project owned by REVDeployer (permanently)
21
+ → Deploys ERC-20 token, configures buyback pools, deploys suckers
22
+ |
23
+ 2. Stage 1 begins (startsAtOrAfter or block.timestamp)
24
+ → Tokens issued at initialIssuance rate per unit of base currency
25
+ → Issuance decays by issuanceCutPercent every issuanceCutFrequency
26
+ → splitPercent of new tokens go to reserved splits
27
+ → Cash outs taxed at cashOutTaxRate (2.5% fee to fee revnet)
28
+ |
29
+ 3. Stage transitions happen automatically
30
+ → When startsAtOrAfter timestamp is reached for next stage
31
+ → New issuance rate, tax rate, splits, etc. take effect
32
+ → No governance, no votes, no owner action required
33
+ |
34
+ 4. Participants can borrow against their tokens
35
+ → REVLoans.borrowFrom(revnetId, source, collateral, ...)
36
+ → Collateral tokens are burned, funds pulled from treasury
37
+ → Loan is an ERC-721 NFT, liquidates after 10 years
38
+ |
39
+ 5. Ongoing operations (permissionless or split operator)
40
+ → Auto-issuance claims (permissionless)
41
+ → Buyback pool configuration (split operator)
42
+ → Sucker deployment (split operator, if ruleset allows)
43
+ → Split group updates (split operator)
44
+ ```
22
45
 
23
- In this repo, you'll find:
24
- - a basic revnet design implemented in `BasicRevnetDeployer`.
25
- - a design that accepts other pay hooks implemented in `PayHookRevnetDeployer`, which accepts other pay hooks that'll get used throughout the revnet's lifetime as it receives payments.
26
- - a design that supports tiered 721 pay hooks implemented in `Tiered721RevnetDeployer`, which accepts data to deploy a tiered 721 pay hook that'll get used throughout the network's lifetime as people pay in, alongside other pay hooks that may also be specified.
27
- - a design supports croptop, implemented in `CroptopRevnetDeployer`, which accepts data to deploy a tiered 721 pay hook that'll get used throughout the project's lifetime as people pay in that can also be posted to by the public through the croptop publisher contract. See https://croptop.eth.limo for more context.
46
+ ### Token-Collateralized Loans
28
47
 
29
- You can use these contracts to deploy treasuries from etherscan, or wherever else they've been exposed from.
48
+ `REVLoans` lets participants borrow against their revnet tokens. Unlike traditional lending:
30
49
 
31
- ## Install
50
+ - **Collateral is burned, not held.** Tokens are destroyed on borrow and re-minted on repay. This keeps the token supply accurate -- collateral tokens don't exist during the loan.
51
+ - **Borrowable amount = cash-out value.** The bonding curve determines how much you can borrow for a given amount of collateral.
52
+ - **Prepaid fee model.** Borrowers choose a prepaid fee (2.5%-50%) that buys an interest-free window. After that window, a time-proportional source fee accrues.
53
+ - **Each loan is an ERC-721 NFT.** Loans can be transferred, and expired loans (10 years) can be liquidated by anyone.
54
+
55
+ ### Deployer Variants
56
+
57
+ - **Basic revnet** -- `deployFor` with stage configurations mapped to Juicebox rulesets.
58
+ - **Tiered 721 revnet** -- `deployWith721sFor` adds a tiered 721 pay hook that mints NFTs as people pay.
59
+ - **Croptop revnet** -- A tiered 721 revnet with Croptop posting criteria, allowing the public to post content.
60
+
61
+ ## Architecture
32
62
 
33
- For `npm` projects (recommended):
63
+ | Contract | Description |
64
+ |----------|-------------|
65
+ | `REVDeployer` | Deploys revnets as Juicebox projects owned by the deployer contract itself (no human owner). Translates stage configurations into Juicebox rulesets, manages buyback hooks, tiered 721 hooks, suckers, split operators, auto-issuance, and cash-out fees. Acts as the ruleset data hook and cash-out hook for every revnet it deploys. |
66
+ | `REVLoans` | Lets participants borrow against their revnet tokens. Collateral tokens are burned on borrow and re-minted on repayment. Each loan is an ERC-721 NFT. Charges a prepaid fee (2.5% min, 50% max) that determines the interest-free duration; after that window, a time-proportional source fee accrues. Loans liquidate after 10 years. |
67
+
68
+ ### How They Relate
69
+
70
+ `REVDeployer` owns every revnet's Juicebox project NFT and holds all administrative permissions. During deployment it grants `REVLoans` the `USE_ALLOWANCE` permission so loans can pull funds from the revnet's terminal. `REVLoans` verifies that a revnet was deployed by its expected `REVDeployer` before issuing any loan.
71
+
72
+ ### Interfaces
73
+
74
+ | Interface | Description |
75
+ |-----------|-------------|
76
+ | `IREVDeployer` | Deployment, data hooks, auto-issuance, split operator management, sucker deployment, plus events. |
77
+ | `IREVLoans` | Borrow, repay, refinance, liquidate, views, plus events. |
78
+
79
+ ## Install
34
80
 
35
81
  ```bash
36
- npm install @bananapus/721-hook
82
+ npm install @rev-net/core-v6
37
83
  ```
38
84
 
39
- For `forge` projects (not recommended):
85
+ If using Forge directly:
40
86
 
41
87
  ```bash
42
- forge install Bananapus/nana-721-hook
88
+ npm install && forge install
43
89
  ```
44
90
 
45
- Add `@bananapus/721-hook/=lib/nana-721-hook/` to `remappings.txt`. You'll also need to install `nana-721-hook`'s dependencies and add similar remappings for them.
91
+ If `forge install` has issues, try `git submodule update --init --recursive`.
46
92
 
47
93
  ## Develop
48
94
 
49
- `nana-721-hook` uses [npm](https://www.npmjs.com/) for package management and the [Foundry](https://github.com/foundry-rs/foundry) development toolchain for builds, tests, and deployments. To get set up, [install Node.js](https://nodejs.org/en/download) and install [Foundry](https://github.com/foundry-rs/foundry):
95
+ | Command | Description |
96
+ |---------|-------------|
97
+ | `forge build` | Compile contracts |
98
+ | `forge test` | Run tests (20+ test files covering deployment, lifecycle, loans, attacks, invariants) |
99
+ | `forge test -vvvv` | Run tests with full traces |
50
100
 
51
- ```bash
52
- curl -L https://foundry.paradigm.xyz | sh
101
+ ## Repository Layout
102
+
103
+ ```
104
+ src/
105
+ REVDeployer.sol # Revnet deployer + data hook (~1,256 lines)
106
+ REVLoans.sol # Token-collateralized lending (~1,333 lines)
107
+ interfaces/
108
+ IREVDeployer.sol # Deployer interface + events
109
+ IREVLoans.sol # Loans interface + events
110
+ structs/
111
+ REVConfig.sol # Top-level deployment config
112
+ REVDescription.sol # ERC-20 metadata (name, ticker, uri, salt)
113
+ REVStageConfig.sol # Economic stage parameters
114
+ REVAutoIssuance.sol # Per-stage cross-chain premint
115
+ REVLoan.sol # Loan state
116
+ REVLoanSource.sol # Terminal + token pair for loans
117
+ REVDeploy721TiersHookConfig.sol # 721 hook deployment config
118
+ REVCroptopAllowedPost.sol # Croptop posting criteria
119
+ REVSuckerDeploymentConfig.sol # Cross-chain sucker deployment
120
+ test/
121
+ REV.integrations.t.sol # Deployment, payments, cash-outs
122
+ REVLifecycle.t.sol # Stage transitions, weight decay
123
+ REVAutoIssuanceFuzz.t.sol # Auto-issuance fuzz tests
124
+ REVInvincibility.t.sol # Economic property fuzzing
125
+ REVInvincibilityHandler.sol # Fuzz handler
126
+ REVDeployerAuditRegressions.t.sol # Deployer audit regressions
127
+ REVLoansSourced.t.sol # Multi-source loan tests
128
+ REVLoansUnSourced.t.sol # Loan error cases
129
+ REVLoansFeeRecovery.t.sol # Fee calculation tests
130
+ REVLoansAttacks.t.sol # Flash loan, reentrancy scenarios
131
+ REVLoans.invariants.t.sol # Loan fuzzing invariants
132
+ REVLoansAuditRegressions.t.sol # Loan audit regressions
133
+ TestPR09-32_*.t.sol # Per-PR regression tests
134
+ helpers/
135
+ MaliciousContracts.sol # Attack contract mocks
136
+ mock/
137
+ MockBuybackDataHook.sol # Mock for buyback hook tests
138
+ script/
139
+ Deploy.s.sol # Sphinx multi-chain deployment
140
+ helpers/
141
+ RevnetCoreDeploymentLib.sol # Deployment artifact reader
53
142
  ```
54
143
 
55
- You can download and install dependencies with:
144
+ ## Permissions
56
145
 
57
- ```bash
58
- npm install && forge install
59
- ```
146
+ ### Split Operator (per-revnet)
147
+
148
+ The split operator has these default permissions:
149
+
150
+ | Permission | Purpose |
151
+ |------------|---------|
152
+ | `SET_SPLIT_GROUPS` | Change reserved token splits |
153
+ | `SET_BUYBACK_POOL` | Configure Uniswap buyback pool |
154
+ | `SET_BUYBACK_TWAP` | Adjust TWAP window for buyback |
155
+ | `SET_PROJECT_URI` | Update project metadata |
156
+ | `ADD_PRICE_FEED` | Add price oracle |
157
+ | `SUCKER_SAFETY` | Emergency sucker functions |
158
+ | `SET_BUYBACK_HOOK` | Swap buyback hook |
159
+ | `SET_ROUTER_TERMINAL` | Swap terminal |
60
160
 
61
- If you run into trouble with `forge install`, try using `git submodule update --init --recursive` to ensure that nested submodules have been properly initialized.
161
+ Plus optional from 721 hook config: `ADJUST_721_TIERS`, `SET_721_METADATA`, `MINT_721`, `SET_721_DISCOUNT_PERCENT`.
62
162
 
63
- Some useful commands:
163
+ ### Global Permissions
64
164
 
65
- | Command | Description |
66
- | --------------------- | --------------------------------------------------- |
67
- | `forge build` | Compile the contracts and write artifacts to `out`. |
68
- | `forge fmt` | Lint. |
69
- | `forge test` | Run the tests. |
70
- | `forge build --sizes` | Get contract sizes. |
71
- | `forge coverage` | Generate a test coverage report. |
72
- | `foundryup` | Update foundry. Run this periodically. |
73
- | `forge clean` | Remove the build artifacts and cache directories. |
165
+ | Grantee | Permission | Scope |
166
+ |---------|------------|-------|
167
+ | `SUCKER_REGISTRY` | `MAP_SUCKER_TOKEN` | All revnets (wildcard projectId=0) |
168
+ | `REVLoans` | `USE_ALLOWANCE` | All revnets (wildcard projectId=0) |
74
169
 
75
- To learn more, visit the [Foundry Book](https://book.getfoundry.sh/) docs.
170
+ ### Permissionless Operations
76
171
 
77
- ## Scripts
172
+ - `autoIssueFor` -- claim auto-issuance tokens (anyone)
173
+ - `burnHeldTokensOf` -- burn reserved tokens held by deployer (anyone)
78
174
 
79
- For convenience, several utility commands are available in `package.json`.
175
+ ## Risks
80
176
 
81
- | Command | Description |
82
- | --------------------------------- | -------------------------------------- |
83
- | `npm test` | Run local tests. |
84
- | `npm run coverage:lcov` | Generate an LCOV test coverage report. |
85
- | `npm run deploy:ethereum-mainnet` | Deploy to Ethereum mainnet |
86
- | `npm run deploy:ethereum-sepolia` | Deploy to Ethereum Sepolia testnet |
87
- | `npm run deploy:optimism-mainnet` | Deploy to Optimism mainnet |
88
- | `npm run deploy:optimism-testnet` | Deploy to Optimism testnet |
177
+ - **No human owner.** `REVDeployer` permanently holds the project NFT. There is no function to release it. This is by design -- revnets are ownerless. But it means bugs in stage configurations cannot be fixed after deployment.
178
+ - **Loan flash-loan exposure.** `borrowableAmountFrom` reads live surplus, which can be inflated via flash loans. A borrower could temporarily inflate the treasury to borrow more than the sustained value would support.
179
+ - **uint112 truncation.** `REVLoan.amount` and `REVLoan.collateral` are `uint112` -- values above ~5.19e33 truncate silently.
180
+ - **Cash-out fee stacking.** Cash outs incur both the Juicebox terminal fee (2.5%) and the revnet cash-out fee (2.5% to fee revnet). These compound.
181
+ - **Auto-issuance stage ID mismatch.** Stage IDs are computed as `block.timestamp + i` during deployment, but actual Juicebox ruleset IDs depend on queuing logic. If timestamps don't align, auto-issuance for later stages may be unclaimed.
182
+ - **NATIVE_TOKEN on non-ETH chains.** Using `JBConstants.NATIVE_TOKEN` on Celo or Polygon means CELO/MATIC, not ETH. Use ERC-20 WETH instead. The matching hash does NOT catch this -- it covers economic parameters but NOT terminal configurations.
183
+ - **30-day cash-out delay.** When deploying an existing revnet to a new chain where the first stage has already started, a 30-day delay is imposed before cash outs are allowed, preventing cross-chain liquidity arbitrage.
184
+ - **Loan source array growth.** `_loanSourcesOf[revnetId]` is unbounded. If an attacker creates loans from many different terminals/tokens, the array grows without limit.
185
+ - **10-year loan liquidation.** Expired loans (10+ years) can be liquidated by anyone. The burned collateral is permanently lost -- it was destroyed at borrow time.
@@ -6,8 +6,6 @@
6
6
  - [IREVLoans](src/interfaces/IREVLoans.sol/interface.IREVLoans.md)
7
7
  - [❱ structs](src/structs/README.md)
8
8
  - [REVAutoIssuance](src/structs/REVAutoIssuance.sol/struct.REVAutoIssuance.md)
9
- - [REVBuybackHookConfig](src/structs/REVBuybackHookConfig.sol/struct.REVBuybackHookConfig.md)
10
- - [REVBuybackPoolConfig](src/structs/REVBuybackPoolConfig.sol/struct.REVBuybackPoolConfig.md)
11
9
  - [REVConfig](src/structs/REVConfig.sol/struct.REVConfig.md)
12
10
  - [REVCroptopAllowedPost](src/structs/REVCroptopAllowedPost.sol/struct.REVCroptopAllowedPost.md)
13
11
  - [REVDeploy721TiersHookConfig](src/structs/REVDeploy721TiersHookConfig.sol/struct.REVDeploy721TiersHookConfig.md)