Skip to content

Commit

Permalink
Onchain Rebalancer (#438)
Browse files Browse the repository at this point in the history
Co-authored-by: Makram <[email protected]>
  • Loading branch information
RensR and makramkd authored Jan 18, 2024
1 parent 5cfbd94 commit 1458510
Show file tree
Hide file tree
Showing 86 changed files with 5,720 additions and 4,089 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/solidity-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
strategy:
fail-fast: false
matrix:
product: [vrf, automation, llo-feeds, functions, shared, ccip]
product: [vrf, automation, llo-feeds, functions, shared, ccip, rebalancer]
needs: [changes]
name: Foundry Tests ${{ matrix.product }}
# See https://github.com/foundry-rs/foundry/issues/3827
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/solidity-hardhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
filters: |
src:
- 'contracts/src/!(v0.8/(llo-feeds|ccip)/**)/**/*'
- 'contracts/src/!(v0.8/(llo-feeds|ccip|rebalancer)/**)/**/*'
- 'contracts/test/**/*'
- 'contracts/package.json'
- 'contracts/pnpm-lock.yaml'
Expand Down
2 changes: 1 addition & 1 deletion contracts/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ALL_FOUNDRY_PRODUCTS contains a list of all products that have a foundry
# profile defined and use the Foundry snapshots.
ALL_FOUNDRY_PRODUCTS = llo-feeds functions shared ccip
ALL_FOUNDRY_PRODUCTS = llo-feeds functions shared ccip rebalancer

# To make a snapshot for a specific product, either set the `FOUNDRY_PROFILE` env var
# or call the target with `FOUNDRY_PROFILE=product`
Expand Down
6 changes: 6 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ test = 'src/v0.8/llo-feeds/test'
solc_version = '0.8.16'
# We cannot turn on deny_warnings = true as that will hide any CI failure

[profile.rebalancer]
optimizer_runs = 1000000
src = 'src/v0.8/rebalancer'
test = 'src/v0.8/rebalancer/test'
solc_version = '0.8.19'

[profile.shared]
optimizer_runs = 1000000
src = 'src/v0.8/shared'
Expand Down
59 changes: 21 additions & 38 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ CommitStore_verify:testPausedReverts() (gas: 18438)
CommitStore_verify:testTooManyLeavesReverts() (gas: 36830)
DefensiveExampleTest:testHappyPathSuccess() (gas: 174862)
DefensiveExampleTest:testRecovery() (gas: 399786)
E2E:testE2E_3MessagesSuccess_gas() (gas: 887876)
EVM2EVMOffRamp__releaseOrMintTokens:testRateLimitErrorsReverts() (gas: 454887)
EVM2EVMOffRamp__releaseOrMintTokens:testTokenHandlingErrorReverts() (gas: 105021)
E2E:testE2E_3MessagesSuccess_gas() (gas: 887747)
EVM2EVMOffRamp__releaseOrMintTokens:testRateLimitErrorsReverts() (gas: 454562)
EVM2EVMOffRamp__releaseOrMintTokens:testTokenHandlingErrorReverts() (gas: 104956)
EVM2EVMOffRamp__releaseOrMintTokens:testUnsupportedTokenReverts() (gas: 19784)
EVM2EVMOffRamp__releaseOrMintTokens:test_releaseOrMintTokensSuccess() (gas: 140642)
EVM2EVMOffRamp__releaseOrMintTokens:test_releaseOrMintTokensSuccess() (gas: 140577)
EVM2EVMOffRamp__report:testReportSuccess() (gas: 127276)
EVM2EVMOffRamp__trialExecute:testRateLimitErrorSuccess() (gas: 174945)
EVM2EVMOffRamp__trialExecute:testTokenHandlingErrorIsCaughtSuccess() (gas: 183267)
EVM2EVMOffRamp__trialExecute:test_trialExecuteSuccess() (gas: 236803)
EVM2EVMOffRamp__trialExecute:testRateLimitErrorSuccess() (gas: 174880)
EVM2EVMOffRamp__trialExecute:testTokenHandlingErrorIsCaughtSuccess() (gas: 183202)
EVM2EVMOffRamp__trialExecute:test_trialExecuteSuccess() (gas: 236738)
EVM2EVMOffRamp_applyPoolUpdates:testApplyPoolUpdatesSuccess() (gas: 2460841)
EVM2EVMOffRamp_applyPoolUpdates:testInvalidTokenPoolConfigReverts() (gas: 17445)
EVM2EVMOffRamp_applyPoolUpdates:testOnlyCallableByOwnerReverts() (gas: 16012)
Expand All @@ -131,22 +131,22 @@ EVM2EVMOffRamp_execute:testRouterYULCallReverts() (gas: 413652)
EVM2EVMOffRamp_execute:testSingleMessageNoTokensSuccess() (gas: 173545)
EVM2EVMOffRamp_execute:testSingleMessageToNonCCIPReceiverSuccess() (gas: 246283)
EVM2EVMOffRamp_execute:testSingleMessagesNoTokensSuccess_gas() (gas: 114672)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceStillExecutesSuccess() (gas: 324122)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceStillExecutesSuccess() (gas: 324057)
EVM2EVMOffRamp_execute:testSkippedIncorrectNonceSuccess() (gas: 51868)
EVM2EVMOffRamp_execute:testStrictUntouchedToSuccessSuccess() (gas: 130894)
EVM2EVMOffRamp_execute:testTokenDataMismatchReverts() (gas: 49702)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensAndGESuccess() (gas: 443492)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensSuccess_gas() (gas: 402592)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensAndGESuccess() (gas: 443362)
EVM2EVMOffRamp_execute:testTwoMessagesWithTokensSuccess_gas() (gas: 402462)
EVM2EVMOffRamp_execute:testUnexpectedTokenDataReverts() (gas: 33032)
EVM2EVMOffRamp_execute:testUnhealthyReverts() (gas: 420019)
EVM2EVMOffRamp_execute:testUnhealthyReverts() (gas: 419889)
EVM2EVMOffRamp_execute:testUnsupportedNumberOfTokensReverts() (gas: 61416)
EVM2EVMOffRamp_execute:testUnsupportedTokenReverts() (gas: 130374)
EVM2EVMOffRamp_executeSingleMessage:testMessageSenderReverts() (gas: 20545)
EVM2EVMOffRamp_executeSingleMessage:testNoTokensSuccess() (gas: 48033)
EVM2EVMOffRamp_executeSingleMessage:testNonContractSuccess() (gas: 20105)
EVM2EVMOffRamp_executeSingleMessage:testNonContractWithTokensSuccess() (gas: 205128)
EVM2EVMOffRamp_executeSingleMessage:testTokenHandlingErrorReverts() (gas: 140043)
EVM2EVMOffRamp_executeSingleMessage:testTokensSuccess() (gas: 234088)
EVM2EVMOffRamp_executeSingleMessage:testNonContractWithTokensSuccess() (gas: 205063)
EVM2EVMOffRamp_executeSingleMessage:testTokenHandlingErrorReverts() (gas: 139978)
EVM2EVMOffRamp_executeSingleMessage:testTokensSuccess() (gas: 234023)
EVM2EVMOffRamp_executeSingleMessage:testZeroGasDONExecutionReverts() (gas: 48581)
EVM2EVMOffRamp_execute_upgrade:testV2NonceNewSenderStartsAtZeroSuccess() (gas: 232107)
EVM2EVMOffRamp_execute_upgrade:testV2NonceStartsAtV1NonceSuccess() (gas: 280032)
Expand All @@ -165,7 +165,7 @@ EVM2EVMOffRamp_manuallyExecute:testManualExecGasLimitMismatchReverts() (gas: 436
EVM2EVMOffRamp_manuallyExecute:testManualExecInvalidGasLimitReverts() (gas: 26052)
EVM2EVMOffRamp_manuallyExecute:testManualExecSuccess() (gas: 189664)
EVM2EVMOffRamp_manuallyExecute:testManualExecWithGasOverrideSuccess() (gas: 190291)
EVM2EVMOffRamp_manuallyExecute:testReentrancyManualExecuteFAILS() (gas: 1835242)
EVM2EVMOffRamp_manuallyExecute:testReentrancyManualExecuteFAILS() (gas: 1835177)
EVM2EVMOffRamp_metadataHash:testMetadataHashSuccess() (gas: 6086)
EVM2EVMOffRamp_setDynamicConfig:testNonOwnerReverts() (gas: 44539)
EVM2EVMOffRamp_setDynamicConfig:testRouterZeroAddressReverts() (gas: 38587)
Expand Down Expand Up @@ -265,13 +265,13 @@ EVM2EVMOnRamp_withdrawNonLinkFees:testNonOwnerOrAdminReverts() (gas: 19487)
EVM2EVMOnRamp_withdrawNonLinkFees:testSettlingBalanceSuccess() (gas: 244922)
EVM2EVMOnRamp_withdrawNonLinkFees:testWithdrawNonLinkFeesSuccess() (gas: 50139)
EVM2EVMOnRamp_withdrawNonLinkFees:testWithdrawToZeroAddressReverts() (gas: 12887)
LockReleaseTokenPool_canAcceptLiquidity:test_CanAcceptLiquiditySuccess() (gas: 2421807)
LockReleaseTokenPool_lockOrBurn:testLockOrBurnWithAllowListReverts() (gas: 23423)
LockReleaseTokenPool_lockOrBurn:testLockOrBurnWithAllowListSuccess() (gas: 60780)
LockReleaseTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 66459)
LockReleaseTokenPool_canAcceptLiquidity:test_CanAcceptLiquiditySuccess() (gas: 2421851)
LockReleaseTokenPool_lockOrBurn:testLockOrBurnWithAllowListReverts() (gas: 23445)
LockReleaseTokenPool_lockOrBurn:testLockOrBurnWithAllowListSuccess() (gas: 60824)
LockReleaseTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 66481)
LockReleaseTokenPool_provideLiquidity:testLiquidityNotAcceptedReverts() (gas: 2421431)
LockReleaseTokenPool_releaseOrMint:testPoolMintNotHealthyReverts() (gas: 57852)
LockReleaseTokenPool_supportsInterface:testSupportsInterfaceSuccess() (gas: 8447)
LockReleaseTokenPool_releaseOrMint:testPoolMintNotHealthyReverts() (gas: 57787)
LockReleaseTokenPool_supportsInterface:testSupportsInterfaceSuccess() (gas: 8469)
LockReleaseTokenPool_withdrawalLiquidity:testInsufficientLiquidityReverts() (gas: 64456)
MerkleMultiProofTest:testCVE_2023_34459() (gas: 5458)
MerkleMultiProofTest:testEmptyLeafReverts() (gas: 3575)
Expand Down Expand Up @@ -303,23 +303,6 @@ OCR2Base_transmit:testTransmit2SignersSuccess_gas() (gas: 51747)
OCR2Base_transmit:testUnAuthorizedTransmitterReverts() (gas: 23447)
OCR2Base_transmit:testUnauthorizedSignerReverts() (gas: 43673)
OCR2Base_transmit:testWrongNumberOfSignaturesReverts() (gas: 20513)
OCR3Base_setOCR3Config:testFMustBePositiveReverts() (gas: 12272)
OCR3Base_setOCR3Config:testFTooHighReverts() (gas: 12456)
OCR3Base_setOCR3Config:testOracleOutOfRegisterReverts() (gas: 14985)
OCR3Base_setOCR3Config:testRepeatAddressReverts() (gas: 45226)
OCR3Base_setOCR3Config:testSetConfigSuccess_gas() (gas: 154872)
OCR3Base_setOCR3Config:testSignerCannotBeZeroAddressReverts() (gas: 24254)
OCR3Base_setOCR3Config:testTooManySignersReverts() (gas: 20243)
OCR3Base_setOCR3Config:testTransmitterCannotBeZeroAddressReverts() (gas: 47104)
OCR3Base_transmit:testConfigDigestMismatchReverts() (gas: 24803)
OCR3Base_transmit:testForkedChainReverts() (gas: 46935)
OCR3Base_transmit:testNonIncreasingSequenceNumberReverts() (gas: 30510)
OCR3Base_transmit:testNonUniqueSignatureReverts() (gas: 64804)
OCR3Base_transmit:testSignatureOutOfRegistrationReverts() (gas: 26109)
OCR3Base_transmit:testTransmit2SignersSuccess_gas() (gas: 56921)
OCR3Base_transmit:testUnAuthorizedTransmitterReverts() (gas: 28599)
OCR3Base_transmit:testUnauthorizedSignerReverts() (gas: 48847)
OCR3Base_transmit:testWrongNumberOfSignaturesReverts() (gas: 25665)
OnRampTokenPoolReentrancy:testSuccess() (gas: 334413)
PingPong_ccipReceive:testCcipReceiveSuccess() (gas: 145351)
PingPong_plumbing:testPausingSuccess() (gas: 14605)
Expand Down
21 changes: 21 additions & 0 deletions contracts/gas-snapshots/rebalancer.gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OCR3Base_setOCR3Config:testFMustBePositiveReverts() (gas: 12269)
OCR3Base_setOCR3Config:testFTooHighReverts() (gas: 12420)
OCR3Base_setOCR3Config:testOracleOutOfRegisterReverts() (gas: 14838)
OCR3Base_setOCR3Config:testRepeatAddressReverts() (gas: 44935)
OCR3Base_setOCR3Config:testSetConfigSuccess_gas() (gas: 154772)
OCR3Base_setOCR3Config:testSignerCannotBeZeroAddressReverts() (gas: 23717)
OCR3Base_setOCR3Config:testTooManySignersReverts() (gas: 19838)
OCR3Base_setOCR3Config:testTransmitterCannotBeZeroAddressReverts() (gas: 46567)
OCR3Base_transmit:testConfigDigestMismatchReverts() (gas: 24788)
OCR3Base_transmit:testForkedChainReverts() (gas: 46905)
OCR3Base_transmit:testNonIncreasingSequenceNumberReverts() (gas: 30480)
OCR3Base_transmit:testNonUniqueSignatureReverts() (gas: 64488)
OCR3Base_transmit:testSignatureOutOfRegistrationReverts() (gas: 26088)
OCR3Base_transmit:testTransmit2SignersSuccess_gas() (gas: 56900)
OCR3Base_transmit:testUnAuthorizedTransmitterReverts() (gas: 28578)
OCR3Base_transmit:testUnauthorizedSignerReverts() (gas: 48820)
OCR3Base_transmit:testWrongNumberOfSignaturesReverts() (gas: 25641)
Rebalancer_rebalanceLiquidity:test_InsufficientLiquidityReverts() (gas: 18832)
Rebalancer_rebalanceLiquidity:test_InvalidRemoteChainReverts() (gas: 161746)
Rebalancer_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess() (gas: 6897851)
Rebalancer_rebalanceLiquidity:test_rebalanceLiquiditySuccess() (gas: 338100)
2 changes: 1 addition & 1 deletion contracts/gas-snapshots/shared.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CallWithExactGas__callWithExactGas:test_CallWithExactGasSafeReturnDataExactGas()
CallWithExactGas__callWithExactGas:test_NoContractReverts() (gas: 11559)
CallWithExactGas__callWithExactGas:test_NoGasForCallExactCheckReverts() (gas: 12908)
CallWithExactGas__callWithExactGas:test_NotEnoughGasForCallReverts() (gas: 13361)
CallWithExactGas__callWithExactGas:test_callWithExactGasSuccess(bytes,bytes4) (runs: 256, μ: 15477, ~: 15418)
CallWithExactGas__callWithExactGas:test_callWithExactGasSuccess(bytes,bytes4) (runs: 256, μ: 15478, ~: 15418)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractExactGasSuccess() (gas: 19147)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractReceiverErrorSuccess() (gas: 67096)
CallWithExactGas__callWithExactGasEvenIfTargetIsNoContract:test_CallWithExactGasEvenIfTargetIsNoContractSuccess(bytes,bytes4) (runs: 256, μ: 15675, ~: 15616)
Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
},
"dependencies": {
"@eth-optimism/contracts": "0.6.0",
"@arbitrum/token-bridge-contracts": "1.1.2",
"@scroll-tech/contracts": "0.1.0",
"@openzeppelin/contracts": "4.9.3",
"@openzeppelin/contracts-upgradeable": "4.9.3"
Expand Down
Loading

0 comments on commit 1458510

Please sign in to comment.