Extensions
An extension gives a coin its own trading rule. It is a small contract that a launch attaches to its pool. On every swap, the pool asks the extension for an extra fee on top of the coin's own fee. Some extensions also act after each swap.
One option on a launch adds one:
await client.launch({
...launch,
extension: {
preset: "sniper_tax",
buyPips: percentToPips("5"), // buys pay 5% more
sellPips: percentToPips("2"), // sells pay 2% more
endSecs: 600, // for the first 10 minutes, then nothing
},
});
The launch transaction deploys the extension for your pool. There is no separate deploy, and nothing to run afterwards.
The samples on this page use client, launchpads, send, operator and launchpadId from Set up a launchpad, and launch, a launch input, from Configuration.
Why use one
- The rule is public before the first trade. It is written into the coin at launch, with its limits. Nobody can change it, add one or remove one afterwards.
- It earns. The extension's fee is paid in the coin's quote token, such as WETH. 5/7 of it goes to the wallet the launch names, and 2/7 to Bankr.
- Holders can always sell. An extension can add a fee to a sell. It can never refuse one.
- It cannot break trading. If an extension's code fails, the trade goes through without the extension's fee.
A pool has at most one extension.
The built-in extensions
Four extensions ship with the contracts. Fees are in pips: 10,000 pips is 1%.
| Extension | preset | What it does | Parameters | On a new launchpad |
|---|---|---|---|---|
| Sniper Tax | "sniper_tax" | A flat extra fee on buys and sells for a window after trading starts | buyPips, sellPips, endSecs | Up to 10% each way, for at most 1 hour |
| Decay Tax | "decay_tax" | An extra fee that falls in a straight line to zero | startBuyPips, startSellPips, decaySecs | Up to 10% each way, over at most 7 days |
| Pump Brake | "pump_brake" | An extra fee on buys while the price is far above the launch price | brakePips, thresholdTicks | Up to 10%, from about 2x the launch price (6,932 ticks) |
| Raffle Run | presetId: 4 | Every buy mints an NFT ticket, and the extra fee buys the coin back and burns it | See A raffle on every buy | Up to 10% each way, for at most 30 days |
Your launchpad sets each one's limits, or switches it off. See Limits on your launchpad.
What you can build
1. A launch that snipers pay for
Bots that buy in the first minutes pay a high fee, and that fee comes to you. Sniper Tax charges a flat extra fee until endSecs after trading starts. After that it charges nothing.
await client.launch({
...launch,
extension: {
preset: "sniper_tax",
buyPips: percentToPips("8"),
sellPips: percentToPips("8"),
endSecs: 900, // 15 minutes
},
});
Everyone who trades in the window pays it, people and bots alike. Pair it with snipe protection for the first seconds: the coin's own opening fee covers the first block, and Sniper Tax covers the minutes after.
2. A launch tax that fades out
Decay Tax starts at a rate you choose and falls to zero in a straight line. Early traders pay the most, and the tax is gone by a date everyone can see.
await client.launch({
...launch,
extension: {
preset: "decay_tax",
startBuyPips: percentToPips("6"),
startSellPips: percentToPips("6"),
decaySecs: 86_400, // falls to zero over 24 hours
},
});
A 6% start over 24 hours charges 4.5% after 6 hours and 3% after 12.
3. A brake on runaway pumps
Pump Brake adds a fee to buys while the coin trades far above its launch price. Sells never pay it. It has no time limit: the brake applies again whenever the price runs past the threshold.
await client.launch({
...launch,
extension: {
preset: "pump_brake",
brakePips: percentToPips("3"), // buys pay 3% more
thresholdTicks: 23_027, // while the price is over about 10x the launch price
},
});
thresholdTicks | Price above launch |
|---|---|
| 6,932 | About 2x |
| 23,027 | About 10x |
| 46,054 | About 100x |
The brake reads the pool's price averaged over time, not the last trade. One block's push can neither trip it nor dodge it.
4. A raffle on every buy
Raffle Run turns a launch into an event. For the length of the run:
- Every buy above a size you set mints an NFT ticket to the buyer. The tickets are ERC-721 tokens on the extension's own contract.
- Buys and sells pay an extra fee. The extension keeps its part and spends it to buy the coin back and burn it, inside later sells.
You run the draw. The tickets are on-chain, so you can pick winners from them any way you like.
import { encodeExtensionPresetParams } from "@bankr/launch-sdk";
import { parseEther } from "viem";
await client.launch({
...launch,
extension: {
presetId: 4, // Raffle Run
params: encodeExtensionPresetParams({
preset: "raffle_run",
buyPips: percentToPips("1"), // buys pay 1% more during the run
sellPips: percentToPips("1"),
runSecs: 7 * 86_400, // the run lasts 7 days
minTicketQuote: parseEther("0.01"), // a buy of 0.01 ETH or more mints a ticket
minBuyback: parseEther("0.0001"), // the least one buyback spends
anchorTauSecs: 21_600, // how slowly the buyback's price ceiling follows the market: 6 hours
}),
},
});
Bankr runs no draw and no interface for Raffle Run: you pick the winners and pay the prizes. Test your raffle before you put it in front of users. A pool with Raffle Run needs more gas on every swap than one with a fee-only extension.
5. A tax that funds a treasury
An extension's fee goes to the launch's first fee recipient by default. Name any other wallet with payee: a community treasury, a team Safe, a cause.
await client.launch({
...launch,
extension: {
preset: "decay_tax",
startBuyPips: percentToPips("4"),
startSellPips: percentToPips("4"),
decaySecs: 7 * 86_400, // one week
payee: "0x5555555555555555555555555555555555555555", // your treasury
},
});
The creator still earns the coin's own trading fees. The tax goes to the treasury. A launch with several fee recipients must name the payee.
6. A launchpad with a house rule
Make an extension part of what your launchpad is. On a launchpad with a signer, your server approves each launch, so it can require one:
// app/api/launch/authorize/route.ts
import { privateKeyToAccount } from "viem/accounts";
import { createAuthorizeHandler } from "@bankr/launch-sdk/server";
const SNIPER_TAX = 1; // the built-in extensions' ids: 1 Sniper Tax, 2 Decay Tax, 3 Pump Brake, 4 Raffle Run
export const POST = createAuthorizeHandler({
account: privateKeyToAccount(process.env.PAD_SIGNER_KEY as `0x${string}`),
chain: "base",
launchpadId: BigInt(process.env.LAUNCHPAD_ID ?? ""),
authorize(_req, launch) {
// Every coin on this launchpad launches with Sniper Tax.
if (launch.params.extension.id !== SNIPER_TAX) {
throw new Response(
JSON.stringify({ error: "Launches here carry Sniper Tax." }),
{ status: 403 },
);
}
},
});
Your app then adds the extension to every launch it builds, and your users never have to think about it.
7. A confirm screen that shows the fee, minute by minute
client.previewExtension reads what an extension will charge and whether it can launch on your launchpad now. It plans nothing and sends nothing. Use it to draw the fee curve before your user signs.
const preview = await client.previewExtension(
{
preset: "decay_tax",
startBuyPips: 40_000,
startSellPips: 40_000,
decaySecs: 3_600,
},
{ launchpadId },
);
console.log(preview.label); // "Decay Tax · Bankr preset"
console.log(preview.description); // "Decay Tax: buys +4%, sells +4% falling to 0 over 3600s"
for (const row of preview.feeTable)
console.log(
`${row.secsSinceLaunch}s: buys ${pipsToPercent(row.buy.totalPips)}%, sells ${pipsToPercent(row.sell.totalPips)}%`,
);
if (preview.refusal) console.log(`cannot launch: ${preview.refusal}`);
| Field | Meaning |
|---|---|
label | A short tag, such as Sniper Tax · Bankr preset. |
description | One line on what it charges. |
feeTable | The coin's fee and the extension's fee together, over time. |
payee | Who is paid. null means the launch's first fee recipient. |
payeeShareBps | The payee's part of the fee, in bps. |
refusal | Why a launch with it would be refused now, or null. |
swapGasHeadroom | What it adds to a swap's gas limit. |
warnings | Sentences a confirm screen should show, such as a fee above 5%. |
A plan carries the same object as plan.extension.
8. Your own rule, in Solidity
When no built-in fits, write the rule yourself. An extension implements two functions:
quote(ctx, extData)is a read-only call before each swap. It returns the extra fee in pips.afterSwap(ctx, delta, extFee, extData)is a call after each swap, for code that acts on a trade, as Raffle Run does. An extension that only sets a fee leaves it empty.
ctx tells the extension the pool, whether the swap is a buy, the amount, the coin's own fee on this swap, the seconds since trading started and the pool's price before the swap.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
/// Everything an extension learns about a swap.
struct SwapCtx {
address sender; // the router that called the pool, not the trader
bytes32 poolId;
bool isBuy; // quote token in, coin out
int256 amountSpecified; // as Uniswap v4 passes it: negative is an exact input
uint24 bankrFeePips; // the coin's own fee on this swap
uint32 secsSinceLaunch; // seconds since trading started
uint160 sqrtPriceX96; // the pool's price before this swap
}
/// The interface every extension implements.
interface IBankrHookExtension {
/// Called before each swap. Returns the extra fee in pips. It can read anything and write nothing.
function quote(SwapCtx calldata ctx, bytes calldata extData) external view returns (uint24 extraPips);
/// Called after each swap, unless the launch declared the extension `quoteOnly`.
function afterSwap(SwapCtx calldata ctx, BalanceDelta delta, uint256 extFee, bytes calldata extData) external;
}
/// A tax that steps down by the day: 5% on the first day of trading, 4% on the second, and nothing from day six.
contract StepDownTax is IBankrHookExtension {
function quote(SwapCtx calldata ctx, bytes calldata) external pure returns (uint24) {
uint256 day = ctx.secsSinceLaunch / 1 days;
return day >= 5 ? 0 : uint24((5 - day) * 10_000); // in pips: 10,000 is 1%
}
// It only sets a fee, so it does nothing after a swap.
function afterSwap(SwapCtx calldata, BalanceDelta, uint256, bytes calldata) external {}
}
The file is complete: it needs only Uniswap's v4-core for BalanceDelta.
Three steps take it live:
- Deploy the code. It must be immutable: the pool checks that the address holds exactly the code hash the launch named.
- Bankr adds its code hash to the allowlist. Only allowlisted code can launch. Ask through the Bankr Help Center, with the extension's address and its source. An allowlisted extension is not tied to one launchpad or one coin.
- Allow custom code on your launchpad, then launch with it:
await send(
await launchpads.configure(launchpadId, {
switches: { extQuoteOnly: true }, // custom code that only sets a fee
knobs: { extMaxPips: { max: percentToPips("5") } }, // the most any extension may add to a fee here
}),
);
const customExtensionLaunch = {
...launch,
extension: {
address: "0x6666666666666666666666666666666666666666", // your deployed extension
codehash:
"0x7777777777777777777777777777777777777777777777777777777777777777", // its code hash
maxBuyPips: percentToPips("5"), // the most it may add to a buy
maxSellPips: percentToPips("5"), // the most it may add to a sell
quoteOnly: true, // it only sets a fee
sunsetSecs: 6 * 86_400, // the pool stops asking it after six days
},
} satisfies LaunchInput<"base">;
| Field | Meaning |
|---|---|
address | The deployed extension. |
codehash | The code hash of that address. The launch reverts on any other. |
maxBuyPips | The most it may add to a buy, at most your launchpad's extMaxPips. The pool never charges more. |
maxSellPips | The same, for a sell. |
quoteOnly | true: the pool only asks for a fee. false: it also calls the extension after each swap. |
sunsetSecs | Seconds after the trading start from which the pool never asks again. 0 means never. |
quoteGas | Gas the fee call is handed on every swap: 50,000 to 250,000. Leave it out for 50,000. |
afterGas | Gas the after-swap call is handed: 150,000 to 1,000,000. Leave it out for 150,000. None when quoteOnly. |
payee | Who is paid the fee. Default: the launch's first fee recipient. |
The allowlist is a review. It is not an audit and not an endorsement. Custom code runs on every trade of the coin, and it can refuse buys. The contracts guarantee only the rules below. Everything else is between you and the code.
The rules every extension lives under
The contracts enforce these, whatever the extension's code does.
- A fee ceiling. The coin's own fee and the extension's fee together never pass the pool's ceiling: 10% on a new launchpad. While the coin's own fee is at the ceiling or above it, such as during snipe protection, the extension charges nothing.
- Declared maximums. A launch declares the most its extension may add to a buy and to a sell. The pool never charges more.
- Sells always go through. An extension can refuse a buy. It can never refuse a sell. None of the built-in extensions refuses buys.
- A failing extension charges nothing. If the fee call reverts or runs out of gas, the trade goes through without the extension's fee.
- Code after the swap cannot break a trade. If it fails, the pool undoes everything that code did, and the trade lands.
- A window is longer than the coin's own fee decay. An extension's window must outlast the launch's snipe protection.
- Windows count from the trading start. On a launch with a scheduled start, that is the start, not the launch transaction.
- It is permanent. The extension, its maximums, its payee and its end are fixed with the coin.
Bankr can switch an extension's fee off on live pools, and on again. While it is off, the extension charges nothing and trading goes on. This can only stop an extra fee, never add one.
Who receives the fee
Every extension fee is taken in the pool's quote token and splits when it is charged:
| Part | Who | Share |
|---|---|---|
| Bankr | Bankr | 2/7 (28.57%) |
| The rest | The payee the launch named. By default, the launch's first fee recipient. | 5/7 (71.43%) |
Your launchpad's payees and the coin's holders take no part of an extension's fee. They share the coin's own trading fee.
The payee's part is credited as claim tokens of the quote token at Uniswap's PoolManager. The payee turns them into the quote token in two steps. publicClient and walletClient here are the payee's:
const { factory, claimsRedeemer, weth } = client.provider.addresses;
const poolManager = await publicClient.readContract({
address: factory,
abi: parseAbi(["function poolManager() view returns (address)"]),
functionName: "poolManager",
});
// Once: let the claims redeemer act for the payee.
await walletClient.sendTransaction({
to: poolManager,
data: encodeFunctionData({
abi: parseAbi(["function setOperator(address operator, bool approved)"]),
functionName: "setOperator",
args: [claimsRedeemer, true],
}),
});
// Any time: redeem everything the payee holds in WETH. Anyone can send it, and it pays the payee only.
await walletClient.sendTransaction({
to: claimsRedeemer,
data: encodeFunctionData({
abi: parseAbi([
"function redeem(address owner, address currency, uint256 amount)",
]),
functionName: "redeem",
args: [walletClient.account.address, weth, 2n ** 256n - 1n], // the highest amount redeems the whole balance
}),
});
Swaps need more gas
A pool with an extension needs a higher gas limit on every swap, for the pool's whole life. Routers and aggregators that already route Bankr pools add it. If you build your own swaps, add the pool's figure to your gas estimate:
import { readExtSwapGasHeadroom, swapGasHeadroom } from "@bankr/launch-sdk";
import type { Hex } from "viem";
// `poolId` is the coin's pool id: `result.poolId` from the launch.
export async function extraSwapGas(poolId: Hex) {
const extHeadroom = await readExtSwapGasHeadroom(client.publicClient, {
hook: client.provider.addresses.hook,
poolId,
});
return swapGasHeadroom({ extHeadroom }); // 960,000 for any Bankr pool, plus the extension's figure
}
Gas used does not change. A swap sent with too little headroom reverts rather than skip the extension.
Limits on your launchpad
Your launchpad decides which extensions a launch may use, and how far each may go.
// Sniper Tax may run for at most 10 minutes on this launchpad. Pump Brake is off.
await send(
await launchpads.setPresetLimits(launchpadId, "sniperTax", {
maxWindowSecs: 600,
}),
);
await send(
await launchpads.setPresetLimits(launchpadId, "pumpBrake", {
allowed: false,
}),
);
| Setting | What it does | A new launchpad |
|---|---|---|
extPresets switch | Allows the built-in extensions. | On |
setPresetLimits(id, preset, limits) | Allows or refuses one built-in extension, and sets its longest window. | Each allowed |
extQuoteOnly switch | Allows custom code that only sets a fee. | Off |
extCallsOut switch | Allows custom code that also acts after each swap. | Off |
extMaxPips knob | The most an extension, built-in or custom, may add to a fee. | Up to 10% |
feeCeilingPips knob | The most the coin's fee and the extension's fee reach together. | Fixed at 10% |
The launchpad's settings name the built-in extensions "sniperTax", "decayTax", "pumpBrake" and "raffleRun".
A parameter outside a limit throws EXTENSION_OUT_OF_BOUNDS, and err.detail names the limit. An extension that cannot launch on the launchpad throws EXTENSION_NOT_ALLOWED with the reason. Both are thrown before anything is signed.