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

BIP-34: Sunrise Improvements #337

Merged
merged 297 commits into from May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
297 commits
Select commit Hold shift + click to select a range
fb4cf2b
Add min base reward
chaikitty Oct 22, 2022
5746ad5
Remove describe.only
chaikitty Oct 22, 2022
4a9a4f3
swapped chainlink oracle <> UniswapV3 Oracle, added mocks
Oct 23, 2022
4de447b
removed logs
Oct 23, 2022
79f289d
comments
Oct 23, 2022
d333184
sunrise() and sunriseWithMode()
chaikitty Oct 23, 2022
a00d024
quick fixes
Oct 23, 2022
135e727
Merge pull request #134 from chaikitty/sun-incentive
Brean0 Oct 24, 2022
3e12cd3
fix mock on js
publiuss Oct 24, 2022
3324bc4
added precision to weather tests
Oct 24, 2022
6d968d3
weather js test fix
Oct 24, 2022
63827d2
Remove merge conflict markers and disable some tests
chaikitty Oct 25, 2022
056c366
final fixes
Oct 25, 2022
5d9ba6c
Remove chainlink from uniswap impersonate
chaikitty Oct 25, 2022
91d976f
fixed weather tests js
Oct 25, 2022
e9b3f56
quick remove sun test
Oct 25, 2022
b1ac8e7
Merge branch 'bip-30' of https://github.com/BeanstalkFarms/Beanstalk …
Oct 25, 2022
d8c5993
clean sm128 lib
Oct 25, 2022
8e22449
changed weather struct for gas, sunriseWithMode() -> gm()
Oct 25, 2022
d24fd24
Lets try this again...
Oct 25, 2022
9d7b139
??
Oct 25, 2022
7faaf12
Add address parameter to gm()
chaikitty Oct 29, 2022
56800f2
Rename to auctionMath
chaikitty Oct 29, 2022
35ca200
added oracle test
Oct 30, 2022
8346930
Modify incentive test to use uniswap ether price
chaikitty Oct 30, 2022
1237fe0
daily fix
Nov 3, 2022
d924dcd
Revert "daily fix"
Nov 3, 2022
9507b33
Merge branch 'master' into foundry
silochad Nov 20, 2022
79b0b2a
Merge branch 'bip-30' of https://github.com/BeanstalkFarms/Beanstalk …
Nov 29, 2022
c7535c9
Merge pull request #96 from BeanstalkFarms/foundry
silochad Dec 2, 2022
0061aaa
rename farm to beanstalk
silochad Dec 2, 2022
7008d17
update remappings, replace some @beanstalk with @contracts
silochad Dec 2, 2022
2a36282
replace: ../farm with ../beanstalk
silochad Dec 2, 2022
867b109
move facets: Silo, Convert, BDV, Whitelist
silochad Dec 2, 2022
2ba540a
fix imports
silochad Dec 2, 2022
a3b0c12
use hardhat-preprocessor for remappings
silochad Dec 2, 2022
98d6b17
simplify remappings, fix imports, map `~` to `contracts`
silochad Dec 2, 2022
e7d90e0
remove over-constrained config vals from foundry.toml, fix imports
silochad Dec 2, 2022
a22f4db
📝 natspec on all SiloFacet functions
Dec 2, 2022
1431ab0
Merge pull request #156 from BeanstalkFarms/doc/module-silo
silochad Dec 3, 2022
61164ca
move facets: Field, Fundraiser
silochad Dec 3, 2022
63caa99
update imports
silochad Dec 3, 2022
5f9d65c
Merge pull request #157 from BeanstalkFarms/doc/module-field
silochad Dec 3, 2022
f8b7061
move facets: DiamondCut, DiamondLoupe, Ownership, Pause
silochad Dec 3, 2022
485fa6e
update imports
silochad Dec 3, 2022
dad549b
Merge pull request #158 from BeanstalkFarms/doc/module-diamond
silochad Dec 3, 2022
ddb68d3
move facet: MarketplaceFacet, Listing, Order, PodTransfer
silochad Dec 3, 2022
ca0b262
update imports
silochad Dec 3, 2022
b8adc6b
Merge pull request #159 from BeanstalkFarms/doc/module-market
silochad Dec 3, 2022
110c8e1
move facets: Fertilizer, Unripe
silochad Dec 3, 2022
eef16dc
update imports
silochad Dec 3, 2022
f06f136
Merge pull request #160 from BeanstalkFarms/doc/module-barn
silochad Dec 3, 2022
edcb38d
move facet: SeasonFacet, Oracle, Sun, Weather
silochad Dec 3, 2022
029d388
update imports
silochad Dec 3, 2022
3269243
Merge pull request #161 from BeanstalkFarms/doc/module-sun
silochad Dec 3, 2022
8289d63
move facets: Curve, Farm, Token
silochad Dec 3, 2022
aac9f85
update imports
silochad Dec 3, 2022
d3aa3ef
Merge pull request #162 from BeanstalkFarms/doc/module-farm
silochad Dec 3, 2022
db511e8
move contract: BeanstalkPrice
silochad Dec 3, 2022
b067bd8
move contract: Fertilizer & components
silochad Dec 3, 2022
9314186
update Fertilizer imports
silochad Dec 3, 2022
304c0a6
remove samples; move this to docs later
silochad Dec 3, 2022
d54349c
cleanup imports
silochad Dec 3, 2022
ebbf7dd
Merge pull request #165 from BeanstalkFarms/doc/module-refactor
silochad Dec 5, 2022
1454d41
🔒 halborn audit bug fixes + removed unneeded constants
Dec 7, 2022
1bed41a
Merge branch 'bip-30' into doc/module-refactor
silochad Dec 12, 2022
ffbf4fd
update submodules
silochad Dec 12, 2022
459e449
remove Deploy leftover from merge; fix imports
silochad Dec 12, 2022
1c26f1e
Merge pull request #173 from BeanstalkFarms/doc/module-refactor
Brean0 Dec 12, 2022
71ef876
🐞 fixed compile issue, tests, impersonate + marketplace + root
Dec 13, 2022
271b697
🐞 re-added mock uniswap contracts in foundry tests
Dec 13, 2022
d67bbdb
♻️ various fixes from code review, refactored if ladder -> binary se…
John-Smith-loves-beanstalk Jan 3, 2023
57a3e5c
added initbip33
Brean0 Jan 5, 2023
c949a60
removed test import from LibDibbler
Brean0 Jan 5, 2023
9058968
remove unused legacy BASE_ADVANCE_INCENTIVE
silochad Jan 22, 2023
9c4aff7
refactor sowNoSoil to remove duplicate abovePeg check
silochad Jan 24, 2023
30840b0
dibbler: add comments, rename constant to TEMPERATURE_SCALE
silochad Jan 24, 2023
b24c9bf
dibbler: rename `auctionMath` -> `scaleYield`
silochad Jan 24, 2023
d69c17d
dibbler: rename `morningAuction` -> `yield`
silochad Jan 24, 2023
edbc9ec
wip: refactor handoff
silochad Jan 24, 2023
2dc521e
refactor LibDibbler, generalized tests
Brean0 Jan 25, 2023
323df6e
added more tests, refactored LibDibbler for gas optimizations
Brean0 Jan 26, 2023
8a43d0b
added helper functions when scaling up or down soil
Brean0 Jan 27, 2023
38833fd
reduced gas overhead costs, added forge helper lib
Brean0 Jan 30, 2023
3c777bd
dependencies
Brean0 Jan 30, 2023
fbe740e
removed min reward
Brean0 Jan 30, 2023
2acdbbd
doc(field): natspec first pass
silochad Jan 30, 2023
a1c3b95
field(!): rename precision factor to YIELD_PRECISION, replace constants
silochad Jan 30, 2023
1f8a1e6
field(!): rename dibbler `yield` to `morningYield`, downcast external…
silochad Jan 30, 2023
fa2c81a
field(!): rename `amount` -> `beans`, `_yield` -> `morningYield`
silochad Jan 30, 2023
1e85551
field(!): rename `plotId` -> `index`
silochad Jan 30, 2023
7a1ba26
field(!): underscore internal funcs
silochad Jan 30, 2023
21c8adc
field(!): make scale up / down symmetric, use constant, reorder params
silochad Jan 30, 2023
aa6f3b8
fundraiser(!): add decimals check, update docstrings
silochad Jan 31, 2023
1abfba2
field: update comments
silochad Jan 31, 2023
3f72d47
field(!): spacing
silochad Jan 31, 2023
c030a1f
refactor(!): `s.w.yield` -> `s.w.t`
silochad Jan 31, 2023
97376ab
AppStorage: change `yield` -> `t`
silochad Jan 31, 2023
9ef7c00
refactor: `morningYield` -> `morningTemperature`
silochad Jan 31, 2023
4d0d413
refactor: `minYield` -> `minTemperature`
silochad Jan 31, 2023
ebd378e
field(!): remove all references to yield besides legacy function
silochad Jan 31, 2023
f223fb7
refactor(!): replace `weather.yield` with `weather.t`
silochad Jan 31, 2023
e4e7eae
refactor(!): switch to `TEMPERATURE_PRECISION`
silochad Jan 31, 2023
8b01e2d
refactor(!) replace `maxYield` with `maxTemperature`
silochad Jan 31, 2023
2634516
dibbler(!): rename `scaleYield` -> `_scaleTemperature`
silochad Jan 31, 2023
075e894
dibbler(!): underscore prefix private vars, finish yield removal
silochad Jan 31, 2023
6c69a7d
weather(!): remove `maxYield`
silochad Jan 31, 2023
3b733a6
tests: `setYieldE` -> `setMaxTempE`
silochad Jan 31, 2023
0534daa
fix maxYield in tests
silochad Jan 31, 2023
ff80234
Updated tests, fix incorrect soil issuance
Brean0 Feb 1, 2023
12ad788
changed var morningTemperature -> _morningTemperature
Brean0 Feb 1, 2023
c1eb30f
field(!): rename `peas` -> `remainingPods`, add `maxTemperature`
silochad Feb 1, 2023
0499902
fix: remainingPods in tests
silochad Feb 1, 2023
7777dc8
fix: change references to peas in tests
silochad Feb 1, 2023
b913b38
sun(!): `setSoilAndPeasAbovePeg` -> `setSoilAbovePeg`
silochad Feb 1, 2023
c366518
doc: SeasonFacet chain
silochad Feb 2, 2023
1abe415
Weather(!): add brackets, comments
silochad Feb 2, 2023
19126c6
doc: many updates
silochad Feb 2, 2023
2114fa1
Oracle(!): remove unused MetapoolOracle event
silochad Feb 2, 2023
4643826
AppStorage(!): update Storage comments
silochad Feb 2, 2023
dbb2a3f
AppStorage(!): comments
silochad Feb 2, 2023
78be27d
SeasonFacet(!): replace `MAXBLOCKSLATE` with `MAX_BLOCKS_LATE`
silochad Feb 2, 2023
e4b5cff
SeasonFacet(!): rename `gm` -> `sunriseTo`
silochad Feb 2, 2023
3688f08
doc: tweak imports
silochad Feb 2, 2023
b959e81
fix: sunrise tests
silochad Feb 2, 2023
a639395
doc: library comments
silochad Feb 2, 2023
de0a34f
refactor(!): replace `nextSowTime` -> `thisSowTime`
silochad Feb 2, 2023
714380c
refactor(!): replace `nextSowTime` -> `thisSowTime` (#314)
silochad Feb 6, 2023
f4b783f
Refactor: `yield` -> `temperature` (#309)
silochad Feb 6, 2023
41e1d05
Merge branch 'sunrise-refactor-dibbler' into doc/facet/sun
silochad Feb 6, 2023
d4b5202
AppStorage(!): move all comments to natspec, add slot viz
silochad Feb 6, 2023
bf6bc55
doc: add sun comment, remove extra return memory slot
silochad Feb 6, 2023
43e490c
doc: tweaks
silochad Feb 6, 2023
12fe338
doc: reorganize curve functions & docs
silochad Feb 7, 2023
00c62d9
remove: LibBeanLUSDConvert
silochad Feb 7, 2023
fa58153
remove: LibPlainCurveConvert
silochad Feb 7, 2023
6b3ef6b
remove: LibBeanLUSDCurve
silochad Feb 7, 2023
82c71dd
doc: update comments
silochad Feb 7, 2023
c4ef829
Updated Table
Brean0 Feb 2, 2023
ea46d75
gas optimizations
Brean0 Feb 2, 2023
9babc15
doc: update comments
silochad Feb 7, 2023
40220b3
refactor(!): move MAX_BLOCKS_LATE constraint to LibIncentive
silochad Feb 7, 2023
a00b89d
fix: add else statements to binary tree, tweak comments
silochad Feb 8, 2023
2f628ac
doc: update comments
silochad Feb 8, 2023
92fa212
refactor(!): use gas efficient return values in FieldFacet & LibDibbler
silochad Feb 8, 2023
2209004
Converted fracExp to use a binary tree for gas efficiency
Brean0 Feb 8, 2023
42b6e40
hardhat
Brean0 Feb 8, 2023
f6fe77a
doc: comment cleanup
silochad Feb 8, 2023
ed27a26
refactor(!): remove unused memory var, fix sol warning with revert
silochad Feb 8, 2023
8fb45ca
refactor(!): use gas efficient return
silochad Feb 8, 2023
d97f260
Oracle(!): use gas efficient return values, finalize docs
silochad Feb 8, 2023
7f0a3cf
doc: reorder LibCurveConvert, start comments
silochad Feb 8, 2023
34202b5
refactor(!): replace `getBeansAtPeg` with `_getBeansAtPeg`
silochad Feb 8, 2023
4716f9b
refactor(!): remove `_` from `_curveRemoveLPAndBuyToPeg`
silochad Feb 8, 2023
aba253b
refactor(!): remove `_` from `_curveSellToPegAndAddLiquidity`
silochad Feb 8, 2023
28bef34
refactor(!): add `_` to `_toPegWithFee`
silochad Feb 8, 2023
9aa1ed1
refactor(!): add `_` to `_calcLPTokenAmount`
silochad Feb 8, 2023
4205aee
doc: update library comments
silochad Feb 8, 2023
f4dd5c6
Documentation: Sun Module + Libraries (#311)
silochad Feb 8, 2023
31807a8
Update protocol/contracts/libraries/LibIncentive.sol
Brean0 Feb 8, 2023
dd3d88d
Update protocol/contracts/libraries/LibIncentive.sol
Brean0 Feb 8, 2023
832c22e
Update protocol/contracts/libraries/LibIncentive.sol
Brean0 Feb 8, 2023
cd5429e
added description, >=
Brean0 Feb 8, 2023
0cb1b99
changed PERIOD to 30 mins (1800)
Brean0 Feb 8, 2023
53b2de4
conform to natspec
Brean0 Feb 8, 2023
3028591
Merge branch 'sunrise-refactor-dibbler' into sun-libs
silochad Feb 8, 2023
8967ecf
Sun module library updates (#332)
silochad Feb 8, 2023
600300c
constant(!): FERTILIZER_DENOMINATOR
silochad Feb 9, 2023
2aa1c07
constant(!): HARVEST_DENOMINATOR
silochad Feb 9, 2023
d792aea
constant(!): SOIL_COEFFICIENT_HIGH and LOW, BEAN, STALK_PER_BEAN, etc.
silochad Feb 9, 2023
fdaa66f
constant(!): SOW_TIME_STEADY
silochad Feb 9, 2023
988bba4
constant(!): add DecimalExtended lib, migrate POD_RATE_UPPER_BOUND
silochad Feb 9, 2023
af30a49
constant(!): migrate OPTIMAL_POD_RATE, POD_RATE_LOWER_BOUND
silochad Feb 9, 2023
a2604a8
constant(!): move DELTA_POD_DEMAND_...
silochad Feb 9, 2023
e6649ca
constant(!): rename to POD_RATE_OPTIMAL
silochad Feb 9, 2023
3d0d624
constant(!): use CURVE_BEAN_METAPOOL
silochad Feb 9, 2023
3dbe524
constant(!): SOP_PRECISION
silochad Feb 9, 2023
8ef982a
constant(!): CURVE_BEAN_METAPOOL
silochad Feb 9, 2023
b45feee
update imports
silochad Feb 9, 2023
bba0c0e
constant(!): BEAN
silochad Feb 9, 2023
99c367f
constant(!): UNRIPE_LP
silochad Feb 9, 2023
f985ccc
constant(!): UNRIPE_BEAN
silochad Feb 9, 2023
8c0f696
LibConvert: update imports
silochad Feb 9, 2023
27f48f1
LibCurveConvert: update imports
silochad Feb 9, 2023
56f0087
update imports
silochad Feb 9, 2023
9abef8c
constant(!): UNIV3_ETH_USDC_POOL
silochad Feb 9, 2023
08f27b9
constant(!): USDC, WETH
silochad Feb 9, 2023
2278cf9
update imports
silochad Feb 9, 2023
16a0e11
update imports
silochad Feb 9, 2023
25ee23e
Added differential testing for fracExp and morningAuction
Brean0 Feb 9, 2023
741140d
update imports, cleanup
silochad Feb 9, 2023
f9124e1
moved constants from C.sol to FieldFacet.sol + LibDibbler + LibIncentive
Brean0 Feb 9, 2023
1ab0f5e
Merge branch 'sunrise-refactor-constants' into fraxExpGas
silochad Feb 10, 2023
934aa34
fix merge conflicts
silochad Feb 10, 2023
21204ed
fix remappings to avoid hardhat error
Brean0 Feb 11, 2023
86c22fc
FFI test view -> pure
Brean0 Feb 11, 2023
aec5a90
refactor diff test structure
silochad Feb 11, 2023
ea9e91b
fmt: Field.t.sol
silochad Feb 11, 2023
6dd101c
Sunrise improvements: refactor constants (#335)
silochad Feb 11, 2023
0c28487
Converted fracExp to use a binary tree for gas efficiency (#331)
silochad Feb 11, 2023
f37cb42
Sunrise Improvements: refactors (#292)
silochad Feb 11, 2023
59ff43f
setup simulate script
k-xo Mar 14, 2023
070089d
write to csv
k-xo Mar 15, 2023
6b4cee7
add profit column
k-xo Mar 15, 2023
a96de57
use 3crv as signer
k-xo Mar 21, 2023
2e98209
removed scaledTemp in fraxExp
Brean0 Mar 21, 2023
8bae126
update determinereward
k-xo Mar 24, 2023
5fb35e5
update gas overhead
k-xo Mar 24, 2023
2581c92
Reset submodules
silochad Mar 27, 2023
7f22024
Merge branch 'master' into bip-sunrise-improvements
silochad Mar 28, 2023
32368b5
fix: depot imports
silochad Mar 28, 2023
7ed48cb
fix: test compilation issues
silochad Mar 28, 2023
3f9fa59
fix remaining tests
Brean0 Mar 29, 2023
a1e9ad6
removed unnecessary console.logs, cleaned test comments
Brean0 Mar 29, 2023
e4a4356
misc comment adjustments in fieldFacet/LibDibbler
Brean0 Mar 29, 2023
aa3d3e5
unnecessary import, reordered
Brean0 Mar 29, 2023
110e0d9
fix: prevent yarn hoisting dependencies from protocol dir
silochad Mar 30, 2023
ad3558e
DiamondCut json files generated from the upgradeWithNewFacets functio…
publiuss Mar 31, 2023
6f701e2
remove open zeppelin local config
publiuss Mar 31, 2023
4af0da7
Revert change in AppStorageOld is the pre-bip0 App Storage. It shoul…
publiuss Mar 31, 2023
7616fb7
Delete extra Init Hot Fix 5
publiuss Mar 31, 2023
9b1d6ac
update SiloFacet comments
publiuss Mar 31, 2023
5ceb5e4
capitalize notice comments in SiloFacet
publiuss Mar 31, 2023
d4087aa
Add overflow comment
publiuss Mar 31, 2023
a92c509
Add warning to incentivize function
publiuss Mar 31, 2023
1ffea40
minor gas efficiency in toDecimal
publiuss Mar 31, 2023
2eb9db1
Added safemath unnecsesary comment
publiuss Mar 31, 2023
bc784e4
Added Safe Cast comment
publiuss Mar 31, 2023
8347d7d
in/outAmount -> amountIn/Out + comment updates
publiuss Mar 31, 2023
e030212
add eth-gas-reporter to package.json
publiuss Mar 31, 2023
29eaae0
Lib Balance clean up
publiuss Mar 31, 2023
2ee654c
use previous balances in oracle not initalized; use max reward if poo…
publiuss Apr 4, 2023
ffaa7e6
removed unnecessary commented code
Brean0 Apr 4, 2023
f7172ab
added helper assertEq helper func
Brean0 Apr 4, 2023
b46840e
large refactoring of tests
Brean0 Apr 5, 2023
0790978
weather -> temperature when applicable, delta -> block
Brean0 Apr 5, 2023
718158f
Merge branch 'bip-sunrise-improvements' of github.com:BeanstalkFarms/…
Brean0 Apr 5, 2023
dc1c00f
Sunrise Improvements Edits (#394)
Brean0 Apr 5, 2023
5252244
field tests
Brean0 Apr 5, 2023
ec54203
better comment for auction math
Brean0 Apr 5, 2023
e3d00d7
gm
Brean0 Apr 5, 2023
445172d
removed unused tests
Brean0 Apr 5, 2023
75ef821
capitalization, fixed tests
Brean0 Apr 5, 2023
3d910d8
remove comment
Brean0 Apr 5, 2023
b0ad634
added code credits
Brean0 Apr 5, 2023
8a5670b
fix tests from merging
Brean0 Apr 5, 2023
6e52517
test
Brean0 Apr 10, 2023
71d5a57
fix marketplace tests
Brean0 Apr 25, 2023
a6e2c1c
Add automatic etherscan verification + BIP-34 deploy script
publiuss Apr 26, 2023
538b7a2
update bip-34 deploy script
publiuss Apr 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -9,14 +9,22 @@ temp
.env
archived
.vscode

# Diamond Cut Outputs
diamondCut-*.json
publiuss marked this conversation as resolved.
Show resolved Hide resolved

#Open Zeppelin Local Config
.openzeppelin/unknown-1337.json

#Editors
.idea/

# Foundry
cache/
out/
coverage_data/
protocol/remappings.txt
.gas-snapshot

# From SDK Monorepo Join:
node_modules
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
@@ -1,3 +1,9 @@
[submodule "protocol/lib/forge-std"]
path = protocol/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "protocol/lib/prb-math"]
path = protocol/lib/prb-math
url = https://github.com/paulrberg/prb-math
[submodule "protocol/lib/solmate"]
path = protocol/lib/solmate
url = https://github.com/transmissions11/solmate
149 changes: 43 additions & 106 deletions protocol/contracts/C.sol
@@ -1,6 +1,4 @@
/*
SPDX-License-Identifier: MIT
*/
// SPDX-License-Identifier: MIT

pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
Expand All @@ -12,62 +10,53 @@ import "./interfaces/IProxyAdmin.sol";
import "./libraries/Decimal.sol";

/**
* @title C
* @author Publius
* @title C holds the contracts for Beanstalk.
**/
* @notice Contains constants used throughout Beanstalk.
*/
library C {

using Decimal for Decimal.D256;
using SafeMath for uint256;

// Constants
uint256 private constant PERCENT_BASE = 1e18;
uint256 private constant PRECISION = 1e18;
//////////////////// Globals ////////////////////

uint256 internal constant PRECISION = 1e18;
uint256 private constant CHAIN_ID = 1;

/// @dev The block time for the chain in seconds.
uint256 internal constant BLOCK_LENGTH_SECONDS = 12;

// Chain
uint256 private constant CHAIN_ID = 1; // Mainnet
//////////////////// Season ////////////////////

// Season
/// @dev The length of a Season meaured in seconds.
uint256 private constant CURRENT_SEASON_PERIOD = 3600; // 1 hour
uint256 private constant BASE_ADVANCE_INCENTIVE = 25e6; // 25 beans
uint256 private constant SOP_PRECISION = 1e24;

// Sun
uint256 private constant FERTILIZER_DENOMINATOR = 3;
uint256 private constant HARVEST_DENOMINATOR = 2;
uint256 private constant SOIL_COEFFICIENT_HIGH = 0.5e18;
uint256 private constant SOIL_COEFFICIENT_LOW = 1.5e18;

// Weather
uint256 private constant POD_RATE_LOWER_BOUND = 0.05e18; // 5%
uint256 private constant OPTIMAL_POD_RATE = 0.15e18; // 15%
uint256 private constant POD_RATE_UPPER_BOUND = 0.25e18; // 25%
uint32 private constant STEADY_SOW_TIME = 60; // 1 minute

uint256 private constant DELTA_POD_DEMAND_LOWER_BOUND = 0.95e18; // 95%
uint256 private constant DELTA_POD_DEMAND_UPPER_BOUND = 1.05e18; // 105%

// Silo
uint256 private constant SEEDS_PER_BEAN = 2;
uint256 private constant STALK_PER_BEAN = 10000;
uint256 internal constant SOP_PRECISION = 1e24;

//////////////////// Silo ////////////////////

uint256 internal constant SEEDS_PER_BEAN = 2;
uint256 internal constant STALK_PER_BEAN = 10000;
uint256 private constant ROOTS_BASE = 1e12;

//////////////////// Exploit Migration ////////////////////

// Exploit
uint256 private constant UNRIPE_LP_PER_DOLLAR = 1884592; // 145_113_507_403_282 / 77_000_000
uint256 private constant ADD_LP_RATIO = 866616;
uint256 private constant INITIAL_HAIRCUT = 185564685220298701; // SET
uint256 private constant INITIAL_HAIRCUT = 185564685220298701;

//////////////////// Contracts ////////////////////

address internal constant BEAN = 0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab;
address internal constant CURVE_BEAN_METAPOOL = 0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49;

address internal constant UNRIPE_BEAN = 0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449;
address internal constant UNRIPE_LP = 0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D;

// Contracts
address private constant BEAN = 0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab;
address private constant CURVE_BEAN_METAPOOL = 0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49;
address private constant CURVE_3_POOL = 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7;
address private constant THREE_CRV = 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490;
address private constant UNRIPE_BEAN = 0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449;
address private constant UNRIPE_LP = 0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D;

address private constant FERTILIZER = 0x402c84De2Ce49aF88f5e2eF3710ff89bFED36cB6;
address private constant FERTILIZER_ADMIN = 0xfECB01359263C12Aa9eD838F878A596F0064aa6e;
address private constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;

address private constant TRI_CRYPTO = 0xc4AD29ba4B3c580e6D59105FFf484999997675Ff;
address private constant TRI_CRYPTO_POOL = 0xD51a44d3FaE010294C616388b506AcdA1bfAAE46;
Expand All @@ -76,54 +65,25 @@ library C {
address private constant UNRIPE_CURVE_BEAN_LUSD_POOL = 0xD652c40fBb3f06d6B58Cb9aa9CFF063eE63d465D;
address private constant UNRIPE_CURVE_BEAN_METAPOOL = 0x3a70DfA7d2262988064A2D051dd47521E43c9BdD;

/**
* Getters
**/
address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address internal constant UNIV3_ETH_USDC_POOL = 0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8;

// Use external contract for block.basefee as to avoid upgrading existing contracts to solidity v8
address private constant BASE_FEE_CONTRACT = 0x84292919cB64b590C0131550483707E43Ef223aC;

function getSeasonPeriod() internal pure returns (uint256) {
return CURRENT_SEASON_PERIOD;
}

function getAdvanceIncentive() internal pure returns (uint256) {
return BASE_ADVANCE_INCENTIVE;
}

function getFertilizerDenominator() internal pure returns (uint256) {
return FERTILIZER_DENOMINATOR;
}

function getHarvestDenominator() internal pure returns (uint256) {
return HARVEST_DENOMINATOR;
function getBlockLengthSeconds() internal pure returns (uint256) {
return BLOCK_LENGTH_SECONDS;
}

function getChainId() internal pure returns (uint256) {
return CHAIN_ID;
}

function getOptimalPodRate() internal pure returns (Decimal.D256 memory) {
return Decimal.ratio(OPTIMAL_POD_RATE, PERCENT_BASE);
}

function getUpperBoundPodRate() internal pure returns (Decimal.D256 memory) {
return Decimal.ratio(POD_RATE_UPPER_BOUND, PERCENT_BASE);
}

function getLowerBoundPodRate() internal pure returns (Decimal.D256 memory) {
return Decimal.ratio(POD_RATE_LOWER_BOUND, PERCENT_BASE);
}

function getUpperBoundDPD() internal pure returns (Decimal.D256 memory) {
return Decimal.ratio(DELTA_POD_DEMAND_UPPER_BOUND, PERCENT_BASE);
}

function getLowerBoundDPD() internal pure returns (Decimal.D256 memory) {
return Decimal.ratio(DELTA_POD_DEMAND_LOWER_BOUND, PERCENT_BASE);
}

function getSteadySowTime() internal pure returns (uint32) {
return STEADY_SOW_TIME;
}

function getSeedsPerBean() internal pure returns (uint256) {
return SEEDS_PER_BEAN;
}
Expand All @@ -136,18 +96,6 @@ library C {
return ROOTS_BASE;
}

function getSopPrecision() internal pure returns (uint256) {
return SOP_PRECISION;
}

function beanAddress() internal pure returns (address) {
return BEAN;
}

function curveMetapoolAddress() internal pure returns (address) {
return CURVE_BEAN_METAPOOL;
}

function unripeLPPool1() internal pure returns (address) {
return UNRIPE_CURVE_BEAN_METAPOOL;
}
Expand All @@ -156,14 +104,6 @@ library C {
return UNRIPE_CURVE_BEAN_LUSD_POOL;
}

function unripeBeanAddress() internal pure returns (address) {
return UNRIPE_BEAN;
}

function unripeLPAddress() internal pure returns (address) {
return UNRIPE_LP;
}

function unripeBean() internal pure returns (IERC20) {
return IERC20(UNRIPE_BEAN);
}
Expand Down Expand Up @@ -204,6 +144,10 @@ library C {
return IERC20(THREE_CRV);
}

function UniV3EthUsdc() internal pure returns (address){
return UNIV3_ETH_USDC_POOL;
}

function fertilizer() internal pure returns (IFertilizer) {
return IFertilizer(FERTILIZER);
}
Expand Down Expand Up @@ -244,11 +188,4 @@ library C {
return INITIAL_HAIRCUT;
}

function soilCoefficientHigh() internal pure returns (uint256) {
return SOIL_COEFFICIENT_HIGH;
}

function soilCoefficientLow() internal pure returns (uint256) {
return SOIL_COEFFICIENT_LOW;
}
}
}