@floorlaunchpad/sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/LICENSE +201 -60
- package/README.md +45 -24
- package/dist/abi/evm-event-names.js +12 -0
- package/dist/abi/evm.gen.js +130 -0
- package/dist/abi/functions.gen.js +144 -0
- package/dist/abi/index.js +17 -0
- package/dist/abi/solana.gen.js +128 -0
- package/dist/burn.js +21 -0
- package/dist/client/evm/index.js +191 -0
- package/dist/client/index.js +19 -0
- package/dist/client/solana/index.js +259 -0
- package/dist/client/types.js +5 -0
- package/dist/codec.js +77 -0
- package/dist/config/codeHash.js +9 -0
- package/dist/config/generated.js +746 -0
- package/dist/config/index.js +49 -0
- package/dist/config/registry.gen.js +118 -0
- package/dist/config/solana-genesis.js +7 -0
- package/dist/ed25519.js +31 -0
- package/dist/errors.js +249 -0
- package/dist/events/index.js +40 -0
- package/dist/events/types.gen.js +3 -0
- package/dist/evm/abi.js +283 -0
- package/dist/evm/balances.js +26 -0
- package/dist/evm/chains.js +144 -0
- package/dist/evm/floor/abi.gen.js +195 -0
- package/dist/evm/floor/calls.js +230 -0
- package/dist/evm/floor/create.js +49 -0
- package/dist/evm/floor/events.js +41 -0
- package/dist/evm/floor/iface.js +44 -0
- package/dist/evm/items.js +209 -0
- package/dist/evm/keccak.js +118 -0
- package/dist/evm/multicall.js +30 -0
- package/dist/evm/router.js +184 -0
- package/dist/evm/zap.js +128 -0
- package/dist/fixtures.js +53 -0
- package/dist/generated/index.js +28 -0
- package/dist/generated/interface.gen.js +146 -0
- package/dist/handle.js +22 -0
- package/dist/index.js +91 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +104 -0
- package/dist/indexer/contract.js +349 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +100 -0
- package/dist/indexer/paths.js +127 -0
- package/dist/indexer/read.js +109 -0
- package/dist/indexer/stream.js +71 -0
- package/dist/lock.js +16 -0
- package/dist/math/fixed.js +154 -0
- package/dist/math/genesis.js +39 -0
- package/dist/math/index.js +20 -0
- package/dist/math/u256.js +49 -0
- package/dist/math/v2/ask.js +162 -0
- package/dist/math/v2/book.js +607 -0
- package/dist/math/v2/circulating.js +62 -0
- package/dist/math/v2/create.js +122 -0
- package/dist/math/v2/display.js +208 -0
- package/dist/math/v2/error.js +17 -0
- package/dist/math/v2/feasibility.js +174 -0
- package/dist/math/v2/fees.js +121 -0
- package/dist/math/v2/holders.js +105 -0
- package/dist/math/v2/milestones.js +40 -0
- package/dist/math/v2/pow.js +69 -0
- package/dist/math/v2/preset.js +151 -0
- package/dist/math/v2/receipt.js +108 -0
- package/dist/math/v2/relay.js +217 -0
- package/dist/math/v2/rows.js +365 -0
- package/dist/math/v2/split.js +111 -0
- package/dist/math/v2/sqrt.js +84 -0
- package/dist/math/v2/supply.js +21 -0
- package/dist/math/v2/team.js +75 -0
- package/dist/math/v2/trade.js +126 -0
- package/dist/math/v2/wide.js +51 -0
- package/dist/quote.js +6 -0
- package/dist/registryPrice.js +23 -0
- package/dist/route/edge-jupiter.js +42 -0
- package/dist/route/edge.js +11 -0
- package/dist/route/graph.js +51 -0
- package/dist/route/path.js +75 -0
- package/dist/route/quote.js +15 -0
- package/dist/route-jupiter.js +35 -0
- package/dist/route.js +8 -0
- package/dist/sha256.js +61 -0
- package/dist/solana/alt.js +18 -0
- package/dist/solana/floor/accounts.js +390 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +140 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +435 -0
- package/dist/solana/floor/metadata.js +198 -0
- package/dist/solana/floor/mint.js +206 -0
- package/dist/solana/floor/program.js +64 -0
- package/dist/solana/floor/registry.js +83 -0
- package/dist/solana/instruction.js +49 -0
- package/dist/solana/pda.js +88 -0
- package/dist/solana/tx.js +138 -0
- package/dist/v2/burnPreview.js +35 -0
- package/dist/v2/circulating.js +11 -0
- package/dist/v2/claimAllEvm.js +70 -0
- package/dist/v2/claims-evm.js +120 -0
- package/dist/v2/claims.js +218 -0
- package/dist/v2/dead.js +21 -0
- package/dist/v2/devbuy.js +37 -0
- package/dist/v2/events.js +115 -0
- package/dist/v2/evm.js +299 -0
- package/dist/v2/evmReads.js +76 -0
- package/dist/v2/genesis.js +76 -0
- package/dist/v2/layouts.js +217 -0
- package/dist/v2/market-evm.js +74 -0
- package/dist/v2/presetRowEvm.js +45 -0
- package/dist/v2/press.js +106 -0
- package/dist/v2/quoteMint.js +52 -0
- package/dist/v2/receipt-tx.js +149 -0
- package/dist/v2/route-alt.js +114 -0
- package/dist/v2/route.js +389 -0
- package/dist/v2/solana.js +391 -0
- package/dist/v2/solanaSettle.js +97 -0
- package/dist/v2/tx/evm.js +126 -0
- package/dist/v2/tx/genesis.js +47 -0
- package/dist/v2/tx/index.js +5 -0
- package/dist/v2/tx/solana.js +118 -0
- package/dist/v2/types.js +13 -0
- package/docs/aggregator.md +61 -0
- package/docs/bot.md +50 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/package.json +428 -32
- package/src/abi/evm-event-names.ts +12 -0
- package/src/abi/evm.gen.ts +139 -0
- package/src/abi/functions.gen.ts +154 -0
- package/src/abi/index.ts +30 -0
- package/src/abi/solana.gen.ts +138 -0
- package/src/burn.ts +37 -0
- package/src/client/evm/index.ts +199 -0
- package/src/client/index.ts +23 -0
- package/src/client/solana/index.ts +260 -0
- package/src/client/types.ts +162 -0
- package/src/codec.ts +77 -0
- package/src/config/codeHash.ts +9 -0
- package/src/config/generated.ts +746 -0
- package/src/config/index.ts +91 -0
- package/src/config/registry.gen.ts +118 -0
- package/src/config/solana-genesis.ts +7 -0
- package/src/ed25519.ts +31 -0
- package/src/errors.ts +270 -0
- package/src/events/index.ts +44 -0
- package/src/events/types.gen.ts +831 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +167 -0
- package/src/evm/floor/abi.gen.ts +195 -0
- package/src/evm/floor/calls.ts +247 -0
- package/src/evm/floor/create.ts +68 -0
- package/src/evm/floor/events.ts +51 -0
- package/src/evm/floor/iface.ts +45 -0
- package/src/evm/items.ts +252 -0
- package/src/evm/keccak.ts +118 -0
- package/src/evm/multicall.ts +43 -0
- package/src/evm/router.ts +209 -0
- package/src/evm/zap.ts +152 -0
- package/src/fixtures.ts +53 -0
- package/src/generated/index.ts +29 -0
- package/src/generated/interface.gen.ts +153 -0
- package/src/handle.ts +22 -0
- package/src/index.ts +91 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +178 -0
- package/src/indexer/contract.ts +410 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +109 -0
- package/src/indexer/paths.ts +190 -0
- package/src/indexer/read.ts +119 -0
- package/src/indexer/stream.ts +83 -0
- package/src/lock.ts +16 -0
- package/src/math/fixed.ts +154 -0
- package/src/math/genesis.ts +39 -0
- package/src/math/index.ts +24 -0
- package/src/math/u256.ts +49 -0
- package/src/math/v2/ask.ts +218 -0
- package/src/math/v2/book.ts +660 -0
- package/src/math/v2/circulating.ts +69 -0
- package/src/math/v2/create.ts +139 -0
- package/src/math/v2/display.ts +250 -0
- package/src/math/v2/error.ts +19 -0
- package/src/math/v2/feasibility.ts +200 -0
- package/src/math/v2/fees.ts +121 -0
- package/src/math/v2/holders.ts +124 -0
- package/src/math/v2/milestones.ts +51 -0
- package/src/math/v2/pow.ts +71 -0
- package/src/math/v2/preset.ts +189 -0
- package/src/math/v2/receipt.ts +162 -0
- package/src/math/v2/relay.ts +235 -0
- package/src/math/v2/rows.ts +412 -0
- package/src/math/v2/split.ts +160 -0
- package/src/math/v2/sqrt.ts +86 -0
- package/src/math/v2/supply.ts +27 -0
- package/src/math/v2/team.ts +75 -0
- package/src/math/v2/trade.ts +145 -0
- package/src/math/v2/wide.ts +52 -0
- package/src/quote.ts +6 -0
- package/src/registryPrice.ts +28 -0
- package/src/route/edge-jupiter.ts +71 -0
- package/src/route/edge.ts +22 -0
- package/src/route/graph.ts +77 -0
- package/src/route/path.ts +84 -0
- package/src/route/quote.ts +46 -0
- package/src/route-jupiter.ts +36 -0
- package/src/route.ts +8 -0
- package/src/sha256.ts +61 -0
- package/src/solana/alt.ts +25 -0
- package/src/solana/floor/accounts.ts +393 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +147 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +491 -0
- package/src/solana/floor/metadata.ts +246 -0
- package/src/solana/floor/mint.ts +242 -0
- package/src/solana/floor/program.ts +64 -0
- package/src/solana/floor/registry.ts +96 -0
- package/src/solana/instruction.ts +61 -0
- package/src/solana/pda.ts +91 -0
- package/src/solana/tx.ts +143 -0
- package/src/v2/burnPreview.ts +52 -0
- package/src/v2/circulating.ts +22 -0
- package/src/v2/claimAllEvm.ts +97 -0
- package/src/v2/claims-evm.ts +179 -0
- package/src/v2/claims.ts +288 -0
- package/src/v2/dead.ts +21 -0
- package/src/v2/devbuy.ts +55 -0
- package/src/v2/events.ts +131 -0
- package/src/v2/evm.ts +349 -0
- package/src/v2/evmReads.ts +121 -0
- package/src/v2/genesis.ts +80 -0
- package/src/v2/layouts.ts +219 -0
- package/src/v2/market-evm.ts +95 -0
- package/src/v2/presetRowEvm.ts +54 -0
- package/src/v2/press.ts +124 -0
- package/src/v2/quoteMint.ts +63 -0
- package/src/v2/receipt-tx.ts +251 -0
- package/src/v2/route-alt.ts +114 -0
- package/src/v2/route.ts +494 -0
- package/src/v2/solana.ts +439 -0
- package/src/v2/solanaSettle.ts +117 -0
- package/src/v2/tx/evm.ts +152 -0
- package/src/v2/tx/genesis.ts +66 -0
- package/src/v2/tx/index.ts +5 -0
- package/src/v2/tx/solana.ts +140 -0
- package/src/v2/types.ts +284 -0
- package/dist/adapter.d.ts +0 -28
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/chain.d.ts +0 -23
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -25
- package/dist/chain.js.map +0 -1
- package/dist/client.d.ts +0 -26
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/dex-adapter.d.ts +0 -228
- package/dist/dex-adapter.d.ts.map +0 -1
- package/dist/dex-adapter.js +0 -407
- package/dist/dex-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/quotes.d.ts +0 -12
- package/dist/quotes.d.ts.map +0 -1
- package/dist/quotes.gen.d.ts +0 -8
- package/dist/quotes.gen.d.ts.map +0 -1
- package/dist/quotes.gen.js +0 -2170
- package/dist/quotes.gen.js.map +0 -1
- package/dist/quotes.js +0 -24
- package/dist/quotes.js.map +0 -1
- package/dist/types.d.ts +0 -111
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/adapter.ts +0 -20
- package/src/chain.ts +0 -39
- package/src/client.ts +0 -41
- package/src/dex-adapter.ts +0 -477
- package/src/quotes.gen.ts +0 -2170
- package/src/quotes.ts +0 -29
- package/src/types.ts +0 -115
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { readUintLE } from "../../codec.js";
|
|
4
|
+
import { FloorError, decodeSolanaProgramError, errorCodeOf } from "../../errors.js";
|
|
5
|
+
import { FloorMathError } from "../../math/index.js";
|
|
6
|
+
import { nextBuyPriceX64 } from "../../math/v2/display.js";
|
|
7
|
+
import { LEG_BACKING, LEG_FLOOR, LEG_HOLDER, LEG_PLATFORM, LEG_TEAM } from "../../math/v2/fees.js";
|
|
8
|
+
import { priceImpactV2, quoteSellImpactV2 } from "../../math/v2/receipt.js";
|
|
9
|
+
import { sCirc } from "../../math/v2/supply.js";
|
|
10
|
+
import { CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TRADER_REF } from "../../solana/floor/instructions.js";
|
|
11
|
+
import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.js";
|
|
12
|
+
import { MAX_COMPUTE_UNIT_LIMIT, computeUnitLimitInstruction } from "../../solana/instruction.js";
|
|
13
|
+
|
|
14
|
+
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../../solana/pda.js";
|
|
15
|
+
import { closeAccountInstruction, createAssociatedTokenAccountIdempotentInstruction, syncNativeInstruction, systemTransferInstruction } from "../../solana/tx.js";
|
|
16
|
+
import { CLAIM_COMPUTE_UNIT_LIMIT_V2 } from "../../v2/claims.js";
|
|
17
|
+
import { FLOOR_HOOK_PROGRAM_ID, buyWithPositionInstructions, claimInstructionV2, holderPositionPda, sellInstructionV2 } from "../../v2/solana.js";
|
|
18
|
+
|
|
19
|
+
import { quoteBuySolanaV2, solanaSettleInputsV2 } from "../../v2/solanaSettle.js";
|
|
20
|
+
import { buyLessIn, buyMinTokens } from "../../math/v2/trade.js";
|
|
21
|
+
import { SOL_BUY_WALK_STEPS } from "../../math/v2/book.js";
|
|
22
|
+
import { MAX_SLIPPAGE_BPS, minOutAt } from "../../v2/press.js";
|
|
23
|
+
import { fillsNothing } from "../../v2/route.js";
|
|
24
|
+
import { decodeQuoteTransferFeeV2, quoteReceivedV2, quoteTransferFeeV2 } from "../../v2/quoteMint.js";
|
|
25
|
+
|
|
26
|
+
import { decodeLaunchV2Typed } from "../../v2/types.js";
|
|
27
|
+
|
|
28
|
+
import { DEFAULT_SLIPPAGE_BPS } from "../types.js";
|
|
29
|
+
|
|
30
|
+
const MINT_SUPPLY_AT = 36;
|
|
31
|
+
|
|
32
|
+
function asFloorError(e ) {
|
|
33
|
+
if (e instanceof FloorError) return e;
|
|
34
|
+
if (e instanceof FloorMathError) {
|
|
35
|
+
const code = errorCodeOf(e.code);
|
|
36
|
+
return new FloorError(code === "Unknown" || code === "Genesis" ? "MathFailed" : code, e.message, { source: "sdk", name: e.code, mathError: e.code, cause: e });
|
|
37
|
+
}
|
|
38
|
+
if (e instanceof RangeError) return new FloorError("BadArgument", e.message, { source: "sdk", cause: e });
|
|
39
|
+
return new FloorError("Unknown", e instanceof Error ? e.message : String(e), { source: "sdk", cause: e });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function guard (f ) {
|
|
43
|
+
try {
|
|
44
|
+
return await f();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw asFloorError(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const bad = (message ) => new FloorError("BadArgument", message, { source: "sdk" });
|
|
51
|
+
|
|
52
|
+
function slippageOf(bps ) {
|
|
53
|
+
const s = bps ?? DEFAULT_SLIPPAGE_BPS;
|
|
54
|
+
if (!Number.isInteger(s) || s < 0 || s > MAX_SLIPPAGE_BPS) throw bad(`slippageBps ${s}: 0 ..= ${MAX_SLIPPAGE_BPS}`);
|
|
55
|
+
return s;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const lessSlippage = (x , bps ) => (x > 0n ? minOutAt(x, bps) : 1n);
|
|
59
|
+
|
|
60
|
+
function feeLegs(f ) {
|
|
61
|
+
return { backing: f[LEG_BACKING], team: f[LEG_TEAM], platform: f[LEG_PLATFORM], floor: f[LEG_FLOOR], holder: f[LEG_HOLDER], total: f.reduce((a, x) => a + x, 0n) };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const impactBps = (ppm ) => (ppm === null ? null : Number(ppm / 100n));
|
|
65
|
+
|
|
66
|
+
export function createSolanaClient(opts ) {
|
|
67
|
+
const { chain, transport } = opts;
|
|
68
|
+
if (chain?.family !== "solana") throw bad(`createSolanaClient: chain family ${String((chain )?.family)}`);
|
|
69
|
+
const pid = chain.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
70
|
+
const hid = chain.hookProgramId ?? FLOOR_HOOK_PROGRAM_ID;
|
|
71
|
+
const ids = { programId: pid, hookProgramId: hid };
|
|
72
|
+
|
|
73
|
+
async function get(address ) {
|
|
74
|
+
try {
|
|
75
|
+
return await transport.rpc.getAccount(address);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw new FloorError("Transport", `getAccount ${address}: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function launchOf(mint ) {
|
|
82
|
+
const address = launchPda(mint, pid)[0];
|
|
83
|
+
const a = await get(address);
|
|
84
|
+
if (a === null) throw new FloorError("BadAccount", `no launch for mint ${mint} (${address})`, { source: "sdk" });
|
|
85
|
+
if (a.owner !== pid) throw new FloorError("BadAccount", `launch ${address} is owned by ${a.owner}, not ${pid}`, { source: "sdk" });
|
|
86
|
+
let l ;
|
|
87
|
+
try {
|
|
88
|
+
l = decodeLaunchV2Typed(a.data);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
throw new FloorError("BadAccount", `launch ${address}: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
|
|
91
|
+
}
|
|
92
|
+
if (l.baseMint !== mint) throw new FloorError("BadAccount", `launch ${address} holds mint ${l.baseMint}, not ${mint}`, { source: "sdk" });
|
|
93
|
+
const m = await get(mint);
|
|
94
|
+
if (m !== null && m.data.length >= MINT_SUPPLY_AT + 8) {
|
|
95
|
+
const live = readUintLE(m.data, MINT_SUPPLY_AT, 8);
|
|
96
|
+
if (live < l.supply) l = { ...l, supply: live };
|
|
97
|
+
}
|
|
98
|
+
return { address, l };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function tradeAccounts(address , l , trader , baseOwner , quoteOwner ) {
|
|
102
|
+
const ref = traderRefPda(trader, l.quoteMint, pid)[0];
|
|
103
|
+
const hasRef = (await get(ref)) !== null;
|
|
104
|
+
return {
|
|
105
|
+
programId: pid, hookProgramId: hid, trader, launch: address, baseMint: l.baseMint, quoteMint: l.quoteMint, tokenVault: l.tokenVault, quoteVault: l.quoteVault,
|
|
106
|
+
traderBase: associatedTokenAddress(baseOwner, l.baseMint, TOKEN_2022_PROGRAM_ID), traderQuote: associatedTokenAddress(quoteOwner, l.quoteMint, l.quoteTokenProgram),
|
|
107
|
+
quoteTokenProgram: l.quoteTokenProgram, traderRef: hasRef ? ref : null, escrow: hasRef ? traderRefEscrow(ref, l.quoteMint, l.quoteTokenProgram) : null,
|
|
108
|
+
baseOwner, quoteOwner,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function wsolLegs(l , owner , payer ) {
|
|
113
|
+
if (l.quoteMint !== WSOL_MINT) return null;
|
|
114
|
+
const account = associatedTokenAddress(owner, WSOL_MINT, l.quoteTokenProgram);
|
|
115
|
+
const existed = (await get(account)) !== null;
|
|
116
|
+
return {
|
|
117
|
+
account,
|
|
118
|
+
open: createAssociatedTokenAccountIdempotentInstruction({ payer, owner, mint: WSOL_MINT, tokenProgram: l.quoteTokenProgram }),
|
|
119
|
+
close: existed || owner !== payer ? null : closeAccountInstruction({ account, destination: owner, owner, tokenProgram: l.quoteTokenProgram }),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function quoteFeeOf(l ) {
|
|
124
|
+
if (l.quoteTokenProgram !== TOKEN_2022_PROGRAM_ID) return null;
|
|
125
|
+
const m = await get(l.quoteMint);
|
|
126
|
+
const fee = m === null ? null : decodeQuoteTransferFeeV2(m.data);
|
|
127
|
+
if (fee === null || (fee.older.basisPoints === 0 && fee.newer.basisPoints === 0)) return null;
|
|
128
|
+
if (transport.rpc.getEpoch) {
|
|
129
|
+
try {
|
|
130
|
+
return { fee, epoch: await transport.rpc.getEpoch() };
|
|
131
|
+
} catch (e) {
|
|
132
|
+
throw new FloorError("Transport", `getEpoch: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const newerHigher = fee.newer.basisPoints >= fee.older.basisPoints;
|
|
136
|
+
return { fee, epoch: newerHigher || fee.newer.epoch === 0n ? fee.newer.epoch : fee.newer.epoch - 1n };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const client = {
|
|
140
|
+
family: "solana",
|
|
141
|
+
chain,
|
|
142
|
+
|
|
143
|
+
quoteBuy: (p ) => guard(async () => {
|
|
144
|
+
const slippageBps = slippageOf(p.slippageBps);
|
|
145
|
+
const { l } = await launchOf(p.launch);
|
|
146
|
+
const tf = await quoteFeeOf(l);
|
|
147
|
+
|
|
148
|
+
const r = quoteBuySolanaV2(l, p.amountIn, { quoteTransferFee: tf });
|
|
149
|
+
|
|
150
|
+
const s = solanaSettleInputsV2(l);
|
|
151
|
+
const less = buyLessIn(p.amountIn, slippageBps);
|
|
152
|
+
const lessFee = tf ? quoteTransferFeeV2(tf.fee, tf.epoch, less) : 0n;
|
|
153
|
+
|
|
154
|
+
let m = 0n;
|
|
155
|
+
if (less > lessFee) {
|
|
156
|
+
try {
|
|
157
|
+
m = buyMinTokens(s.book, s.row, s.sup, less - lessFee, 0, SOL_BUY_WALK_STEPS);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
if (!fillsNothing(e)) throw e;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const minOut = m > 0n ? m : 1n;
|
|
163
|
+
const spot = nextBuyPriceX64(s.book);
|
|
164
|
+
return {
|
|
165
|
+
family: "solana", chainId: null, side: "buy", launch: p.launch, amountIn: p.amountIn, amountOut: r.buy.tokens, minOut, slippageBps,
|
|
166
|
+
fees: feeLegs(r.buy.fees), priceImpactBps: impactBps(priceImpactV2(spot, r.buy.net, r.buy.tokens, "buy").ppm), refund: r.refundReceived,
|
|
167
|
+
graduates: r.buy.graduatedNow,
|
|
168
|
+
};
|
|
169
|
+
}),
|
|
170
|
+
|
|
171
|
+
quoteSell: (p ) => guard(async () => {
|
|
172
|
+
const slippageBps = slippageOf(p.slippageBps);
|
|
173
|
+
if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
|
|
174
|
+
const { l } = await launchOf(p.launch);
|
|
175
|
+
const s = solanaSettleInputsV2(l);
|
|
176
|
+
const { quote, impact } = quoteSellImpactV2(s.book, p.tokensIn, sCirc(s.book, s.sup));
|
|
177
|
+
|
|
178
|
+
const tf = await quoteFeeOf(l);
|
|
179
|
+
const amountOut = tf ? quoteReceivedV2(tf.fee, tf.epoch, quote.out) : quote.out;
|
|
180
|
+
return {
|
|
181
|
+
family: "solana", chainId: null, side: "sell", launch: p.launch, amountIn: p.tokensIn, amountOut, minOut: lessSlippage(quote.out, slippageBps),
|
|
182
|
+
slippageBps, fees: feeLegs(quote.fees), priceImpactBps: impactBps(impact.ppm), refund: quote.unfilled, graduates: false,
|
|
183
|
+
};
|
|
184
|
+
}),
|
|
185
|
+
|
|
186
|
+
buildBuy: (p ) => guard(async () => {
|
|
187
|
+
if (p.amountIn <= 0n) throw bad("amountIn must be > 0");
|
|
188
|
+
const { address, l } = await launchOf(p.launch);
|
|
189
|
+
const owner = p.recipient ?? p.trader;
|
|
190
|
+
const a = await tradeAccounts(address, l, p.trader, owner, p.trader);
|
|
191
|
+
|
|
192
|
+
const hasPosition = owner !== p.trader || (await get(holderPositionPda(address, owner, hid)[0])) !== null;
|
|
193
|
+
const wsol = await wsolLegs(l, p.trader, p.trader);
|
|
194
|
+
const instructions = [
|
|
195
|
+
computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
|
|
196
|
+
createAssociatedTokenAccountIdempotentInstruction({ payer: p.trader, owner, mint: l.baseMint, tokenProgram: TOKEN_2022_PROGRAM_ID }),
|
|
197
|
+
...(wsol ? [wsol.open, systemTransferInstruction({ from: p.trader, to: wsol.account, lamports: p.amountIn }), syncNativeInstruction(wsol.account)] : []),
|
|
198
|
+
...buyWithPositionInstructions({ ...a, amountIn: p.amountIn, minOut: p.minOut, hasPosition }),
|
|
199
|
+
...(wsol?.close ? [wsol.close] : []),
|
|
200
|
+
];
|
|
201
|
+
return { family: "solana", instructions };
|
|
202
|
+
}),
|
|
203
|
+
|
|
204
|
+
buildSell: (p ) => guard(async () => {
|
|
205
|
+
if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
|
|
206
|
+
const { address, l } = await launchOf(p.launch);
|
|
207
|
+
const to = p.recipient ?? p.trader;
|
|
208
|
+
const a = await tradeAccounts(address, l, p.trader, p.trader, to);
|
|
209
|
+
const wsol = await wsolLegs(l, to, p.trader);
|
|
210
|
+
const instructions = [
|
|
211
|
+
computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
|
|
212
|
+
wsol ? wsol.open : createAssociatedTokenAccountIdempotentInstruction({ payer: p.trader, owner: to, mint: l.quoteMint, tokenProgram: l.quoteTokenProgram }),
|
|
213
|
+
sellInstructionV2({ ...a, tokensIn: p.tokensIn, minOut: p.minOut }),
|
|
214
|
+
...(wsol?.close ? [wsol.close] : []),
|
|
215
|
+
];
|
|
216
|
+
return { family: "solana", instructions };
|
|
217
|
+
}),
|
|
218
|
+
|
|
219
|
+
claim: (p ) => guard(async () => {
|
|
220
|
+
const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
|
|
221
|
+
const launches = [];
|
|
222
|
+
let qtp = null;
|
|
223
|
+
for (const mint of p.launches) {
|
|
224
|
+
const { address, l } = await launchOf(mint);
|
|
225
|
+
if (l.quoteMint !== p.quote) throw bad(`launch ${mint} trades in ${l.quoteMint}, not ${p.quote}`);
|
|
226
|
+
qtp = l.quoteTokenProgram;
|
|
227
|
+
const slot = teamSlotPda(address, pid)[0];
|
|
228
|
+
launches.push({
|
|
229
|
+
launch: address, quoteVault: l.quoteVault, teamSlot: (await get(slot)) !== null ? slot : null, baseMint: l.baseMint,
|
|
230
|
+
...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (qtp === null) {
|
|
234
|
+
const m = await get(p.quote);
|
|
235
|
+
if (m === null) throw new FloorError("BadAccount", `no quote mint ${p.quote}`, { source: "sdk" });
|
|
236
|
+
qtp = m.owner;
|
|
237
|
+
}
|
|
238
|
+
const ro = (p.types & CLAIM_TRADER_REF) !== 0 ? refOwedPda(p.wallet, p.quote, pid)[0] : null;
|
|
239
|
+
const claim = claimInstructionV2({
|
|
240
|
+
...ids, sender: p.wallet, wallet: p.wallet, quoteMint: p.quote, quoteTokenProgram: qtp, destination: associatedTokenAddress(p.wallet, p.quote, qtp),
|
|
241
|
+
config: configPda(pid)[0], refOwed: ro, refOwedVault: ro ? refOwedVault(ro, p.quote, qtp) : null, types: p.types, launches,
|
|
242
|
+
unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID,
|
|
243
|
+
});
|
|
244
|
+
return { family: "solana", instructions: [computeUnitLimitInstruction(CLAIM_COMPUTE_UNIT_LIMIT_V2), claim] };
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
send: async (tx ) => {
|
|
248
|
+
if (!transport.send) throw new FloorError("NoSend", "this client was given no transport.send", { source: "sdk" });
|
|
249
|
+
try {
|
|
250
|
+
return [await transport.send(tx)];
|
|
251
|
+
} catch (e) {
|
|
252
|
+
throw decodeSolanaProgramError(e, ids) ?? new FloorError("Transport", `send: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
decodeError: (raw ) => decodeSolanaProgramError(raw, ids),
|
|
257
|
+
};
|
|
258
|
+
return client;
|
|
259
|
+
}
|
package/dist/codec.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
4
|
+
const INDEX = new Map ([...ALPHABET].map((c, i) => [c, i]));
|
|
5
|
+
|
|
6
|
+
export function base58Encode(bytes ) {
|
|
7
|
+
let zeros = 0;
|
|
8
|
+
while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
|
|
9
|
+
let n = 0n;
|
|
10
|
+
for (const b of bytes) n = (n << 8n) | BigInt(b);
|
|
11
|
+
let out = "";
|
|
12
|
+
while (n > 0n) {
|
|
13
|
+
out = ALPHABET[Number(n % 58n)] + out;
|
|
14
|
+
n /= 58n;
|
|
15
|
+
}
|
|
16
|
+
return "1".repeat(zeros) + out;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function base58Decode(s ) {
|
|
20
|
+
let zeros = 0;
|
|
21
|
+
while (zeros < s.length && s[zeros] === "1") zeros++;
|
|
22
|
+
let n = 0n;
|
|
23
|
+
for (const c of s) {
|
|
24
|
+
const v = INDEX.get(c);
|
|
25
|
+
if (v === undefined) throw new RangeError(`not base58: ${JSON.stringify(c)}`);
|
|
26
|
+
n = n * 58n + BigInt(v);
|
|
27
|
+
}
|
|
28
|
+
const body = [];
|
|
29
|
+
while (n > 0n) {
|
|
30
|
+
body.unshift(Number(n & 0xffn));
|
|
31
|
+
n >>= 8n;
|
|
32
|
+
}
|
|
33
|
+
return Uint8Array.from([...new Array (zeros).fill(0), ...body]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function addressBytes(address ) {
|
|
37
|
+
const b = base58Decode(address);
|
|
38
|
+
if (b.length !== 32) throw new RangeError(`not a 32-byte address: ${address}`);
|
|
39
|
+
return b;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function hex(bytes ) {
|
|
43
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function concatBytes(...parts ) {
|
|
47
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
48
|
+
let o = 0;
|
|
49
|
+
for (const p of parts) {
|
|
50
|
+
out.set(p, o);
|
|
51
|
+
o += p.length;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function readUintLE(b , off , len ) {
|
|
57
|
+
if (off + len > b.length) throw new RangeError(`read past the end: ${off}+${len} > ${b.length}`);
|
|
58
|
+
let v = 0n;
|
|
59
|
+
for (let i = len - 1; i >= 0; i--) v = (v << 8n) | BigInt(b[off + i]);
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function readI32LE(b , off ) {
|
|
64
|
+
return Number(BigInt.asIntN(32, readUintLE(b, off, 4)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function uintLE(v , len ) {
|
|
68
|
+
if (v < 0n || v >> BigInt(8 * len) !== 0n) throw new RangeError(`${v} does not fit ${len} bytes`);
|
|
69
|
+
const out = new Uint8Array(len);
|
|
70
|
+
for (let i = 0; i < len; i++) out[i] = Number((v >> BigInt(8 * i)) & 0xffn);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function i32LE(v ) {
|
|
75
|
+
if (!Number.isInteger(v) || v < -(2 ** 31) || v >= 2 ** 31) throw new RangeError(`${v} is not an i32`);
|
|
76
|
+
return uintLE(BigInt.asUintN(32, BigInt(v)), 4);
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, hexToBytes } from "../evm/abi.js";
|
|
4
|
+
import { keccak256 } from "../evm/keccak.js";
|
|
5
|
+
|
|
6
|
+
export function evmCodeHash(code ) {
|
|
7
|
+
if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code) || /^0x0*$/.test(code)) throw new Error(`evmCodeHash: not runtime code: ${String(code).slice(0, 20)}`);
|
|
8
|
+
return bytesToHex(keccak256(hexToBytes(code))).toLowerCase();
|
|
9
|
+
}
|