@floorlaunchpad/sdk 0.4.0 → 0.6.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/dist/abi/evm.gen.js +5 -0
  3. package/dist/abi/functions.gen.js +1 -1
  4. package/dist/client/solana/index.js +13 -8
  5. package/dist/config/generated.js +78 -1
  6. package/dist/config/registry.gen.js +1 -1
  7. package/dist/evm/chains.js +56 -18
  8. package/dist/evm/squid.js +10 -10
  9. package/dist/evm/zap.js +148 -35
  10. package/dist/index.js +1 -0
  11. package/dist/indexer/bodies.js +9 -0
  12. package/dist/indexer/client.js +2 -0
  13. package/dist/indexer/contract.js +48 -2
  14. package/dist/indexer/paths.js +26 -0
  15. package/dist/indexer/read.js +3 -0
  16. package/dist/math/v2/book.js +40 -7
  17. package/dist/math/v2/create.js +1 -1
  18. package/dist/math/v2/relay.js +201 -1
  19. package/dist/math/v2/split.js +60 -15
  20. package/dist/math/v2/trade.js +16 -8
  21. package/dist/ton/addresses.js +36 -0
  22. package/dist/ton/book-check.js +23 -0
  23. package/dist/ton/book.js +119 -0
  24. package/dist/ton/cell.js +542 -0
  25. package/dist/ton/consts.generated.js +17 -0
  26. package/dist/ton/content.js +83 -0
  27. package/dist/ton/gas.js +198 -0
  28. package/dist/ton/governance.js +401 -0
  29. package/dist/ton/index.js +18 -0
  30. package/dist/ton/messages.js +340 -0
  31. package/dist/ton/ops.js +37 -0
  32. package/dist/ton/price.js +51 -0
  33. package/dist/ton/quote-entry.js +116 -0
  34. package/dist/ton/quote.js +25 -0
  35. package/dist/ton/reader.js +378 -0
  36. package/dist/ton/types.js +43 -0
  37. package/dist/ton/wallet.js +26 -0
  38. package/dist/v2/devbuy.js +6 -4
  39. package/dist/v2/evm.js +3 -1
  40. package/dist/v2/layouts.js +5 -1
  41. package/dist/v2/presetRowEvm.js +21 -2
  42. package/dist/v2/router.js +2 -2
  43. package/dist/v2/solanaSettle.js +2 -0
  44. package/docs/ton.md +107 -0
  45. package/examples/floor-line.html +1 -1
  46. package/package.json +6 -1
  47. package/src/abi/evm.gen.ts +5 -0
  48. package/src/abi/functions.gen.ts +1 -1
  49. package/src/client/solana/index.ts +13 -8
  50. package/src/config/generated.ts +78 -1
  51. package/src/config/registry.gen.ts +1 -1
  52. package/src/evm/chains.ts +63 -17
  53. package/src/evm/squid.ts +10 -10
  54. package/src/evm/zap.ts +185 -36
  55. package/src/index.ts +1 -0
  56. package/src/indexer/bodies.ts +11 -0
  57. package/src/indexer/client.ts +5 -1
  58. package/src/indexer/contract.ts +48 -2
  59. package/src/indexer/paths.ts +47 -0
  60. package/src/indexer/read.ts +5 -2
  61. package/src/math/v2/book.ts +42 -7
  62. package/src/math/v2/create.ts +1 -1
  63. package/src/math/v2/relay.ts +208 -1
  64. package/src/math/v2/split.ts +70 -16
  65. package/src/math/v2/trade.ts +16 -8
  66. package/src/ton/addresses.ts +38 -0
  67. package/src/ton/book-check.ts +24 -0
  68. package/src/ton/book.ts +136 -0
  69. package/src/ton/cell.ts +547 -0
  70. package/src/ton/consts.generated.ts +17 -0
  71. package/src/ton/content.ts +97 -0
  72. package/src/ton/gas.ts +209 -0
  73. package/src/ton/governance.ts +452 -0
  74. package/src/ton/index.ts +18 -0
  75. package/src/ton/messages.ts +343 -0
  76. package/src/ton/ops.ts +37 -0
  77. package/src/ton/price.ts +54 -0
  78. package/src/ton/quote-entry.ts +138 -0
  79. package/src/ton/quote.ts +67 -0
  80. package/src/ton/reader.ts +420 -0
  81. package/src/ton/types.ts +201 -0
  82. package/src/ton/wallet.ts +30 -0
  83. package/src/v2/devbuy.ts +6 -4
  84. package/src/v2/evm.ts +5 -1
  85. package/src/v2/layouts.ts +5 -1
  86. package/src/v2/presetRowEvm.ts +21 -2
  87. package/src/v2/router.ts +2 -2
  88. package/src/v2/solanaSettle.ts +2 -0
  89. package/src/v2/types.ts +4 -1
