@floorlaunchpad/sdk 0.1.1 → 0.3.1
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 +114 -0
- package/LICENSE +201 -60
- package/README.md +54 -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 +130 -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 +803 -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 +148 -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/squid.js +107 -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 +93 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +105 -0
- package/dist/indexer/contract.js +358 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +105 -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 +392 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +144 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +448 -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/router.js +22 -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/floor-line.md +66 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/examples/floor-line.html +104 -0
- package/package.json +429 -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 +140 -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 +803 -0
- package/src/config/index.ts +93 -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 +842 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +171 -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/squid.ts +138 -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 +93 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +180 -0
- package/src/indexer/contract.ts +419 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +115 -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 +395 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +151 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +504 -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/router.ts +22 -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,88 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, base58Encode, concatBytes } from "../codec.js";
|
|
4
|
+
import { isOnCurve } from "../ed25519.js";
|
|
5
|
+
import { sha256 } from "../sha256.js";
|
|
6
|
+
|
|
7
|
+
export const SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
8
|
+
export const BPF_LOADER_UPGRADEABLE_ID = "BPFLoaderUpgradeab1e11111111111111111111111";
|
|
9
|
+
export const TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
10
|
+
export const TOKEN_2022_PROGRAM_ID = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
11
|
+
export const ASSOCIATED_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
12
|
+
export const ADDRESS_LOOKUP_TABLE_PROGRAM_ID = "AddressLookupTab1e1111111111111111111111111";
|
|
13
|
+
export const RENT_SYSVAR_ID = "SysvarRent111111111111111111111111111111111";
|
|
14
|
+
export const CLOCK_SYSVAR_ID = "SysvarC1ock11111111111111111111111111111111";
|
|
15
|
+
|
|
16
|
+
export const WSOL_MINT = "So11111111111111111111111111111111111111112";
|
|
17
|
+
|
|
18
|
+
const MAX_SEED_LEN = 32;
|
|
19
|
+
const MAX_SEEDS = 16;
|
|
20
|
+
const PDA_MARKER = new TextEncoder().encode("ProgramDerivedAddress");
|
|
21
|
+
|
|
22
|
+
function seedBytes(s ) {
|
|
23
|
+
return typeof s === "string" ? new TextEncoder().encode(s) : s;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createProgramAddress(seeds , programId ) {
|
|
27
|
+
if (seeds.length > MAX_SEEDS) throw new RangeError("at most 16 seeds");
|
|
28
|
+
const parts = seeds.map(seedBytes);
|
|
29
|
+
for (const p of parts) if (p.length > MAX_SEED_LEN) throw new RangeError("a seed is at most 32 bytes");
|
|
30
|
+
const h = sha256(concatBytes(...parts, addressBytes(programId), PDA_MARKER));
|
|
31
|
+
return isOnCurve(h) ? null : base58Encode(h);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const PDA_CACHE_MAX = 2_048;
|
|
35
|
+
const pdaCache = new Map ();
|
|
36
|
+
|
|
37
|
+
export function clearPdaCache() {
|
|
38
|
+
pdaCache.clear();
|
|
39
|
+
ataCache.clear();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pdaKey(seeds , programId ) {
|
|
43
|
+
let k = programId;
|
|
44
|
+
for (const s of seeds) k += typeof s === "string" ? `|s${s.length}:${s}` : `|b${s.length}:${String.fromCharCode(...s)}`;
|
|
45
|
+
return k;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function findProgramAddress(seeds , programId ) {
|
|
49
|
+
if (seeds.length > MAX_SEEDS - 1) throw new RangeError("at most 16 seeds");
|
|
50
|
+
for (const s of seeds) if (typeof s !== "string" && s.length > MAX_SEED_LEN) throw new RangeError("a seed is at most 32 bytes");
|
|
51
|
+
const key = pdaKey(seeds, programId);
|
|
52
|
+
const hit = pdaCache.get(key);
|
|
53
|
+
if (hit) {
|
|
54
|
+
pdaCache.delete(key);
|
|
55
|
+
pdaCache.set(key, hit);
|
|
56
|
+
return hit;
|
|
57
|
+
}
|
|
58
|
+
for (let bump = 255; bump >= 0; bump--) {
|
|
59
|
+
const a = createProgramAddress([...seeds, Uint8Array.of(bump)], programId);
|
|
60
|
+
if (a !== null) {
|
|
61
|
+
const r = Object.freeze([a, bump] );
|
|
62
|
+
if (pdaCache.size >= PDA_CACHE_MAX) pdaCache.delete(pdaCache.keys().next().value );
|
|
63
|
+
pdaCache.set(key, r);
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("no viable bump");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const programDataPda = (program ) => findProgramAddress([addressBytes(program)], BPF_LOADER_UPGRADEABLE_ID);
|
|
71
|
+
|
|
72
|
+
export const eventAuthorityPda = (program ) => findProgramAddress(["__event_authority"], program);
|
|
73
|
+
|
|
74
|
+
const ataCache = new Map ();
|
|
75
|
+
|
|
76
|
+
export function associatedTokenAddress(owner , mint , tokenProgram = TOKEN_2022_PROGRAM_ID) {
|
|
77
|
+
const key = `${owner}|${mint}|${tokenProgram}`;
|
|
78
|
+
const hit = ataCache.get(key);
|
|
79
|
+
if (hit !== undefined) {
|
|
80
|
+
ataCache.delete(key);
|
|
81
|
+
ataCache.set(key, hit);
|
|
82
|
+
return hit;
|
|
83
|
+
}
|
|
84
|
+
const a = findProgramAddress([addressBytes(owner), addressBytes(tokenProgram), addressBytes(mint)], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
85
|
+
if (ataCache.size >= PDA_CACHE_MAX) ataCache.delete(ataCache.keys().next().value );
|
|
86
|
+
ataCache.set(key, a);
|
|
87
|
+
return a;
|
|
88
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, concatBytes, uintLE } from "../codec.js";
|
|
4
|
+
import { R, W, RS, WS } from "./instruction.js";
|
|
5
|
+
|
|
6
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, SYSTEM_PROGRAM_ID, TOKEN_PROGRAM_ID, associatedTokenAddress } from "./pda.js";
|
|
7
|
+
|
|
8
|
+
export function createAssociatedTokenAccountIdempotentInstruction(p ) {
|
|
9
|
+
return {
|
|
10
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
11
|
+
accounts: [WS(p.payer), W(associatedTokenAddress(p.owner, p.mint, p.tokenProgram)), R(p.owner), R(p.mint), R(SYSTEM_PROGRAM_ID), R(p.tokenProgram)],
|
|
12
|
+
data: new Uint8Array([1]),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function systemTransferInstruction(p ) {
|
|
17
|
+
return { programAddress: SYSTEM_PROGRAM_ID, accounts: [WS(p.from), W(p.to)], data: concatBytes(uintLE(2n, 4), uintLE(p.lamports, 8)) };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function syncNativeInstruction(account ) {
|
|
21
|
+
return { programAddress: TOKEN_PROGRAM_ID, accounts: [W(account)], data: new Uint8Array([17]) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function closeAccountInstruction(p ) {
|
|
25
|
+
return { programAddress: p.tokenProgram ?? TOKEN_PROGRAM_ID, accounts: [W(p.account), W(p.destination), RS(p.owner)], data: new Uint8Array([9]) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function burnCheckedInstruction(p ) {
|
|
29
|
+
return { programAddress: p.tokenProgram, accounts: [W(p.account), W(p.mint), RS(p.owner)], data: concatBytes(new Uint8Array([15]), uintLE(p.amount, 8), new Uint8Array([p.decimals])) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function shortVec(n ) {
|
|
33
|
+
const out = [];
|
|
34
|
+
let v = n;
|
|
35
|
+
for (;;) {
|
|
36
|
+
let b = v & 0x7f;
|
|
37
|
+
v >>= 7;
|
|
38
|
+
if (v === 0) {
|
|
39
|
+
out.push(b);
|
|
40
|
+
return new Uint8Array(out);
|
|
41
|
+
}
|
|
42
|
+
out.push(b | 0x80);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function cmpBytes(a , b ) {
|
|
47
|
+
for (let i = 0; i < 32; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function compileV0Message(p ) {
|
|
52
|
+
|
|
53
|
+
const meta = new Map ();
|
|
54
|
+
const get = (k ) => {
|
|
55
|
+
let m = meta.get(k);
|
|
56
|
+
if (!m) meta.set(k, (m = { signer: false, writable: false, invoked: false }));
|
|
57
|
+
return m;
|
|
58
|
+
};
|
|
59
|
+
for (const ix of p.instructions) {
|
|
60
|
+
get(ix.programAddress).invoked = true;
|
|
61
|
+
for (const a of ix.accounts) {
|
|
62
|
+
const m = get(a.address);
|
|
63
|
+
m.signer ||= a.role >= 2;
|
|
64
|
+
m.writable ||= (a.role & 1) === 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const pm = get(p.payer);
|
|
68
|
+
pm.signer = true;
|
|
69
|
+
pm.writable = true;
|
|
70
|
+
|
|
71
|
+
const bytes = new Map ();
|
|
72
|
+
for (const k of meta.keys()) bytes.set(k, addressBytes(k));
|
|
73
|
+
const byAddress = (x , y ) => cmpBytes(bytes.get(x[0]) , bytes.get(y[0]) );
|
|
74
|
+
const lookups = [];
|
|
75
|
+
const loadedW = [];
|
|
76
|
+
const loadedR = [];
|
|
77
|
+
for (const t of p.lookupTables ?? []) {
|
|
78
|
+
const drain = (f ) => {
|
|
79
|
+
|
|
80
|
+
const idx = [];
|
|
81
|
+
const keys = [];
|
|
82
|
+
const ordered = [...meta.entries()].filter(([, m]) => f(m)).sort(byAddress);
|
|
83
|
+
for (const [key] of ordered) {
|
|
84
|
+
const i = t.addresses.indexOf(key);
|
|
85
|
+
if (i >= 0) {
|
|
86
|
+
if (i > 255) throw new RangeError("address lookup table index overflow");
|
|
87
|
+
idx.push(i);
|
|
88
|
+
keys.push(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const key of keys) meta.delete(key);
|
|
92
|
+
return [idx, keys];
|
|
93
|
+
};
|
|
94
|
+
const [w, wk] = drain((m) => !m.signer && !m.invoked && m.writable);
|
|
95
|
+
const [r, rk] = drain((m) => !m.signer && !m.invoked && !m.writable);
|
|
96
|
+
if (w.length || r.length) {
|
|
97
|
+
lookups.push({ table: t.address, w, r });
|
|
98
|
+
loadedW.push(...wk);
|
|
99
|
+
loadedR.push(...rk);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
meta.delete(p.payer);
|
|
103
|
+
const sorted = [...meta.entries()].sort(byAddress);
|
|
104
|
+
const pick = (f ) => sorted.filter(([, m]) => f(m)).map(([k]) => k);
|
|
105
|
+
const ws = [p.payer, ...pick((m) => m.signer && m.writable)];
|
|
106
|
+
const rs = pick((m) => m.signer && !m.writable);
|
|
107
|
+
const wn = pick((m) => !m.signer && m.writable);
|
|
108
|
+
const rn = pick((m) => !m.signer && !m.writable);
|
|
109
|
+
const statics = [...ws, ...rs, ...wn, ...rn];
|
|
110
|
+
const all = [...statics, ...loadedW, ...loadedR];
|
|
111
|
+
const index = new Map(all.map((k, i) => [k, i]));
|
|
112
|
+
const at = (k ) => {
|
|
113
|
+
const i = index.get(k);
|
|
114
|
+
if (i === undefined || i > 255) throw new RangeError(`account index: ${k}`);
|
|
115
|
+
return i;
|
|
116
|
+
};
|
|
117
|
+
const parts = [
|
|
118
|
+
new Uint8Array([0x80, ws.length + rs.length, rs.length, rn.length]),
|
|
119
|
+
shortVec(statics.length),
|
|
120
|
+
...statics.map((k) => bytes.get(k) ),
|
|
121
|
+
addressBytes(p.recentBlockhash),
|
|
122
|
+
shortVec(p.instructions.length),
|
|
123
|
+
];
|
|
124
|
+
for (const ix of p.instructions) {
|
|
125
|
+
parts.push(new Uint8Array([at(ix.programAddress)]), shortVec(ix.accounts.length), new Uint8Array(ix.accounts.map((a) => at(a.address))));
|
|
126
|
+
parts.push(shortVec(ix.data.length), ix.data);
|
|
127
|
+
}
|
|
128
|
+
parts.push(shortVec(lookups.length));
|
|
129
|
+
for (const l of lookups) parts.push(addressBytes(l.table), shortVec(l.w.length), new Uint8Array(l.w), shortVec(l.r.length), new Uint8Array(l.r));
|
|
130
|
+
return concatBytes(...parts);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function transactionSize(message ) {
|
|
134
|
+
const signers = message[0] === 0x80 ? message[1] : message[0];
|
|
135
|
+
return shortVec(signers).length + 64 * signers + message.length;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const PACKET_DATA_SIZE = 1_232;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { moneyHeld } from "../math/v2/book.js";
|
|
4
|
+
|
|
5
|
+
import { sCirc } from "../math/v2/supply.js";
|
|
6
|
+
|
|
7
|
+
import { priceX64 } from "../math/v2/sqrt.js";
|
|
8
|
+
import { tokensToMathV2 } from "./solanaSettle.js";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function floorAfterBurnV2(
|
|
13
|
+
inputs ,
|
|
14
|
+
burned ,
|
|
15
|
+
opts = {},
|
|
16
|
+
) {
|
|
17
|
+
const math = (x ) => (opts.decimals === undefined ? x : tokensToMathV2(x, opts.decimals));
|
|
18
|
+
if (burned <= 0n) throw new RangeError(`burn ${burned}: must be > 0`);
|
|
19
|
+
const b = math(burned);
|
|
20
|
+
const stored = inputs.sup.live;
|
|
21
|
+
const mint = opts.mintSupply === undefined ? stored : math(opts.mintSupply);
|
|
22
|
+
const liveBefore = mint < stored ? mint : stored;
|
|
23
|
+
const sup0 = { live: liveBefore, dead: inputs.sup.dead };
|
|
24
|
+
const sCircBefore = sCirc(inputs.book, sup0);
|
|
25
|
+
if (b > sCircBefore) throw new RangeError(`burn ${b} > ${sCircBefore} circulating`);
|
|
26
|
+
const liveAfter = liveBefore - b;
|
|
27
|
+
const sCircAfter = sCirc(inputs.book, { live: liveAfter, dead: inputs.sup.dead });
|
|
28
|
+
const beforeX64 = priceX64(inputs.book.sqrtF);
|
|
29
|
+
let swept = 0n;
|
|
30
|
+
|
|
31
|
+
if (sCircAfter === 0n) swept = moneyHeld(inputs.book);
|
|
32
|
+
const afterX64 = beforeX64;
|
|
33
|
+
const riseBps = beforeX64 === 0n ? 0n : ((afterX64 - beforeX64) * 10_000n) / beforeX64;
|
|
34
|
+
return { beforeX64, afterX64, riseBps, liveBefore, liveAfter, sCircBefore, sCircAfter, allBurned: swept > 0n || sCircAfter === 0n, swept };
|
|
35
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, checksumAddress, decodeAbi, encodeCall } from "../evm/abi.js";
|
|
4
|
+
import { planEvmClaimAllV2 } from "./claims-evm.js";
|
|
5
|
+
import { EVM_TOKEN_SCALE } from "./market-evm.js";
|
|
6
|
+
import { evmSignature } from "../generated/index.js";
|
|
7
|
+
|
|
8
|
+
export const MAX_LAUNCHES_PER_OWED_READ_V2 = 100;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const OWED_V2_SIG = evmSignature("owedV2");
|
|
13
|
+
|
|
14
|
+
const OWED_V2_LAUNCH_ROWS = "(uint256,address,address,uint256,uint256,uint256,uint256,uint256,uint256,uint64,uint256)[]";
|
|
15
|
+
const OWED_V2_QUOTE_ROWS = "(address,uint256,uint256,uint256,uint256,uint256)[]";
|
|
16
|
+
|
|
17
|
+
function owedCall(wallet , launchIds , quotes ) {
|
|
18
|
+
return bytesToHex(encodeCall(OWED_V2_SIG, [checksumAddress(wallet), [...launchIds], quotes.map((q) => checksumAddress(q))]));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function toMath(chain , what ) {
|
|
22
|
+
if (chain % EVM_TOKEN_SCALE !== 0n) throw new RangeError(`owedV2.${what} ${chain} is not a whole math unit`);
|
|
23
|
+
return chain / EVM_TOKEN_SCALE;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function decodeOwed(data ) {
|
|
27
|
+
const [ls, qs] = decodeAbi([OWED_V2_LAUNCH_ROWS, OWED_V2_QUOTE_ROWS], data) ;
|
|
28
|
+
const n = (v ) => v ;
|
|
29
|
+
return {
|
|
30
|
+
launches: ls.map((r) => ({
|
|
31
|
+
launchId: n(r[0]), quote: checksumAddress(r[1] ), token: checksumAddress(r[2] ), creator: n(r[3]), creatorRef: n(r[4]),
|
|
32
|
+
teamSlot: n(r[5]), holder: n(r[6]), teamBuy: toMath(n(r[7]), "teamBuy"), teamBuyLocked: toMath(n(r[8]), "teamBuyLocked"),
|
|
33
|
+
shareBought: toMath(n(r[10]), "shareBought"), unlockAt: n(r[9]),
|
|
34
|
+
})),
|
|
35
|
+
quotes: qs.map((r) => ({ quote: checksumAddress(r[0] ), creator: n(r[1]), creatorRef: n(r[2]), teamSlot: n(r[3]), traderRef: n(r[4]), payout: n(r[5]) })),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function evmOwedReaderOfClaimsViewV2(p
|
|
40
|
+
|
|
41
|
+
) {
|
|
42
|
+
const to = checksumAddress(p.floorAmm);
|
|
43
|
+
const per = p.maxLaunchesPerRead ?? MAX_LAUNCHES_PER_OWED_READ_V2;
|
|
44
|
+
if (!Number.isInteger(per) || per < 1) throw new RangeError("maxLaunchesPerRead must be ≥ 1");
|
|
45
|
+
return {
|
|
46
|
+
async owed(wallet, launchIds, quotes) {
|
|
47
|
+
const out = { launches: [], quotes: [] };
|
|
48
|
+
for (let i = 0; i === 0 || i < launchIds.length; i += per) {
|
|
49
|
+
const ids = launchIds.slice(i, i + per);
|
|
50
|
+
const qs = i === 0 ? quotes : [];
|
|
51
|
+
const r = decodeOwed(await p.ethCall(to, owedCall(wallet, ids, qs)));
|
|
52
|
+
if (r.launches.length !== ids.length || r.quotes.length !== qs.length) throw new RangeError("owedV2: one row per launch and per quote");
|
|
53
|
+
out.launches.push(...r.launches);
|
|
54
|
+
out.quotes.push(...r.quotes);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function planEvmClaimAll(p
|
|
62
|
+
|
|
63
|
+
) {
|
|
64
|
+
const reader = evmOwedReaderOfClaimsViewV2({ floorAmm: p.floorAmm, ethCall: p.ethCall, maxLaunchesPerRead: p.maxLaunchesPerRead });
|
|
65
|
+
const owed = await reader.owed(p.wallet, p.launchIds, p.quotes);
|
|
66
|
+
const plan = planEvmClaimAllV2({
|
|
67
|
+
floorAmm: p.floorAmm, wallet: p.wallet, owed, payoutTo: p.payoutTo, maxQuotesPerCall: p.maxQuotesPerCall, maxLaunchesPerCall: p.maxLaunchesPerCall,
|
|
68
|
+
});
|
|
69
|
+
return { ...plan, owed };
|
|
70
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, checksumAddress, decodeAbi, encodeCall } from "../evm/abi.js";
|
|
4
|
+
import { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_PAYOUT, CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF } from "../evm/floor/iface.js";
|
|
5
|
+
import { CLAIM_HOLDER_EVM, claimV2Call } from "./evm.js";
|
|
6
|
+
|
|
7
|
+
import { claimPayoutToCallV2 } from "./tx/evm.js";
|
|
8
|
+
import { evmSignature } from "../generated/index.js";
|
|
9
|
+
|
|
10
|
+
export const MAX_CLAIM_QUOTES_PER_CALL_V2 = 25;
|
|
11
|
+
|
|
12
|
+
export const MAX_CLAIM_LAUNCHES_PER_CALL_V2 = 25;
|
|
13
|
+
|
|
14
|
+
export const launchBitsEvmV2 = (o ) =>
|
|
15
|
+
(o.creator > 0n ? CLAIM_CREATOR : 0) | (o.creatorRef > 0n ? CLAIM_CREATOR_REF : 0) | (o.teamSlot > 0n ? CLAIM_TEAM_SLOT : 0) |
|
|
16
|
+
(o.holder > 0n ? CLAIM_HOLDER_EVM : 0) | (o.teamBuy > 0n ? CLAIM_TEAM_BUY : 0) | (o.shareBought > 0n ? CLAIM_SHARE_BOUGHT : 0);
|
|
17
|
+
const quoteBits = (o , payout ) =>
|
|
18
|
+
(o.creator > 0n ? CLAIM_CREATOR : 0) | (o.creatorRef > 0n ? CLAIM_CREATOR_REF : 0) | (o.teamSlot > 0n ? CLAIM_TEAM_SLOT : 0) |
|
|
19
|
+
(o.traderRef > 0n ? CLAIM_TRADER_REF : 0) | (payout && o.payout > 0n ? CLAIM_PAYOUT : 0);
|
|
20
|
+
|
|
21
|
+
export function planEvmClaimAllV2(p
|
|
22
|
+
|
|
23
|
+
) {
|
|
24
|
+
const maxQ = p.maxQuotesPerCall ?? MAX_CLAIM_QUOTES_PER_CALL_V2;
|
|
25
|
+
const maxL = p.maxLaunchesPerCall ?? MAX_CLAIM_LAUNCHES_PER_CALL_V2;
|
|
26
|
+
for (const m of [maxQ, maxL]) if (!Number.isInteger(m) || m < 1) throw new RangeError("a per-call bound must be ≥ 1");
|
|
27
|
+
const to = p.payoutTo === undefined ? null : checksumAddress(p.payoutTo);
|
|
28
|
+
if (to !== null && BigInt(to) === 0n) throw new RangeError("payoutTo: not the zero address");
|
|
29
|
+
const skipped = [];
|
|
30
|
+
|
|
31
|
+
const byQuote = new Map ();
|
|
32
|
+
const entry = (q ) => {
|
|
33
|
+
let e = byQuote.get(q);
|
|
34
|
+
if (!e) byQuote.set(q, (e = { quote: q, types: 0, amount: 0n, launches: [] }));
|
|
35
|
+
return e;
|
|
36
|
+
};
|
|
37
|
+
const seen = new Set ();
|
|
38
|
+
const payouts = [];
|
|
39
|
+
for (const o of p.owed.quotes) {
|
|
40
|
+
const q = checksumAddress(o.quote);
|
|
41
|
+
if (seen.has(q)) throw new RangeError(`quote ${q} listed twice`);
|
|
42
|
+
seen.add(q);
|
|
43
|
+
const t = quoteBits(o, to === null);
|
|
44
|
+
if (to !== null && o.payout > 0n) payouts.push({ quote: q, amount: o.payout, call: claimPayoutToCallV2({ floorAmm: p.floorAmm, quote: q, to }) });
|
|
45
|
+
if (t === 0) continue;
|
|
46
|
+
const e = entry(q);
|
|
47
|
+
e.types |= t;
|
|
48
|
+
e.amount += o.creator + o.creatorRef + o.teamSlot + o.traderRef + (to === null ? o.payout : 0n);
|
|
49
|
+
}
|
|
50
|
+
const ids = new Set ();
|
|
51
|
+
for (const [at, l] of p.owed.launches.entries()) {
|
|
52
|
+
if (ids.has(l.launchId)) throw new RangeError(`launch ${l.launchId} listed twice`);
|
|
53
|
+
ids.add(l.launchId);
|
|
54
|
+
const t = launchBitsEvmV2(l);
|
|
55
|
+
if (t === 0) {
|
|
56
|
+
skipped.push(`launch:${l.launchId}`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
entry(checksumAddress(l.quote)).launches.push({ at, id: l.launchId, types: t, amount: l.creator + l.creatorRef + l.teamSlot + l.holder, tokens: l.teamBuy + l.shareBought });
|
|
60
|
+
}
|
|
61
|
+
const claims = [];
|
|
62
|
+
let cur = { quotes: [], launches: [], types: 0 };
|
|
63
|
+
const flush = () => {
|
|
64
|
+
if (cur.quotes.length === 0) return;
|
|
65
|
+
const quotes = cur.quotes.map((e) => e.quote);
|
|
66
|
+
|
|
67
|
+
const launchIds = [...cur.launches].sort((a, b) => a.at - b.at).map((l) => l.id);
|
|
68
|
+
claims.push({
|
|
69
|
+
launchIds, quotes, types: cur.types, amount: cur.quotes.reduce((a, e) => a + e.amount, 0n) + cur.launches.reduce((a, l) => a + l.amount, 0n),
|
|
70
|
+
tokens: cur.launches.reduce((a, l) => a + l.tokens, 0n), call: claimV2Call({ floorAmm: p.floorAmm, wallet: p.wallet, types: cur.types, quotes, launchIds }),
|
|
71
|
+
});
|
|
72
|
+
cur = { quotes: [], launches: [], types: 0 };
|
|
73
|
+
};
|
|
74
|
+
for (const e of byQuote.values()) {
|
|
75
|
+
|
|
76
|
+
let first = true;
|
|
77
|
+
for (let i = 0; i < Math.max(1, e.launches.length); ) {
|
|
78
|
+
if (cur.quotes.length >= maxQ || cur.launches.length >= maxL) flush();
|
|
79
|
+
const room = maxL - cur.launches.length;
|
|
80
|
+
const slice = e.launches.slice(i, i + room);
|
|
81
|
+
cur.quotes.push(first ? e : { ...e, types: 0, amount: 0n });
|
|
82
|
+
cur.types |= (first ? e.types : 0) | slice.reduce((a, l) => a | l.types, 0);
|
|
83
|
+
cur.launches.push(...slice);
|
|
84
|
+
first = false;
|
|
85
|
+
i += Math.max(1, slice.length);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
flush();
|
|
89
|
+
return { claims, payouts, skipped };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function readAndPlanEvmClaimAllV2(
|
|
93
|
+
reader ,
|
|
94
|
+
p ,
|
|
95
|
+
) {
|
|
96
|
+
const owed = await reader.owed(p.wallet, p.launchIds, p.quotes);
|
|
97
|
+
return planEvmClaimAllV2({ ...p, owed });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const OWED_LAUNCH = "(uint256,address,address,uint256,uint256,uint256,uint256,uint256,uint256,uint64,uint256)[]";
|
|
101
|
+
const OWED_QUOTE = "(address,uint256,uint256,uint256,uint256,uint256)[]";
|
|
102
|
+
|
|
103
|
+
export function evmOwedReaderOfViewsV2(p ) {
|
|
104
|
+
const to = checksumAddress(p.floorAmm);
|
|
105
|
+
return {
|
|
106
|
+
async owed(wallet, launchIds, quotes) {
|
|
107
|
+
const qs = quotes.map((q) => checksumAddress(q));
|
|
108
|
+
const [ls, rows] = decodeAbi([OWED_LAUNCH, OWED_QUOTE], await p.ethCall(to, bytesToHex(encodeCall(evmSignature("owedV2"), [wallet, [...launchIds], qs])))) ;
|
|
109
|
+
if (ls.length !== launchIds.length || rows.length !== qs.length) throw new RangeError("owedV2: one row a launch id and a quote");
|
|
110
|
+
const launches = ls.map((r) => ({
|
|
111
|
+
launchId: r[0] , quote: checksumAddress(r[1] ), creator: r[3] , creatorRef: r[4] , teamSlot: r[5] ,
|
|
112
|
+
holder: r[6] , teamBuy: r[7] , teamBuyLocked: r[8] , shareBought: r[10] ,
|
|
113
|
+
}));
|
|
114
|
+
const out = rows.map((r) => ({
|
|
115
|
+
quote: checksumAddress(r[0] ), creator: r[1] , creatorRef: r[2] , teamSlot: r[3] , traderRef: r[4] , payout: r[5] ,
|
|
116
|
+
}));
|
|
117
|
+
return { launches, quotes: out };
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|