Skip to content

Instantly share code, notes, and snippets.

@giovannidisiena
Last active September 4, 2025 20:15
Show Gist options
  • Select an option

  • Save giovannidisiena/a2cab373d084beb7f74e0ad5188378fe to your computer and use it in GitHub Desktop.

Select an option

Save giovannidisiena/a2cab373d084beb7f74e0ad5188378fe to your computer and use it in GitHub Desktop.
Bunni withdrawal test
[
["0x7c1519fff43607c1b8b12d224f1128efcab53248", 515503158529255605221],
["0xb3c00ed3f2d97bd69c2c56f6996083ad333ca009", 210075935000400000000],
["0xbd5bce81b64f0cc649dfe9473b916986af1d6496", 198256237911820551472],
["0xb7ddffb7de7325a19dc25b3d73695c45573492b5", 178381703810760918402],
["0xf5552c7601d6876f1740f130afc4303b2c466f25", 162517136132400000000],
["0xef4fb24ad0916217251f553c0596f8edc630eb66", 118755092867200000000],
["0x42cfe2b6c77098cf86149ef7adfa2f06a395d175", 116692862836638379986],
["0x5d1124fb77c539ec92e3ef853053bbce1e98271b", 43216357219663932208],
["0x40c287181a240393740812eadf66495527501221", 37669863914374485107],
["0x74ee8116c0216a726993294b21213c7efe562757", 5874523447040724454],
["0xdd27479b75e4f1a4b55bc89fa699ef37fadd097c", 3970773039242736089],
["0xc0eb8756187e7add8da324d8473553b2d157e1a0", 1988756509932804102],
["0xf4b785ef2c10d5662a053043e362e7e74e14a206", 989954826161909330],
["0xeb4576fe753dab07635c0bb6c8f0a355e1db5d31", 787990269620259515],
["0x56025c57c2621b08f5cf7f0d3acab5c2a818e5fa", 555646657613697742],
["0x420021031006f89ea584b01f7f5d41f8a3070b32", 248143893206452523],
["0x8462d4115c14ba5c6d4481709be9fe7daea8af09", 248056423363133368],
["0x657d8bccdd9c6e1da8da1e7d331cfdea8357adbc", 236251767799831762],
["0x662f9e81dbb4195cc254df50bb79565e465a2005", 148620718436158686],
["0x9194851f2a28e209216beb93b736ff3cf8579948", 105409882769513369],
["0x713aae16b46bae6abe820f54a224404a3d6c8f52", 63295656133168386],
["0x74548187e10374c9099dddb5b2472234d42abfb8", 749191775330],
["0xf47e977a4e8d3bfa54c65aeb269880bc96f0b153", 528400219598],
["0x4a61433ef785a05da448b0935f316870767b75ab", 505381056]
]
Logs:
Idle balance before: 3.16691973136e11 USDC
Reserve balance before: 6.94669046658e11 USDC, 1.54599188579e11 USDT
Active balance before: 3.77977073522e11 USDC, 1.54599188579e11 USDT
Pranking 0x7C1519fFf43607c1b8b12d224F1128Efcab53248
Withdrew 2.24335826083e11 USDC and 4.9926129352e10 USDT
Idle balance: 2.14419738971e11 USDC
Reserve balance: 4.70333220574e11 USDC, 1.04673059226e11 USDT
Pranking 0xB3C00Ed3F2d97BD69C2C56F6996083AD333cA009
Withdrew 9.1420503712e10 USDC and 2.0345711041e10 USDT
Idle balance: 1.72742137464e11 USDC
Reserve balance: 3.78912716862e11 USDC, 8.4327348185e10 USDT
Pranking 0xBD5bCe81b64F0Cc649DfE9473b916986af1D6496
Withdrew 8.6276827158e10 USDC and 1.9200981439e10 USDT
Idle balance: 1.33409481489e11 USDC
Reserve balance: 2.92635889704e11 USDC, 6.5126366745e10 USDT
Pranking 0xb7ddfFB7DE7325a19Dc25b3d73695c45573492B5
Withdrew 7.7627859732e10 USDC and 1.7276146366e10 USDT
Idle balance: 9.8019794576e10 USDC
Reserve balance: 2.15008029971e11 USDC, 4.7850220379e10 USDT
Pranking 0xf5552C7601d6876f1740f130aFC4303B2C466F25
Withdrew 7.0723942974e10 USDC and 1.5739673805e10 USDT
Idle balance: 6.5777527332e10 USDC
Reserve balance: 1.44284086997e11 USDC, 3.2110546574e10 USDT
Pranking 0xeF4fB24aD0916217251F553c0596F8Edc630EB66
Withdrew 5.1679648163e10 USDC and 1.1501349758e10 USDT
Idle balance: 4.2217344499e10 USDC
Reserve balance: 9.2604438833e10 USDC, 2.0609196816e10 USDT
Pranking 0x42CFe2b6C77098cF86149Ef7ADFa2F06A395D175
Withdrew 5.0782210255e10 USDC and 1.1301624187e10 USDT
Idle balance: 1.9066293732e10 USDC
Reserve balance: 4.1822228578e10 USDC, 9.307572628e9 USDT
Pranking 0x5D1124FB77c539eC92E3ef853053bBcE1E98271b
Withdrew 1.8806824044e10 USDC and 4.185474725e9 USDT
Idle balance: 1.049246963e10 USDC
Reserve balance: 2.3015404534e10 USDC, 5.122097903e9 USDT
Pranking 0x40c287181a240393740812eADf66495527501221
Withdrew 1.639311011e10 USDC and 3.648300632e9 USDT
Idle balance: 3.019031146e9 USDC
Reserve balance: 6.622294423e9 USDC, 1.473797271e9 USDT
Pranking 0x74EE8116C0216a726993294B21213c7eFE562757
Withdrew 2.556465559e9 USDC and 5.68943588e8 USDT
Idle balance: 1.853566633e9 USDC
Reserve balance: 4.065828864e9 USDC, 9.04853682e8 USDT
Pranking 0xDD27479b75E4F1A4b55BC89fa699eF37fadD097C
Withdrew 1.727994552e9 USDC and 3.84566661e8 USDT
Idle balance: 1.065792934e9 USDC
Reserve balance: 2.337834312e9 USDC, 5.20287021e8 USDT
Pranking 0xc0Eb8756187e7add8dA324D8473553B2d157e1a0
Withdrew 8.65463823e8 USDC and 1.92609711e8 USDT
Idle balance: 6.71237502e8 USDC
Reserve balance: 1.472370488e9 USDC, 3.2767731e8 USDT
Pranking 0xf4b785ef2c10D5662A053043E362e7E74E14A206
Withdrew 4.3080693e8 USDC and 9.5876449e7 USDT
Idle balance: 4.74837363e8 USDC
Reserve balance: 1.041563557e9 USDC, 2.3180086e8 USDT
Pranking 0xEB4576fE753DAB07635c0Bb6c8f0A355e1Db5d31
Withdrew 3.42916323e8 USDC and 7.6316319e7 USDT
Idle balance: 3.18505585e8 USDC
Reserve balance: 6.98647234e8 USDC, 1.5548454e8 USDT
Pranking 0x56025C57C2621b08F5cf7F0d3ACAb5c2a818e5FA
Withdrew 2.41805407e8 USDC and 5.3814e7 USDT
Idle balance: 2.0826916e8 USDC
Reserve balance: 4.56841826e8 USDC, 1.0167054e8 USDT
Pranking 0x420021031006f89eA584B01f7F5D41f8A3070b32
Withdrew 1.07986856e8 USDC and 2.4032566e7 USDT
Idle balance: 1.59039141e8 USDC
Reserve balance: 3.4885497e8 USDC, 7.7637973e7 USDT
Pranking 0x8462D4115C14Ba5c6D4481709Be9FE7dAEa8af09
Withdrew 1.07948791e8 USDC and 2.4024095e7 USDT
Idle balance: 1.09826475e8 USDC
Reserve balance: 2.40906178e8 USDC, 5.3613878e7 USDT
Pranking 0x657D8BcCDD9C6e1Da8DA1e7d331CFdeA8357AdBc
Withdrew 1.0281166e8 USDC and 2.2880823e7 USDT
Idle balance: 6.2955771e7 USDC
Reserve balance: 1.38094518e8 USDC, 3.0733054e7 USDT
Pranking 0x662f9E81dBb4195CC254df50bB79565E465A2005
Withdrew 6.4676522e7 USDC and 1.4393815e7 USDT
Idle balance: 3.3470456e7 USDC
Reserve balance: 7.3417995e7 USDC, 1.6339239e7 USDT
Pranking 0x9194851F2A28e209216bEB93b736Ff3cF8579948
Withdrew 4.5872102e7 USDC and 1.0208876e7 USDT
Idle balance: 1.255787e7 USDC
Reserve balance: 2.7545893e7 USDC, 6.130362e6 USDT
Pranking 0x713aae16b46bae6aBE820F54A224404A3D6c8F52
Withdrew 2.75449e7 USDC and 6.130141e6 USDT
Idle balance: 4.52e2 USDC
Reserve balance: 9.92e2 USDC, 2.21e2 USDT
Pranking 0x74548187e10374C9099Dddb5b2472234d42aBfB8
Withdrew 3.26e2 USDC and 7.1e1 USDT
Idle balance: 3.04e2 USDC
Reserve balance: 6.66e2 USDC, 1.49e2 USDT
Pranking 0xF47e977a4E8D3BFA54C65AeB269880bC96F0B153
Withdrew 2.29e2 USDC and 5e1 USDT
Idle balance: 1.99e2 USDC
Reserve balance: 4.37e2 USDC, 9.9e1 USDT
Pranking 0x4A61433eF785a05da448b0935f316870767b75AB
Withdrew 0e0 USDC and 0e0 USDT
Idle balance: 1.99e2 USDC
Reserve balance: 4.37e2 USDC, 9.9e1 USDT
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
import {
SafeERC20, IERC20
} from "@uniswap/v4-core/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IBunniHub} from "bunni-v2/src/interfaces/IBunniHub.sol";
import {IdleBalance} from "bunni-v2/src/types/IdleBalance.sol";
import {Test, console} from "forge-std/Test.sol";
contract WithdrawTest is Test {
IBunniHub constant BUNNI_HUB = IBunniHub(0x000000000049C7bcBCa294E63567b4D21EB765f1);
address constant BUNNI_HOOK = 0x000052423c1dB6B7ff8641b85A7eEfc7B2791888;
address constant BUNNI_USDC_USDT_LP = 0xc92c2ba90213Fc3048A527052B0b4FeBFA716763;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
Currency constant USDC_CURRENCY = Currency.wrap(USDC);
Currency constant USDT_CURRENCY = Currency.wrap(USDT);
uint8 constant QUEUED_WITHDRAW_PAUSE_POSITION = 1;
uint8 constant WITHDRAW_PAUSE_POSITION = 2;
PoolKey poolKey;
PoolId poolId;
struct Allocation {
address addr;
uint256 amount;
}
function setUp() public {
vm.createSelectFork("mainnet", 23284706);
poolKey = PoolKey({
currency0: USDC_CURRENCY,
currency1: USDT_CURRENCY,
fee: 0,
tickSpacing: 1,
hooks: IHooks(BUNNI_HOOK)
});
poolId = poolKey.toId();
(uint8 pauseFlags,) = BUNNI_HUB.getPauseStatus();
// unset position 1 and 2
uint8 updatedFlags =
pauseFlags &= ~(uint8(1) << QUEUED_WITHDRAW_PAUSE_POSITION | uint8(1) << WITHDRAW_PAUSE_POSITION);
assertEq(updatedFlags, 249);
vm.prank(0x9a8FEe232DCF73060Af348a1B62Cdb0a19852d13);
BUNNI_HUB.setPauseFlags(updatedFlags);
}
function test_withdraw() public {
IdleBalance idle = BUNNI_HUB.idleBalance(poolId);
(uint256 idleBalance, bool isToken0) = idle.fromIdleBalance();
console.log("Idle balance before: %e %s", idleBalance, isToken0 ? "USDC" : "USDT");
(uint256 balance0, uint256 balance1) = BUNNI_HUB.poolBalances(poolId);
console.log("Reserve balance before: %e USDC, %e USDT", balance0, balance1);
if (isToken0) {
balance0 -= idleBalance;
} else {
balance1 -= idleBalance;
}
console.log("Active balance before: %e USDC, %e USDT", balance0, balance1);
console.log("\n");
string memory json = vm.readFile("test/holders.json");
Allocation[] memory allocations = abi.decode(vm.parseJsonType(json, "(address,uint256)[]"), (Allocation[]));
for (uint256 i = 0; i < allocations.length; i++) {
address holder = allocations[i].addr;
console.log("Pranking %s", holder);
vm.prank(holder);
(uint256 amount0, uint256 amount1) = BUNNI_HUB.withdraw(
IBunniHub.WithdrawParams({
poolKey: poolKey,
recipient: allocations[i].addr,
shares: allocations[i].amount,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp,
useQueuedWithdrawal: false
})
);
console.log("Withdrew %e USDC and %e USDT", amount0, amount1);
console.log("\n");
idle = BUNNI_HUB.idleBalance(poolId);
(idleBalance, isToken0) = idle.fromIdleBalance();
console.log("Idle balance: %e %s", idleBalance, isToken0 ? "USDC" : "USDT");
(balance0, balance1) = BUNNI_HUB.poolBalances(poolId);
console.log("Reserve balance: %e USDC, %e USDT", balance0, balance1);
console.log("\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment