@misonetwork/sdk 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.
- package/LICENSE +201 -0
- package/README.md +644 -0
- package/dist/client.d.ts +197 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +218 -0
- package/dist/client.js.map +1 -0
- package/dist/contracts/composition_credits/composition_credits.d.ts +181 -0
- package/dist/contracts/composition_credits/composition_credits.d.ts.map +1 -0
- package/dist/contracts/composition_credits/composition_credits.js +109 -0
- package/dist/contracts/composition_credits/composition_credits.js.map +1 -0
- package/dist/contracts/composition_credits/composition_party_role.d.ts +119 -0
- package/dist/contracts/composition_credits/composition_party_role.d.ts.map +1 -0
- package/dist/contracts/composition_credits/composition_party_role.js +139 -0
- package/dist/contracts/composition_credits/composition_party_role.js.map +1 -0
- package/dist/contracts/composition_credits/deps/miso_credit/credit.d.ts +24 -0
- package/dist/contracts/composition_credits/deps/miso_credit/credit.d.ts.map +1 -0
- package/dist/contracts/composition_credits/deps/miso_credit/credit.js +23 -0
- package/dist/contracts/composition_credits/deps/miso_credit/credit.js.map +1 -0
- package/dist/contracts/composition_credits/deps/sui/vec_map.d.ts +37 -0
- package/dist/contracts/composition_credits/deps/sui/vec_map.d.ts.map +1 -0
- package/dist/contracts/composition_credits/deps/sui/vec_map.js +28 -0
- package/dist/contracts/composition_credits/deps/sui/vec_map.js.map +1 -0
- package/dist/contracts/composition_royalty_pool/composition_royalty_pool.d.ts +87 -0
- package/dist/contracts/composition_royalty_pool/composition_royalty_pool.d.ts.map +1 -0
- package/dist/contracts/composition_royalty_pool/composition_royalty_pool.js +80 -0
- package/dist/contracts/composition_royalty_pool/composition_royalty_pool.js.map +1 -0
- package/dist/contracts/cover_art/cover_art.d.ts +85 -0
- package/dist/contracts/cover_art/cover_art.d.ts.map +1 -0
- package/dist/contracts/cover_art/cover_art.js +68 -0
- package/dist/contracts/cover_art/cover_art.js.map +1 -0
- package/dist/contracts/cover_art/deps/ori/walrus_data.d.ts +52 -0
- package/dist/contracts/cover_art/deps/ori/walrus_data.d.ts.map +1 -0
- package/dist/contracts/cover_art/deps/ori/walrus_data.js +37 -0
- package/dist/contracts/cover_art/deps/ori/walrus_data.js.map +1 -0
- package/dist/contracts/miso/composition.d.ts +231 -0
- package/dist/contracts/miso/composition.d.ts.map +1 -0
- package/dist/contracts/miso/composition.js +231 -0
- package/dist/contracts/miso/composition.js.map +1 -0
- package/dist/contracts/miso/deal.d.ts +184 -0
- package/dist/contracts/miso/deal.d.ts.map +1 -0
- package/dist/contracts/miso/deal.js +184 -0
- package/dist/contracts/miso/deal.js.map +1 -0
- package/dist/contracts/miso/deps/bps/bps.d.ts +19 -0
- package/dist/contracts/miso/deps/bps/bps.d.ts.map +1 -0
- package/dist/contracts/miso/deps/bps/bps.js +21 -0
- package/dist/contracts/miso/deps/bps/bps.js.map +1 -0
- package/dist/contracts/miso/recording.d.ts +228 -0
- package/dist/contracts/miso/recording.d.ts.map +1 -0
- package/dist/contracts/miso/recording.js +221 -0
- package/dist/contracts/miso/recording.js.map +1 -0
- package/dist/contracts/miso/release.d.ts +280 -0
- package/dist/contracts/miso/release.d.ts.map +1 -0
- package/dist/contracts/miso/release.js +282 -0
- package/dist/contracts/miso/release.js.map +1 -0
- package/dist/contracts/miso/track.d.ts +118 -0
- package/dist/contracts/miso/track.d.ts.map +1 -0
- package/dist/contracts/miso/track.js +118 -0
- package/dist/contracts/miso/track.js.map +1 -0
- package/dist/contracts/recording_credits/deps/miso_credit/credit.d.ts +24 -0
- package/dist/contracts/recording_credits/deps/miso_credit/credit.d.ts.map +1 -0
- package/dist/contracts/recording_credits/deps/miso_credit/credit.js +23 -0
- package/dist/contracts/recording_credits/deps/miso_credit/credit.js.map +1 -0
- package/dist/contracts/recording_credits/deps/sui/vec_map.d.ts +37 -0
- package/dist/contracts/recording_credits/deps/sui/vec_map.d.ts.map +1 -0
- package/dist/contracts/recording_credits/deps/sui/vec_map.js +28 -0
- package/dist/contracts/recording_credits/deps/sui/vec_map.js.map +1 -0
- package/dist/contracts/recording_credits/deps/sui/vec_set.d.ts +21 -0
- package/dist/contracts/recording_credits/deps/sui/vec_set.d.ts.map +1 -0
- package/dist/contracts/recording_credits/deps/sui/vec_set.js +20 -0
- package/dist/contracts/recording_credits/deps/sui/vec_set.js.map +1 -0
- package/dist/contracts/recording_credits/recording_credits.d.ts +2313 -0
- package/dist/contracts/recording_credits/recording_credits.d.ts.map +1 -0
- package/dist/contracts/recording_credits/recording_credits.js +270 -0
- package/dist/contracts/recording_credits/recording_credits.js.map +1 -0
- package/dist/contracts/recording_credits/recording_party_role.d.ts +1174 -0
- package/dist/contracts/recording_credits/recording_party_role.d.ts.map +1 -0
- package/dist/contracts/recording_credits/recording_party_role.js +692 -0
- package/dist/contracts/recording_credits/recording_party_role.js.map +1 -0
- package/dist/contracts/recording_royalty_pool/recording_royalty_pool.d.ts +90 -0
- package/dist/contracts/recording_royalty_pool/recording_royalty_pool.d.ts.map +1 -0
- package/dist/contracts/recording_royalty_pool/recording_royalty_pool.js +80 -0
- package/dist/contracts/recording_royalty_pool/recording_royalty_pool.js.map +1 -0
- package/dist/contracts/release_cover_art/deps/0x340057f2174fb59e4626742dd2b46c662237837b6187450cb59e4976ce7eac78/walrus_data.d.ts +52 -0
- package/dist/contracts/release_cover_art/deps/0x340057f2174fb59e4626742dd2b46c662237837b6187450cb59e4976ce7eac78/walrus_data.d.ts.map +1 -0
- package/dist/contracts/release_cover_art/deps/0x340057f2174fb59e4626742dd2b46c662237837b6187450cb59e4976ce7eac78/walrus_data.js +37 -0
- package/dist/contracts/release_cover_art/deps/0x340057f2174fb59e4626742dd2b46c662237837b6187450cb59e4976ce7eac78/walrus_data.js.map +1 -0
- package/dist/contracts/release_cover_art/deps/cover_art/cover_art.d.ts +46 -0
- package/dist/contracts/release_cover_art/deps/cover_art/cover_art.d.ts.map +1 -0
- package/dist/contracts/release_cover_art/deps/cover_art/cover_art.js +21 -0
- package/dist/contracts/release_cover_art/deps/cover_art/cover_art.js.map +1 -0
- package/dist/contracts/release_cover_art/deps/per_track/per_track.d.ts +33 -0
- package/dist/contracts/release_cover_art/deps/per_track/per_track.d.ts.map +1 -0
- package/dist/contracts/release_cover_art/deps/per_track/per_track.js +32 -0
- package/dist/contracts/release_cover_art/deps/per_track/per_track.js.map +1 -0
- package/dist/contracts/release_cover_art/release_cover_art.d.ts +300 -0
- package/dist/contracts/release_cover_art/release_cover_art.d.ts.map +1 -0
- package/dist/contracts/release_cover_art/release_cover_art.js +168 -0
- package/dist/contracts/release_cover_art/release_cover_art.js.map +1 -0
- package/dist/contracts/release_credits/deps/miso_credit/credit.d.ts +24 -0
- package/dist/contracts/release_credits/deps/miso_credit/credit.d.ts.map +1 -0
- package/dist/contracts/release_credits/deps/miso_credit/credit.js +23 -0
- package/dist/contracts/release_credits/deps/miso_credit/credit.js.map +1 -0
- package/dist/contracts/release_credits/deps/sui/vec_map.d.ts +37 -0
- package/dist/contracts/release_credits/deps/sui/vec_map.d.ts.map +1 -0
- package/dist/contracts/release_credits/deps/sui/vec_map.js +28 -0
- package/dist/contracts/release_credits/deps/sui/vec_map.js.map +1 -0
- package/dist/contracts/release_credits/release_credits.d.ts +142 -0
- package/dist/contracts/release_credits/release_credits.d.ts.map +1 -0
- package/dist/contracts/release_credits/release_credits.js +108 -0
- package/dist/contracts/release_credits/release_credits.js.map +1 -0
- package/dist/contracts/release_credits/release_party_role.d.ts +58 -0
- package/dist/contracts/release_credits/release_party_role.d.ts.map +1 -0
- package/dist/contracts/release_credits/release_party_role.js +66 -0
- package/dist/contracts/release_credits/release_party_role.js.map +1 -0
- package/dist/contracts/royalty_pool/deps/std/type_name.d.ts +18 -0
- package/dist/contracts/royalty_pool/deps/std/type_name.d.ts.map +1 -0
- package/dist/contracts/royalty_pool/deps/std/type_name.js +20 -0
- package/dist/contracts/royalty_pool/deps/std/type_name.js.map +1 -0
- package/dist/contracts/royalty_pool/deps/sui/balance.d.ts +13 -0
- package/dist/contracts/royalty_pool/deps/sui/balance.d.ts.map +1 -0
- package/dist/contracts/royalty_pool/deps/sui/balance.js +15 -0
- package/dist/contracts/royalty_pool/deps/sui/balance.js.map +1 -0
- package/dist/contracts/royalty_pool/deps/sui/vec_map.d.ts +37 -0
- package/dist/contracts/royalty_pool/deps/sui/vec_map.d.ts.map +1 -0
- package/dist/contracts/royalty_pool/deps/sui/vec_map.js +28 -0
- package/dist/contracts/royalty_pool/deps/sui/vec_map.js.map +1 -0
- package/dist/contracts/royalty_pool/pool.d.ts +358 -0
- package/dist/contracts/royalty_pool/pool.d.ts.map +1 -0
- package/dist/contracts/royalty_pool/pool.js +352 -0
- package/dist/contracts/royalty_pool/pool.js.map +1 -0
- package/dist/contracts/royalty_pool/stake.d.ts +202 -0
- package/dist/contracts/royalty_pool/stake.d.ts.map +1 -0
- package/dist/contracts/royalty_pool/stake.js +197 -0
- package/dist/contracts/royalty_pool/stake.js.map +1 -0
- package/dist/contracts/utils/index.d.ts +31 -0
- package/dist/contracts/utils/index.d.ts.map +1 -0
- package/dist/contracts/utils/index.js +162 -0
- package/dist/contracts/utils/index.js.map +1 -0
- package/dist/contracts.d.ts +18 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +26 -0
- package/dist/contracts.js.map +1 -0
- package/dist/cover.d.ts +48 -0
- package/dist/cover.d.ts.map +1 -0
- package/dist/cover.js +68 -0
- package/dist/cover.js.map +1 -0
- package/dist/credits.d.ts +171 -0
- package/dist/credits.d.ts.map +1 -0
- package/dist/credits.js +360 -0
- package/dist/credits.js.map +1 -0
- package/dist/execute.d.ts +49 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +114 -0
- package/dist/execute.js.map +1 -0
- package/dist/extensions/royalty-pool.d.ts +32 -0
- package/dist/extensions/royalty-pool.d.ts.map +1 -0
- package/dist/extensions/royalty-pool.js +33 -0
- package/dist/extensions/royalty-pool.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +48 -0
- package/dist/internal.js.map +1 -0
- package/dist/parsers.d.ts +9 -0
- package/dist/parsers.d.ts.map +1 -0
- package/dist/parsers.js +52 -0
- package/dist/parsers.js.map +1 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +380 -0
- package/dist/queries.js.map +1 -0
- package/dist/schemas.d.ts +99 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +76 -0
- package/dist/schemas.js.map +1 -0
- package/dist/transactions.d.ts +158 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +154 -0
- package/dist/transactions.js.map +1 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/view.d.ts +21 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +36 -0
- package/dist/view.js.map +1 -0
- package/package.json +111 -0
- package/src/client.ts +278 -0
- package/src/contracts/composition_credits/composition_credits.ts +169 -0
- package/src/contracts/composition_credits/composition_party_role.ts +189 -0
- package/src/contracts/composition_credits/deps/miso_credit/credit.ts +27 -0
- package/src/contracts/composition_credits/deps/sui/vec_map.ts +33 -0
- package/src/contracts/composition_royalty_pool/composition_royalty_pool.ts +135 -0
- package/src/contracts/cover_art/cover_art.ts +99 -0
- package/src/contracts/cover_art/deps/ori/walrus_data.ts +36 -0
- package/src/contracts/miso/composition.ts +343 -0
- package/src/contracts/miso/deal.ts +257 -0
- package/src/contracts/miso/deps/bps/bps.ts +23 -0
- package/src/contracts/miso/recording.ts +298 -0
- package/src/contracts/miso/release.ts +392 -0
- package/src/contracts/miso/track.ts +153 -0
- package/src/contracts/recording_credits/deps/miso_credit/credit.ts +27 -0
- package/src/contracts/recording_credits/deps/sui/vec_map.ts +33 -0
- package/src/contracts/recording_credits/deps/sui/vec_set.ts +21 -0
- package/src/contracts/recording_credits/recording_credits.ts +458 -0
- package/src/contracts/recording_credits/recording_party_role.ts +1041 -0
- package/src/contracts/recording_royalty_pool/recording_royalty_pool.ts +138 -0
- package/src/contracts/release_cover_art/deps/0x340057f2174fb59e4626742dd2b46c662237837b6187450cb59e4976ce7eac78/walrus_data.ts +36 -0
- package/src/contracts/release_cover_art/deps/cover_art/cover_art.ts +23 -0
- package/src/contracts/release_cover_art/deps/per_track/per_track.ts +36 -0
- package/src/contracts/release_cover_art/release_cover_art.ts +251 -0
- package/src/contracts/release_credits/deps/miso_credit/credit.ts +27 -0
- package/src/contracts/release_credits/deps/sui/vec_map.ts +33 -0
- package/src/contracts/release_credits/release_credits.ts +156 -0
- package/src/contracts/release_credits/release_party_role.ts +87 -0
- package/src/contracts/royalty_pool/deps/std/type_name.ts +22 -0
- package/src/contracts/royalty_pool/deps/sui/balance.ts +17 -0
- package/src/contracts/royalty_pool/deps/sui/vec_map.ts +33 -0
- package/src/contracts/royalty_pool/pool.ts +577 -0
- package/src/contracts/royalty_pool/stake.ts +317 -0
- package/src/contracts/utils/index.ts +229 -0
- package/src/contracts.ts +30 -0
- package/src/cover.ts +136 -0
- package/src/credits.ts +645 -0
- package/src/execute.ts +141 -0
- package/src/extensions/royalty-pool.ts +85 -0
- package/src/index.ts +17 -0
- package/src/internal.ts +85 -0
- package/src/parsers.ts +80 -0
- package/src/queries.ts +478 -0
- package/src/schemas.ts +96 -0
- package/src/transactions.ts +290 -0
- package/src/types.ts +244 -0
- package/src/view.ts +59 -0
package/src/execute.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Transaction execution + effect extraction (the Signer-parameter pattern).
|
|
5
|
+
//
|
|
6
|
+
// Builders elsewhere only *append* to a caller-owned Transaction; this module is
|
|
7
|
+
// where a transaction is actually submitted. `signAndExecute` submits over the
|
|
8
|
+
// unified Core API, unwraps the `{ $kind: "Transaction", Transaction }` envelope,
|
|
9
|
+
// waits for finality, and returns changed objects, the objectId→type map, balance
|
|
10
|
+
// changes, and net gas for downstream extraction. Everything here is
|
|
11
|
+
// transport-agnostic — it takes any `ClientWithCoreApi`, so gRPC / JSON-RPC /
|
|
12
|
+
// GraphQL clients all work.
|
|
13
|
+
//
|
|
14
|
+
// `executeViaExecutor`, which submitted a non-idempotent PTB through a
|
|
15
|
+
// `ParallelTransactionExecutor` exactly once, moved to `@misofm/sdk` along with
|
|
16
|
+
// its only caller (`share.ts`'s batch currency publishing) — it builds on
|
|
17
|
+
// `buildTx`/`toExecResult`/`FULL_INCLUDE` exported from this module.
|
|
18
|
+
|
|
19
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
20
|
+
import type { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
21
|
+
import type { Signer } from "@mysten/sui/cryptography";
|
|
22
|
+
import type { TxThunk } from "./transactions.ts";
|
|
23
|
+
|
|
24
|
+
/** The effect fields every submit path requests, so extraction is uniform. */
|
|
25
|
+
export const FULL_INCLUDE = { effects: true, objectTypes: true, balanceChanges: true } as const;
|
|
26
|
+
type FullInclude = typeof FULL_INCLUDE;
|
|
27
|
+
|
|
28
|
+
export interface ExecResult {
|
|
29
|
+
digest: string;
|
|
30
|
+
/** Objects created/mutated/deleted by the transaction. */
|
|
31
|
+
changedObjects: SuiClientTypes.ChangedObject[];
|
|
32
|
+
/** Map of changed objectId → fully-qualified type. */
|
|
33
|
+
objectTypes: Record<string, string>;
|
|
34
|
+
/** Net coin balance deltas by address. */
|
|
35
|
+
balanceChanges: SuiClientTypes.BalanceChange[];
|
|
36
|
+
/** Net gas cost in MIST (computation + storage − rebate). */
|
|
37
|
+
gasUsed: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Builds a fresh Transaction from one or more thunks (awaiting async ones). */
|
|
41
|
+
export async function buildTx(...thunks: TxThunk[]): Promise<Transaction> {
|
|
42
|
+
const tx = new Transaction();
|
|
43
|
+
for (const thunk of thunks) await thunk(tx);
|
|
44
|
+
return tx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Normalizes the `{ $kind }` transaction-result envelope into an {@link ExecResult}. */
|
|
48
|
+
export function toExecResult(res: SuiClientTypes.TransactionResult<FullInclude>): ExecResult {
|
|
49
|
+
if (res.$kind !== "Transaction") {
|
|
50
|
+
const failed = res.FailedTransaction;
|
|
51
|
+
const status = failed.effects?.status;
|
|
52
|
+
const err = status && !status.success ? JSON.stringify(status.error) : "unknown error";
|
|
53
|
+
throw new Error(`Transaction failed: ${err} (digest ${failed.digest})`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const t = res.Transaction;
|
|
57
|
+
const effects = t.effects as SuiClientTypes.TransactionEffects;
|
|
58
|
+
if (!effects.status.success) {
|
|
59
|
+
throw new Error(`Transaction reverted: ${JSON.stringify(effects.status.error)} (digest ${t.digest})`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
digest: t.digest,
|
|
64
|
+
changedObjects: effects.changedObjects,
|
|
65
|
+
objectTypes: (t.objectTypes as Record<string, string>) ?? {},
|
|
66
|
+
balanceChanges: (t.balanceChanges as SuiClientTypes.BalanceChange[]) ?? [],
|
|
67
|
+
gasUsed: netGas(effects.gasUsed),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Signs, executes, and waits for a transaction; returns changes, types, gas. */
|
|
72
|
+
export async function signAndExecute(client: ClientWithCoreApi, signer: Signer, tx: Transaction): Promise<ExecResult> {
|
|
73
|
+
const res = await client.core.signAndExecuteTransaction({ transaction: tx, signer, include: FULL_INCLUDE });
|
|
74
|
+
const result = toExecResult(res);
|
|
75
|
+
await client.core.waitForTransaction({ digest: result.digest });
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Convenience: build from thunks, then sign+execute in one call. */
|
|
80
|
+
export async function execThunks(client: ClientWithCoreApi, signer: Signer, ...thunks: TxThunk[]): Promise<ExecResult> {
|
|
81
|
+
return signAndExecute(client, signer, await buildTx(...thunks));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ── Object-change extractors ────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
/** The package id from the (single) newly-published package. */
|
|
87
|
+
export function publishedPackageId(r: ExecResult): string {
|
|
88
|
+
const pkg = r.changedObjects.find((c) => c.idOperation === "Created" && c.outputState === "PackageWrite");
|
|
89
|
+
if (!pkg) throw new Error("No published package found in object changes.");
|
|
90
|
+
return pkg.objectId;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** All package ids newly published by the transaction (up to 5 per PTB). */
|
|
94
|
+
export function allPublishedPackageIds(r: ExecResult): string[] {
|
|
95
|
+
return r.changedObjects
|
|
96
|
+
.filter((c) => c.idOperation === "Created" && c.outputState === "PackageWrite")
|
|
97
|
+
.map((c) => c.objectId);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The first newly-created object whose type contains `substr`. */
|
|
101
|
+
export function createdByType(r: ExecResult, substr: string): string {
|
|
102
|
+
const id = maybeCreatedByType(r, substr);
|
|
103
|
+
if (!id) throw new Error(`No created object with type containing "${substr}" found in object changes.`);
|
|
104
|
+
return id;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Like {@link createdByType} but returns undefined instead of throwing. */
|
|
108
|
+
export function maybeCreatedByType(r: ExecResult, substr: string): string | undefined {
|
|
109
|
+
for (const c of r.changedObjects) {
|
|
110
|
+
if (c.idOperation === "Created" && (r.objectTypes[c.objectId] ?? "").includes(substr)) return c.objectId;
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The first newly-created object whose type is EXACTLY `type` (for non-generic types). */
|
|
116
|
+
export function createdByExactType(r: ExecResult, type: string): string {
|
|
117
|
+
for (const c of r.changedObjects) {
|
|
118
|
+
if (c.idOperation === "Created" && r.objectTypes[c.objectId] === type) return c.objectId;
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`No created object of exact type "${type}" found in object changes.`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** All newly-created objects whose type contains `substr`. */
|
|
124
|
+
export function allCreatedByType(r: ExecResult, substr: string): { objectId: string; objectType: string }[] {
|
|
125
|
+
const out: { objectId: string; objectType: string }[] = [];
|
|
126
|
+
for (const c of r.changedObjects) {
|
|
127
|
+
const type = r.objectTypes[c.objectId] ?? "";
|
|
128
|
+
if (c.idOperation === "Created" && type.includes(substr)) out.push({ objectId: c.objectId, objectType: type });
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The signed balance delta for `address` in `coinType`, or "0" if absent. */
|
|
134
|
+
export function balanceDelta(r: ExecResult, address: string, coinType: string): string {
|
|
135
|
+
const change = r.balanceChanges.find((b) => b.address === address && b.coinType === coinType);
|
|
136
|
+
return change?.amount ?? "0";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function netGas(gasUsed: SuiClientTypes.GasCostSummary): number {
|
|
140
|
+
return Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate);
|
|
141
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// First-party royalty-pool extension.
|
|
5
|
+
//
|
|
6
|
+
// A RoyaltyPool<Share, Currency> is an accumulator-based royalty-distribution pool
|
|
7
|
+
// bound to a composition or recording. It is created via the work's admin-gated
|
|
8
|
+
// `uid_mut(&AdminCap)` derived-object hook (`initialize_pool`), then shared
|
|
9
|
+
// (`pool::share`). Because `initialize_pool` borrows the work `&mut` (and the cap
|
|
10
|
+
// `&`) — not a shared on-chain input — it composes INSIDE the work's publish PTB:
|
|
11
|
+
// run it after `createComposition`/`createRecording` and before `finalize*` (which
|
|
12
|
+
// consumes the work into `share_object` and transfers the cap to the owner).
|
|
13
|
+
//
|
|
14
|
+
// Scope here is create + share only. Stake registration, funding (receive/redeem/
|
|
15
|
+
// deposit), and claiming are later owner/holder actions, not part of publishing.
|
|
16
|
+
|
|
17
|
+
import type { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
18
|
+
import * as compositionRoyaltyPool from "../contracts/composition_royalty_pool/composition_royalty_pool.ts";
|
|
19
|
+
import * as recordingRoyaltyPool from "../contracts/recording_royalty_pool/recording_royalty_pool.ts";
|
|
20
|
+
import * as pool from "../contracts/royalty_pool/pool.ts";
|
|
21
|
+
|
|
22
|
+
export interface AttachCompositionRoyaltyPoolParams {
|
|
23
|
+
/** The Composition — an in-PTB `createComposition` result, borrowed `&mut`. */
|
|
24
|
+
composition: TransactionObjectArgument;
|
|
25
|
+
/** The CompositionAdminCap, borrowed `&`. */
|
|
26
|
+
adminCap: TransactionObjectArgument;
|
|
27
|
+
/** The composition's share type (the pool's `Share` phantom = CompositionShare). */
|
|
28
|
+
compositionShareType: string;
|
|
29
|
+
/** Fully-qualified coin type the pool accumulates (the `Currency` phantom). */
|
|
30
|
+
currency: string;
|
|
31
|
+
compositionRoyaltyPoolPackageId: string;
|
|
32
|
+
royaltyPoolPackageId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Creates a royalty pool for a composition and shares it, appending to `tx`. */
|
|
36
|
+
export function attachCompositionRoyaltyPool(tx: Transaction, params: AttachCompositionRoyaltyPoolParams): void {
|
|
37
|
+
const created = tx.add(
|
|
38
|
+
compositionRoyaltyPool.initializePool({
|
|
39
|
+
package: params.compositionRoyaltyPoolPackageId,
|
|
40
|
+
typeArguments: [params.compositionShareType, params.currency],
|
|
41
|
+
arguments: [params.composition, params.adminCap],
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
tx.add(
|
|
45
|
+
pool.share({
|
|
46
|
+
package: params.royaltyPoolPackageId,
|
|
47
|
+
typeArguments: [params.compositionShareType, params.currency],
|
|
48
|
+
arguments: [created],
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AttachRecordingRoyaltyPoolParams {
|
|
54
|
+
/** The Recording — an in-PTB `createRecording` result, borrowed `&mut`. */
|
|
55
|
+
recording: TransactionObjectArgument;
|
|
56
|
+
/** The RecordingAdminCap, borrowed `&`. */
|
|
57
|
+
adminCap: TransactionObjectArgument;
|
|
58
|
+
/** The recording's own share type (the pool's `Share` phantom = RecordingShare). */
|
|
59
|
+
recordingShareType: string;
|
|
60
|
+
/** The parent composition's share type (the recording's `CompositionShare` phantom). */
|
|
61
|
+
compositionShareType: string;
|
|
62
|
+
/** Fully-qualified coin type the pool accumulates (the `Currency` phantom). */
|
|
63
|
+
currency: string;
|
|
64
|
+
recordingRoyaltyPoolPackageId: string;
|
|
65
|
+
royaltyPoolPackageId: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Creates a royalty pool for a recording and shares it, appending to `tx`. */
|
|
69
|
+
export function attachRecordingRoyaltyPool(tx: Transaction, params: AttachRecordingRoyaltyPoolParams): void {
|
|
70
|
+
const created = tx.add(
|
|
71
|
+
recordingRoyaltyPool.initializePool({
|
|
72
|
+
package: params.recordingRoyaltyPoolPackageId,
|
|
73
|
+
typeArguments: [params.recordingShareType, params.compositionShareType, params.currency],
|
|
74
|
+
arguments: [params.recording, params.adminCap],
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
// The pool is RoyaltyPool<RecordingShare, Currency> — Share is the recording's own share type.
|
|
78
|
+
tx.add(
|
|
79
|
+
pool.share({
|
|
80
|
+
package: params.royaltyPoolPackageId,
|
|
81
|
+
typeArguments: [params.recordingShareType, params.currency],
|
|
82
|
+
arguments: [created],
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export * from "./types.ts";
|
|
5
|
+
export * from "./schemas.ts";
|
|
6
|
+
export * from "./transactions.ts";
|
|
7
|
+
export * from "./execute.ts";
|
|
8
|
+
export * from "./extensions/royalty-pool.ts";
|
|
9
|
+
export * from "./queries.ts";
|
|
10
|
+
export * from "./parsers.ts";
|
|
11
|
+
export * from "./view.ts";
|
|
12
|
+
export * from "./client.ts";
|
|
13
|
+
|
|
14
|
+
// Generated, ABI-bound bindings (BCS structs + type-safe Move calls).
|
|
15
|
+
export * as contracts from "./contracts.ts";
|
|
16
|
+
export * from "./cover.ts";
|
|
17
|
+
export * from "./credits.ts";
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Internal shared helpers (not exported from the package root).
|
|
5
|
+
//
|
|
6
|
+
// 1) Mappers from the generated BCS-parse output (snake_case, with @mysten/bcs
|
|
7
|
+
// conventions: enums as `{ $kind, [Variant]: payload }`, tuples as arrays,
|
|
8
|
+
// VecMap as `{ contents: [{ key, value }] }`, u64/u256 as strings, Address as
|
|
9
|
+
// hex) into the public camelCase domain types in `./types`. These are the
|
|
10
|
+
// single boundary between codegen output and the public API, so when the
|
|
11
|
+
// generated shapes change, type errors surface here.
|
|
12
|
+
//
|
|
13
|
+
// 2) PTB building blocks — the `0x1::option` move-call targets used when a
|
|
14
|
+
// generated call needs an `Option` argument built inline. Consumed by
|
|
15
|
+
// `./cover` and `./credits`; `./transactions` does not use them.
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
BPS,
|
|
19
|
+
Composition,
|
|
20
|
+
Recording,
|
|
21
|
+
Release as ReleaseType,
|
|
22
|
+
Track,
|
|
23
|
+
TrackState,
|
|
24
|
+
} from "./types.ts";
|
|
25
|
+
|
|
26
|
+
// === PTB building blocks ===
|
|
27
|
+
|
|
28
|
+
/** `0x1::option::none` / `0x1::option::some` moveCall targets. */
|
|
29
|
+
export const OPTION_NONE = "0x1::option::none";
|
|
30
|
+
export const OPTION_SOME = "0x1::option::some";
|
|
31
|
+
|
|
32
|
+
// === Mappers ===
|
|
33
|
+
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
35
|
+
type Parsed = any;
|
|
36
|
+
|
|
37
|
+
// === Primitives ===
|
|
38
|
+
|
|
39
|
+
/** `BPS` is a Move tuple struct `(u16)`, parsed as `[number]`. */
|
|
40
|
+
export function mapBps(d: Parsed): BPS {
|
|
41
|
+
return { value: Number(Array.isArray(d) ? d[0] : d) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Lifecycle state enum (`Initialized | Published(u64)`). */
|
|
45
|
+
export function mapState(
|
|
46
|
+
d: Parsed,
|
|
47
|
+
): { type: "Initialized" } | { type: "Published"; timestampMs: number } {
|
|
48
|
+
if (d?.$kind === "Published") return { type: "Published", timestampMs: Number(d.Published) };
|
|
49
|
+
return { type: "Initialized" };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// === Objects ===
|
|
53
|
+
|
|
54
|
+
export function mapComposition(id: string, d: Parsed): Composition {
|
|
55
|
+
return {
|
|
56
|
+
id,
|
|
57
|
+
state: mapState(d.state),
|
|
58
|
+
title: d.title,
|
|
59
|
+
royaltyRate: mapBps(d.royalty_rate),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function mapRecording(id: string, d: Parsed): Recording {
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
state: mapState(d.state),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function mapTrack(d: Parsed): Track {
|
|
71
|
+
return {
|
|
72
|
+
state: (d.state?.$kind ?? "Unassigned") as TrackState,
|
|
73
|
+
recordingId: d.recording_id,
|
|
74
|
+
splitBps: mapBps(d.split_bps),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function mapRelease(id: string, d: Parsed): ReleaseType {
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
state: mapState(d.state),
|
|
82
|
+
title: d.title,
|
|
83
|
+
tracks: (d.tracks ?? []).map(mapTrack),
|
|
84
|
+
};
|
|
85
|
+
}
|
package/src/parsers.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Event parsers. The BCS layouts come from the codegen-generated structs (so
|
|
5
|
+
// they track the on-chain ABI automatically); these functions parse raw event
|
|
6
|
+
// bytes and map them to the public camelCase event types.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
CompositionPublishedEvent as CompositionPublishedEventBcs,
|
|
10
|
+
CompositionRoyaltySetEvent as CompositionRoyaltySetEventBcs,
|
|
11
|
+
} from "./contracts/miso/composition.ts";
|
|
12
|
+
import { RecordingPublishedEvent as RecordingPublishedEventBcs } from "./contracts/miso/recording.ts";
|
|
13
|
+
import { ReleasePublishedEvent as ReleasePublishedEventBcs } from "./contracts/miso/release.ts";
|
|
14
|
+
import {
|
|
15
|
+
DealCreatedEvent as DealCreatedEventBcs,
|
|
16
|
+
DealAcceptedEvent as DealAcceptedEventBcs,
|
|
17
|
+
DealRejectedEvent as DealRejectedEventBcs,
|
|
18
|
+
} from "./contracts/miso/deal.ts";
|
|
19
|
+
import type {
|
|
20
|
+
CompositionPublishedEvent,
|
|
21
|
+
CompositionRoyaltySetEvent,
|
|
22
|
+
RecordingPublishedEvent,
|
|
23
|
+
ReleasePublishedEvent,
|
|
24
|
+
DealCreatedEvent,
|
|
25
|
+
DealAcceptedEvent,
|
|
26
|
+
DealRejectedEvent,
|
|
27
|
+
} from "./types.ts";
|
|
28
|
+
|
|
29
|
+
// === Composition ===
|
|
30
|
+
|
|
31
|
+
export function parseCompositionPublishedEvent(bytes: Uint8Array): CompositionPublishedEvent {
|
|
32
|
+
const e = CompositionPublishedEventBcs.parse(bytes);
|
|
33
|
+
return { compositionId: e.composition_id };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function parseCompositionRoyaltySetEvent(bytes: Uint8Array): CompositionRoyaltySetEvent {
|
|
37
|
+
const e = CompositionRoyaltySetEventBcs.parse(bytes);
|
|
38
|
+
return { royaltyRateBps: e.royalty_rate_bps };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// === Recording ===
|
|
42
|
+
|
|
43
|
+
export function parseRecordingPublishedEvent(bytes: Uint8Array): RecordingPublishedEvent {
|
|
44
|
+
const e = RecordingPublishedEventBcs.parse(bytes);
|
|
45
|
+
return { recordingId: e.recording_id };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// === Release ===
|
|
49
|
+
|
|
50
|
+
export function parseReleasePublishedEvent(bytes: Uint8Array): ReleasePublishedEvent {
|
|
51
|
+
const e = ReleasePublishedEventBcs.parse(bytes);
|
|
52
|
+
return { releaseId: e.release_id };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// === Deal ===
|
|
56
|
+
|
|
57
|
+
export function parseDealCreatedEvent(bytes: Uint8Array): DealCreatedEvent {
|
|
58
|
+
const e = DealCreatedEventBcs.parse(bytes);
|
|
59
|
+
return {
|
|
60
|
+
dealId: e.deal_id,
|
|
61
|
+
releaseId: e.release_id,
|
|
62
|
+
trackSplitBps: { value: e.track_split_bps_value },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function parseDealAcceptedEvent(bytes: Uint8Array): DealAcceptedEvent {
|
|
67
|
+
const e = DealAcceptedEventBcs.parse(bytes);
|
|
68
|
+
return {
|
|
69
|
+
dealId: e.deal_id,
|
|
70
|
+
releaseId: e.release_id,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function parseDealRejectedEvent(bytes: Uint8Array): DealRejectedEvent {
|
|
75
|
+
const e = DealRejectedEventBcs.parse(bytes);
|
|
76
|
+
return {
|
|
77
|
+
dealId: e.deal_id,
|
|
78
|
+
releaseId: e.release_id,
|
|
79
|
+
};
|
|
80
|
+
}
|