Skip to content

Commit

Permalink
Temple v2 deploy scripts (#834)
Browse files Browse the repository at this point in the history
* feat: temple v2 interfaces

* feat: dUSD initial implementation. testing wip

* feat: cleanup, more tests

* feat: cleanup, more tests

* feat: dUSD implementation and tests

* feat: minor updates, improved tests

* slither updates

* feat: start of strategies

* feat: add dusd testnet admin contract

* feat: added DSR base strategy

* feat: initial TRV - still WIP

* feat: still WIP

* feat: strategies report asset balances

* feat: strategies report asset balances

* feat: tests

* feat: gnosis strategy tests

* feat: wip dsr base strategy tests

* feat: wip continues

* Add safe guard

* Convert to revert string error for Safe UI

* Refactor elevated access

* Add v2 readme

* Add v2 readme

* Updated access

* Updated readme, batch update on guard

* Update README.md

Cleaned up the wording for clarity / readability

* TLC pre-requisites (#804)

* Updated Temple v2 to support TLC

* Add the RAMOS strategy (#805)

* implement the RAMOS strategy reporting the underlying assets

* add tests for RAMOS strategy

* disable the ETH balance report

* update tests for RAMOS strategy

* add TPI on TRV constructor in RAMOS strategy test

* implement functions to add/remove liquidity on RAMOS strategy

* proportional add liquidity

* update the addLiquidity function on RAMOS and the quote functions on PoolHelper

* update RAMOS contract and tests

* implement borrow/repay features on RAMOS strategy and add tests for borrow

* fix bpt total supply issue and add tests for repay

* fix issues on RAMOS contract

* remove operators from RAMOS strategy

* update tests for adding/removing the liquidity

* fix tests for RAMOS and PoolHelper contracts

* update the RAMOS access control mechanism and fix the tests for RAMOS and RAMOS strategy

* set the explicit access to RAMOS on RAMOS strategy test

* Tlc (#806)

* Updated Temple v2 to support TLC

* Updated Temple v2 to support TLC

* Updated Temple v2 to support TLC

* Initial TLC

* Make TLC a strategy

* Use an index accumulator instead of shares

* Updates, gas golfing

* comment out logs

* Tlc reworked (#807)

* Reworked to fit size - strategy split out

* Tlc delegatecall (#808)

* delegatecall

* Reworked to fit size - strategy split out

* added storage to interfaces

* fix up (#809)

* update names

* remove loops

* add expiry to fund request window

* refactor to take token address as input

* further tests

* tests, tests, tests

* split fund request types, tests

* positive interest rate only

* add more tests, cleanup

* comment all of the things

* a couple of extra tests

* remove oud, update tests

* flatten TLC contract

* fix edge cases on interest rate model

* interface tweaks to shutdown, asset balances

* PR feedback, solhint

* refactor ramos imports, ramos strategy updates

* Update ramos tests

* Add comments to Ramos, autoshutdown ramos

* Move TPI into a separate oracle contract

* rename temple/stable in ramos

* ramos rebalance up/down join & exit

* Add fees to ramos

* review feedback

* feedback: use propose/accept model for roles

* refactor: rename protocolTokenVault to tokenVault

* test: add compound & linear kink interest tests

* test: add max allowed ir test & remove unreachable code

* fix: typo tabs for spaces

* fix: ci typo case issue

* wip: implement tokenVault.repayQuoteToken

* feat: update rebalanceDownExit, rebalanceUpJoin, removeLiquidity & add Liquidity with latest tokenVault functions

* feat: TRV borrow and repay functions included in ramos strategy

* fix: update various descriptions

* feat: ramos strategy do not borrow & repay from the TVR directly any longer, ramos does it & tests updated

* docs: update IRamosTokensVault descriptions

* Update TRV to be multi-asset (#817)

* Update TRV to be multi-asset

* Merged from upstream

* Update events from RamosStrategy

* update tlc interface to remove cooldown (#818)

* update tlc interface to remove cooldown

* update tlc interface to remove cooldown

* update tlc interface to remove cooldown

* Temple v2 circuit breaker (#820)

* initial circuit breaker algo

* fix/optimisation

* Add tests, optimise, cleanup - start proxy

* Update TLC to remove requests

* Added tests, improved gas

* Added tests, improved gas

* Correct tests

* Merged with upstream

* Correct tests

* review feedback

* review feedback

* update circuit breaker so mappings are centrally configured

* update threshold safe guard to accept empty function sig - eg eth transfer

* Temple v2 review feedback ramos strategy tests (#822)

* test: add missing ramos strategy test vault functions

* test: update TEMPLE_INITIAL_TOTAL_SUPPLY val

* minor test/comment updates

* minor gas

* review feedback

* Add sepolia, initial shell of contract addrs

* prioritise TLC first

* improved deploy and mine to dump args to files

* chore: add temple v2 initial deploy scripts

* chore: add temple v2 initial deploy scripts

* chore: use owner.getAddress() as executor/rescuer

* chore: script 01-06 deployed

* chore: scripts 07-10 & 12-13 deployed

* Added a testnet version of the DSR base rate

* chore: script 11 deployed

* review feedback

* chore: draft postdeploy script

* chore: updates to postdeploy scripts

* chore: add msig executor & rescuer and allow owner to mint/burn temple

* update deploy scripts for TLC

* review feedback

* updates for slither

* update to 0.8.18, update slither db

* update to 0.8.18, update slither db

* slither gh

* update test

* ramos testnet deploy scripts

* fix typo

* cleanup files

* Add gnosis strategy

* Remove ramos liquidity

* fix: v2 audit: yAudit/temple-lending-report#1

* fix: v2 audit: yAudit/temple-lending-report#2

* fix: v2 audit: yAudit/temple-lending-report#3

* fix: v2 audit: yAudit/temple-lending-report#5

* fix: v2 audit: yAudit/temple-lending-report#6

* fix: v2 audit: yAudit/temple-lending-report#7

* fix: v2 audit: yAudit/temple-lending-report#9

* fix: v2 audit: yAudit/temple-lending-report#10

* fix: v2 audit: yAudit/temple-lending-report#11

* fix: v2 audit: yAudit/temple-lending-report#12

* fix: v2 audit: yAudit/temple-lending-report#14

* fix: v2 audit: yAudit/temple-lending-report#15

* fix: v2 audit: yAudit/temple-lending-report#16 yAudit/temple-lending-report#18

* fix: v2 audit: yAudit/temple-lending-report#17

* fix: v2 audit: yAudit/temple-lending-report#20

* fix: v2 audit: yAudit/temple-lending-report#22 yAudit/temple-lending-report#23

* fix: v2 audit: yAudit/temple-lending-report#24

* fix: v2 audit: yAudit/temple-lending-report#26

* fix: v2 audit: yAudit/temple-lending-report#27

* fix: v2 audit: yAudit/temple-lending-report#28

* fix: v2 audit: yAudit/temple-lending-report#29

* fix: v2 audit: yAudit/temple-lending-report#30

* fix: v2 audit: yAudit/temple-lending-report#31

* Temple v2 forked localhost tests (#832)

* test: add local fork tests skeleton

* test: add tlc borrow & repay local fork tests

* test: tlc forked tests using existing mainnet contracts

* test: update scripts to newest path

* test: add **/localhost/deploymentArgs to .gitignore

* chore: move from ../scripts/v2/sepolia/* to ../scripts/sepolia/v2/*

* chore: use symlinks to avoid duplication in local mainnet fork

* test: address CRs

* chore: add transaction builder msig json & readme steps for temple v2 mainnet deployment

* test: add transfer ownership tests

* chore: update readme & add temple-v2-transactions-batch.json as post-deploy step for mainnet gnosis safe app

* feat: remove symlinks

* feat: copy missing mainnet scripts, update readme & separate executor/rescuer transaction batch json

* feat: add gnosys1 & ramos deploys scripts to mainnet & update local mainnet fork tests

* feat: address CRs

* feat: update deploy scripts names & comments on transaction builder json files

* fix: v2 audit: yAudit/temple-lending-report#32

* fix: v2 audit: yAudit/temple-lending-report#35

* fix: v2 audit: yAudit/temple-lending-report#36

* fix: v2 audit: yAudit/temple-lending-report#38

* fix: v2 audit: yAudit/temple-lending-report#40

* fix: v2 audit: yAudit/temple-lending-report#41

* fix: v2 audit: yAudit/temple-lending-report#42

* fix: v2 audit: yAudit/temple-lending-report#44

* fix: v2 audit: yAudit/temple-lending-report#45 Also see PaulRBerg/prb-math#198

* fix: v2 audit: yAudit/temple-lending-report#46

* fix: v2 audit: yAudit/temple-lending-report#49

* fix: v2 audit: yAudit/temple-lending-report#48

* fix: v2 audit: yAudit/temple-lending-report#50

* fix: v2 audit: yAudit/temple-lending-report#51

* fix: v2 audit: yAudit/temple-lending-report#52

* fix: v2 audit: yAudit/temple-lending-report#53

* fix: v2 audit: yAudit/temple-lending-report#54

* fix: v2 audit: yAudit/temple-lending-report#55

* fix: v2 audit: yAudit/temple-lending-report#12  part 2

* fix: v2 audit: yAudit/temple-lending-report#5  part 2

* update dToken for gas optimisations and extra events

* revert contract changes

* fix: v2 audit: yAudit/temple-lending-report#56

* fix: v2 audit: yAudit/temple-lending-report#46 (updated to how it was addressed)

* added extra test, removed redundant error, partially reverted 6cd79a0

* updated foundry version, slither, CI

* corrected safe fork lib to be internal

* updated deployment scripts post audit

* dToken rounding and gas golfing

dtoken rounding

* update foundry version and std lib

* dtoken rounding

* rename postRebalanceSlippage => postRebalanceDelta

* Update deploy scripts for ramos

* add gnosis safe threshold to scripts

* updated deploy scripts for mainnet readiness

* updates after internal review

* dariox request -- add the DebtCeilingUpdated event on addStrategy

* add complex liquidation test when rescue mode/paused liquidations

* review feedback on safe guard test

* review feedback on temple base strategy

* update post deploy script

* update post-merge

---------

Co-authored-by: temple-advocate <92966776+temple-advocate@users.noreply.github.com>
Co-authored-by: cool-eth <82349338+cool-eth@users.noreply.github.com>
Co-authored-by: frost ostrich <frost_ostrich@proton.me>
Co-authored-by: frost-ostrich <127277105+frost-ostrich@users.noreply.github.com>
  • Loading branch information
5 people authored Aug 23, 2023
1 parent 7ed36cb commit 843b5a4
Show file tree
Hide file tree
Showing 105 changed files with 4,448 additions and 539 deletions.
5 changes: 4 additions & 1 deletion protocol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ dist
coverage
coverage.json
lcov.info
report
report

# autogenerated fork args
scripts/deploys/localhost/deploymentArgs
73 changes: 73 additions & 0 deletions protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,45 @@ You can also run and test locally by replacing `yarn hardhat:testnet` with `yarn
in order to setup the right local state



#### Local Deployment

The protocol app uses hardhat for development. The following steps will compile the contracts and deploy to a local hardhat node

```bash
# Compile the contracts
yarn compile

# Generate the typechain.
yarn typechain

The protocol test suite can be run without deploying to a local-node by running

```bash
# Run tests, no deployment neccessary
yarn test
```

#### Local Forks

##### 1. Temple V2 - TLC

In one terminal window:
```bash
# Run a local node forked off mainnet
yarn local-fork:mainnet
```

In another window run the following scripts:
```bash
# Deploy temple v2 contracts
# This also include the transfer ownership script
yarn local-fork:deploy:templev2
# Then finally some forked mainnet tests for Temple v2
yarn local-fork:test:templev2
```

## VSCode Testing

https://hardhat.org/guides/vscode-tests.html
Expand All @@ -46,3 +85,37 @@ tl;dr;
3. For each category + finding, analyse and either:
1. Fix the issue or
2. If it's a false positive then ignore the finding by typing the list index number in the triage.
## Temple V2 deployment
The following are the steps to deploy temple v2 latest contracts to mainnet. Copy & paste each `npx hardhat run ...` command from `core`, `tlc` & `ramos` in order to deploy to mainnet, after each successful deployment, please do the following:
- (**mandatory**) Deploy each contract under `scripts/deploy/mainnet/v2/**/**.ts`, you can find various examples in `scripts/deploys/localhost/v2/deploy-localhost-forsk.sh`, please remember to use the mainnet network, e.g `npx hardhat run --network mainnet scripts/deploys/mainnet/v2/core/02-circuit-breaker-proxy.ts`. *NB you'll need to deploy first the core contracts. Remember to run the post-deployment scripts for each folder to setup the contract*
- (**mandatory**) Copy newest generated contract address in its respective place under `scripts/deploys/mainnet/v2/core/contract-addressses.ts`
- (**recommended**) Verify & publish contract src to etherscan:
```
npx hardhat verify --network mainnet XXXX --constructor-args scripts/deploys/mainnet/deploymentArgs/XXXX.js
```

### 3. Commit & merge to main

- 3.1 Create a new PR and commit the latest changes from above steps for another member(s) of the team to confirm

### 4. Transfer ownership from deployer to multisigs

- 4.1 Once msig addresses have been approved by temple core team, please update both EXECUTOR & RESCUER multisig addresses (`mainnet.**.**.**_MSIG`) in `scripts/deploys/mainnet/v2/contract-addresses.ts` file. Be aware that strategies may have different executor/rescuer msig.

- 4.2 Transfer deployer ownership to predefined msig addresses on the step above with
```
npx hardhat run --network mainnet scripts/deploys/mainnet/v2/post-deploy/999-transfer-ownership.ts
```

### 5. Initial rescuer & executor msig transactions

The new rescuer & executor msig contract addresses would need to perform a set of initial transactions to be able to operate as expected, please find below the steps required:

- 5.1 Update the transaction builder batch files `scripts/deploys/mainnet/v2/post-deploy/temple-v2-XXX-transactions-batch.json`, change all the placeholders `0xXXXX` for the relevant address in `scripts/deploys/mainnet/v2/contract-addresses.ts` under the mainnet network.

- 5.2 Share the updated transaction builder batch file `temple-v2-XXX-transactions-batch.json` with any of the MC team members, that way they can import it in their safe app `https://app.safe.global/` > `transaction builder` and approve it accordingly. Please be sure to share each file accordingly to the msig address.

4 changes: 4 additions & 0 deletions protocol/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ module.exports = {
: [],
gasPrice: 2000000000,
},
anvil: {
url: "http://127.0.0.1:8545/",
accounts: "remote",
},
},
etherscan: {

Expand Down
4 changes: 4 additions & 0 deletions protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "templeDOA",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@balancer-labs/sdk": "^1.1.2",
"@ethersproject/bytes": "^5.7.0",
"@gnosis.pm/safe-contracts": "^1.3.0",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.4",
Expand Down Expand Up @@ -61,6 +62,9 @@
"hardhat": "hardhat",
"local-metrics": "hardhat run --network localhost scripts/metrics.ts",
"local-fork": "hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/5uWfALq4t1xR49V3EW5bBZEE4xh97l-A --fork-block-number 13205117",
"local-fork:mainnet": "hardhat node --fork https://eth-mainnet.g.alchemy.com/v2/LjzU7NEw1jfJZSDBP10rGeg53cSlzscP --fork-block-number 17625800",
"local-fork:deploy:templev2": "$PWD/scripts/deploys/localhost/v2/deploy-localhost-fork.sh",
"local-fork:test:templev2": "hardhat run --network localhost scripts/deploys/localhost/v2/999-localhost-fork-test.ts",
"forge-test": "forge test",
"forge-coverage": "forge coverage",
"forge-coverage-html": "forge coverage --report lcov && genhtml lcov.info -o report --branch-coverage --legend"
Expand Down
1 change: 1 addition & 0 deletions protocol/scripts/deploys/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ const expectedEnvvars: { [key: string]: string[] } = {
gnosisChiado: ['GNOSIS_CHIADO_ADDRESS_PRIVATE_KEY', 'GNOSIS_CHIADO_RPC_URL'],
polygonMumbai: ['MUMBAI_ADDRESS_PRIVATE_KEY', 'MUMBAI_RPC_URL'],
sepolia: ['SEPOLIA_ADDRESS_PRIVATE_KEY', 'SEPOLIA_RPC_URL'],
anvil: [],
localhost: [],
};

Expand Down
Loading

0 comments on commit 843b5a4

Please sign in to comment.