@interest-protocol/blast-admin-sdk 0.1.0 → 0.2.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.
@@ -1,6 +1,8 @@
1
+ import { requireU64 } from "@interest-protocol/blast-core/integers";
1
2
  import type { SharedObjectIdentity } from "@interest-protocol/blast-core/sui";
2
3
  import { normalizeSharedObjectIdentity } from "@interest-protocol/blast-core/sui";
3
4
  import type {
5
+ TransactionArgument,
4
6
  TransactionObjectArgument,
5
7
  TransactionObjectInput,
6
8
  } from "@mysten/sui/transactions";
@@ -11,7 +13,7 @@ import {
11
13
  normalizeSuiObjectId,
12
14
  } from "@mysten/sui/utils";
13
15
 
14
- /** The immutable `blast_admin` package and its shared singleton `blast_acl::ACL`. */
16
+ /** The canonical `blast_admin` package (immutability deferred) and its shared singleton `blast_acl::ACL`. */
15
17
  export type AdminDeployment = {
16
18
  packageId: string;
17
19
  acl: SharedObjectIdentity;
@@ -26,10 +28,38 @@ export function normalizeAdminDeployment(
26
28
  };
27
29
  }
28
30
 
31
+ /** `blast_admin::package_admin`'s roles, each generic over one package's OTW. */
32
+ export const PACKAGE_ROLES = [
33
+ "UpgradeAdmin",
34
+ "PauseAdmin",
35
+ "UnpauseAdmin",
36
+ "CancelAdmin",
37
+ ] as const;
38
+ export type PackageRole = (typeof PACKAGE_ROLES)[number];
39
+
40
+ /** `<admin>::package_admin::<role><otw>`: one package's infrastructure role. */
41
+ export function packageRoleType(
42
+ admin: Pick<AdminDeployment, "packageId">,
43
+ otw: string,
44
+ role: PackageRole,
45
+ ): string {
46
+ if (!PACKAGE_ROLES.includes(role))
47
+ throw new TypeError(`unknown package_admin role ${String(role)}`);
48
+ return normalizeStructTag(
49
+ `${normalizeSuiObjectId(admin.packageId)}::package_admin::${role}<${normalizeStructTag(otw)}>`,
50
+ );
51
+ }
52
+
53
+ /** One package's shared `PackageVersion<OTW>` or `PackageAdmin<OTW>` and its OTW type. */
54
+ type PackageObjectOptions<Name extends "packageVersion" | "packageAdmin"> = {
55
+ otw: string;
56
+ } & Record<Name, SharedObjectIdentity>;
57
+
29
58
  /**
30
- * `blast_admin::blast_acl` calls. A role is a Move type its consumer package
31
- * declares (for example `<launchpad>::blast_fun_domain::FeeAdmin`); each
32
- * product's `roleType` names its own.
59
+ * `blast_admin::blast_acl` and `blast_admin::package_admin` calls. A product
60
+ * role is a `blast_core::blast_domain` type (`coreRoleType`); a package role
61
+ * is `package_admin::<Role><OTW>` (`packageRoleType`). A product's own
62
+ * `unpause` and `make_immutable` wrappers live with the product.
33
63
  */
34
64
  export class AdminCalls {
35
65
  readonly deployment: AdminDeployment;
@@ -166,6 +196,111 @@ export class AdminCalls {
166
196
  };
167
197
  }
168
198
 
