Skip to content

Commit

Permalink
implemented integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrbch committed Oct 24, 2024
1 parent 7eb47d4 commit b40416a
Show file tree
Hide file tree
Showing 22 changed files with 4,980 additions and 50 deletions.
16 changes: 1 addition & 15 deletions add-collateral.json
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
{
"51": {
"tokenAddress": "0x0000000000000000000000000000000000000000",
"testOracle": "0x0000000000000000000000000000000000000000",
"fathomProxyFactory": "0x0000000000000000000000000000000000000000",
"fathomProxyAdmin": "0x0000000000000000000000000000000000000000"
},
"31337": {
"tokenAddress": "0x0000000000000000000000000000000000000000",
"testOracle": "0x0000000000000000000000000000000000000000",
"fathomProxyFactory": "0x0000000000000000000000000000000000000000",
"fathomProxyAdmin": "0x0000000000000000000000000000000000000000"
},
"token": "GLD"
}
{"51":{"tokenAddress":"0x0000000000000000000000000000000000000000","testOracle":"0x0000000000000000000000000000000000000000","fathomProxyFactory":"0x0000000000000000000000000000000000000000","fathomProxyAdmin":"0x0000000000000000000000000000000000000000"},"31337":{"tokenAddress":"0x828e4F72BC7B912f6Fde900071212aAA075BBd22","testOracle":"0x0dC763b6a547deb5ED263cdf26B5e4D456989582","fathomProxyFactory":"0x28c6408131836B0f1Adbae443b65B76487723C4b","fathomProxyAdmin":"0xc38d2D6bc857129aAAd365eDae5f7f286f4Ce994"},"token":"GLD"}
6 changes: 3 additions & 3 deletions common/collateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const { formatBytes32String } = ethers.utils;

const USD_STABLE = formatBytes32String("USD-STABLE");
const FTHM = formatBytes32String("FTHM");
const WNATIVE = formatBytes32String("WNATIVE");
const NATIVE = formatBytes32String("NATIVE");
const WXDC = formatBytes32String("WXDC");
const XDC = formatBytes32String("XDC");
const GLD = formatBytes32String("GLD");
const USD_COL = formatBytes32String("USD-COL");

