@interest-protocol/blast-admin-sdk 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.
- package/README.md +8 -2
- package/dist/events.d.ts +67 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +66 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/reducer.d.ts +19 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +67 -0
- package/dist/reducer.js.map +1 -0
- package/dist/state.d.ts +42 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +57 -0
- package/dist/state.js.map +1 -0
- package/dist/transactions.d.ts +105 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +198 -0
- package/dist/transactions.js.map +1 -0
- package/package.json +55 -4
- package/src/events.ts +103 -0
- package/src/index.ts +4 -0
- package/src/reducer.ts +97 -0
- package/src/state.ts +102 -0
- package/src/transactions.ts +294 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { SharedObjectIdentity } from "@interest-protocol/blast-core/sui";
|
|
2
|
+
import { normalizeSharedObjectIdentity } from "@interest-protocol/blast-core/sui";
|
|
3
|
+
import type {
|
|
4
|
+
TransactionObjectArgument,
|
|
5
|
+
TransactionObjectInput,
|
|
6
|
+
} from "@mysten/sui/transactions";
|
|
7
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
8
|
+
import {
|
|
9
|
+
normalizeStructTag,
|
|
10
|
+
normalizeSuiAddress,
|
|
11
|
+
normalizeSuiObjectId,
|
|
12
|
+
} from "@mysten/sui/utils";
|
|
13
|
+
|
|
14
|
+
/** The immutable `blast_admin` package and its shared singleton `blast_acl::ACL`. */
|
|
15
|
+
export type AdminDeployment = {
|
|
16
|
+
packageId: string;
|
|
17
|
+
acl: SharedObjectIdentity;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function normalizeAdminDeployment(
|
|
21
|
+
deployment: AdminDeployment,
|
|
22
|
+
): AdminDeployment {
|
|
23
|
+
return {
|
|
24
|
+
packageId: normalizeSuiObjectId(deployment.packageId),
|
|
25
|
+
acl: normalizeSharedObjectIdentity("admin.acl", deployment.acl),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
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.
|
|
33
|
+
*/
|
|
34
|
+
export class AdminCalls {
|
|
35
|
+
readonly deployment: AdminDeployment;
|
|
36
|
+
|
|
37
|
+
constructor(deployment: AdminDeployment) {
|
|
38
|
+
this.deployment = normalizeAdminDeployment(deployment);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `sign_in<Role>`: this PTB's `AdminWitness<Role>`; the `AdminCap` must hold `role`. */
|
|
42
|
+
signIn(options: { adminCap: TransactionObjectInput; role: string }) {
|
|
43
|
+
const role = normalizeStructTag(options.role);
|
|
44
|
+
return (tx: Transaction): TransactionObjectArgument =>
|
|
45
|
+
tx.moveCall({
|
|
46
|
+
target: this.#target("sign_in"),
|
|
47
|
+
typeArguments: [role],
|
|
48
|
+
arguments: [this.#acl(tx, false), tx.object(options.adminCap)],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `grant_admin`: delivers a new `AdminCap` with no role to `recipient`. */
|
|
53
|
+
grantAdmin(options: {
|
|
54
|
+
superAdminCap: TransactionObjectInput;
|
|
55
|
+
recipient: string;
|
|
56
|
+
}) {
|
|
57
|
+
const recipient = normalizeSuiAddress(options.recipient);
|
|
58
|
+
return (tx: Transaction): void => {
|
|
59
|
+
tx.moveCall({
|
|
60
|
+
target: this.#target("grant_admin"),
|
|
61
|
+
arguments: [
|
|
62
|
+
this.#acl(tx, true),
|
|
63
|
+
tx.object(options.superAdminCap),
|
|
64
|
+
tx.pure.address(recipient),
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `revoke_admin`: retires a live `AdminCap` and every role it holds. */
|
|
71
|
+
revokeAdmin(options: {
|
|
72
|
+
superAdminCap: TransactionObjectInput;
|
|
73
|
+
adminCapId: string;
|
|
74
|
+
}) {
|
|
75
|
+
const adminCapId = normalizeSuiObjectId(options.adminCapId);
|
|
76
|
+
return (tx: Transaction): void => {
|
|
77
|
+
tx.moveCall({
|
|
78
|
+
target: this.#target("revoke_admin"),
|
|
79
|
+
arguments: [
|
|
80
|
+
this.#acl(tx, true),
|
|
81
|
+
tx.object(options.superAdminCap),
|
|
82
|
+
tx.pure.id(adminCapId),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** `grant_role<Role>` to a live administrator. */
|
|
89
|
+
grantRole(options: {
|
|
90
|
+
superAdminCap: TransactionObjectInput;
|
|
91
|
+
adminCapId: string;
|
|
92
|
+
role: string;
|
|
93
|
+
}) {
|
|
94
|
+
return this.#roleCall("grant_role", options);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `revoke_role<Role>` from a live administrator. */
|
|
98
|
+
revokeRole(options: {
|
|
99
|
+
superAdminCap: TransactionObjectInput;
|
|
100
|
+
adminCapId: string;
|
|
101
|
+
role: string;
|
|
102
|
+
}) {
|
|
103
|
+
return this.#roleCall("revoke_role", options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** `destroy_admin_cap`: deletes the holder's own live or revoked cap. */
|
|
107
|
+
destroyAdminCap(options: { adminCap: TransactionObjectInput }) {
|
|
108
|
+
return (tx: Transaction): void => {
|
|
109
|
+
tx.moveCall({
|
|
110
|
+
target: this.#target("destroy_admin_cap"),
|
|
111
|
+
arguments: [this.#acl(tx, true), tx.object(options.adminCap)],
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* `begin_super_admin_transfer`: nominates `recipient`, who may accept once
|
|
118
|
+
* the ACL's seven-day delay passes; it replaces a pending nomination.
|
|
119
|
+
*/
|
|
120
|
+
beginSuperAdminTransfer(options: {
|
|
121
|
+
superAdminCap: TransactionObjectInput;
|
|
122
|
+
recipient: string;
|
|
123
|
+
}) {
|
|
124
|
+
const recipient = normalizeSuiAddress(options.recipient);
|
|
125
|
+
return (tx: Transaction): void => {
|
|
126
|
+
tx.moveCall({
|
|
127
|
+
target: this.#target("begin_super_admin_transfer"),
|
|
128
|
+
arguments: [
|
|
129
|
+
this.#acl(tx, true),
|
|
130
|
+
tx.object(options.superAdminCap),
|
|
131
|
+
tx.pure.address(recipient),
|
|
132
|
+
tx.object.clock(),
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
cancelSuperAdminTransfer(options: { superAdminCap: TransactionObjectInput }) {
|
|
139
|
+
return (tx: Transaction): void => {
|
|
140
|
+
tx.moveCall({
|
|
141
|
+
target: this.#target("cancel_super_admin_transfer"),
|
|
142
|
+
arguments: [this.#acl(tx, true), tx.object(options.superAdminCap)],
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `accept_super_admin_transfer`: the sender must be the ready nominee. */
|
|
148
|
+
acceptSuperAdminTransfer() {
|
|
149
|
+
return (tx: Transaction): void => {
|
|
150
|
+
tx.moveCall({
|
|
151
|
+
target: this.#target("accept_super_admin_transfer"),
|
|
152
|
+
arguments: [this.#acl(tx, true), tx.object.clock()],
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `destroy_retired_super_admin_cap`: deletes a root an accepted transfer replaced. */
|
|
158
|
+
destroyRetiredSuperAdminCap(options: {
|
|
159
|
+
superAdminCap: TransactionObjectInput;
|
|
160
|
+
}) {
|
|
161
|
+
return (tx: Transaction): void => {
|
|
162
|
+
tx.moveCall({
|
|
163
|
+
target: this.#target("destroy_retired_super_admin_cap"),
|
|
164
|
+
arguments: [this.#acl(tx, false), tx.object(options.superAdminCap)],
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#roleCall(
|
|
170
|
+
functionName: "grant_role" | "revoke_role",
|
|
171
|
+
options: {
|
|
172
|
+
superAdminCap: TransactionObjectInput;
|
|
173
|
+
adminCapId: string;
|
|
174
|
+
role: string;
|
|
175
|
+
},
|
|
176
|
+
) {
|
|
177
|
+
const role = normalizeStructTag(options.role);
|
|
178
|
+
const adminCapId = normalizeSuiObjectId(options.adminCapId);
|
|
179
|
+
return (tx: Transaction): void => {
|
|
180
|
+
tx.moveCall({
|
|
181
|
+
target: this.#target(functionName),
|
|
182
|
+
typeArguments: [role],
|
|
183
|
+
arguments: [
|
|
184
|
+
this.#acl(tx, true),
|
|
185
|
+
tx.object(options.superAdminCap),
|
|
186
|
+
tx.pure.id(adminCapId),
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
#target(functionName: string): string {
|
|
193
|
+
return `${this.deployment.packageId}::blast_acl::${functionName}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#acl(tx: Transaction, mutable: boolean): TransactionObjectArgument {
|
|
197
|
+
return tx.sharedObjectRef({ ...this.deployment.acl, mutable });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** One-call PTBs for the ACL's root and administrators. */
|
|
202
|
+
export class AdminTransactions {
|
|
203
|
+
readonly call: AdminCalls;
|
|
204
|
+
|
|
205
|
+
constructor(deployment: AdminDeployment) {
|
|
206
|
+
this.call = new AdminCalls(deployment);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
grantAdmin(options: { superAdminCapId: string; recipient: string }) {
|
|
210
|
+
return single(
|
|
211
|
+
this.call.grantAdmin({
|
|
212
|
+
superAdminCap: options.superAdminCapId,
|
|
213
|
+
recipient: options.recipient,
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
revokeAdmin(options: { superAdminCapId: string; adminCapId: string }) {
|
|
219
|
+
return single(
|
|
220
|
+
this.call.revokeAdmin({
|
|
221
|
+
superAdminCap: options.superAdminCapId,
|
|
222
|
+
adminCapId: options.adminCapId,
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
grantRole(options: {
|
|
228
|
+
superAdminCapId: string;
|
|
229
|
+
adminCapId: string;
|
|
230
|
+
role: string;
|
|
231
|
+
}) {
|
|
232
|
+
return single(
|
|
233
|
+
this.call.grantRole({
|
|
234
|
+
...options,
|
|
235
|
+
superAdminCap: options.superAdminCapId,
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
revokeRole(options: {
|
|
241
|
+
superAdminCapId: string;
|
|
242
|
+
adminCapId: string;
|
|
243
|
+
role: string;
|
|
244
|
+
}) {
|
|
245
|
+
return single(
|
|
246
|
+
this.call.revokeRole({
|
|
247
|
+
...options,
|
|
248
|
+
superAdminCap: options.superAdminCapId,
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
destroyAdminCap(options: { adminCapId: string }) {
|
|
254
|
+
return single(this.call.destroyAdminCap({ adminCap: options.adminCapId }));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
beginSuperAdminTransfer(options: {
|
|
258
|
+
superAdminCapId: string;
|
|
259
|
+
recipient: string;
|
|
260
|
+
}) {
|
|
261
|
+
return single(
|
|
262
|
+
this.call.beginSuperAdminTransfer({
|
|
263
|
+
superAdminCap: options.superAdminCapId,
|
|
264
|
+
recipient: options.recipient,
|
|
265
|
+
}),
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
cancelSuperAdminTransfer(options: { superAdminCapId: string }) {
|
|
270
|
+
return single(
|
|
271
|
+
this.call.cancelSuperAdminTransfer({
|
|
272
|
+
superAdminCap: options.superAdminCapId,
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
acceptSuperAdminTransfer() {
|
|
278
|
+
return single(this.call.acceptSuperAdminTransfer());
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
destroyRetiredSuperAdminCap(options: { superAdminCapId: string }) {
|
|
282
|
+
return single(
|
|
283
|
+
this.call.destroyRetiredSuperAdminCap({
|
|
284
|
+
superAdminCap: options.superAdminCapId,
|
|
285
|
+
}),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function single(call: (tx: Transaction) => void): Transaction {
|
|
291
|
+
const tx = new Transaction();
|
|
292
|
+
tx.add(call);
|
|
293
|
+
return tx;
|
|
294
|
+
}
|