199
+ /** `package_admin::pause<OTW>` with a `PauseAdmin<OTW>` witness: sets `bits` now. */
200
+ pause(
201
+ options: PackageObjectOptions<"packageVersion"> & {
202
+ adminWitness: TransactionObjectInput;
203
+ bits: number;
204
+ },
205
+ ) {
206
+ const bits = requirePauseBits(options.bits);
207
+ return (tx: Transaction): void => {
208
+ tx.moveCall({
209
+ target: this.#packageAdminTarget("pause"),
210
+ typeArguments: [normalizeStructTag(options.otw)],
211
+ arguments: [
212
+ tx.sharedObjectRef({ ...options.packageVersion, mutable: true }),
213
+ tx.object(options.adminWitness),
214
+ tx.pure.u8(bits),
215
+ ],
216
+ });
217
+ };
218
+ }
219
+
220
+ /** `package_admin::schedule_upgrade<OTW>` of one 32-byte package digest. */
221
+ scheduleUpgrade(
222
+ options: PackageObjectOptions<"packageAdmin"> & {
223
+ adminWitness: TransactionObjectInput;
224
+ digest: Uint8Array;
225
+ },
226
+ ) {
227
+ if (options.digest.length !== 32)
228
+ throw new RangeError("a package digest is 32 bytes");
229
+ const digest = Array.from(options.digest);
230
+ return this.#upgradeCall(options, "schedule_upgrade", (tx) => [
231
+ tx.object(options.adminWitness),
232
+ tx.pure.vector("u8", digest),
233
+ tx.object.clock(),
234
+ ]);
235
+ }
236
+
237
+ /** `package_admin::schedule_make_immutable<OTW>`. */
238
+ scheduleMakeImmutable(
239
+ options: PackageObjectOptions<"packageAdmin"> & {
240
+ adminWitness: TransactionObjectInput;
241
+ },
242
+ ) {
243
+ return this.#upgradeCall(options, "schedule_make_immutable", (tx) => [
244
+ tx.object(options.adminWitness),
245
+ tx.object.clock(),
246
+ ]);
247
+ }
248
+
249
+ /** `package_admin::cancel_upgrade_action<OTW>` with a `CancelAdmin<OTW>` witness. */
250
+ cancelUpgradeAction(
251
+ options: PackageObjectOptions<"packageAdmin"> & {
252
+ adminWitness: TransactionObjectInput;
253
+ },
254
+ ) {
255
+ return this.#upgradeCall(options, "cancel_upgrade_action", (tx) => [
256
+ tx.object(options.adminWitness),
257
+ ]);
258
+ }
259
+
260
+ /** `package_admin::schedule_upgrade_delay<OTW>`: proposes only a new delay. */
261
+ scheduleUpgradeDelay(
262
+ options: PackageObjectOptions<"packageAdmin"> & {
263
+ adminWitness: TransactionObjectInput;
264
+ delayMs: bigint;
265
+ },
266
+ ) {
267
+ const delayMs = requireU64("delayMs", options.delayMs);
268
+ return this.#upgradeCall(options, "schedule_upgrade_delay", (tx) => [
269
+ tx.object(options.adminWitness),
270
+ tx.pure.u64(delayMs),
271
+ tx.object.clock(),
272
+ ]);
273
+ }
274
+
275
+ /** `package_admin::apply_upgrade_delay<OTW>`: anyone, once ready. */
276
+ applyUpgradeDelay(options: PackageObjectOptions<"packageAdmin">) {
277
+ return this.#upgradeCall(options, "apply_upgrade_delay", (tx) => [
278
+ tx.object.clock(),
279
+ ]);
280
+ }
281
+
282
+ #upgradeCall(
283
+ options: PackageObjectOptions<"packageAdmin">,
284
+ functionName: string,
285
+ rest: (tx: Transaction) => TransactionArgument[],
286
+ ) {
287
+ const otw = normalizeStructTag(options.otw);
288
+ return (tx: Transaction): void => {
289
+ tx.moveCall({
290
+ target: this.#packageAdminTarget(functionName),
291
+ typeArguments: [otw],
292
+ arguments: [
293
+ tx.sharedObjectRef({ ...options.packageAdmin, mutable: true }),
294
+ ...rest(tx),
295
+ ],
296
+ });
297
+ };
298
+ }
299
+
300
+ #packageAdminTarget(functionName: string): string {
301
+ return `${this.deployment.packageId}::package_admin::${functionName}`;
302
+ }
303
+
169
304
  #roleCall(
170
305
  functionName: "grant_role" | "revoke_role",
171
306
  options: {
@@ -287,6 +422,16 @@ export class AdminTransactions {
287
422
  }
288
423
  }
289
424
 
425
+ /**
426
+ * Pause bits are a nonzero mask within `valid` (a package's
427
+ * `valid_pause_bits`; any `u8` when the package checks them itself).
428
+ */
429
+ export function requirePauseBits(bits: number, valid = 0xff): number {
430
+ if (!Number.isInteger(bits) || bits <= 0 || (bits & ~valid) !== 0)
431
+ throw new RangeError(`pause bits must be a nonzero mask within ${valid}`);
432
+ return bits;
433
+ }
434
+
290
435
  function single(call: (tx: Transaction) => void): Transaction {
291
436
  const tx = new Transaction();
292
437
  tx.add(call);