module.exports = { NATIVE, FTHM, WNATIVE, USD_COL, USD_STABLE, GLD };
module.exports = { XDC, FTHM, WXDC, USD_COL, USD_STABLE, GLD };
2 changes: 1 addition & 1 deletion deploy/deploy-add-collateral/01_deploy_add_collateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { configPool } = require("../../scripts/configuration/add-collateral/confi

module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
// Setup
await deploy(getNamedAccounts, deployments);
await deploy(getNamedAccounts, deployments, getChainId);
await deployProxies(deployments, getChainId);
await initialize(getChainId);
await addRoles(getChainId);
Expand Down
6 changes: 3 additions & 3 deletions deploy/deploy-main/01_deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const { addCollateralPools } = require("../../scripts/configuration/deploy/addCo

module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
// Setup
await deployContracts(getNamedAccounts, deployments);
await deployProxies(deployments);
await deployContracts(getNamedAccounts, deployments, getChainId);
await deployProxies(deployments, getChainId);
await initialize(deployments, getChainId);
await addRoles(deployments);
await addRoles(deployments, getChainId);
await configureFees(deployments);
await configureShowStopper(deployments);
await deployVault(getNamedAccounts, deployments, getChainId);
Expand Down
8 changes: 4 additions & 4 deletions deploy/deploy-test-fixture/01_deploy_test_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const { deployVault: deployVaultAddCollateral } = require("../../scripts/setup/a
module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
// Setup
await deployMocks(getNamedAccounts, deployments, getChainId);
await deployContracts(getNamedAccounts, deployments);
await deployProxies(deployments);
await deployContracts(getNamedAccounts, deployments, getChainId);
await deployProxies(deployments, getChainId);
await initialize(deployments, getChainId, true);
await addRoles(deployments);
await addRoles(deployments, getChainId);
await configureFees(deployments);
await configureShowStopper(deployments);
await deployVault(getNamedAccounts, deployments, getChainId, true);
Expand All @@ -55,7 +55,7 @@ module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
await addCollateralPreDeployment(getNamedAccounts, deployments, getChainId);

// Add collateral
await deploy(getNamedAccounts, deployments);
await deploy(getNamedAccounts, deployments, getChainId);
await deployProxiesAddCollateral(deployments, getChainId, true);
await initializeAddCollateral(getChainId, true);
await addRolesAddCollateral(getChainId, true);
Expand Down
2 changes: 2 additions & 0 deletions scripts/setup/add-collateral/deploy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { usePlugin } = require("../../../common/add-collateral-helper");

async function deploy(getNamedAccounts, deployments, getChainId) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup/add-collateral/deployVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function deployVault(getNamedAccounts, deployments, getChainId, forFixture

let tokenAddress;
if (forFixture) {
const ERC20 = await deployments.get("ERC20");
const ERC20 = await deployments.get("GLD");
tokenAddress = ERC20.address;
} else {
tokenAddress = config.tokenAddress;
Expand Down
7 changes: 2 additions & 5 deletions scripts/setup/add-collateral/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,18 @@ async function initialize(getChainId, forFixture = false) {
delayFathomOraclePriceFeed: delayFathomOraclePriceFeed.address,
};

let tokenAddress, usdAddress, dexFactoryAddress;
let tokenAddress, usdAddress;
if (forFixture) {
const GLD = await deployments.get("GLD");
const USD = await deployments.get("USD");
const DEXFactory = await deployments.get("DEXFactory");
tokenAddress = GLD.address;
usdAddress = USD.address;
dexFactoryAddress = DEXFactory.address;
} else {
tokenAddress = config.tokenAddress;
usdAddress = addresses.USD;
dexFactoryAddress = addresses.DEXFactory;
}

await dexPriceOracle.initialize(dexFactoryAddress);
await dexPriceOracle.initialize(addresses.DEXFactory);
await collateralTokenAdapter.initialize(bookKeeper.address, poolId, tokenAddress, proxyWalletFactory.address);
delayFathomOraclePriceFeed.initialize(dexPriceOracle.address, tokenAddress, usdAddress, accessControlConfig.address, poolId);
fs.writeFileSync(`./addresses_${token}.json`, JSON.stringify(newAddresses));
Expand Down
21 changes: 16 additions & 5 deletions scripts/setup/deploy/addRoles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { ethers } = require("hardhat");
const { getProxy } = require("../../../common/proxies");

async function addRoles(deployments) {
async function addRoles(deployments, getChainId) {
const chainId = await getChainId();

const ProxyFactory = await deployments.get("FathomProxyFactory");
const proxyFactory = await ethers.getContractAt("FathomProxyFactory", ProxyFactory.address);

Expand All @@ -20,8 +22,14 @@ async function addRoles(deployments) {
const collateralTokenAdapter = await getProxy(proxyFactory, "CollateralTokenAdapter");
const systemDebtEngine = await getProxy(proxyFactory, "SystemDebtEngine");
const adminControls = await getProxy(proxyFactory, "AdminControls");
// TODO
const fathomBridge = await getProxy(proxyFactory, "FathomBridge");

let fathomBridge;
if (chainId !== "31337") {
// Get FathomBridge Proxy only on testnet/mainnet
fathomBridge = await getProxy(proxyFactory, "FathomBridge");
} else {
fathomBridge = null;
}

await accessControlConfig.grantRole(await accessControlConfig.BOOK_KEEPER_ROLE(), bookKeeper.address);

Expand Down Expand Up @@ -50,8 +58,11 @@ async function addRoles(deployments) {

await accessControlConfig.grantRole(await accessControlConfig.COLLATERAL_MANAGER_ROLE(), systemDebtEngine.address);

// TODO
await fathomStablecoin.grantRole(await fathomStablecoin.MINTER_ROLE(), fathomBridge.address);
// Grant MINTER_ROLE to FathomBridge only on testnet/mainnet
if (chainId !== "31337") {
await fathomStablecoin.grantRole(await fathomStablecoin.MINTER_ROLE(), fathomBridge.address);
}

await fathomStablecoin.grantRole(await fathomStablecoin.MINTER_ROLE(), stablecoinAdapter.address);

await accessControlConfig.grantRole(await accessControlConfig.GOV_ROLE(), adminControls.address);
Expand Down
16 changes: 10 additions & 6 deletions scripts/setup/deploy/deployContracts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
async function deployContracts(getNamedAccounts, deployments) {
async function deployContracts(getNamedAccounts, deployments, getChainId) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = await getChainId();

await deploy("AccessControlConfig", {
from: deployer,
Expand Down Expand Up @@ -152,11 +153,14 @@ async function deployContracts(getNamedAccounts, deployments) {
args: [],
log: true,
});
await deploy("FathomBridge", {
from: deployer,
args: [],
log: true,
});
// Deploy FathomBridge only on testnet/mainnet
if (chainId !== "31337") {
await deploy("FathomBridge", {
from: deployer,
args: [],
log: true,
});
}
}

module.exports = {
Expand Down
12 changes: 10 additions & 2 deletions scripts/setup/deploy/deployProxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ const contracts = [
"CentralizedOraclePriceFeed",
"StableSwapModuleWrapper",
"SimplePriceFeed",
"FathomBridge",
// "FathomBridge",
];

async function deployProxies(deployments) {
async function deployProxies(deployments, getChainId) {
const chainId = await getChainId();

const fathomProxyFactory = await deployments.get("FathomProxyFactory");
const fathomProxyFactoryAddress = fathomProxyFactory.address;

Expand All @@ -46,6 +48,12 @@ async function deployProxies(deployments) {
return fathomProxyFactoryContract.createProxy(formatBytes32String(contract), instance.address, fathomProxyAdminAddress, "0x");
})
);

// Create FathomBridge Proxy only on testnet/mainnet
if (chainId !== "31337") {
const instance = await deployments.get("FathomBridge");
await fathomProxyFactoryContract.createProxy(formatBytes32String("FathomBridge"), instance.address, fathomProxyAdminAddress, "0x");
}
}

module.exports = {
Expand Down
24 changes: 19 additions & 5 deletions scripts/setup/deploy/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ async function initialize(deployments, getChainId, forFixture = false) {
const stableSwapModuleWrapper = await getProxy(proxyFactory, "StableSwapModuleWrapper");
const simplePriceFeed = await getProxy(proxyFactory, "SimplePriceFeed");
const slidingWindowDexOracle = await getProxy(proxyFactory, "SlidingWindowDexOracle");
// TODO
const fathomBridge = await getProxy(proxyFactory, "FathomBridge");

let fathomBridge;
if (chainId !== "31337") {
// Get FathomBridge Proxy only on testnet/mainnet
fathomBridge = await getProxy(proxyFactory, "FathomBridge");
} else {
fathomBridge = null;
}

const fathomStablecoinProxyActions = await ethers.getContractAt("FathomStablecoinProxyActions", FathomStablecoinProxyActions.address);

Expand Down Expand Up @@ -120,8 +126,12 @@ async function initialize(deployments, getChainId, forFixture = false) {
);
await simplePriceFeed.initialize(accessControlConfig.address);
// await slidingWindowDexOracle.initialize(addresses.DEXFactory, 1800, 15);
// TODO
await fathomBridge.initialize(addresses.AsterizmInitializerLib, fathomStablecoin.address, accessControlConfig.address);

// Initialize FathomBridge Proxy only on testnet/mainnet
if (chainId !== "31337") {
await fathomBridge.initialize(addresses.AsterizmInitializerLib, fathomStablecoin.address, accessControlConfig.address);
console.log("FathomBridge initialized");
}

const newAddresses = {
proxyFactory: proxyFactory.address,
Expand Down Expand Up @@ -153,9 +163,13 @@ async function initialize(deployments, getChainId, forFixture = false) {
proxyActionsStorage: proxyActionsStorage.address,
fathomProxyAdmin: proxyAdmin.address,
slidingWindowDexOracle: slidingWindowDexOracle.address,
fathomBridge: fathomBridge.address, // TODO
// fathomBridge: fathomBridge.address,
};

if (chainId !== "31337") {
newAddresses.fathomBridge = fathomBridge.address;
}

fs.writeFileSync("./addresses.json", JSON.stringify(newAddresses));
}

Expand Down
67 changes: 67 additions & 0 deletions test/integration/AdminControls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { ethers } = require("hardhat");
const { expect } = require("chai");

const { getProxy } = require("../../common/proxies");

describe("AdminControls", () => {
// Contract
let adminControls;
let positionManager;
let bookKeeper;
let liquidationEngine;
let systemDebtEngine;
let priceOracle;
let stablecoinAdapter;
let stableSwapModule;
let flashMintModule;

beforeEach(async () => {
await deployments.fixture(["DeployTestFixture"]);

const ProxyFactory = await deployments.get("FathomProxyFactory");
const proxyFactory = await ethers.getContractAt("FathomProxyFactory", ProxyFactory.address);

adminControls = await getProxy(proxyFactory, "AdminControls");
liquidationEngine = await getProxy(proxyFactory, "LiquidationEngine");
positionManager = await getProxy(proxyFactory, "PositionManager");
stablecoinAdapter = await getProxy(proxyFactory, "StablecoinAdapter");
systemDebtEngine = await getProxy(proxyFactory, "SystemDebtEngine");
priceOracle = await getProxy(proxyFactory, "PriceOracle");
stableSwapModule = await getProxy(proxyFactory, "StableSwapModule");
flashMintModule = await getProxy(proxyFactory, "FlashMintModule");
bookKeeper = await getProxy(proxyFactory, "BookKeeper");
});

describe("#pause", () => {
context("pause protocol", () => {
it("protocol contracts should be paused", async () => {
await adminControls.pauseProtocol();

expect(await bookKeeper.paused()).to.be.equal(true);
expect(await liquidationEngine.paused()).to.be.equal(true);
expect(await positionManager.paused()).to.be.equal(true);
expect(await systemDebtEngine.paused()).to.be.equal(true);
expect(await stablecoinAdapter.paused()).to.be.equal(true);
expect(await priceOracle.paused()).to.be.equal(true);
expect(await flashMintModule.paused()).to.be.equal(true);
});
});
});
describe("#unpause", () => {
context("unpause protocol", () => {
it("protocol contracts should be unpaused", async () => {
await adminControls.pauseProtocol();

await adminControls.unpauseProtocol();

expect(await bookKeeper.paused()).to.be.equal(false);
expect(await liquidationEngine.paused()).to.be.equal(false);
expect(await positionManager.paused()).to.be.equal(false);
expect(await systemDebtEngine.paused()).to.be.equal(false);
expect(await stablecoinAdapter.paused()).to.be.equal(false);
expect(await priceOracle.paused()).to.be.equal(false);
expect(await flashMintModule.paused()).to.be.equal(false);
});
});
});
});
Loading

0 comments on commit b40416a

Please sign in to comment.