@@ -0,0 +1,378 @@
1
+
2
+
3
+ import { Address, beginCell, bytesOfBase64, fromBoc } from "./cell.js";
4
+
5
+ import { addr, accountAddress as deriveAccount } from "./addresses.js";
6
+
7
+ export const intItem = (value ) => ({ type: "int", value: BigInt(value) });
8
+
9
+ export const addressItem = (a ) => ({ type: "slice", cell: beginCell().storeAddress(a === null ? null : addr(a)).endCell() });
10
+
11
+ export class StackError extends Error {}
12
+
13
+ const int = (s , i , name ) => {
14
+ const x = s[i];
15
+ if (!x || x.type !== "int") throw new StackError(`${name}: expected an int at ${i}`);
16
+ return x.value;
17
+ };
18
+ const bool = (s , i , name ) => int(s, i, name) !== 0n;
19
+ const cell = (s , i , name ) => {
20
+ const x = s[i];
21
+ if (!x || (x.type !== "cell" && x.type !== "slice")) throw new StackError(`${name}: expected a cell at ${i}`);
22
+ return x.cell;
23
+ };
24
+ const address = (s , i , name ) => {
25
+ const x = s[i];
26
+ if (!x) throw new StackError(`${name}: missing item ${i}`);
27
+ if (x.type === "null") return null;
28
+ if (x.type !== "slice" && x.type !== "cell") throw new StackError(`${name}: expected an address at ${i}`);
29
+ return x.cell.beginParse().loadAddress();
30
+ };
31
+ const need = (s , n , name ) => {
32
+ if (s.length < n) throw new StackError(`${name}: ${s.length} stack items, expected ${n}`);
33
+ };
34
+
35
+ const parseNum = (v ) => {
36
+ const t = String(v);
37
+ return t.startsWith("-") ? -BigInt(t.slice(1)) : BigInt(t);
38
+ };
39
+
40
+ export function parseToncenterStack(raw ) {
41
+ return raw.map((e) => {
42
+ let type ;
43
+ let v ;
44
+ if (Array.isArray(e)) [type, v] = e ;
45
+ else if (e && typeof e === "object" && typeof (e )["@type"] === "string") {
46
+
47
+ const t = (e )["@type"] ;
48
+ if (t === "tvm.stackEntryNumber") { type = "num"; v = (e ).number?.number ?? (e ).number; }
49
+ else if (t === "tvm.stackEntryCell") { type = "cell"; v = (e ).cell; }
50
+ else if (t === "tvm.stackEntrySlice") { type = "slice"; v = (e ).slice; }
51
+ else if (t === "tvm.stackEntryTuple") { type = "tuple"; v = (e ).tuple; }
52
+ else if (t === "tvm.stackEntryList") { type = "list"; v = (e ).list; }
53
+ else if (t === "tvm.stackEntryUnsupported") { type = "null"; v = null; }
54
+ else throw new StackError(`unknown stack item type ${t}`);
55
+ } else {
56
+ type = (e ).type;
57
+ v = (e ).value;
58
+ }
59
+ switch (type) {
60
+ case "num":
61
+ case "int":
62
+ return { type: "int", value: parseNum(v) };
63
+ case "cell":
64
+ return { type: "cell", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
65
+ case "slice":
66
+ case "cell_slice":
67
+ return { type: "slice", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
68
+ case "null":
69
+ return { type: "null" };
70
+ case "tuple":
71
+ case "list": {
72
+ const els = v?.elements ?? v ?? [];
73
+
74
+ if (els.length === 0) return { type: "null" };
75
+ return { type: "tuple", items: parseToncenterStack(els) };
76
+ }
77
+ default:
78
+ throw new StackError(`unknown stack item type ${type}`);
79
+ }
80
+ });
81
+ }
82
+
83
+ export function parseCoinsMap(root , keyBits ) {
84
+ const out = new Map ();
85
+ if (!root) return out;
86
+ const walk = (c , prefix , prefixLen ) => {
87
+ const s = c.beginParse();
88
+ const m = keyBits - prefixLen;
89
+
90
+ let lbl = 0n;
91
+ let len = 0;
92
+ const lenBits = (n ) => Math.ceil(Math.log2(n + 1));
93
+ if (!s.loadBit()) {
94
+
95
+ while (s.loadBit()) len++;
96
+ lbl = len > 0 ? s.loadUint(len) : 0n;
97
+ } else if (!s.loadBit()) {
98
+ len = Number(s.loadUint(lenBits(m)));
99
+ lbl = len > 0 ? s.loadUint(len) : 0n;
100
+ } else {
101
+ const bit = s.loadBit();
102
+ len = Number(s.loadUint(lenBits(m)));
103
+ lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
104
+ }
105
+ const pfx = (prefix << BigInt(len)) | lbl;
106
+ const plen = prefixLen + len;
107
+ if (plen === keyBits) {
108
+ out.set(pfx, s.loadCoins());
109
+ return;
110
+ }
111
+
112
+ const l = s.loadRef();
113
+ const r = s.loadRef();
114
+ walk(l, pfx << 1n, plen + 1);
115
+ walk(r, (pfx << 1n) | 1n, plen + 1);
116
+ };
117
+ walk(root, 0n, 0);
118
+ return out;
119
+ }
120
+
121
+ function feesOf(s , i , name ) {
122
+ const x = s[i];
123
+ if (!x || x.type !== "tuple" || x.items.length < 5) throw new StackError(`${name}: expected a 5-int tuple at ${i}`);
124
+ const [backing, team, platform, floor, holder] = [0, 1, 2, 3, 4].map((k) => int(x.items, k, `${name}[${k}]`));
125
+ return { backing: backing , team: team , platform: platform , floor: floor , holder: holder };
126
+ }
127
+
128
+ async function run(rpc , a , method , stack = []) {
129
+ return rpc.runGetMethod(addr(a), method, stack);
130
+ }
131
+
132
+ export async function getLaunchState(rpc , launch ) {
133
+ const s = await run(rpc, launch, "get_launch_state");
134
+ need(s, 14, "get_launch_state");
135
+ return {
136
+ id: int(s, 0, "id"), factory: address(s, 1, "factory"), creator: address(s, 2, "creator"), quote: address(s, 3, "quote"),
137
+ presetId: int(s, 4, "preset_id"), graduated: bool(s, 5, "phase"), supply: int(s, 6, "supply"), circulating: int(s, 7, "circulating"),
138
+ dead: int(s, 8, "dead"), f: int(s, 9, "f"), c: int(s, 10, "c"), k: int(s, 11, "k"), moneyInPlace: int(s, 12, "money_in_place"),
139
+ reserve: int(s, 13, "reserve"),
140
+ };
141
+ }
142
+
143
+ export async function getLaunchBook(rpc , launch ) {
144
+ const s = await run(rpc, launch, "get_launch_book");
145
+ need(s, 1, "get_launch_book");
146
+ return cell(s, 0, "book");
147
+ }
148
+ export async function getLaunchMilestones(rpc , launch ) {
149
+ return cell(await run(rpc, launch, "get_launch_milestones"), 0, "milestones");
150
+ }
151
+ export async function getFeeCurve(rpc , launch ) {
152
+ return cell(await run(rpc, launch, "get_fee_curve"), 0, "curve");
153
+ }
154
+ export async function getCirculating(rpc , launch ) {
155
+ return int(await run(rpc, launch, "get_circulating"), 0, "s_circ");
156
+ }
157
+ export async function getBidMoney(rpc , launch ) {
158
+ const s = await run(rpc, launch, "get_bid_money");
159
+ need(s, 4, "get_bid_money");
160
+ return { f: int(s, 0, "f"), c: int(s, 1, "c"), k: int(s, 2, "k"), moneyInPlace: int(s, 3, "money_in_place") };
161
+ }
162
+ export async function getHolderBook(rpc , launch ) {
163
+ const s = await run(rpc, launch, "get_holder_book");
164
+ need(s, 3, "get_holder_book");
165
+ return { indexX64: int(s, 0, "index_x64"), w: int(s, 1, "w"), bucket: int(s, 2, "bucket") };
166
+ }
167
+ export async function getTeamShare(rpc , launch , place ) {
168
+ const s = await run(rpc, launch, "get_team_share", [intItem(place)]);
169
+ need(s, 2, "get_team_share");
170
+ return { owed: int(s, 0, "owed"), bought: int(s, 1, "bought") };
171
+ }
172
+ export async function getGasParams(rpc , launch ) {
173
+ const s = await run(rpc, launch, "get_gas_params");
174
+ need(s, 4, "get_gas_params");
175
+ return { buyFwdMin: int(s, 0, "buy_fwd_min"), sellFwdMin: int(s, 1, "sell_fwd_min"), refundFwdMin: int(s, 2, "refund_fwd_min"), reclaimAfter: int(s, 3, "reclaim_after") };
176
+ }
177
+ export async function getQuoteWallet(rpc , launch ) {
178
+ return address(await run(rpc, launch, "get_quote_wallet"), 0, "wallet");
179
+ }
180
+ export async function getQuoteBooks(rpc , launch ) {
181
+ const s = await run(rpc, launch, "get_quote_books");
182
+ need(s, 5, "get_quote_books");
183
+ return { entry: cell(s, 0, "entry"), booked: int(s, 1, "booked"), syncedBalance: int(s, 2, "synced_balance"), syncedAt: int(s, 3, "synced_at"), surplus: int(s, 4, "surplus") };
184
+ }
185
+ export async function getWalletAddress(rpc , master , owner ) {
186
+ return address(await run(rpc, master, "get_wallet_address", [addressItem(owner)]), 0, "wallet");
187
+ }
188
+ export async function getLaunchAddress(rpc , factory , id ) {
189
+ return address(await run(rpc, factory, "get_launch_address", [intItem(id)]), 0, "launch");
190
+ }
191
+ export async function getAccountAddress(rpc , launch , owner ) {
192
+ return address(await run(rpc, launch, "get_account_address", [addressItem(owner)]), 0, "account");
193
+ }
194
+ export async function getPosition(rpc , wallet ) {
195
+ const s = await run(rpc, wallet, "get_position");
196
+ need(s, 5, "get_position");
197
+ return { amount: int(s, 0, "amount"), owed: int(s, 1, "owed"), indexSnapX64: int(s, 2, "index_snap_x64"), optedIn: bool(s, 3, "opted_in"), dead: bool(s, 4, "dead") };
198
+ }
199
+ export async function getWalletData(rpc , wallet ) {
200
+ const s = await run(rpc, wallet, "get_wallet_data");
201
+ need(s, 3, "get_wallet_data");
202
+ return { balance: int(s, 0, "balance"), owner: address(s, 1, "owner"), master: address(s, 2, "master") };
203
+ }
204
+
205
+ export async function simBuy(rpc , launch , money , now ) {
206
+ const s = await run(rpc, launch, "sim_buy", [intItem(money), intItem(now)]);
207
+ need(s, 6, "sim_buy");
208
+ return { tokens: int(s, 0, "tokens"), refund: int(s, 1, "refund"), fees: feesOf(s, 2, "fees"), steps: Number(int(s, 3, "steps")), budgetHit: bool(s, 4, "budget_hit"), errorClass: Number(int(s, 5, "class")) };
209
+ }
210
+ export async function simSell(rpc , launch , tokens , now ) {
211
+ const s = await run(rpc, launch, "sim_sell", [intItem(tokens), intItem(now)]);
212
+ need(s, 3, "sim_sell");
213
+ return { out: int(s, 0, "out"), fees: feesOf(s, 1, "fees"), errorClass: Number(int(s, 2, "class")) };
214
+ }
215
+
216
+ export async function quoteBuyMoney(rpc , launch , tokens ) {
217
+ return int(await run(rpc, launch, "quote_buy", [intItem(tokens)]), 0, "money");
218
+ }
219
+ export async function quoteSellTokens(rpc , launch , out ) {
220
+ return int(await run(rpc, launch, "quote_sell", [intItem(out)]), 0, "tokens");
221
+ }
222
+
223
+ export async function getOwed(rpc , account ) {
224
+ const s = await run(rpc, account, "get_owed");
225
+ need(s, 3, "get_owed");
226
+ const m = s[0];
227
+ return {
228
+ owed: parseCoinsMap(m && m.type !== "null" && m.type !== "int" ? (m ).cell : null, 16),
229
+ teamBuyLockUntil: int(s, 1, "team_buy_lock_until"), teamBuyTokens: int(s, 2, "team_buy_tokens"),
230
+ };
231
+ }
232
+
233
+ export async function getOwedOf(rpc , chain , launch , owner ) {
234
+ return getOwed(rpc, deriveAccount(chain, launch, owner));
235
+ }
236
+ export async function getInFlight(rpc , account , payoutId ) {
237
+ const s = await run(rpc, account, "get_in_flight", [intItem(payoutId)]);
238
+ need(s, 4, "get_in_flight");
239
+ return { quote: address(s, 0, "quote"), amount: int(s, 1, "amount"), bit: Number(int(s, 2, "bit")), sentAt: int(s, 3, "sent_at") };
240
+ }
241
+ export async function getConfig(rpc , factory )
242
+
243
+ {
244
+ const s = await run(rpc, factory, "get_config");
245
+ need(s, 13, "get_config");
246
+ return {
247
+ authority: address(s, 0, "authority"), pendingAuthority: address(s, 1, "pending_authority"), timelock: address(s, 2, "timelock"), treasury: address(s, 3, "treasury"),
248
+ createPaused: bool(s, 4, "create_paused"), nativeCreateFee: int(s, 5, "native_create_fee"), referralAuthority: int(s, 6, "referral_authority"),
249
+ priceUpdater: int(s, 7, "price_updater"), holderDest: address(s, 8, "holder_dest"), metadataBase: s[9]?.type === "null" ? null : cell(s, 9, "metadata_base"),
250
+ launchCount: int(s, 10, "launch_count"), nextPresetId: int(s, 11, "next_preset_id"), codeVersion: int(s, 12, "code_version"),
251
+ };
252
+ }
253
+ export async function getQuote(rpc , factory , master ) {
254
+ const s = await run(rpc, factory, "get_quote", [addressItem(master)]);
255
+ need(s, 3, "get_quote");
256
+ return { entry: cell(s, 0, "entry"), usdCentsX64: int(s, 1, "usd_cents_x64"), validUntil: int(s, 2, "valid_until") };
257
+ }
258
+
259
+ export async function getTonQuotePrice(rpc , factory , quote ) {
260
+ const s = await run(rpc, factory, "get_quote", [addressItem(quote)]);
261
+ need(s, 3, "get_quote");
262
+ const usdCentsX64 = int(s, 1, "usd_cents_x64");
263
+ const validUntil = int(s, 2, "valid_until");
264
+ if (s[0] .type === "null") return { listed: false, entry: null, usdCentsX64, validUntil };
265
+ return { listed: true, entry: decodeTonQuoteEntry(cell(s, 0, "entry")), usdCentsX64, validUntil };
266
+ }
267
+
268
+ export function decodeTonQuoteEntry(c ) {
269
+ const s = c.beginParse();
270
+ const kind = Number(s.loadUint(1)) ;
271
+ const master = s.loadAddress();
272
+ const decimals = Number(s.loadUint(8));
273
+ const walletKind = Number(s.loadUint(8));
274
+ const walletCodeHash = s.loadUint(256);
275
+ const walletCode = s.loadMaybeRef();
276
+ const createFee = s.loadCoins();
277
+ const issuerCanFreeze = s.loadBit();
278
+ const createsEnabled = s.loadBit();
279
+ const cap = s.loadCoins();
280
+ s.endParse();
281
+ return { kind, master, decimals, walletKind, walletCodeHash, walletCode, createFee, issuerCanFreeze, createsEnabled, cap };
282
+ }
283
+
284
+ export function parseRefMap(root , keyBits ) {
285
+ const out = new Map ();
286
+ if (!root) return out;
287
+ const lenBits = (n ) => Math.ceil(Math.log2(n + 1));
288
+ const walk = (c , prefix , prefixLen ) => {
289
+ const s = c.beginParse();
290
+ const m = keyBits - prefixLen;
291
+ let lbl = 0n;
292
+ let len = 0;
293
+ if (!s.loadBit()) {
294
+ while (s.loadBit()) len++;
295
+ lbl = len > 0 ? s.loadUint(len) : 0n;
296
+ } else if (!s.loadBit()) {
297
+ len = Number(s.loadUint(lenBits(m)));
298
+ lbl = len > 0 ? s.loadUint(len) : 0n;
299
+ } else {
300
+ const bit = s.loadBit();
301
+ len = Number(s.loadUint(lenBits(m)));
302
+ lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
303
+ }
304
+ const pfx = (prefix << BigInt(len)) | lbl;
305
+ const plen = prefixLen + len;
306
+ if (plen === keyBits) {
307
+ out.set(pfx, s.loadRef());
308
+ return;
309
+ }
310
+ const l = s.loadRef();
311
+ const r = s.loadRef();
312
+ walk(l, pfx << 1n, plen + 1);
313
+ walk(r, (pfx << 1n) | 1n, plen + 1);
314
+ };
315
+ walk(root, 0n, 0);
316
+ return out;
317
+ }
318
+
319
+ export function decodeTonSlotPlace(c , place ) {
320
+ const s = c.beginParse();
321
+ const member = s.loadAddress();
322
+ const handle = s.loadBit() ? s.loadUint(256) : null;
323
+ const shares = s.loadUint(64);
324
+ const weightPpb = s.loadUint(32);
325
+ const slotOwed = s.loadCoins();
326
+ const boughtOwed = s.loadCoins();
327
+ const teamBuyPart = s.loadCoins();
328
+ s.endParse();
329
+ return { place, member, handle, shares, weightPpb, slotOwed, boughtOwed, teamBuyPart };
330
+ }
331
+
332
+ export async function getTeamSlot(rpc , launch ) {
333
+ const s = await run(rpc, launch, "get_team_slot");
334
+ need(s, 5, "get_team_slot");
335
+ const d = s[4];
336
+ const dict = d && d.type !== "null" && d.type !== "int" ? (d ).cell : null;
337
+ const places = [...parseRefMap(dict, 4)].sort((a, b) => (a[0] < b[0] ? -1 : 1)).map(([k, c]) => decodeTonSlotPlace(c, Number(k)));
338
+ return { slotBps: int(s, 0, "slot_bps"), count: Number(int(s, 1, "count")), shareTotal: int(s, 2, "share_total"), shareBuyDay: int(s, 3, "share_buy_day"), places };
339
+ }
340
+
341
+ export async function getPresetRow(rpc , factory , id ) {
342
+ const s = await run(rpc, factory, "get_preset_row", [intItem(id)]);
343
+ need(s, 6, "get_preset_row");
344
+ const r = s[0];
345
+ const row = r && r.type !== "null" && r.type !== "int" ? (r ).cell : null;
346
+ let rowBytes = null;
347
+ if (row) {
348
+ const parts = [];
349
+ for (let cur = row; cur; ) {
350
+ const sl = cur.beginParse();
351
+ parts.push(sl.loadBytes(sl.remainingBits / 8));
352
+ cur = sl.remainingRefs ? sl.loadRef() : null;
353
+ }
354
+ rowBytes = new Uint8Array(parts.reduce((a, p) => a + p.length, 0));
355
+ let o = 0;
356
+ for (const p of parts) (rowBytes.set(p, o), (o += p.length));
357
+ }
358
+ return {
359
+ found: row !== null, row, rowBytes, enabled: bool(s, 1, "enabled"), deleted: bool(s, 2, "deleted"), checked: bool(s, 3, "checked"),
360
+ version: int(s, 4, "version"), hash: int(s, 5, "hash"),
361
+ };
362
+ }
363
+
364
+ export async function getTraderAddress(rpc , factory , trader ) {
365
+ return address(await run(rpc, factory, "get_trader_address", [addressItem(trader)]), 0, "trader");
366
+ }
367
+
368
+ export async function getFamily(rpc , factory , family ) {
369
+ if (!Number.isInteger(family) || family < 0 || family > 4) throw new RangeError("family must be 0 to 4");
370
+ const s = await run(rpc, factory, "get_family", [intItem(family)]);
371
+ need(s, 3, "get_family");
372
+ return { version: int(s, 0, "version"), initHash: int(s, 1, "init_hash"), codeHash: int(s, 2, "code_hash") };
373
+ }
374
+ export async function getTimelockInfo(rpc , timelock ) {
375
+ const s = await run(rpc, timelock, "get_timelock");
376
+ need(s, 3, "get_timelock");
377
+ return { admin: address(s, 0, "admin"), factory: address(s, 1, "factory"), delay: int(s, 2, "delay") };
378
+ }
@@ -0,0 +1,43 @@
1
+
2
+
3
+ export const DEFAULT_GAS = {
4
+ buyFwdMin: 300_000_000n,
5
+ sellFwdMin: 300_000_000n,
6
+ refundFwdMin: 60_000_000n,
7
+ reclaimAfter: 3600n,
8
+ };
9
+
10
+ export const TON_CLAIM = {
11
+ CREATOR: 1,
12
+ CREATOR_REF: 2,
13
+ TEAM_SLOT: 4,
14
+ TRADER_REF: 8,
15
+ EXTRA_RESERVED: 32,
16
+ PAYOUT: 64,
17
+ TEAM_BUY: 128,
18
+ SHARE_BOUGHT: 256,
19
+ HOLDER: 512,
20
+ } ;
21
+ export const TON_CLAIM_KNOWN = 975;
22
+
23
+ export const TON_WALK_STEPS = 16;
24
+
25
+  
26
+
27
+ export const REFERRED_HOP = 60_000_000n;
28
+
29
+ export const REFERRED_FWD_MIN = 240_000_000n;
30
+
31
+ export const REFERRED_SELL_FWD_MIN = 240_000_000n;
32
+
33
+ export const REFERRED_GIFT_FWD_MIN = REFERRED_FWD_MIN + REFERRED_HOP;
34
+
35
+ export const REFERRED_FWD_DEFAULT = DEFAULT_GAS.buyFwdMin + REFERRED_HOP;
36
+ export const REFERRED_SELL_FWD_DEFAULT = DEFAULT_GAS.sellFwdMin + REFERRED_HOP;
37
+ export const REFERRED_GIFT_FWD_DEFAULT = REFERRED_FWD_DEFAULT + REFERRED_HOP;
38
+ export const REFERRED_SELL_GIFT_FWD_DEFAULT = REFERRED_SELL_FWD_DEFAULT + REFERRED_HOP;
39
+
40
+  
41
+
42
+      
43
+
@@ -0,0 +1,26 @@
1
+
2
+
3
+ import { base64Of, stateInitCell, toBoc } from "./cell.js";
4
+
5
+ const VALID_FOR_DEFAULT = 300;
6
+ const VALID_FOR_MAX = 600;
7
+ const MAX_MESSAGES_DEFAULT = 4;
8
+
9
+ export function tonConnectRequest(tx , o ) {
10
+ const max = o.maxMessages ?? MAX_MESSAGES_DEFAULT;
11
+ const n = tx.messages.length;
12
+ if (n < 1 || n > max) throw new RangeError(`a request carries 1 to ${max} messages, got ${n}`);
13
+ const validFor = o.validForS ?? VALID_FOR_DEFAULT;
14
+ if (!Number.isInteger(validFor) || validFor < 1 || validFor > VALID_FOR_MAX) throw new RangeError("validForS must be 1 to 600");
15
+ if (!Number.isInteger(o.nowS) || o.nowS < 0) throw new RangeError("nowS must be a non-negative integer (seconds)");
16
+ const messages = tx.messages.map((m) => {
17
+ const out = {
18
+ address: m.to.toString({ bounceable: m.bounce, urlSafe: true }),
19
+ amount: m.value.toString(),
20
+ payload: base64Of(toBoc(m.body)),
21
+ };
22
+ if (m.stateInit) out.stateInit = base64Of(toBoc(stateInitCell(m.stateInit.code, m.stateInit.data)));
23
+ return out;
24
+ });
25
+ return { validUntil: o.nowS + validFor, messages };
26
+ }
package/dist/v2/devbuy.js CHANGED
@@ -18,18 +18,20 @@ export function teamSlotWallets(slot ) {
18
18
 
19
19
  export const impactBps = (before , after ) => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
20
20
 
21
- export function devBuyFromTrade(t , team , ctx = {}) {
21
+ export function devBuyFromTrade(t , team , ctx = {}) {
22
22
  if (!t.isBuy) return null;
23
+
24
+ const person = ctx.buyer ?? t.trader;
23
25
  let role = null;
24
26
  if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
25
27
  else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
26
- else if (t.trader === team.creator) role = "creator";
27
- else if (teamSlotWallets(team.teamSlot).includes(t.trader)) role = "team_member";
28
+ else if (person === team.creator) role = "creator";
29
+ else if (teamSlotWallets(team.teamSlot).includes(person)) role = "team_member";
28
30
  if (role === null) return null;
29
31
  const priceBeforeX64 = priceX64(t.sqrtBefore);
30
32
  const priceAfterX64 = priceX64(t.sqrtAfter);
31
33
  return {
32
- launch: t.launch, trader: t.trader, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
34
+ launch: t.launch, trader: person, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
33
35
  impactBps: impactBps(priceBeforeX64, priceAfterX64), slot: t.slot,
34
36
  };
35
37
  }
package/dist/v2/evm.js CHANGED
@@ -20,7 +20,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
20
20
 
21
21
  const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
22
22
 
23
- const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5])`;
23
+ const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5],uint128,uint64,bool)`;
24
24
 
25
25
  const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
26
26
 
@@ -129,6 +129,7 @@ export function decodeLaunchBook(data ) {
129
129
  sqrtP: big(t[0]), sqrtF: big(t[1]), f: big(t[2]), bandMoney: bigs(t[3]), nRanges: nR, ranges,
130
130
  sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
131
131
  bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] , feePpm: nums(t[17]),
132
+ kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] ,
132
133
  };
133
134
  }
134
135
  export function decodeSimBuy(data ) {
@@ -253,6 +254,7 @@ export function evmSettleInputsV2(b , row , sup , m
253
254
  bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
254
255
  bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
255
256
  bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
257
+ kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
256
258
  feePpm: [...b.feePpm], graduated: b.graduated,
257
259
 
258
260
  feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
@@ -130,7 +130,11 @@ export const LAUNCH_V2 = [
130
130
  ["backing_credited", "u64"],
131
131
  ["incinerated", "u64"],
132
132
  ["last_ts", "i64"],
133
- ["book_hash", "bytes:32"],
133
+
134
+ ["k_at_f", "u64"],
135
+ ["k_floor_tokens", "u64"],
136
+ ["kpot", "u8"],
137
+ ["pad_end", "bytes:15"],
134
138
  ];
135
139
 
136
140
  export const HOLDER_POSITION = [
@@ -5,6 +5,7 @@ import { bytesToHex, decodeAbi, encodeCall, hexToBytes } from "../evm/abi.js";
5
5
  import { ROW_LEN, decodeRowV2 } from "../math/v2/preset.js";
6
6
 
7
7
  import { evmSignature } from "../generated/index.js";
8
+ import { MULTICALL3_ADDRESS, aggregate3Call, decodeAggregate3Result } from "../evm/multicall.js";
8
9
 
9
10
  export const PRESET_ROW_VIEW_EVM = { sig: evmSignature("presetRow"), ret: ["(uint8,bool,bool,uint32,bytes32,bytes)"] } ;
10
11
  export const NEXT_PRESET_ID_VIEW_EVM = { sig: evmSignature("nextPresetId"), ret: ["uint8"] } ;
@@ -37,9 +38,27 @@ export function presetMenuV2(rows )
37
38
  .map((r) => ({ id: r.id, version: r.version, rowHash: bytesToHex(r.rowHash), row: decodeRowV2(r.row) }));
38
39
  }
39
40
 
40
- export async function readPresetMenuEvmV2(rpc , amm ) {
41
+ const PRESET_MENU_BATCH = 100;
42
+
43
+ export async function readPresetMenuEvmV2(
44
+ rpc , amm , opts = {},
45
+ ) {
41
46
  const next = decodeNextPresetIdEvmV2(await rpc.ethCall(amm, nextPresetIdCallV2()));
42
47
  const ids = Array.from({ length: Math.max(0, next - 1) }, (_, i) => i + 1).filter((id) => id !== RETIRED_ID);
43
- const rows = await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id)))));
48
+ if (opts.multicall === null) {
49
+ return presetMenuV2(await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id))))));
50
+ }
51
+ const multicall = opts.multicall ?? MULTICALL3_ADDRESS;
52
+ const chunks = [];
53
+ for (let i = 0; i < ids.length; i += PRESET_MENU_BATCH) chunks.push(ids.slice(i, i + PRESET_MENU_BATCH));
54
+ const rows = (await Promise.all(chunks.map(async (chunk) => {
55
+ const call = aggregate3Call(chunk.map((id) => ({ target: amm, allowFailure: true, callData: presetRowCallV2(id) })), multicall);
56
+ const res = decodeAggregate3Result(await rpc.ethCall(call.to, call.data));
57
+ if (res.length !== chunk.length) throw new RangeError(`aggregate3: ${res.length} results, ${chunk.length} calls`);
58
+ return res.map((r, i) => {
59
+ if (!r.success) throw new Error(`presetRow(${chunk[i]}) failed: ${r.returnData}`);
60
+ return decodePresetRowEvmV2(r.returnData);
61
+ });
62
+ }))).flat();
44
63
  return presetMenuV2(rows);
