Published
Edited
Sep 8, 2020
1 star
Insert cell
Insert cell
Insert cell
async function setupFork(aliases, network = 'mainnet') {
const world = new World(await GanacheEnv(socket.ganache))
await world.env.read(github(`networks/${network}.json`))
await world.env.assign(aliases)
await world.fork(network, {unlocked_accounts: Object.values(aliases)})
return world;
}
Insert cell
world = setupFork({
CompHolder: 'Reservoir',
Guardian: '0x18c8F1222083997405F2E482338A4650ac02e1d6',
StdComptrollerG5: '0x7b5e3521a049c8ff88e6349f33044c6cc33c113c',
ETHWhale: '0x99c85bb64564d9ef9a99621301f22c9993cb89e3',
USDTWhale: '0x1a2869ad1e52acf28afb6dbd4b402a514fba2b65',
USDCWhale: '0xa700a7e660669ff27025b2db95af2e61bce910e6'
})
Insert cell
{
const {address, array, uint} = world.env.bindings()
const Compound = await world.env.library(CompoundLib)
const CompGov = await world.env.library(CompGovLib)

const $$proposeUpgrade = () => [
{...CompGov.$delegate(address('CompHolder')), from: 'CompHolder'},
{...CompGov.$propose(
"Borrow Caps Comptroller Patch",
[
{Unitroller: '_setPendingImplementation(address)', args: [address('StdComptrollerG5')]},
{StdComptrollerG5: '_become(address)', args: [address('Unitroller')]},
{Unitroller: '_setBorrowCapGuardian(address)', args: [address('Guardian')]}
]
), from: 'CompHolder'}
]

await world.exec([
$$proposeUpgrade(),
(w) => CompGov.whipLastProposal(address('CompHolder'), w),
{send: '_setMarketBorrowCaps', to: 'Comptroller', args: [array(address)([address('cUSDT')]), array(uint)([exp(100e6, 6)])], from: 'Guardian'},

Compound.$$basicLiquidate(address('ETHWhale'), 'cETH', exp(1), 'cUSDT', exp(240, 6), exp(100, 6), address('USDTWhale')), // depends on price
{send: '_setMarketBorrowCaps', to: 'Comptroller', args: [array(address)([address('cUSDT')]), array(uint)([exp(1e6, 6)])], from: 'Guardian'}
])
await world.reverts(
Compound.$$basicBorrow('cETH', exp(1), 'cUSDT', exp(240, 6), address('ETHWhale')),
'market borrow cap reached'
)
await world.exec([
{send: '_setMarketBorrowCaps', to: 'Comptroller', args: [array(address)([address('cUSDT')]), array(uint)([exp(100e6, 6)])], from: 'Guardian'},
Compound.$$basicBorrow('cETH', exp(1), 'cUSDT', exp(240, 6), address('ETHWhale'))
])

return world;
}
Insert cell
gasDelta = ({
before: {
mint: 123413,
enterMarkets: 47587,
borrow: 218894,
approve: 30949,
liquidateBorrow: 398009
},

afterWithoutCap: {
mint: 123434,
enterMarkets: 47609,
borrow: 219674,
approve: 30949,
liquidateBorrow: 397878
},
afterWithCap: {
mint: 123390,
enterMarkets: 47609,
borrow: 222597,
approve: 30949,
liquidateBorrow: 397967
}
})
Insert cell
Insert cell
Insert cell
import {CompoundLib, CompGovLib} from '@jflatow/quest-for-compound'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more