@suilend/sdk 12.7.0 → 13.0.0-next.g803bba0
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/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
- package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
- package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
- package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
- package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
- package/_generated/_dependencies/std/option/structs.js +155 -0
- package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
- package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
- package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
- package/_generated/_dependencies/sui/bag/structs.js +154 -0
- package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
- package/_generated/_dependencies/sui/balance/structs.js +306 -0
- package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
- package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
- package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
- package/_generated/_dependencies/sui/object-table/structs.js +164 -0
- package/_generated/_envs/index.d.ts +3 -0
- package/_generated/_envs/index.js +18 -0
- package/_generated/_envs/mainnet.d.ts +2 -0
- package/_generated/_envs/mainnet.js +490 -0
- package/_generated/_framework/env.d.ts +137 -0
- package/_generated/_framework/env.js +261 -0
- package/_generated/_framework/reified.d.ts +68 -36
- package/_generated/_framework/reified.js +110 -98
- package/_generated/_framework/util.d.ts +4 -4
- package/_generated/_framework/util.js +82 -79
- package/_generated/_framework/vector.d.ts +11 -9
- package/_generated/_framework/vector.js +10 -10
- package/_generated/suilend/cell/structs.d.ts +24 -22
- package/_generated/suilend/cell/structs.js +68 -24
- package/_generated/suilend/decimal/structs.d.ts +28 -24
- package/_generated/suilend/decimal/structs.js +45 -24
- package/_generated/suilend/index.d.ts +5 -6
- package/_generated/suilend/index.js +10 -19
- package/_generated/suilend/lending-market/functions.d.ts +1123 -149
- package/_generated/suilend/lending-market/functions.js +1121 -207
- package/_generated/suilend/lending-market/structs.d.ts +985 -1290
- package/_generated/suilend/lending-market/structs.js +2482 -1282
- package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
- package/_generated/suilend/lending-market-registry/functions.js +30 -6
- package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
- package/_generated/suilend/liquidity-mining/structs.js +449 -319
- package/_generated/suilend/obligation/structs.d.ts +406 -918
- package/_generated/suilend/obligation/structs.js +786 -596
- package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
- package/_generated/suilend/rate-limiter/functions.js +139 -21
- package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
- package/_generated/suilend/rate-limiter/structs.js +98 -48
- package/_generated/suilend/reserve/structs.d.ts +611 -904
- package/_generated/suilend/reserve/structs.js +1528 -736
- package/_generated/suilend/reserve-config/functions.d.ts +718 -96
- package/_generated/suilend/reserve-config/functions.js +751 -157
- package/_generated/suilend/reserve-config/structs.d.ts +148 -163
- package/_generated/suilend/reserve-config/structs.js +260 -94
- package/client.d.ts +2 -2
- package/client.js +22 -39
- package/lib/initialize.d.ts +76 -76
- package/lib/initialize.js +10 -10
- package/lib/proCompatible.js +5 -5
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +9 -9
- package/parsers/obligation.d.ts +14 -14
- package/parsers/obligation.js +4 -4
- package/parsers/rateLimiter.d.ts +1 -1
- package/parsers/reserve.d.ts +12 -12
- package/parsers/reserve.js +2 -2
- package/strategies.d.ts +14 -14
- package/utils/simulate.d.ts +1 -1
- package/utils/simulate.js +5 -5
- package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
- package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x1/index.js +0 -3
- package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
- package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
- package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
- package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x2/index.js +0 -3
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
- package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment management for sui-client-gen generated code.
|
|
3
|
+
*
|
|
4
|
+
* This module provides runtime environment switching, allowing generated code
|
|
5
|
+
* to work with different networks (mainnet, testnet, custom) without regeneration.
|
|
6
|
+
*/
|
|
7
|
+
// Environment registry - maps env name to config
|
|
8
|
+
const envRegistry = {};
|
|
9
|
+
// Active environment state
|
|
10
|
+
let activeEnv = null;
|
|
11
|
+
let activeEnvName = null;
|
|
12
|
+
let publishedAtOverrides = {};
|
|
13
|
+
/**
|
|
14
|
+
* Register an environment configuration.
|
|
15
|
+
* Called during init to register generated env configs.
|
|
16
|
+
*/
|
|
17
|
+
export function registerEnv(name, config) {
|
|
18
|
+
envRegistry[name] = config;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get a registered environment configuration by name.
|
|
22
|
+
* Useful when building an ad-hoc config derived from a known env, e.g. via `cloneEnv`.
|
|
23
|
+
* @throws Error if the environment is not registered.
|
|
24
|
+
*/
|
|
25
|
+
export function getEnv(name) {
|
|
26
|
+
const config = envRegistry[name];
|
|
27
|
+
if (!config) {
|
|
28
|
+
const available = Object.keys(envRegistry).join(', ') || '(none registered)';
|
|
29
|
+
throw new Error(`Environment '${name}' not found. Available: ${available}`);
|
|
30
|
+
}
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Produce a new `EnvConfig` by shallow-merging `overrides` onto `base`, per package.
|
|
35
|
+
*
|
|
36
|
+
* Only the fields you provide on each package are replaced — other fields (including
|
|
37
|
+
* the untouched packages) are preserved by reference. Useful for creating a scoped
|
|
38
|
+
* env for a single call (e.g. to target a historical `publishedAt`) without mutating
|
|
39
|
+
* any shared state.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const historical = cloneEnv(getEnv('mainnet'), {
|
|
43
|
+
* packages: { 'my-app': { publishedAt: '0x...' } },
|
|
44
|
+
* })
|
|
45
|
+
* transfer(tx, typeArgs, args, { env: historical })
|
|
46
|
+
*/
|
|
47
|
+
export function cloneEnv(base, overrides) {
|
|
48
|
+
const mergeSection = (section, patch) => {
|
|
49
|
+
if (!patch)
|
|
50
|
+
return { ...section };
|
|
51
|
+
const merged = { ...section };
|
|
52
|
+
for (const [pkgName, pkgPatch] of Object.entries(patch)) {
|
|
53
|
+
const prior = section[pkgName];
|
|
54
|
+
if (!prior) {
|
|
55
|
+
throw new Error(`cloneEnv: cannot override unknown package '${pkgName}'. `
|
|
56
|
+
+ `Available: ${Object.keys(section).join(', ') || '(none)'}`);
|
|
57
|
+
}
|
|
58
|
+
merged[pkgName] = {
|
|
59
|
+
...prior,
|
|
60
|
+
...pkgPatch,
|
|
61
|
+
typeOrigins: { ...prior.typeOrigins, ...(pkgPatch.typeOrigins ?? {}) },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return merged;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
packages: mergeSection(base.packages, overrides?.packages),
|
|
68
|
+
dependencies: mergeSection(base.dependencies, overrides?.dependencies),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set the active environment by name.
|
|
73
|
+
* @param name - The name of a registered environment
|
|
74
|
+
* @param overrides - Optional map of package names to publishedAt addresses to override
|
|
75
|
+
* @throws Error if the environment is not registered
|
|
76
|
+
*/
|
|
77
|
+
export function setActiveEnv(name, overrides) {
|
|
78
|
+
if (!envRegistry[name]) {
|
|
79
|
+
const available = Object.keys(envRegistry).join(', ') || '(none registered)';
|
|
80
|
+
throw new Error(`Environment '${name}' not found. Available: ${available}`);
|
|
81
|
+
}
|
|
82
|
+
activeEnv = envRegistry[name];
|
|
83
|
+
activeEnvName = name;
|
|
84
|
+
publishedAtOverrides = overrides ?? {};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Set the active environment using a custom config object.
|
|
88
|
+
* Use this to provide a custom environment configuration at runtime.
|
|
89
|
+
* @param config - A custom EnvConfig object
|
|
90
|
+
* @param overrides - Optional map of package names to publishedAt addresses to override
|
|
91
|
+
*/
|
|
92
|
+
export function setActiveEnvWithConfig(config, overrides) {
|
|
93
|
+
activeEnv = config;
|
|
94
|
+
activeEnvName = 'custom';
|
|
95
|
+
publishedAtOverrides = overrides ?? {};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the active environment configuration.
|
|
99
|
+
* @throws Error if no environment is set
|
|
100
|
+
*/
|
|
101
|
+
export function getActiveEnv() {
|
|
102
|
+
if (!activeEnv) {
|
|
103
|
+
throw new Error('No active environment. Call setActiveEnv() or import the envs module first.');
|
|
104
|
+
}
|
|
105
|
+
return activeEnv;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the active environment name.
|
|
109
|
+
* Returns null if no environment is set.
|
|
110
|
+
*/
|
|
111
|
+
export function getActiveEnvName() {
|
|
112
|
+
return activeEnvName;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the list of registered environment names.
|
|
116
|
+
*/
|
|
117
|
+
export function getRegisteredEnvs() {
|
|
118
|
+
return Object.keys(envRegistry);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Describe the env source for error messages: either a caller-supplied scope or
|
|
122
|
+
* the current active env (named).
|
|
123
|
+
*/
|
|
124
|
+
function envScopeLabel(env) {
|
|
125
|
+
return env ? 'supplied environment' : `active environment '${activeEnvName}'`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolve an `EnvConfig` for a read: use the caller-supplied one if present, else
|
|
129
|
+
* fall back to the active global env. A missing active env throws.
|
|
130
|
+
*/
|
|
131
|
+
function resolveEnv(env) {
|
|
132
|
+
return env ?? getActiveEnv();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get configuration for a top-level package.
|
|
136
|
+
* @throws Error if package not found
|
|
137
|
+
*/
|
|
138
|
+
export function getPackageConfig(pkgName, env) {
|
|
139
|
+
const source = resolveEnv(env);
|
|
140
|
+
const config = source.packages[pkgName];
|
|
141
|
+
if (!config) {
|
|
142
|
+
throw new Error(`Package '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
143
|
+
}
|
|
144
|
+
return config;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get configuration for a dependency package.
|
|
148
|
+
* @throws Error if dependency not found
|
|
149
|
+
*/
|
|
150
|
+
export function getDependencyConfig(pkgName, env) {
|
|
151
|
+
const source = resolveEnv(env);
|
|
152
|
+
const config = source.dependencies[pkgName];
|
|
153
|
+
if (!config) {
|
|
154
|
+
throw new Error(`Dependency '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
155
|
+
}
|
|
156
|
+
return config;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the publishedAt address for function calls.
|
|
160
|
+
*
|
|
161
|
+
* When an explicit `env` is supplied, it is authoritative and the module-level
|
|
162
|
+
* `publishedAtOverrides` (set via `setActiveEnv`) are ignored — callers that pass
|
|
163
|
+
* their own env own their own scope. Otherwise the active env is used with overrides
|
|
164
|
+
* applied on top.
|
|
165
|
+
*
|
|
166
|
+
* @throws Error if package not found
|
|
167
|
+
*/
|
|
168
|
+
export function getPublishedAt(pkgName, env) {
|
|
169
|
+
if (env) {
|
|
170
|
+
const config = env.packages[pkgName] || env.dependencies[pkgName];
|
|
171
|
+
if (!config) {
|
|
172
|
+
throw new Error(`Package '${pkgName}' not found in supplied environment`);
|
|
173
|
+
}
|
|
174
|
+
return config.publishedAt;
|
|
175
|
+
}
|
|
176
|
+
if (publishedAtOverrides[pkgName]) {
|
|
177
|
+
return publishedAtOverrides[pkgName];
|
|
178
|
+
}
|
|
179
|
+
const active = getActiveEnv();
|
|
180
|
+
const config = active.packages[pkgName] || active.dependencies[pkgName];
|
|
181
|
+
if (!config) {
|
|
182
|
+
throw new Error(`Package '${pkgName}' not found in active environment '${activeEnvName}'`);
|
|
183
|
+
}
|
|
184
|
+
return config.publishedAt;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get the type origin address for a specific type.
|
|
188
|
+
* Used in $typeName construction for structs and enums.
|
|
189
|
+
* @param pkgName - Kebab-case package name
|
|
190
|
+
* @param moduleTypePath - "module::TypeName" format (e.g., "balance::Balance")
|
|
191
|
+
* @throws Error if package or type origin not found
|
|
192
|
+
*/
|
|
193
|
+
export function getTypeOrigin(pkgName, moduleTypePath, env) {
|
|
194
|
+
const source = resolveEnv(env);
|
|
195
|
+
const config = source.packages[pkgName] || source.dependencies[pkgName];
|
|
196
|
+
if (!config) {
|
|
197
|
+
throw new Error(`Package '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
198
|
+
}
|
|
199
|
+
const origin = config.typeOrigins[moduleTypePath];
|
|
200
|
+
if (!origin) {
|
|
201
|
+
throw new Error(`Type origin for '${moduleTypePath}' not found in package '${pkgName}'. `
|
|
202
|
+
+ `Available: ${Object.keys(config.typeOrigins).join(', ') || '(none)'}`);
|
|
203
|
+
}
|
|
204
|
+
return origin;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the original package ID.
|
|
208
|
+
* Works for both packages and dependencies.
|
|
209
|
+
* @throws Error if package not found
|
|
210
|
+
*/
|
|
211
|
+
export function getOriginalId(pkgName, env) {
|
|
212
|
+
const source = resolveEnv(env);
|
|
213
|
+
const config = source.packages[pkgName] || source.dependencies[pkgName];
|
|
214
|
+
if (!config) {
|
|
215
|
+
throw new Error(`Package '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
216
|
+
}
|
|
217
|
+
return config.originalId;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get all distinct addresses where types in this package were defined.
|
|
221
|
+
* Useful for understanding package upgrade history and querying objects.
|
|
222
|
+
* Works for both packages and dependencies.
|
|
223
|
+
* @param pkgName - Kebab-case package name
|
|
224
|
+
* @returns Array of unique addresses, sorted for determinism
|
|
225
|
+
* @throws Error if package not found
|
|
226
|
+
*/
|
|
227
|
+
export function getTypeOriginAddresses(pkgName, env) {
|
|
228
|
+
const source = resolveEnv(env);
|
|
229
|
+
const config = source.packages[pkgName] || source.dependencies[pkgName];
|
|
230
|
+
if (!config) {
|
|
231
|
+
throw new Error(`Package '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
232
|
+
}
|
|
233
|
+
const uniqueAddresses = new Set(Object.values(config.typeOrigins));
|
|
234
|
+
return Array.from(uniqueAddresses).sort();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get distinct addresses where specific types are defined.
|
|
238
|
+
* Useful for querying objects of specific types.
|
|
239
|
+
* Works for both packages and dependencies.
|
|
240
|
+
* @param pkgName - Kebab-case package name
|
|
241
|
+
* @param moduleTypePaths - Array of "module::TypeName" strings (e.g., ["balance::Balance", "coin::Coin"])
|
|
242
|
+
* @returns Array of unique addresses, sorted for determinism
|
|
243
|
+
* @throws Error if package not found or any type origin not found
|
|
244
|
+
*/
|
|
245
|
+
export function getTypeOriginAddressesFor(pkgName, moduleTypePaths, env) {
|
|
246
|
+
const source = resolveEnv(env);
|
|
247
|
+
const config = source.packages[pkgName] || source.dependencies[pkgName];
|
|
248
|
+
if (!config) {
|
|
249
|
+
throw new Error(`Package '${pkgName}' not found in ${envScopeLabel(env)}`);
|
|
250
|
+
}
|
|
251
|
+
const addresses = new Set();
|
|
252
|
+
for (const path of moduleTypePaths) {
|
|
253
|
+
const origin = config.typeOrigins[path];
|
|
254
|
+
if (!origin) {
|
|
255
|
+
throw new Error(`Type origin for '${path}' not found in package '${pkgName}'. `
|
|
256
|
+
+ `Available: ${Object.keys(config.typeOrigins).join(', ') || '(none)'}`);
|
|
257
|
+
}
|
|
258
|
+
addresses.add(origin);
|
|
259
|
+
}
|
|
260
|
+
return Array.from(addresses).sort();
|
|
261
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BcsType } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export { vector } from
|
|
1
|
+
import { BcsType } from '@mysten/sui/bcs';
|
|
2
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
3
|
+
import { FieldsWithTypes } from './util';
|
|
4
|
+
export { vector } from './vector';
|
|
5
5
|
export interface StructClass {
|
|
6
6
|
readonly $typeName: string;
|
|
7
7
|
readonly $fullTypeName: string;
|
|
@@ -12,7 +12,7 @@ export interface StructClass {
|
|
|
12
12
|
__StructClass: true;
|
|
13
13
|
}
|
|
14
14
|
export interface VectorClass {
|
|
15
|
-
readonly $typeName:
|
|
15
|
+
readonly $typeName: 'vector';
|
|
16
16
|
readonly $fullTypeName: string;
|
|
17
17
|
readonly $typeArgs: [string];
|
|
18
18
|
readonly $isPhantom: readonly [false];
|
|
@@ -21,13 +21,23 @@ export interface VectorClass {
|
|
|
21
21
|
readonly elements: any;
|
|
22
22
|
__VectorClass: true;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
25
|
-
|
|
24
|
+
export interface EnumVariantClass {
|
|
25
|
+
readonly $typeName: string;
|
|
26
|
+
readonly $fullTypeName: string;
|
|
27
|
+
readonly $variantName: string;
|
|
28
|
+
readonly $typeArgs: string[];
|
|
29
|
+
readonly $isPhantom: readonly boolean[];
|
|
30
|
+
toJSONField(): Record<string, any>;
|
|
31
|
+
toJSON(): Record<string, any>;
|
|
32
|
+
__EnumVariantClass: true;
|
|
33
|
+
}
|
|
34
|
+
export type Primitive = 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'address';
|
|
35
|
+
export type TypeArgument = StructClass | Primitive | VectorClass | EnumVariantClass;
|
|
26
36
|
export interface StructClassReified<T extends StructClass, Fields> {
|
|
27
|
-
typeName: T[
|
|
37
|
+
typeName: T['$typeName'];
|
|
28
38
|
fullTypeName: ToTypeStr<T>;
|
|
29
|
-
typeArgs: T[
|
|
30
|
-
isPhantom: T[
|
|
39
|
+
typeArgs: T['$typeArgs'];
|
|
40
|
+
isPhantom: T['$isPhantom'];
|
|
31
41
|
reifiedTypeArgs: Array<Reified<TypeArgument, any> | PhantomReified<PhantomTypeArgument>>;
|
|
32
42
|
bcs: BcsType<any>;
|
|
33
43
|
fromFields(fields: Record<string, any>): T;
|
|
@@ -35,14 +45,17 @@ export interface StructClassReified<T extends StructClass, Fields> {
|
|
|
35
45
|
fromBcs(data: Uint8Array): T;
|
|
36
46
|
fromJSONField: (field: any) => T;
|
|
37
47
|
fromJSON: (json: Record<string, any>) => T;
|
|
38
|
-
|
|
48
|
+
fromCoreObject: (obj: SuiClientTypes.Object<{
|
|
49
|
+
content: true;
|
|
50
|
+
}>) => T;
|
|
51
|
+
fetch: (client: ClientWithCoreApi, id: string) => Promise<T>;
|
|
39
52
|
new: (fields: Fields) => T;
|
|
40
|
-
kind:
|
|
53
|
+
kind: 'StructClassReified';
|
|
41
54
|
}
|
|
42
55
|
export interface VectorClassReified<T extends VectorClass, Elements> {
|
|
43
|
-
typeName: T[
|
|
56
|
+
typeName: T['$typeName'];
|
|
44
57
|
fullTypeName: ToTypeStr<T>;
|
|
45
|
-
typeArgs: T[
|
|
58
|
+
typeArgs: T['$typeArgs'];
|
|
46
59
|
isPhantom: readonly [false];
|
|
47
60
|
reifiedTypeArgs: Array<Reified<TypeArgument, any>>;
|
|
48
61
|
bcs: BcsType<any>;
|
|
@@ -52,48 +65,67 @@ export interface VectorClassReified<T extends VectorClass, Elements> {
|
|
|
52
65
|
fromJSONField: (field: any) => T;
|
|
53
66
|
fromJSON: (json: Record<string, any>) => T;
|
|
54
67
|
new: (elements: Elements) => T;
|
|
55
|
-
kind:
|
|
68
|
+
kind: 'VectorClassReified';
|
|
56
69
|
}
|
|
57
|
-
export
|
|
58
|
-
|
|
70
|
+
export interface EnumClassReified<T extends EnumVariantClass, Fields> {
|
|
71
|
+
typeName: T['$typeName'];
|
|
72
|
+
fullTypeName: T['$fullTypeName'];
|
|
73
|
+
typeArgs: T['$typeArgs'];
|
|
74
|
+
isPhantom: T['$isPhantom'];
|
|
75
|
+
reifiedTypeArgs: Array<Reified<TypeArgument, any> | PhantomReified<PhantomTypeArgument>>;
|
|
76
|
+
bcs: BcsType<any>;
|
|
77
|
+
fromFields(fields: Record<string, any>): T;
|
|
78
|
+
fromFieldsWithTypes(item: FieldsWithTypes): T;
|
|
79
|
+
fromBcs(data: Uint8Array): T;
|
|
80
|
+
fromJSONField: (field: any) => T;
|
|
81
|
+
fromJSON: (json: Record<string, any>) => T;
|
|
82
|
+
new: (variant: string, fields: Fields) => T;
|
|
83
|
+
kind: 'EnumClassReified';
|
|
84
|
+
}
|
|
85
|
+
export type Reified<T extends TypeArgument, Fields> = T extends Primitive ? Primitive : T extends StructClass ? StructClassReified<T, Fields> : T extends VectorClass ? VectorClassReified<T, Fields> : T extends EnumVariantClass ? EnumClassReified<T, Fields> : never;
|
|
86
|
+
export type ToTypeArgument<T extends Primitive | StructClassReified<StructClass, any> | VectorClassReified<VectorClass, any> | EnumClassReified<EnumVariantClass, any>> = T extends Primitive ? T : T extends StructClassReified<infer U, any> ? U : T extends VectorClassReified<infer U, any> ? U : T extends EnumClassReified<infer U, any> ? U : never;
|
|
59
87
|
export type ToPhantomTypeArgument<T extends PhantomReified<PhantomTypeArgument>> = T extends PhantomReified<infer U> ? U : never;
|
|
60
88
|
export type PhantomTypeArgument = string;
|
|
61
89
|
export interface PhantomReified<P> {
|
|
62
|
-
phantomType: P;
|
|
63
|
-
kind:
|
|
90
|
+
readonly phantomType: P;
|
|
91
|
+
kind: 'PhantomReified';
|
|
64
92
|
}
|
|
65
93
|
export declare function phantom<T extends Reified<TypeArgument, any>>(reified: T): PhantomReified<ToTypeStr<ToTypeArgument<T>>>;
|
|
66
94
|
export declare function phantom<P extends PhantomTypeArgument>(phantomType: P): PhantomReified<P>;
|
|
67
|
-
export type ToTypeStr<T extends TypeArgument> = T extends Primitive ? T : T extends StructClass ? T[
|
|
95
|
+
export type ToTypeStr<T extends TypeArgument> = T extends Primitive ? T : T extends StructClass ? T['$fullTypeName'] : T extends VectorClass ? T['$fullTypeName'] : never;
|
|
68
96
|
export type PhantomToTypeStr<T extends PhantomTypeArgument> = T extends PhantomTypeArgument ? T : never;
|
|
69
|
-
export type ToJSON<T extends TypeArgument> = T extends
|
|
70
|
-
$typeName:
|
|
97
|
+
export type ToJSON<T extends TypeArgument> = T extends 'bool' ? boolean : T extends 'u8' ? number : T extends 'u16' ? number : T extends 'u32' ? number : T extends 'u64' ? string : T extends 'u128' ? string : T extends 'u256' ? string : T extends 'address' ? string : T extends {
|
|
98
|
+
$typeName: '0x1::string::String';
|
|
71
99
|
} ? string : T extends {
|
|
72
|
-
$typeName:
|
|
100
|
+
$typeName: '0x1::ascii::String';
|
|
73
101
|
} ? string : T extends {
|
|
74
|
-
$typeName:
|
|
102
|
+
$typeName: '0x2::object::UID';
|
|
75
103
|
} ? string : T extends {
|
|
76
|
-
$typeName:
|
|
104
|
+
$typeName: '0x2::object::ID';
|
|
77
105
|
} ? string : T extends {
|
|
78
|
-
$typeName:
|
|
106
|
+
$typeName: '0x2::url::Url';
|
|
79
107
|
} ? string : T extends {
|
|
80
|
-
$typeName:
|
|
108
|
+
$typeName: '0x1::type_name::TypeName';
|
|
109
|
+
} ? string : T extends {
|
|
110
|
+
$typeName: '0x1::option::Option';
|
|
81
111
|
__inner: infer U extends TypeArgument;
|
|
82
|
-
} ? ToJSON<U> | null : T extends VectorClass ? ReturnType<T[
|
|
83
|
-
export type ToField<T extends TypeArgument> = T extends
|
|
84
|
-
$typeName:
|
|
112
|
+
} ? ToJSON<U> | null : T extends VectorClass ? ReturnType<T['toJSONField']> : T extends StructClass ? ReturnType<T['toJSONField']> : T extends EnumVariantClass ? ReturnType<T['toJSONField']> : never;
|
|
113
|
+
export type ToField<T extends TypeArgument> = T extends 'bool' ? boolean : T extends 'u8' ? number : T extends 'u16' ? number : T extends 'u32' ? number : T extends 'u64' ? bigint : T extends 'u128' ? bigint : T extends 'u256' ? bigint : T extends 'address' ? string : T extends {
|
|
114
|
+
$typeName: '0x1::string::String';
|
|
115
|
+
} ? string : T extends {
|
|
116
|
+
$typeName: '0x1::ascii::String';
|
|
85
117
|
} ? string : T extends {
|
|
86
|
-
$typeName:
|
|
118
|
+
$typeName: '0x2::object::UID';
|
|
87
119
|
} ? string : T extends {
|
|
88
|
-
$typeName:
|
|
120
|
+
$typeName: '0x2::object::ID';
|
|
89
121
|
} ? string : T extends {
|
|
90
|
-
$typeName:
|
|
122
|
+
$typeName: '0x2::url::Url';
|
|
91
123
|
} ? string : T extends {
|
|
92
|
-
$typeName:
|
|
124
|
+
$typeName: '0x1::type_name::TypeName';
|
|
93
125
|
} ? string : T extends {
|
|
94
|
-
$typeName:
|
|
126
|
+
$typeName: '0x1::option::Option';
|
|
95
127
|
__inner: infer U extends TypeArgument;
|
|
96
|
-
} ? ToField<U> | null : T extends VectorClass ? T[
|
|
128
|
+
} ? ToField<U> | null : T extends VectorClass ? T['elements'] : T extends StructClass ? T : T extends EnumVariantClass ? T : never;
|
|
97
129
|
export declare function toBcs<T extends Reified<TypeArgument, any>>(arg: T): BcsType<any>;
|
|
98
130
|
export declare function extractType<T extends Reified<TypeArgument, any>>(reified: T): ToTypeStr<ToTypeArgument<T>>;
|
|
99
131
|
export declare function extractType<T extends PhantomReified<PhantomTypeArgument>>(reified: T): PhantomToTypeStr<ToPhantomTypeArgument<T>>;
|