@floorlaunchpad/sdk 0.7.0 → 0.8.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/README.md +12 -1
  3. package/dist/abi/evm.gen.js +75 -2
  4. package/dist/abi/functions.gen.js +87 -1
  5. package/dist/abi/solana.gen.js +59 -0
  6. package/dist/client/solana/index.js +25 -6
  7. package/dist/config/generated.js +803 -26374
  8. package/dist/errors.js +20 -1
  9. package/dist/events/types.gen.js +1 -1
  10. package/dist/evm/chains.js +49 -0
  11. package/dist/evm/floor/abi.gen.js +115 -0
  12. package/dist/evm/squid.js +21 -5
  13. package/dist/evm/venues.js +302 -0
  14. package/dist/generated/interface.gen.js +45 -1
  15. package/dist/index.js +7 -0
  16. package/dist/indexer/bodies.js +154 -2
  17. package/dist/indexer/client.js +8 -1
  18. package/dist/indexer/contract.js +78 -11
  19. package/dist/indexer/paths.js +46 -0
  20. package/dist/indexer/read.js +14 -1
  21. package/dist/math/v2/book.js +24 -7
  22. package/dist/math/v2/create.js +1 -1
  23. package/dist/math/v2/escrow.js +205 -0
  24. package/dist/math/v2/office.js +110 -0
  25. package/dist/math/v2/relay.js +263 -96
  26. package/dist/math/v2/team.js +28 -0
  27. package/dist/math/v2/trade.js +3 -1
  28. package/dist/reprice.js +88 -0
  29. package/dist/route/quote.js +16 -0
  30. package/dist/scaledUi.js +113 -0
  31. package/dist/solana/floor/accounts.js +8 -2
  32. package/dist/solana/floor/events.js +56 -1
  33. package/dist/solana/floor/instructions.js +16 -0
  34. package/dist/stockRefresh.js +99 -0
  35. package/dist/ton/consts.generated.js +2 -2
  36. package/dist/ton/gas.js +3 -3
  37. package/dist/v2/claims.js +28 -5
  38. package/dist/v2/devbuy.js +28 -3
  39. package/dist/v2/evm.js +178 -5
  40. package/dist/v2/layouts.js +100 -2
  41. package/dist/v2/office-events.js +127 -0
  42. package/dist/v2/office-evm.js +68 -0
  43. package/dist/v2/office-read.js +182 -0
  44. package/dist/v2/office-solana.js +134 -0
  45. package/dist/v2/office-trade.js +73 -0
  46. package/dist/v2/route-alt.js +1 -0
  47. package/dist/v2/route.js +1 -1
  48. package/dist/v2/solana.js +224 -5
  49. package/dist/v2/solanaSettle.js +2 -0
  50. package/dist/v2/tx/evm.js +51 -1
  51. package/dist/v2/tx/solana.js +3 -3
  52. package/dist/v2/types.js +4 -0
  53. package/docs/aggregator.md +19 -0
  54. package/examples/floor-line.html +1 -1
  55. package/package.json +26 -1
  56. package/src/abi/evm.gen.ts +75 -2
  57. package/src/abi/functions.gen.ts +87 -1
  58. package/src/abi/solana.gen.ts +59 -0
  59. package/src/client/solana/index.ts +25 -6
  60. package/src/config/generated.ts +803 -26374
  61. package/src/errors.ts +20 -1
  62. package/src/events/types.gen.ts +402 -1
  63. package/src/evm/chains.ts +58 -0
  64. package/src/evm/floor/abi.gen.ts +115 -0
  65. package/src/evm/squid.ts +22 -6
  66. package/src/evm/venues.ts +340 -0
  67. package/src/generated/interface.gen.ts +45 -1
  68. package/src/index.ts +7 -0
  69. package/src/indexer/bodies.ts +167 -2
  70. package/src/indexer/client.ts +16 -2
  71. package/src/indexer/contract.ts +84 -12
  72. package/src/indexer/paths.ts +77 -0
  73. package/src/indexer/read.ts +16 -3
  74. package/src/math/v2/book.ts +23 -7
  75. package/src/math/v2/create.ts +1 -1
  76. package/src/math/v2/escrow.ts +213 -0
  77. package/src/math/v2/office.ts +114 -0
  78. package/src/math/v2/relay.ts +269 -96
  79. package/src/math/v2/team.ts +28 -0
  80. package/src/math/v2/trade.ts +3 -1
  81. package/src/reprice.ts +121 -0
  82. package/src/route/quote.ts +16 -0
  83. package/src/scaledUi.ts +123 -0
  84. package/src/solana/floor/accounts.ts +8 -2
  85. package/src/solana/floor/events.ts +57 -2
  86. package/src/solana/floor/instructions.ts +16 -0
  87. package/src/stockRefresh.ts +131 -0
  88. package/src/ton/consts.generated.ts +2 -2
  89. package/src/ton/gas.ts +3 -3
  90. package/src/v2/claims.ts +34 -5
  91. package/src/v2/devbuy.ts +38 -3
  92. package/src/v2/evm.ts +204 -5
  93. package/src/v2/layouts.ts +100 -2
  94. package/src/v2/office-events.ts +133 -0
  95. package/src/v2/office-evm.ts +76 -0
  96. package/src/v2/office-read.ts +264 -0
  97. package/src/v2/office-solana.ts +159 -0
  98. package/src/v2/office-trade.ts +96 -0
  99. package/src/v2/route-alt.ts +1 -0
  100. package/src/v2/route.ts +1 -1
  101. package/src/v2/solana.ts +235 -5
  102. package/src/v2/solanaSettle.ts +2 -0
  103. package/src/v2/tx/evm.ts +51 -1
  104. package/src/v2/tx/solana.ts +5 -3
  105. package/src/v2/types.ts +66 -1
