mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-11-02 06:16:10 +00:00
* feat(cookbook): cover every create_v2 coin parameter in the launch scripts Both create scripts now build create_v2 through pumpfun_instructions_v2 instead of each carrying their own copy of the discriminators, PDAs and account list. - A holder-reward coin's curve creator is derived rather than assumed, so the opening buy finds the matching creator vault instead of reverting. - create_v2's three trailing arguments are settable independently. None omits an argument, a value sends it, so all four wire forms are reachable and an explicit default is distinct from an omission. - create_v2 carries all four remaining accounts, quote_control included. Without them the program ignores creator_fee_bps. - --creator, --creator-fee-bps and --quote-mint added. A creator fee on a SOL-paired coin warns, because the program stores zero for it; the create-and-buy script refuses one outright before sending anything. - The opening buy is sized from Global's reserves and fee rates. - Mayhem mode is off by default. Removes the fee-recipient lookup whose result was discarded and the buy wrapper whose parameters were unused. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(regression): verify the launch path's create_v2 arguments Eight offline checks: the substituted creator on a holder-reward coin, every committed create_v2 fixture round-tripping through the trailing argument encoder, all four wire forms being reachable, --creator reaching the wire, the opening buy following Global rather than constants, the Global decoder stopping cleanly on a short buffer, and the four quote accounts being present with the ATA under the quote mint's own program. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: correct create_v2's remaining accounts and the creator-fee rule create_v2 takes four remaining accounts, not three; the fourth is the QuoteControl PDA. Omitting them is accepted and yields a SOL-paired coin, which is also how a creator fee goes missing: the program applies creator_fee_bps only to a coin priced in something other than SOL, and otherwise stores zero without an error. Also records that solders documents TransactionConfig.priority_fee as micro-lamports while SIMD-0385 defines the field as total lamports. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): price a new coin in an asset other than SOL --quote-mint on both create scripts, checked against both registries that admit a quote asset. QuoteControl carries most of them with a per-mint opening reserve; Global.whitelisted_quote_mints carries USDC, which QuoteControl does not list, so consulting either alone refuses a mint the program accepts. A mint neither admits is refused rather than priced from a default, since the opening reserve spans orders of magnitude. The quote mint's token program and decimals are resolved from chain, and --amount is denominated in the quote asset rather than in SOL. A paused mint is refused before anything is sent, and a scaled-UI mint says so, because amounts here are raw units. A creator fee now works, since pump.fun applies one only to a coin priced in something other than SOL. On a SOL-paired coin it is refused instead of being accepted and stored as zero. The create-and-buy script requires the wallet to already hold the quote asset; it does not acquire one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): launch a coin in one v1 transaction Create, extend, the buyer's token account and the buy now travel under a single signature, so nobody can buy between the create and the opening buy. They were split because the two together are 1479 bytes against the 1232 a v0 transaction is held to; SIMD-0296 raised the limit to 4096 for v1 and the combined message uses about a third of it. v1 has no address lookup tables -- the larger limit exists so the whole account list goes inline -- and it carries the compute budget in the message header, so the script sends no ComputeBudget instructions. The priority fee is now one total in lamports rather than micro-lamports per compute unit; the constant is converted, not renamed. The two-transaction path is removed rather than kept behind a flag. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): state the loaded-accounts data size limit on the v1 launch A v1 message carries this limit in its header, and left unset it is zero rather than the network default, so the runtime rejects the transaction for exceeding it. The launch skips preflight, so the rejection never reached the caller: send returned a signature that never landed. Measured against a forked mainnet, the launch is rejected at 128 KiB and lands at 256 KiB. The limit is set to 1 MiB, which leaves room for a quote mint whose accounts are larger, and the verifier fails if it is dropped or set at or below the measured failing size. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): offer the launch as a v0 or a v1 transaction The Solana transaction version changes what a launch can be, so it is the script that changes rather than a flag on one of them. _txv1 sends create and buy under a single signature, so the coin is bought by the transaction that creates it. _txv0 sends them as two transactions, because together they do not fit what a v0 transaction can carry, and anyone watching the create can buy in the gap. Use it when the endpoint will not take a v1 send. The coin is identical either way: quote asset, creator fee, holder rewards and mayhem mode all behave the same. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * refactor(cookbook): drop the instruction version from script names The cookbook ships one form of each pump.fun action, so `_v2` in a basename distinguished nothing — and it read as a Solana transaction version, which is a different thing and now appears in the same names. `pumpfun_buy_token_exact_sol_in.py` already went without it. Every trade script loses the suffix, the shared module becomes `pumpfun_instructions.py`, and the retired path is named for what it is rather than for the instruction set it uses. The instruction each script builds is named in its docstring, where it cannot be mistaken for a transaction version. `txv0`/`txv1` is now the only version marker in any filename, and it is the one the reader chooses between. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): refuse mayhem mode paired with a non-SOL quote asset The program rejects the pairing with MayhemModeQuoteMintNotAllowed (6071), so a mayhem coin is always SOL-paired — and therefore can never carry a creator fee, which needs a non-SOL quote. Both create scripts now refuse the combination before sending, rather than letting it land as a reverted transaction that has already cost fees. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): size the v1 loaded-accounts limit for what mainnet loads The limit counts the executable data of every program a transaction touches, not just the accounts it names, and the pump program's own code is the bulk of it. The previous figure was set against a local fork, which does not charge for executables; on mainnet the launch was rejected with MaxLoadedAccountsDataSizeExceeded. Set to the network default a v0 transaction gets when nothing narrows it, which is the behaviour being reproduced. The verifier now holds the mainnet figure as its floor. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): a creator fee needs a QuoteControl quote mint, not just a non-SOL one Measured on mainnet: the fee is applied on a coin priced in a mint QuoteControl admits, whether that mint is SPL Token or Token-2022, and is not applied on wrapped SOL or on USDC — which the older Global whitelist carries and QuoteControl does not. The deciding property is registry membership, so the previous check let a USDC-priced coin through and the program stored zero without an error. Also stops the sell script calling a price "SOL" when the curve is priced in something else. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): offer the create-only script as a v0 or a v1 transaction Same split as the create-and-buy pair, for the same reason: the Solana transaction version is the reader's choice, so it is the script that changes rather than a flag. _txv1 carries the compute budget in the message header and sends no ComputeBudget instructions; _txv0 sends them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): refuse a paused quote mint on the create-and-buy path too The check only ran in the create-only scripts, so a launch that also buys could reach the chain with a quote mint whose transfers are paused. On the two-transaction path that leaves a created coin nobody bought, after the create has already cost rent. Also corrects the v1 script's run docstring, which still described two transactions and a spend denominated in SOL. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): say --amount is in whole quote units, not raw ones The scaled-UI notice told the reader the opposite of what the scripts do: --amount is multiplied by the mint's decimals, so it is a whole-token figure. A reader who followed the notice would have overspent by a factor of the decimals. Reworded so the multiplier is described as what it is — a display scale a wallet applies — rather than as something the amount has to account for. The create-only scripts carried the same wording without even taking an amount. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
266 lines
9.6 KiB
Python
266 lines
9.6 KiB
Python
"""Verify a coin's quote asset is chosen from the registries, not assumed.
|
|
|
|
A coin can be priced in an asset other than SOL, and picking that asset wrong is
|
|
not a near miss: the opening reserve, the decimals and the token program all
|
|
change with it.
|
|
|
|
Two registries are live and neither is a superset of the other.
|
|
`Global.whitelisted_quote_mints` holds one entry; `QuoteControl` holds far more,
|
|
and USDC is in the former and not the latter. Validating against either alone
|
|
refuses a mint the program accepts.
|
|
|
|
They are not interchangeable once a coin carries a creator fee, either: the fee
|
|
is applied only on a coin priced in a `QuoteControl` mint. On wrapped SOL, and
|
|
on a mint only the Global whitelist carries, the program takes the argument and
|
|
stores zero.
|
|
|
|
The opening virtual quote reserve is per mint and spans orders of magnitude
|
|
across the admitted set, so substituting a default for an unlisted mint
|
|
misprices the opening buy rather than approximating it.
|
|
|
|
Tokenised equities among the admitted mints carry Token-2022 extensions their
|
|
issuer controls. `pausableConfig` fails every trade on every coin priced in that
|
|
mint while it is set, so it is refused up front rather than discovered at buy
|
|
time.
|
|
|
|
Offline machine checks, no network and no funds moved:
|
|
|
|
1. QuoteControl decodes into mint -> opening reserve, and a truncated entry
|
|
at the tail is dropped rather than read past the end of the buffer.
|
|
2. A mint QuoteControl admits prices from its own entry.
|
|
3. A mint only `Global.whitelisted_quote_mints` lists prices from Global's
|
|
`initial_virtual_quote_reserves` -- the USDC case.
|
|
4. Wrapped SOL prices from Global's `initial_virtual_sol_reserves`.
|
|
5. A mint neither registry admits raises, rather than taking a default.
|
|
6. A paused quote mint is refused.
|
|
7. A scaled-UI quote mint reports its multiplier, and an ordinary mint
|
|
reports none.
|
|
8. A creator fee is refused unless QuoteControl admits the quote mint.
|
|
Anywhere else the program takes the argument and stores zero, and a mint
|
|
the older Global whitelist carries -- USDC -- is one of those places.
|
|
9. Mayhem mode paired with a non-SOL quote asset is refused before sending.
|
|
The program rejects the pairing with MayhemModeQuoteMintNotAllowed
|
|
(6071), and a create that reaches the chain has already cost fees.
|
|
|
|
Usage:
|
|
uv run tests/regression/verify_quote_asset_selection.py
|
|
"""
|
|
|
|
import struct
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(PROJECT_ROOT / "cookbook" / "pumpfun" / "trade"))
|
|
|
|
import pumpfun_instructions as pump # noqa: E402
|
|
from solders.keypair import Keypair # noqa: E402
|
|
from solders.pubkey import Pubkey # noqa: E402
|
|
|
|
USDC = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
|
|
|
|
# One real QuoteControl entry, used as a value distinct from Global's figure.
|
|
REGISTRY_RESERVE = 16_685_497
|
|
SCALED_MULTIPLIER = 1.0026642
|
|
FLOAT_TOLERANCE = 1e-9
|
|
|
|
GLOBAL = {
|
|
"initial_virtual_sol_reserves": 30_000_000_000,
|
|
"initial_virtual_quote_reserves": 4_292_000_000,
|
|
"whitelisted_quote_mints": [USDC],
|
|
}
|
|
|
|
|
|
def build_quote_control(entries: list[tuple[Pubkey, int]], *, truncate: bool) -> bytes:
|
|
"""Serialize a QuoteControl account holding `entries`."""
|
|
head = bytes(8) + bytes(32) + bytes(64)
|
|
body = struct.pack("<I", len(entries))
|
|
for mint, reserves in entries:
|
|
body += bytes(mint) + struct.pack("<Q", reserves)
|
|
if truncate:
|
|
body = body[:-12]
|
|
return head + body
|
|
|
|
|
|
def check_registry_decodes() -> bool:
|
|
mints = [(Keypair().pubkey(), 1_000 * (i + 1)) for i in range(4)]
|
|
decoded = pump.decode_quote_control(build_quote_control(mints, truncate=False))
|
|
if decoded != dict(mints):
|
|
print(f" decoded {len(decoded)} entries, expected {len(mints)}")
|
|
return False
|
|
clipped = pump.decode_quote_control(build_quote_control(mints, truncate=True))
|
|
if len(clipped) != len(mints) - 1:
|
|
print(f" a truncated tail gave {len(clipped)} entries, expected 3")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_registry_mint_prices_from_its_entry() -> bool:
|
|
mint = Keypair().pubkey()
|
|
registry = {mint: REGISTRY_RESERVE}
|
|
got = pump.opening_quote_reserves(registry, mint, GLOBAL)
|
|
if got != REGISTRY_RESERVE:
|
|
print(f" got {got}, expected the registry entry")
|
|
return False
|
|
# Not Global's figure, which is what a one-registry implementation returns.
|
|
if got == GLOBAL["initial_virtual_quote_reserves"]:
|
|
print(" fell back to Global instead of using the entry")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_global_whitelisted_mint_is_accepted() -> bool:
|
|
got = pump.opening_quote_reserves({}, USDC, GLOBAL)
|
|
if got != GLOBAL["initial_virtual_quote_reserves"]:
|
|
print(f" got {got}, expected Global's initial_virtual_quote_reserves")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_wrapped_sol_uses_the_sol_reserve() -> bool:
|
|
got = pump.opening_quote_reserves({}, pump.WSOL_MINT, GLOBAL)
|
|
return got == GLOBAL["initial_virtual_sol_reserves"]
|
|
|
|
|
|
def check_unlisted_mint_raises() -> bool:
|
|
stranger = Keypair().pubkey()
|
|
try:
|
|
got = pump.opening_quote_reserves({}, stranger, GLOBAL)
|
|
except ValueError:
|
|
return True
|
|
print(f" returned {got} for a mint neither registry admits")
|
|
return False
|
|
|
|
|
|
def check_paused_mint_is_refused() -> bool:
|
|
mint = Keypair().pubkey()
|
|
paused = {
|
|
"extensions": [{"extension": "pausableConfig", "state": {"paused": True}}]
|
|
}
|
|
try:
|
|
pump.check_quote_mint_tradable(mint, paused)
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
print(" a paused mint was accepted")
|
|
return False
|
|
live = {"extensions": [{"extension": "pausableConfig", "state": {"paused": False}}]}
|
|
try:
|
|
pump.check_quote_mint_tradable(mint, live)
|
|
except ValueError:
|
|
print(" an unpaused mint was refused")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_scaled_multiplier_is_reported() -> bool:
|
|
mint = Keypair().pubkey()
|
|
scaled = {
|
|
"extensions": [
|
|
{
|
|
"extension": "scaledUiAmountConfig",
|
|
"state": {"multiplier": str(SCALED_MULTIPLIER)},
|
|
}
|
|
]
|
|
}
|
|
got = pump.check_quote_mint_tradable(mint, scaled)
|
|
if got is None or abs(got - SCALED_MULTIPLIER) > FLOAT_TOLERANCE:
|
|
print(f" multiplier came back as {got}")
|
|
return False
|
|
if pump.check_quote_mint_tradable(mint, {"extensions": []}) is not None:
|
|
print(" an unscaled mint reported a multiplier")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_fee_needs_a_registry_mint() -> bool:
|
|
listed = Keypair().pubkey()
|
|
registry = {listed: REGISTRY_RESERVE}
|
|
|
|
# Allowed where the fee is actually applied.
|
|
try:
|
|
pump.check_creator_fee_quote(registry, listed, 250)
|
|
except ValueError:
|
|
print(" refused a fee on a mint QuoteControl admits")
|
|
return False
|
|
|
|
# Refused everywhere it would silently store zero.
|
|
for label, mint in (
|
|
("wrapped SOL", pump.WSOL_MINT),
|
|
("a Global-whitelisted mint", USDC),
|
|
("an unlisted mint", Keypair().pubkey()),
|
|
):
|
|
try:
|
|
pump.check_creator_fee_quote(registry, mint, 250)
|
|
except ValueError:
|
|
continue
|
|
print(f" allowed a fee against {label}, which stores zero")
|
|
return False
|
|
|
|
# No fee requested is never refused, whatever the mint.
|
|
try:
|
|
pump.check_creator_fee_quote(registry, pump.WSOL_MINT, None)
|
|
pump.check_creator_fee_quote(registry, pump.WSOL_MINT, 0)
|
|
except ValueError:
|
|
print(" refused a launch that asked for no fee at all")
|
|
return False
|
|
return True
|
|
|
|
|
|
def check_mayhem_rejects_a_non_sol_quote() -> bool:
|
|
stranger = Keypair().pubkey()
|
|
try:
|
|
pump.check_mayhem_quote_pairing(stranger, is_mayhem_mode=True)
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
print(" a mayhem coin was allowed a non-SOL quote asset")
|
|
return False
|
|
# The pairing is only refused for mayhem, and only for a non-SOL asset.
|
|
try:
|
|
pump.check_mayhem_quote_pairing(stranger, is_mayhem_mode=False)
|
|
pump.check_mayhem_quote_pairing(pump.WSOL_MINT, is_mayhem_mode=True)
|
|
except ValueError:
|
|
print(" refused a pairing the program accepts")
|
|
return False
|
|
return True
|
|
|
|
|
|
def main() -> int:
|
|
checks = [
|
|
("QuoteControl decodes, short tail dropped", check_registry_decodes),
|
|
(
|
|
"a QuoteControl mint prices from its entry",
|
|
check_registry_mint_prices_from_its_entry,
|
|
),
|
|
(
|
|
"a Global-whitelisted mint is accepted",
|
|
check_global_whitelisted_mint_is_accepted,
|
|
),
|
|
("wrapped SOL uses the SOL reserve", check_wrapped_sol_uses_the_sol_reserve),
|
|
("a mint neither registry admits raises", check_unlisted_mint_raises),
|
|
("a paused quote mint is refused", check_paused_mint_is_refused),
|
|
(
|
|
"a scaled quote mint reports its multiplier",
|
|
check_scaled_multiplier_is_reported,
|
|
),
|
|
("a fee needs a QuoteControl mint", check_fee_needs_a_registry_mint),
|
|
("mayhem refuses a non-SOL quote", check_mayhem_rejects_a_non_sol_quote),
|
|
]
|
|
failed = 0
|
|
for label, check in checks:
|
|
try:
|
|
ok = check()
|
|
except Exception as error: # noqa: BLE001 - report and continue
|
|
print(f"FAIL {label}: {type(error).__name__}: {error}")
|
|
failed += 1
|
|
continue
|
|
print(f"{'PASS' if ok else 'FAIL'} {label}")
|
|
failed += 0 if ok else 1
|
|
print(f"\n{len(checks) - failed}/{len(checks)} checks passed")
|
|
return 1 if failed else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|