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

VAL-112 Prevent creating pools with unsupported asset types #112

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions contracts/PoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ contract PoolFactory is IPoolFactory {
settings.requestCancellationFeeBps <= 10_000,
"PoolFactory: Invalid request cancellation fee"
);
require(
IServiceConfiguration(_serviceConfiguration).isLiquidityAsset(
liquidityAsset
),
"PoolFactory: invalid asset"
);

// Create the pool
Pool pool = new Pool(
Expand Down
6 changes: 5 additions & 1 deletion contracts/ServiceConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration {
/**
* @dev Set a liquidity asset as valid or not.
*/
function setLiquidityAsset(address addr, bool value) public onlyOperator {
function setLiquidityAsset(address addr, bool value)
public
override
onlyOperator
{
isLiquidityAsset[addr] = value;
emit LiquidityAssetSet(addr, value);
}
Expand Down
7 changes: 7 additions & 0 deletions contracts/interfaces/IServiceConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ interface IServiceConfiguration is IAccessControl {
* @param value amount of each payment that is allocated to the first loss vault. Value is in basis points, e.g. 500 equals 5%.
*/
function setFirstLossFeeBps(uint256 value) external;

/**
* @dev Sets supported liquidity assets for the protocol. Callable by the operator.
* @param addr Address of liquidity asset
* @param value Whether supported or not
*/
function setLiquidityAsset(address addr, bool value) external;
}
21 changes: 15 additions & 6 deletions test/PoolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
deployPoolControllerFactory,
deployWithdrawControllerFactory
} from "./support/pool";
import { deployServiceConfiguration } from "./support/serviceconfiguration";

describe("PoolFactory", () => {
async function deployFixture() {
Expand All @@ -17,12 +18,10 @@ describe("PoolFactory", () => {
const { mockERC20: liquidityAsset } = await deployMockERC20();

// Deploy the Service Configuration contract
const ServiceConfiguration = await ethers.getContractFactory(
"ServiceConfiguration",
operator
);
const serviceConfiguration = await ServiceConfiguration.deploy();
await serviceConfiguration.deployed();
const { serviceConfiguration } = await deployServiceConfiguration(operator);

// Add ERC20 as support currency
await serviceConfiguration.setLiquidityAsset(liquidityAsset.address, true);

const PoolLib = await ethers.getContractFactory("PoolLib");
const poolLib = await PoolLib.deploy();
Expand Down Expand Up @@ -131,6 +130,16 @@ describe("PoolFactory", () => {
).to.be.revertedWith("PoolFactory: Invalid request cancellation fee");
});

it("reverts if liquidity asset is not supported", async () => {
const { poolFactory } = await loadFixture(deployFixture);

const { mockERC20: otherAsset } = await deployMockERC20();

await expect(
poolFactory.createPool(otherAsset.address, DEFAULT_POOL_SETTINGS)
).to.be.revertedWith("PoolFactory: invalid asset");
});

it("emits PoolCreated", async () => {
const { poolFactory, liquidityAsset } = await loadFixture(deployFixture);

Expand Down