-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drafting integration flows for assets
- Loading branch information
Showing
7 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.21; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol"; | ||
|
||
contract TestERC4626 is ERC4626 { | ||
constructor( | ||
IERC20 asset, | ||
string memory tokenName, | ||
string memory tokenSymbol | ||
) ERC4626(asset) ERC20(tokenName, tokenSymbol) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { HardhatRuntimeEnvironment } from "hardhat/types" | ||
import type { DeployFunction } from "hardhat-deploy/types" | ||
|
||
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { | ||
const { getNamedAccounts, deployments } = hre | ||
const { log } = deployments | ||
const { deployer } = await getNamedAccounts() | ||
|
||
const tBTC = await deployments.get("TBTC") | ||
|
||
if (hre.network.tags.allowStubs) { | ||
log("deploying Mock ERC4626 Vault") | ||
|
||
await deployments.deploy("Vault", { | ||
contract: "TestERC4626", | ||
from: deployer, | ||
args: [tBTC.address, "MockVault", "MV"], | ||
log: true, | ||
waitConfirmations: 1, | ||
}) | ||
} | ||
} | ||
|
||
export default func | ||
|
||
func.tags = ["TestERC4626"] | ||
func.dependencies = ["TBTC"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { ethers } from "hardhat" | ||
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" | ||
import { expect } from "chai" | ||
import { | ||
SnapshotRestorer, | ||
takeSnapshot, | ||
loadFixture, | ||
} from "@nomicfoundation/hardhat-toolbox/network-helpers" | ||
import type { Acre, Dispatcher, TestERC4626, TestERC20 } from "../../typechain" | ||
import { deployment } from "../helpers/context" | ||
import { getNamedSigner, getUnnamedSigner } from "../helpers/signer" | ||
import { to1e18 } from "../utils" | ||
|
||
async function fixture() { | ||
const { tbtc, acre, dispatcher, vault } = await deployment() | ||
const { governance } = await getNamedSigner() | ||
const [thirdParty] = await getUnnamedSigner() | ||
|
||
return { acre, dispatcher, governance, thirdParty, vault, tbtc } | ||
} | ||
|
||
describe.only("Integration Test - Asset Flows", () => { | ||
let snapshot: SnapshotRestorer | ||
|
||
let dispatcher: Dispatcher | ||
let acre: Acre | ||
let vault: TestERC4626 | ||
let tbtc: TestERC20 | ||
let governance: HardhatEthersSigner | ||
let thirdParty: HardhatEthersSigner | ||
|
||
before(async () => { | ||
;({ acre, dispatcher, governance, thirdParty, vault, tbtc } = await loadFixture(fixture)) | ||
|
||
await dispatcher.connect(governance).authorizeVault(vault.getAddress()) | ||
await tbtc.mint(acre.getAddress(), to1e18(100000)) | ||
}) | ||
|
||
beforeEach(async () => { | ||
snapshot = await takeSnapshot() | ||
}) | ||
|
||
afterEach(async () => { | ||
await snapshot.restore() | ||
}) | ||
|
||
|
||
describe("depositToVault", () => { | ||
const tbtcToDeposit = to1e18(100) | ||
const shares = to1e18(100) | ||
|
||
context("when caller is not Acre (stBTC)", () => { | ||
it("should revert when depositing to a vault", async () => { | ||
await expect( | ||
dispatcher.connect(thirdParty).depositToVault(vault.getAddress(), tbtcToDeposit, shares), | ||
).to.be.revertedWithCustomError( | ||
Check failure on line 56 in core/test/integration/AssetFlows.test.ts GitHub Actions / core-format
|
||
dispatcher, | ||
"CallerUnauthorized", | ||
).withArgs("Acre only") | ||
}) | ||
}) | ||
|
||
context("when caller is Acre (stBTC)", () => { | ||
it("should revert when vault is unauthorized", async () => { | ||
const randomAddress = await ethers.Wallet.createRandom().getAddress() | ||
await expect( | ||
acre.depositToVault(randomAddress, tbtcToDeposit, shares), | ||
).to.be.revertedWithCustomError( | ||
dispatcher, | ||
"VaultUnauthorized", | ||
) | ||
}) | ||
|
||
it("should be able to deposit to an authorized vault", async () => { | ||
await acre.depositToVault(vault.getAddress(), tbtcToDeposit, shares) | ||
|
||
expect(await tbtc.balanceOf(vault.getAddress())).to.equal(tbtcToDeposit) | ||
}) | ||
|
||
it("should be able to receive vault's shares", async () => { | ||
await acre.depositToVault(vault.getAddress(), tbtcToDeposit, shares) | ||
|
||
expect(await vault.balanceOf(acre.getAddress())).to.equal(shares) | ||
}) | ||
|
||
// TODO: add more tests | ||
}) | ||
}) | ||
|
||
describe("redeemFromVault", () => { | ||
// TODO: add tests | ||
}) | ||
}) |