-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VAL-139 Missing Sanity Checks (#176)
* Add validation that Loans cannot be created with a liquidity asset that does not match its corresponding Pool asset. * Add validation that serviceFeeBps for Pools cannot exceed 100% * Add semi-duplicative require statement enforcing maxRedeem() constraint in redeem() * Add missing require statements to the Factories. Update mock contracts to reflect added validation done in the Loan in prior commit. * Code review
- Loading branch information
Showing
11 changed files
with
175 additions
and
10 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
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
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,94 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
import { activatePool, deployPool, deployVaultFactory } from "../support/pool"; | ||
import { DEFAULT_LOAN_SETTINGS } from "../support/loan"; | ||
import { getCommonSigners } from "../support/utils"; | ||
import { deployMockERC20 } from "../support/erc20"; | ||
|
||
describe("LoanFactory", () => { | ||
async function deployLoanFactoryFixture() { | ||
const { deployer, operator, pauser, poolAdmin, borrower } = | ||
await getCommonSigners(); | ||
|
||
// Create a pool | ||
const { pool, liquidityAsset, serviceConfiguration } = await deployPool({ | ||
poolAdmin: poolAdmin, | ||
pauser | ||
}); | ||
|
||
// Create a difference ERC20 | ||
const { mockERC20: otherMockERC2O } = await deployMockERC20( | ||
"OtherTestToken", | ||
"OTT" | ||
); | ||
|
||
await activatePool(pool, poolAdmin, liquidityAsset); | ||
|
||
const LoanLib = await ethers.getContractFactory("LoanLib"); | ||
const loanLib = await LoanLib.deploy(); | ||
|
||
const vaultFactory = await deployVaultFactory(serviceConfiguration.address); | ||
|
||
const LoanFactory = await ethers.getContractFactory("LoanFactory"); | ||
const loanFactory = await LoanFactory.deploy( | ||
serviceConfiguration.address, | ||
vaultFactory.address | ||
); | ||
await loanFactory.deployed(); | ||
|
||
await serviceConfiguration | ||
.connect(operator) | ||
.setLoanFactory(loanFactory.address, true); | ||
|
||
// Deploy Loan implementation contract | ||
const LoanImpl = await ethers.getContractFactory("Loan", { | ||
libraries: { | ||
LoanLib: loanLib.address | ||
} | ||
}); | ||
const loanImpl = await LoanImpl.deploy(); | ||
|
||
// Set implementation on the LoanFactory | ||
await loanFactory.connect(deployer).setImplementation(loanImpl.address); | ||
|
||
return { | ||
loanFactory, | ||
borrower, | ||
pool, | ||
liquidityAsset, | ||
otherMockERC2O, | ||
serviceConfiguration, | ||
operator | ||
}; | ||
} | ||
|
||
describe("createLoan()", () => { | ||
it("reverts if liquidity asset doesn't match the pool", async () => { | ||
const { | ||
loanFactory, | ||
borrower, | ||
pool, | ||
otherMockERC2O, | ||
serviceConfiguration, | ||
operator | ||
} = await loadFixture(deployLoanFactoryFixture); | ||
|
||
// Set otherMockERC20 as a supported currency in the protocol | ||
// However, it's still mismatched with the pool, so we expect creating the loan to fail | ||
await serviceConfiguration | ||
.connect(operator) | ||
.setLiquidityAsset(otherMockERC2O.address, true); | ||
expect(await pool.asset()).to.not.equal(otherMockERC2O.address); | ||
|
||
await expect( | ||
loanFactory.createLoan( | ||
borrower.address, | ||
pool.address, | ||
otherMockERC2O.address, | ||
DEFAULT_LOAN_SETTINGS | ||
) | ||
).to.be.revertedWith("LoanLib: Not allowed asset for pool"); | ||
}); | ||
}); | ||
}); |
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,35 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
import { getCommonSigners } from "../support/utils"; | ||
import { deployServiceConfiguration } from "../support/serviceconfiguration"; | ||
|
||
describe("VaultFactory", () => { | ||
async function deployVaultFactoryFixture() { | ||
const { deployer, other } = await getCommonSigners(); | ||
const { serviceConfiguration } = await deployServiceConfiguration(); | ||
|
||
const Factory = await ethers.getContractFactory("VaultFactory"); | ||
const factory = await Factory.deploy(serviceConfiguration.address); | ||
|
||
// Create Vault implementation | ||
const Vault = await ethers.getContractFactory("Vault"); | ||
const vault = await Vault.deploy(); | ||
return { | ||
vault, | ||
factory, | ||
deployer, | ||
other | ||
}; | ||
} | ||
|
||
describe("createVault()", () => { | ||
it("reverts if no implementation is set", async () => { | ||
const { factory, other } = await loadFixture(deployVaultFactoryFixture); | ||
|
||
await expect(factory.createVault(other.address)).to.be.revertedWith( | ||
"VaultFactory: no implementation set" | ||
); | ||
}); | ||
}); | ||
}); |
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