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

TRUST M-8: Reward distribution in RewardableERC20 #993

Closed
wants to merge 522 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
522 commits
Select commit Hold shift + click to select a range
7309e1d
even simpler
tbrent May 12, 2023
bfa151a
nit
tbrent May 12, 2023
efa2a74
fix StRSR extreme tests
tbrent May 12, 2023
7a8703b
only run extreme tests when EXTREME=1
tbrent May 12, 2023
db72f7b
fix failing tests
tbrent May 12, 2023
c96ee4b
Merge pull request #816 from reserve-protocol/3.0.0-gas-optimize
tbrent May 12, 2023
eab5a39
Merge pull request #822 from reserve-protocol/master
akshatmittal May 12, 2023
0192cda
gas snapshots
tbrent May 15, 2023
6498795
Merge pull request #823 from reserve-protocol/3.0.0-gas-snapshots
tbrent May 15, 2023
585222b
new auction length validations
julianmrodri May 17, 2023
f74264c
adjust broker tests
julianmrodri May 17, 2023
68df6a8
fix comment
julianmrodri May 17, 2023
b647511
fix revenue tests
julianmrodri May 17, 2023
48fb3b8
Merge pull request #827 from reserve-protocol/feat-broker
tbrent May 17, 2023
0b85b08
make first offered dutch auction price exactly highPrice; + comments
tbrent May 17, 2023
339fcea
further simplification
tbrent May 17, 2023
e043d10
remove kruft --dev depedency
tbrent May 18, 2023
849f1e3
DutchTrade: 30% / 70% auction split with 4/5 as the exp base
tbrent May 18, 2023
65824a8
Revenues tests
tbrent May 18, 2023
3e91bf1
Recollateralization tests
tbrent May 18, 2023
5f94e2d
remove prime nonce and update tests (#824)
tbrent May 18, 2023
af4bff7
final answer: 33%/66% split with 18.6 minute auctions
tbrent May 18, 2023
a39beea
new gas snapshots
tbrent May 18, 2023
e590d4a
Correct vendor files (#826)
pmckelvy1 May 18, 2023
924f518
backwards compatible FacadeRead/Act (#825)
tbrent May 18, 2023
dacb348
fix failing tests
tbrent May 18, 2023
a732632
Merge branch '3.0.0' into manipulated-prices
tbrent May 18, 2023
403615b
docs/system-design.md
tbrent May 18, 2023
9f2cf7e
fix Broker test
tbrent May 18, 2023
14ea9cf
system-design.md: withdrawalLeak
tbrent May 18, 2023
28532d1
cache quantities only
tbrent May 18, 2023
053c1a9
skip over RToken dust balances without computing price
tbrent May 18, 2023
0af3dc4
add test for trading RToken last
tbrent May 18, 2023
7b6ed64
gas snapshots
tbrent May 18, 2023
6008aad
delete console.log
tbrent May 18, 2023
b94fd68
mainnet facadeAct/facadeRead addresses
tbrent May 19, 2023
85d5263
fix distributor internal consistency + add clearer comment
tbrent May 19, 2023
db2466d
more comment clarifications
tbrent May 19, 2023
7822771
switch from trading RToken last to virtually redeeming it first
tbrent May 19, 2023
623f9a0
remove MAX_DESTINATIONS
tbrent May 19, 2023
c023675
add-back distributor-dust optimization + use dissolve() as function name
tbrent May 19, 2023
a22f53f
fix typo
tbrent May 19, 2023
0ba27bf
align P0 RToken with P1
tbrent May 19, 2023
17d10be
fix RToken test
tbrent May 19, 2023
de997b0
remove unreachable line
tbrent May 19, 2023
064f02f
add test nit
tbrent May 19, 2023
da63858
Merge pull request #829 from reserve-protocol/gas-optimize-rebalance
tbrent May 19, 2023
1a168b6
Merge branch '3.0.0' into manipulated-prices
pmckelvy1 May 19, 2023
2a7e75a
simplify RToken/BackingManager relationship + remove redundant modifiers
tbrent May 19, 2023
1379fcf
tests
tbrent May 19, 2023
15faffc
gas snapshots
tbrent May 19, 2023
6eda68b
polish off RToken + final snapshots
tbrent May 20, 2023
9bdb1e3
keep notTradingPausedOrFrozen on setBasketsNeeded
tbrent May 20, 2023
6b58e9f
re-order tryTrade and document nonReentrant testatibility
tbrent May 20, 2023
7265e24
fix RTokenP0
tbrent May 20, 2023
cb6c045
fix integration test inconsistency in CI
tbrent May 20, 2023
090be39
Merge branch 'manipulated-prices' into 3.0.0-audit-tbrent
tbrent May 20, 2023
de6f2da
fix P1 tests
tbrent May 20, 2023
ac26373
TraderP1: fix ordering and label nonReentrant requirement
tbrent May 20, 2023
659d3c8
test cacheComponents() doesn't break anything
tbrent May 20, 2023
38b86cd
make auction algorithm far more general; switch to 40%/60% 30m
tbrent May 20, 2023
215bedd
cache components P1 only
tbrent May 20, 2023
9be8709
snipe in last possible second in tests
tbrent May 20, 2023
2bb2e13
updated gas snapshots
tbrent May 20, 2023
352ea80
cacheComponents the right way
tbrent May 20, 2023
318c8c6
Merge pull request #828 from reserve-protocol/manipulated-prices
tbrent May 20, 2023
eed2ebd
Merge branch '3.0.0' into 3.0.0-audit-tbrent
tbrent May 20, 2023
b096416
updated gas snapshots
tbrent May 20, 2023
12812c3
nit over DutchTrade comments
tbrent May 20, 2023
f4beb60
a few more comments
tbrent May 20, 2023
3d6f097
Facades: terser way to try-catch 3.0.0/2.1.0 implementations
tbrent May 21, 2023
4e7697a
FacadeRead: remove basketNonce from redeem function to match RToken.r…
tbrent May 21, 2023
40de8d1
FacadeRead.nextRecollateralizationAuction: make backwards compatible …
tbrent May 21, 2023
205befd
fix compile
tbrent May 21, 2023
2831935
docs/system-design.md: document dutch auctions
tbrent May 21, 2023
58d6795
docs/system-design.md: document all the places we make a blocktime as…
tbrent May 21, 2023
fec188c
CHANGELOG.md: partially complete
tbrent May 21, 2023
40078c0
invert changelog
tbrent May 21, 2023
3a85b21
fix call to settle trade
julianmrodri May 22, 2023
c73aa2a
Merge pull request #832 from reserve-protocol/fix-facaderead
tbrent May 22, 2023
c509a2c
Merge branch '3.0.0' into 3.0.0-audit-tbrent
tbrent May 22, 2023
59156a9
bump Versioned mixin
tbrent May 22, 2023
830d070
FacadeRead/Act: parse version and make version-specific call
tbrent May 22, 2023
d014777
fix typo
tbrent May 22, 2023
f425495
lint clean
tbrent May 22, 2023
1fe413d
add back tests for transfer/transferFrom to RToken
tbrent May 22, 2023
8cc1cea
Merge pull request #831 from reserve-protocol/3.0.0-audit-tbrent
tbrent May 22, 2023
c29455f
bump suggested withdrawalLeak to 1%
tbrent May 22, 2023
6db28bd
bump suggested withdrawalLeak to 5%
tbrent May 22, 2023
e0b66e4
nitpicks
akshatmittal May 22, 2023
80a3a93
use 3.0.0 in tests for Permit approvals, etc
tbrent May 22, 2023
da6d2ce
Remove comment
akshatmittal May 22, 2023
aa6f130
Merge pull request #834 from reserve-protocol/3.0.0-review-akshat
akshatmittal May 22, 2023
57a77ff
Merge pull request #833 from reserve-protocol/parse-version
tbrent May 22, 2023
b72d3f6
document StRSR.cancelUnstake
tbrent May 23, 2023
ab35193
remove all mention of manageTokens
tbrent May 23, 2023
6e9e32f
remove kruft event
tbrent May 23, 2023
e1b2254
update RewardableLibP1 comments
tbrent May 23, 2023
d6459b3
CHANGELOG.md
tbrent May 23, 2023
647b6c0
add summaries
tbrent May 23, 2023
be89c47
CHANGELOG.md: 3.0.0 upgrade instructions
tbrent May 23, 2023
0c11e56
Merge pull request #835 from reserve-protocol/3.0.0-docs
tbrent May 23, 2023
5028f3a
FacadeRead.overview(): do not revert if an asset lotLow is 0
tbrent May 23, 2023
9ade0b3
move trading functions around. FacadeRead was over limit
tbrent May 24, 2023
35d015b
new FacadeRead/FacadeAct addresses
tbrent May 24, 2023
0f4115f
basket handler fix in historical basket
julianmrodri May 24, 2023
cfd1635
add untestable comments
julianmrodri May 24, 2023
c4ec247
Merge pull request #836 from reserve-protocol/3.0.0-rc2
tbrent May 24, 2023
9d0e65f
3.0.0 rc3 (#837)
julianmrodri Jul 3, 2023
498819c
3.0.0 rc4 (#857)
tbrent Jul 3, 2023
1e24984
Merge branch 'master' into 3.0.0
tbrent Jul 3, 2023
a82b672
fix compiling
tbrent Jul 3, 2023
3d847b0
lint clean
tbrent Jul 3, 2023
a99856e
BasketHandlerP1 to under contract limit
tbrent Jul 3, 2023
23ffa89
nit
tbrent Jul 3, 2023
16b4c87
Broker.test.ts
tbrent Jul 4, 2023
33454b5
Revenues.test.ts
tbrent Jul 4, 2023
fe85f8a
curve collateralTests.ts
tbrent Jul 4, 2023
e51b466
Fix 4byte 300 (#862)
pmckelvy1 Jul 5, 2023
aedbd14
prettier fixes 3.0.0 (#859)
julianmrodri Jul 6, 2023
ce892b2
ci tests - non-determinism (#858)
julianmrodri Jul 6, 2023
eea6776
fix storage slots Distributor (#865)
julianmrodri Jul 7, 2023
e351b32
additional furnace timestamp check (#866)
julianmrodri Jul 7, 2023
6da3481
Base Testnet configuration (#867)
julianmrodri Jul 11, 2023
a1092d7
Base Testnet configuration (#867)
julianmrodri Jul 11, 2023
05961a1
Stargate Asset Plugin (#863)
akshatmittal Jul 18, 2023
9ee60f1
Update mattjurenka/morpho to 3.0.0 (#853)
jankjr Jul 18, 2023
e92b43a
Allow `settleTrade` when paused or frozen (#876)
akshatmittal Jul 28, 2023
3c20f04
Morpho - Add missing tokens to deployment and expand unit tests (#874)
jankjr Aug 1, 2023
e85ed27
Zero distribution (#878)
tbrent Aug 2, 2023
12c81a0
Bunch of small changes (#877)
akshatmittal Aug 2, 2023
809a8d2
useAvailable when setting throttles. (#872)
pmckelvy1 Aug 3, 2023
64ed2a9
Disable dutch auctions per-collateral (#873)
tbrent Aug 3, 2023
ef66344
c4 #51 (#871)
pmckelvy1 Aug 3, 2023
117f63e
gas test asset.refresh() for all tests (#880)
tbrent Aug 4, 2023
a6871ac
Fix 4byte Integration (#879)
akshatmittal Aug 7, 2023
949b0be
Dutch trade decimals (#883)
tbrent Aug 8, 2023
9655b34
add new tenderly fork with different chain id
tbrent Aug 8, 2023
9d8b7e2
tenderly fork addresses
tbrent Aug 8, 2023
7aa0628
init readme doc for building on top
tbrent Aug 8, 2023
fe5d38d
README: add responsible disclosure section while we're at it
tbrent Aug 8, 2023
e8f5568
C4 #29 (#885)
tbrent Aug 9, 2023
30d5bfc
[docs] Positive Token Redemption Value (#887)
akshatmittal Aug 10, 2023
4ce086f
C4: handle Chainlink oracle deprecation (#886)
jankjr Aug 10, 2023
20bedef
C4: StRSR reset stakes functionality (#888)
julianmrodri Aug 10, 2023
809b4a8
C4: add test to show effect of someone frontrunning a gnosis trade (#…
jankjr Aug 11, 2023
e5f0a36
remove --parallel from all package.json targets (#893)
tbrent Aug 11, 2023
08212ff
RecollateralizationLib gas optimization (#890)
tbrent Aug 11, 2023
6d4cf57
Gas tests (#895)
tbrent Aug 14, 2023
99d9db7
Bunch of gas optimizations (#894)
akshatmittal Aug 14, 2023
11aa80b
deployment: overwrite addresses when working with tenderly
tbrent Aug 18, 2023
bc8a177
do not stop refreshing prices for DISABLED collateral (#902)
tbrent Aug 21, 2023
54dde6d
update gas snapshots (#904)
tbrent Aug 21, 2023
5d551f4
Single price (#900)
tbrent Aug 21, 2023
45d8c36
c4: #5 Potential Early Exploit in Morho-Aave ERC4626 Implementation (…
jankjr Aug 21, 2023
2cb41d4
avoid revert when checking recoll auctions
julianmrodri Aug 22, 2023
91cc33e
rollback change in facade
julianmrodri Aug 22, 2023
19d84ef
C4: #35 #32, fixes rETH / cbETH / ankrETH ref unit and adds soft defa…
jankjr Aug 22, 2023
f8a7519
document recommended throttle limits. (#905)
pmckelvy1 Aug 22, 2023
006eb16
fix rebalance in facade (#908)
julianmrodri Aug 22, 2023
1b37c77
C4 39 use comet decimals instead of wrapper decimals. (#889)
pmckelvy1 Aug 22, 2023
755cf3c
update Asset price comment. (#910)
pmckelvy1 Aug 23, 2023
4fb96fa
C4 Audit (Plugin) Changes (#896)
akshatmittal Aug 23, 2023
8aa658e
Restrict disabling dutch auctions to those started by the BackingMana…
tbrent Aug 23, 2023
2c98933
Stargate fixes (#881)
pmckelvy1 Aug 24, 2023
a0480a8
3.0.0 rc5 (#882)
pmckelvy1 Aug 24, 2023
c10d1cf
README
tbrent Aug 23, 2023
c4c0a2a
nit: re-order usings to alphabetic ordering
tbrent Aug 24, 2023
1828744
C4 40: Restrict dutch trades to being disabled only by BackingManager…
tbrent Aug 24, 2023
97f6d4b
CHANGELOG.md
tbrent Aug 24, 2023
51bbdf1
collateral.md
tbrent Aug 24, 2023
4ed50dc
mev.md
tbrent Aug 24, 2023
9dc44c6
save gas by only checking aggregator if there is a revert (#914)
tbrent Aug 25, 2023
544213c
Merge branch '3.0.0' into 3.0.0-rc6
tbrent Aug 25, 2023
14600bd
Merge branch '3.0.0-rc6' into docs
tbrent Aug 25, 2023
9657c31
facade support batch auctions (#918)
julianmrodri Aug 27, 2023
1db057b
document RTokenAsset.price() oracleError double-counting (#916)
tbrent Aug 28, 2023
57c88d1
try catch on ctoken exchangeRateCurrent (#921)
julianmrodri Aug 30, 2023
ea1e6c1
Clarify rewards handling on transfer (#920)
julianmrodri Aug 30, 2023
b420059
3.1.0 c4 20 (#922)
tbrent Aug 31, 2023
b0849fd
C4 +inf (#917)
tbrent Aug 31, 2023
1cbbc46
Merge branch '3.0.0-rc6' into 3.1.0-rc1
tbrent Aug 31, 2023
4d989e5
distribute token to buy in setDistribution (#925)
julianmrodri Aug 31, 2023
875bfc3
C4 mit 31 - standoff scenario (#923)
pmckelvy1 Aug 31, 2023
8d9edaa
cherry-pick enable-only auction setters (#924)
tbrent Aug 31, 2023
907299c
loss of pending rewards when claiming in StaticAToken (#926)
julianmrodri Aug 31, 2023
e1d26ca
update CHANGELOG and a few stale comments
tbrent Aug 31, 2023
3897314
Merge branch '3.0.0-rc6' into docs
tbrent Aug 31, 2023
1bcc268
clarify aave V2 erc20s don't need to upgrade
tbrent Aug 31, 2023
8487981
Merge branch 'docs' into 3.1.0-rc1
tbrent Aug 31, 2023
817c36d
CHANGELOG.md
tbrent Aug 31, 2023
9587d28
compile
tbrent Aug 31, 2023
ecc62f3
Update docs for 3.0.0 (#915)
tbrent Sep 1, 2023
b31005b
Upg checker 3.0 (#909)
julianmrodri Sep 1, 2023
5d04fbb
price(): fix possible overflow threat
tbrent Sep 1, 2023
3a198ee
Additional checks and logging (#929)
julianmrodri Sep 1, 2023
18f3b9d
enforce UNPRICED if high price overflows
tbrent Sep 1, 2023
999c7e3
add oracle helpers for testing decay/precise prices
tbrent Sep 1, 2023
53aeffd
decrease testing oracle timeout
tbrent Sep 1, 2023
6611712
Merge branch '3.0.0-rc6' into 3.1.0-rc1
pmckelvy1 Sep 1, 2023
5289955
Asset.test.ts
tbrent Sep 1, 2023
acc6722
Collateral.test.ts
tbrent Sep 1, 2023
e5ffdaf
Asset.test.ts
tbrent Sep 1, 2023
4c80697
test/integration/AssetPlugins.test.ts
tbrent Sep 1, 2023
4b1fcf7
cap maxTradeSell using low price, not high
tbrent Sep 1, 2023
4641d0f
EasyAuction.test.ts
tbrent Sep 1, 2023
1e5e647
test/plugins/individual-collateral/**/*.test.ts
tbrent Sep 2, 2023
9745ed3
Merge branch '3.1.0-rc1' of github.com:reserve-protocol/protocol into…
tbrent Sep 2, 2023
53f24f7
fix AssetPlugins integration tests
tbrent Sep 2, 2023
7a1b16f
Revenues.test.ts
tbrent Sep 2, 2023
f720f27
Recollateralization.test.ts
tbrent Sep 2, 2023
1deef71
CTokenFiatCollateral.test.ts
tbrent Sep 2, 2023
8cd6317
ComplexBasket.test.ts
tbrent Sep 2, 2023
dd69679
Facade.test.ts
tbrent Sep 2, 2023
722fea6
Main.test.ts
tbrent Sep 2, 2023
843a9c6
fix plugin tests.
pmckelvy1 Sep 3, 2023
86aa66b
fix final failing tests
tbrent Sep 5, 2023
b7c9581
advance oracles to prevent timeouts (#933)
tbrent Sep 11, 2023
632fe66
merge 3.0.0 in
tbrent Oct 2, 2023
0f2d605
Merge branch 'master' into 3.1.0
tbrent Oct 2, 2023
04e4e5a
cleanup
tbrent Oct 2, 2023
4106b1a
more cleanup
tbrent Oct 2, 2023
7262b6c
more cleanup
tbrent Oct 3, 2023
7de7885
fix broken tests
tbrent Oct 3, 2023
14a46ae
gas snapshots
tbrent Oct 3, 2023
1adc381
remove some bad merge kruft
tbrent Oct 3, 2023
9a67530
comments and cosmetics
tbrent Oct 3, 2023
a9043a8
Merge branch 'master' into 3.1.0
tbrent Oct 6, 2023
6a8a2bf
Trust M-01 & M-02: RevenueTrader.settleTrade() (#966)
julianmrodri Oct 9, 2023
ae598c6
Trust M-11: Fix storage slots (#968)
julianmrodri Oct 9, 2023
ce38d3b
Revert "Trust M-01 & M-02: RevenueTrader.settleTrade() (#966)"
julianmrodri Oct 9, 2023
ef0a1c3
Trust M-01 & M-02: RevenueTrader.settleTrade() (#969)
julianmrodri Oct 12, 2023
535dbc3
TRUST M-06: Keep buffer when minting rtoken revenue (#972)
julianmrodri Oct 16, 2023
ab79276
TRUST Recommendation 1: reward and underlying checks in RewardERC20 w…
julianmrodri Oct 16, 2023
2de6b0d
fix lint in Revenue traders
julianmrodri Oct 17, 2023
29c0f4c
TRUST QA-2: DefaultThreshold check for Non-Self referential (#980)
julianmrodri Oct 17, 2023
a007c47
Trust M-07: RTokenAsset.refresh() (#964)
tbrent Oct 18, 2023
de352e1
TRUST L-7: Restriction on reportViolation (#981)
julianmrodri Oct 19, 2023
fcade85
Trst-M-11 (#979)
tbrent Oct 19, 2023
35b063c
TRUST M-4: Call reward accounting functions (#984)
julianmrodri Oct 20, 2023
b23cf5c
Merge branch 'master' into 3.1.0
tbrent Oct 20, 2023
124e401
gas snapshots
tbrent Oct 20, 2023
6fccc54
TRUST QA-4: Smoother exposedRefPrice in case of default (#987)
julianmrodri Oct 23, 2023
c1e9f04
Trst m 14 (#982)
tbrent Oct 24, 2023
6bc0b02
TRUST QA-3: Set correct version (#985)
julianmrodri Oct 24, 2023
8d96002
TRUST QA-5/10/11: Optimizations on BasketHandler (#986)
julianmrodri Oct 24, 2023
c20ea91
TRUST QA-6/7: Optimizations in Distributor (#988)
julianmrodri Oct 24, 2023
5aa2d4e
gas snapshots
tbrent Oct 25, 2023
a7f76a7
TRUST QA-21: minimum voting delay (#990)
julianmrodri Oct 25, 2023
ca53604
add buffer for decimals in shares calculations
julianmrodri Oct 26, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- run: yarn devchain &
env:
MAINNET_RPC_URL: https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161
FORK_BLOCK: 18329921
FORK_NETWORK: mainnet
- run: yarn deploy:run --network localhost
env:
Expand Down
40 changes: 33 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

# 3.1.0 - Unreleased

### Upgrade Steps -- Required

Upgrade all core contracts and _all_ assets. ERC20s do not need to be upgraded. Use `Deployer.deployRTokenAsset()` to create a new `RTokenAsset` instance. This asset should be swapped too.

Then, call `Broker.cacheComponents()`.

### Core Protocol Contracts

- `BackingManager`
- Replace use of `lotPrice()` with `price()`
- `BasketHandler`
- Remove `lotPrice()`
- `Broker` [+1 slot]
- Disallow starting dutch trades with non-RTokenAsset assets when `lastSave() != block.timestamp`
- `Furnace`
- Allow melting while frozen

## Plugins

### Assets

- Remove `lotPrice()`
- Alter `price().high` to decay upwards to 3x over the price timeout

# 3.0.1

### Upgrade steps
Expand All @@ -8,6 +34,8 @@ Update `BackingManager`, both `RevenueTraders` (rTokenTrader/rsrTrader), and cal

# 3.0.0

Bump solidity version to 0.8.19

### Upgrade Steps

#### Required Steps
Expand Down Expand Up @@ -38,9 +66,7 @@ It is acceptable to leave these function calls out of the initial upgrade tx and
### Core Protocol Contracts

- `AssetRegistry` [+1 slot]
Summary: StRSR contract need to know when refresh() was last called
- # Add last refresh timestamp tracking and expose via `lastRefresh()` getter
Summary: Other component contracts need to know when refresh() was last called
Summary: Other component contracts need to know when refresh() was last called
- Add `lastRefresh()` timestamp getter
- Add `size()` getter for number of registered assets
- Require asset is SOUND on registration
Expand Down Expand Up @@ -180,10 +206,10 @@ Remove `FacadeMonitor` - now redundant with `nextRecollateralizationAuction()` a
- `FacadeRead`
Summary: Add new data summary views frontends may be interested in

- Remove `basketNonce` from `redeem(.., uint48 basketNonce)`
- Add `redeemCustom(.., uint48[] memory basketNonces, uint192[] memory portions)` callstatic to simulate multi-basket redemptions
- Remove `traderBalances(..)`
- Add `balancesAcrossAllTraders(IBackingManager) returns (IERC20[] memory erc20s, uint256[] memory balances, uint256[] memory balancesNeededByBackingManager)`
- Remove `basketNonce` from `redeem(.., uint48 basketNonce)`
- Add `redeemCustom(.., uint48[] memory basketNonces, uint192[] memory portions)` callstatic to simulate multi-basket redemptions
- Remove `traderBalances(..)`
- Add `balancesAcrossAllTraders(IBackingManager) returns (IERC20[] memory erc20s, uint256[] memory balances, uint256[] memory balancesNeededByBackingManager)`

- `FacadeWrite`
Summary: More expressive and fine-grained control over the set of pausers and freezers
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ For a much more detailed explanation of the economic design, including an hour-l
- [Testing with Echidna](https://github.com/reserve-protocol/protocol/blob/master/docs/using-echidna.md): Notes so far on setup and usage of Echidna (which is decidedly an integration-in-progress!)
- [Deployment](https://github.com/reserve-protocol/protocol/blob/master/docs/deployment.md): How to do test deployments in our environment.
- [System Design](https://github.com/reserve-protocol/protocol/blob/master/docs/system-design.md): The overall architecture of our system, and some detailed descriptions about what our protocol is _intended_ to do.
- [Pause and Freeze States](https://github.com/reserve-protocol/protocol/blob/master/docs/pause-freeze-states.md): An overview of which protocol functions are halted in the paused and frozen states.
- [Deployment Variables](https://github.com/reserve-protocol/protocol/blob/master/docs/deployment-variables.md) A detailed description of the governance variables of the protocol.
- [Our Solidity Style](https://github.com/reserve-protocol/protocol/blob/master/docs/solidity-style.md): Common practices, details, and conventions relevant to reading and writing our Solidity source code, estpecially where those go beyond standard practice.
- [Writing Collateral Plugins](https://github.com/reserve-protocol/protocol/blob/master/docs/collateral.md): An overview of how to develop collateral plugins and the concepts / questions involved.
Expand Down
2 changes: 1 addition & 1 deletion common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ export const MAX_THROTTLE_PCT_RATE = BigNumber.from(10).pow(18)
export const GNOSIS_MAX_TOKENS = BigNumber.from(7).mul(BigNumber.from(10).pow(28))

// Timestamps
export const MAX_ORACLE_TIMEOUT = BigNumber.from(2).pow(48).sub(1)
export const MAX_ORACLE_TIMEOUT = BigNumber.from(2).pow(48).sub(1).sub(300)
export const MAX_TRADING_DELAY = 31536000 // 1 year
export const MIN_WARMUP_PERIOD = 60 // 1 minute
export const MAX_WARMUP_PERIOD = 31536000 // 1 year
Expand Down
6 changes: 3 additions & 3 deletions contracts/facade/FacadeAct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ contract FacadeAct is IFacadeAct, Multicall {
}

surpluses[i] = erc20s[i].balanceOf(address(revenueTrader));
(uint192 lotLow, ) = reg.assets[i].lotPrice(); // {UoA/tok}
if (lotLow == 0) continue;
(uint192 low, ) = reg.assets[i].price(); // {UoA/tok}
if (low == 0) continue;

// {qTok} = {UoA} / {UoA/tok}
minTradeAmounts[i] = minTradeVolume.safeDiv(lotLow, FLOOR).shiftl_toUint(
minTradeAmounts[i] = minTradeVolume.safeDiv(low, FLOOR).shiftl_toUint(
int8(reg.assets[i].erc20Decimals())
);

Expand Down
6 changes: 1 addition & 5 deletions contracts/facade/FacadeRead.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ contract FacadeRead is IFacadeRead {

// Poke Main
main.assetRegistry().refresh();
main.furnace().melt();

// {BU}
BasketRange memory basketsHeld = main.basketHandler().basketsHeldBy(account);
Expand Down Expand Up @@ -74,7 +73,6 @@ contract FacadeRead is IFacadeRead {

// Poke Main
reg.refresh();
main.furnace().melt();

// Compute # of baskets to create `amount` qRTok
uint192 baskets = (rTok.totalSupply() > 0) // {BU}
Expand Down Expand Up @@ -120,7 +118,6 @@ contract FacadeRead is IFacadeRead {

// Poke Main
main.assetRegistry().refresh();
main.furnace().melt();

uint256 supply = rTok.totalSupply();

Expand Down Expand Up @@ -202,7 +199,7 @@ contract FacadeRead is IFacadeRead {
IBasketHandler basketHandler = rToken.main().basketHandler();

// solhint-disable-next-line no-empty-blocks
try rToken.main().furnace().melt() {} catch {}
try rToken.main().furnace().melt() {} catch {} // <3.1.0 RTokens may revert while frozen

(erc20s, deposits) = basketHandler.quote(FIX_ONE, CEIL);

Expand Down Expand Up @@ -241,7 +238,6 @@ contract FacadeRead is IFacadeRead {
{
IMain main = rToken.main();
main.assetRegistry().refresh();
main.furnace().melt();

erc20s = main.assetRegistry().erc20s();
balances = new uint256[](erc20s.length);
Expand Down
4 changes: 3 additions & 1 deletion contracts/facade/FacadeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract FacadeTest is IFacadeTest {
erc20s
);
try main.rsrTrader().manageTokens(rsrERC20s, rsrKinds) {} catch {}
try main.rsrTrader().distributeTokenToBuy() {} catch {}

// Start exact RToken auctions
(IERC20[] memory rTokenERC20s, TradeKind[] memory rTokenKinds) = traderERC20s(
Expand All @@ -74,6 +75,7 @@ contract FacadeTest is IFacadeTest {
erc20s
);
try main.rTokenTrader().manageTokens(rTokenERC20s, rTokenKinds) {} catch {}
try main.rTokenTrader().distributeTokenToBuy() {} catch {}
// solhint-enable no-empty-blocks
}

Expand All @@ -97,7 +99,6 @@ contract FacadeTest is IFacadeTest {

// Poke Main
reg.refresh();
main.furnace().melt();

address backingManager = address(main.backingManager());
IERC20 rsr = main.rsr();
Expand Down Expand Up @@ -134,6 +135,7 @@ contract FacadeTest is IFacadeTest {
IERC20[] memory traderERC20sAll = new IERC20[](erc20sAll.length);
for (uint256 i = 0; i < erc20sAll.length; ++i) {
if (
erc20sAll[i] != trader.tokenToBuy() &&
address(trader.trades(erc20sAll[i])) == address(0) &&
erc20sAll[i].balanceOf(address(trader)) > 1
) {
Expand Down
15 changes: 8 additions & 7 deletions contracts/interfaces/IAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ interface IAsset is IRewardable {
function refresh() external;

/// Should not revert
/// low should be nonzero if the asset could be worth selling
/// @return low {UoA/tok} The lower end of the price estimate
/// @return high {UoA/tok} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);

/// Should not revert
/// lotLow should be nonzero when the asset might be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);

/// @return {tok} The balance of the ERC20 in whole tokens
function bal(address account) external view returns (uint192);

Expand Down Expand Up @@ -67,8 +62,14 @@ interface TestIAsset is IAsset {
/// @return {s} Seconds that an oracle value is considered valid
function oracleTimeout() external view returns (uint48);

/// @return {s} Seconds that the lotPrice should decay over, after stale price
/// @return {s} Seconds that the price().low should decay over, after stale price
function priceTimeout() external view returns (uint48);

/// @return {UoA/tok} The last saved low price
function savedLowPrice() external view returns (uint192);

/// @return {UoA/tok} The last saved high price
function savedHighPrice() external view returns (uint192);
}

/// CollateralStatus must obey a linear ordering. That is:
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface IAssetRegistry is IComponent {
function init(IMain main_, IAsset[] memory assets_) external;

/// Fully refresh all asset state
/// @custom:interaction
/// @custom:refresher
function refresh() external;

/// Register `asset`
Expand Down
7 changes: 1 addition & 6 deletions contracts/interfaces/IBasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,11 @@ interface IBasketHandler is IComponent {
function basketsHeldBy(address account) external view returns (BasketRange memory);

/// Should not revert
/// low should be nonzero when BUs are worth selling
/// @return low {UoA/BU} The lower end of the price estimate
/// @return high {UoA/BU} The upper end of the price estimate
function price() external view returns (uint192 low, uint192 high);

/// Should not revert
/// lotLow should be nonzero if a BU could be worth selling
/// @return lotLow {UoA/tok} The lower end of the lot price estimate
/// @return lotHigh {UoA/tok} The upper end of the lot price estimate
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh);

/// @return timestamp The timestamp at which the basket was last set
function timestamp() external view returns (uint48);

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IBroker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum TradeKind {
BATCH_AUCTION
}

/// Cache of all (lot) prices for a pair to prevent re-lookup
/// Cache of all prices for a pair to prevent re-lookup
struct TradePrices {
uint192 sellLow; // {UoA/sellTok} can be 0
uint192 sellHigh; // {UoA/sellTok} should not be 0
Expand Down
2 changes: 1 addition & 1 deletion contracts/mixins/Versioned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.19;
import "../interfaces/IVersioned.sol";

// This value should be updated on each release
string constant VERSION = "3.0.1";
string constant VERSION = "3.1.0";

/**
* @title Versioned
Expand Down
14 changes: 8 additions & 6 deletions contracts/p0/BackingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ contract BackingManagerP0 is TradingP0, IBackingManager {
/// @custom:interaction
function rebalance(TradeKind kind) external notTradingPausedOrFrozen {
main.assetRegistry().refresh();
main.furnace().melt();

// DoS prevention: unless caller is self, require 1 empty block between like-kind auctions
require(
Expand Down Expand Up @@ -149,7 +148,6 @@ contract BackingManagerP0 is TradingP0, IBackingManager {
require(ArrayLib.allUnique(erc20s), "duplicate tokens");

main.assetRegistry().refresh();
main.furnace().melt();

require(tradesOpen == 0, "trade open");
require(main.basketHandler().isReady(), "basket not ready");
Expand All @@ -166,16 +164,20 @@ contract BackingManagerP0 is TradingP0, IBackingManager {
uint256 rsrBal = main.rsr().balanceOf(address(this));
if (rsrBal > 0) {
main.rsr().safeTransfer(address(main.stRSR()), rsrBal);
main.stRSR().payoutRewards();
}

// Mint revenue RToken
// Keep backingBuffer worth of collateral before recognizing revenue
uint192 needed = main.rToken().basketsNeeded().mul(FIX_ONE.plus(backingBuffer)); // {BU}
if (basketsHeld.bottom.gt(needed)) {
main.rToken().mint(basketsHeld.bottom.minus(needed));
needed = main.rToken().basketsNeeded().mul(FIX_ONE.plus(backingBuffer)); // keep buffer
{
uint192 baskets = (basketsHeld.bottom.div(FIX_ONE + backingBuffer));
if (baskets > main.rToken().basketsNeeded()) {
main.rToken().mint(baskets - main.rToken().basketsNeeded());
}
}

uint192 needed = main.rToken().basketsNeeded().mul(FIX_ONE.plus(backingBuffer)); // {BU}

// Handout excess assets above what is needed, including any newly minted RToken
RevenueTotals memory totals = main.distributor().totals();
for (uint256 i = 0; i < erc20s.length; i++) {
Expand Down
25 changes: 5 additions & 20 deletions contracts/p0/BasketHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {
}
emit BasketSet(nonce, basket.erc20s, refAmts, true);
disabled = true;

trackStatus();
}

/// Switch the basket, only callable directly by governance or after a default
Expand All @@ -199,7 +201,7 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {

require(
main.hasRole(OWNER, _msgSender()) ||
(status() == CollateralStatus.DISABLED && !main.tradingPausedOrFrozen()),
(lastStatus == CollateralStatus.DISABLED && !main.tradingPausedOrFrozen()),
"basket unrefreshable"
);
_switchBasket();
Expand Down Expand Up @@ -368,26 +370,11 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {
}

/// Should not revert
/// low should be nonzero when the asset might be worth selling
/// @return low {UoA/BU} The lower end of the price estimate
/// @return high {UoA/BU} The upper end of the price estimate
// returns sum(quantity(erc20) * price(erc20) for erc20 in basket.erc20s)
function price() external view returns (uint192 low, uint192 high) {
return _price(false);
}

/// Should not revert
/// lowLow should be nonzero when the asset might be worth selling
/// @return lotLow {UoA/BU} The lower end of the lot price estimate
/// @return lotHigh {UoA/BU} The upper end of the lot price estimate
// returns sum(quantity(erc20) * lotPrice(erc20) for erc20 in basket.erc20s)
function lotPrice() external view returns (uint192 lotLow, uint192 lotHigh) {
return _price(true);
}

/// Returns the price of a BU, using the lot prices if `useLotPrice` is true
/// @return low {UoA/BU} The lower end of the lot price estimate
/// @return high {UoA/BU} The upper end of the lot price estimate
function _price(bool useLotPrice) internal view returns (uint192 low, uint192 high) {
IAssetRegistry reg = main.assetRegistry();

uint256 low256;
Expand All @@ -397,9 +384,7 @@ contract BasketHandlerP0 is ComponentP0, IBasketHandler {
uint192 qty = quantity(basket.erc20s[i]);
if (qty == 0) continue;

(uint192 lowP, uint192 highP) = useLotPrice
? reg.toAsset(basket.erc20s[i]).lotPrice()
: reg.toAsset(basket.erc20s[i]).price();
(uint192 lowP, uint192 highP) = reg.toAsset(basket.erc20s[i]).price();

low256 += qty.safeMul(lowP, RoundingMode.FLOOR);

Expand Down
13 changes: 12 additions & 1 deletion contracts/p0/Broker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract BrokerP0 is ComponentP0, IBroker {

/// Disable the broker until re-enabled by governance
/// @custom:protected
function reportViolation() external notTradingPausedOrFrozen {
function reportViolation() external {
require(trades[_msgSender()], "unrecognized trade contract");
ITrade trade = ITrade(_msgSender());
TradeKind kind = trade.KIND();
Expand Down Expand Up @@ -239,6 +239,11 @@ contract BrokerP0 is ComponentP0, IBroker {
"dutch auctions disabled for token pair"
);
require(dutchAuctionLength > 0, "dutch auctions not enabled");
require(
priceNotDecayed(req.sell) && priceNotDecayed(req.buy),
"dutch auctions require live prices"
);

DutchTrade trade = DutchTrade(Clones.clone(address(dutchTradeImplementation)));
trades[address(trade)] = true;

Expand All @@ -251,4 +256,10 @@ contract BrokerP0 is ComponentP0, IBroker {
trade.init(caller, req.sell, req.buy, req.sellAmount, dutchAuctionLength, prices);
return trade;
}

/// @return true iff the price is not decayed, or it's the RTokenAsset
function priceNotDecayed(IAsset asset) private view returns (bool) {
return
asset.lastSave() == block.timestamp || address(asset.erc20()) == address(main.rToken());
}
}
Loading
Loading