Skip to content

Commit

Permalink
Add Gateway contract + other small fixes (#35)
Browse files Browse the repository at this point in the history
* add prettier:watch npm command

to format files when on save

* add base Account management

* add canCall functionality to the account factory

* use canCall from the factory and add simple withdraw function for any tokens

* add simple withdrawEth function to allow any ETH deposited here to be withdraw by the owner

* only withdraw to owner

* remove useless canCall function

as the mapping is already public

* add basic testing of the account factory

* more tests for the account factory

* Create AccountImplementation.t.sol

* add missing test for init

* add test for withdraw fail

* add natspec

* add natspect for account factory

* remove boring batchable to use oz/multicall

also finish testing account implementation

* implement multicall locally

* rework AccountImplementation

* rewrite natspec

* Create MockBalancerVault.sol

* add initiatedByOwnerOrOwner modifier

* complete unit test

* add flashloan fail test

* add create balancer weighted pool script

* WIP integration testing

* use swap on univ2 instead of balancer

* Update IntegrationTestSepoliaBorrowLeverage.sol

* import TestnetToken from sepolia branch

* cleanup

* add borrowOnBehalf on a term

* wip gatewayV1

* add testBorrowOnBehalfSuccess on lending term

* WIP gateway v1

* finish gateway impl

* add sepolia gateway deploy

* various eswak review fixes

* fix build and tests

* fix getSelector function

* fix scripts route

* remove old unit tests

* add script SimpleBorrowOnSDAI using the gateway

* add gateway calls to the gateway

* onboard a new term

* fix simple borrow sDAI

* add missing revert string on the gateway

* Create SimpleBorrowOnSDAIWithLeverage.s.sol

* fix missing revert msg

* fix scripts

* Create PauseGateway.s.sol

* fix deployment to sepolia

* Update package.json

* prettier fix

* wip fix proposal

* remove extract address lib

* remove AddressLib

and create ECGTest

* add/update deploy scripts

* Move rate limit utils to rate-limits folder

* Update README.md

* Fix forge deal() on ERC20RebaseDistributor

* Fix roles in deployment script

* Add roles.sepolia.json

* Update DeployGatewayV1.s.sol

* Fix integration tests

* Remove references to sDAI in integration tests

* prettier

* clean comments on the gatewayv1

* Remove callFee reference in readme

* add unit test sepolia gateway (vip)

* add test without permit

* add integ test flashloan gateway

* fix test:integration npm script to not redeploy by default

* Fix integration tests (2)

* GIP_0: set shorter delegateLockupPeriod on sepolia

* cleanup console log and prettier:fix

* missing console log removal

* Fix offboard vote on past votes

* Add events in LendingTerm for AH & hardCap setters

* Fix 1259 (reorg after lending term factory use)

* Add borrowWithBalancerFlashLoan & repayWithBalancerFlashLoan

* Add GatewayV1.bidWithBalancerFlashLoan()

* ProfitManager: handling of creditMultiplier = 0

* Cleanup OnboardNewTerm.s.sol & PauseGateway.s.sol

* Run prettier:fix

* Add entryPoint/afterEntry modifiers to Gateway

* Fix gateway integration tests

if creditMultiplier != 1, rounding down can happen

* Remove MockExternalContract

* GIP_0 coherence on term onboarding

* Increase default auction duration to 2h

* Add unit tests for GatewayV1

---------

Co-authored-by: Erwan Beauvois <[email protected]>
Co-authored-by: Erwan Beauvois <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent 5003806 commit dba62fb
Show file tree
Hide file tree
Showing 64 changed files with 4,389 additions and 1,145 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Dominant lending protocols like MakerDAO, Aave, and Compound rely on trusted ora

Recent attempts to address these problems involve isolated markets, helping to silo risk but fragmenting liquidity, as well as peer to peer markets, which remove trust assumptions but impose complexity upon users.

The Ethereum Credit Guild seeks to strike a new middle ground between honest-majority systems and pure peer to peer lending. Incentive alignment and appropriate checks and balances allow saving and credit operations without relying on trusted third parties, and responding on demand to changes in the market through an open parameter control process. The system makes an **honest minority assumption**, and if you possess sufficient tokens to constitute that minority, requires no trust assumptions at all. Its failure mode is to safely end lending operations (with borrowers compensated for the inconvenience), and one or several new iterations can be started with their own ownership distributions.
The Ethereum Credit Guild seeks to strike a new middle ground between honest-majority systems and pure peer to peer lending. Incentive alignment and appropriate checks and balances allow saving and credit operations without relying on trusted third parties, and responding on demand to changes in the market through an open parameter control process. The system makes an **honest minority assumption**, and if you possess sufficient tokens to constitute that minority, requires no trust assumptions at all. Its failure mode is to safely end lending operations, and one or several new iterations can be started with their own ownership distributions.

We hope to see a diversity of markets applying the same core principles as this the v1 market described in this document, as well as continued development of the core technology, especially in regards to scaling.

Expand Down Expand Up @@ -114,7 +114,7 @@ The deployment script of the protocol, located in `test/proposals/gips/GIP_0.sol
| `loan/SimplePSM.sol` | 99 | [PSM_USDC](https://sepolia.etherscan.io/address/0x66839a9a16beba26af1c717e9c1d604dff9d91f7#code) | Used to maintain peg between credit tokens and a reference asset |
| `loan/SurplusGuildMinter.sol` | 222 | [SURPLUS_GUILD_MINTER](https://sepolia.etherscan.io/address/0x3b5b95249b0a598a4347be4c2736ad4eb877b16d#code) | Used to provide first-loss capital in credit tokens to borrow `GUILD` and participate in the gauge system without exposure to `GUILD` token price |
| `rate-limits/RateLimitedMinter.sol` | 36 | [RATE_LIMITED_GUILD_MINTER](https://sepolia.etherscan.io/address/0xa29b96371dec4edaac637ee721c16046ee0b7dff#code), [RATE_LIMITED_CREDIT_MINTER](https://sepolia.etherscan.io/address/0xc8197e8b9ffe1039761f56c41c6ce9cbc7c2d1d9#code) | Implements limitations on `GUILD` and credit tokens minting |
| `utils/RateLimitedV2.sol` | 98 | n/a | Abstract class util for rate limits |
| `rate-limits/RateLimitedV2.sol` | 98 | n/a | Abstract class util for rate limits |

Total SLOC: 3739

Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ optimizer_runs = 200
# paths
src = 'src'
test = 'test'
script = 'script'
script = 'scripts'

# contracts in libs are excluded from code coverage reports
libs = ['lib', 'script']
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
"test": "npm run test:unit",
"test:unit": "forge test --match-path './test/unit/**' -vvv",
"test:proposals": "forge test --match-path './test/proposals/**' --fork-url $ETH_RPC_URL -vvv",
"test:integration": "forge test --match-path './test/integration/**' --fork-url $ETH_RPC_URL -vvv",
"coverage": "forge coverage --fork-url $ETH_RPC_URL --match-path './test/**' --report lcov --report summary",
"coverage:unit": "forge coverage --match-path './test/unit/**' --report lcov --report summary",
"coverage:integration": "forge coverage --match-path './test/integration/**' --fork-url $ETH_RPC_URL --report lcov --report summary",
"test:integration": "DO_DEPLOY=false DO_AFTER_DEPLOY=false DO_VALIDATE=false forge test --match-path './test/integration/**' --fork-url $ETH_RPC_URL -vvv",
"coverage": "forge coverage --fork-url $ETH_RPC_URL --match-path './test/**' --report summary --report lcov",
"coverage:unit": "forge coverage --match-path './test/unit/**' --report summary --report lcov",
"coverage:integration": "forge coverage --match-path './test/integration/**' --fork-url $ETH_RPC_URL --report summary --report lcov",
"coverage:prune": "lcov --remove ./lcov.info -o ./lcov.info 'test/*'",
"fork": "anvil --fork-url $ETH_RPC_URL --block-time 10 --chain-id 1337",
"deploy:local": "ETH_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 forge script scripts/DeployProposal.s.sol:DeployProposal -vvvv --rpc-url http://127.0.0.1:8545 --broadcast",
"prettier": "npx prettier --check 'src/**/*.sol'",
"prettier:fix": "npx prettier --write 'src/**/*.sol'"
"prettier": "npx prettier --check \"(src|test|scripts)/**/*.sol\"",
"prettier:fix": "npx prettier --write \"(src|test|scripts)/**/*.sol\"",
"prettier:watch": "onchange \"(src|test|scripts)/**/*.sol\" -- prettier --write {{changed}}"
},
"authors": "elliotfriedman,eswak,joeysantoro,onetruekirk",
"devDependencies": {
Expand All @@ -30,7 +31,8 @@
"prettier": "2.5.1",
"prettier-plugin-solidity": "1.0.0",
"solhint": "2.0.0",
"solhint-plugin-prettier": "0.0.5"
"solhint-plugin-prettier": "0.0.5",
"onchange": "^7.1.0"
},
"lint-staged": {
"*.{sol}": [
Expand Down
122 changes: 122 additions & 0 deletions protocol-configuration/addresses.sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
[
{
"addr": "0x0000000000000000000000000000000000000000",
"name": "ZERO_ADDRESS"
},
{
"addr": "0x6ef71ca9cd708883e129559f5edbfb9d9d5c6148",
"name": "TEAM_MULTISIG"
},
{
"addr": "0xb027658e189F9814663631b12B9CDF8dd7CC977C",
"name": "ESWAK"
},
{
"addr": "0xbad06297eB7878502E045319a7c4a8904b49BEEF",
"name": "BADBEEF"
},
{
"addr": "0xb63C817ab0Bf103bF0149fb18fe22CdEAb5EF7b1",
"name": "TOMTOM"
},
{
"addr": "0xfc2290dbf4db882b6d3d07ecb1e00d0531b45680",
"name": "CORE"
},
{
"addr": "0x7b8b4418990e4daf35f5c7f0165dc487b1963641",
"name": "ERC20_USDC"
},
{
"addr": "0x1ced1eb530b5e71e6db9221a22c725e862fc0e60",
"name": "ERC20_WBTC"
},
{
"addr": "0x9f07498d9f4903b10db57a3bd1d91b6b64aed61e",
"name": "ERC20_SDAI"
},
{
"addr": "0x8738c00828c8e6883326ea5ba104cacff95808e0",
"name": "PROFIT_MANAGER"
},
{
"addr": "0x7dff544f61b262d7218811f78c94c3b2f4e3dca1",
"name": "ERC20_GUSDC"
},
{
"addr": "0x79e2b8553da5361d90ed08a9e3f2f3e5e5ff2f8f",
"name": "ERC20_GUILD"
},
{
"addr": "0x81aa07eb1b22e3d3b9c7cc728640721064cad4a9",
"name": "RATE_LIMITED_CREDIT_MINTER"
},
{
"addr": "0x9594af6eea97b43673bb046db152428b13c48377",
"name": "RATE_LIMITED_GUILD_MINTER"
},
{
"addr": "0x7386c5ffbb710e543a0f3c40c1e7ee1ddcaedf51",
"name": "SURPLUS_GUILD_MINTER"
},
{
"addr": "0x912e76518b318c209ef7ff04d119967acae3569e",
"name": "AUCTION_HOUSE"
},
{
"addr": "0x87b22b22666c15c11b8632c8a132ee820b783061",
"name": "LENDING_TERM_V1"
},
{
"addr": "0xc19d710f13a725fd67021e8c45bdedffe95202e3",
"name": "PSM_USDC"
},
{
"addr": "0x14025e6f3ac44d6d2212605bce695b7d379c2350",
"name": "DAO_GOVERNOR_GUILD"
},
{
"addr": "0x34badf7afe7c981d7b399f092f4557bef09c1b6f",
"name": "DAO_TIMELOCK"
},
{
"addr": "0x76b513119671176a87fa538e5814c50dd49e3e66",
"name": "DAO_VETO_CREDIT"
},
{
"addr": "0x6ef90254dd61782ead7d95974d1d47f4f7d2d377",
"name": "DAO_VETO_GUILD"
},
{
"addr": "0x3274ebe53c4fa1d0a59ad8fadbc6f944186b408e",
"name": "ONBOARD_GOVERNOR_GUILD"
},
{
"addr": "0x1026847b30385606d3a22e62d5ede3b1b8e2448a",
"name": "ONBOARD_TIMELOCK"
},
{
"addr": "0xd09195208a829990b0b72ef6d08d9637779338c8",
"name": "ONBOARD_VETO_CREDIT"
},
{
"addr": "0x68e47e70f66a484fcb0cef215a46d76300b2e2b2",
"name": "ONBOARD_VETO_GUILD"
},
{
"addr": "0xb2aed7b9dce6826d510a2559da83afd5a2af9405",
"name": "OFFBOARD_GOVERNOR_GUILD"
},
{
"addr": "0x938998fca53d8bfd91bc1726d26238e9eada596c",
"name": "TERM_SDAI_1"
},
{
"addr": "0x820e8f9399514264fd8cb21cee5f282c723131f6",
"name": "TERM_WBTC_1"
},
{
"addr": "0xd3ecfc72fe299b58764e12ac38d59f20fc287052",
"name": "LENDING_TERM_FACTORY"
}
]
79 changes: 79 additions & 0 deletions protocol-configuration/roles.sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"GOVERNOR": [
"OFFBOARD_GOVERNOR_GUILD",
"DAO_TIMELOCK",
"ONBOARD_TIMELOCK",
"ESWAK",
"BADBEEF",
"TOMTOM"
],
"GUARDIAN": [
"TEAM_MULTISIG"
],
"CREDIT_MINTER": [
"RATE_LIMITED_CREDIT_MINTER",
"PSM_USDC"
],
"CREDIT_BURNER": [
"PROFIT_MANAGER",
"PSM_USDC",
"TERM_SDAI_1",
"TERM_WBTC_1"
],
"RATE_LIMITED_CREDIT_MINTER": [
"TERM_SDAI_1",
"TERM_WBTC_1"
],
"GUILD_MINTER": [
"RATE_LIMITED_GUILD_MINTER",
"ESWAK",
"BADBEEF"
],
"RATE_LIMITED_GUILD_MINTER": [
"SURPLUS_GUILD_MINTER",
"TEAM_MULTISIG"
],
"GAUGE_ADD": [
"DAO_TIMELOCK",
"ONBOARD_TIMELOCK"
],
"GAUGE_REMOVE": [
"DAO_TIMELOCK",
"OFFBOARD_GOVERNOR_GUILD"
],
"GAUGE_PARAMETERS": [
"DAO_TIMELOCK"
],
"GAUGE_PNL_NOTIFIER": [
"TERM_SDAI_1",
"TERM_WBTC_1"
],
"GUILD_GOVERNANCE_PARAMETERS": [
"DAO_TIMELOCK"
],
"GUILD_SURPLUS_BUFFER_WITHDRAW": [
"SURPLUS_GUILD_MINTER"
],
"CREDIT_GOVERNANCE_PARAMETERS": [
"DAO_TIMELOCK"
],
"CREDIT_REBASE_PARAMETERS": [
"DAO_TIMELOCK",
"PSM_USDC"
],
"PROPOSER": [
"DAO_GOVERNOR_GUILD",
"ONBOARD_GOVERNOR_GUILD"
],
"EXECUTOR": [
"ZERO_ADDRESS"
],
"CANCELLER": [
"DAO_VETO_CREDIT",
"DAO_VETO_GUILD",
"ONBOARD_VETO_CREDIT",
"ONBOARD_VETO_GUILD",
"DAO_GOVERNOR_GUILD",
"ONBOARD_GOVERNOR_GUILD"
]
}
Loading

0 comments on commit dba62fb

Please sign in to comment.