ElyChestSharedRealtimeHook
BSCElyChestSharedRealtimeHook is a Uniswap v4 hook on BSC. Runs code on every swap. Can take tokens from swaps. Runs at pool creation. Handles donations to LPs.
- Contract name
- ElyChestSharedRealtimeHook
How this hook works
Buyback and burnA buyback and burn hook. It takes a tax on trades, charges more right after launch and manages its own liquidity.
Takes a tax on trades
On top of the normal pool fee, it keeps part of each trade as a tax.
The code that does this (beforeSwap):function beforeSwap(address sender,PoolKey calldata key,SwapParams calldata p,bytes calldata) external onlyManager nonReentrant returns(bytes4,BeforeSwapDelta,uint24){ bytes32 id=PoolId.unwrap(key.toId());Market storage m=markets[id];require(m.token!=address(0)&&!m.recovered,Guard(16)); _start(id,m);(address actor,bool verified)=_actor(sender);(uint256 platform,,uint256 rate,)=feeContext(id,actor,p.zeroForOne); bool buySide=p.zeroForOne;bool exactIn=p.amountSpecified<0;uint256 specified=uint256(exactIn?-p.amountSpecified:p.amountSpecified); require(specified>0&&specified<=uint256(uint128(type(int128).max)),Guard(18));uint256 maxFee; int256 inner=p.amountSpecified; if(buySide&&exactIn){maxFee=_ceil(specified,rate,T.BPS);require(specified>maxFee,Guard(19));inner=-int256(specified-maxFee);} if(!buySide&&!exactIn)inner=int256(_ceil(specified,T.BPS,T.BPS-rate)); BalanceDelta d=manager.swap(key,SwapParams(buySide,inner,p.sqrtPriceLimitX96),""); uint256 quote=uint256(uint128(buySide?-d.amount0():d.amount0())); uint256 tokens=uint256(uint128(buySide?d.amount1():-d.amount1()));require(quote!=0&&tokens!=0,Guard(20)); uint256 fee=buySide?(exactIn&"e==specified-maxFee?maxFee:_ceil(quote,rate,T.BPS-rate)):_ceil(quote,rate,T.BPS); uint256 gross=buySide?quote+fee:quote;uint256 output=buySide?tokens:quote-fee;require(output!=0,Guard(21)); if(!exactIn)require(output==specified,Guard(22)); uint256 actualInput=buySide?gross:tokens;require(!exactIn||actualInput==specified,"partial fill unsupported");uint256 refund=0; // Exact-in partial fills revert above. Never strand a refund in a router // whose caller may not include an input SWEEP command. uint256 chargedInput=exactIn?specified:actualInput; int128 caller0=buySide?-_i(chargedInput):_i(output); int128 caller1=buySide?_i(output):-_i(chargedInput); if(fee!=0){manager.mint(address(this),0,fee);_book(id,m,fee,_ceil(gross,platform,T.BPS));} if(refund!=0){Currency currency=buySide?key.currency0:key.currency1;manager.take(currency,sender,refund);emit HookRefund(id,sender,Currency.unwrap(currency),refund);} _end(id,m);emit HookSwap(id,sender,-caller0,-caller1,uint128(fee),0);emit HookFee(id,sender,uint128(fee),0); uint256 protocolFee=_ceil(gross,platform,T.BPS);emit TradeActor(id,sender,actor,verified,buySide,protocolFee,fee-protocolFee); bool nativeSpecified=(exactIn==buySide); return(IHooks.beforeSwap.selector,nativeSpecified?toBeforeSwapDelta(-caller0,-caller1):toBeforeSwapDelta(-caller1,-caller0),0); }Higher at launch
The tax starts higher right after launch and comes down over time, which makes it costly for bots to buy first.
The code that does this (feeContext):function feeContext(bytes32 id,address actor,bool buySide) public view returns(uint256 platform,uint256 project,uint256 total,bool exempt){ Market storage m=markets[id];require(m.token!=address(0)&&!m.recovered,Guard(16));bool effectiveGraduated=m.graduated||_wouldGraduate(id,m);platform=effectiveGraduated?T.POST:T.PLATFORM_PRE; bool window=m.protection&&block.timestamp<uint256(m.createdAt)+T.WINDOW; exempt=window&&actor!=address(0)&&launchExempt[id][actor]; project=exempt?0:buySide&&window?9900-platform:(buySide?m.tax.buyBps:m.tax.sellBps);total=platform+project; }Manages its own liquidity
It adds and removes liquidity itself, so it can own part or all of the pool.
The code that does this (unlockCallback):function unlockCallback(bytes calldata data) external onlyManager returns(bytes memory){ (uint8 action,address token)=abi.decode(data,(uint8,address));Market storage m=markets[poolId(token)];require(m.token==token,Guard(16)); if(action==0){(BalanceDelta d,)=manager.modifyLiquidity(poolKey(token),ModifyLiquidityParams(T.LOWER_TICK,upperTick,int256(uint256(m.seedLiquidity)),bytes32(0)),"");_settle(poolKey(token),d,address(this));return "";} if(action==3){(,,uint256 unused,address recipient)=abi.decode(data,(uint8,address,uint256,address));if(unused!=0)_cash(recipient,unused);(BalanceDelta d,)=manager.modifyLiquidity(poolKey(token),ModifyLiquidityParams(T.LOWER_TICK,upperTick,-int256(uint256(m.seedLiquidity)),bytes32(0)),"");m.seedLiquidity=0;_settle(poolKey(token),d,recipient);return "";} if(action==4){(,,uint256 amount,address recipient)=abi.decode(data,(uint8,address,uint256,address));_cash(recipient,amount);return "";} if(action==1||action==2){_processCallback(action,data);return "";} revert("invalid callback action"); }Buys back the token
It uses what it collects to buy the token back.
The code that does this (beforeSwap):function beforeSwap(address sender,PoolKey calldata key,SwapParams calldata p,bytes calldata) external onlyManager nonReentrant returns(bytes4,BeforeSwapDelta,uint24){ bytes32 id=PoolId.unwrap(key.toId());Market storage m=markets[id];require(m.token!=address(0)&&!m.recovered,Guard(16)); _start(id,m);(address actor,bool verified)=_actor(sender);(uint256 platform,,uint256 rate,)=feeContext(id,actor,p.zeroForOne); bool buySide=p.zeroForOne;bool exactIn=p.amountSpecified<0;uint256 specified=uint256(exactIn?-p.amountSpecified:p.amountSpecified); require(specified>0&&specified<=uint256(uint128(type(int128).max)),Guard(18));uint256 maxFee; int256 inner=p.amountSpecified; if(buySide&&exactIn){maxFee=_ceil(specified,rate,T.BPS);require(specified>maxFee,Guard(19));inner=-int256(specified-maxFee);} if(!buySide&&!exactIn)inner=int256(_ceil(specified,T.BPS,T.BPS-rate)); BalanceDelta d=manager.swap(key,SwapParams(buySide,inner,p.sqrtPriceLimitX96),""); uint256 quote=uint256(uint128(buySide?-d.amount0():d.amount0())); uint256 tokens=uint256(uint128(buySide?d.amount1():-d.amount1()));require(quote!=0&&tokens!=0,Guard(20)); uint256 fee=buySide?(exactIn&"e==specified-maxFee?maxFee:_ceil(quote,rate,T.BPS-rate)):_ceil(quote,rate,T.BPS); uint256 gross=buySide?quote+fee:quote;uint256 output=buySide?tokens:quote-fee;require(output!=0,Guard(21)); if(!exactIn)require(output==specified,Guard(22)); uint256 actualInput=buySide?gross:tokens;require(!exactIn||actualInput==specified,"partial fill unsupported");uint256 refund=0; // Exact-in partial fills revert above. Never strand a refund in a router // whose caller may not include an input SWEEP command. uint256 chargedInput=exactIn?specified:actualInput; int128 caller0=buySide?-_i(chargedInput):_i(output); int128 caller1=buySide?_i(output):-_i(chargedInput); if(fee!=0){manager.mint(address(this),0,fee);_book(id,m,fee,_ceil(gross,platform,T.BPS));} if(refund!=0){Currency currency=buySide?key.currency0:key.currency1;manager.take(currency,sender,refund);emit HookRefund(id,sender,Currency.unwrap(currency),refund);} _end(id,m);emit HookSwap(id,sender,-caller0,-caller1,uint128(fee),0);emit HookFee(id,sender,uint128(fee),0); uint256 protocolFee=_ceil(gross,platform,T.BPS);emit TradeActor(id,sender,actor,verified,buySide,protocolFee,fee-protocolFee); bool nativeSpecified=(exactIn==buySide); return(IHooks.beforeSwap.selector,nativeSpecified?toBeforeSwapDelta(-caller0,-caller1):toBeforeSwapDelta(-caller1,-caller0),0); }Burns tokens
It destroys some tokens (or sends them to an address nobody controls), so there are fewer of them.
The code that does this (processCallback):function _processCallback(uint8 action,bytes calldata data) private { ProcessRequest memory r=abi.decode(data,(ProcessRequest)); bytes32 id=poolId(r.token);Market storage m=markets[id]; require(m.token!=address(0)&&!m.recovered&&r.action==action,Guard(16)); require(r.deadline>=block.timestamp&&r.deadline<=block.timestamp+300,Guard(30)); _cash(address(this),r.amount); _start(id,m); uint256 swapAmount=action==1?r.amount:r.amount/2; require(swapAmount>0&&swapAmount<=uint256(uint128(type(int128).max)),Guard(40)); PoolKey memory key=poolKey(r.token); BalanceDelta d=manager.swap(key,SwapParams(true,-int256(swapAmount),TickMath.MIN_SQRT_PRICE+1),""); require(d.amount0()<0&&d.amount1()>0,Guard(41)); require(uint256(-int256(d.amount0()))==swapAmount,"partial fill unsupported"); uint256 out=uint256(int256(d.amount1()));require(out>=r.minSwap,Guard(31)); _settle(key,d,address(this)); if(action==1){StandardRealtimeToken(r.token).burn(out);emit BuybackProcessed(id,r.amount,out);} else _processLP(id,m,r,out); _end(id,m); }Keeps a price record
It records the pool’s price over time, so other apps can read a fair average price.
The code that does this (observeProcessPrice):function observeProcessPrice(bytes32 id) external nonReentrant { Market storage m=markets[id];require(m.token!=address(0)&&!m.recovered,Guard(16)); require(m.observationAt==0||block.timestamp-m.observationAt>300,Guard(25)); _accrue(m);m.observationAt=uint64(block.timestamp);m.observationCumulative=m.tickCumulative; emit ProcessObserved(id,block.timestamp,m.tickCumulative); }
Who controls it: The pool creator can call: claim creator. The code cannot be changed.
What do these labels mean? Based on the hook’s published code.
What it can do
Its code executes inside each trade in pools that use it.
It can take or add tokens during a swap. Fees, burns and custom curves work this way, and so do scams.
It runs when a pool is created, often to lock in that pool’s settings.
It runs when someone donates tokens to the pool’s LPs.
Hook history
Across all its pools, the hook handled a trade: $0.289, and took its fee from a trade: $0.00584.
- Handled a trade 7 times, worth $0.289
Latest transactions
- 0xa651e4f9…fa625f block 133,112,853
- 0x2ca43734…1e00c4 block 133,112,837
- 0xce2273ac…e3c0a4 block 133,109,930
- 0x3f70a47c…d2663b block 133,109,915
- 0x42c8508b…9583a6 block 133,107,654
- 0x291db6df…4f7d55 block 133,107,642
- 0xf162a5d0…dca03e block 133,107,633
- Took its fee from a trade 7 times, worth $0.00584
Latest transactions
- 0xa651e4f9…fa625f block 133,112,853
- 0x2ca43734…1e00c4 block 133,112,837
- 0xce2273ac…e3c0a4 block 133,109,930
- 0x3f70a47c…d2663b block 133,109,915
- 0x42c8508b…9583a6 block 133,107,654
- 0x291db6df…4f7d55 block 133,107,642
- 0xf162a5d0…dca03e block 133,107,633
- Trade actor 7 times
Latest transactions
- 0xa651e4f9…fa625f block 133,112,853
- 0x2ca43734…1e00c4 block 133,112,837
- 0xce2273ac…e3c0a4 block 133,109,930
- 0x3f70a47c…d2663b block 133,109,915
- 0x42c8508b…9583a6 block 133,107,654
- 0x291db6df…4f7d55 block 133,107,642
- 0xf162a5d0…dca03e block 133,107,633
- Funded the dividend 4 times
Latest transactions
- 0xa651e4f9…fa625f block 133,112,853
- 0xce2273ac…e3c0a4 block 133,109,930
- 0x42c8508b…9583a6 block 133,107,654
- 0x291db6df…4f7d55 block 133,107,642
- Announced a dividend 3 times
Latest transactions
- 0x2ca43734…1e00c4 block 133,112,837
- 0x3f70a47c…d2663b block 133,109,915
- 0xf162a5d0…dca03e block 133,107,633
- Paid pool creators their fees 1 time
Counted from what the hook recorded on-chain across all its pools, for every action in its published code, plus token transfers in and out of it. Dollar values count the amounts paid in ETH, stablecoins, BNB and BTC, at today’s prices.