@haneullabs/haneulns 1.0.2 → 1.2.5
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/CHANGELOG.md +108 -0
- package/dist/constants.d.mts +0 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +20 -20
- package/dist/constants.mjs.map +1 -1
- package/dist/contracts/haneulns/controller.mjs +11 -4
- package/dist/contracts/haneulns/controller.mjs.map +1 -1
- package/dist/contracts/haneulns/deps/haneul/balance.mjs +2 -13
- package/dist/contracts/haneulns/deps/haneul/balance.mjs.map +1 -1
- package/dist/contracts/haneulns/deps/haneul/vec_map.mjs +1 -2
- package/dist/contracts/haneulns/deps/haneul/vec_map.mjs.map +1 -1
- package/dist/contracts/haneulns/deps/std/type_name.mjs +13 -10
- package/dist/contracts/haneulns/deps/std/type_name.mjs.map +1 -1
- package/dist/contracts/haneulns/domain.mjs +11 -16
- package/dist/contracts/haneulns/domain.mjs.map +1 -1
- package/dist/contracts/haneulns/haneulns.mjs +12 -9
- package/dist/contracts/haneulns/haneulns.mjs.map +1 -1
- package/dist/contracts/haneulns/name_record.mjs +14 -13
- package/dist/contracts/haneulns/name_record.mjs.map +1 -1
- package/dist/contracts/haneulns/payment.mjs +16 -17
- package/dist/contracts/haneulns/payment.mjs.map +1 -1
- package/dist/contracts/haneulns/pricing_config.mjs +1 -2
- package/dist/contracts/haneulns/pricing_config.mjs.map +1 -1
- package/dist/contracts/haneulns_coupons/coupon_house.mjs +4 -5
- package/dist/contracts/haneulns_coupons/coupon_house.mjs.map +1 -1
- package/dist/contracts/haneulns_coupons/data.mjs +2 -8
- package/dist/contracts/haneulns_coupons/data.mjs.map +1 -1
- package/dist/contracts/haneulns_coupons/deps/haneul/bag.mjs +4 -32
- package/dist/contracts/haneulns_coupons/deps/haneul/bag.mjs.map +1 -1
- package/dist/contracts/haneulns_discounts/deps/haneul/linked_table.mjs +5 -2
- package/dist/contracts/haneulns_discounts/deps/haneul/linked_table.mjs.map +1 -1
- package/dist/contracts/haneulns_discounts/deps/haneulns/pricing_config.mjs +2 -8
- package/dist/contracts/haneulns_discounts/deps/haneulns/pricing_config.mjs.map +1 -1
- package/dist/contracts/haneulns_discounts/discounts.mjs +3 -4
- package/dist/contracts/haneulns_discounts/discounts.mjs.map +1 -1
- package/dist/contracts/haneulns_discounts/free_claims.mjs +4 -5
- package/dist/contracts/haneulns_discounts/free_claims.mjs.map +1 -1
- package/dist/contracts/haneulns_payments/deps/haneul/vec_map.mjs +1 -2
- package/dist/contracts/haneulns_payments/deps/haneul/vec_map.mjs.map +1 -1
- package/dist/contracts/haneulns_payments/deps/std/type_name.mjs +13 -10
- package/dist/contracts/haneulns_payments/deps/std/type_name.mjs.map +1 -1
- package/dist/contracts/haneulns_payments/payments.mjs +4 -3
- package/dist/contracts/haneulns_payments/payments.mjs.map +1 -1
- package/dist/contracts/pyth/data_source.mjs +2 -8
- package/dist/contracts/pyth/data_source.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +2 -8
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +2 -8
- package/dist/contracts/pyth/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs +2 -8
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/bytes32.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs +2 -8
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/consumed_vaas.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs +2 -8
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/external_address.mjs.map +1 -1
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs +2 -8
- package/dist/contracts/pyth/deps/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/set.mjs.map +1 -1
- package/dist/contracts/pyth/state.mjs +2 -8
- package/dist/contracts/pyth/state.mjs.map +1 -1
- package/dist/contracts/utils/index.mjs +97 -12
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/contracts/wormhole/bytes32.mjs +2 -8
- package/dist/contracts/wormhole/bytes32.mjs.map +1 -1
- package/dist/contracts/wormhole/consumed_vaas.mjs +2 -8
- package/dist/contracts/wormhole/consumed_vaas.mjs.map +1 -1
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +2 -8
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -1
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs +2 -8
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.mjs.map +1 -1
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs +2 -8
- package/dist/contracts/wormhole/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.mjs.map +1 -1
- package/dist/contracts/wormhole/external_address.mjs +2 -8
- package/dist/contracts/wormhole/external_address.mjs.map +1 -1
- package/dist/contracts/wormhole/fee_collector.mjs +2 -8
- package/dist/contracts/wormhole/fee_collector.mjs.map +1 -1
- package/dist/contracts/wormhole/set.mjs +2 -8
- package/dist/contracts/wormhole/set.mjs.map +1 -1
- package/dist/contracts/wormhole/state.mjs +2 -8
- package/dist/contracts/wormhole/state.mjs.map +1 -1
- package/dist/haneulns-client.d.mts +10 -10
- package/dist/haneulns-client.d.mts.map +1 -1
- package/dist/haneulns-client.mjs +9 -10
- package/dist/haneulns-client.mjs.map +1 -1
- package/dist/haneulns-transaction.d.mts +7 -8
- package/dist/haneulns-transaction.d.mts.map +1 -1
- package/dist/haneulns-transaction.mjs +4 -5
- package/dist/haneulns-transaction.mjs.map +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +1 -2
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -4
- package/dist/pyth/PriceServiceConnection.mjs +1 -2
- package/dist/pyth/PriceServiceConnection.mjs.map +1 -1
- package/dist/pyth/pyth-helpers.mjs +1 -1
- package/dist/pyth/pyth-helpers.mjs.map +1 -1
- package/dist/pyth/pyth.mjs +8 -6
- package/dist/pyth/pyth.mjs.map +1 -1
- package/dist/types.d.mts +3 -3
- package/dist/types.d.mts.map +1 -1
- package/package.json +11 -12
- package/src/constants.ts +19 -19
- package/src/contracts/haneulns/admin.ts +2 -2
- package/src/contracts/haneulns/auction.ts +2 -2
- package/src/contracts/haneulns/config.ts +18 -18
- package/src/contracts/haneulns/constants.ts +4 -4
- package/src/contracts/haneulns/controller.ts +95 -1
- package/src/contracts/haneulns/core_config.ts +19 -19
- package/src/contracts/haneulns/domain.ts +18 -20
- package/src/contracts/haneulns/haneulns.ts +7 -7
- package/src/contracts/haneulns/haneulns_registration.ts +11 -11
- package/src/contracts/haneulns/name_record.ts +24 -29
- package/src/contracts/haneulns/payment.ts +23 -23
- package/src/contracts/haneulns/pricing_config.ts +16 -16
- package/src/contracts/haneulns/registry.ts +61 -75
- package/src/contracts/haneulns/subdomain_registration.ts +2 -2
- package/src/contracts/haneulns_coupons/coupon_house.ts +19 -19
- package/src/contracts/haneulns_coupons/range.ts +7 -7
- package/src/contracts/haneulns_coupons/rules.ts +27 -27
- package/src/contracts/haneulns_discounts/discounts.ts +7 -7
- package/src/contracts/haneulns_discounts/free_claims.ts +7 -7
- package/src/contracts/haneulns_payments/payments.ts +13 -13
- package/src/contracts/utils/index.ts +185 -24
- package/src/haneulns-client.ts +14 -14
- package/src/haneulns-transaction.ts +5 -5
- package/src/index.ts +3 -3
- package/src/types.ts +2 -2
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
bcs,
|
|
3
|
-
BcsType,
|
|
4
|
-
TypeTag,
|
|
3
|
+
type BcsType,
|
|
4
|
+
type TypeTag,
|
|
5
5
|
TypeTagSerializer,
|
|
6
6
|
BcsStruct,
|
|
7
7
|
BcsEnum,
|
|
8
8
|
BcsTuple,
|
|
9
9
|
} from '@haneullabs/haneul/bcs';
|
|
10
|
-
import { normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
11
|
-
import { TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
|
|
12
|
-
import { ClientWithCoreApi, HaneulClientTypes } from '@haneullabs/haneul/client';
|
|
10
|
+
import { normalizeStructTag, normalizeHaneulAddress } from '@haneullabs/haneul/utils';
|
|
11
|
+
import { type TransactionArgument, isArgument } from '@haneullabs/haneul/transactions';
|
|
12
|
+
import { type ClientWithCoreApi, type HaneulClientTypes } from '@haneullabs/haneul/client';
|
|
13
13
|
|
|
14
14
|
const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress('0x1');
|
|
15
15
|
const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress('0x2');
|
|
16
16
|
|
|
17
17
|
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
Include
|
|
21
|
-
> extends HaneulClientTypes.GetObjectOptions<Include> {
|
|
22
|
-
client: ClientWithCoreApi;
|
|
23
|
-
}
|
|
19
|
+
export type GetOptions<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {}> =
|
|
20
|
+
HaneulClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };
|
|
24
21
|
|
|
25
|
-
export
|
|
26
|
-
Include
|
|
27
|
-
> extends HaneulClientTypes.GetObjectsOptions<Include> {
|
|
28
|
-
client: ClientWithCoreApi;
|
|
29
|
-
}
|
|
22
|
+
export type GetManyOptions<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content'> = {}> =
|
|
23
|
+
HaneulClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };
|
|
30
24
|
|
|
31
25
|
export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
|
|
32
26
|
const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
@@ -63,7 +57,8 @@ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null
|
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
if (structTag.module === 'option' && structTag.name === 'Option') {
|
|
66
|
-
const
|
|
60
|
+
const inner = structTag.typeParams[0];
|
|
61
|
+
const type = inner ? getPureBcsSchema(inner) : null;
|
|
67
62
|
return type ? bcs.option(type) : null;
|
|
68
63
|
}
|
|
69
64
|
}
|
|
@@ -95,7 +90,7 @@ export function normalizeMoveArguments(
|
|
|
95
90
|
const normalizedArgs: TransactionArgument[] = [];
|
|
96
91
|
|
|
97
92
|
let index = 0;
|
|
98
|
-
for (const
|
|
93
|
+
for (const argType of argTypes) {
|
|
99
94
|
if (argType === '0x2::clock::Clock') {
|
|
100
95
|
normalizedArgs.push((tx) => tx.object.clock());
|
|
101
96
|
continue;
|
|
@@ -143,28 +138,162 @@ export function normalizeMoveArguments(
|
|
|
143
138
|
continue;
|
|
144
139
|
}
|
|
145
140
|
|
|
146
|
-
const
|
|
147
|
-
const bcsType = type === null ? null : getPureBcsSchema(type);
|
|
141
|
+
const bcsType = argType === null ? null : getPureBcsSchema(argType);
|
|
148
142
|
|
|
149
143
|
if (bcsType) {
|
|
150
144
|
const bytes = bcsType.serialize(arg as never);
|
|
151
145
|
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
152
146
|
continue;
|
|
153
|
-
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (typeof arg === 'string') {
|
|
154
150
|
normalizedArgs.push((tx) => tx.object(arg));
|
|
155
151
|
continue;
|
|
156
152
|
}
|
|
157
153
|
|
|
158
|
-
throw new Error(`Invalid argument ${stringify(arg)} for type ${
|
|
154
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
|
|
159
155
|
}
|
|
160
156
|
|
|
161
157
|
return normalizedArgs;
|
|
162
158
|
}
|
|
163
159
|
|
|
160
|
+
/* -------------------------- Move type tags -------------------------- */
|
|
161
|
+
|
|
162
|
+
/** A type argument: a type tag string, or a BCS type whose name is a Move type. */
|
|
163
|
+
export type TypeArgument = string | BcsType<any>;
|
|
164
|
+
|
|
165
|
+
export interface TypeTagOptions {
|
|
166
|
+
package?: string;
|
|
167
|
+
typeArguments?: readonly TypeArgument[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* `typeArguments` is required when the type's name contains unfilled
|
|
172
|
+
* `phantom X` parameters (at any depth). Everything else — argument arity,
|
|
173
|
+
* position contents, and tag validity — is validated at runtime.
|
|
174
|
+
*/
|
|
175
|
+
type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`
|
|
176
|
+
? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]
|
|
177
|
+
: [options?: TypeTagOptions];
|
|
178
|
+
|
|
179
|
+
type ResolveTypeTagOptions<Name extends string> = {
|
|
180
|
+
client: ClientWithCoreApi;
|
|
181
|
+
} & (Name extends `${string}phantom ${string}`
|
|
182
|
+
? TypeTagOptions & { typeArguments: readonly TypeArgument[] }
|
|
183
|
+
: TypeTagOptions);
|
|
184
|
+
|
|
185
|
+
const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
|
|
186
|
+
|
|
187
|
+
function splitTopLevelTypeArgs(inner: string): string[] {
|
|
188
|
+
const parts: string[] = [];
|
|
189
|
+
let depth = 0;
|
|
190
|
+
let current = '';
|
|
191
|
+
for (const char of inner) {
|
|
192
|
+
if (char === ',' && depth === 0) {
|
|
193
|
+
parts.push(current.trim());
|
|
194
|
+
current = '';
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (char === '<') depth++;
|
|
198
|
+
if (char === '>') depth--;
|
|
199
|
+
current += char;
|
|
200
|
+
}
|
|
201
|
+
if (current) parts.push(current.trim());
|
|
202
|
+
return parts;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function buildTypeTag(name: string, options: TypeTagOptions | undefined): string {
|
|
206
|
+
const lt = name.indexOf('<');
|
|
207
|
+
const base = lt === -1 ? name : name.slice(0, lt);
|
|
208
|
+
|
|
209
|
+
if (base.split('::').length !== 3) {
|
|
210
|
+
throw new Error(`${name} is not a top-level Move type`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let result = name;
|
|
214
|
+
|
|
215
|
+
if (options?.typeArguments) {
|
|
216
|
+
const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
|
|
217
|
+
const supplied = options.typeArguments.map((arg) => {
|
|
218
|
+
if (typeof arg === 'string') {
|
|
219
|
+
return arg;
|
|
220
|
+
}
|
|
221
|
+
if (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {
|
|
222
|
+
return arg.name;
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`Invalid type argument ${stringify(arg)}`);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (supplied.length !== baked.length) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
result = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (HAS_PHANTOM_REGEX.test(result)) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
options?.typeArguments
|
|
239
|
+
? `A type argument contains an unfilled phantom parameter in ${result}`
|
|
240
|
+
: `Missing type arguments for ${result}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (options?.package) {
|
|
245
|
+
const [, ...rest] = result.split('::');
|
|
246
|
+
result = [options.package, ...rest].join('::');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// fully validate address-only tags (MVR names can't be parsed as type tags)
|
|
250
|
+
if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {
|
|
251
|
+
TypeTagSerializer.parseFromStr(result);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function resolveBuiltTypeTag(
|
|
258
|
+
name: string,
|
|
259
|
+
options: { client: ClientWithCoreApi } & TypeTagOptions,
|
|
260
|
+
): Promise<string> {
|
|
261
|
+
const { client, ...rest } = options;
|
|
262
|
+
const { type } = await client.core.mvr.resolveType({
|
|
263
|
+
type: buildTypeTag(name, rest),
|
|
264
|
+
});
|
|
265
|
+
return normalizeStructTag(type);
|
|
266
|
+
}
|
|
267
|
+
|
|
164
268
|
export class MoveStruct<
|
|
165
269
|
T extends Record<string, BcsType<any>>,
|
|
166
270
|
const Name extends string = string,
|
|
167
271
|
> extends BcsStruct<T, Name> {
|
|
272
|
+
/**
|
|
273
|
+
* Build the type tag for this struct.
|
|
274
|
+
*
|
|
275
|
+
* `typeArguments` is the full positional list, in Move declaration order, and
|
|
276
|
+
* is required when the struct has unfilled phantom parameters. The result may
|
|
277
|
+
* contain MVR names: those are valid in transaction `typeArguments`, but for
|
|
278
|
+
* queries or comparisons against on-chain data use `resolveTypeTag` instead.
|
|
279
|
+
*/
|
|
280
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
281
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Build the type tag for this struct, then resolve any MVR names through the
|
|
286
|
+
* client (using its configured overrides and the MVR API) and return the
|
|
287
|
+
* normalized, address-only form suitable for queries and comparisons against
|
|
288
|
+
* on-chain data.
|
|
289
|
+
*/
|
|
290
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
291
|
+
return resolveBuiltTypeTag(
|
|
292
|
+
this.name,
|
|
293
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
168
297
|
async get<Include extends Omit<HaneulClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
169
298
|
objectId,
|
|
170
299
|
...options
|
|
@@ -178,6 +307,10 @@ export class MoveStruct<
|
|
|
178
307
|
objectIds: [objectId],
|
|
179
308
|
});
|
|
180
309
|
|
|
310
|
+
if (!res) {
|
|
311
|
+
throw new Error(`No object found for id ${objectId}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
181
314
|
return res;
|
|
182
315
|
}
|
|
183
316
|
|
|
@@ -215,16 +348,44 @@ export class MoveStruct<
|
|
|
215
348
|
export class MoveEnum<
|
|
216
349
|
T extends Record<string, BcsType<any> | null>,
|
|
217
350
|
const Name extends string,
|
|
218
|
-
> extends BcsEnum<T, Name> {
|
|
351
|
+
> extends BcsEnum<T, Name> {
|
|
352
|
+
/** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */
|
|
353
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
354
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */
|
|
358
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
359
|
+
return resolveBuiltTypeTag(
|
|
360
|
+
this.name,
|
|
361
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
219
365
|
|
|
220
366
|
export class MoveTuple<
|
|
221
367
|
const T extends readonly BcsType<any>[],
|
|
222
368
|
const Name extends string,
|
|
223
|
-
> extends BcsTuple<T, Name> {
|
|
369
|
+
> extends BcsTuple<T, Name> {
|
|
370
|
+
/** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */
|
|
371
|
+
typeTag(...args: TypeTagParams<Name>): string {
|
|
372
|
+
return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */
|
|
376
|
+
async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
|
|
377
|
+
return resolveBuiltTypeTag(
|
|
378
|
+
this.name,
|
|
379
|
+
options as { client: ClientWithCoreApi } & TypeTagOptions,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
224
383
|
|
|
225
384
|
function stringify(val: unknown) {
|
|
226
385
|
if (typeof val === 'object') {
|
|
227
|
-
return JSON.stringify(val, (
|
|
386
|
+
return JSON.stringify(val, (_key, value) =>
|
|
387
|
+
typeof value === 'bigint' ? value.toString() : value,
|
|
388
|
+
);
|
|
228
389
|
}
|
|
229
390
|
if (typeof val === 'bigint') {
|
|
230
391
|
return val.toString();
|
package/src/haneulns-client.ts
CHANGED
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
CoinTypeDiscount,
|
|
12
12
|
NameRecord,
|
|
13
13
|
PackageInfo,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
HaneulnsClientConfig,
|
|
15
|
+
HaneulnsPriceList,
|
|
16
16
|
} from './types.js';
|
|
17
17
|
|
|
18
18
|
import { ConfigKey } from './contracts/haneulns/haneulns.js';
|
|
@@ -21,7 +21,7 @@ import { NameRecord as NameRecordBcs } from './contracts/haneulns/name_record.js
|
|
|
21
21
|
import { PricingConfig, RenewalConfig } from './contracts/haneulns/pricing_config.js';
|
|
22
22
|
import { PaymentsConfig } from './contracts/haneulns_payments/payments.js';
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type HaneulnsExtensionOptions<Name extends string = 'haneulns'> = {
|
|
25
25
|
name?: Name;
|
|
26
26
|
packageInfo?: PackageInfo;
|
|
27
27
|
};
|
|
@@ -45,11 +45,11 @@ export type SuinsExtensionOptions<Name extends string = 'haneulns'> = {
|
|
|
45
45
|
export function haneulns<const Name extends string = 'haneulns'>({
|
|
46
46
|
name = 'haneulns' as Name,
|
|
47
47
|
packageInfo,
|
|
48
|
-
}:
|
|
48
|
+
}: HaneulnsExtensionOptions<Name> = {}) {
|
|
49
49
|
return {
|
|
50
50
|
name,
|
|
51
51
|
register: (client: ClientWithCoreApi) => {
|
|
52
|
-
return new
|
|
52
|
+
return new HaneulnsClient({
|
|
53
53
|
client,
|
|
54
54
|
network: client.network,
|
|
55
55
|
packageInfo,
|
|
@@ -58,12 +58,12 @@ export function haneulns<const Name extends string = 'haneulns'>({
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export class
|
|
61
|
+
export class HaneulnsClient {
|
|
62
62
|
client: ClientWithCoreApi;
|
|
63
63
|
network: HaneulClientTypes.Network;
|
|
64
64
|
config: PackageInfo;
|
|
65
65
|
|
|
66
|
-
constructor(config:
|
|
66
|
+
constructor(config: HaneulnsClientConfig) {
|
|
67
67
|
this.client = config.client;
|
|
68
68
|
this.network = config.network || 'mainnet';
|
|
69
69
|
|
|
@@ -88,8 +88,8 @@ export class SuinsClient {
|
|
|
88
88
|
// [ 4, 4 ] => 100000000,
|
|
89
89
|
// [ 5, 63 ] => 20000000
|
|
90
90
|
// }
|
|
91
|
-
async getPriceList(): Promise<
|
|
92
|
-
if (!this.config.haneulns) throw new Error('
|
|
91
|
+
async getPriceList(): Promise<HaneulnsPriceList> {
|
|
92
|
+
if (!this.config.haneulns) throw new Error('Haneulns object ID is not set');
|
|
93
93
|
if (!this.config.packageId) throw new Error('Price list config not found');
|
|
94
94
|
|
|
95
95
|
const configType = `${this.config.packageIdV1}::haneulns::ConfigKey<${this.config.packageIdPricing}::pricing_config::PricingConfig>`;
|
|
@@ -126,8 +126,8 @@ export class SuinsClient {
|
|
|
126
126
|
// [ 4, 4 ] => 100000000,
|
|
127
127
|
// [ 5, 63 ] => 20000000
|
|
128
128
|
// }
|
|
129
|
-
async getRenewalPriceList(): Promise<
|
|
130
|
-
if (!this.config.haneulns) throw new Error('
|
|
129
|
+
async getRenewalPriceList(): Promise<HaneulnsPriceList> {
|
|
130
|
+
if (!this.config.haneulns) throw new Error('Haneulns object ID is not set');
|
|
131
131
|
if (!this.config.packageId) throw new Error('Price list config not found');
|
|
132
132
|
|
|
133
133
|
const configType = `${this.config.packageIdV1}::haneulns::ConfigKey<${this.config.packageIdPricing}::pricing_config::RenewalConfig>`;
|
|
@@ -165,7 +165,7 @@ export class SuinsClient {
|
|
|
165
165
|
// 'b48aac3f53bab328e1eb4c5b3c34f55e760f2fb3f2305ee1a474878d80f650f0::TESTNS::TESTNS' => 25
|
|
166
166
|
// }
|
|
167
167
|
async getCoinTypeDiscount(): Promise<CoinTypeDiscount> {
|
|
168
|
-
if (!this.config.haneulns) throw new Error('
|
|
168
|
+
if (!this.config.haneulns) throw new Error('Haneulns object ID is not set');
|
|
169
169
|
if (!this.config.packageId) throw new Error('Price list config not found');
|
|
170
170
|
|
|
171
171
|
const configType = `${this.config.packageIdV1}::haneulns::ConfigKey<${this.config.payments.packageId}::payments::PaymentsConfig>`;
|
|
@@ -193,7 +193,7 @@ export class SuinsClient {
|
|
|
193
193
|
|
|
194
194
|
async getNameRecord(name: string): Promise<NameRecord | null> {
|
|
195
195
|
if (!isValidHaneulNSName(name)) throw new Error('Invalid HaneulNS name');
|
|
196
|
-
if (!this.config.registryTableId) throw new Error('
|
|
196
|
+
if (!this.config.registryTableId) throw new Error('Haneulns package ID is not set');
|
|
197
197
|
|
|
198
198
|
const labels = normalizeHaneulNSName(name, 'dot').split('.').reverse();
|
|
199
199
|
|
|
@@ -232,7 +232,7 @@ export class SuinsClient {
|
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* Calculates the registration or renewal price for an SLD (Second Level Domain).
|
|
235
|
-
* It expects a domain name, the number of years and a `
|
|
235
|
+
* It expects a domain name, the number of years and a `HaneulnsPriceList` object,
|
|
236
236
|
* as returned from `haneulnsClient.getPriceList()` function, or `haneulns.getRenewalPriceList()` function.
|
|
237
237
|
*
|
|
238
238
|
* It throws an error:
|
|
@@ -11,7 +11,7 @@ import { isValidHaneulNSName, normalizeHaneulNSName, HANEUL_CLOCK_OBJECT_ID } fr
|
|
|
11
11
|
|
|
12
12
|
import { ALLOWED_METADATA, MAX_U64 } from './constants.js';
|
|
13
13
|
import { isNestedSubName, isSubName, zeroCoin } from './helpers.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type { HaneulnsClient } from './haneulns-client.js';
|
|
15
15
|
import type { DiscountInfo, ReceiptParams, RegistrationParams, RenewalParams } from './types.js';
|
|
16
16
|
|
|
17
17
|
import * as payment from './contracts/haneulns/payment.js';
|
|
@@ -21,11 +21,11 @@ import * as couponHouse from './contracts/haneulns_coupons/coupon_house.js';
|
|
|
21
21
|
import * as discounts from './contracts/haneulns_discounts/discounts.js';
|
|
22
22
|
import * as freeClaims from './contracts/haneulns_discounts/free_claims.js';
|
|
23
23
|
|
|
24
|
-
export class
|
|
25
|
-
haneulnsClient:
|
|
24
|
+
export class HaneulnsTransaction {
|
|
25
|
+
haneulnsClient: HaneulnsClient;
|
|
26
26
|
transaction: Transaction;
|
|
27
27
|
|
|
28
|
-
constructor(client:
|
|
28
|
+
constructor(client: HaneulnsClient, transaction: Transaction) {
|
|
29
29
|
this.haneulnsClient = client;
|
|
30
30
|
this.transaction = transaction;
|
|
31
31
|
}
|
|
@@ -349,7 +349,7 @@ export class SuinsTransaction {
|
|
|
349
349
|
|
|
350
350
|
/**
|
|
351
351
|
* Builds the PTB to create a leaf subdomain.
|
|
352
|
-
* Parent can be a `
|
|
352
|
+
* Parent can be a `HaneulnsRegistration` or a `SubDomainRegistration` object.
|
|
353
353
|
* Can be passed in as an ID or a TransactionArgument.
|
|
354
354
|
*/
|
|
355
355
|
createLeafSubName({
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { haneulns,
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
3
|
+
export { haneulns, HaneulnsClient, type HaneulnsExtensionOptions } from './haneulns-client.js';
|
|
4
|
+
export { HaneulnsTransaction } from './haneulns-transaction.js';
|
|
5
|
+
export type { HaneulnsClientConfig, PackageInfo } from './types.js';
|
|
6
6
|
export { ALLOWED_METADATA, mainPackage } from './constants.js';
|
|
7
7
|
export {
|
|
8
8
|
isSubName,
|
package/src/types.ts
CHANGED
|
@@ -98,12 +98,12 @@ export type ReceiptParams = {
|
|
|
98
98
|
priceInfoObjectId?: string | null;
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
export type
|
|
101
|
+
export type HaneulnsClientConfig = {
|
|
102
102
|
client: ClientWithCoreApi;
|
|
103
103
|
network?: HaneulClientTypes.Network;
|
|
104
104
|
packageInfo?: PackageInfo;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
export type
|
|
107
|
+
export type HaneulnsPriceList = Map<[number, number], number>;
|
|
108
108
|
|
|
109
109
|
export type CoinTypeDiscount = Map<string, number>;
|