package/dist/v2/evm.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.js";
3
+ import { checksumAddress, decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.js";
4
4
  import { keccak256 } from "../evm/keccak.js";
5
5
 
6
6
  import { claimCall } from "../evm/floor/calls.js";
@@ -11,6 +11,8 @@ import { buy } from "../math/v2/trade.js";
11
11
 
12
12
  import { evmSignature } from "../generated/index.js";
13
13
  import { CLAIM_BITS, CLAIM_KNOWN_MASKS } from "../generated/index.js";
14
+ import { slotMemberKeyEvm } from "./tx/evm.js";
15
+
14
16
  import { EVM_EVENT_SCHEMAS } from "../abi/evm.gen.js";
15
17
  import { V2_EVENT_FIELD_NAMES } from "../abi/evm-event-names.js";
16
18
 
@@ -20,7 +22,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
20
22
 
21
23
  const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
22
24
 
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)`;
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,uint32)`;
24
26
 
25
27
  const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
26
28
 
@@ -64,6 +66,8 @@ export const V2_TOKEN_VIEWS = {
64
66
 
65
67
  export const V2_CALLS = {
66
68
  creditBacking: evmSignature("creditBacking"),
69
+
70
+ creditPlatform: evmSignature("creditPlatform"),
67
71
  } ;
68
72
 
69
73
  export const V2_TOKEN_CALLS = {
@@ -90,6 +94,17 @@ export function creditBackingCall(amm , launchId , quote ,
90
94
  return call(amm, V2_CALLS.creditBacking, [launchId, amount], quote.toLowerCase() === NATIVE ? amount : 0n);
91
95
  }
92
96
 
97
+ export function creditPlatformCall(amm , launchId , quote , amount , memo = new Uint8Array(32)) {
98
+ if (amount <= 0n) throw new RangeError("creditPlatform: amount must be > 0 (NothingToDo)");
99
+ if (memo.length !== 32) throw new RangeError("creditPlatform: the memo is 32 bytes");
100
+ return call(amm, V2_CALLS.creditPlatform, [launchId, amount, memo], quote.toLowerCase() === NATIVE ? amount : 0n);
101
+ }
102
+
103
+ export function setDealFeeCapCall(amm , capBps ) {
104
+ if (!Number.isInteger(capBps) || capBps < 0 || capBps > 5000) throw new RangeError("setDealFeeCap: capBps in 0..=5000");
105
+ return call(amm, evmSignature("setDealFeeCap"), [BigInt(capBps)]);
106
+ }
107
+
93
108
  export function claimV2Call(p ) {
94
109
  if (!Number.isInteger(p.types) || p.types <= 0 || (p.types & ~CLAIM_KNOWN_V2_EVM) !== 0) throw new RangeError("UnknownClaimType: the v2 claim takes bits 1, 2, 4, 8, 64, 128, 256, 512 (16 and 32 are reserved)");
95
110
  if ((p.types & CLAIM_HOLDER_EVM) === 0) return claimCall(p);
@@ -119,7 +134,14 @@ function one(name , data )
119
134
  }
120
135
 
121
136
  export function decodeLaunchBook(data ) {
122
- const [t] = one("launchBook", data) ;
137
+
138
+ const [t] = (() => {
139
+ try {
140
+ return one("launchBook", data) ;
141
+ } catch {
142
+ return decodeAbi([LAUNCH_BOOK.replace(/,uint32\)$/, ")")], data) ;
143
+ }
144
+ })();
123
145
  const nR = n(t[4]);
124
146
  const ranges = (t[5] ).slice(0, nR).map((r) => ({
125
147
  sqrtA: big(r[0]), sqrtB: big(r[1]), tokens: big(r[2]), askLeft: big(r[3]), back: big(r[4]), place: big(r[5]),
@@ -130,6 +152,7 @@ export function decodeLaunchBook(data ) {
130
152
  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
153
  bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] , feePpm: nums(t[17]),
132
154
  kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] ,
155
+ ...(t.length > 21 && n(t[21]) !== 0 && { kKept: n(t[21]) }),
133
156
  };
134
157
  }
135
158
  export function decodeSimBuy(data ) {
@@ -193,11 +216,16 @@ export const V2_EVENTS = Object.fromEntries(
193
216
 
194
217
  export const V2_EVENTS_ELSEWHERE = [
195
218
  "Initialized", "LaunchCreated", "PayoutOwed", "TeamSlotOpened", "Upgraded", "Approval", "Transfer", "EIP712DomainChanged", "Claimed", "ClaimSkipped",
196
- "HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
219
+ "HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "BookRelayed" , "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
197
220
  "TeamSlotMember",
221
+ "DealFeePaid", "PlatformCredited", "TeamSlotDealFee",
222
+ "DealEscrowOpened", "DealEscrowArmed", "DealEscrowReleased", "DealEscrowRefunded", "DealEscrowCancelAgreed", "DealEscrowCancelled",
223
+ "DealEscrowTermsV3", "DealEscrowSplit", "DealEscrowProofSubmitted", "DealEscrowProofObjected",
224
+ "TeamSlotAgency", "TeamSlotAgencyPaid",
198
225
 
199
226
  "ConfigWritten", "HandleBound", "HandleOwedMoved", "MetadataBaseSet", "NativeCreateFeeSet", "PriceUpdaterSet", "QuoteCapSet",
200
227
  "QuoteWritten", "TraderRefCleared", "TraderRefOpened", "TreasurySet",
228
+ "DealFeeCapSet",
201
229
  ] ;
202
230
 
203
231
  let topics ;
@@ -259,7 +287,7 @@ export function evmSettleInputsV2(b , row , sup , m
259
287
  bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
260
288
  bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
261
289
  bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
262
- kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
290
+ kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens, ...(b.kKept ? { kKept: b.kKept } : {}),
263
291
  feePpm: [...b.feePpm], graduated: b.graduated,
264
292
 
265
293
  feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
@@ -304,3 +332,148 @@ export async function readHolderV2(
304
332
  const standing = holderStandingV2({ address: p.address, code, optedIn: decodeOptedIn(opted), program: p.program });
305
333
  return { amount: x.amount, owed: x.owed, indexSnap: x.indexSnap, standing, optIn: standing.weight === "contract-not-opted-in" ? optInCall(p.token) : null };
306
334
  }
335
+
336
+ export const DEAL_V3_STEP = { mcap: 0, volume: 1, upfront: 2 } ;
337
+
338
+ export const DEAL_V3_PROOF = { none: 0, waiting: 1, submitted: 2, objected: 3, resubmitted: 4 } ;
339
+ export const DEAL_AGENCY_BPS_MAX = 3_000;
340
+ export const DEAL_PROOF_WINDOW_SECS = 86_400n;
341
+
342
+ const DEAL_TERMS_V3 = "(uint8[],uint256[],uint256[],uint8,address,uint16,int64)";
343
+ export const DEAL_V3_CALLS = {
344
+ dealEscrowOpenV3: `dealEscrowOpenV3(uint256,address,bytes32,bool,${DEAL_TERMS_V3})`,
345
+ dealEscrowArmV3: "dealEscrowArmV3(bytes32,uint8)",
346
+ dealEscrowReleaseV3: "dealEscrowReleaseV3(bytes32,uint8)",
347
+ dealEscrowSubmitProof: "dealEscrowSubmitProof(bytes32,uint8,bytes32)",
348
+ dealEscrowObject: "dealEscrowObject(bytes32,uint8)",
349
+ teamSlotAddDealV3: "teamSlotAddDealV3(uint256,bytes32,uint8,uint256,uint16,address,uint16)",
350
+ } ;
351
+ export const DEAL_V3_VIEWS = {
352
+ refVolume: { sig: "refVolume(uint256,address)", ret: ["uint256"] },
353
+ teamSlotAgencyOf: { sig: "teamSlotAgencyOf(uint256,uint8)", ret: ["address", "uint16"] },
354
+ dealEscrowV3Of: {
355
+ sig: "dealEscrowV3Of(bytes32)",
356
+ ret: ["(uint8,uint8[8],uint8[8],int64[8],bytes32[8],address,uint16,uint256,uint256)"],
357
+ },
358
+ } ;
359
+
360
+ const stepOk = (name , step ) => {
361
+ if (!Number.isInteger(step) || step < 0 || step > 7) throw new RangeError(`${name}: step in 0..8 (DealEscrowSteps)`);
362
+ return BigInt(step);
363
+ };
364
+
365
+ export function dealEscrowOpenV3Call(p ) {
366
+ const t = p.terms;
367
+ const n = t.kinds.length;
368
+ if (n < 1 || n > 8 || t.targets.length !== n || t.amounts.length !== n) throw new RangeError("dealEscrowOpenV3: 1..=8 steps, one target and amount each (DealEscrowSteps)");
369
+ if (!Number.isInteger(t.proofMask) || t.proofMask < 0 || t.proofMask >> n !== 0) throw new RangeError("dealEscrowOpenV3: proofMask bits only below n (DealEscrowSteps)");
370
+ if (t.kinds.some((k) => k !== 0 && k !== 1 && k !== 2)) throw new RangeError("dealEscrowOpenV3: kinds are 0 (market cap), 1 (volume), 2 (up front)");
371
+ const hasAgency = t.agency.toLowerCase() !== NATIVE;
372
+ if (hasAgency !== (t.agencyBps !== 0) || t.agencyBps < 0 || t.agencyBps > DEAL_AGENCY_BPS_MAX) throw new RangeError("dealEscrowOpenV3: an agency needs 1..=3000 bps, none needs 0 (DealEscrowAgency)");
373
+ if (p.ref32.length !== 32) throw new RangeError("dealEscrowOpenV3: ref32 is 32 bytes");
374
+ const total = t.amounts.reduce((a, b) => a + b, 0n);
375
+ const value = !p.assetIsToken && p.quote.toLowerCase() === NATIVE ? total : 0n;
376
+ const terms = [t.kinds.map(BigInt), [...t.targets], [...t.amounts], BigInt(t.proofMask), t.agency, BigInt(t.agencyBps), t.expiry];
377
+ return call(p.floorAmm, DEAL_V3_CALLS.dealEscrowOpenV3, [p.launchId, p.kol, p.ref32, p.assetIsToken, terms], value);
378
+ }
379
+
380
+ export const dealEscrowArmV3Call = (floorAmm , escrow , step ) =>
381
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowArmV3, [hexToBytes(escrow), stepOk("dealEscrowArmV3", step)]);
382
+
383
+ export const dealEscrowReleaseV3Call = (floorAmm , escrow , step ) =>
384
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowReleaseV3, [hexToBytes(escrow), stepOk("dealEscrowReleaseV3", step)]);
385
+
386
+ export function dealEscrowSubmitProofCall(floorAmm , escrow , step , proofHash ) {
387
+ if (proofHash.length !== 32) throw new RangeError("dealEscrowSubmitProof: the hash is 32 bytes");
388
+ return call(floorAmm, DEAL_V3_CALLS.dealEscrowSubmitProof, [hexToBytes(escrow), stepOk("dealEscrowSubmitProof", step), proofHash]);
389
+ }
390
+
391
+ export const dealEscrowObjectCall = (floorAmm , escrow , step ) =>
392
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowObject, [hexToBytes(escrow), stepOk("dealEscrowObject", step)]);
393
+
394
+ export function teamSlotAddDealV3Call(p ) {
395
+ if (p.shares <= 0n) throw new RangeError("teamSlotAddDealV3: shares > 0 (NothingToDo)");
396
+ if (!Number.isInteger(p.dealFeeBps) || p.dealFeeBps < 0 || p.dealFeeBps > 0xffff) throw new RangeError("teamSlotAddDealV3: dealFeeBps is a uint16");
397
+ const hasAgency = p.agency.toLowerCase() !== NATIVE;
398
+ if (!Number.isInteger(p.agencyBps) || hasAgency !== (p.agencyBps !== 0) || p.agencyBps < 0 || p.agencyBps > DEAL_AGENCY_BPS_MAX) {
399
+ throw new RangeError("teamSlotAddDealV3: an agency needs 1..=3000 bps, none needs 0 (DealEscrowAgency)");
400
+ }
401
+ const { key, kind } = slotMemberKeyEvm(p.member);
402
+ return call(p.floorAmm, DEAL_V3_CALLS.teamSlotAddDealV3, [p.launchId, hexToBytes(key), BigInt(kind), p.shares, BigInt(p.dealFeeBps), p.agency, BigInt(p.agencyBps)]);
403
+ }
404
+
405
+ export const teamSlotAgencyOfData = (launchId , place ) => {
406
+ if (!Number.isInteger(place) || place < 0 || place > 9) throw new RangeError("teamSlotAgencyOf: place in 0..10 (BadArgument)");
407
+ return bytesToHex(encodeCall(DEAL_V3_VIEWS.teamSlotAgencyOf.sig, [launchId, BigInt(place)]));
408
+ };
409
+ export function decodeTeamSlotAgencyOf(data ) {
410
+ const [a, bps] = decodeAbi(DEAL_V3_VIEWS.teamSlotAgencyOf.ret, data) ;
411
+ return a.toLowerCase() === NATIVE && bps === 0n ? null : { agency: checksumAddress(a), agencyBps: Number(bps) };
412
+ }
413
+
414
+ export const refVolumeData = (launchId , referrer ) => bytesToHex(encodeCall(DEAL_V3_VIEWS.refVolume.sig, [launchId, referrer]));
415
+ export const dealEscrowV3OfData = (escrow ) => bytesToHex(encodeCall(DEAL_V3_VIEWS.dealEscrowV3Of.sig, [hexToBytes(escrow)]));
416
+ export const decodeRefVolume = (data ) => decodeAbi(DEAL_V3_VIEWS.refVolume.ret, data)[0] ;
417
+
418
+ export function decodeDealEscrowV3Of(data ) {
419
+ const v = decodeAbi(DEAL_V3_VIEWS.dealEscrowV3Of.ret, data)[0] ;
420
+ const nums = (x ) => (x ).map(Number);
421
+ return {
422
+ version: Number(v[0]),
423
+ kinds: nums(v[1]),
424
+ proof: nums(v[2]),
425
+ proofEnds: v[3] ,
426
+ proofHash: (v[4] ).map((b) => (typeof b === "string" ? b : bytesToHex(b))),
427
+ agency: checksumAddress(v[5] ),
428
+ agencyBps: Number(v[6]),
429
+ volAtLock: v[7] ,
430
+ volumeNow: v[8] ,
431
+ };
432
+ }
433
+
434
+ export const DEAL_V3_EVENTS = {
435
+ DealEscrowTermsV3: {
436
+ sig: "DealEscrowTermsV3(uint256,bytes32,bytes32,uint8[],uint8,address,uint16,uint256)",
437
+ indexed: ["launchId", "escrow"],
438
+ names: ["launchId", "escrow", "ref32", "kinds", "proofMask", "agency", "agencyBps", "volAtLock"],
439
+ },
440
+ DealEscrowSplit: {
441
+ sig: "DealEscrowSplit(uint256,bytes32,bytes32,uint8,uint8,address,uint256,address,uint256,address[3],uint256[3],uint256)",
442
+ indexed: ["launchId", "escrow", "kol"],
443
+ names: ["launchId", "escrow", "ref32", "step", "kind", "kol", "kolPart", "agency", "agencyPart", "tiers", "refs", "feeRest"],
444
+ },
445
+ DealEscrowProofSubmitted: {
446
+ sig: "DealEscrowProofSubmitted(uint256,bytes32,bytes32,uint8,bytes32,uint8,int64)",
447
+ indexed: ["launchId", "escrow"],
448
+ names: ["launchId", "escrow", "ref32", "step", "proofHash", "state", "windowEnds"],
449
+ },
450
+ DealEscrowProofObjected: {
451
+ sig: "DealEscrowProofObjected(uint256,bytes32,bytes32,uint8)",
452
+ indexed: ["launchId", "escrow"],
453
+ names: ["launchId", "escrow", "ref32", "step"],
454
+ },
455
+ } ;
456
+
457
+ let dealTopics ;
458
+ const DEAL_TOPICS = () =>
459
+ (dealTopics ??= new Map((Object.keys(DEAL_V3_EVENTS) ).map((k) => [eventTopic(DEAL_V3_EVENTS[k].sig), k])));
460
+ export const dealV3EventTopic = (name ) => eventTopic(DEAL_V3_EVENTS[name].sig);
461
+
462
+ export function decodeDealV3Log(log ) {
463
+ const name = DEAL_TOPICS().get((log.topics[0] ?? "").toLowerCase());
464
+ if (!name) return null;
465
+ const ev = DEAL_V3_EVENTS[name];
466
+ const types = ev.sig.slice(ev.sig.indexOf("(") + 1, -1).split(",");
467
+ const idx = new Set (ev.indexed);
468
+ if (log.topics.length !== 1 + idx.size) throw new RangeError(`${name}: ${log.topics.length - 1} indexed topics, want ${idx.size}`);
469
+ const fields = {};
470
+ let t = 1;
471
+ const bodyTypes = [];
472
+ const bodyNames = [];
473
+ ev.names.forEach((n, i) => {
474
+ if (idx.has(n)) fields[n] = decodeAbi([types[i]], hexToBytes(log.topics[t++]))[0];
475
+ else (bodyTypes.push(types[i]), bodyNames.push(n));
476
+ });
477
+ decodeAbi(bodyTypes, log.data).forEach((v, i) => (fields[bodyNames[i]] = v));
478
+ return { name, fields };
479
+ }
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { hex } from "../codec.js";
3
+ import { base58Encode, hex } from "../codec.js";
4
4
  import { accountDiscriminator } from "../solana/instruction.js";
5
5
  import { AccountDecodeError, decodeStruct, encodeStruct, layoutSize } from "../solana/floor/accounts.js";
6
6
 
@@ -135,7 +135,7 @@ export const LAUNCH_V2 = [
135
135
  ["k_floor_tokens", "u64"],
136
136
  ["kpot", "u8"],
137
137
 
138
- ["pad_og", "bytes:3"],
138
+ ["k_kept", "bytes:3"],
139
139
  ["creator_ref_og_until", "u32[3]"],
140
140
  ];
141
141
 
@@ -179,6 +179,85 @@ export const DEAD_MARK = [
179
179
  ["counted", "u64"],
180
180
  ];
181
181
 
182
+ export const DEAL_ESCROW = [
183
+ ["version", "u8"],
184
+ ["bump", "u8"],
185
+ ["n", "u8"],
186
+ ["kind", "u8"],
187
+ ["released", "u8"],
188
+ ["refunded", "u8"],
189
+ ["decimals", "u8"],
190
+ ["pad_fee_bps", "u8"],
191
+ ["fee_bps", "u16"],
192
+ ["cancel", "u8"],
193
+ ["pad_expiry", "bytes:5"],
194
+ ["expiry", "i64"],
195
+ ["opened_at", "i64"],
196
+ ["launch", "pubkey"],
197
+ ["launcher", "pubkey"],
198
+ ["kol", "pubkey"],
199
+ ["asset_mint", "pubkey"],
200
+ ["asset_token_program", "pubkey"],
201
+ ["vault", "pubkey"],
202
+ ["ref32", "bytes:32"],
203
+ ["targets", "u128l[8]"],
204
+ ["amounts", "u64[8]"],
205
+ ["armed_at", "i64[8]"],
206
+ ["armed_slot", "u64[8]"],
207
+
208
+ ["agency", "pubkey"],
209
+ ["vol_at_lock", "u128l"],
210
+ ["proof_ends", "i64[8]"],
211
+ ["proof_hash", "bytes:32[8]"],
212
+ ["kinds", "u8[8]"],
213
+ ["proof", "u8[8]"],
214
+ ["agency_bps", "u16"],
215
+
216
+ ["vol_src", "u8"],
217
+
218
+ ["pad_size", "bytes:13"],
219
+ ];
220
+
221
+ export const DEAL_ESCROW_SIZE = 976;
222
+
223
+ export const DEAL_ESCROW_V3_VERSION = 3;
224
+
225
+ export const REF_VOLUME = [
226
+ ["launch", "pubkey"],
227
+ ["referrer", "pubkey"],
228
+ ["volume", "u128l"],
229
+ ["bump", "u8"],
230
+ ["pad_size", "bytes:15"],
231
+ ];
232
+ export const REF_VOLUME_SIZE = 96;
233
+
234
+ export const SEAT_AGENCY_LAYOUT = [
235
+ ["launch", "pubkey"],
236
+ ["agency", "pubkey"],
237
+ ["agency_bps", "u16"],
238
+ ["index", "u8"],
239
+ ["bump", "u8"],
240
+ ["pad_size", "bytes:4"],
241
+ ];
242
+ export const SEAT_AGENCY_SIZE = 72;
243
+
244
+ export const REF_VOLUME_ENTRY = [
245
+ ["referrer", "pubkey"],
246
+ ["volume", "u128l"],
247
+ ];
248
+ export const REF_VOLUME_BOOK = [
249
+ ["launch", "pubkey"],
250
+ ["len", "u8"],
251
+ ["bump", "u8"],
252
+ ["pad_entries", "bytes:14"],
253
+ ["entries", "bytes:1536"],
254
+ ];
255
+ export const REF_VOLUME_BOOK_SIZE = 1584;
256
+ export const REF_VOLUME_BOOK_CAP = 32;
257
+
258
+ export const VOL_SRC_REF_VOLUME = 0;
259
+ export const VOL_SRC_BOOK = 1;
260
+
182
261
  export const LOTS_MAX = 16;
183
262
  export const MEMBERS_MAX = 10;
184
263
 
@@ -190,6 +269,10 @@ export const LAYOUTS_V2 = {
190
269
  HolderPosition: HOLDER_POSITION,
191
270
  HolderBook: HOLDER_BOOK,
192
271
  DeadMark: DEAD_MARK,
272
+ DealEscrow: DEAL_ESCROW,
273
+ RefVolume: REF_VOLUME,
274
+ RefVolumeBook: REF_VOLUME_BOOK,
275
+ SeatAgency: SEAT_AGENCY_LAYOUT,
193
276
  } ;
194
277
 
195
278
  export function decodeAccountV2(name , data ) {
@@ -221,3 +304,18 @@ export const decodePresetRowV2 = (d ) => decodeAccountV2("PresetRowV2
221
304
  export const decodeHolderPosition = (d ) => decodeAccountV2("HolderPosition", d);
222
305
  export const decodeHolderBook = (d ) => decodeAccountV2("HolderBook", d);
223
306
  export const decodeDeadMark = (d ) => decodeAccountV2("DeadMark", d);
307
+
308
+ export const decodeDealEscrow = (d ) => decodeAccountV2("DealEscrow", d);
309
+
310
+ export const decodeRefVolume = (d ) => decodeAccountV2("RefVolume", d);
311
+
312
+ export function refVolumeBookEntries(book ) {
313
+ const out = [];
314
+ for (let i = 0; i < Math.min(book.len, REF_VOLUME_BOOK_CAP); i++) {
315
+ const e = book.entries.subarray(48 * i, 48 * i + 48);
316
+ let v = 0n;
317
+ for (let j = 47; j >= 32; j--) v = (v << 8n) | BigInt(e[j]);
318
+ out.push({ referrer: base58Encode(e.subarray(0, 32)), volume: v });
319
+ }
320
+ return out;
321
+ }
@@ -0,0 +1,127 @@
1
+
2
+
3
+ import { hex } from "../codec.js";
4
+ import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.js";
5
+ import { Reader, Writer } from "../solana/floor/borsh.js";
6
+ import { base58Encode } from "../codec.js";
7
+ import { decodeAbi, eventTopic, hexToBytes } from "../evm/abi.js";
8
+
9
+ const S = (...f ) => f;
10
+
11
+ export const OFFICE_EVENTS = {
12
+ OfficeOpened: S(["officeId", "id"], ["controller", "addr"], ["quote", "addr"]),
13
+ OfficeMemberAdded: S(["officeId", "id"], ["member", "addr"]),
14
+ OfficeMemberLeft: S(["officeId", "id"], ["member", "addr"], ["byController", "bool"], ["units", "amt"], ["cashOut", "amt64"], ["launches", "launches"], ["tokensOut", "toksV"]),
15
+ OfficeDeposit: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"], ["units", "amt"], ["valueBefore", "amt"], ["unitsTotal", "amt"]),
16
+ OfficeShareSet: S(["officeId", "id"], ["member", "addr"], ["shareBps", "u16"], ["shareSum", "u16"]),
17
+ OfficeBuy: S(["officeId", "id"], ["buyer", "addr"], ["launch", "launch"], ["gross", "amt64"], ["tokens", "tok"], ["refund", "amt64"]),
18
+ OfficeSell: S(["officeId", "id"], ["seller", "addr"], ["buyer", "addr"], ["launch", "launch"], ["tokens", "tok"], ["out", "amt64"], ["unfilled", "tok"]),
19
+ OfficeControllerProposed: S(["officeId", "id"], ["member", "addr"]),
20
+ OfficeControllerSet: S(["officeId", "id"], ["controller", "addr"]),
21
+ OfficeMergeProposed: S(["officeId", "id"], ["other", "id"], ["newController", "addr"]),
22
+ OfficeMergeCancelled: S(["officeId", "id"]),
23
+ OfficeMerged: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["unitsTo", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"]),
24
+
25
+ OfficeMergeStarted: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"], ["members", "u16"]),
26
+
27
+ OfficeMergeStep: S(["officeId", "id"], ["other", "id"], ["moved", "u16"], ["left", "u16"], ["unitsTo", "amt"]),
28
+
29
+ OfficePayoutOwed: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"]),
30
+ };
31
+ export const OFFICE_EVENT_NAMES = Object.keys(OFFICE_EVENTS);
32
+
33
+ export const OFFICE_UNFILLED_LEN = 6;
34
+
35
+ function solRead(r , k ) {
36
+ switch (k) {
37
+ case "id": return hex(r.bytes(32));
38
+ case "addr":
39
+ case "launch": return base58Encode(r.bytes(32));
40
+ case "bool": return r.bool();
41
+ case "u16": return r.u16();
42
+ case "amt": return r.u128();
43
+ case "amt64": return r.u64();
44
+ case "tok": return r.u64();
45
+ case "toks": return Array.from({ length: OFFICE_UNFILLED_LEN }, () => r.u64());
46
+ case "launches": return Array.from({ length: r.u32() }, () => base58Encode(r.bytes(32)));
47
+ case "toksV": return Array.from({ length: r.u32() }, () => r.u64());
48
+ }
49
+ }
50
+ function solWrite(w , k , v ) {
51
+ switch (k) {
52
+ case "id": w.bytes(hexToBytes(v)); break;
53
+ case "addr":
54
+ case "launch": w.pubkey(v); break;
55
+ case "bool": w.bool(v); break;
56
+ case "u16": w.u16(v); break;
57
+ case "amt": w.u128(v); break;
58
+ case "amt64": w.u64(v); break;
59
+ case "tok": w.u64(v); break;
60
+ case "toks":
61
+ if (v.length !== OFFICE_UNFILLED_LEN) throw new RangeError(`tokensUnfilled: ${OFFICE_UNFILLED_LEN} values`);
62
+ for (const x of v) w.u64(x);
63
+ break;
64
+ case "launches": w.u32(v.length); for (const x of v) w.pubkey(x); break;
65
+ case "toksV": w.u32(v.length); for (const x of v) w.u64(x); break;
66
+ }
67
+ }
68
+
69
+ let disc ;
70
+ const DISC = () => (disc ??= new Map(OFFICE_EVENT_NAMES.map((n) => [hex(eventDiscriminator(n)), n])));
71
+
72
+ export function decodeOfficeEventData(data ) {
73
+ const name = DISC().get(hex(data.slice(0, 8)));
74
+ if (!name) return null;
75
+ const r = new Reader(data.slice(8));
76
+ const fields = {};
77
+ for (const [f, k] of OFFICE_EVENTS[name]) fields[f] = solRead(r, k);
78
+ if (r.o !== r.b.length) throw new RangeError(`${name}: ${r.b.length} body bytes, the schema reads ${r.o}`);
79
+ return { name, fields };
80
+ }
81
+
82
+ export function encodeOfficeEventData(e ) {
83
+ const w = new Writer().bytes(eventDiscriminator(e.name));
84
+ for (const [f, k] of OFFICE_EVENTS[e.name] ?? []) solWrite(w, k, e.fields[f]);
85
+ return w.done();
86
+ }
87
+
88
+ export function decodeOfficeEventCpi(ixData ) {
89
+ if (ixData.length < 16 || hex(ixData.slice(0, 8)) !== hex(EVENT_IX_TAG_LE)) return null;
90
+ return decodeOfficeEventData(ixData.slice(8));
91
+ }
92
+
93
+ const EVM_TYPE = { id: "bytes32", addr: "address", launch: "uint256", bool: "bool", u16: "uint16", amt: "uint256", amt64: "uint256", tok: "uint256", toks: "uint256[]", launches: "uint256[]", toksV: "uint256[]" };
94
+
95
+ export const officeEventSignature = (name ) => `${name}(${OFFICE_EVENTS[name].map(([, k]) => EVM_TYPE[k]).join(",")})`;
96
+
97
+ export const OFFICE_LOG_TOPICS = new Map(OFFICE_EVENT_NAMES.map((n) => [eventTopic(officeEventSignature(n)), n]));
98
+
99
+ const EVM_INDEXED = {
100
+ OfficeOpened: ["officeId", "controller"], OfficeMemberAdded: ["officeId", "member"], OfficeMemberLeft: ["officeId", "member"],
101
+ OfficeDeposit: ["officeId", "member"], OfficeShareSet: ["officeId", "member"], OfficeBuy: ["officeId", "buyer", "launch"],
102
+ OfficeSell: ["officeId", "seller", "launch"], OfficeControllerProposed: ["officeId", "member"], OfficeControllerSet: ["officeId", "controller"],
103
+ OfficeMergeProposed: ["officeId", "other"], OfficeMergeCancelled: ["officeId"], OfficeMerged: ["officeId", "other"], OfficeMergeStarted: ["officeId", "other"], OfficeMergeStep: ["officeId", "other"], OfficePayoutOwed: ["officeId", "member"],
104
+ };
105
+ const topicWord = (t , k ) => {
106
+ const h = t.toLowerCase();
107
+ return k === "addr" ? "0x" + h.slice(-40) : k === "launch" ? String(BigInt(h)) : h;
108
+ };
109
+
110
+ export function decodeOfficeLog(log ) {
111
+ const name = OFFICE_LOG_TOPICS.get(log.topics[0]?.toLowerCase() ?? "");
112
+ if (!name) return null;
113
+ const spec = OFFICE_EVENTS[name];
114
+ const n = log.topics.length - 1;
115
+ const table = EVM_INDEXED[name] ?? [];
116
+ const idx = n === table.length ? table : spec.slice(0, n).map(([f]) => f);
117
+ const dataSpec = spec.filter(([f]) => !idx.includes(f));
118
+ const vals = dataSpec.length === 0 ? [] : decodeAbi(dataSpec.map(([, k]) => EVM_TYPE[k]), log.data);
119
+ const fields = {};
120
+ let ti = 1;
121
+ for (const [f, k] of spec.filter(([f]) => idx.includes(f))) fields[f] = topicWord(log.topics[ti++], k);
122
+ dataSpec.forEach(([f, k], i) => {
123
+ const v = vals[i];
124
+ fields[f] = k === "launch" ? String(v) : k === "launches" ? (v ).map(String) : k === "id" || k === "addr" ? String(v).toLowerCase() : v;
125
+ });
126
+ return { name, fields };
127
+ }
@@ -0,0 +1,68 @@
1
+
2
+
3
+ import { decodeAbi, encodeCall } from "../evm/abi.js";
4
+
5
+ export const OFFICE_SIGNATURES = {
6
+ officeOpen: "officeOpen(bytes32,address)",
7
+ officeAddMember: "officeAddMember(bytes32,address)",
8
+ officeRemoveMember: "officeRemoveMember(bytes32,address)",
9
+ officeLeave: "officeLeave(bytes32)",
10
+ officeDeposit: "officeDeposit(bytes32,uint256)",
11
+ officeSetShare: "officeSetShare(bytes32,address,uint16)",
12
+ officeBuy: "officeBuy(bytes32,uint256,uint256,uint256)",
13
+ officeSell: "officeSell(bytes32,uint256,address,uint256,uint256)",
14
+ officeProposeController: "officeProposeController(bytes32,address)",
15
+ officeAcceptController: "officeAcceptController(bytes32)",
16
+ officeProposeMerge: "officeProposeMerge(bytes32,bytes32,address)",
17
+ officeAcceptMerge: "officeAcceptMerge(bytes32,bytes32,address)",
18
+ officeCancelMerge: "officeCancelMerge(bytes32)",
19
+ officeMergeStep: "officeMergeStep(bytes32)",
20
+ officeOf: "officeOf(bytes32)",
21
+ officeMemberOf: "officeMemberOf(bytes32,address)",
22
+ officeValue: "officeValue(bytes32)",
23
+ } ;
24
+
25
+ const ZERO_ADDRESS = "0x" + "00".repeat(20);
26
+ const call = (sig , v , value = 0n) => ({ data: encodeCall(OFFICE_SIGNATURES[sig], v), value });
27
+ const u = (name , x , bits ) => {
28
+ if (x < 0n || x >= 1n << BigInt(bits)) throw new RangeError(`${name} is a u${bits}`);
29
+ return x;
30
+ };
31
+ const id = (officeId ) => {
32
+ if (!/^0x[0-9a-fA-F]{64}$/.test(officeId) || /^0x0+$/.test(officeId)) throw new RangeError("officeId is 32 non-zero bytes (0x hex)");
33
+ return officeId;
34
+ };
35
+
36
+ export const officeOpenCall = (p ) => call("officeOpen", [id(p.officeId), p.quote]);
37
+ export const officeAddMemberCall = (p ) => call("officeAddMember", [id(p.officeId), p.member]);
38
+ export const officeRemoveMemberCall = (p ) => call("officeRemoveMember", [id(p.officeId), p.member]);
39
+ export const officeLeaveCall = (p ) => call("officeLeave", [id(p.officeId)]);
40
+
41
+ export const officeDepositCall = (p ) =>
42
+ call("officeDeposit", [id(p.officeId), u("amount", p.amount, 256)], p.nativeQuote ? p.amount : 0n);
43
+ export const officeSetShareCall = (p ) => {
44
+ if (!Number.isInteger(p.shareBps) || p.shareBps < 0 || p.shareBps > 10_000) throw new RangeError("shareBps is 0..=10000 (ShareSum)");
45
+ return call("officeSetShare", [id(p.officeId), p.member, BigInt(p.shareBps)]);
46
+ };
47
+ export const officeBuyCall = (p ) =>
48
+ call("officeBuy", [id(p.officeId), u("launchId", p.launchId, 256), u("gross", p.gross, 256), u("minTokens", p.minTokens, 256)]);
49
+ export const officeSellCall = (p ) =>
50
+ call("officeSell", [id(p.officeId), u("launchId", p.launchId, 256), p.buyer, u("tokens", p.tokens, 256), u("minOut", p.minOut, 256)]);
51
+
52
+ export const officeProposeControllerCall = (p ) => call("officeProposeController", [id(p.officeId), p.member ?? ZERO_ADDRESS]);
53
+ export const officeAcceptControllerCall = (p ) => call("officeAcceptController", [id(p.officeId)]);
54
+ export const officeProposeMergeCall = (p ) => call("officeProposeMerge", [id(p.officeId), id(p.other), p.newController]);
55
+ export const officeAcceptMergeCall = (p ) => call("officeAcceptMerge", [id(p.officeId), id(p.other), p.newController]);
56
+ export const officeCancelMergeCall = (p ) => call("officeCancelMerge", [id(p.officeId)]);
57
+
58
+ export const officeMergeStepCall = (p ) => call("officeMergeStep", [id(p.officeId)]);
59
+ export const officeOfCall = (p ) => call("officeOf", [id(p.officeId)]);
60
+ export const officeMemberOfCall = (p ) => call("officeMemberOf", [id(p.officeId), p.member]);
61
+ export const officeValueCall = (p ) => call("officeValue", [id(p.officeId)]);
62
+
63
+ export function decodeOfficeMemberOf(ret ) {
64
+ const [units, shareBps] = decodeAbi(["uint256", "uint16"], ret) ;
65
+ return { units, shareBps: Number(shareBps) };
66
+ }
67
+
68
+ export const decodeOfficeValue = (ret ) => decodeAbi(["uint256"], ret)[0] ;