Skip to content

ARM integration to Lending Markets #79

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

Open
wants to merge 69 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
92c56bc
Added strategies to the ARM
naddison36 Apr 9, 2025
7c3f652
Changed license to BUSL-1.1
naddison36 Apr 10, 2025
cb8a72b
Added Origin ARM
naddison36 Apr 10, 2025
3686235
Changed to use IERC4626 for lending markets
naddison36 Apr 16, 2025
5485c20
Update Natspec
naddison36 Apr 16, 2025
2f6a086
Validate the market asset is the same as the liquidityAsset
naddison36 Apr 16, 2025
6a31da2
Added Sonic support
naddison36 Apr 16, 2025
996d724
Add Sonic deployments file
naddison36 Apr 16, 2025
d93b83a
Made the Zapper more generic so it can work with multiple ARMs
naddison36 Apr 17, 2025
707aad0
Change addMarket to addMarkets
naddison36 Apr 17, 2025
b0a5130
fix: prevent redeeming zero shares in AbstractARM contract
naddison36 Apr 21, 2025
7ee6ac7
fix: update maxWithdraw call to use contract address in AbstractARM
naddison36 Apr 21, 2025
0d3bd10
Silo market strategy (#69)
naddison36 Apr 23, 2025
c66eaf2
Add tests for Origin ARM. (#68)
clement-ux Apr 23, 2025
f82d917
ARM Harvester (#72)
naddison36 Apr 30, 2025
41c62e2
Add invariant test to OriginARM. (#70)
clement-ux Apr 30, 2025
8927be5
Made the Harvester's price provider optional (#74)
naddison36 Apr 30, 2025
e9381a3
Add test for OriginARM Harvester (#73)
clement-ux Apr 30, 2025
00def3a
Fix issue on SiloMarket and add more tests onHarvester. (#75)
clement-ux Apr 30, 2025
87b8c9b
Changed setActiveMarket to use balanceOf instead of maxRedeem (#76)
naddison36 May 2, 2025
6026ad1
fix available assets (#77)
naddison36 May 2, 2025
031c2d9
Add more fork tests (#78)
clement-ux May 5, 2025
ff2f946
Updated SiloMarket Natspec
naddison36 May 5, 2025
64c4a45
Fix Natspec
naddison36 May 5, 2025
b934042
removed sender check in previewRedeem
naddison36 May 5, 2025
887b3a8
Added CollectedRewards event
naddison36 May 5, 2025
5832f49
Added ERC-4626 events to SiloMarket
naddison36 May 5, 2025
c516aad
Plug `SiloMarket.sol` to Varlamore vault instead of markets. (#81)
clement-ux May 9, 2025
f78382c
Removed duplicate _setFee
naddison36 May 12, 2025
635deda
Gas improvements
naddison36 May 12, 2025
9444bee
Remove unused Math import in Harvester
naddison36 May 12, 2025
ab67219
Renamed Harvester to SonicHarvester
naddison36 May 12, 2025
e94b0d6
Merge remote-tracking branch 'origin/nicka/liquidity-strategies' into…
naddison36 May 12, 2025
700fa99
Added onlyOwner to initialize on SonicHarvester
naddison36 May 12, 2025
0f31d92
Updated Natspec
naddison36 May 13, 2025
add235b
Deploy OriginARM proxy (#85)
naddison36 May 14, 2025
e290a11
Off-chain components (#87)
naddison36 May 19, 2025
997eb6d
Fixed gap for backward compatibility (#89)
naddison36 May 19, 2025
beb139e
Fixed OETH fork tests with new OETH Whale
naddison36 May 20, 2025
590ed3c
Fix collect test to handle expired incentives program and validate to…
clement-ux May 20, 2025
500111e
Reduced the initial OriginARM cap to 200 S
naddison36 May 20, 2025
4681eaa
Update Magpie router address in SonicHarvester and add setter function
clement-ux May 20, 2025
29e6fe2
Refactor SonicHarvester constructor to remove Magpie router parameter…
clement-ux May 20, 2025
d57b82a
Changed setActiveMarket so all shares are redeemed from the active ma…
naddison36 May 20, 2025
dcfff4f
Merge remote-tracking branch 'origin/nicka/liquidity-strategies' into…
naddison36 May 20, 2025
2fadc88
Added a gap to SonicHarvester
naddison36 May 20, 2025
b00de77
Added contract version to Magpie router address comment
naddison36 May 20, 2025
4a9eac1
Prettier
naddison36 May 20, 2025
0f78495
Update slippage parameter type to string in Helpers contract and adju…
clement-ux May 21, 2025
6991a2a
Fix CI (#91)
clement-ux May 22, 2025
8bba5e0
Deploy Origin ARM on Sonic (#90)
naddison36 May 22, 2025
0957903
Hardhat tasks for Origin ARM (#92)
naddison36 May 26, 2025
d9086a8
Consistent Solidity pragma (#93)
naddison36 May 27, 2025
5bf267e
N-01 Prefix increment operator ++i to save gas in loops (#95)
naddison36 May 27, 2025
f600dad
L-09 Don't revert of setting the new active market is the same as the…
naddison36 May 27, 2025
584c856
Natspec updates (#97)
naddison36 May 27, 2025
ca431df
N-22 Update Natspec (#98)
naddison36 May 27, 2025
2670c89
Gas optimized allocate (#96)
naddison36 May 27, 2025
2e4cffa
More Natspec (#99)
naddison36 May 27, 2025
b251cc1
Added allocateThreshold (#84)
naddison36 May 28, 2025
3ef4b53
M-01 Operator Can Steal Rewards From the Harvester (#100)
naddison36 May 28, 2025
7e7fb47
Changes from internal reviews (#101)
naddison36 May 29, 2025
a558b45
Setup Origin ARM Defender Actions (#102)
naddison36 May 29, 2025
ba513cc
Increase token amounts in swap tests for better coverage
clement-ux May 29, 2025
2ebe2f6
Increase WETH amounts in swap tests for improved coverage
clement-ux May 29, 2025
149c8f4
Fix totalAssets assertion in requestRedeem test after loss scenario
clement-ux May 29, 2025
b54252d
Add test for totalAssets after full asset loss in LidoARM
clement-ux May 29, 2025
d731cad
Return the liquidity delta from allocate to help with off-chain proce…
naddison36 May 30, 2025
e160864
Refactor tests to improve coverage and add preview assertions for dep…
clement-ux Jun 2, 2025
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: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PROVIDER_URL= # [MANDATORY] : URL Provider for mainnet forks.
TESTNET_URL=
HOLESKY_URL=
SONIC_URL=

### Etherscan ###
# ETHERSCAN_API_KEY= # [OPTIONAL] : API Key for Etherscan. Useful for verifying contracts and reading logs on forks.
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ jobs:
run: forge fmt --check

foundry-tests:
name: Foundry fork tests
name: Foundry tests
runs-on: ubuntu-latest
env:
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
SONIC_URL: ${{ secrets.SONIC_URL }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -41,10 +42,15 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1

- name: Install Dependencies
run: forge soldeer install
run: forge soldeer install && yarn install

- name: Check contract sizes
run: forge build --sizes

- name: Run fork tests
run: forge test -vvv --summary --detailed
- name: Run non-invariant tests
run: make test

- name: Run invariant tests
run: |
make test-invariant-lido
make test-invariant-origin
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.formatOnSave": true,
"plantuml.exportOutDir": "docs",
"plantuml.exportOutDir": "docs/plantuml",
"plantuml.exportFormat": "png",
"plantuml.exportIncludeFolderHeirarchy": false,
"plantuml.exportSubFolder": false,
Expand Down
1 change: 1 addition & 0 deletions Hardhat.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
1. Start a local Anvil node forked from the latest block

```
export PROVIDER_URL=
anvil --fork-url="$PROVIDER_URL"
```

Expand Down
36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clean:
@rm -rf broadcast cache out

clean-all:
@rm -rf broadcast cache out dependencies node_modules soldeer.lock
@rm -rf broadcast cache out dependencies node_modules soldeer.lock yarn.lock lcov.info lcov.info.pruned

gas:
@forge test --gas-report
Expand All @@ -30,21 +30,30 @@ test-std:
forge test --summary --fail-fast --show-progress

test:
@FOUNDRY_NO_MATCH_CONTRACT=Invariant make test-std
@FOUNDRY_NO_MATCH_CONTRACT=Fuzzer $(MAKE) test-std

test-f-%:
@FOUNDRY_MATCH_TEST=$* make test-std
@FOUNDRY_MATCH_TEST=$* $(MAKE) test-std

test-c-%:
@FOUNDRY_MATCH_CONTRACT=$* make test-std
@FOUNDRY_MATCH_CONTRACT=$* $(MAKE) test-std

test-all:
@make test-std
@$(MAKE) test-std

test-invariant-lido:
@FOUNDRY_INVARIANT_FAIL_ON_REVERT=false FOUNDRY_MATCH_CONTRACT=FuzzerFoundry_OethARM $(MAKE) test-std

test-invariant-origin:
@FOUNDRY_INVARIANT_FAIL_ON_REVERT=true FOUNDRY_MATCH_CONTRACT=FuzzerFoundry_OriginARM $(MAKE) test-std

test-invariants:
@$(MAKE) test-invariant-lido && $(MAKE) test-invariant-origin


# Coverage
coverage:
@forge coverage --report lcov
@lcov --ignore-errors unused --remove ./lcov.info -o ./lcov.info.pruned "test/*" "script/*"

coverage-html:
@make coverage
Expand All @@ -54,21 +63,36 @@ coverage-html:
simulate-s-%:
@forge script script/$*.s.sol --fork-url $(PROVIDER_URL) -vvvvv

simulate-sonic-s-%:
@forge script script/$*.s.sol --fork-url $(SONIC_URL) -vvvvv

run-s-%:
@forge script script/$*.s.sol --rpc-url $(PROVIDER_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvvvv

run-sonic-s-%:
@forge script script/$*.s.sol --rpc-url $(SONIC_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvvvv

# Deploy scripts
deploy:
@forge script script/deploy/DeployManager.sol --rpc-url $(PROVIDER_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvvv

deploy-local:
@forge script script/deploy/DeployManager.sol --rpc-url $(LOCAL_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow -vvvv

deploy-testnet:
@forge script script/deploy/DeployManager.sol --rpc-url $(TESTNET_URL) --broadcast --slow --unlocked -vvvv

deploy-holesky:
@forge script script/deploy/DeployManager.sol --rpc-url $(HOLESKY_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvv

deploy-sonic:
@forge script script/deploy/DeployManager.sol --rpc-url $(SONIC_URL) --private-key ${DEPLOYER_PRIVATE_KEY} --broadcast --slow --verify -vvv

simulate-deploys:
@forge script script/deploy/DeployManager.sol --fork-url $(PROVIDER_URL) --private-key ${DEPLOYER_PRIVATE_KEY} -vvvv

simulate-sonic-deploys:
@forge script script/deploy/DeployManager.sol --fork-url $(SONIC_URL) --private-key ${DEPLOYER_PRIVATE_KEY} -vvvv

# Override default `test` and `coverage` targets
.PHONY: test coverage
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ In the `.env` file, set `DEPLOYER_PRIVATE_KEY`, `ETHERSCAN_API_KEY` and `PROVIDE
make deploy
```

### Sonic

In the `.env` file, set `DEPLOYER_PRIVATE_KEY` and `SONIC_URL` to the mainnet values.

```bash
make deploy-sonic
```

## Contract Verification

If the verification doesn't work with the deployment, it can be done separately with forge `verify-contract`.
Expand All @@ -202,6 +210,9 @@ forge verify-contract 0xd8fF298eAed581f74ab845Af62C48aCF85B2f05e OethARM \

# Verify Proxy
forge verify-contract 0x6bac785889A4127dB0e0CeFEE88E0a9F1Aaf3cC7 Proxy

# Verify Proxy on Sonic
forge verify-contract --chain 146 --etherscan-api-key $SONICSCAN_API_KEY 0x2F872623d1E1Af5835b08b0E49aAd2d81d649D30 Proxy
```

## Open Zeppelin Defender
Expand Down Expand Up @@ -240,6 +251,11 @@ npx hardhat setActionVars --id c010fb76-ea63-409d-9981-69322d27993a
npx hardhat setActionVars --id 127171fd-7b85-497e-8335-fd7907c08386
npx hardhat setActionVars --id 84b5f134-8351-4402-8f6a-fb4376034bc4
npx hardhat setActionVars --id ffcfc580-7b0a-42ed-a4f2-3f0a3add9779
npx hardhat setActionVars --id 32dbc67b-89f3-4856-8f3d-ad4dc5a09322
npx hardhat setActionVars --id 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6
npx hardhat setActionVars --id a9fc4c86-0506-4809-afbc-93b5e558cb68
npx hardhat setActionVars --id 12977d51-d107-45eb-ac20-45942009ab01
npx hardhat setActionVars --id 6ec46510-0b8e-48b4-a4c8-de759aad0ba4

# The Defender autotask client uses generic env var names so we'll set them first from the values in the .env file
export API_KEY=
Expand All @@ -252,6 +268,11 @@ npx defender-autotask update-code c010fb76-ea63-409d-9981-69322d27993a ./dist/au
npx defender-autotask update-code 127171fd-7b85-497e-8335-fd7907c08386 ./dist/autoClaimLidoWithdraw
npx defender-autotask update-code 84b5f134-8351-4402-8f6a-fb4376034bc4 ./dist/collectLidoFees
npx defender-autotask update-code ffcfc580-7b0a-42ed-a4f2-3f0a3add9779 ./dist/setPrices
npx defender-autotask update-code 32dbc67b-89f3-4856-8f3d-ad4dc5a09322 ./dist/collectFeesSonic
npx defender-autotask update-code 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6 ./dist/allocateSonic
npx defender-autotask update-code a9fc4c86-0506-4809-afbc-93b5e558cb68 ./dist/collectRewardsSonic
npx defender-autotask update-code 12977d51-d107-45eb-ac20-45942009ab01 ./dist/autoRequestWithdrawSonic
npx defender-autotask update-code 6ec46510-0b8e-48b4-a4c8-de759aad0ba4 ./dist/autoClaimWithdrawSonic
```

`rollup` and `defender-autotask` can be installed globally to avoid the `npx` prefix.
Expand Down
17 changes: 17 additions & 0 deletions build/deployments-146.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"executions": {
"001_DeployOriginARMProxyScript": 1747110973,
"002_DeployOriginARMScript": 1747907433
},
"contracts": {
"HARVESTER": "0x08876C0F5a80c1a43A6396b13A881A26F4b6Adfe",
"HARVESTER_IMPL": "0x995B0Fd5A5289bD1776406754933De12DBaf2314",
"ORIGIN_ARM": "0x2F872623d1E1Af5835b08b0E49aAd2d81d649D30",
"ORIGIN_ARM_CAP_IMPL": "0xB05e625e8a688883B13ed2AedAdC42669a76907A",
"ORIGIN_ARM_CAP_MAN": "0x38B654d7859dab79935c9CF99267392c06D254cF",
"ORIGIN_ARM_IMPL": "0x0f26EAC83E07077c6fD236CE000aAD8a25E06e07",
"ORIGIN_ARM_ZAPPER": "0xcb8199AB7F8b7D97885FBDfb1f0ABc044f403C18",
"SILO_VARLAMORE_S_MARKET": "0x248Dbbc31F2D7675775DB4A9308a98444DaBaECf",
"SILO_VARLAMORE_S_MARKET_IMPL": "0x42ee4912377f0240669eb05C9fA62d122Cd9bca6"
}
}
Binary file added docs/plantuml/sonicContracts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions docs/plantuml/sonicContracts.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
@startuml

!$originColor = DeepSkyBlue
' !$originColor = WhiteSmoke
!$newColor = LightGreen
!$changedColor = Orange
!$thirdPartyColor = WhiteSmoke

legend
blue - Origin
' green - new
' orange - changed
white - 3rd Party
end legend

title "Sonic Automated Redemption Manager (ARM) Contract Dependencies"


object "Sonic Zapper" as zap #$originColor {
asset: S
}

object "Origin ARM" as originArm <<Proxy>> #$originColor {
assets: OS, wS
}

' object "Beets ARM" as beetsArm <<Proxy>> #$originColor {
' }

' object "Angles ARM" as anglesArm <<Proxy>> #$originColor {
' }

' object "CapManager" as capMan <<Proxy>> #$originColor {
' }
object "Origin\nCapManager" as osCapMan <<Proxy>> #$originColor {
}
' object "Beets\nCapManager" as stCapMan <<Proxy>> #$originColor {
' }
' object "Angles\nCapManager" as anCapMan <<Proxy>> #$originColor {
' }


' object "ARM" as arm <<Proxy>> #$originColor {
' }
' object "Strategy" as strat <<Proxy>> #$originColor {
' }

object "Silo\nStrategy" as siloStrategy #$originColor {
asset: wS
}

object "Varlamore\nVault" as siloVault <<Silo>> #$thirdPartyColor {
asset: wS
}
object "Varlamore\nGauge" as siloGauge <<Silo>> #$thirdPartyColor {
asset: wS
}

object "Lending\nMarkets" as siloLend <<Silo>> #$thirdPartyColor {
markets: stS, wOS, wanS, beS
}
' object "Lending\nMarket\nGauge" as gauge #$thirdPartyColor {
' }
' object "Liquid\nStaking\nToken" as lst #$thirdPartyColor {
' }

object "OS\nVault" as os <<Proxy>> #$originColor {
asset: wS
}

' object "Beets\nVault" as beets #$thirdPartyColor {
' }

' object "Angles\nVault" as angles #$thirdPartyColor {
' }

object "Origin\nHarvester" as osHarv #$originColor {
reward: SILO
}

' object "Beets\nHarvester" as stHarv #$originColor {
' }

object "Router" as magpie <<Magpie>> #$thirdPartyColor {
pair: SILO/wS
}

' object "Price\nProvider" as priceProvider #$originColor {
' Assets: Silo
' }

' object "Silo\nOracle" as siloOracle #$thirdPartyColor {
' }

' arm .> strat : ERC-4626
' strat .> lend : ERC-4626
' strat ..> gauge
' arm ..> lst

zap ..> originArm
' zap ..> beetsArm
' zap ..> anglesArm

' originArm <..> capMan
' beetsArm <..> capMan
' anglesArm <..> capMan
originArm <.> osCapMan
' beetsArm <.> stCapMan
' anglesArm <..> anCapMan


originArm <... osHarv
' beetsArm <... stHarv

osHarv .> siloStrategy
' stHarv .> siloStrategy

originArm ..> siloStrategy
siloStrategy ..> siloVault
siloStrategy ..> siloGauge
siloVault ..> siloLend
' beetsArm ...> siloStrategy
' anglesArm ..> lend

originArm ..> os
' beetsArm ..> beets
' anglesArm ...> angles

osHarv ..> magpie
' stHarv ..> magpie

' osHarv ..> priceProvider
' stHarv ..> priceProvider
' priceProvider ..> siloOracle


@enduml
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ verbosity = 3
sender = "0x0165C55EF814dEFdd658532A48Bd17B2c8356322"
tx_origin = "0x0165C55EF814dEFdd658532A48Bd17B2c8356322"
auto_detect_remappings = false
gas_reports = ["OethARM", "Proxy", "LidoARM"]
gas_reports = ["OethARM", "Proxy", "LidoARM", "OriginARM"]
fs_permissions = [{ access = "read-write", path = "./build" }]
extra_output_files = ["metadata"]
ignored_warnings_from = ["src/contracts/Proxy.sol"]
Expand All @@ -22,6 +22,7 @@ remappings = [
]
optimizer = true
optimizer_runs = 200
ffi = true

[fuzz]
runs = 1_000
Expand Down Expand Up @@ -49,5 +50,6 @@ remappings_location = "config"

[rpc_endpoints]
mainnet = "${PROVIDER_URL}"
sonic = "${SONIC_URL}"

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
4 changes: 4 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module.exports = {
url: `${process.env.HOLESKY_URL}`,
chainId: 17000,
},
sonic: {
url: `${process.env.SONIC_URL}`,
chainId: 146,
},
testnet: {
url: `${process.env.TESTNET_URL}`,
chainId: 1,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@solidity-parser/parser": "^0.18.0",
"axios": "^1.7.5",
"axios": "^1.9.0",
"builtin-modules": "^3.3.0",
"chai": "^4.3.10",
"dayjs": "^1.11.12",
Expand Down
Loading
Loading