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

Sweep Comptroller WBTC #193

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
39 changes: 39 additions & 0 deletions contracts/ComptrollerSweeper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pragma solidity = 0.5.17;

import {ComptrollerV7Storage} from "./ComptrollerStorage.sol";
import {Unitroller} from "./Unitroller.sol";
import {EIP20Interface} from "./EIP20Interface.sol";

/**
* @title Compound's Comptroller Sweeper Contract
* @author Arr00
*/
contract ComptrollerSweeper is ComptrollerV7Storage {
/**
* @notice Become the implementation of the unitroller
* @param unitroller The address of the unitroller to become
*/
function _become(Unitroller unitroller) external {
require(msg.sender == unitroller.admin(), "ComptrollerSweeper::_become: only unitroller admin can change brains");
require(unitroller._acceptImplementation() == 0, "ComptrollerSweeper::_become: change not authorized");
}

/**
* @notice Sweep ERC-20 tokens from controller (excluding COMP)
* @dev ERC-20 transfer function is not guaranteed to succeed
* @param token The address of the ERC-20 token to sweep
*/
function _sweep(EIP20Interface token) external {
require(msg.sender == admin, "ComptrollerSweeper::_sweep: only admin can sweep");
require(address(token) != getCompAddress(), "ComptrollerSweeper::_sweep: can not sweep comp");
require(token.transfer(admin, token.balanceOf(address(this))), "ComptrollerSweeper::_sweep: transfer failed");
}

/**
* @notice Return the address of the COMP token
* @return address The address of COMP
*/
function getCompAddress() public view returns (address) {
return 0xc00e94Cb662C3520282E6f5717214004A7f26888;
}
}
21 changes: 21 additions & 0 deletions scenario/src/Builder/ComptrollerImplBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const ComptrollerScenarioG6Contract = getContract('ComptrollerScenarioG6');
const ComptrollerScenarioContract = getTestContract('ComptrollerScenario');
const ComptrollerContract = getContract('Comptroller');

const ComptrollerSweeperContract = getContract('ComptrollerSweeper');

const ComptrollerBorkedContract = getTestContract('ComptrollerBorked');

export interface ComptrollerImplData {
Expand Down Expand Up @@ -291,6 +293,25 @@ export async function buildComptrollerImpl(
}
),

new Fetcher<{ name: StringV }, ComptrollerImplData> (
`
#### Sweeper

* "Sweeper name:<String>" - A Sweeper Comptroller
* E.g. "ComptrollerImpl Deploy Sweeper MySweeper"
`,
'Sweeper',
[new Arg('name', getStringV)],
async (world, {name}) => {
return {
invokation: await ComptrollerSweeperContract.deploy<ComptrollerImpl>(world, from, []),
name: name.val,
contract: 'ComptrollerSweeper',
description: 'Sweeper Comptroller Impl'
};
}
),

