Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/verification/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ export async function assertMarketSupplyingIsPaused(provider: ethers.providers.J
console.log(` ✅ ${market.name} market supply is paused`)
}
}

export async function assertLiquidationsArePaused(provider: ethers.providers.JsonRpcProvider, contracts: ContractBundle) {
const comptroller = contracts.COMPTROLLER.contract.connect(provider)

const result = await comptroller.seizeGuardianPaused()

if (result === false) {
throw new Error(`Liquidations were expected to NOT be paused but were!`)
} else {
console.log(` ✅ Liquidations are paused`)
}
}

export async function assertLiquidationsAreNOTPaused(provider: ethers.providers.JsonRpcProvider, contracts: ContractBundle) {
const comptroller = contracts.COMPTROLLER.contract.connect(provider)

const result = await comptroller.seizeGuardianPaused()

if (result === true) {
throw new Error(`Liquidations were expected to NOT be paused but were!`)
} else {
console.log(` ✅ Liquidations are not paused`)
}
}

export async function assertMarketSupplyingIsNOTPaused(provider: ethers.providers.JsonRpcProvider, contracts: ContractBundle, market: Market) {
const comptroller = contracts.COMPTROLLER.contract.connect(provider)

Expand Down
18 changes: 18 additions & 0 deletions test/mip-16/assertCurrentExpectedState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {ethers} from "ethers";

import {ContractBundle} from "@moonwell-fi/moonwell.js";
import { assertLiquidationsArePaused, assertMarketBorrowIsPaused } from '../../src/verification/assertions'

export async function assertCurrentExpectedState(contracts: ContractBundle, provider: ethers.providers.JsonRpcProvider){
console.log("[+] Asserting system is in a paused state")

// Global liquidations are paused
await assertLiquidationsArePaused(provider, contracts)

// Each market is also paused.
const markets = Object.keys(contracts.MARKETS)
for (let i = 0; i < markets.length; i++) {
const market = contracts.MARKETS[markets[i]]
await assertMarketBorrowIsPaused(provider, contracts, market)
}
}
25 changes: 25 additions & 0 deletions test/mip-16/assertExpectedEndState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ethers} from "ethers";

import {ContractBundle} from "@moonwell-fi/moonwell.js";
import { assertLiquidationsAreNOTPaused, assertMarketBorrowIsNOTPaused, assertCF } from '../../src/verification/assertions'

export async function assertExpectedEndState(contracts: ContractBundle, provider: ethers.providers.JsonRpcProvider, expectedUSDCCollateralFactor: number){
// Global liquidations are paused
await assertLiquidationsAreNOTPaused(provider, contracts)

// Each market is also paused.
const markets = Object.keys(contracts.MARKETS)
for (let i = 0; i < markets.length; i++) {
const market = contracts.MARKETS[markets[i]]
await assertMarketBorrowIsNOTPaused(provider, contracts, market)
}

// Assert that the collateral factor on USDC is as expected
const usdcMarketAddress = contracts.MARKETS['USDC.multi'].mTokenAddress
assertCF(
provider,
contracts,
usdcMarketAddress,
expectedUSDCCollateralFactor,
)
}
55 changes: 55 additions & 0 deletions test/mip-16/generateProposalData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {ethers} from "ethers";
import {ContractBundle, ProposalData} from "@moonwell-fi/moonwell.js";

export async function generateProposalData(contracts: ContractBundle, provider: ethers.providers.JsonRpcProvider){
console.log("[+] Generating Proposal Data")

const data: ProposalData = {
targets: [
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
"0x0b7a0eaa884849c6af7a129e899536dddca4905e",
],
values: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
signatures: [
"_setSeizePaused(bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setBorrowPaused(address,bool)",
"_setCollateralFactor(address,uint256)",
],
callDatas: [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa80000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000006503d905338e2ebb550c9ec39ced525b612e77ae0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000006a1a771c7826596652dadc9145feaae62b1cd07f0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000a0d116513bd0b8f3f14e6ea41556c6ec34688e0f0000000000000000000000000000000000000000000000000000000000000000",
"0x00000000000000000000000093ef8b7c6171bab1c0a51092b2c9da8dc2ba0e9d0000000000000000000000000000000000000000000000000000000000000000",
"0x00000000000000000000000036918b66f9a3ec7a59d0007d8458db17bdffbf210000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000006e745367f4ad2b3da7339aee65dc85d416614d900000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000d0670aee3698f66e2d4daf071eb9c690d978bfa800000000000000000000000000000000000000000000000008e1bc9bf0400000",
]
}

return data
}
56 changes: 56 additions & 0 deletions test/mip-16/mip-16-verification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {ethers} from 'ethers'
import {
passGovProposal,
setupDeployerAndEnvForGovernance,
sleep,
startGanache
} from "../../src";

import {Contracts} from '@moonwell-fi/moonwell.js'
import {generateProposalData} from "./generateProposalData";
import {assertCurrentExpectedState} from "./assertCurrentExpectedState";
import {assertExpectedEndState} from "./assertExpectedEndState";
import {fMOVRGrant} from "./vars";

const FORK_BLOCK = 3262019

const EXPECTED_USDC_COLLATERAL_FACTOR = 640000000000000000

test("mip-16-verifications", async () => {

const contracts = Contracts.moonriver

const forkedChainProcess = await startGanache(
contracts,
FORK_BLOCK,
'https://rpc.api.moonriver.moonbeam.network',
[fMOVRGrant]
)

console.log("Waiting 5 seconds for chain to bootstrap...")
await sleep(5)

try {
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545')

// Go transfer MFAM to the deployer key from the fMOVRGrant treasury, delegate those well to the deployer,
// and assert the deployer has enough voting power to pass a proposal
await setupDeployerAndEnvForGovernance(contracts, provider, fMOVRGrant, FORK_BLOCK)

await assertCurrentExpectedState(contracts, provider)

// Generate new proposal data
const proposalData = await generateProposalData(contracts, provider)

// Pass the proposal
await passGovProposal(contracts, provider, proposalData)

// Assert that our end state is as desired
await assertExpectedEndState(contracts, provider, EXPECTED_USDC_COLLATERAL_FACTOR)
} finally {
// Kill our child chain.
console.log("Shutting down Ganache chain. PID", forkedChainProcess.pid!)
process.kill(-forkedChainProcess.pid!)
console.log("Ganache chain stopped.")
}
});
3 changes: 3 additions & 0 deletions test/mip-16/vars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export const ECOSYSTEM_RESERVE = '0x7793E08Eb4525309C46C9BA394cE33361A167ba4'
export const fMOVRGrant = '0x45DD368E30C07804b037260071d332e547C874F0'