@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/src/v2/evm.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.ts";
3
+ import { checksumAddress, decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.ts";
4
4
  import { keccak256 } from "../evm/keccak.ts";
5
5
  import type { AbiValue } from "../evm/abi.ts";
6
6
  import { claimCall } from "../evm/floor/calls.ts";
@@ -13,6 +13,8 @@ import type { SplitRow } from "../math/v2/split.ts";
13
13
  import type { Supply } from "../math/v2/supply.ts";
14
14
  import { evmSignature } from "../generated/index.ts";
15
15
  import { CLAIM_BITS, CLAIM_KNOWN_MASKS } from "../generated/index.ts";
16
+ import { slotMemberKeyEvm } from "./tx/evm.ts";
17
+ import type { SlotMemberEvm } from "./tx/evm.ts";
16
18
  import { EVM_EVENT_SCHEMAS } from "../abi/evm.gen.ts";
17
19
  import { V2_EVENT_FIELD_NAMES } from "../abi/evm-event-names.ts";
18
20
 
@@ -22,7 +24,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
22
24
 
23
25
  const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
24
26
 
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)`;
27
+ 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)`;
26
28
 
27
29
  const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
28
30
 
@@ -66,6 +68,8 @@ export const V2_TOKEN_VIEWS = {
66
68
 
67
69
  export const V2_CALLS = {
68
70
  creditBacking: evmSignature("creditBacking"),
71
+
72
+ creditPlatform: evmSignature("creditPlatform"),
69
73
  } as const;
70
74
 
71
75
  export const V2_TOKEN_CALLS = {
@@ -93,6 +97,17 @@ export function creditBackingCall(amm: string, launchId: bigint, quote: string,
93
97
  return call(amm, V2_CALLS.creditBacking, [launchId, amount], quote.toLowerCase() === NATIVE ? amount : 0n);
94
98
  }
95
99
 
100
+ export function creditPlatformCall(amm: string, launchId: bigint, quote: string, amount: bigint, memo: Uint8Array = new Uint8Array(32)): EvmCall {
101
+ if (amount <= 0n) throw new RangeError("creditPlatform: amount must be > 0 (NothingToDo)");
102
+ if (memo.length !== 32) throw new RangeError("creditPlatform: the memo is 32 bytes");
103
+ return call(amm, V2_CALLS.creditPlatform, [launchId, amount, memo], quote.toLowerCase() === NATIVE ? amount : 0n);
104
+ }
105
+
106
+ export function setDealFeeCapCall(amm: string, capBps: number): EvmCall {
107
+ if (!Number.isInteger(capBps) || capBps < 0 || capBps > 5000) throw new RangeError("setDealFeeCap: capBps in 0..=5000");
108
+ return call(amm, evmSignature("setDealFeeCap"), [BigInt(capBps)]);
109
+ }
110
+
96
111
  export function claimV2Call(p: { floorAmm: string; wallet: string; types: number; quotes: readonly string[]; launchIds?: readonly bigint[] }): EvmCall {
97
112
  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)");
98
113
  if ((p.types & CLAIM_HOLDER_EVM) === 0) return claimCall(p);
@@ -130,6 +145,8 @@ export interface LaunchBookV2 {
130
145
  ckAtF: bigint; ckFloorTokens: bigint;
131
146
 
132
147
  kpot: boolean; kAtF: bigint; kFloorTokens: bigint;
148
+
149
+ kKept?: number;
133
150
  graduated: boolean;
134
151
 
135
152
  feePpm: number[];
@@ -147,7 +164,14 @@ function one(name: keyof typeof V2_VIEWS, data: string | Uint8Array): AbiValue[]
147
164
  }
148
165
 
149
166
  export function decodeLaunchBook(data: string | Uint8Array): LaunchBookV2 {
150
- const [t] = one("launchBook", data) as AbiValue[][];
167
+
168
+ const [t] = (() => {
169
+ try {
170
+ return one("launchBook", data) as AbiValue[][];
171
+ } catch {
172
+ return decodeAbi([LAUNCH_BOOK.replace(/,uint32\)$/, ")")], data) as AbiValue[][];
173
+ }
174
+ })();
151
175
  const nR = n(t[4]);
152
176
  const ranges = (t[5] as AbiValue[][]).slice(0, nR).map((r) => ({
153
177
  sqrtA: big(r[0]), sqrtB: big(r[1]), tokens: big(r[2]), askLeft: big(r[3]), back: big(r[4]), place: big(r[5]),
@@ -158,6 +182,7 @@ export function decodeLaunchBook(data: string | Uint8Array): LaunchBookV2 {
158
182
  sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
159
183
  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
184
  kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] as boolean,
185
+ ...(t.length > 21 && n(t[21]) !== 0 && { kKept: n(t[21]) }),
161
186
  };
162
187
  }
163
188
  export function decodeSimBuy(data: string | Uint8Array): SimBuyV2 {
@@ -236,11 +261,16 @@ export const V2_EVENTS = Object.fromEntries(
236
261
 
237
262
  export const V2_EVENTS_ELSEWHERE = [
238
263
  "Initialized", "LaunchCreated", "PayoutOwed", "TeamSlotOpened", "Upgraded", "Approval", "Transfer", "EIP712DomainChanged", "Claimed", "ClaimSkipped",
239
- "HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
264
+ "HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "BookRelayed" , "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
240
265
  "TeamSlotMember",
266
+ "DealFeePaid", "PlatformCredited", "TeamSlotDealFee",
267
+ "DealEscrowOpened", "DealEscrowArmed", "DealEscrowReleased", "DealEscrowRefunded", "DealEscrowCancelAgreed", "DealEscrowCancelled",
268
+ "DealEscrowTermsV3", "DealEscrowSplit", "DealEscrowProofSubmitted", "DealEscrowProofObjected",
269
+ "TeamSlotAgency", "TeamSlotAgencyPaid",
241
270
 
242
271
  "ConfigWritten", "HandleBound", "HandleOwedMoved", "MetadataBaseSet", "NativeCreateFeeSet", "PriceUpdaterSet", "QuoteCapSet",
243
272
  "QuoteWritten", "TraderRefCleared", "TraderRefOpened", "TreasurySet",
273
+ "DealFeeCapSet",
244
274
  ] as const;
245
275
 
246
276
  let topics: Map<string, keyof typeof V2_EVENTS> | undefined;
@@ -302,7 +332,7 @@ export function evmSettleInputsV2(b: LaunchBookV2, row: SplitRow, sup: Supply, m
302
332
  bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
303
333
  bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
304
334
  bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
305
- kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
335
+ kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens, ...(b.kKept ? { kKept: b.kKept } : {}),
306
336
  feePpm: [...b.feePpm], graduated: b.graduated,
307
337
 
308
338
  feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
@@ -356,3 +386,172 @@ export async function readHolderV2(
356
386
  const standing = holderStandingV2({ address: p.address, code, optedIn: decodeOptedIn(opted), program: p.program });
357
387
  return { amount: x.amount, owed: x.owed, indexSnap: x.indexSnap, standing, optIn: standing.weight === "contract-not-opted-in" ? optInCall(p.token) : null };
358
388
  }
389
+
390
+ export const DEAL_V3_STEP = { mcap: 0, volume: 1, upfront: 2 } as const;
391
+
392
+ export const DEAL_V3_PROOF = { none: 0, waiting: 1, submitted: 2, objected: 3, resubmitted: 4 } as const;
393
+ export const DEAL_AGENCY_BPS_MAX = 3_000;
394
+ export const DEAL_PROOF_WINDOW_SECS = 86_400n;
395
+
396
+ const DEAL_TERMS_V3 = "(uint8[],uint256[],uint256[],uint8,address,uint16,int64)";
397
+ export const DEAL_V3_CALLS = {
398
+ dealEscrowOpenV3: `dealEscrowOpenV3(uint256,address,bytes32,bool,${DEAL_TERMS_V3})`,
399
+ dealEscrowArmV3: "dealEscrowArmV3(bytes32,uint8)",
400
+ dealEscrowReleaseV3: "dealEscrowReleaseV3(bytes32,uint8)",
401
+ dealEscrowSubmitProof: "dealEscrowSubmitProof(bytes32,uint8,bytes32)",
402
+ dealEscrowObject: "dealEscrowObject(bytes32,uint8)",
403
+ teamSlotAddDealV3: "teamSlotAddDealV3(uint256,bytes32,uint8,uint256,uint16,address,uint16)",
404
+ } as const;
405
+ export const DEAL_V3_VIEWS = {
406
+ refVolume: { sig: "refVolume(uint256,address)", ret: ["uint256"] },
407
+ teamSlotAgencyOf: { sig: "teamSlotAgencyOf(uint256,uint8)", ret: ["address", "uint16"] },
408
+ dealEscrowV3Of: {
409
+ sig: "dealEscrowV3Of(bytes32)",
410
+ ret: ["(uint8,uint8[8],uint8[8],int64[8],bytes32[8],address,uint16,uint256,uint256)"],
411
+ },
412
+ } as const;
413
+
414
+ export interface DealTermsV3Input {
415
+ kinds: readonly number[];
416
+ targets: readonly bigint[];
417
+ amounts: readonly bigint[];
418
+
419
+ proofMask: number;
420
+
421
+ agency: string;
422
+ agencyBps: number;
423
+ expiry: bigint;
424
+ }
425
+
426
+ const stepOk = (name: string, step: number): bigint => {
427
+ if (!Number.isInteger(step) || step < 0 || step > 7) throw new RangeError(`${name}: step in 0..8 (DealEscrowSteps)`);
428
+ return BigInt(step);
429
+ };
430
+
431
+ export function dealEscrowOpenV3Call(p: { floorAmm: string; launchId: bigint; kol: string; ref32: Uint8Array; assetIsToken: boolean; quote: string; terms: DealTermsV3Input }): EvmCall {
432
+ const t = p.terms;
433
+ const n = t.kinds.length;
434
+ 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)");
435
+ if (!Number.isInteger(t.proofMask) || t.proofMask < 0 || t.proofMask >> n !== 0) throw new RangeError("dealEscrowOpenV3: proofMask bits only below n (DealEscrowSteps)");
436
+ 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)");
437
+ const hasAgency = t.agency.toLowerCase() !== NATIVE;
438
+ 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)");
439
+ if (p.ref32.length !== 32) throw new RangeError("dealEscrowOpenV3: ref32 is 32 bytes");
440
+ const total = t.amounts.reduce((a, b) => a + b, 0n);
441
+ const value = !p.assetIsToken && p.quote.toLowerCase() === NATIVE ? total : 0n;
442
+ const terms: AbiValue[] = [t.kinds.map(BigInt), [...t.targets], [...t.amounts], BigInt(t.proofMask), t.agency, BigInt(t.agencyBps), t.expiry];
443
+ return call(p.floorAmm, DEAL_V3_CALLS.dealEscrowOpenV3, [p.launchId, p.kol, p.ref32, p.assetIsToken, terms], value);
444
+ }
445
+
446
+ export const dealEscrowArmV3Call = (floorAmm: string, escrow: string, step: number): EvmCall =>
447
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowArmV3, [hexToBytes(escrow), stepOk("dealEscrowArmV3", step)]);
448
+
449
+ export const dealEscrowReleaseV3Call = (floorAmm: string, escrow: string, step: number): EvmCall =>
450
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowReleaseV3, [hexToBytes(escrow), stepOk("dealEscrowReleaseV3", step)]);
451
+
452
+ export function dealEscrowSubmitProofCall(floorAmm: string, escrow: string, step: number, proofHash: Uint8Array): EvmCall {
453
+ if (proofHash.length !== 32) throw new RangeError("dealEscrowSubmitProof: the hash is 32 bytes");
454
+ return call(floorAmm, DEAL_V3_CALLS.dealEscrowSubmitProof, [hexToBytes(escrow), stepOk("dealEscrowSubmitProof", step), proofHash]);
455
+ }
456
+
457
+ export const dealEscrowObjectCall = (floorAmm: string, escrow: string, step: number): EvmCall =>
458
+ call(floorAmm, DEAL_V3_CALLS.dealEscrowObject, [hexToBytes(escrow), stepOk("dealEscrowObject", step)]);
459
+
460
+ export function teamSlotAddDealV3Call(p: { floorAmm: string; launchId: bigint; member: SlotMemberEvm; shares: bigint; dealFeeBps: number; agency: string; agencyBps: number }): EvmCall {
461
+ if (p.shares <= 0n) throw new RangeError("teamSlotAddDealV3: shares > 0 (NothingToDo)");
462
+ if (!Number.isInteger(p.dealFeeBps) || p.dealFeeBps < 0 || p.dealFeeBps > 0xffff) throw new RangeError("teamSlotAddDealV3: dealFeeBps is a uint16");
463
+ const hasAgency = p.agency.toLowerCase() !== NATIVE;
464
+ if (!Number.isInteger(p.agencyBps) || hasAgency !== (p.agencyBps !== 0) || p.agencyBps < 0 || p.agencyBps > DEAL_AGENCY_BPS_MAX) {
465
+ throw new RangeError("teamSlotAddDealV3: an agency needs 1..=3000 bps, none needs 0 (DealEscrowAgency)");
466
+ }
467
+ const { key, kind } = slotMemberKeyEvm(p.member);
468
+ return call(p.floorAmm, DEAL_V3_CALLS.teamSlotAddDealV3, [p.launchId, hexToBytes(key), BigInt(kind), p.shares, BigInt(p.dealFeeBps), p.agency, BigInt(p.agencyBps)]);
469
+ }
470
+
471
+ export const teamSlotAgencyOfData = (launchId: bigint, place: number): string => {
472
+ if (!Number.isInteger(place) || place < 0 || place > 9) throw new RangeError("teamSlotAgencyOf: place in 0..10 (BadArgument)");
473
+ return bytesToHex(encodeCall(DEAL_V3_VIEWS.teamSlotAgencyOf.sig, [launchId, BigInt(place)]));
474
+ };
475
+ export function decodeTeamSlotAgencyOf(data: string | Uint8Array): { agency: string; agencyBps: number } | null {
476
+ const [a, bps] = decodeAbi(DEAL_V3_VIEWS.teamSlotAgencyOf.ret, data) as [string, bigint];
477
+ return a.toLowerCase() === NATIVE && bps === 0n ? null : { agency: checksumAddress(a), agencyBps: Number(bps) };
478
+ }
479
+
480
+ export const refVolumeData = (launchId: bigint, referrer: string): string => bytesToHex(encodeCall(DEAL_V3_VIEWS.refVolume.sig, [launchId, referrer]));
481
+ export const dealEscrowV3OfData = (escrow: string): string => bytesToHex(encodeCall(DEAL_V3_VIEWS.dealEscrowV3Of.sig, [hexToBytes(escrow)]));
482
+ export const decodeRefVolume = (data: string | Uint8Array): bigint => decodeAbi(DEAL_V3_VIEWS.refVolume.ret, data)[0] as bigint;
483
+
484
+ export interface DealEscrowV3Read {
485
+ version: number;
486
+ kinds: number[];
487
+ proof: number[];
488
+ proofEnds: bigint[];
489
+ proofHash: string[];
490
+ agency: string;
491
+ agencyBps: number;
492
+ volAtLock: bigint;
493
+ volumeNow: bigint;
494
+ }
495
+ export function decodeDealEscrowV3Of(data: string | Uint8Array): DealEscrowV3Read {
496
+ const v = decodeAbi(DEAL_V3_VIEWS.dealEscrowV3Of.ret, data)[0] as AbiValue[];
497
+ const nums = (x: AbiValue): number[] => (x as bigint[]).map(Number);
498
+ return {
499
+ version: Number(v[0]),
500
+ kinds: nums(v[1]),
501
+ proof: nums(v[2]),
502
+ proofEnds: v[3] as bigint[],
503
+ proofHash: (v[4] as Uint8Array[]).map((b) => (typeof b === "string" ? b : bytesToHex(b))),
504
+ agency: checksumAddress(v[5] as string),
505
+ agencyBps: Number(v[6]),
506
+ volAtLock: v[7] as bigint,
507
+ volumeNow: v[8] as bigint,
508
+ };
509
+ }
510
+
511
+ export const DEAL_V3_EVENTS = {
512
+ DealEscrowTermsV3: {
513
+ sig: "DealEscrowTermsV3(uint256,bytes32,bytes32,uint8[],uint8,address,uint16,uint256)",
514
+ indexed: ["launchId", "escrow"],
515
+ names: ["launchId", "escrow", "ref32", "kinds", "proofMask", "agency", "agencyBps", "volAtLock"],
516
+ },
517
+ DealEscrowSplit: {
518
+ sig: "DealEscrowSplit(uint256,bytes32,bytes32,uint8,uint8,address,uint256,address,uint256,address[3],uint256[3],uint256)",
519
+ indexed: ["launchId", "escrow", "kol"],
520
+ names: ["launchId", "escrow", "ref32", "step", "kind", "kol", "kolPart", "agency", "agencyPart", "tiers", "refs", "feeRest"],
521
+ },
522
+ DealEscrowProofSubmitted: {
523
+ sig: "DealEscrowProofSubmitted(uint256,bytes32,bytes32,uint8,bytes32,uint8,int64)",
524
+ indexed: ["launchId", "escrow"],
525
+ names: ["launchId", "escrow", "ref32", "step", "proofHash", "state", "windowEnds"],
526
+ },
527
+ DealEscrowProofObjected: {
528
+ sig: "DealEscrowProofObjected(uint256,bytes32,bytes32,uint8)",
529
+ indexed: ["launchId", "escrow"],
530
+ names: ["launchId", "escrow", "ref32", "step"],
531
+ },
532
+ } as const;
533
+ export type DealV3EventName = keyof typeof DEAL_V3_EVENTS;
534
+
535
+ let dealTopics: Map<string, DealV3EventName> | undefined;
536
+ const DEAL_TOPICS = (): Map<string, DealV3EventName> =>
537
+ (dealTopics ??= new Map((Object.keys(DEAL_V3_EVENTS) as DealV3EventName[]).map((k) => [eventTopic(DEAL_V3_EVENTS[k].sig), k])));
538
+ export const dealV3EventTopic = (name: DealV3EventName): string => eventTopic(DEAL_V3_EVENTS[name].sig);
539
+
540
+ export function decodeDealV3Log(log: { topics: readonly string[]; data: string }): { name: DealV3EventName; fields: Record<string, AbiValue> } | null {
541
+ const name = DEAL_TOPICS().get((log.topics[0] ?? "").toLowerCase());
542
+ if (!name) return null;
543
+ const ev = DEAL_V3_EVENTS[name];
544
+ const types = ev.sig.slice(ev.sig.indexOf("(") + 1, -1).split(",");
545
+ const idx = new Set<string>(ev.indexed);
546
+ if (log.topics.length !== 1 + idx.size) throw new RangeError(`${name}: ${log.topics.length - 1} indexed topics, want ${idx.size}`);
547
+ const fields: Record<string, AbiValue> = {};
548
+ let t = 1;
549
+ const bodyTypes: string[] = [];
550
+ const bodyNames: string[] = [];
551
+ ev.names.forEach((n, i) => {
552
+ if (idx.has(n)) fields[n] = decodeAbi([types[i]], hexToBytes(log.topics[t++]))[0];
553
+ else (bodyTypes.push(types[i]), bodyNames.push(n));
554
+ });
555
+ decodeAbi(bodyTypes, log.data).forEach((v, i) => (fields[bodyNames[i]] = v));
556
+ return { name, fields };
557
+ }
package/src/v2/layouts.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { hex } from "../codec.ts";
3
+ import { base58Encode, hex } from "../codec.ts";
4
4
  import { accountDiscriminator } from "../solana/instruction.ts";
5
5
  import { AccountDecodeError, decodeStruct, encodeStruct, layoutSize } from "../solana/floor/accounts.ts";
6
6
  import type { Layout } from "../solana/floor/accounts.ts";
@@ -136,7 +136,7 @@ export const LAUNCH_V2: Layout = [
136
136
  ["k_floor_tokens", "u64"],
137
137
  ["kpot", "u8"],
138
138
 
139
- ["pad_og", "bytes:3"],
139
+ ["k_kept", "bytes:3"],
140
140
  ["creator_ref_og_until", "u32[3]"],
141
141
  ];
142
142
 
@@ -180,6 +180,85 @@ export const DEAD_MARK: Layout = [
180
180
  ["counted", "u64"],
181
181
  ];
182
182
 
183
+ export const DEAL_ESCROW: Layout = [
184
+ ["version", "u8"],
185
+ ["bump", "u8"],
186
+ ["n", "u8"],
187
+ ["kind", "u8"],
188
+ ["released", "u8"],
189
+ ["refunded", "u8"],
190
+ ["decimals", "u8"],
191
+ ["pad_fee_bps", "u8"],
192
+ ["fee_bps", "u16"],
193
+ ["cancel", "u8"],
194
+ ["pad_expiry", "bytes:5"],
195
+ ["expiry", "i64"],
196
+ ["opened_at", "i64"],
197
+ ["launch", "pubkey"],
198
+ ["launcher", "pubkey"],
199
+ ["kol", "pubkey"],
200
+ ["asset_mint", "pubkey"],
201
+ ["asset_token_program", "pubkey"],
202
+ ["vault", "pubkey"],
203
+ ["ref32", "bytes:32"],
204
+ ["targets", "u128l[8]"],
205
+ ["amounts", "u64[8]"],
206
+ ["armed_at", "i64[8]"],
207
+ ["armed_slot", "u64[8]"],
208
+
209
+ ["agency", "pubkey"],
210
+ ["vol_at_lock", "u128l"],
211
+ ["proof_ends", "i64[8]"],
212
+ ["proof_hash", "bytes:32[8]"],
213
+ ["kinds", "u8[8]"],
214
+ ["proof", "u8[8]"],
215
+ ["agency_bps", "u16"],
216
+
217
+ ["vol_src", "u8"],
218
+
219
+ ["pad_size", "bytes:13"],
220
+ ];
221
+
222
+ export const DEAL_ESCROW_SIZE = 976;
223
+
224
+ export const DEAL_ESCROW_V3_VERSION = 3;
225
+
226
+ export const REF_VOLUME: Layout = [
227
+ ["launch", "pubkey"],
228
+ ["referrer", "pubkey"],
229
+ ["volume", "u128l"],
230
+ ["bump", "u8"],
231
+ ["pad_size", "bytes:15"],
232
+ ];
233
+ export const REF_VOLUME_SIZE = 96;
234
+
235
+ export const SEAT_AGENCY_LAYOUT: Layout = [
236
+ ["launch", "pubkey"],
237
+ ["agency", "pubkey"],
238
+ ["agency_bps", "u16"],
239
+ ["index", "u8"],
240
+ ["bump", "u8"],
241
+ ["pad_size", "bytes:4"],
242
+ ];
243
+ export const SEAT_AGENCY_SIZE = 72;
244
+
245
+ export const REF_VOLUME_ENTRY: Layout = [
246
+ ["referrer", "pubkey"],
247
+ ["volume", "u128l"],
248
+ ];
249
+ export const REF_VOLUME_BOOK: Layout = [
250
+ ["launch", "pubkey"],
251
+ ["len", "u8"],
252
+ ["bump", "u8"],
253
+ ["pad_entries", "bytes:14"],
254
+ ["entries", "bytes:1536"],
255
+ ];
256
+ export const REF_VOLUME_BOOK_SIZE = 1584;
257
+ export const REF_VOLUME_BOOK_CAP = 32;
258
+
259
+ export const VOL_SRC_REF_VOLUME = 0;
260
+ export const VOL_SRC_BOOK = 1;
261
+
183
262
  export const LOTS_MAX = 16;
184
263
  export const MEMBERS_MAX = 10;
185
264
 
@@ -191,6 +270,10 @@ export const LAYOUTS_V2 = {
191
270
  HolderPosition: HOLDER_POSITION,
192
271
  HolderBook: HOLDER_BOOK,
193
272
  DeadMark: DEAD_MARK,
273
+ DealEscrow: DEAL_ESCROW,
274
+ RefVolume: REF_VOLUME,
275
+ RefVolumeBook: REF_VOLUME_BOOK,
276
+ SeatAgency: SEAT_AGENCY_LAYOUT,
194
277
  } as const;
195
278
  export type AccountNameV2 = keyof typeof LAYOUTS_V2;
196
279
 
@@ -223,3 +306,18 @@ export const decodePresetRowV2 = (d: Uint8Array) => decodeAccountV2("PresetRowV2
223
306
  export const decodeHolderPosition = (d: Uint8Array) => decodeAccountV2("HolderPosition", d);
224
307
  export const decodeHolderBook = (d: Uint8Array) => decodeAccountV2("HolderBook", d);
225
308
  export const decodeDeadMark = (d: Uint8Array) => decodeAccountV2("DeadMark", d);
309
+
310
+ export const decodeDealEscrow = (d: Uint8Array): Record<string, any> => decodeAccountV2("DealEscrow", d);
311
+
312
+ export const decodeRefVolume = (d: Uint8Array): Record<string, any> => decodeAccountV2("RefVolume", d);
313
+
314
+ export function refVolumeBookEntries(book: { len: number; entries: Uint8Array }): { referrer: string; volume: bigint }[] {
315
+ const out: { referrer: string; volume: bigint }[] = [];
316
+ for (let i = 0; i < Math.min(book.len, REF_VOLUME_BOOK_CAP); i++) {
317
+ const e = book.entries.subarray(48 * i, 48 * i + 48);
318
+ let v = 0n;
319
+ for (let j = 47; j >= 32; j--) v = (v << 8n) | BigInt(e[j]);
320
+ out.push({ referrer: base58Encode(e.subarray(0, 32)), volume: v });
321
+ }
322
+ return out;
323
+ }
@@ -0,0 +1,133 @@
1
+
2
+
3
+ import { hex } from "../codec.ts";
4
+ import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.ts";
5
+ import { Reader, Writer } from "../solana/floor/borsh.ts";
6
+ import { base58Encode } from "../codec.ts";
7
+ import { decodeAbi, eventTopic, hexToBytes } from "../evm/abi.ts";
8
+
9
+ type K = "id" | "addr" | "launch" | "bool" | "u16" | "amt" | "amt64" | "tok" | "toks" | "launches" | "toksV";
10
+ const S = (...f: [string, K][]): [string, K][] => f;
11
+
12
+ export const OFFICE_EVENTS: Record<string, [string, K][]> = {
13
+ OfficeOpened: S(["officeId", "id"], ["controller", "addr"], ["quote", "addr"]),
14
+ OfficeMemberAdded: S(["officeId", "id"], ["member", "addr"]),
15
+ OfficeMemberLeft: S(["officeId", "id"], ["member", "addr"], ["byController", "bool"], ["units", "amt"], ["cashOut", "amt64"], ["launches", "launches"], ["tokensOut", "toksV"]),
16
+ OfficeDeposit: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"], ["units", "amt"], ["valueBefore", "amt"], ["unitsTotal", "amt"]),
17
+ OfficeShareSet: S(["officeId", "id"], ["member", "addr"], ["shareBps", "u16"], ["shareSum", "u16"]),
18
+ OfficeBuy: S(["officeId", "id"], ["buyer", "addr"], ["launch", "launch"], ["gross", "amt64"], ["tokens", "tok"], ["refund", "amt64"]),
19
+ OfficeSell: S(["officeId", "id"], ["seller", "addr"], ["buyer", "addr"], ["launch", "launch"], ["tokens", "tok"], ["out", "amt64"], ["unfilled", "tok"]),
20
+ OfficeControllerProposed: S(["officeId", "id"], ["member", "addr"]),
21
+ OfficeControllerSet: S(["officeId", "id"], ["controller", "addr"]),
22
+ OfficeMergeProposed: S(["officeId", "id"], ["other", "id"], ["newController", "addr"]),
23
+ OfficeMergeCancelled: S(["officeId", "id"]),
24
+ OfficeMerged: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["unitsTo", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"]),
25
+
26
+ OfficeMergeStarted: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"], ["members", "u16"]),
27
+
28
+ OfficeMergeStep: S(["officeId", "id"], ["other", "id"], ["moved", "u16"], ["left", "u16"], ["unitsTo", "amt"]),
29
+
30
+ OfficePayoutOwed: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"]),
31
+ };
32
+ export const OFFICE_EVENT_NAMES = Object.keys(OFFICE_EVENTS);
33
+
34
+ export const OFFICE_UNFILLED_LEN = 6;
35
+
36
+ export interface OfficeEvent {
37
+ name: string;
38
+ fields: Record<string, any>;
39
+ }
40
+
41
+ function solRead(r: Reader, k: K): unknown {
42
+ switch (k) {
43
+ case "id": return hex(r.bytes(32));
44
+ case "addr":
45
+ case "launch": return base58Encode(r.bytes(32));
46
+ case "bool": return r.bool();
47
+ case "u16": return r.u16();
48
+ case "amt": return r.u128();
49
+ case "amt64": return r.u64();
50
+ case "tok": return r.u64();
51
+ case "toks": return Array.from({ length: OFFICE_UNFILLED_LEN }, () => r.u64());
52
+ case "launches": return Array.from({ length: r.u32() }, () => base58Encode(r.bytes(32)));
53
+ case "toksV": return Array.from({ length: r.u32() }, () => r.u64());
54
+ }
55
+ }
56
+ function solWrite(w: Writer, k: K, v: any): void {
57
+ switch (k) {
58
+ case "id": w.bytes(hexToBytes(v)); break;
59
+ case "addr":
60
+ case "launch": w.pubkey(v); break;
61
+ case "bool": w.bool(v); break;
62
+ case "u16": w.u16(v); break;
63
+ case "amt": w.u128(v); break;
64
+ case "amt64": w.u64(v); break;
65
+ case "tok": w.u64(v); break;
66
+ case "toks":
67
+ if (v.length !== OFFICE_UNFILLED_LEN) throw new RangeError(`tokensUnfilled: ${OFFICE_UNFILLED_LEN} values`);
68
+ for (const x of v) w.u64(x);
69
+ break;
70
+ case "launches": w.u32(v.length); for (const x of v) w.pubkey(x); break;
71
+ case "toksV": w.u32(v.length); for (const x of v) w.u64(x); break;
72
+ }
73
+ }
74
+
75
+ let disc: Map<string, string> | undefined;
76
+ const DISC = (): Map<string, string> => (disc ??= new Map(OFFICE_EVENT_NAMES.map((n) => [hex(eventDiscriminator(n)), n])));
77
+
78
+ export function decodeOfficeEventData(data: Uint8Array): OfficeEvent | null {
79
+ const name = DISC().get(hex(data.slice(0, 8)));
80
+ if (!name) return null;
81
+ const r = new Reader(data.slice(8));
82
+ const fields: Record<string, any> = {};
83
+ for (const [f, k] of OFFICE_EVENTS[name]) fields[f] = solRead(r, k);
84
+ if (r.o !== r.b.length) throw new RangeError(`${name}: ${r.b.length} body bytes, the schema reads ${r.o}`);
85
+ return { name, fields };
86
+ }
87
+
88
+ export function encodeOfficeEventData(e: OfficeEvent): Uint8Array {
89
+ const w = new Writer().bytes(eventDiscriminator(e.name));
90
+ for (const [f, k] of OFFICE_EVENTS[e.name] ?? []) solWrite(w, k, e.fields[f]);
91
+ return w.done();
92
+ }
93
+
94
+ export function decodeOfficeEventCpi(ixData: Uint8Array): OfficeEvent | null {
95
+ if (ixData.length < 16 || hex(ixData.slice(0, 8)) !== hex(EVENT_IX_TAG_LE)) return null;
96
+ return decodeOfficeEventData(ixData.slice(8));
97
+ }
98
+
99
+ const EVM_TYPE: Record<K, string> = { id: "bytes32", addr: "address", launch: "uint256", bool: "bool", u16: "uint16", amt: "uint256", amt64: "uint256", tok: "uint256", toks: "uint256[]", launches: "uint256[]", toksV: "uint256[]" };
100
+
101
+ export const officeEventSignature = (name: string): string => `${name}(${OFFICE_EVENTS[name].map(([, k]) => EVM_TYPE[k]).join(",")})`;
102
+
103
+ export const OFFICE_LOG_TOPICS: ReadonlyMap<string, string> = new Map(OFFICE_EVENT_NAMES.map((n) => [eventTopic(officeEventSignature(n)), n]));
104
+
105
+ const EVM_INDEXED: Record<string, readonly string[]> = {
106
+ OfficeOpened: ["officeId", "controller"], OfficeMemberAdded: ["officeId", "member"], OfficeMemberLeft: ["officeId", "member"],
107
+ OfficeDeposit: ["officeId", "member"], OfficeShareSet: ["officeId", "member"], OfficeBuy: ["officeId", "buyer", "launch"],
108
+ OfficeSell: ["officeId", "seller", "launch"], OfficeControllerProposed: ["officeId", "member"], OfficeControllerSet: ["officeId", "controller"],
109
+ OfficeMergeProposed: ["officeId", "other"], OfficeMergeCancelled: ["officeId"], OfficeMerged: ["officeId", "other"], OfficeMergeStarted: ["officeId", "other"], OfficeMergeStep: ["officeId", "other"], OfficePayoutOwed: ["officeId", "member"],
110
+ };
111
+ const topicWord = (t: string, k: K): any => {
112
+ const h = t.toLowerCase();
113
+ return k === "addr" ? "0x" + h.slice(-40) : k === "launch" ? String(BigInt(h)) : h;
114
+ };
115
+
116
+ export function decodeOfficeLog(log: { topics: readonly string[]; data: string }): OfficeEvent | null {
117
+ const name = OFFICE_LOG_TOPICS.get(log.topics[0]?.toLowerCase() ?? "");
118
+ if (!name) return null;
119
+ const spec = OFFICE_EVENTS[name];
120
+ const n = log.topics.length - 1;
121
+ const table = EVM_INDEXED[name] ?? [];
122
+ const idx = n === table.length ? table : spec.slice(0, n).map(([f]) => f);
123
+ const dataSpec = spec.filter(([f]) => !idx.includes(f));
124
+ const vals = dataSpec.length === 0 ? [] : decodeAbi(dataSpec.map(([, k]) => EVM_TYPE[k]), log.data);
125
+ const fields: Record<string, any> = {};
126
+ let ti = 1;
127
+ for (const [f, k] of spec.filter(([f]) => idx.includes(f))) fields[f] = topicWord(log.topics[ti++], k);
128
+ dataSpec.forEach(([f, k], i) => {
129
+ const v: any = vals[i];
130
+ fields[f] = k === "launch" ? String(v) : k === "launches" ? (v as bigint[]).map(String) : k === "id" || k === "addr" ? String(v).toLowerCase() : v;
131
+ });
132
+ return { name, fields };
133
+ }
@@ -0,0 +1,76 @@
1
+
2
+
3
+ import { decodeAbi, encodeCall } from "../evm/abi.ts";
4
+ import type { AbiValue } from "../evm/abi.ts";
5
+
6
+ export interface OfficeCall {
7
+
8
+ data: Uint8Array;
9
+
10
+ value: bigint;
11
+ }
12
+
13
+ export const OFFICE_SIGNATURES = {
14
+ officeOpen: "officeOpen(bytes32,address)",
15
+ officeAddMember: "officeAddMember(bytes32,address)",
16
+ officeRemoveMember: "officeRemoveMember(bytes32,address)",
17
+ officeLeave: "officeLeave(bytes32)",
18
+ officeDeposit: "officeDeposit(bytes32,uint256)",
19
+ officeSetShare: "officeSetShare(bytes32,address,uint16)",
20
+ officeBuy: "officeBuy(bytes32,uint256,uint256,uint256)",
21
+ officeSell: "officeSell(bytes32,uint256,address,uint256,uint256)",
22
+ officeProposeController: "officeProposeController(bytes32,address)",
23
+ officeAcceptController: "officeAcceptController(bytes32)",
24
+ officeProposeMerge: "officeProposeMerge(bytes32,bytes32,address)",
25
+ officeAcceptMerge: "officeAcceptMerge(bytes32,bytes32,address)",
26
+ officeCancelMerge: "officeCancelMerge(bytes32)",
27
+ officeMergeStep: "officeMergeStep(bytes32)",
28
+ officeOf: "officeOf(bytes32)",
29
+ officeMemberOf: "officeMemberOf(bytes32,address)",
30
+ officeValue: "officeValue(bytes32)",
31
+ } as const;
32
+
33
+ const ZERO_ADDRESS = "0x" + "00".repeat(20);
34
+ const call = (sig: keyof typeof OFFICE_SIGNATURES, v: AbiValue[], value = 0n): OfficeCall => ({ data: encodeCall(OFFICE_SIGNATURES[sig], v), value });
35
+ const u = (name: string, x: bigint, bits: number): bigint => {
36
+ if (x < 0n || x >= 1n << BigInt(bits)) throw new RangeError(`${name} is a u${bits}`);
37
+ return x;
38
+ };
39
+ const id = (officeId: string): string => {
40
+ if (!/^0x[0-9a-fA-F]{64}$/.test(officeId) || /^0x0+$/.test(officeId)) throw new RangeError("officeId is 32 non-zero bytes (0x hex)");
41
+ return officeId;
42
+ };
43
+
44
+ export const officeOpenCall = (p: { officeId: string; quote: string }): OfficeCall => call("officeOpen", [id(p.officeId), p.quote]);
45
+ export const officeAddMemberCall = (p: { officeId: string; member: string }): OfficeCall => call("officeAddMember", [id(p.officeId), p.member]);
46
+ export const officeRemoveMemberCall = (p: { officeId: string; member: string }): OfficeCall => call("officeRemoveMember", [id(p.officeId), p.member]);
47
+ export const officeLeaveCall = (p: { officeId: string }): OfficeCall => call("officeLeave", [id(p.officeId)]);
48
+
49
+ export const officeDepositCall = (p: { officeId: string; amount: bigint; nativeQuote?: boolean }): OfficeCall =>
50
+ call("officeDeposit", [id(p.officeId), u("amount", p.amount, 256)], p.nativeQuote ? p.amount : 0n);
51
+ export const officeSetShareCall = (p: { officeId: string; member: string; shareBps: number }): OfficeCall => {
52
+ if (!Number.isInteger(p.shareBps) || p.shareBps < 0 || p.shareBps > 10_000) throw new RangeError("shareBps is 0..=10000 (ShareSum)");
53
+ return call("officeSetShare", [id(p.officeId), p.member, BigInt(p.shareBps)]);
54
+ };
55
+ export const officeBuyCall = (p: { officeId: string; launchId: bigint; gross: bigint; minTokens: bigint }): OfficeCall =>
56
+ call("officeBuy", [id(p.officeId), u("launchId", p.launchId, 256), u("gross", p.gross, 256), u("minTokens", p.minTokens, 256)]);
57
+ export const officeSellCall = (p: { officeId: string; launchId: bigint; buyer: string; tokens: bigint; minOut: bigint }): OfficeCall =>
58
+ call("officeSell", [id(p.officeId), u("launchId", p.launchId, 256), p.buyer, u("tokens", p.tokens, 256), u("minOut", p.minOut, 256)]);
59
+
60
+ export const officeProposeControllerCall = (p: { officeId: string; member?: string }): OfficeCall => call("officeProposeController", [id(p.officeId), p.member ?? ZERO_ADDRESS]);
61
+ export const officeAcceptControllerCall = (p: { officeId: string }): OfficeCall => call("officeAcceptController", [id(p.officeId)]);
62
+ export const officeProposeMergeCall = (p: { officeId: string; other: string; newController: string }): OfficeCall => call("officeProposeMerge", [id(p.officeId), id(p.other), p.newController]);
63
+ export const officeAcceptMergeCall = (p: { officeId: string; other: string; newController: string }): OfficeCall => call("officeAcceptMerge", [id(p.officeId), id(p.other), p.newController]);
64
+ export const officeCancelMergeCall = (p: { officeId: string }): OfficeCall => call("officeCancelMerge", [id(p.officeId)]);
65
+
66
+ export const officeMergeStepCall = (p: { officeId: string }): OfficeCall => call("officeMergeStep", [id(p.officeId)]);
67
+ export const officeOfCall = (p: { officeId: string }): OfficeCall => call("officeOf", [id(p.officeId)]);
68
+ export const officeMemberOfCall = (p: { officeId: string; member: string }): OfficeCall => call("officeMemberOf", [id(p.officeId), p.member]);
69
+ export const officeValueCall = (p: { officeId: string }): OfficeCall => call("officeValue", [id(p.officeId)]);
70
+
71
+ export function decodeOfficeMemberOf(ret: Uint8Array | string): { units: bigint; shareBps: number } {
72
+ const [units, shareBps] = decodeAbi(["uint256", "uint16"], ret) as [bigint, bigint];
73
+ return { units, shareBps: Number(shareBps) };
74
+ }
75
+
76
+ export const decodeOfficeValue = (ret: Uint8Array | string): bigint => decodeAbi(["uint256"], ret)[0] as bigint;