@interest-protocol/blast-core 0.0.0-stage → 0.1.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 (97) hide show
  1. package/README.md +8 -2
  2. package/dist/arrays.d.ts +3 -0
  3. package/dist/arrays.d.ts.map +1 -0
  4. package/dist/arrays.js +9 -0
  5. package/dist/arrays.js.map +1 -0
  6. package/dist/bcs.d.ts +16 -0
  7. package/dist/bcs.d.ts.map +1 -0
  8. package/dist/bcs.js +29 -0
  9. package/dist/bcs.js.map +1 -0
  10. package/dist/bytecode-template.d.ts +67 -0
  11. package/dist/bytecode-template.d.ts.map +1 -0
  12. package/dist/bytecode-template.js +175 -0
  13. package/dist/bytecode-template.js.map +1 -0
  14. package/dist/cetus.d.ts +14 -0
  15. package/dist/cetus.d.ts.map +1 -0
  16. package/dist/cetus.js +13 -0
  17. package/dist/cetus.js.map +1 -0
  18. package/dist/coins.d.ts +20 -0
  19. package/dist/coins.d.ts.map +1 -0
  20. package/dist/coins.js +2 -0
  21. package/dist/coins.js.map +1 -0
  22. package/dist/events.d.ts +14 -0
  23. package/dist/events.d.ts.map +1 -0
  24. package/dist/events.js +43 -0
  25. package/dist/events.js.map +1 -0
  26. package/dist/gas.d.ts +26 -0
  27. package/dist/gas.d.ts.map +1 -0
  28. package/dist/gas.js +130 -0
  29. package/dist/gas.js.map +1 -0
  30. package/dist/index.d.ts +14 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +14 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/integers.d.ts +36 -0
  35. package/dist/integers.d.ts.map +1 -0
  36. package/dist/integers.js +70 -0
  37. package/dist/integers.js.map +1 -0
  38. package/dist/merkle.d.ts +12 -0
  39. package/dist/merkle.d.ts.map +1 -0
  40. package/dist/merkle.js +41 -0
  41. package/dist/merkle.js.map +1 -0
  42. package/dist/migration-math.d.ts +15 -0
  43. package/dist/migration-math.d.ts.map +1 -0
  44. package/dist/migration-math.js +64 -0
  45. package/dist/migration-math.js.map +1 -0
  46. package/dist/ptb.d.ts +9 -0
  47. package/dist/ptb.d.ts.map +1 -0
  48. package/dist/ptb.js +14 -0
  49. package/dist/ptb.js.map +1 -0
  50. package/dist/rewards/allocations.d.ts +98 -0
  51. package/dist/rewards/allocations.d.ts.map +1 -0
  52. package/dist/rewards/allocations.js +475 -0
  53. package/dist/rewards/allocations.js.map +1 -0
  54. package/dist/rewards/checkpoints.d.ts +34 -0
  55. package/dist/rewards/checkpoints.d.ts.map +1 -0
  56. package/dist/rewards/checkpoints.js +94 -0
  57. package/dist/rewards/checkpoints.js.map +1 -0
  58. package/dist/rewards/holders.d.ts +35 -0
  59. package/dist/rewards/holders.d.ts.map +1 -0
  60. package/dist/rewards/holders.js +106 -0
  61. package/dist/rewards/holders.js.map +1 -0
  62. package/dist/rewards/keeper.d.ts +17 -0
  63. package/dist/rewards/keeper.d.ts.map +1 -0
  64. package/dist/rewards/keeper.js +21 -0
  65. package/dist/rewards/keeper.js.map +1 -0
  66. package/dist/rewards/state.d.ts +55 -0
  67. package/dist/rewards/state.d.ts.map +1 -0
  68. package/dist/rewards/state.js +80 -0
  69. package/dist/rewards/state.js.map +1 -0
  70. package/dist/sui.d.ts +22 -0
  71. package/dist/sui.d.ts.map +1 -0
  72. package/dist/sui.js +58 -0
  73. package/dist/sui.js.map +1 -0
  74. package/dist/timelock.d.ts +15 -0
  75. package/dist/timelock.d.ts.map +1 -0
  76. package/dist/timelock.js +30 -0
  77. package/dist/timelock.js.map +1 -0
  78. package/package.json +112 -4
  79. package/src/arrays.ts +8 -0
  80. package/src/bcs.ts +41 -0
  81. package/src/bytecode-template.ts +257 -0
  82. package/src/cetus.ts +28 -0
  83. package/src/coins.ts +19 -0
  84. package/src/events.ts +64 -0
  85. package/src/gas.ts +162 -0
  86. package/src/index.ts +13 -0
  87. package/src/integers.ts +103 -0
  88. package/src/merkle.ts +47 -0
  89. package/src/migration-math.ts +81 -0
  90. package/src/ptb.ts +35 -0
  91. package/src/rewards/allocations.ts +710 -0
  92. package/src/rewards/checkpoints.ts +143 -0
  93. package/src/rewards/holders.ts +149 -0
  94. package/src/rewards/keeper.ts +45 -0
  95. package/src/rewards/state.ts +113 -0
  96. package/src/sui.ts +105 -0
  97. package/src/timelock.ts +47 -0
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @interest-protocol/blast-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The core package in the [Blast SDK monorepo](https://github.com/interest-protocol/blast-v2-sdk).
4
+
5
+ ```sh
6
+ npm install @interest-protocol/blast-core
7
+ ```
8
+
9
+ See the repository README and docs for usage, development, and release guidance.
@@ -0,0 +1,3 @@
1
+ /** `values.at(index)`, throwing instead of returning `undefined`. */
2
+ export declare function itemAt<T>(values: readonly T[], index: number): T;
3
+ //# sourceMappingURL=arrays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAMhE"}
package/dist/arrays.js ADDED
@@ -0,0 +1,9 @@
1
+ /** `values.at(index)`, throwing instead of returning `undefined`. */
2
+ export function itemAt(values, index) {
3
+ const value = values.at(index);
4
+ if (value === undefined) {
5
+ throw new RangeError(`index ${index} is outside ${values.length} items`);
6
+ }
7
+ return value;
8
+ }
9
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.js","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAI,MAAoB,EAAE,KAAa;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,UAAU,CAAC,SAAS,KAAK,eAAe,MAAM,CAAC,MAAM,QAAQ,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/bcs.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export declare const suiIdBcs: import("@mysten/sui/bcs").BcsStruct<{
2
+ bytes: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
3
+ }, string>;
4
+ export declare const suiUidBcs: import("@mysten/sui/bcs").BcsStruct<{
5
+ id: import("@mysten/sui/bcs").BcsStruct<{
6
+ bytes: import("@mysten/sui/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
7
+ }, string>;
8
+ }, string>;
9
+ export declare const suiBalanceBcs: import("@mysten/sui/bcs").BcsStruct<{
10
+ value: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
11
+ }, string>;
12
+ export declare const suiObjectIdBcs: import("@mysten/sui/bcs").BcsType<string, string, string>;
13
+ export declare const moveTypeNameBcs: import("@mysten/sui/bcs").BcsType<string, string, string>;
14
+ export declare const u64Bcs: import("@mysten/sui/bcs").BcsType<bigint, bigint, "u64">;
15
+ export declare const addressBcs: import("@mysten/sui/bcs").BcsType<string, string, "bytes[32]">;
16
+ //# sourceMappingURL=bcs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bcs.d.ts","sourceRoot":"","sources":["../src/bcs.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,QAAQ;;UAA2C,CAAC;AACjE,eAAO,MAAM,SAAS;;;;UAAsC,CAAC;AAC7D,eAAO,MAAM,aAAa;;UAA8C,CAAC;AAEzE,eAAO,MAAM,cAAc,2DAGzB,CAAC;AAMH,eAAO,MAAM,eAAe,2DAUxB,CAAC;AAEL,eAAO,MAAM,MAAM,0DAGjB,CAAC;AAEH,eAAO,MAAM,UAAU,gEAGrB,CAAC"}
package/dist/bcs.js ADDED
@@ -0,0 +1,29 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ import { normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, } from "@mysten/sui/utils";
3
+ export const suiIdBcs = bcs.struct("ID", { bytes: bcs.Address });
4
+ export const suiUidBcs = bcs.struct("UID", { id: suiIdBcs });
5
+ export const suiBalanceBcs = bcs.struct("Balance", { value: bcs.u64() });
6
+ export const suiObjectIdBcs = suiIdBcs.transform({
7
+ input: (value) => ({ bytes: normalizeSuiObjectId(value) }),
8
+ output: (value) => normalizeSuiObjectId(value.bytes),
9
+ });
10
+ const asciiStringBcs = bcs.struct("AsciiString", {
11
+ bytes: bcs.vector(bcs.u8()),
12
+ });
13
+ export const moveTypeNameBcs = bcs
14
+ .struct("TypeName", { name: asciiStringBcs })
15
+ .transform({
16
+ input: (value) => ({
17
+ name: { bytes: Array.from(new TextEncoder().encode(value)) },
18
+ }),
19
+ output: (value) => normalizeStructTag(new TextDecoder().decode(Uint8Array.from(value.name.bytes))),
20
+ });
21
+ export const u64Bcs = bcs.u64().transform({
22
+ input: (value) => value,
23
+ output: (value) => BigInt(value),
24
+ });
25
+ export const addressBcs = bcs.Address.transform({
26
+ input: (value) => normalizeSuiAddress(value),
27
+ output: (value) => normalizeSuiAddress(value),
28
+ });
29
+ //# sourceMappingURL=bcs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bcs.js","sourceRoot":"","sources":["../src/bcs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACjE,MAAM,CAAC,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,SAAS,CAAC;IACxC,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK;IAC/B,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;CACjC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;IAC9C,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC;IACpD,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC;CAC9C,CAAC,CAAC"}
@@ -0,0 +1,67 @@
1
+ export type CompiledConstant = {
2
+ type_: unknown;
3
+ data: number[];
4
+ };
5
+ export type CompiledModule = Record<string, unknown> & {
6
+ address_identifiers: string[];
7
+ constant_pool: CompiledConstant[];
8
+ function_handles: {
9
+ module: number;
10
+ name: number;
11
+ }[];
12
+ identifiers: string[];
13
+ module_handles: {
14
+ address: number;
15
+ name: number;
16
+ }[];
17
+ function_defs: {
18
+ code: {
19
+ code: unknown[];
20
+ } | null;
21
+ }[];
22
+ };
23
+ /** One constant the template patches: its pool type, compiled default, and new value. */
24
+ export type ConstantPatch = {
25
+ name: string;
26
+ type: string;
27
+ expected: Uint8Array;
28
+ replacement: Uint8Array;
29
+ };
30
+ export type BytecodeTemplateInitOptions = {
31
+ module_or_path?: unknown;
32
+ };
33
+ /**
34
+ * Initializes the bytecode-template WASM helper once for every template. A
35
+ * browser can supply its WASM URL when the bundler cannot discover the package
36
+ * asset automatically.
37
+ */
38
+ export declare function initializeBytecodeTemplate(options?: BytecodeTemplateInitOptions): Promise<void>;
39
+ /** Deserializes a template module and checks the tables patching reads. */
40
+ export declare function deserializeTemplate(label: string, bytecode: Uint8Array): CompiledModule;
41
+ /**
42
+ * Replaces each patch's one constant, found by pool type and compiled default,
43
+ * then merges any constants the replacements made equal. Every slot is resolved
44
+ * before any is written, so replacements may swap values between slots of the
45
+ * same type.
46
+ */
47
+ export declare function patchConstantSlots(label: string, compiled: CompiledModule, patches: readonly ConstantPatch[]): void;
48
+ /**
49
+ * Rejects a module or witness name that another identifier of the template
50
+ * already uses, other than the placeholders it replaces.
51
+ */
52
+ export declare function assertIdentifierSlots(label: string, compiled: CompiledModule, placeholders: readonly string[], identifiers: {
53
+ moduleName: string;
54
+ witnessName: string;
55
+ }): void;
56
+ /**
57
+ * Derives the module and one-time-witness names from a symbol, the same
58
+ * transformation as Blast V1: the witness is the uppercased symbol and the
59
+ * module its lowercase form, spaces becoming underscores.
60
+ */
61
+ export declare function deriveTemplateIdentifiers(symbol: string, requestedModuleName?: string): {
62
+ moduleName: string;
63
+ witnessName: string;
64
+ };
65
+ export declare function requireString(name: string, value: string): string;
66
+ export declare function requireNonEmptyString(name: string, value: string): string;
67
+ //# sourceMappingURL=bytecode-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytecode-template.d.ts","sourceRoot":"","sources":["../src/bytecode-template.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACrD,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,gBAAgB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACpD,aAAa,EAAE;QAAE,IAAI,EAAE;YAAE,IAAI,EAAE,OAAO,EAAE,CAAA;SAAE,GAAG,IAAI,CAA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175 @@
1
+ import initBytecodeTemplate, { deserialize, } from "@mysten/move-bytecode-template";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+ let initialization;
4
+ /**
5
+ * Initializes the bytecode-template WASM helper once for every template. A
6
+ * browser can supply its WASM URL when the bundler cannot discover the package
7
+ * asset automatically.
8
+ */
9
+ export function initializeBytecodeTemplate(options) {
10
+ if (initialization)
11
+ return initialization;
12
+ const pending = Promise.resolve(initBytecodeTemplate(options)).then(() => undefined);
13
+ initialization = pending.catch((error) => {
14
+ initialization = undefined;
15
+ throw error;
16
+ });
17
+ return initialization;
18
+ }
19
+ /** Deserializes a template module and checks the tables patching reads. */
20
+ export function deserializeTemplate(label, bytecode) {
21
+ const value = deserialize(bytecode);
22
+ if (!isRecord(value))
23
+ throw new TypeError(`${label} is not a module`);
24
+ if (!isStringArray(value.address_identifiers) ||
25
+ !Array.isArray(value.constant_pool) ||
26
+ !Array.isArray(value.function_handles) ||
27
+ !isStringArray(value.identifiers) ||
28
+ !Array.isArray(value.module_handles) ||
29
+ !Array.isArray(value.function_defs)) {
30
+ throw new TypeError(`${label} has invalid module tables`);
31
+ }
32
+ return value;
33
+ }
34
+ /**
35
+ * Replaces each patch's one constant, found by pool type and compiled default,
36
+ * then merges any constants the replacements made equal. Every slot is resolved
37
+ * before any is written, so replacements may swap values between slots of the
38
+ * same type.
39
+ */
40
+ export function patchConstantSlots(label, compiled, patches) {
41
+ const targets = patches.map((patch) => {
42
+ const matches = compiled.constant_pool.flatMap((constant, index) => constantTypeName(constant.type_) === patch.type &&
43
+ bytesEqual(constant.data, patch.expected)
44
+ ? [index]
45
+ : []);
46
+ if (matches.length !== 1) {
47
+ throw new TypeError(`${label} must have one ${patch.name} constant slot`);
48
+ }
49
+ return matches[0];
50
+ });
51
+ if (new Set(targets).size !== targets.length) {
52
+ throw new TypeError(`${label} constant slots must be distinct`);
53
+ }
54
+ patches.forEach((patch, patchIndex) => {
55
+ const target = targets[patchIndex];
56
+ if (target === undefined)
57
+ throw new TypeError("Missing constant slot");
58
+ const constant = compiled.constant_pool[target];
59
+ if (!constant)
60
+ throw new TypeError("Missing constant");
61
+ constant.data = Array.from(patch.replacement);
62
+ });
63
+ mergeDuplicateConstants(compiled);
64
+ }
65
+ /**
66
+ * The bytecode verifier rejects a module whose constant pool holds the same
67
+ * type and value twice (`DUPLICATE_ELEMENT`), which patching produces whenever
68
+ * two slots of one type receive equal values: one recipient for every
69
+ * capability, a name equal to the symbol, or two false flags. Each duplicate's
70
+ * loads move to the last copy, which keeps a module's error constants, declared
71
+ * after its settings, at their indices for clever-error decoding. The freed
72
+ * slot becomes a unique `vector<u8>` that nothing loads, so no other index
73
+ * shifts.
74
+ */
75
+ function mergeDuplicateConstants(compiled) {
76
+ const pool = compiled.constant_pool;
77
+ const lastIndex = new Map(pool.map((constant, index) => [constantKey(constant), index]));
78
+ const redirects = new Map();
79
+ pool.forEach((constant, index) => {
80
+ const kept = lastIndex.get(constantKey(constant));
81
+ if (kept !== undefined && kept !== index)
82
+ redirects.set(index, kept);
83
+ });
84
+ if (redirects.size === 0)
85
+ return;
86
+ for (const definition of compiled.function_defs) {
87
+ for (const instruction of definition.code?.code ?? []) {
88
+ if (isRecord(instruction) && typeof instruction.LdConst === "number") {
89
+ instruction.LdConst =
90
+ redirects.get(instruction.LdConst) ?? instruction.LdConst;
91
+ }
92
+ }
93
+ }
94
+ for (const index of redirects.keys()) {
95
+ let attempt = 0;
96
+ let unused;
97
+ do {
98
+ unused = {
99
+ type_: { Vector: "U8" },
100
+ data: Array.from(bcs
101
+ .string()
102
+ .serialize(`\u0000unused-constant-${index}-${attempt++}`)
103
+ .toBytes()),
104
+ };
105
+ } while (lastIndex.has(constantKey(unused)));
106
+ pool[index] = unused;
107
+ lastIndex.set(constantKey(unused), index);
108
+ }
109
+ }
110
+ function constantKey(constant) {
111
+ return `${constantTypeName(constant.type_)}:${constant.data.join(",")}`;
112
+ }
113
+ /**
114
+ * Rejects a module or witness name that another identifier of the template
115
+ * already uses, other than the placeholders it replaces.
116
+ */
117
+ export function assertIdentifierSlots(label, compiled, placeholders, identifiers) {
118
+ const occupied = new Set(compiled.identifiers.filter((identifier) => !placeholders.includes(identifier)));
119
+ if (occupied.has(identifiers.moduleName)) {
120
+ throw new RangeError(`moduleName ${identifiers.moduleName} collides with the ${label}`);
121
+ }
122
+ if (occupied.has(identifiers.witnessName)) {
123
+ throw new RangeError(`witnessName ${identifiers.witnessName} collides with the ${label}`);
124
+ }
125
+ }
126
+ /**
127
+ * Derives the module and one-time-witness names from a symbol, the same
128
+ * transformation as Blast V1: the witness is the uppercased symbol and the
129
+ * module its lowercase form, spaces becoming underscores.
130
+ */
131
+ export function deriveTemplateIdentifiers(symbol, requestedModuleName) {
132
+ const normalizedSymbol = requireNonEmptyString("symbol", symbol);
133
+ const witnessName = normalizedSymbol.toUpperCase().replaceAll(" ", "_");
134
+ const moduleName = requestedModuleName ?? normalizedSymbol.toLowerCase().replaceAll(" ", "_");
135
+ if (!/^[A-Z][A-Z0-9_]*$/.test(witnessName)) {
136
+ throw new RangeError("symbol must produce an uppercase Move witness identifier");
137
+ }
138
+ if (!/^[a-z][a-z0-9_]*$/.test(moduleName)) {
139
+ throw new RangeError("moduleName must start with a lowercase letter and contain only lowercase letters, digits, or underscores");
140
+ }
141
+ return { moduleName, witnessName };
142
+ }
143
+ export function requireString(name, value) {
144
+ if (typeof value !== "string") {
145
+ throw new TypeError(`${name} must be a string`);
146
+ }
147
+ return value;
148
+ }
149
+ export function requireNonEmptyString(name, value) {
150
+ const normalized = requireString(name, value).trim();
151
+ if (!normalized)
152
+ throw new RangeError(`${name} must not be empty`);
153
+ return normalized;
154
+ }
155
+ function constantTypeName(value) {
156
+ if (typeof value === "string")
157
+ return value;
158
+ if (!isRecord(value))
159
+ return "";
160
+ const entries = Object.entries(value);
161
+ if (entries.length !== 1 || !entries[0])
162
+ return "";
163
+ return `${entries[0][0]}(${constantTypeName(entries[0][1])})`;
164
+ }
165
+ function bytesEqual(left, right) {
166
+ return (left.length === right.length &&
167
+ left.every((value, index) => value === right[index]));
168
+ }
169
+ function isRecord(value) {
170
+ return typeof value === "object" && value !== null;
171
+ }
172
+ function isStringArray(value) {
173
+ return (Array.isArray(value) && value.every((item) => typeof item === "string"));
174
+ }
175
+ //# sourceMappingURL=bytecode-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytecode-template.js","sourceRoot":"","sources":["../src/bytecode-template.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,EAAE,EAC3B,WAAW,GACZ,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AA+BtC,IAAI,cAAyC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAqC;IAErC,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAE1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CACjE,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;IACF,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAChD,cAAc,GAAG,SAAS,CAAC;QAC3B,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CACjC,KAAa,EACb,QAAoB;IAEpB,MAAM,KAAK,GAAY,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,kBAAkB,CAAC,CAAC;IACtE,IACE,CAAC,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC;QACzC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC;QACnC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,g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I,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CACxE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Cetus orders a pool's coin types by type name. `a` means Meme is coin A
3
+ * (`Pool<Meme, Quote>`); `b` means Quote is coin A (`Pool<Quote, Meme>`).
4
+ * Every Cetus route after `new` takes `<Meme, Quote, CoinA, CoinB>`
5
+ * (contracts ADR 0100); the SDK derives `CoinA` and `CoinB` from this side.
6
+ */
7
+ export type CetusMemeSide = "a" | "b";
8
+ /**
9
+ * Cetus orders a pool's coins by `type_name::with_defining_ids` text (64 hex
10
+ * digits, no `0x`); Meme is coin A exactly when its name sorts after Quote's.
11
+ * Pass original (defining) type addresses.
12
+ */
13
+ export declare function cetusMemeSide(memeType: string, quoteType: string): CetusMemeSide;
14
+ //# sourceMappingURL=cetus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cetus.d.ts","sourceRoot":"","sources":["../src/cetus.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,CAAC;AAEtC;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,aAAa,CAEf"}
package/dist/cetus.js ADDED
@@ -0,0 +1,13 @@
1
+ import { normalizeStructTag, parseStructTag } from "@mysten/sui/utils";
2
+ /**
3
+ * Cetus orders a pool's coins by `type_name::with_defining_ids` text (64 hex
4
+ * digits, no `0x`); Meme is coin A exactly when its name sorts after Quote's.
5
+ * Pass original (defining) type addresses.
6
+ */
7
+ export function cetusMemeSide(memeType, quoteType) {
8
+ return cetusTypeName(memeType) > cetusTypeName(quoteType) ? "a" : "b";
9
+ }
10
+ function cetusTypeName(type) {
11
+ return normalizeStructTag(parseStructTag(type)).replace(/0x([0-9a-f]{64})/g, "$1");
12
+ }
13
+ //# sourceMappingURL=cetus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cetus.js","sourceRoot":"","sources":["../src/cetus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAUvE;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAgB,EAChB,SAAiB;IAEjB,OAAO,aAAa,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACxE,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CACrD,mBAAmB,EACnB,IAAI,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * How a transaction builder sources the SUI the transaction itself spends: a
3
+ * fee, a deposit, or a SUI-quoted purchase. Other coin types always come from
4
+ * the sender's coins and address balance.
5
+ *
6
+ * `useGasCoin` is passed to `@mysten/sui`'s `tx.coin`, whose default (`true`)
7
+ * withdraws from the sender's address balance when it covers the amount and
8
+ * otherwise splits the gas coin. Pass `false` when someone else pays gas: a
9
+ * sponsored transaction's gas coin belongs to the sponsor, who may reject a
10
+ * transaction that uses it as an argument or end up paying the sender's SUI.
11
+ * With `false`, the SUI comes from the sender's coins and address balance, so
12
+ * a self-paying sender needs SUI beyond what gas selection takes.
13
+ *
14
+ * Builders take it at construction and per call; the per-call value wins,
15
+ * and both default to `true`, `@mysten/sui`'s own default.
16
+ */
17
+ export type CoinSourceOptions = Readonly<{
18
+ useGasCoin?: boolean;
19
+ }>;
20
+ //# sourceMappingURL=coins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../src/coins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC,CAAC"}
package/dist/coins.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=coins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coins.js","sourceRoot":"","sources":["../src/coins.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export type SuiEventPosition = {
2
+ checkpoint: bigint;
3
+ transactionDigest: string;
4
+ eventIndex: number;
5
+ };
6
+ export type NativeTransactionPosition = Pick<SuiEventPosition, "checkpoint" | "transactionDigest">;
7
+ export declare function normalizeSuiEventPosition(input: {
8
+ checkpoint: bigint | number | string | null;
9
+ transactionDigest: string;
10
+ eventIndex: number;
11
+ }): SuiEventPosition;
12
+ export declare function normalizeNativeTransactionPosition(input: NativeTransactionPosition, label?: string): NativeTransactionPosition;
13
+ export declare function suiEventId(position: SuiEventPosition): string;
14
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,gBAAgB,EAChB,YAAY,GAAG,mBAAmB,CACnC,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,gBAAgB,CA4BnB;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,yBAAyB,EAChC,KAAK,GAAE,MAA6B,GACnC,yBAAyB,CAS3B;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAE7D"}
package/dist/events.js ADDED
@@ -0,0 +1,43 @@
1
+ import { requireU64 } from "./integers.js";
2
+ export function normalizeSuiEventPosition(input) {
3
+ if (input.checkpoint === null) {
4
+ throw new TypeError("event requires checkpoint metadata");
5
+ }
6
+ if (typeof input.checkpoint === "number" &&
7
+ !Number.isSafeInteger(input.checkpoint)) {
8
+ throw new TypeError("event checkpoint must be a u64");
9
+ }
10
+ let checkpoint;
11
+ try {
12
+ checkpoint = BigInt(input.checkpoint);
13
+ }
14
+ catch {
15
+ throw new TypeError("event checkpoint must be a u64");
16
+ }
17
+ requireU64("event checkpoint", checkpoint);
18
+ if (!input.transactionDigest) {
19
+ throw new TypeError("event transaction digest is required");
20
+ }
21
+ if (!Number.isSafeInteger(input.eventIndex) || input.eventIndex < 0) {
22
+ throw new RangeError("event index must be a non-negative integer");
23
+ }
24
+ return {
25
+ checkpoint,
26
+ transactionDigest: input.transactionDigest,
27
+ eventIndex: input.eventIndex,
28
+ };
29
+ }
30
+ export function normalizeNativeTransactionPosition(input, label = "native transaction") {
31
+ requireU64(`${label} checkpoint`, input.checkpoint);
32
+ if (!input.transactionDigest) {
33
+ throw new TypeError(`${label} transaction digest is required`);
34
+ }
35
+ return {
36
+ checkpoint: input.checkpoint,
37
+ transactionDigest: input.transactionDigest,
38
+ };
39
+ }
40
+ export function suiEventId(position) {
41
+ return `${position.transactionDigest}:${position.eventIndex}`;
42
+ }
43
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAa3C,MAAM,UAAU,yBAAyB,CAAC,KAIzC;IACC,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,C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C;AAED,MAAM,UAAU,UAAU,CAAC,QAA0B;IACnD,OAAO,GAAG,QAAQ,CAAC,iBAAiB,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;AAChE,CAAC"}
package/dist/gas.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { TransactionPlugin } from "@mysten/sui/transactions";
2
+ /**
3
+ * A build plugin that budgets a transaction at its gross cost plus headroom
4
+ * when the caller has not set a budget.
5
+ *
6
+ * `@mysten/sui` and the fullnode budget the simulated net cost (computation
7
+ * plus storage less rebate) plus 1,000 gas units, about 13 bytes of storage.
8
+ * Execution fails with `InsufficientGas` once `budget - computation < storage
9
+ * - rebate`, so a transaction whose execution writes more storage than its
10
+ * simulation runs out of gas. Cetus seeds a new pool's tick skip list from the
11
+ * clock, so creating a pool writes up to 18 more bytes in about one execution
12
+ * in four: a presale's Cetus migration ran out of gas that way on 2026-10-05.
13
+ * The SDK attaches this plugin to its Cetus migration and pool-creation calls;
14
+ * other transactions keep the default budget.
15
+ *
16
+ * The plugin probes once more and budgets the simulated computation plus all
17
+ * storage, ignoring the rebate, plus a fifth and 10,000 gas units. The charge
18
+ * is unchanged, since the rebate is still credited; only the ceiling rises. A
19
+ * payer that cannot cover that ceiling, given how `@mysten/sui` then picks its
20
+ * gas payment, keeps the default net budget. A transaction-kind build, a
21
+ * budget already set, no client, or a failing probe also leave the default
22
+ * resolver in charge, with its own errors. A plugin does not survive JSON
23
+ * serialization: add it again after `Transaction.from(json)`.
24
+ */
25
+ export declare function grossGasBudget(): TransactionPlugin;
26
+ //# sourceMappingURL=gas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../src/gas.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAoBlE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,IAAI,iBAAiB,CA6BlD"}