45
64
  }
package/dist/v2/router.js CHANGED
@@ -8,9 +8,9 @@ export function carriesNoRefund(gross , refund , budgetHit
8
8
  return refund === 0n || isDustRefund(gross, refund, budgetHit);
9
9
  }
10
10
 
11
- export const GAS_FLAT = { buy: 700_000, sell: 750_000 } ;
11
+ export const GAS_FLAT = { buy: 1_100_000, sell: 850_000 } ;
12
12
 
13
- export const GAS_PER_STEP = { buy: 40_000, sell: 40_000 } ;
13
+ export const GAS_PER_STEP = { buy: 45_000, sell: 40_000 } ;
14
14
 
15
15
  export const GAS_FLAT_STEPS = 4;
16
16
 
@@ -52,6 +52,8 @@ export function solanaSettleInputsV2(l , opts
52
52
  nBands: l.nBands,
53
53
  bandEdge: [...l.bandEdge], bandMoney: [...l.bandMoney], bandTokens: [...l.bandTokens],
54
54
  nC: l.nC, bandF: [...l.bandF], bandFClaim: [...l.bandFClaim], ckAtF: l.ckAtF, ckFloorTokens: l.ckFloorTokens,
55
+
56
+ kpot: l.kpot !== 0, kAtF: l.kAtF, kFloorTokens: l.kFloorTokens,
55
57
  feePpm: l.feePpm.map(n), feeStartPpm: l.feeStartPpm.map(n), sqrtFeeA: l.sqrtFeeA, sqrtFeeB: l.sqrtFeeB,
56
58
  graduated: l.graduated !== 0, nRanges: l.nRanges, ranges,
57
59