@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
package/src/v2/evm.ts CHANGED
@@ -22,7 +22,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
22
22
 
23
23
  const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
24
24
 
25
- const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5])`;
25
+ 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)`;
26
26
 
27
27
  const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
28
28
 
@@ -128,6 +128,8 @@ export interface LaunchBookV2 {
128
128
  bandF: bigint[]; bandFClaim: bigint[];
129
129
 
130
130
  ckAtF: bigint; ckFloorTokens: bigint;
131
+
132
+ kpot: boolean; kAtF: bigint; kFloorTokens: bigint;
131
133
  graduated: boolean;
132
134
 
133
135
  feePpm: number[];
@@ -155,6 +157,7 @@ export function decodeLaunchBook(data: string | Uint8Array): LaunchBookV2 {
155
157
  sqrtP: big(t[0]), sqrtF: big(t[1]), f: big(t[2]), bandMoney: bigs(t[3]), nRanges: nR, ranges,
156
158
  sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
157
159
  bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] as boolean, feePpm: nums(t[17]),
160
+ kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] as boolean,
158
161
  };
159
162
  }
160
163
  export function decodeSimBuy(data: string | Uint8Array): SimBuyV2 {
@@ -294,6 +297,7 @@ export function evmSettleInputsV2(b: LaunchBookV2, row: SplitRow, sup: Supply, m
294
297
  bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
295
298
  bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
296
299
  bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
300
+ kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
297
301
  feePpm: [...b.feePpm], graduated: b.graduated,
298
302
 
299
303
  feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
package/src/v2/layouts.ts CHANGED
@@ -131,7 +131,11 @@ export const LAUNCH_V2: Layout = [
131
131
  ["backing_credited", "u64"],
132
132
  ["incinerated", "u64"],
133
133
  ["last_ts", "i64"],
134
- ["book_hash", "bytes:32"],
134
+
135
+ ["k_at_f", "u64"],
136
+ ["k_floor_tokens", "u64"],
137
+ ["kpot", "u8"],
138
+ ["pad_end", "bytes:15"],
135
139
  ];
136
140
 
137
141
  export const HOLDER_POSITION: Layout = [
@@ -6,6 +6,7 @@ import { ROW_LEN, decodeRowV2 } from "../math/v2/preset.ts";
6
6
  import type { RowV2 } from "../math/v2/preset.ts";
7
7
  import type { PresetRowV2Account } from "./types.ts";
8
8
  import { evmSignature } from "../generated/index.ts";
9
+ import { MULTICALL3_ADDRESS, aggregate3Call, decodeAggregate3Result } from "../evm/multicall.ts";
9
10
 
10
11
  export const PRESET_ROW_VIEW_EVM = { sig: evmSignature("presetRow"), ret: ["(uint8,bool,bool,uint32,bytes32,bytes)"] } as const;
11
12
  export const NEXT_PRESET_ID_VIEW_EVM = { sig: evmSignature("nextPresetId"), ret: ["uint8"] } as const;
@@ -46,9 +47,27 @@ export function presetMenuV2(rows: readonly (PresetRowV2Account | null)[]): Pres
46
47
  .map((r) => ({ id: r.id, version: r.version, rowHash: bytesToHex(r.rowHash), row: decodeRowV2(r.row) }));
47
48
  }
48
49
 
49
- export async function readPresetMenuEvmV2(rpc: { ethCall: (to: string, data: string) => Promise<string> }, amm: string): Promise<PresetMenuItemV2[]> {
50
+ const PRESET_MENU_BATCH = 100;
51
+
52
+ export async function readPresetMenuEvmV2(
53
+ rpc: { ethCall: (to: string, data: string) => Promise<string> }, amm: string, opts: { multicall?: string | null } = {},
54
+ ): Promise<PresetMenuItemV2[]> {
50
55
  const next = decodeNextPresetIdEvmV2(await rpc.ethCall(amm, nextPresetIdCallV2()));
51
56
  const ids = Array.from({ length: Math.max(0, next - 1) }, (_, i) => i + 1).filter((id) => id !== RETIRED_ID);
52
- const rows = await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id)))));
57
+ if (opts.multicall === null) {
58
+ return presetMenuV2(await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id))))));
59
+ }
60
+ const multicall = opts.multicall ?? MULTICALL3_ADDRESS;
61
+ const chunks: number[][] = [];
62
+ for (let i = 0; i < ids.length; i += PRESET_MENU_BATCH) chunks.push(ids.slice(i, i + PRESET_MENU_BATCH));
63
+ const rows = (await Promise.all(chunks.map(async (chunk) => {
64
+ const call = aggregate3Call(chunk.map((id) => ({ target: amm, allowFailure: true, callData: presetRowCallV2(id) })), multicall);
65
+ const res = decodeAggregate3Result(await rpc.ethCall(call.to, call.data));
66
+ if (res.length !== chunk.length) throw new RangeError(`aggregate3: ${res.length} results, ${chunk.length} calls`);
67
+ return res.map((r, i) => {
68
+ if (!r.success) throw new Error(`presetRow(${chunk[i]}) failed: ${r.returnData}`);
69
+ return decodePresetRowEvmV2(r.returnData);
70
+ });
71
+ }))).flat();
53
72
  return presetMenuV2(rows);
54
73
  }
package/src/v2/router.ts CHANGED
@@ -8,9 +8,9 @@ export function carriesNoRefund(gross: bigint, refund: bigint, budgetHit: boolea
8
8
  return refund === 0n || isDustRefund(gross, refund, budgetHit);
9
9
  }
10
10
 
11
- export const GAS_FLAT = { buy: 700_000, sell: 750_000 } as const;
11
+ export const GAS_FLAT = { buy: 1_100_000, sell: 850_000 } as const;
12
12
 
13
- export const GAS_PER_STEP = { buy: 40_000, sell: 40_000 } as const;
13
+ export const GAS_PER_STEP = { buy: 45_000, sell: 40_000 } as const;
14
14
 
15
15
  export const GAS_FLAT_STEPS = 4;
16
16
 
@@ -72,6 +72,8 @@ export function solanaSettleInputsV2(l: LaunchV2Account, opts: { mintSupply?: bi
72
72
  nBands: l.nBands,
73
73
  bandEdge: [...l.bandEdge], bandMoney: [...l.bandMoney], bandTokens: [...l.bandTokens],
74
74
  nC: l.nC, bandF: [...l.bandF], bandFClaim: [...l.bandFClaim], ckAtF: l.ckAtF, ckFloorTokens: l.ckFloorTokens,
75
+
76
+ kpot: l.kpot !== 0, kAtF: l.kAtF, kFloorTokens: l.kFloorTokens,
75
77
  feePpm: l.feePpm.map(n), feeStartPpm: l.feeStartPpm.map(n), sqrtFeeA: l.sqrtFeeA, sqrtFeeB: l.sqrtFeeB,
76
78
  graduated: l.graduated !== 0, nRanges: l.nRanges, ranges,
77
79
 
package/src/v2/types.ts CHANGED
@@ -115,7 +115,10 @@ export interface LaunchV2Account {
115
115
  backingCredited: bigint;
116
116
  incinerated: bigint;
117
117
  lastTs: bigint;
118
- bookHash: Uint8Array;
118
+ kAtF: bigint;
119
+ kFloorTokens: bigint;
120
+ kpot: number;
121
+ padEnd: Uint8Array;
119
122
  }
120
123
 
121
124
  export interface HolderPositionAccount {