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

Deposit to ERC4626 Vaults #71

Merged
merged 36 commits into from
Jan 3, 2024
Merged

Deposit to ERC4626 Vaults #71

merged 36 commits into from
Jan 3, 2024

Conversation

dimpar
Copy link
Member

@dimpar dimpar commented Dec 8, 2023

  • Added allocation functionality that deposits a single asset (tBTC) to an authorized vault
  • Added and adjusted deployment scripts
  • Changed unit tests and added an integration test that validates the flow of assets from Acre contract through Dispatcher that deposits assets to an authorized ERC4626 Vault

@dimpar dimpar requested review from nkuba and r-czajkowski December 8, 2023 16:43
@dimpar dimpar self-assigned this Dec 8, 2023
@dimpar dimpar changed the base branch from main to vaults-acre-router December 8, 2023 17:03
Renamed AcreRouter to Dispatcher and introduced an abstract contract
called Router that will handle moving funds between Acre and Vaults.

In order to deposit / redeem assets, Acre contract should approve assets
for Dispatcher to spend and call depositToVault or redeemFromVault
functions. These Acre's functions can be also called by a bot for
rebalancing purposes.
@dimpar dimpar force-pushed the deposit-redeem-to-vaults branch from f1f439d to 54a1562 Compare December 12, 2023 14:49
@dimpar dimpar force-pushed the deposit-redeem-to-vaults branch from c0485d9 to 1166e5e Compare December 12, 2023 21:53
Base automatically changed from vaults-acre-router to test-fixtures December 13, 2023 07:41
Base automatically changed from test-fixtures to main December 13, 2023 08:50
@dimpar dimpar changed the title Deposit and redeem assets to/from ERC4626 Vaults Deposit to ERC4626 Vaults Dec 28, 2023
@dimpar dimpar marked this pull request as ready for review December 28, 2023 14:09
Copy link
Member

@nkuba nkuba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed contracts and deployment scripts. Will get back to tests in the next review round.

core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/deploy/11_update_dispatcher.ts Outdated Show resolved Hide resolved
core/deploy/11_update_dispatcher.ts Outdated Show resolved Hide resolved
core/deploy/12_update_maintainer.ts Outdated Show resolved Hide resolved
core/deploy/12_update_maintainer.ts Outdated Show resolved Hide resolved
core/hardhat.config.ts Outdated Show resolved Hide resolved
core/contracts/Acre.sol Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/test/integration/AssetFlows.test.ts Outdated Show resolved Hide resolved
core/test/integration/AssetFlows.test.ts Outdated Show resolved Hide resolved
Comment on lines 53 to 54
const assetsToAllocate = to1e18(100)
const minSharesOut = to1e18(100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use different value for minSharesOut to be able to test if the Router actually enforces the check.

Suggested change
const assetsToAllocate = to1e18(100)
const minSharesOut = to1e18(100)
const assetsToAllocate = to1e18(100)
const expectedSharesOut = assetsToAllocate
const minSharesOut = expectedSharesOut - 1n

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is checked in when allocation is not successful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename the test name then, to be clear, what scenario we are covering, "when allocation is not successful" feels too general.

core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/contracts/Acre.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/deploy/00_resolve_testing_erc4626.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Outdated Show resolved Hide resolved
core/test/Acre.test.ts Show resolved Hide resolved
describe("updateDispatcher", () => {
context("when caller is not an owner", () => {
it("should revert", async () => {
await expect(acre.connect(staker1).updateDispatcher(ZeroAddress))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get one more signer named thirdParty from getUnnamedSigner() function call in the fixture setup and use it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core/test/Acre.test.ts Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
dimpar added 2 commits January 3, 2024 13:57
Added test to Deployment.test.ts checking the initial state right after
the deployment scripts execution.
nkuba
nkuba previously approved these changes Jan 3, 2024
Copy link
Member

@nkuba nkuba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM I left a non-blocking comment.

Comment on lines 27 to 32
let governance: HardhatEthersSigner
let thirdParty: HardhatEthersSigner
let maintainer: HardhatEthersSigner
let vault: TestERC4626
let acre: Acre
let tbtc: TestERC20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move contract vars definition above signers for consistency?

  let acre: Acre
  let tbtc: TestERC20
  let vault: TestERC4626

  let governance: HardhatEthersSigner
  let thirdParty: HardhatEthersSigner
  let maintainer: HardhatEthersSigner

@nkuba nkuba enabled auto-merge January 3, 2024 14:58
core/contracts/Router.sol Outdated Show resolved Hide resolved
core/contracts/Router.sol Outdated Show resolved Hide resolved
core/contracts/Dispatcher.sol Outdated Show resolved Hide resolved
core/test/Deployment.test.ts Outdated Show resolved Hide resolved
core/test/Deployment.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
core/test/Dispatcher.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@r-czajkowski r-czajkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@nkuba nkuba merged commit 6463c79 into main Jan 3, 2024
11 checks passed
@nkuba nkuba deleted the deposit-redeem-to-vaults branch January 3, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants