@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
package/src/sha256.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const K = new Uint32Array([
|
|
4
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
5
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
6
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
7
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
8
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
9
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
10
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
11
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));
|
|
15
|
+
|
|
16
|
+
export function sha256(msg: Uint8Array): Uint8Array {
|
|
17
|
+
const bitLen = BigInt(msg.length) * 8n;
|
|
18
|
+
const padded = new Uint8Array(Math.ceil((msg.length + 9) / 64) * 64);
|
|
19
|
+
padded.set(msg);
|
|
20
|
+
padded[msg.length] = 0x80;
|
|
21
|
+
for (let i = 0; i < 8; i++) padded[padded.length - 1 - i] = Number((bitLen >> BigInt(8 * i)) & 0xffn);
|
|
22
|
+
const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
23
|
+
const w = new Uint32Array(64);
|
|
24
|
+
for (let off = 0; off < padded.length; off += 64) {
|
|
25
|
+
for (let i = 0; i < 16; i++) {
|
|
26
|
+
const j = off + 4 * i;
|
|
27
|
+
w[i] = (padded[j] << 24) | (padded[j + 1] << 16) | (padded[j + 2] << 8) | padded[j + 3];
|
|
28
|
+
}
|
|
29
|
+
for (let i = 16; i < 64; i++) {
|
|
30
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
31
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
32
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
|
33
|
+
}
|
|
34
|
+
let [a, b, c, d, e, f, g, hh] = h;
|
|
35
|
+
for (let i = 0; i < 64; i++) {
|
|
36
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
37
|
+
const ch = (e & f) ^ (~e & g);
|
|
38
|
+
const t1 = (hh + S1 + ch + K[i] + w[i]) | 0;
|
|
39
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
40
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
41
|
+
const t2 = (S0 + maj) | 0;
|
|
42
|
+
hh = g;
|
|
43
|
+
g = f;
|
|
44
|
+
f = e;
|
|
45
|
+
e = (d + t1) | 0;
|
|
46
|
+
d = c;
|
|
47
|
+
c = b;
|
|
48
|
+
b = a;
|
|
49
|
+
a = (t1 + t2) | 0;
|
|
50
|
+
}
|
|
51
|
+
h[0] += a; h[1] += b; h[2] += c; h[3] += d; h[4] += e; h[5] += f; h[6] += g; h[7] += hh;
|
|
52
|
+
}
|
|
53
|
+
const out = new Uint8Array(32);
|
|
54
|
+
for (let i = 0; i < 8; i++) {
|
|
55
|
+
out[4 * i] = h[i] >>> 24;
|
|
56
|
+
out[4 * i + 1] = (h[i] >>> 16) & 0xff;
|
|
57
|
+
out[4 * i + 2] = (h[i] >>> 8) & 0xff;
|
|
58
|
+
out[4 * i + 3] = h[i] & 0xff;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { base58Encode, readUintLE } from "../codec.ts";
|
|
4
|
+
import type { LookupTable } from "./tx.ts";
|
|
5
|
+
|
|
6
|
+
export const LOOKUP_TABLE_META_SIZE = 56;
|
|
7
|
+
|
|
8
|
+
export interface LookupTableAccount extends LookupTable {
|
|
9
|
+
deactivationSlot: bigint;
|
|
10
|
+
lastExtendedSlot: bigint;
|
|
11
|
+
authority: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function decodeLookupTable(address: string, data: Uint8Array): LookupTableAccount {
|
|
15
|
+
if (data.length < LOOKUP_TABLE_META_SIZE || readUintLE(data, 0, 4) !== 1n || (data.length - LOOKUP_TABLE_META_SIZE) % 32 !== 0) throw new RangeError("not a lookup table account");
|
|
16
|
+
const addresses: string[] = [];
|
|
17
|
+
for (let o = LOOKUP_TABLE_META_SIZE; o < data.length; o += 32) addresses.push(base58Encode(data.slice(o, o + 32)));
|
|
18
|
+
return {
|
|
19
|
+
address,
|
|
20
|
+
addresses,
|
|
21
|
+
deactivationSlot: readUintLE(data, 4, 8),
|
|
22
|
+
lastExtendedSlot: readUintLE(data, 12, 8),
|
|
23
|
+
authority: data[21] === 1 ? base58Encode(data.slice(22, 54)) : null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, base58Encode, hex } from "../../codec.ts";
|
|
4
|
+
import { accountDiscriminator } from "../instruction.ts";
|
|
5
|
+
|
|
6
|
+
type FieldType = string;
|
|
7
|
+
export type Layout = readonly (readonly [name: string, type: FieldType])[];
|
|
8
|
+
|
|
9
|
+
export const SLOT_MEMBER: Layout = [
|
|
10
|
+
["key", "bytes:32"],
|
|
11
|
+
["kind", "u8"],
|
|
12
|
+
["state", "u8"],
|
|
13
|
+
["pad", "bytes:6"],
|
|
14
|
+
["paid", "u64"],
|
|
15
|
+
["requested", "u64"],
|
|
16
|
+
["earned", "u64"],
|
|
17
|
+
["withdrawn", "u64"],
|
|
18
|
+
["reserved", "bytes:8"],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export const CONFIG: Layout = [
|
|
22
|
+
["version", "u8"],
|
|
23
|
+
["bump", "u8"],
|
|
24
|
+
["create_paused", "u8"],
|
|
25
|
+
["next_preset_id", "u8"],
|
|
26
|
+
["pad0", "bytes:4"],
|
|
27
|
+
["authority", "pubkey"],
|
|
28
|
+
["pending_authority", "pubkey"],
|
|
29
|
+
["timelock", "pubkey"],
|
|
30
|
+
["referral_authority", "pubkey"],
|
|
31
|
+
["launch_count", "u64"],
|
|
32
|
+
["holder_dest", "pubkey"],
|
|
33
|
+
|
|
34
|
+
["native_create_fee", "u64"],
|
|
35
|
+
["native_fees_owed", "u64"],
|
|
36
|
+
|
|
37
|
+
["metadata_base", "bytes:72"],
|
|
38
|
+
["metadata_base_len", "u8"],
|
|
39
|
+
|
|
40
|
+
["pad_metadata_base_len", "bytes:7"],
|
|
41
|
+
|
|
42
|
+
["treasury", "pubkey"],
|
|
43
|
+
|
|
44
|
+
["price_updater", "pubkey"],
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
export const QUOTE_ENTRY: Layout = [
|
|
48
|
+
["version", "u8"],
|
|
49
|
+
["bump", "u8"],
|
|
50
|
+
["enabled", "u8"],
|
|
51
|
+
["decimals", "u8"],
|
|
52
|
+
["pad0", "bytes:4"],
|
|
53
|
+
["mint", "pubkey"],
|
|
54
|
+
["token_program", "pubkey"],
|
|
55
|
+
["create_fee", "u64"],
|
|
56
|
+
["usd_cents_x64", "u128l"],
|
|
57
|
+
["launches", "u64"],
|
|
58
|
+
["updated_at", "i64"],
|
|
59
|
+
|
|
60
|
+
["admitted_caps", "u32"],
|
|
61
|
+
["pad1", "u32"],
|
|
62
|
+
["reserved", "bytes:56"],
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
export const TEAM_SLOT: Layout = [
|
|
66
|
+
["version", "u8"],
|
|
67
|
+
["bump", "u8"],
|
|
68
|
+
["member_count", "u8"],
|
|
69
|
+
["flags", "u8"],
|
|
70
|
+
["rate_bps", "u16"],
|
|
71
|
+
["pad0", "bytes:2"],
|
|
72
|
+
["price", "u64"],
|
|
73
|
+
["bought", "u64"],
|
|
74
|
+
["reserved_total", "u64"],
|
|
75
|
+
["opened_at", "i64"],
|
|
76
|
+
["launch", "pubkey"],
|
|
77
|
+
["creator", "pubkey"],
|
|
78
|
+
["members", "SlotMember[10]"],
|
|
79
|
+
["reserved", "bytes:64"],
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
export const TRADER_REF: Layout = [
|
|
83
|
+
["trader", "pubkey"],
|
|
84
|
+
["quote_mint", "pubkey"],
|
|
85
|
+
["tiers", "pubkey[3]"],
|
|
86
|
+
["owed", "u64[3]"],
|
|
87
|
+
["rolled", "u64[3]"],
|
|
88
|
+
["bump", "u8"],
|
|
89
|
+
["escrow_bump", "u8"],
|
|
90
|
+
["revoked", "u8"],
|
|
91
|
+
|
|
92
|
+
["pad0", "bytes:5"],
|
|
93
|
+
["reserved", "bytes:24"],
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
export const TRADER_LINK: Layout = [
|
|
97
|
+
["wallet", "pubkey"],
|
|
98
|
+
["tiers", "pubkey[3]"],
|
|
99
|
+
["bump", "u8"],
|
|
100
|
+
["reserved", "bytes:24"],
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
export const REF_OWED: Layout = [
|
|
104
|
+
["referrer", "pubkey"],
|
|
105
|
+
["quote_mint", "pubkey"],
|
|
106
|
+
["owed", "u64"],
|
|
107
|
+
["paid", "u64"],
|
|
108
|
+
["bump", "u8"],
|
|
109
|
+
["pad0", "bytes:7"],
|
|
110
|
+
["reserved", "bytes:24"],
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
export const GENESIS_RAISE: Layout = [
|
|
114
|
+
["version", "u8"],
|
|
115
|
+
["bump", "u8"],
|
|
116
|
+
["accepted", "u8"],
|
|
117
|
+
["vault_bump", "u8"],
|
|
118
|
+
["count", "u16"],
|
|
119
|
+
["pad0", "bytes:2"],
|
|
120
|
+
["old_sale", "pubkey"],
|
|
121
|
+
["total_migrated", "u64"],
|
|
122
|
+
["donation", "u64"],
|
|
123
|
+
["accepted_at", "i64"],
|
|
124
|
+
["accepted_slot", "u64"],
|
|
125
|
+
|
|
126
|
+
["preset_id", "u8"],
|
|
127
|
+
["opened", "u8"],
|
|
128
|
+
|
|
129
|
+
["public_open", "u8"],
|
|
130
|
+
["pad1", "bytes:5"],
|
|
131
|
+
["cap", "u64"],
|
|
132
|
+
["ends_at", "i64"],
|
|
133
|
+
["migrated_refunded", "u64"],
|
|
134
|
+
["phase3_total", "u64"],
|
|
135
|
+
["raised_final", "u64"],
|
|
136
|
+
["tokens_out", "u64"],
|
|
137
|
+
["tokens_claimed", "u64"],
|
|
138
|
+
["weight_total", "u64"],
|
|
139
|
+
["launch", "pubkey"],
|
|
140
|
+
["base_mint", "pubkey"],
|
|
141
|
+
["deployer", "pubkey"],
|
|
142
|
+
|
|
143
|
+
["refund_total", "u64"],
|
|
144
|
+
["refund_claimed", "u64"],
|
|
145
|
+
["credit_claimed", "u64"],
|
|
146
|
+
["refund_owed", "u64"],
|
|
147
|
+
["refund_dust", "u64"],
|
|
148
|
+
|
|
149
|
+
["creator", "pubkey"],
|
|
150
|
+
["list_root", "bytes:32"],
|
|
151
|
+
["listed_reserve", "u64"],
|
|
152
|
+
["listed_total", "u64"],
|
|
153
|
+
|
|
154
|
+
["wagmi_preset_id", "u8"],
|
|
155
|
+
["wagmi_opened", "u8"],
|
|
156
|
+
["pad2", "bytes:6"],
|
|
157
|
+
["usdc_converted", "u64"],
|
|
158
|
+
["sol_unconverted", "u64"],
|
|
159
|
+
["wagmi_usdc", "u64"],
|
|
160
|
+
["wagmi_floor_in", "u64"],
|
|
161
|
+
["wagmi_floor_refund", "u64"],
|
|
162
|
+
["wagmi_floor_refund_claimed", "u64"],
|
|
163
|
+
["wagmi_tokens_out", "u64"],
|
|
164
|
+
["wagmi_tokens_claimed", "u64"],
|
|
165
|
+
["wagmi_launch", "pubkey"],
|
|
166
|
+
["wagmi_mint", "pubkey"],
|
|
167
|
+
["sol_converted", "u64"],
|
|
168
|
+
["floor_usdc_in", "u64"],
|
|
169
|
+
["usdc_refund_total", "u64"],
|
|
170
|
+
["usdc_refund_claimed", "u64"],
|
|
171
|
+
["usdc_refund_owed", "u64"],
|
|
172
|
+
["usdc_excess", "u64"],
|
|
173
|
+
|
|
174
|
+
["wagmi_credit_claimed", "u64"],
|
|
175
|
+
["wagmi_floor_dust", "u64"],
|
|
176
|
+
|
|
177
|
+
["wagmi_cap_tokens", "u64"],
|
|
178
|
+
["wagmi_over_cap_floor", "u64"],
|
|
179
|
+
["wagmi_over_cap_out", "u64"],
|
|
180
|
+
|
|
181
|
+
["wagmi_buy_fees", "u64[5]"],
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
export const GENESIS_ALLOCATION: Layout = [
|
|
185
|
+
["wallet", "pubkey"],
|
|
186
|
+
["contributed", "u64"],
|
|
187
|
+
["claimed_tokens", "u64"],
|
|
188
|
+
["refunded", "u64"],
|
|
189
|
+
["bump", "u8"],
|
|
190
|
+
["flags", "u8"],
|
|
191
|
+
["pad0", "bytes:6"],
|
|
192
|
+
["migrated", "u64"],
|
|
193
|
+
|
|
194
|
+
["raise_refund", "u64"],
|
|
195
|
+
["refund_owed", "u64"],
|
|
196
|
+
|
|
197
|
+
["listed_old", "u64"],
|
|
198
|
+
["listed", "u64"],
|
|
199
|
+
|
|
200
|
+
["wagmi_claimed", "u64"],
|
|
201
|
+
["usdc_refund", "u64"],
|
|
202
|
+
["usdc_owed", "u64"],
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
export const GENESIS_ALLOC_MIGRATED = 1;
|
|
206
|
+
export const GENESIS_ALLOC_REFUNDED = 2;
|
|
207
|
+
export const GENESIS_ALLOC_CLAIMED = 4;
|
|
208
|
+
export const GENESIS_ALLOC_WAGMI_CLAIMED = 8;
|
|
209
|
+
|
|
210
|
+
const NESTED: Record<string, Layout> = { SlotMember: SLOT_MEMBER };
|
|
211
|
+
|
|
212
|
+
export const LAYOUTS = { Config: CONFIG, QuoteEntry: QUOTE_ENTRY, TeamSlot: TEAM_SLOT, SlotMember: SLOT_MEMBER, TraderRef: TRADER_REF, TraderLink: TRADER_LINK, RefOwed: REF_OWED, GenesisRaise: GENESIS_RAISE, GenesisAllocation: GENESIS_ALLOCATION } as const;
|
|
213
|
+
|
|
214
|
+
function scalarSize(t: string): number {
|
|
215
|
+
switch (t) {
|
|
216
|
+
case "u8":
|
|
217
|
+
return 1;
|
|
218
|
+
case "u16":
|
|
219
|
+
return 2;
|
|
220
|
+
case "u32":
|
|
221
|
+
return 4;
|
|
222
|
+
case "u64":
|
|
223
|
+
case "i64":
|
|
224
|
+
return 8;
|
|
225
|
+
case "u128l":
|
|
226
|
+
return 16;
|
|
227
|
+
case "pubkey":
|
|
228
|
+
return 32;
|
|
229
|
+
}
|
|
230
|
+
if (t.startsWith("bytes:")) return Number(t.slice(6));
|
|
231
|
+
if (t in NESTED) return layoutSize(NESTED[t]);
|
|
232
|
+
throw new Error(`unknown field type ${t}`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function fieldSize(t: FieldType): number {
|
|
236
|
+
const m = /^(.+)\[(\d+)\]$/.exec(t);
|
|
237
|
+
return m ? scalarSize(m[1]) * Number(m[2]) : scalarSize(t);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function layoutOffsets(l: Layout): [string, number, number][] {
|
|
241
|
+
let o = 0;
|
|
242
|
+
return l.map(([n, t]) => {
|
|
243
|
+
const s = fieldSize(t);
|
|
244
|
+
const r: [string, number, number] = [n, o, s];
|
|
245
|
+
o += s;
|
|
246
|
+
return r;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function layoutSize(l: Layout): number {
|
|
251
|
+
return l.reduce((a, [, t]) => a + fieldSize(t), 0);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const camel = (s: string): string => s.replace(/_([a-z0-9])/g, (_, c: string) => c.toUpperCase());
|
|
255
|
+
|
|
256
|
+
function readUint(b: Uint8Array, o: number, n: number): bigint {
|
|
257
|
+
let v = 0n;
|
|
258
|
+
for (let i = n - 1; i >= 0; i--) v = (v << 8n) | BigInt(b[o + i]);
|
|
259
|
+
return v;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function readScalar(b: Uint8Array, o: number, t: string): unknown {
|
|
263
|
+
switch (t) {
|
|
264
|
+
case "u8":
|
|
265
|
+
case "u16":
|
|
266
|
+
case "u32":
|
|
267
|
+
return Number(readUint(b, o, scalarSize(t)));
|
|
268
|
+
case "u64":
|
|
269
|
+
return readUint(b, o, 8);
|
|
270
|
+
case "i64": {
|
|
271
|
+
const v = readUint(b, o, 8);
|
|
272
|
+
return v >= 1n << 63n ? v - (1n << 64n) : v;
|
|
273
|
+
}
|
|
274
|
+
case "u128l":
|
|
275
|
+
return readUint(b, o, 16);
|
|
276
|
+
case "pubkey":
|
|
277
|
+
return base58Encode(b.slice(o, o + 32));
|
|
278
|
+
}
|
|
279
|
+
if (t.startsWith("bytes:")) return b.slice(o, o + Number(t.slice(6)));
|
|
280
|
+
if (t in NESTED) return decodeStruct(NESTED[t], b, o);
|
|
281
|
+
throw new Error(`unknown field type ${t}`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function decodeStruct(l: Layout, b: Uint8Array, o = 0): Record<string, any> {
|
|
285
|
+
const out: Record<string, any> = {};
|
|
286
|
+
let at = o;
|
|
287
|
+
for (const [n, t] of l) {
|
|
288
|
+
const m = /^(.+)\[(\d+)\]$/.exec(t);
|
|
289
|
+
if (m) {
|
|
290
|
+
const s = scalarSize(m[1]);
|
|
291
|
+
out[camel(n)] = Array.from({ length: Number(m[2]) }, (_, i) => readScalar(b, at + i * s, m[1]));
|
|
292
|
+
} else out[camel(n)] = readScalar(b, at, t);
|
|
293
|
+
at += fieldSize(t);
|
|
294
|
+
}
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function writeScalar(b: Uint8Array, o: number, t: string, v: any): void {
|
|
299
|
+
if (v === undefined) return;
|
|
300
|
+
if (t === "pubkey") {
|
|
301
|
+
b.set(addressBytes(v), o);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (t.startsWith("bytes:")) {
|
|
305
|
+
b.set(v, o);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (t in NESTED) {
|
|
309
|
+
encodeStructInto(NESTED[t], v, b, o);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const n = scalarSize(t);
|
|
313
|
+
let x = BigInt(v);
|
|
314
|
+
if (t === "i64" && x < 0n) x += 1n << 64n;
|
|
315
|
+
for (let i = 0; i < n; i++) {
|
|
316
|
+
b[o + i] = Number(x & 0xffn);
|
|
317
|
+
x >>= 8n;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function encodeStructInto(l: Layout, v: Record<string, any>, b: Uint8Array, o: number): void {
|
|
322
|
+
let at = o;
|
|
323
|
+
for (const [n, t] of l) {
|
|
324
|
+
const x = v[camel(n)];
|
|
325
|
+
const m = /^(.+)\[(\d+)\]$/.exec(t);
|
|
326
|
+
if (m && x !== undefined) {
|
|
327
|
+
const s = scalarSize(m[1]);
|
|
328
|
+
(x as any[]).forEach((e, i) => writeScalar(b, at + i * s, m[1], e));
|
|
329
|
+
} else if (!m) writeScalar(b, at, t, x);
|
|
330
|
+
at += fieldSize(t);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function encodeStruct(l: Layout, v: Record<string, any>): Uint8Array {
|
|
335
|
+
const b = new Uint8Array(layoutSize(l));
|
|
336
|
+
encodeStructInto(l, v, b, 0);
|
|
337
|
+
return b;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function encodeAccount(name: keyof typeof LAYOUTS, v: Record<string, any>): Uint8Array {
|
|
341
|
+
const l = LAYOUTS[name];
|
|
342
|
+
const b = new Uint8Array(8 + layoutSize(l));
|
|
343
|
+
if (name !== "SlotMember") b.set(accountDiscriminator(name), 0);
|
|
344
|
+
encodeStructInto(l, v, b, 8);
|
|
345
|
+
return b;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export class AccountDecodeError extends Error {
|
|
349
|
+
constructor(detail: string) {
|
|
350
|
+
super(`floor_amm account: ${detail}`);
|
|
351
|
+
this.name = "AccountDecodeError";
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function decodeAccount(name: keyof typeof LAYOUTS, data: Uint8Array): Record<string, any> {
|
|
356
|
+
const l = LAYOUTS[name];
|
|
357
|
+
const d = accountDiscriminator(name);
|
|
358
|
+
|
|
359
|
+
if (data.length !== 8 + layoutSize(l)) throw new AccountDecodeError(`${name}: ${data.length} bytes, want ${8 + layoutSize(l)}`);
|
|
360
|
+
if (hex(data.slice(0, 8)) !== hex(d)) throw new AccountDecodeError(`${name}: wrong discriminator`);
|
|
361
|
+
return decodeStruct(l, data, 8);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const decodeConfig = (d: Uint8Array) => decodeAccount("Config", d);
|
|
365
|
+
export const decodeQuoteEntry = (d: Uint8Array) => decodeAccount("QuoteEntry", d);
|
|
366
|
+
export const decodeTeamSlot = (d: Uint8Array) => decodeAccount("TeamSlot", d);
|
|
367
|
+
export const decodeTraderRef = (d: Uint8Array) => decodeAccount("TraderRef", d);
|
|
368
|
+
export const decodeTraderLink = (d: Uint8Array) => decodeAccount("TraderLink", d);
|
|
369
|
+
export const decodeRefOwed = (d: Uint8Array) => decodeAccount("RefOwed", d);
|
|
370
|
+
export const decodeGenesisRaise = (d: Uint8Array) => decodeAccount("GenesisRaise", d);
|
|
371
|
+
export const decodeGenesisAllocation = (d: Uint8Array) => decodeAccount("GenesisAllocation", d);
|
|
372
|
+
|
|
373
|
+
export function accountKind(data: Uint8Array): keyof typeof LAYOUTS | null {
|
|
374
|
+
const d = hex(data.slice(0, 8));
|
|
375
|
+
for (const name of Object.keys(LAYOUTS) as (keyof typeof LAYOUTS)[]) {
|
|
376
|
+
if (name === "SlotMember" || hex(accountDiscriminator(name)) !== d) continue;
|
|
377
|
+
if (data.length !== 8 + layoutSize(LAYOUTS[name])) throw new AccountDecodeError(`${name}: ${data.length} bytes, want ${8 + layoutSize(LAYOUTS[name])}`);
|
|
378
|
+
return name;
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export const STATUS_LIVE = 1;
|
|
384
|
+
|
|
385
|
+
export const PRESET_CHECKED_ALL = 2;
|
|
386
|
+
|
|
387
|
+
export const PRESET_CHECKED_STEP1 = 1;
|
|
388
|
+
export const SLOT_ACTIVE = 1;
|
|
389
|
+
export const SLOT_FREE = 2;
|
|
390
|
+
|
|
391
|
+
export function metadataBaseOf(configData: Uint8Array): string {
|
|
392
|
+
const c = decodeConfig(configData);
|
|
393
|
+
const n = Math.min(Number(c.metadataBaseLen), 72);
|
|
394
|
+
return new TextDecoder().decode((c.metadataBase as Uint8Array).slice(0, n));
|
|
395
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, base58Encode } from "../../codec.ts";
|
|
4
|
+
|
|
5
|
+
export class Writer {
|
|
6
|
+
private parts: number[] = [];
|
|
7
|
+
uint(v: bigint | number, n: number): this {
|
|
8
|
+
let x = BigInt(v);
|
|
9
|
+
if (x < 0n || x >= 1n << BigInt(8 * n)) throw new RangeError(`a ${8 * n}-bit value out of range: ${v}`);
|
|
10
|
+
for (let i = 0; i < n; i++) {
|
|
11
|
+
this.parts.push(Number(x & 0xffn));
|
|
12
|
+
x >>= 8n;
|
|
13
|
+
}
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
u8 = (v: number): this => this.uint(v, 1);
|
|
17
|
+
u16 = (v: number): this => this.uint(v, 2);
|
|
18
|
+
u32 = (v: number): this => this.uint(v, 4);
|
|
19
|
+
u64 = (v: bigint): this => this.uint(v, 8);
|
|
20
|
+
u128 = (v: bigint): this => this.uint(v, 16);
|
|
21
|
+
bool = (v: boolean): this => this.u8(v ? 1 : 0);
|
|
22
|
+
pubkey = (a: string): this => this.bytes(addressBytes(a));
|
|
23
|
+
bytes(b: Uint8Array): this {
|
|
24
|
+
for (const x of b) this.parts.push(x);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
string(s: string): this {
|
|
28
|
+
const b = new TextEncoder().encode(s);
|
|
29
|
+
return this.u32(b.length).bytes(b);
|
|
30
|
+
}
|
|
31
|
+
done(): Uint8Array {
|
|
32
|
+
return Uint8Array.from(this.parts);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Reader {
|
|
37
|
+
o = 0;
|
|
38
|
+
readonly b: Uint8Array;
|
|
39
|
+
constructor(b: Uint8Array) {
|
|
40
|
+
this.b = b;
|
|
41
|
+
}
|
|
42
|
+
uint(n: number): bigint {
|
|
43
|
+
if (this.o + n > this.b.length) throw new RangeError("borsh: data too short");
|
|
44
|
+
let v = 0n;
|
|
45
|
+
for (let i = n - 1; i >= 0; i--) v = (v << 8n) | BigInt(this.b[this.o + i]);
|
|
46
|
+
this.o += n;
|
|
47
|
+
return v;
|
|
48
|
+
}
|
|
49
|
+
u8 = (): number => Number(this.uint(1));
|
|
50
|
+
u16 = (): number => Number(this.uint(2));
|
|
51
|
+
u32 = (): number => Number(this.uint(4));
|
|
52
|
+
u64 = (): bigint => this.uint(8);
|
|
53
|
+
i64 = (): bigint => {
|
|
54
|
+
const v = this.uint(8);
|
|
55
|
+
return v >= 1n << 63n ? v - (1n << 64n) : v;
|
|
56
|
+
};
|
|
57
|
+
u128 = (): bigint => this.uint(16);
|
|
58
|
+
bool = (): boolean => this.u8() !== 0;
|
|
59
|
+
bytes(n: number): Uint8Array {
|
|
60
|
+
if (this.o + n > this.b.length) throw new RangeError("borsh: data too short");
|
|
61
|
+
const r = this.b.slice(this.o, this.o + n);
|
|
62
|
+
this.o += n;
|
|
63
|
+
return r;
|
|
64
|
+
}
|
|
65
|
+
pubkey = (): string => base58Encode(this.bytes(32));
|
|
66
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { MEMBERS_MAX as MAX_MEMBERS } from "../../v2/layouts.ts";
|
|
4
|
+
import { createLaunchInstructionV2 } from "../../v2/solana.ts";
|
|
5
|
+
import type { Instruction } from "../instruction.ts";
|
|
6
|
+
import { computeUnitLimitInstruction, computeUnitPriceInstruction } from "../instruction.ts";
|
|
7
|
+
import { PACKET_DATA_SIZE, compileV0Message, transactionSize } from "../tx.ts";
|
|
8
|
+
import type { LookupTable } from "../tx.ts";
|
|
9
|
+
import { createMintAccounts, teamSlotAddInstruction, TEAM_SLOT_PENDING_HANDLE, TEAM_SLOT_WALLET } from "./instructions.ts";
|
|
10
|
+
import { FLOOR_AMM_PROGRAM_ID, teamSlotPda } from "./program.ts";
|
|
11
|
+
|
|
12
|
+
export interface CreateSlotMember {
|
|
13
|
+
|
|
14
|
+
key: string;
|
|
15
|
+
kind: typeof TEAM_SLOT_WALLET | typeof TEAM_SLOT_PENDING_HANDLE;
|
|
16
|
+
|
|
17
|
+
amount: bigint;
|
|
18
|
+
|
|
19
|
+
payNow: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const MAX_TX_LOCKS = 64;
|
|
23
|
+
|
|
24
|
+
export interface CreateWithSlotPlan {
|
|
25
|
+
instructions: Instruction[];
|
|
26
|
+
message: Uint8Array;
|
|
27
|
+
size: number;
|
|
28
|
+
locks: number;
|
|
29
|
+
|
|
30
|
+
fits: boolean;
|
|
31
|
+
|
|
32
|
+
transactions: { instructions: Instruction[]; message: Uint8Array; size: number }[];
|
|
33
|
+
|
|
34
|
+
teamSlot: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function planCreateWithSlot(p: {
|
|
38
|
+
create: Parameters<typeof createLaunchInstructionV2>[0];
|
|
39
|
+
members: readonly CreateSlotMember[];
|
|
40
|
+
recentBlockhash: string;
|
|
41
|
+
lookupTables?: LookupTable[];
|
|
42
|
+
computeUnitLimit?: number;
|
|
43
|
+
microLamports?: bigint;
|
|
44
|
+
}): CreateWithSlotPlan {
|
|
45
|
+
const c = p.create;
|
|
46
|
+
const pid = c.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
47
|
+
if (p.members.length > MAX_MEMBERS) throw new RangeError(`a Team Slot has at most ${MAX_MEMBERS} members (R103)`);
|
|
48
|
+
const mint = createMintAccounts({ ...c, programId: pid });
|
|
49
|
+
const teamSlot = teamSlotPda(mint.launch, pid)[0];
|
|
50
|
+
const pay = { payer: c.creator, launch: mint.launch, teamSlot, quoteMint: c.quoteMint, payerQuote: c.creatorQuote, quoteVault: mint.quoteVault, quoteTokenProgram: c.quoteTokenProgram, baseMint: mint.baseMint, programId: pid };
|
|
51
|
+
const instructions: Instruction[] = [
|
|
52
|
+
...(p.computeUnitLimit !== undefined ? [computeUnitLimitInstruction(p.computeUnitLimit)] : []),
|
|
53
|
+
...(p.microLamports !== undefined ? [computeUnitPriceInstruction(p.microLamports)] : []),
|
|
54
|
+
createLaunchInstructionV2(c),
|
|
55
|
+
|
|
56
|
+
...[...p.members.filter((m) => m.payNow), ...p.members.filter((m) => !m.payNow)].map((m) => teamSlotAddInstruction({ ...pay, key: m.key, kind: m.kind, amount: m.amount, payNow: m.payNow })),
|
|
57
|
+
];
|
|
58
|
+
const compile = (ixs: Instruction[]) => {
|
|
59
|
+
const m = compileV0Message({ payer: c.creator, instructions: ixs, recentBlockhash: p.recentBlockhash, lookupTables: p.lookupTables });
|
|
60
|
+
return { instructions: ixs, message: m, size: transactionSize(m) };
|
|
61
|
+
};
|
|
62
|
+
const whole = compile(instructions);
|
|
63
|
+
const { message, size } = whole;
|
|
64
|
+
const lockSet = new Set<string>([c.creator]);
|
|
65
|
+
for (const ix of instructions) {
|
|
66
|
+
lockSet.add(ix.programAddress);
|
|
67
|
+
for (const a of ix.accounts) lockSet.add(a.address);
|
|
68
|
+
}
|
|
69
|
+
const fits = size <= PACKET_DATA_SIZE && lockSet.size <= MAX_TX_LOCKS;
|
|
70
|
+
|
|
71
|
+
const transactions: CreateWithSlotPlan["transactions"] = [];
|
|
72
|
+
if (fits) transactions.push(whole);
|
|
73
|
+
else {
|
|
74
|
+
const budget = instructions.slice(0, instructions.length - 1 - p.members.length);
|
|
75
|
+
const adds = instructions.slice(instructions.length - p.members.length);
|
|
76
|
+
let cur = instructions.slice(0, instructions.length - p.members.length);
|
|
77
|
+
for (const a of adds) {
|
|
78
|
+
const next = compile([...cur, a]);
|
|
79
|
+
if (next.size <= PACKET_DATA_SIZE) cur = [...cur, a];
|
|
80
|
+
else {
|
|
81
|
+
transactions.push(compile(cur));
|
|
82
|
+
cur = [...budget, a];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
transactions.push(compile(cur));
|
|
86
|
+
for (const t of transactions) if (t.size > PACKET_DATA_SIZE) throw new RangeError(`a create transaction is ${t.size} B even alone: give a lookup table`);
|
|
87
|
+
}
|
|
88
|
+
return { instructions, message, size, locks: lockSet.size, fits, transactions, teamSlot };
|
|
89
|
+
}
|