@misofm/sdk 0.6.0 → 0.8.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.
- package/README.md +37 -29
- package/dist/client.d.ts +46 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +97 -6
- package/dist/client.js.map +1 -1
- package/dist/contracts/release_registry/release_registry.d.ts +114 -0
- package/dist/contracts/release_registry/release_registry.d.ts.map +1 -0
- package/dist/contracts/release_registry/release_registry.js +119 -0
- package/dist/contracts/release_registry/release_registry.js.map +1 -0
- package/dist/contracts/royalty_pool/pool.d.ts +28 -2
- package/dist/contracts/royalty_pool/pool.d.ts.map +1 -1
- package/dist/contracts/royalty_pool/pool.js +28 -2
- package/dist/contracts/royalty_pool/pool.js.map +1 -1
- package/dist/contracts/utils/index.d.ts +44 -0
- package/dist/contracts/utils/index.d.ts.map +1 -1
- package/dist/contracts/utils/index.js +104 -2
- package/dist/contracts/utils/index.js.map +1 -1
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +4 -1
- package/dist/contracts.js.map +1 -1
- package/dist/cover.d.ts +3 -6
- package/dist/cover.d.ts.map +1 -1
- package/dist/cover.js +7 -16
- package/dist/cover.js.map +1 -1
- package/dist/credits.d.ts.map +1 -1
- package/dist/credits.js +17 -43
- package/dist/credits.js.map +1 -1
- package/dist/deployments.d.ts +95 -0
- package/dist/deployments.d.ts.map +1 -0
- package/dist/deployments.js +64 -0
- package/dist/deployments.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/read/catalog.d.ts +2 -12
- package/dist/read/catalog.d.ts.map +1 -1
- package/dist/read/catalog.js +9 -24
- package/dist/read/catalog.js.map +1 -1
- package/dist/read/config.d.ts +7 -9
- package/dist/read/config.d.ts.map +1 -1
- package/dist/read/config.js +24 -38
- package/dist/read/config.js.map +1 -1
- package/dist/read/index.d.ts +1 -1
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +1 -1
- package/dist/read/index.js.map +1 -1
- package/dist/read/types.d.ts +1 -1
- package/dist/read/types.d.ts.map +1 -1
- package/dist/read/wallet.d.ts +3 -7
- package/dist/read/wallet.d.ts.map +1 -1
- package/dist/read/wallet.js +11 -38
- package/dist/read/wallet.js.map +1 -1
- package/dist/read/works.d.ts +2 -5
- package/dist/read/works.d.ts.map +1 -1
- package/dist/read/works.js +7 -37
- package/dist/read/works.js.map +1 -1
- package/dist/release-graph.d.ts +6 -19
- package/dist/release-graph.d.ts.map +1 -1
- package/dist/release-graph.js +29 -43
- package/dist/release-graph.js.map +1 -1
- package/dist/transactions.d.ts +12 -28
- package/dist/transactions.d.ts.map +1 -1
- package/dist/transactions.js +23 -28
- package/dist/transactions.js.map +1 -1
- package/package.json +8 -4
- package/src/client.ts +152 -10
- package/src/contracts/release_registry/release_registry.ts +160 -0
- package/src/contracts/royalty_pool/pool.ts +28 -2
- package/src/contracts/utils/index.ts +156 -4
- package/src/contracts.ts +5 -1
- package/src/cover.ts +8 -19
- package/src/credits.ts +23 -63
- package/src/deployments.ts +148 -0
- package/src/index.ts +6 -3
- package/src/read/catalog.ts +9 -29
- package/src/read/config.ts +29 -46
- package/src/read/index.ts +0 -1
- package/src/read/types.ts +1 -1
- package/src/read/wallet.ts +11 -37
- package/src/read/works.ts +5 -42
- package/src/release-graph.ts +40 -75
- package/src/transactions.ts +33 -62
package/src/client.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
// (https://sdk.mystenlabs.com/sui/sdk-building). Register it once and the
|
|
6
6
|
// platform layer hangs off whatever client you already have:
|
|
7
7
|
//
|
|
8
|
-
// const client = new SuiGrpcClient({ network, baseUrl })
|
|
9
|
-
// .$extend(misoPlatform({ packageId, settingsId }));
|
|
8
|
+
// const client = new SuiGrpcClient({ network, baseUrl }).$extend(miso());
|
|
10
9
|
//
|
|
11
|
-
// await client.
|
|
12
|
-
//
|
|
10
|
+
// await client.miso.getSale({ releaseId, currencyType });
|
|
11
|
+
// await client.miso.protocol.getReleaseById(releaseId);
|
|
12
|
+
// tx.add(client.miso.tx.buyRecord({ releaseId, currencyType, amount, recipient }));
|
|
13
13
|
//
|
|
14
14
|
// Two things this buys over calling the bare functions:
|
|
15
15
|
//
|
|
@@ -26,11 +26,20 @@
|
|
|
26
26
|
// `tx` builds transactions without executing, `bcs` exposes the generated struct
|
|
27
27
|
// definitions, `ids` is the address math that replaces a registry.
|
|
28
28
|
|
|
29
|
-
import type {
|
|
29
|
+
import type {
|
|
30
|
+
ClientWithCoreApi,
|
|
31
|
+
SuiClientRegistration,
|
|
32
|
+
} from "@mysten/sui/client";
|
|
30
33
|
import type { Signer } from "@mysten/sui/cryptography";
|
|
34
|
+
import type { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
35
|
+
import {
|
|
36
|
+
miso as protocolMiso,
|
|
37
|
+
type MisoProtocolClient,
|
|
38
|
+
} from "@misonetwork/sdk/client";
|
|
31
39
|
|
|
32
40
|
import * as listingContract from "./contracts/miso_pressing/listing.ts";
|
|
33
41
|
import * as pressingContract from "./contracts/miso_pressing/pressing.ts";
|
|
42
|
+
import * as releaseRegistry from "./contracts/release_registry/release_registry.ts";
|
|
34
43
|
import {
|
|
35
44
|
buyRecord,
|
|
36
45
|
deriveListingId,
|
|
@@ -63,14 +72,42 @@ import {
|
|
|
63
72
|
publishComposition,
|
|
64
73
|
publishRecording,
|
|
65
74
|
publishCompositionAndRecording,
|
|
75
|
+
publishRelease,
|
|
66
76
|
} from "./transactions.ts";
|
|
67
77
|
import type {
|
|
68
78
|
TxThunk,
|
|
69
79
|
PublishCompositionParams,
|
|
70
80
|
PublishRecordingParams,
|
|
71
81
|
PublishCompositionAndRecordingParams,
|
|
82
|
+
PublishReleaseParams,
|
|
72
83
|
} from "./transactions.ts";
|
|
73
84
|
import * as share from "./share.ts";
|
|
85
|
+
import {
|
|
86
|
+
getMisoPlatformDeployment,
|
|
87
|
+
type MisoPlatformDeployment,
|
|
88
|
+
} from "./deployments.ts";
|
|
89
|
+
|
|
90
|
+
/** Defaults `options.package` to `pkg` for every generated call function. */
|
|
91
|
+
function bindModulePackage<M extends object>(mod: M, pkg: string): M {
|
|
92
|
+
const out: Record<string, unknown> = {};
|
|
93
|
+
for (const [key, value] of Object.entries({ ...mod })) {
|
|
94
|
+
out[key] =
|
|
95
|
+
typeof value === "function"
|
|
96
|
+
? (options: { package?: string }) =>
|
|
97
|
+
(value as (o: unknown) => unknown)({ package: pkg, ...options })
|
|
98
|
+
: value;
|
|
99
|
+
}
|
|
100
|
+
return out as M;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface MisoOptions<Name extends string = "miso"> {
|
|
104
|
+
/** Name for the client extension. Defaults to `miso`. */
|
|
105
|
+
name?: Name;
|
|
106
|
+
/** Complete custom deployment; omit to select the bundled client network. */
|
|
107
|
+
deployment?: MisoPlatformDeployment;
|
|
108
|
+
/** Required only by protocol methods that perform global type discovery. */
|
|
109
|
+
graphqlClient?: SuiGraphQLClient;
|
|
110
|
+
}
|
|
74
111
|
|
|
75
112
|
export interface MisoPlatformConfig {
|
|
76
113
|
/** The published `miso_pressing` package. */
|
|
@@ -93,6 +130,10 @@ export interface MisoPlatformConfig {
|
|
|
93
130
|
* builders (they disperse shares via minato).
|
|
94
131
|
*/
|
|
95
132
|
minatoPackageId?: string;
|
|
133
|
+
/** The published `release_registry` extension package used to mint releases. */
|
|
134
|
+
releaseRegistryPackageId?: string;
|
|
135
|
+
/** The one shared `ReleaseRegistry` object created by that package's `init`. */
|
|
136
|
+
releaseRegistryId?: string;
|
|
96
137
|
}
|
|
97
138
|
|
|
98
139
|
/** Params with the ids this client already knows dropped from the call site. */
|
|
@@ -101,13 +142,33 @@ type Configured<T> = Omit<T, "misoPressingPackageId" | "settingsId">;
|
|
|
101
142
|
/** Publish-builder params with the protocol/minato ids this client already knows dropped. */
|
|
102
143
|
type ConfiguredPublish<T> = Omit<T, "misoPackageId" | "minatoPackageId">;
|
|
103
144
|
|
|
145
|
+
/** Release-builder params with this client's core, share, and registry ids dropped. */
|
|
146
|
+
type ConfiguredRelease<T> = Omit<T, "misoPackageId" | "minatoPackageId" | "releaseRegistryPackageId" | "releaseRegistryId">;
|
|
147
|
+
|
|
104
148
|
export class MisoPlatformClient {
|
|
105
149
|
readonly #client: ClientWithCoreApi;
|
|
106
150
|
readonly #config: MisoPlatformConfig;
|
|
151
|
+
/** The permissionless protocol layer wrapped by this platform facade. */
|
|
152
|
+
readonly protocol: MisoProtocolClient;
|
|
153
|
+
/** Bundled/custom deployment selected for the full facade, when available. */
|
|
154
|
+
readonly deployment?: MisoPlatformDeployment;
|
|
107
155
|
|
|
108
|
-
constructor(
|
|
156
|
+
constructor(
|
|
157
|
+
client: ClientWithCoreApi,
|
|
158
|
+
config: MisoPlatformConfig,
|
|
159
|
+
protocol?: MisoProtocolClient,
|
|
160
|
+
deployment?: MisoPlatformDeployment,
|
|
161
|
+
) {
|
|
109
162
|
this.#client = client;
|
|
110
163
|
this.#config = config;
|
|
164
|
+
this.protocol =
|
|
165
|
+
protocol ??
|
|
166
|
+
protocolMiso({
|
|
167
|
+
deployment: config.misoPackageId
|
|
168
|
+
? { packageId: config.misoPackageId }
|
|
169
|
+
: undefined,
|
|
170
|
+
}).register(client);
|
|
171
|
+
this.deployment = deployment;
|
|
111
172
|
}
|
|
112
173
|
|
|
113
174
|
get packageId(): string {
|
|
@@ -129,7 +190,7 @@ export class MisoPlatformClient {
|
|
|
129
190
|
if (!misoPackageId) {
|
|
130
191
|
throw new Error(
|
|
131
192
|
"misoPlatform: `misoPackageId` is required for the publish builders " +
|
|
132
|
-
"(publishComposition, publishRecording, publishCompositionAndRecording) — pass it to misoPlatform({ misoPackageId }).",
|
|
193
|
+
"(publishComposition, publishRecording, publishCompositionAndRecording, publishRelease) — pass it to misoPlatform({ misoPackageId }).",
|
|
133
194
|
);
|
|
134
195
|
}
|
|
135
196
|
return misoPackageId;
|
|
@@ -146,6 +207,16 @@ export class MisoPlatformClient {
|
|
|
146
207
|
return minatoPackageId;
|
|
147
208
|
}
|
|
148
209
|
|
|
210
|
+
#releaseRegistry(): { packageId: string; id: string } {
|
|
211
|
+
const { releaseRegistryPackageId: packageId, releaseRegistryId: id } = this.#config;
|
|
212
|
+
if (!packageId || !id) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
"misoPlatform: `releaseRegistryPackageId` and `releaseRegistryId` are required to build a release — pass both to misoPlatform(...).",
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return { packageId, id };
|
|
218
|
+
}
|
|
219
|
+
|
|
149
220
|
// ── Reads ─────────────────────────────────────────────────────────────────
|
|
150
221
|
|
|
151
222
|
/** The run itself, or `null` if this release has never opened one. */
|
|
@@ -211,6 +282,15 @@ export class MisoPlatformClient {
|
|
|
211
282
|
publishRecording({ ...p, misoPackageId: this.#misoPackageId(), minatoPackageId: this.#minatoPackageId() }),
|
|
212
283
|
publishCompositionAndRecording: (p: ConfiguredPublish<PublishCompositionAndRecordingParams>): TxThunk =>
|
|
213
284
|
publishCompositionAndRecording({ ...p, misoPackageId: this.#misoPackageId(), minatoPackageId: this.#minatoPackageId() }),
|
|
285
|
+
publishRelease: (p: ConfiguredRelease<PublishReleaseParams>): TxThunk => {
|
|
286
|
+
const registry = this.#releaseRegistry();
|
|
287
|
+
return publishRelease({
|
|
288
|
+
...p,
|
|
289
|
+
misoPackageId: this.#misoPackageId(),
|
|
290
|
+
releaseRegistryPackageId: registry.packageId,
|
|
291
|
+
releaseRegistryId: registry.id,
|
|
292
|
+
});
|
|
293
|
+
},
|
|
214
294
|
};
|
|
215
295
|
|
|
216
296
|
// ── Share currency provisioning (executes; Signer pattern) ─────────────────
|
|
@@ -223,7 +303,18 @@ export class MisoPlatformClient {
|
|
|
223
303
|
// ── Generated layer ───────────────────────────────────────────────────────
|
|
224
304
|
|
|
225
305
|
/** Generated Move-call bindings, for commands this facade doesn't wrap. */
|
|
226
|
-
|
|
306
|
+
get call() {
|
|
307
|
+
return {
|
|
308
|
+
listing: bindModulePackage(listingContract, this.packageId),
|
|
309
|
+
pressing: bindModulePackage(pressingContract, this.packageId),
|
|
310
|
+
releaseRegistry: this.#config.releaseRegistryPackageId
|
|
311
|
+
? bindModulePackage(
|
|
312
|
+
releaseRegistry,
|
|
313
|
+
this.#config.releaseRegistryPackageId,
|
|
314
|
+
)
|
|
315
|
+
: releaseRegistry,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
227
318
|
|
|
228
319
|
/** Generated BCS definitions, for parsing objects or events yourself. */
|
|
229
320
|
readonly bcs = {
|
|
@@ -231,11 +322,53 @@ export class MisoPlatformClient {
|
|
|
231
322
|
PressingAdminCap: pressingContract.PressingAdminCap,
|
|
232
323
|
Listing: listingContract.Listing,
|
|
233
324
|
Price: listingContract.Price,
|
|
325
|
+
ReleaseRegistry: releaseRegistry.ReleaseRegistry,
|
|
326
|
+
ReleaseRegistryCreatedEvent: releaseRegistry.ReleaseRegistryCreatedEvent,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** The full Miso client exposed by `@misofm/sdk`. */
|
|
331
|
+
export { MisoPlatformClient as MisoClient };
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Registers the complete Miso facade at `client.miso`.
|
|
335
|
+
*
|
|
336
|
+
* Platform operations live directly on `client.miso`; the lower-level
|
|
337
|
+
* permissionless protocol SDK is available at `client.miso.protocol`.
|
|
338
|
+
*/
|
|
339
|
+
export function miso<const Name extends string = "miso">(
|
|
340
|
+
options: MisoOptions<Name> = {},
|
|
341
|
+
): SuiClientRegistration<ClientWithCoreApi, Name, MisoPlatformClient> {
|
|
342
|
+
const name = (options.name ?? "miso") as Name;
|
|
343
|
+
return {
|
|
344
|
+
name,
|
|
345
|
+
register: (client: ClientWithCoreApi) => {
|
|
346
|
+
const deployment =
|
|
347
|
+
options.deployment ?? getMisoPlatformDeployment(client.network);
|
|
348
|
+
const protocol = protocolMiso({
|
|
349
|
+
deployment: deployment.protocol,
|
|
350
|
+
graphqlClient: options.graphqlClient,
|
|
351
|
+
}).register(client);
|
|
352
|
+
return new MisoPlatformClient(
|
|
353
|
+
client,
|
|
354
|
+
{
|
|
355
|
+
packageId: deployment.packages.pressing,
|
|
356
|
+
settingsId: deployment.objects.recordSettings,
|
|
357
|
+
misoPackageId: deployment.protocol.packageId,
|
|
358
|
+
minatoPackageId: deployment.packages.minato,
|
|
359
|
+
releaseRegistryPackageId: deployment.packages.releaseRegistry,
|
|
360
|
+
releaseRegistryId: deployment.objects.releaseRegistry,
|
|
361
|
+
},
|
|
362
|
+
protocol,
|
|
363
|
+
deployment,
|
|
364
|
+
);
|
|
365
|
+
},
|
|
234
366
|
};
|
|
235
367
|
}
|
|
236
368
|
|
|
237
369
|
/**
|
|
238
|
-
*
|
|
370
|
+
* @deprecated Prefer zero-config `miso()`, which registers the complete facade
|
|
371
|
+
* at `client.miso` and exposes the protocol layer at `client.miso.protocol`.
|
|
239
372
|
*
|
|
240
373
|
* `settingsId` is optional so a read-only client (an indexer, a catalog page) can
|
|
241
374
|
* skip it; asking to build a purchase without it throws rather than sending a
|
|
@@ -244,6 +377,15 @@ export class MisoPlatformClient {
|
|
|
244
377
|
export function misoPlatform(config: MisoPlatformConfig) {
|
|
245
378
|
return {
|
|
246
379
|
name: "misoPlatform" as const,
|
|
247
|
-
register: (client: ClientWithCoreApi) =>
|
|
380
|
+
register: (client: ClientWithCoreApi) => {
|
|
381
|
+
const protocol = protocolMiso({
|
|
382
|
+
deployment: config.misoPackageId
|
|
383
|
+
? {
|
|
384
|
+
packageId: config.misoPackageId,
|
|
385
|
+
}
|
|
386
|
+
: undefined,
|
|
387
|
+
}).register(client);
|
|
388
|
+
return new MisoPlatformClient(client, config, protocol);
|
|
389
|
+
},
|
|
248
390
|
};
|
|
249
391
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The recommended canonical parent namespace for `miso::release::new`.
|
|
8
|
+
*
|
|
9
|
+
* `miso::release::new` takes `parent: &mut UID` and derives every release's id
|
|
10
|
+
* from `(parent, digest)`: core is deliberately parent-agnostic and implements no
|
|
11
|
+
* coordination policy of its own (see the "Consent scope" section of
|
|
12
|
+
* `miso::release`'s module doc). This package supplies the one recommended parent
|
|
13
|
+
* — a shared, permissionless, undeletable `UID` — and is deliberately the _only_
|
|
14
|
+
* policy it implements: it neither gates who may assemble a release through it nor
|
|
15
|
+
* interprets what a `Track` means.
|
|
16
|
+
*
|
|
17
|
+
* ### One instance, ever
|
|
18
|
+
*
|
|
19
|
+
* The module exposes no constructor: the only `ReleaseRegistry` that can ever
|
|
20
|
+
* exist is the canonical one created and shared by package initialization. "The
|
|
21
|
+
* registry" is therefore unambiguous on-chain — the type itself names the
|
|
22
|
+
* namespace, not a config convention. Every `new_release` takes `&mut` on that one
|
|
23
|
+
* shared object, so release creation through it serializes per checkpoint; the
|
|
24
|
+
* ceiling is accepted — releases are rare events. Alternative namespaces are still
|
|
25
|
+
* possible, but they live in other packages: core is parent-agnostic, and any
|
|
26
|
+
* object exposing a `&mut UID` (a release escrow, for instance) can parent its own
|
|
27
|
+
* releases; ids derived under different parents never collide, by construction of
|
|
28
|
+
* `derive_address`.
|
|
29
|
+
*
|
|
30
|
+
* ### Liveness
|
|
31
|
+
*
|
|
32
|
+
* The canonical instance is shared at publish, and this module exposes no delete
|
|
33
|
+
* function and no `uid_mut`: its only capability is being a derivation parent.
|
|
34
|
+
* That undeletability is a consent guarantee, not an accident — a `Track`'s
|
|
35
|
+
* `target_release_id` commits to this namespace's liveness (see `miso::release`'s
|
|
36
|
+
* module doc), and a deletable parent would strand every track and offer that ever
|
|
37
|
+
* targeted it. Keeping the surface to exactly one capability is what makes that
|
|
38
|
+
* guarantee durable: there is nothing else here to reason about.
|
|
39
|
+
*
|
|
40
|
+
* ### Permissionless
|
|
41
|
+
*
|
|
42
|
+
* No capability gates `new_release`: anyone holding a fully-formed `vector<Track>`
|
|
43
|
+
* may assemble and claim a release through this registry. That is not a gap —
|
|
44
|
+
* consent already lives in the `Track`s themselves, each one minted by its
|
|
45
|
+
* recording's admin via cap-gated `miso::track::new` against this exact digest.
|
|
46
|
+
* Assembly is bookkeeping over consent already given, not a second authorization
|
|
47
|
+
* step.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
|
|
51
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
52
|
+
import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
|
|
53
|
+
const $moduleName = '@local-pkg/release_registry::release_registry';
|
|
54
|
+
export const ReleaseRegistry = new MoveStruct({ name: `${$moduleName}::ReleaseRegistry`, fields: {
|
|
55
|
+
id: bcs.Address
|
|
56
|
+
} });
|
|
57
|
+
export const ReleaseRegistryCreatedEvent = new MoveStruct({ name: `${$moduleName}::ReleaseRegistryCreatedEvent`, fields: {
|
|
58
|
+
registry_id: bcs.Address,
|
|
59
|
+
created_by: bcs.Address
|
|
60
|
+
} });
|
|
61
|
+
export interface NewReleaseArguments {
|
|
62
|
+
self: RawTransactionArgument<string>;
|
|
63
|
+
title: RawTransactionArgument<string>;
|
|
64
|
+
tracks: TransactionArgument;
|
|
65
|
+
nonce: RawTransactionArgument<number | bigint>;
|
|
66
|
+
}
|
|
67
|
+
export interface NewReleaseOptions {
|
|
68
|
+
package?: string;
|
|
69
|
+
arguments: NewReleaseArguments | [
|
|
70
|
+
self: RawTransactionArgument<string>,
|
|
71
|
+
title: RawTransactionArgument<string>,
|
|
72
|
+
tracks: TransactionArgument,
|
|
73
|
+
nonce: RawTransactionArgument<number | bigint>
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Assembles a release by delegating to `miso::release::new` with this registry as
|
|
78
|
+
* parent. Returns the `(Release, ReleaseAdminCap)` pair rather than transferring
|
|
79
|
+
* or sharing either: the release is not on-chain-final until `release::publish`
|
|
80
|
+
* consumes it by value — typically later in the same PTB — and where the cap ends
|
|
81
|
+
* up is the caller's decision, not this function's.
|
|
82
|
+
*/
|
|
83
|
+
export function newRelease(options: NewReleaseOptions) {
|
|
84
|
+
const packageAddress = options.package ?? '@local-pkg/release_registry';
|
|
85
|
+
const argumentsTypes = [
|
|
86
|
+
null,
|
|
87
|
+
'0x1::string::String',
|
|
88
|
+
'vector<null>',
|
|
89
|
+
'u256'
|
|
90
|
+
] satisfies (string | null)[];
|
|
91
|
+
const parameterNames = ["self", "title", "tracks", "nonce"];
|
|
92
|
+
return (tx: Transaction) => tx.moveCall({
|
|
93
|
+
package: packageAddress,
|
|
94
|
+
module: 'release_registry',
|
|
95
|
+
function: 'new_release',
|
|
96
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export interface DeriveTargetReleaseIdArguments {
|
|
100
|
+
self: RawTransactionArgument<string>;
|
|
101
|
+
recordingIds: RawTransactionArgument<Array<string>>;
|
|
102
|
+
trackSplitValues: RawTransactionArgument<Array<number | bigint>>;
|
|
103
|
+
nonce: RawTransactionArgument<number | bigint>;
|
|
104
|
+
}
|
|
105
|
+
export interface DeriveTargetReleaseIdOptions {
|
|
106
|
+
package?: string;
|
|
107
|
+
arguments: DeriveTargetReleaseIdArguments | [
|
|
108
|
+
self: RawTransactionArgument<string>,
|
|
109
|
+
recordingIds: RawTransactionArgument<Array<string>>,
|
|
110
|
+
trackSplitValues: RawTransactionArgument<Array<number | bigint>>,
|
|
111
|
+
nonce: RawTransactionArgument<number | bigint>
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Derives the release id `new_release` would produce for the given inputs under
|
|
116
|
+
* this registry, without creating anything. Delegates to
|
|
117
|
+
* `miso::release::derive_target_release_id` with this registry's own id as parent.
|
|
118
|
+
*/
|
|
119
|
+
export function deriveTargetReleaseId(options: DeriveTargetReleaseIdOptions) {
|
|
120
|
+
const packageAddress = options.package ?? '@local-pkg/release_registry';
|
|
121
|
+
const argumentsTypes = [
|
|
122
|
+
null,
|
|
123
|
+
'vector<0x2::object::ID>',
|
|
124
|
+
'vector<u64>',
|
|
125
|
+
'u256'
|
|
126
|
+
] satisfies (string | null)[];
|
|
127
|
+
const parameterNames = ["self", "recordingIds", "trackSplitValues", "nonce"];
|
|
128
|
+
return (tx: Transaction) => tx.moveCall({
|
|
129
|
+
package: packageAddress,
|
|
130
|
+
module: 'release_registry',
|
|
131
|
+
function: 'derive_target_release_id',
|
|
132
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export interface IdArguments {
|
|
136
|
+
self: RawTransactionArgument<string>;
|
|
137
|
+
}
|
|
138
|
+
export interface IdOptions {
|
|
139
|
+
package?: string;
|
|
140
|
+
arguments: IdArguments | [
|
|
141
|
+
self: RawTransactionArgument<string>
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the registry's object id — the derivation parent that
|
|
146
|
+
* `derive_target_release_id` and `new_release` both commit to.
|
|
147
|
+
*/
|
|
148
|
+
export function id(options: IdOptions) {
|
|
149
|
+
const packageAddress = options.package ?? '@local-pkg/release_registry';
|
|
150
|
+
const argumentsTypes = [
|
|
151
|
+
null
|
|
152
|
+
] satisfies (string | null)[];
|
|
153
|
+
const parameterNames = ["self"];
|
|
154
|
+
return (tx: Transaction) => tx.moveCall({
|
|
155
|
+
package: packageAddress,
|
|
156
|
+
module: 'release_registry',
|
|
157
|
+
function: 'id',
|
|
158
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Accumulator-based royalty distribution pool for the protocol's share tokens.
|
|
8
8
|
*
|
|
9
9
|
* A `RoyaltyPool<Share, Currency>` is a derived object of any UID-bearing parent.
|
|
10
10
|
* Its address is deterministically derived from `(parent_id, Currency)` — at most
|
|
@@ -21,7 +21,33 @@
|
|
|
21
21
|
* transfers or balances credited to the pool's funds-accumulator. Both are
|
|
22
22
|
* permissionless: anyone who notices stuck funds can fold them in. The canonical
|
|
23
23
|
* funding path remains `deposit(balance)` from a higher-layer extension (e.g.
|
|
24
|
-
* `composition_royalty_distributor`) that pulls from the parent's address.
|
|
24
|
+
* `composition_royalty_distributor`) that pulls from the parent's address. Note
|
|
25
|
+
* the recovery valves run through `deposit`, which aborts while no shares are
|
|
26
|
+
* staked — and the pool has no other withdrawal path — so funds sent to the pool's
|
|
27
|
+
* address before the first registration stay locked until a stake registers.
|
|
28
|
+
* Payers should always target the parent's address, never the pool's.
|
|
29
|
+
*
|
|
30
|
+
* ### No activation delay (deliberate)
|
|
31
|
+
*
|
|
32
|
+
* Registration earns from the next deposit onward; there is no bonding or
|
|
33
|
+
* unbonding period (contrast Sui native staking's next-epoch activation). With the
|
|
34
|
+
* protocol's fixed-supply share token this is safe: a stake's take of any deposit
|
|
35
|
+
* is `v · s / S` with `S` (total registered) bounded by the share supply, so a
|
|
36
|
+
* continuously registered stake is guaranteed at least its pro-rata share of total
|
|
37
|
+
* supply on every deposit. Short-lived or just-in-time registrations can only
|
|
38
|
+
* compete for the _unregistered_ supply's drift — the designed incentive for being
|
|
39
|
+
* registered — never below any registered stake's floor.
|
|
40
|
+
*
|
|
41
|
+
* ### Precision
|
|
42
|
+
*
|
|
43
|
+
* The share token's shape is fixed at issuance by the protocol — exactly 10¹³ base
|
|
44
|
+
* units, 6 decimals, supply made immutable via `miso_share::share::initialize`
|
|
45
|
+
* (`make_supply_fixed`) — so `staked_shares ≤ 10¹³` objectively. A deposit of
|
|
46
|
+
* `value ≥ 1` base units therefore advances the accumulator by
|
|
47
|
+
* `value · PRECISION / staked_shares ≥ 10¹⁸ / 10¹³ = 10⁵`: the truncation-to-zero
|
|
48
|
+
* case that would permanently lock a deposit in the pool balance is impossible by
|
|
49
|
+
* construction, not by convention. Sub-base-unit claim residue (the remaining
|
|
50
|
+
* source of locked dust) is documented on `unregister_stake`.
|
|
25
51
|
*/
|
|
26
52
|
|
|
27
53
|
import { MoveStruct, MoveTuple, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
BcsEnum,
|
|
9
9
|
BcsTuple,
|
|
10
10
|
} from '@mysten/sui/bcs';
|
|
11
|
-
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
11
|
+
import { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';
|
|
12
12
|
import { type TransactionArgument, isArgument } from '@mysten/sui/transactions';
|
|
13
13
|
import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
|
|
14
14
|
|
|
@@ -158,10 +158,140 @@ export function normalizeMoveArguments(
|
|
|
158
158
|
return normalizedArgs;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/* -------------------------- Move type tags -------------------------- */
|
|
162
|
+
|
|
163
|
+
/** A type argument: a type tag string, or a BCS type whose name is a Move type. */
|
|
164
|
+
export type TypeArgument = string | BcsType<any>;
|
|
165
|
+
|
|
166
|
+
export interface TypeTagOptions {
|
|
167
|
+
package?: string;
|
|
168
|
+
typeArguments?: readonly TypeArgument[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* `typeArguments` is required when the type's name contains unfilled
|
|
173
|
+
* `phantom X` parameters (at any depth). Everything else — argument arity,
|
|
174
|
+
* position contents, and tag validity — is validated at runtime.
|
|
175
|
+
*/
|
|
176
|
+
type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`
|
|
177
|
+
? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]
|
|
178
|
+
: [options?: TypeTagOptions];
|
|
179
|
+
|
|
180
|
+
type ResolveTypeTagOptions<Name extends string> = { client: ClientWithCoreApi } & (
|
|
181
|
+
Name extends `${string}phantom ${string}`
|
|
182
|
+
? TypeTagOptions & { typeArguments: readonly TypeArgument[] }
|
|
183
|
+
: TypeTagOptions
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
|
|
187
|
+
|
|
188
|
+
function splitTopLevelTypeArgs(inner: string): string[] {
|
|
189
|
+
const parts: string[] = [];
|
|
190
|
+
let depth = 0;
|
|
191
|
+
let current = '';
|
|
192
|
+
for (const char of inner) {
|
|
193
|
+
if (char === ',' && depth === 0) {
|
|
194
|
+
parts.push(current.trim());
|
|
195
|
+
current = '';
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (char === '<') depth++;
|
|
199
|
+
if (char === '>') depth--;
|
|
200
|
+
current += char;
|
|
201
|
+
}
|
|
202
|
+
if (current) parts.push(current.trim());
|
|
203
|
+
return parts;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildTypeTag(name: string, options: TypeTagOptions | undefined): string {
|
|
207
|
+
const lt = name.indexOf('<');
|
|
208
|
+
const base = lt === -1 ? name : name.slice(0, lt);
|
|
209
|
+
|
|
210
|
+
if (base.split('::').length !== 3) {
|
|
211
|
+
throw new Error(`${name} is not a top-level Move type`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let result = name;
|
|
215
|
+
|
|
216
|
+
if (options?.typeArguments) {
|
|
217
|
+
const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
|
|
218
|
+
const supplied = options.typeArguments.map((arg) => {
|
|
219
|
+
if (typeof arg === 'string') {
|
|
220
|
+
return arg;
|
|
221
|
+
}
|
|
222
|
+
if (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {
|
|
223
|
+
return arg.name;
|
|
224
|
+
}
|
|
225
|
+
throw new Error(`Invalid type argument ${stringify(arg)}`);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
if (supplied.length !== baked.length) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
result = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (HAS_PHANTOM_REGEX.test(result)) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
options?.typeArguments
|
|
240
|
+
? `A type argument contains an unfilled phantom parameter in ${result}`
|
|
241
|
+
: `Missing type arguments for ${result}`,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (options?.package) {
|
|
246
|
+
const [, ...rest] = result.split('::');
|
|
247
|
+
result = [options.package, ...rest].join('::');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// fully validate address-only tags (MVR names can't be parsed as type tags)
|
|
251
|
+
if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {
|
|
252
|
+
TypeTagSerializer.parseFromStr(result);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function resolveBuiltTypeTag(
|
|
259
|
+
name: string,
|
|
260
|
+
options: { client: ClientWithCoreApi } & TypeTagOptions,
|
|
261
|
+
): Promise<string> {
|
|
262
|
+
const { client, ...rest } = options;
|
|
263
|
+
const { type } = await client.core.mvr.resolveType({
|
|
264
|
+
type: buildTypeTag(name, rest),
|
|
265
|
+
});
|
|
266
|
+
return normalizeStructTag(type);
|
|
267
|
+
}
|
|
268
|
+
|
|
161
269
|
export class MoveStruct<
|
|
162
270
|
T extends Record<string, BcsType<any>>,
|
|
163
271
|
const Name extends string = string,
|
|
164
272
|
> extends BcsStruct<T, Name> {
|
|
273
|
+
/**
|
|
274
|
+
* Build the type tag for this struct.
|
|
275
|
+
*
|
|
276
|
+
* `typeArguments` is the full positional list, in Move declaration order, and
|
|
277
|
+
* is required when the struct has unfilled phantom parameters. The result may
|
|
278
|
+
* contain MVR names: those are valid in transaction `typeArguments`, but for
|
|
279
|
+
* queries or comparisons against on-chain data use `resolveTypeTag` instead.
|
|
280
|
+
*/
|
|
281
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
282
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Build the type tag for this struct, then resolve any MVR names through the
|
|
287
|
+
* client (using its configured overrides and the MVR API) and return the
|
|
288
|
+
* normalized, address-only form suitable for queries and comparisons against
|
|
289
|
+
* on-chain data.
|
|
290
|
+
*/
|
|
291
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
292
|
+
return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
|
|
293
|
+
}
|
|
294
|
+
|
|
165
295
|
async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
166
296
|
objectId,
|
|
167
297
|
...options
|
|
@@ -210,16 +340,38 @@ export class MoveStruct<
|
|
|
210
340
|
export class MoveEnum<
|
|
211
341
|
T extends Record<string, BcsType<any> | null>,
|
|
212
342
|
const Name extends string,
|
|
213
|
-
> extends BcsEnum<T, Name> {
|
|
343
|
+
> extends BcsEnum<T, Name> {
|
|
344
|
+
/** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */
|
|
345
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
346
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */
|
|
350
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
351
|
+
return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
214
354
|
|
|
215
355
|
export class MoveTuple<
|
|
216
356
|
const T extends readonly BcsType<any>[],
|
|
217
357
|
const Name extends string,
|
|
218
|
-
> extends BcsTuple<T, Name> {
|
|
358
|
+
> extends BcsTuple<T, Name> {
|
|
359
|
+
/** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */
|
|
360
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
361
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */
|
|
365
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
366
|
+
return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
219
369
|
|
|
220
370
|
function stringify(val: unknown) {
|
|
221
371
|
if (typeof val === 'object') {
|
|
222
|
-
return JSON.stringify(val, (
|
|
372
|
+
return JSON.stringify(val, (_key, value) =>
|
|
373
|
+
typeof value === 'bigint' ? value.toString() : value,
|
|
374
|
+
);
|
|
223
375
|
}
|
|
224
376
|
if (typeof val === 'bigint') {
|
|
225
377
|
return val.toString();
|
package/src/contracts.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Move calls). Re-exported from the package root as the `contracts` namespace.
|
|
6
6
|
//
|
|
7
7
|
// PLATFORM + EXTENSION packages. The protocol core (`miso`: Composition,
|
|
8
|
-
// Recording, Release,
|
|
8
|
+
// Recording, Release, Track) generates into `@misonetwork/sdk` and is
|
|
9
9
|
// re-exported from ITS `contracts` namespace — import it from there rather than
|
|
10
10
|
// mirroring it here.
|
|
11
11
|
|
|
@@ -14,6 +14,10 @@ export * as pressing from "./contracts/miso_pressing/pressing.ts";
|
|
|
14
14
|
export * as listing from "./contracts/miso_pressing/listing.ts";
|
|
15
15
|
export * as certificate from "./contracts/miso_pressing/certificate.ts";
|
|
16
16
|
|
|
17
|
+
// The canonical release-id derivation parent — the only PTB-callable path to
|
|
18
|
+
// minting a `Release` now that core's `release::new` takes `&mut UID`.
|
|
19
|
+
export * as releaseRegistry from "./contracts/release_registry/release_registry.ts";
|
|
20
|
+
|
|
17
21
|
// Existing launch drops remain readable and purchasable while releases move to
|
|
18
22
|
// the pressing/listing contracts.
|
|
19
23
|
export * as drop from "./contracts/miso_drop/drop.ts";
|