@zing-protocol/zing-sdk 0.0.1
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 +12 -0
- package/package.json +37 -0
- package/src/_generated/index.js +6 -0
- package/src/_generated/utils/index.ts +181 -0
- package/src/_generated/zing_framework/coin_utils.ts +41 -0
- package/src/_generated/zing_framework/deps/sui/object.ts +16 -0
- package/src/_generated/zing_framework/derived_object_bag.ts +400 -0
- package/src/_generated/zing_framework/derived_table.ts +366 -0
- package/src/_generated/zing_governance/admin.ts +47 -0
- package/src/_generated/zing_governance/deps/sui/object.ts +16 -0
- package/src/_generated/zing_governance/treasury.ts +134 -0
- package/src/_generated/zing_identity/config.ts +191 -0
- package/src/_generated/zing_identity/deps/std/type_name.ts +25 -0
- package/src/_generated/zing_identity/deps/sui/object.ts +16 -0
- package/src/_generated/zing_identity/deps/sui/object_table.ts +26 -0
- package/src/_generated/zing_identity/deps/sui/table.ts +38 -0
- package/src/_generated/zing_identity/deps/sui/vec_set.ts +28 -0
- package/src/_generated/zing_identity/ecdsa.ts +166 -0
- package/src/_generated/zing_identity/identity.ts +661 -0
- package/src/_generated/zing_identity/reclaim.ts +803 -0
- package/src/_generated/zing_studio/app.ts +855 -0
- package/src/_generated/zing_studio/article.ts +598 -0
- package/src/_generated/zing_studio/config.ts +475 -0
- package/src/_generated/zing_studio/deps/std/type_name.ts +25 -0
- package/src/_generated/zing_studio/deps/sui/bag.ts +43 -0
- package/src/_generated/zing_studio/deps/sui/balance.ts +20 -0
- package/src/_generated/zing_studio/deps/sui/coin.ts +21 -0
- package/src/_generated/zing_studio/deps/sui/dynamic_field.ts +272 -0
- package/src/_generated/zing_studio/deps/sui/object.ts +16 -0
- package/src/_generated/zing_studio/deps/sui/table.ts +38 -0
- package/src/_generated/zing_studio/deps/sui/vec_map.ts +39 -0
- package/src/_generated/zing_studio/deps/sui/vec_set.ts +28 -0
- package/src/_generated/zing_studio/deps/walrus/blob.ts +22 -0
- package/src/_generated/zing_studio/deps/walrus/events.ts +124 -0
- package/src/_generated/zing_studio/deps/walrus/metadata.ts +137 -0
- package/src/_generated/zing_studio/deps/walrus/storage_resource.ts +17 -0
- package/src/_generated/zing_studio/deps/zing_framework/derived_object_bag.ts +17 -0
- package/src/_generated/zing_studio/deps/zing_framework/derived_table.ts +17 -0
- package/src/_generated/zing_studio/donation.ts +18 -0
- package/src/_generated/zing_studio/enclave.ts +466 -0
- package/src/_generated/zing_studio/nitro_attestation.ts +308 -0
- package/src/_generated/zing_studio/referral.ts +447 -0
- package/src/_generated/zing_studio/storage.ts +664 -0
- package/src/_generated/zing_studio/studio.ts +682 -0
- package/src/bcs.ts +139 -0
- package/src/client/index.ts +557 -0
- package/src/client/types.ts +28 -0
- package/src/components/index.ts +3 -0
- package/src/components/wallet-provider.tsx +53 -0
- package/src/components/walrus-provider.tsx +212 -0
- package/src/components/zing-provider.tsx +54 -0
- package/src/config/common.ts +82 -0
- package/src/config/index.ts +45 -0
- package/src/config/mainnet.ts +109 -0
- package/src/config/testnet.ts +111 -0
- package/src/config/types.ts +69 -0
- package/src/const.ts +32 -0
- package/src/getters.ts +523 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/useGetStudio.ts +22 -0
- package/src/hooks/useGetTierPlan.ts +115 -0
- package/src/hooks/useReclaim.ts +165 -0
- package/src/hooks/useSignAndExecuteTransaction.ts +57 -0
- package/src/hooks/useSignPersonalMessage.ts +28 -0
- package/src/hooks/useZingInfiniteQueries.ts +92 -0
- package/src/hooks/useZingMutation.ts +66 -0
- package/src/hooks/useZingQueries.ts +107 -0
- package/src/hooks/useZingQuery.ts +88 -0
- package/src/index.ts +15 -0
- package/src/lib/utils/colorful-logger.ts +27 -0
- package/src/lib/utils/const.ts +25 -0
- package/src/lib/utils/helpers.ts +78 -0
- package/src/lib/utils/index.ts +5 -0
- package/src/lib/utils/init-app-with-shadow.ts +42 -0
- package/src/lib/utils/quilt.ts +317 -0
- package/src/lib/utils/reclaim.ts +148 -0
- package/src/lib/utils/types.ts +14 -0
- package/src/mutations/index.ts +3 -0
- package/src/mutations/seal.ts +78 -0
- package/src/mutations/signer.ts +241 -0
- package/src/mutations/walrus.ts +862 -0
- package/src/stores/index.ts +3 -0
- package/src/stores/walletStore.ts +360 -0
- package/src/stores/walrusStore.ts +118 -0
- package/src/stores/zkloginStore.ts +53 -0
- package/src/types.ts +120 -0
- package/tsconfig.json +12 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zing-protocol/zing-sdk",
|
|
3
|
+
"sideEffects": false,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./src/*": "./src/*"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"type-check": "tsc --noEmit"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@mysten/seal": "catalog:",
|
|
18
|
+
"@mysten/sui": "catalog:",
|
|
19
|
+
"@mysten/walrus": "catalog:",
|
|
20
|
+
"@tanstack/react-query": "catalog:",
|
|
21
|
+
"@reclaimprotocol/js-sdk": "^4.5.1",
|
|
22
|
+
"js-sha3": "^0.9.3",
|
|
23
|
+
"zustand": "^5.0.8"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@package/tsconfig": "workspace:*",
|
|
31
|
+
"type-fest": "^4.41.0",
|
|
32
|
+
"typescript": "^5.8.3",
|
|
33
|
+
"@types/react": "catalog:",
|
|
34
|
+
"@types/react-dom": "catalog:",
|
|
35
|
+
"@types/node": "catalog:"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as Reclaim from "./zing_identity/reclaim.js";
|
|
2
|
+
export * as Identity from "./zing_identity/identity.js";
|
|
3
|
+
export * as StudioApp from "./zing_studio/app.js";
|
|
4
|
+
export * as Studio from "./zing_studio/studio.js";
|
|
5
|
+
export * as Article from "./zing_studio/article.js";
|
|
6
|
+
export * as Storage from "./zing_studio/storage.js";
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bcs,
|
|
3
|
+
TypeTagSerializer,
|
|
4
|
+
BcsStruct,
|
|
5
|
+
BcsEnum,
|
|
6
|
+
BcsTuple,
|
|
7
|
+
} from "@mysten/sui/bcs";
|
|
8
|
+
import { isArgument } from "@mysten/sui/transactions";
|
|
9
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
10
|
+
import type { BcsType, TypeTag } from "@mysten/sui/bcs";
|
|
11
|
+
import type { TransactionArgument } from "@mysten/sui/transactions";
|
|
12
|
+
|
|
13
|
+
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
|
|
14
|
+
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
|
|
15
|
+
const SUI_SYSTEM_ADDRESS = normalizeSuiAddress("0x3");
|
|
16
|
+
|
|
17
|
+
function stringify(val: unknown) {
|
|
18
|
+
if (typeof val === "object") {
|
|
19
|
+
return JSON.stringify(val, (val: unknown) => val);
|
|
20
|
+
}
|
|
21
|
+
if (typeof val === "bigint") {
|
|
22
|
+
return val.toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return val;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
29
|
+
|
|
30
|
+
export function getPureBcsSchema(
|
|
31
|
+
typeTag: string | TypeTag,
|
|
32
|
+
): BcsType<any> | null {
|
|
33
|
+
const parsedTag =
|
|
34
|
+
typeof typeTag === "string"
|
|
35
|
+
? TypeTagSerializer.parseFromStr(typeTag)
|
|
36
|
+
: typeTag;
|
|
37
|
+
|
|
38
|
+
if ("u8" in parsedTag) {
|
|
39
|
+
return bcs.U8;
|
|
40
|
+
} else if ("u16" in parsedTag) {
|
|
41
|
+
return bcs.U16;
|
|
42
|
+
} else if ("u32" in parsedTag) {
|
|
43
|
+
return bcs.U32;
|
|
44
|
+
} else if ("u64" in parsedTag) {
|
|
45
|
+
return bcs.U64;
|
|
46
|
+
} else if ("u128" in parsedTag) {
|
|
47
|
+
return bcs.U128;
|
|
48
|
+
} else if ("u256" in parsedTag) {
|
|
49
|
+
return bcs.U256;
|
|
50
|
+
} else if ("address" in parsedTag) {
|
|
51
|
+
return bcs.Address;
|
|
52
|
+
} else if ("bool" in parsedTag) {
|
|
53
|
+
return bcs.Bool;
|
|
54
|
+
} else if ("vector" in parsedTag) {
|
|
55
|
+
const type = getPureBcsSchema(parsedTag.vector);
|
|
56
|
+
return type ? bcs.vector(type) : null;
|
|
57
|
+
} else if ("struct" in parsedTag) {
|
|
58
|
+
const structTag = parsedTag.struct;
|
|
59
|
+
const pkg = normalizeSuiAddress(parsedTag.struct.address);
|
|
60
|
+
|
|
61
|
+
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
62
|
+
if (
|
|
63
|
+
(structTag.module === "ascii" || structTag.module === "string") &&
|
|
64
|
+
structTag.name === "String"
|
|
65
|
+
) {
|
|
66
|
+
return bcs.String;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (structTag.module === "option" && structTag.name === "Option") {
|
|
70
|
+
const type = getPureBcsSchema(structTag.typeParams[0]!);
|
|
71
|
+
return type ? bcs.option(type) : null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
pkg === SUI_FRAMEWORK_ADDRESS &&
|
|
77
|
+
structTag.module === "Object" &&
|
|
78
|
+
structTag.name === "ID"
|
|
79
|
+
) {
|
|
80
|
+
return bcs.Address;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function normalizeMoveArguments(
|
|
88
|
+
args: unknown[] | object,
|
|
89
|
+
argTypes: string[],
|
|
90
|
+
parameterNames?: string[],
|
|
91
|
+
) {
|
|
92
|
+
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
93
|
+
if (parameterNames && argLen !== parameterNames.length) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const normalizedArgs: TransactionArgument[] = [];
|
|
100
|
+
|
|
101
|
+
let index = 0;
|
|
102
|
+
for (const [i, argType] of argTypes.entries()) {
|
|
103
|
+
if (argType === `${SUI_FRAMEWORK_ADDRESS}::deny_list::DenyList`) {
|
|
104
|
+
normalizedArgs.push((tx) => tx.object.denyList());
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (argType === `${SUI_FRAMEWORK_ADDRESS}::random::Random`) {
|
|
109
|
+
normalizedArgs.push((tx) => tx.object.random());
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (argType === `${SUI_FRAMEWORK_ADDRESS}::clock::Clock`) {
|
|
114
|
+
normalizedArgs.push((tx) => tx.object.clock());
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (argType === `${SUI_SYSTEM_ADDRESS}::sui_system::SuiSystemState`) {
|
|
119
|
+
normalizedArgs.push((tx) => tx.object.system());
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let arg;
|
|
124
|
+
if (Array.isArray(args)) {
|
|
125
|
+
if (index >= args.length) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
arg = args[index];
|
|
131
|
+
} else {
|
|
132
|
+
if (!parameterNames) {
|
|
133
|
+
throw new Error(`Expected arguments to be passed as an array`);
|
|
134
|
+
}
|
|
135
|
+
const name = parameterNames[index];
|
|
136
|
+
arg = args[name as keyof typeof args];
|
|
137
|
+
|
|
138
|
+
if (arg === undefined) {
|
|
139
|
+
throw new Error(`Parameter ${name} is required`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
index += 1;
|
|
144
|
+
|
|
145
|
+
if (typeof arg === "function" || isArgument(arg)) {
|
|
146
|
+
normalizedArgs.push(arg as TransactionArgument);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const type = argTypes[i]!;
|
|
151
|
+
const bcsType = getPureBcsSchema(type);
|
|
152
|
+
|
|
153
|
+
if (bcsType) {
|
|
154
|
+
const bytes = bcsType.serialize(arg as never);
|
|
155
|
+
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
156
|
+
continue;
|
|
157
|
+
} else if (typeof arg === "string") {
|
|
158
|
+
normalizedArgs.push((tx) => tx.object(arg));
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return normalizedArgs;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class MoveStruct<
|
|
169
|
+
T extends Record<string, BcsType<any>>,
|
|
170
|
+
const Name extends string = string,
|
|
171
|
+
> extends BcsStruct<T, Name> {}
|
|
172
|
+
|
|
173
|
+
export class MoveEnum<
|
|
174
|
+
T extends Record<string, BcsType<any> | null>,
|
|
175
|
+
const Name extends string,
|
|
176
|
+
> extends BcsEnum<T, Name> {}
|
|
177
|
+
|
|
178
|
+
export class MoveTuple<
|
|
179
|
+
T extends readonly BcsType<any>[],
|
|
180
|
+
const Name extends string,
|
|
181
|
+
> extends BcsTuple<T, Name> {}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import { normalizeMoveArguments } from "../utils/index.js";
|
|
5
|
+
import type { RawTransactionArgument } from "../utils/index.js";
|
|
6
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
|
|
8
|
+
export interface BurnOrSendPositiveCoinArguments {
|
|
9
|
+
coin: RawTransactionArgument<string>;
|
|
10
|
+
recipient: RawTransactionArgument<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface BurnOrSendPositiveCoinOptions {
|
|
13
|
+
package?: string;
|
|
14
|
+
arguments:
|
|
15
|
+
| BurnOrSendPositiveCoinArguments
|
|
16
|
+
| [
|
|
17
|
+
coin: RawTransactionArgument<string>,
|
|
18
|
+
recipient: RawTransactionArgument<string>,
|
|
19
|
+
];
|
|
20
|
+
typeArguments: [string];
|
|
21
|
+
}
|
|
22
|
+
export function burnOrSendPositiveCoin(options: BurnOrSendPositiveCoinOptions) {
|
|
23
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
24
|
+
const argumentsTypes = [
|
|
25
|
+
`0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,
|
|
26
|
+
"address",
|
|
27
|
+
] satisfies string[];
|
|
28
|
+
const parameterNames = ["coin", "recipient"];
|
|
29
|
+
return (tx: Transaction) =>
|
|
30
|
+
tx.moveCall({
|
|
31
|
+
package: packageAddress,
|
|
32
|
+
module: "coin_utils",
|
|
33
|
+
function: "burn_or_send_positive_coin",
|
|
34
|
+
arguments: normalizeMoveArguments(
|
|
35
|
+
options.arguments,
|
|
36
|
+
argumentsTypes,
|
|
37
|
+
parameterNames,
|
|
38
|
+
),
|
|
39
|
+
typeArguments: options.typeArguments,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
|
|
5
|
+
/** Sui object identifiers */
|
|
6
|
+
|
|
7
|
+
import { MoveStruct } from "../../../utils/index.js";
|
|
8
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
9
|
+
|
|
10
|
+
const $moduleName = "0x2::object";
|
|
11
|
+
export const UID = new MoveStruct({
|
|
12
|
+
name: `${$moduleName}::UID`,
|
|
13
|
+
fields: {
|
|
14
|
+
id: bcs.Address,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
import * as object from "./deps/sui/object.js";
|
|
5
|
+
import { MoveStruct, normalizeMoveArguments } from "../utils/index.js";
|
|
6
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
7
|
+
import type { RawTransactionArgument } from "../utils/index.js";
|
|
8
|
+
import type { BcsType } from "@mysten/sui/bcs";
|
|
9
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
10
|
+
|
|
11
|
+
const $moduleName = "@local-pkg/zing_framework::derived_object_bag";
|
|
12
|
+
export const DerivedObjectBag = new MoveStruct({
|
|
13
|
+
name: `${$moduleName}::DerivedObjectBag`,
|
|
14
|
+
fields: {
|
|
15
|
+
/** the ID of this bag */
|
|
16
|
+
id: object.UID,
|
|
17
|
+
/** the number of key-value pairs in the bag */
|
|
18
|
+
size: bcs.u64(),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
export interface NewArguments<K extends BcsType<any>> {
|
|
22
|
+
parent: RawTransactionArgument<string>;
|
|
23
|
+
key: RawTransactionArgument<K>;
|
|
24
|
+
}
|
|
25
|
+
export interface NewOptions<K extends BcsType<any>> {
|
|
26
|
+
package?: string;
|
|
27
|
+
arguments:
|
|
28
|
+
| NewArguments<K>
|
|
29
|
+
| [parent: RawTransactionArgument<string>, key: RawTransactionArgument<K>];
|
|
30
|
+
typeArguments: [string];
|
|
31
|
+
}
|
|
32
|
+
/** Creates a new, empty bag */
|
|
33
|
+
export function _new<K extends BcsType<any>>(options: NewOptions<K>) {
|
|
34
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
35
|
+
const argumentsTypes = [
|
|
36
|
+
"0x0000000000000000000000000000000000000000000000000000000000000002::object::UID",
|
|
37
|
+
`${options.typeArguments[0]}`,
|
|
38
|
+
] satisfies string[];
|
|
39
|
+
const parameterNames = ["parent", "key"];
|
|
40
|
+
return (tx: Transaction) =>
|
|
41
|
+
tx.moveCall({
|
|
42
|
+
package: packageAddress,
|
|
43
|
+
module: "derived_object_bag",
|
|
44
|
+
function: "new",
|
|
45
|
+
arguments: normalizeMoveArguments(
|
|
46
|
+
options.arguments,
|
|
47
|
+
argumentsTypes,
|
|
48
|
+
parameterNames,
|
|
49
|
+
),
|
|
50
|
+
typeArguments: options.typeArguments,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export interface AddArguments<K extends BcsType<any>, V extends BcsType<any>> {
|
|
54
|
+
bag: RawTransactionArgument<string>;
|
|
55
|
+
k: RawTransactionArgument<K>;
|
|
56
|
+
v: RawTransactionArgument<V>;
|
|
57
|
+
}
|
|
58
|
+
export interface AddOptions<K extends BcsType<any>, V extends BcsType<any>> {
|
|
59
|
+
package?: string;
|
|
60
|
+
arguments:
|
|
61
|
+
| AddArguments<K, V>
|
|
62
|
+
| [
|
|
63
|
+
bag: RawTransactionArgument<string>,
|
|
64
|
+
k: RawTransactionArgument<K>,
|
|
65
|
+
v: RawTransactionArgument<V>,
|
|
66
|
+
];
|
|
67
|
+
typeArguments: [string, string];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Adds a key-value pair to the bag `bag: &mut DerivedObjectBag` Aborts with
|
|
71
|
+
* `sui::dynamic_field::EFieldAlreadyExists` if the bag already has an entry with
|
|
72
|
+
* that key `k: K`.
|
|
73
|
+
*/
|
|
74
|
+
export function add<K extends BcsType<any>, V extends BcsType<any>>(
|
|
75
|
+
options: AddOptions<K, V>,
|
|
76
|
+
) {
|
|
77
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
78
|
+
const argumentsTypes = [
|
|
79
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
80
|
+
`${options.typeArguments[0]}`,
|
|
81
|
+
`${options.typeArguments[1]}`,
|
|
82
|
+
] satisfies string[];
|
|
83
|
+
const parameterNames = ["bag", "k", "v"];
|
|
84
|
+
return (tx: Transaction) =>
|
|
85
|
+
tx.moveCall({
|
|
86
|
+
package: packageAddress,
|
|
87
|
+
module: "derived_object_bag",
|
|
88
|
+
function: "add",
|
|
89
|
+
arguments: normalizeMoveArguments(
|
|
90
|
+
options.arguments,
|
|
91
|
+
argumentsTypes,
|
|
92
|
+
parameterNames,
|
|
93
|
+
),
|
|
94
|
+
typeArguments: options.typeArguments,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export interface BorrowArguments<K extends BcsType<any>> {
|
|
98
|
+
bag: RawTransactionArgument<string>;
|
|
99
|
+
k: RawTransactionArgument<K>;
|
|
100
|
+
}
|
|
101
|
+
export interface BorrowOptions<K extends BcsType<any>> {
|
|
102
|
+
package?: string;
|
|
103
|
+
arguments:
|
|
104
|
+
| BorrowArguments<K>
|
|
105
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
106
|
+
typeArguments: [string, string];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Immutably borrows the value associated with the key in the bag
|
|
110
|
+
* `bag: &DerivedObjectBag`. Aborts with `sui::dynamic_field::EFieldDoesNotExist`
|
|
111
|
+
* if the bag does not have an entry with that key `k: K`. Aborts with
|
|
112
|
+
* `sui::dynamic_field::EFieldTypeMismatch` if the bag has an entry for the key,
|
|
113
|
+
* but the value does not have the specified type.
|
|
114
|
+
*/
|
|
115
|
+
export function borrow<K extends BcsType<any>>(options: BorrowOptions<K>) {
|
|
116
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
117
|
+
const argumentsTypes = [
|
|
118
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
119
|
+
`${options.typeArguments[0]}`,
|
|
120
|
+
] satisfies string[];
|
|
121
|
+
const parameterNames = ["bag", "k"];
|
|
122
|
+
return (tx: Transaction) =>
|
|
123
|
+
tx.moveCall({
|
|
124
|
+
package: packageAddress,
|
|
125
|
+
module: "derived_object_bag",
|
|
126
|
+
function: "borrow",
|
|
127
|
+
arguments: normalizeMoveArguments(
|
|
128
|
+
options.arguments,
|
|
129
|
+
argumentsTypes,
|
|
130
|
+
parameterNames,
|
|
131
|
+
),
|
|
132
|
+
typeArguments: options.typeArguments,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export interface BorrowMutArguments<K extends BcsType<any>> {
|
|
136
|
+
bag: RawTransactionArgument<string>;
|
|
137
|
+
k: RawTransactionArgument<K>;
|
|
138
|
+
}
|
|
139
|
+
export interface BorrowMutOptions<K extends BcsType<any>> {
|
|
140
|
+
package?: string;
|
|
141
|
+
arguments:
|
|
142
|
+
| BorrowMutArguments<K>
|
|
143
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
144
|
+
typeArguments: [string, string];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Mutably borrows the value associated with the key in the bag
|
|
148
|
+
* `bag: &mut DerivedObjectBag`. Aborts with
|
|
149
|
+
* `sui::dynamic_field::EFieldDoesNotExist` if the bag does not have an entry with
|
|
150
|
+
* that key `k: K`. Aborts with `sui::dynamic_field::EFieldTypeMismatch` if the bag
|
|
151
|
+
* has an entry for the key, but the value does not have the specified type.
|
|
152
|
+
*/
|
|
153
|
+
export function borrowMut<K extends BcsType<any>>(
|
|
154
|
+
options: BorrowMutOptions<K>,
|
|
155
|
+
) {
|
|
156
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
157
|
+
const argumentsTypes = [
|
|
158
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
159
|
+
`${options.typeArguments[0]}`,
|
|
160
|
+
] satisfies string[];
|
|
161
|
+
const parameterNames = ["bag", "k"];
|
|
162
|
+
return (tx: Transaction) =>
|
|
163
|
+
tx.moveCall({
|
|
164
|
+
package: packageAddress,
|
|
165
|
+
module: "derived_object_bag",
|
|
166
|
+
function: "borrow_mut",
|
|
167
|
+
arguments: normalizeMoveArguments(
|
|
168
|
+
options.arguments,
|
|
169
|
+
argumentsTypes,
|
|
170
|
+
parameterNames,
|
|
171
|
+
),
|
|
172
|
+
typeArguments: options.typeArguments,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
export interface RemoveArguments<K extends BcsType<any>> {
|
|
176
|
+
bag: RawTransactionArgument<string>;
|
|
177
|
+
k: RawTransactionArgument<K>;
|
|
178
|
+
}
|
|
179
|
+
export interface RemoveOptions<K extends BcsType<any>> {
|
|
180
|
+
package?: string;
|
|
181
|
+
arguments:
|
|
182
|
+
| RemoveArguments<K>
|
|
183
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
184
|
+
typeArguments: [string, string];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Mutably borrows the key-value pair in the bag `bag: &mut DerivedObjectBag` and
|
|
188
|
+
* returns the value. Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the
|
|
189
|
+
* bag does not have an entry with that key `k: K`. Aborts with
|
|
190
|
+
* `sui::dynamic_field::EFieldTypeMismatch` if the bag has an entry for the key,
|
|
191
|
+
* but the value does not have the specified type.
|
|
192
|
+
*/
|
|
193
|
+
export function remove<K extends BcsType<any>>(options: RemoveOptions<K>) {
|
|
194
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
195
|
+
const argumentsTypes = [
|
|
196
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
197
|
+
`${options.typeArguments[0]}`,
|
|
198
|
+
] satisfies string[];
|
|
199
|
+
const parameterNames = ["bag", "k"];
|
|
200
|
+
return (tx: Transaction) =>
|
|
201
|
+
tx.moveCall({
|
|
202
|
+
package: packageAddress,
|
|
203
|
+
module: "derived_object_bag",
|
|
204
|
+
function: "remove",
|
|
205
|
+
arguments: normalizeMoveArguments(
|
|
206
|
+
options.arguments,
|
|
207
|
+
argumentsTypes,
|
|
208
|
+
parameterNames,
|
|
209
|
+
),
|
|
210
|
+
typeArguments: options.typeArguments,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export interface ContainsArguments<K extends BcsType<any>> {
|
|
214
|
+
bag: RawTransactionArgument<string>;
|
|
215
|
+
k: RawTransactionArgument<K>;
|
|
216
|
+
}
|
|
217
|
+
export interface ContainsOptions<K extends BcsType<any>> {
|
|
218
|
+
package?: string;
|
|
219
|
+
arguments:
|
|
220
|
+
| ContainsArguments<K>
|
|
221
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
222
|
+
typeArguments: [string];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns true iff there is an value associated with the key `k: K` in the bag
|
|
226
|
+
* `bag: &DerivedObjectBag`
|
|
227
|
+
*/
|
|
228
|
+
export function contains<K extends BcsType<any>>(options: ContainsOptions<K>) {
|
|
229
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
230
|
+
const argumentsTypes = [
|
|
231
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
232
|
+
`${options.typeArguments[0]}`,
|
|
233
|
+
] satisfies string[];
|
|
234
|
+
const parameterNames = ["bag", "k"];
|
|
235
|
+
return (tx: Transaction) =>
|
|
236
|
+
tx.moveCall({
|
|
237
|
+
package: packageAddress,
|
|
238
|
+
module: "derived_object_bag",
|
|
239
|
+
function: "contains",
|
|
240
|
+
arguments: normalizeMoveArguments(
|
|
241
|
+
options.arguments,
|
|
242
|
+
argumentsTypes,
|
|
243
|
+
parameterNames,
|
|
244
|
+
),
|
|
245
|
+
typeArguments: options.typeArguments,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
export interface ContainsWithTypeArguments<K extends BcsType<any>> {
|
|
249
|
+
bag: RawTransactionArgument<string>;
|
|
250
|
+
k: RawTransactionArgument<K>;
|
|
251
|
+
}
|
|
252
|
+
export interface ContainsWithTypeOptions<K extends BcsType<any>> {
|
|
253
|
+
package?: string;
|
|
254
|
+
arguments:
|
|
255
|
+
| ContainsWithTypeArguments<K>
|
|
256
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
257
|
+
typeArguments: [string, string];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Returns true iff there is an value associated with the key `k: K` in the bag
|
|
261
|
+
* `bag: &DerivedObjectBag` with an assigned value of type `V`
|
|
262
|
+
*/
|
|
263
|
+
export function containsWithType<K extends BcsType<any>>(
|
|
264
|
+
options: ContainsWithTypeOptions<K>,
|
|
265
|
+
) {
|
|
266
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
267
|
+
const argumentsTypes = [
|
|
268
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
269
|
+
`${options.typeArguments[0]}`,
|
|
270
|
+
] satisfies string[];
|
|
271
|
+
const parameterNames = ["bag", "k"];
|
|
272
|
+
return (tx: Transaction) =>
|
|
273
|
+
tx.moveCall({
|
|
274
|
+
package: packageAddress,
|
|
275
|
+
module: "derived_object_bag",
|
|
276
|
+
function: "contains_with_type",
|
|
277
|
+
arguments: normalizeMoveArguments(
|
|
278
|
+
options.arguments,
|
|
279
|
+
argumentsTypes,
|
|
280
|
+
parameterNames,
|
|
281
|
+
),
|
|
282
|
+
typeArguments: options.typeArguments,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
export interface LengthArguments {
|
|
286
|
+
bag: RawTransactionArgument<string>;
|
|
287
|
+
}
|
|
288
|
+
export interface LengthOptions {
|
|
289
|
+
package?: string;
|
|
290
|
+
arguments: LengthArguments | [bag: RawTransactionArgument<string>];
|
|
291
|
+
}
|
|
292
|
+
/** Returns the size of the bag, the number of key-value pairs */
|
|
293
|
+
export function length(options: LengthOptions) {
|
|
294
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
295
|
+
const argumentsTypes = [
|
|
296
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
297
|
+
] satisfies string[];
|
|
298
|
+
const parameterNames = ["bag"];
|
|
299
|
+
return (tx: Transaction) =>
|
|
300
|
+
tx.moveCall({
|
|
301
|
+
package: packageAddress,
|
|
302
|
+
module: "derived_object_bag",
|
|
303
|
+
function: "length",
|
|
304
|
+
arguments: normalizeMoveArguments(
|
|
305
|
+
options.arguments,
|
|
306
|
+
argumentsTypes,
|
|
307
|
+
parameterNames,
|
|
308
|
+
),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
export interface IsEmptyArguments {
|
|
312
|
+
bag: RawTransactionArgument<string>;
|
|
313
|
+
}
|
|
314
|
+
export interface IsEmptyOptions {
|
|
315
|
+
package?: string;
|
|
316
|
+
arguments: IsEmptyArguments | [bag: RawTransactionArgument<string>];
|
|
317
|
+
}
|
|
318
|
+
/** Returns true iff the bag is empty (if `length` returns `0`) */
|
|
319
|
+
export function isEmpty(options: IsEmptyOptions) {
|
|
320
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
321
|
+
const argumentsTypes = [
|
|
322
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
323
|
+
] satisfies string[];
|
|
324
|
+
const parameterNames = ["bag"];
|
|
325
|
+
return (tx: Transaction) =>
|
|
326
|
+
tx.moveCall({
|
|
327
|
+
package: packageAddress,
|
|
328
|
+
module: "derived_object_bag",
|
|
329
|
+
function: "is_empty",
|
|
330
|
+
arguments: normalizeMoveArguments(
|
|
331
|
+
options.arguments,
|
|
332
|
+
argumentsTypes,
|
|
333
|
+
parameterNames,
|
|
334
|
+
),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
export interface DestroyEmptyArguments {
|
|
338
|
+
bag: RawTransactionArgument<string>;
|
|
339
|
+
}
|
|
340
|
+
export interface DestroyEmptyOptions {
|
|
341
|
+
package?: string;
|
|
342
|
+
arguments: DestroyEmptyArguments | [bag: RawTransactionArgument<string>];
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Destroys an empty bag Aborts with `EBagNotEmpty` if the bag still contains
|
|
346
|
+
* values
|
|
347
|
+
*/
|
|
348
|
+
export function destroyEmpty(options: DestroyEmptyOptions) {
|
|
349
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
350
|
+
const argumentsTypes = [
|
|
351
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
352
|
+
] satisfies string[];
|
|
353
|
+
const parameterNames = ["bag"];
|
|
354
|
+
return (tx: Transaction) =>
|
|
355
|
+
tx.moveCall({
|
|
356
|
+
package: packageAddress,
|
|
357
|
+
module: "derived_object_bag",
|
|
358
|
+
function: "destroy_empty",
|
|
359
|
+
arguments: normalizeMoveArguments(
|
|
360
|
+
options.arguments,
|
|
361
|
+
argumentsTypes,
|
|
362
|
+
parameterNames,
|
|
363
|
+
),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
export interface ValueIdArguments<K extends BcsType<any>> {
|
|
367
|
+
bag: RawTransactionArgument<string>;
|
|
368
|
+
k: RawTransactionArgument<K>;
|
|
369
|
+
}
|
|
370
|
+
export interface ValueIdOptions<K extends BcsType<any>> {
|
|
371
|
+
package?: string;
|
|
372
|
+
arguments:
|
|
373
|
+
| ValueIdArguments<K>
|
|
374
|
+
| [bag: RawTransactionArgument<string>, k: RawTransactionArgument<K>];
|
|
375
|
+
typeArguments: [string];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Returns the ID of the object associated with the key if the bag has an entry
|
|
379
|
+
* with key `k: K` Returns none otherwise
|
|
380
|
+
*/
|
|
381
|
+
export function valueId<K extends BcsType<any>>(options: ValueIdOptions<K>) {
|
|
382
|
+
const packageAddress = options.package ?? "@local-pkg/zing_framework";
|
|
383
|
+
const argumentsTypes = [
|
|
384
|
+
`${packageAddress}::derived_object_bag::DerivedObjectBag`,
|
|
385
|
+
`${options.typeArguments[0]}`,
|
|
386
|
+
] satisfies string[];
|
|
387
|
+
const parameterNames = ["bag", "k"];
|
|
388
|
+
return (tx: Transaction) =>
|
|
389
|
+
tx.moveCall({
|
|
390
|
+
package: packageAddress,
|
|
391
|
+
module: "derived_object_bag",
|
|
392
|
+
function: "value_id",
|
|
393
|
+
arguments: normalizeMoveArguments(
|
|
394
|
+
options.arguments,
|
|
395
|
+
argumentsTypes,
|
|
396
|
+
parameterNames,
|
|
397
|
+
),
|
|
398
|
+
typeArguments: options.typeArguments,
|
|
399
|
+
});
|
|
400
|
+
}
|