new Fetcher<{ name: StringV }, ComptrollerImplData>(
`
#### Borked
Expand Down
44 changes: 44 additions & 0 deletions spec/sim/0112-sweep-comptroller/hypothetical_execution.scen
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env yarn repl -s

PrintTransactionLogs

Alias Arr00 "0x2B384212EDc04Ae8bB41738D05BA20E33277bf33"
Alias CompHolder "0xF977814e90dA44bFA03b6295A0616a897441aceC"
Alias CompHolder2 "0xfa9b5f7fdc8ab34aaf3099889475d47febf830d7"
Alias CurrentImpl "0xBafE01ff935C7305907c33BF824352eE5979B526"
Alias USDCSupplyer "0x41fA28CA6d17AeF97D641AA230e57243b10AFcD4"
Alias WBTCSender "0x6918fE32bB0CCfba961C554699c1B506eD0Bd458"

Web3Fork "https://mainnet-eth.compound.finance/@15071471" (CompHolder CompHolder2 Arr00 USDCSupplyer)
UseConfigs mainnet

ComptrollerImpl Deploy Sweeper ComptrollerSweeper
Assert Equal (Unitroller Implementation) (Address CurrentImpl)

From CompHolder (Comp Delegate CompHolder)
From CompHolder2 (Comp Delegate CompHolder)

From CompHolder (GovernorBravo GovernorBravoDelegator Propose "Sweep Comptroller" [(Address Unitroller) (Address ComptrollerSweeper) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address CurrentImpl) (Address WBTC) (Address cUNI)] [0 0 0 0 0 0 0 0 0 0] ["_setPendingImplementation(address)" "_become(address)" "_sweep(address)" "_sweep(address)" "_sweep(address)" "_sweep(address)" "_setPendingImplementation(address)" "_become(address)" "transfer(address,uint256)" "transfer(address,uint256)"] [[(Address ComptrollerSweeper)] [(Address Unitroller)] [(Address WBTC)] [(Address UNI)] [(Address BAT)] [(Address SAI)] [(Address CurrentImpl)] [(Address Unitroller)] [(Address WBTCSender) "30147937"] [(Address Arr00) "8900000000000"]])

-- Vote for, queue, and execute the proposal
MineBlock
AdvanceBlocks 13140
From CompHolder (GovernorBravo GovernorBravoDelegator Proposal LastProposal Vote For)
AdvanceBlocks 20000
GovernorBravo GovernorBravoDelegator Proposal LastProposal Queue
IncreaseTime 604910
GovernorBravo GovernorBravoDelegator Proposal LastProposal Execute

Assert Equal (Erc20 WBTC TokenBalance (Address WBTCSender)) (30147937)
Assert Equal (Unitroller Implementation) (Address CurrentImpl)
Assert Equal (Erc20 (Address cUNI) TokenBalance (Address Arr00)) (8900000000000)


-- Verify normal functionality
RedeemUnderlying USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (100000)

Mint USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (0)

Print "Sweep comptroller sucessfully!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env yarn repl -s

PrintTransactionLogs

Alias Arr00 "0x2B384212EDc04Ae8bB41738D05BA20E33277bf33"
Alias CompHolder "0xF977814e90dA44bFA03b6295A0616a897441aceC"
Alias CompHolder2 "0xfa9b5f7fdc8ab34aaf3099889475d47febf830d7"
Alias CurrentImpl "0xBafE01ff935C7305907c33BF824352eE5979B526"
Alias ComptrollerSweeper "0xff3c813559127d60da732a0e8ec836f4c162df82"
Alias WBTCSender "0x6918fE32bB0CCfba961C554699c1B506eD0Bd458"
Alias USDCSupplyer "0x41fA28CA6d17AeF97D641AA230e57243b10AFcD4"

Web3Fork "https://mainnet-eth.compound.finance/@15071471" (CompHolder CompHolder2 Arr00 USDCSupplyer)
UseConfigs mainnet

Assert Equal (Unitroller Implementation) (Address CurrentImpl)

From CompHolder (Comp Delegate CompHolder)
From CompHolder2 (Comp Delegate CompHolder)

From CompHolder (GovernorBravo GovernorBravoDelegator Propose "Sweep Comptroller" [(Address Unitroller) (Address ComptrollerSweeper) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address Unitroller) (Address CurrentImpl) (Address WBTC) (Address cUNI)] [0 0 0 0 0 0 0 0 0 0] ["_setPendingImplementation(address)" "_become(address)" "_sweep(address)" "_sweep(address)" "_sweep(address)" "_sweep(address)" "_setPendingImplementation(address)" "_become(address)" "transfer(address,uint256)" "transfer(address,uint256)"] [[(Address ComptrollerSweeper)] [(Address Unitroller)] [(Address WBTC)] [(Address UNI)] [(Address BAT)] [(Address SAI)] [(Address CurrentImpl)] [(Address Unitroller)] [(Address WBTCSender) "30147937"] [(Address Arr00) "8900000000000"]])

-- Vote for, queue, and execute the proposal
MineBlock
AdvanceBlocks 13140
From CompHolder (GovernorBravo GovernorBravoDelegator Proposal LastProposal Vote For)
AdvanceBlocks 20000
GovernorBravo GovernorBravoDelegator Proposal LastProposal Queue
IncreaseTime 604910
GovernorBravo GovernorBravoDelegator Proposal LastProposal Execute

Assert Equal (Erc20 WBTC TokenBalance (Address WBTCSender)) (30147937)
Assert Equal (Unitroller Implementation) (Address CurrentImpl)
Assert Equal (Erc20 (Address cUNI) TokenBalance (Address Arr00)) (8900000000000)


-- Verify normal functionality
RedeemUnderlying USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (100000)

Mint USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (0)

Print "Sweep comptroller sucessfully!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env yarn repl -s

PrintTransactionLogs

Alias Arr00 "0x2B384212EDc04Ae8bB41738D05BA20E33277bf33"
Alias CompHolder "0xF977814e90dA44bFA03b6295A0616a897441aceC"
Alias CompHolder2 "0xfa9b5f7fdc8ab34aaf3099889475d47febf830d7"
Alias CurrentImpl "0xBafE01ff935C7305907c33BF824352eE5979B526"
Alias ComptrollerSweeper "0xff3c813559127d60da732a0e8ec836f4c162df82"
Alias WBTCSender "0x6918fE32bB0CCfba961C554699c1B506eD0Bd458"
Alias USDCSupplyer "0x41fA28CA6d17AeF97D641AA230e57243b10AFcD4"

Web3Fork "https://mainnet-eth.compound.finance/@15072867" (CompHolder CompHolder2 Arr00 USDCSupplyer)
UseConfigs mainnet

Assert Equal (Unitroller Implementation) (Address CurrentImpl)

From CompHolder (Comp Delegate CompHolder)
From CompHolder2 (Comp Delegate CompHolder)

-- Vote for, queue, and execute the proposal
MineBlock
AdvanceBlocks 13140
From CompHolder (GovernorBravo GovernorBravoDelegator Proposal LastProposal Vote For)
AdvanceBlocks 20000
GovernorBravo GovernorBravoDelegator Proposal LastProposal Queue
IncreaseTime 604910
GovernorBravo GovernorBravoDelegator Proposal LastProposal Execute

Assert Equal (Erc20 WBTC TokenBalance (Address WBTCSender)) (30147937)
Assert Equal (Unitroller Implementation) (Address CurrentImpl)
Assert Equal (Erc20 (Address cUNI) TokenBalance (Address Arr00)) (8900000000000)


-- Verify normal functionality
RedeemUnderlying USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (100000)

Mint USDCSupplyer 100000 cUSDC
Assert Equal (Erc20 USDC TokenBalance (Address USDCSupplyer)) (0)

Print "Sweep comptroller sucessfully!"