@suilend/sdk 12.7.0 → 13.0.0-next.g122801a
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 +617 -83
- package/lib/initialize.js +151 -48
- 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/obligation.d.ts +3 -0
- package/utils/obligation.js +10 -0
- 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
|
@@ -1,80 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export type BalanceReified<T extends PhantomTypeArgument> = Reified<Balance<T>, BalanceFields<T>>;
|
|
10
|
-
export declare class Balance<T extends PhantomTypeArgument> implements StructClass {
|
|
11
|
-
__StructClass: true;
|
|
12
|
-
static readonly $typeName = "0x2::balance::Balance";
|
|
13
|
-
static readonly $numTypeParams = 1;
|
|
14
|
-
static readonly $isPhantom: readonly [true];
|
|
15
|
-
readonly $typeName = "0x2::balance::Balance";
|
|
16
|
-
readonly $fullTypeName: `${typeof PKG_V30}::balance::Balance<${PhantomToTypeStr<T>}>`;
|
|
17
|
-
readonly $typeArgs: [PhantomToTypeStr<T>];
|
|
18
|
-
readonly $isPhantom: readonly [true];
|
|
19
|
-
readonly value: ToField<"u64">;
|
|
20
|
-
private constructor();
|
|
21
|
-
static reified<T extends PhantomReified<PhantomTypeArgument>>(T: T): BalanceReified<ToPhantomTypeArgument<T>>;
|
|
22
|
-
static get r(): typeof Balance.reified;
|
|
23
|
-
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<Balance<ToPhantomTypeArgument<T>>>>;
|
|
24
|
-
static get p(): typeof Balance.phantom;
|
|
25
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
26
|
-
value: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
27
|
-
}, string>;
|
|
28
|
-
static fromFields<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, fields: Record<string, any>): Balance<ToPhantomTypeArgument<T>>;
|
|
29
|
-
static fromFieldsWithTypes<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, item: FieldsWithTypes): Balance<ToPhantomTypeArgument<T>>;
|
|
30
|
-
static fromBcs<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, data: Uint8Array): Balance<ToPhantomTypeArgument<T>>;
|
|
31
|
-
toJSONField(): {
|
|
32
|
-
value: string;
|
|
33
|
-
};
|
|
34
|
-
toJSON(): {
|
|
35
|
-
value: string;
|
|
36
|
-
$typeName: string;
|
|
37
|
-
$typeArgs: [PhantomToTypeStr<T>];
|
|
38
|
-
};
|
|
39
|
-
static fromJSONField<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, field: any): Balance<ToPhantomTypeArgument<T>>;
|
|
40
|
-
static fromJSON<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, json: Record<string, any>): Balance<ToPhantomTypeArgument<T>>;
|
|
41
|
-
static fetch<T extends PhantomReified<PhantomTypeArgument>>(client: SuiGrpcClient, typeArg: T, id: string): Promise<Balance<ToPhantomTypeArgument<T>>>;
|
|
42
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A storable handler for Balances in general. Is used in the `Coin`
|
|
3
|
+
* module to allow balance operations and can be used to implement
|
|
4
|
+
* custom coins with `Supply` and `Balance`s.
|
|
5
|
+
*/
|
|
6
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
7
|
+
import { PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr } from '../../../_framework/reified';
|
|
8
|
+
import { FieldsWithTypes } from '../../../_framework/util';
|
|
43
9
|
export declare function isSupply(type: string): boolean;
|
|
44
10
|
export interface SupplyFields<T extends PhantomTypeArgument> {
|
|
45
|
-
value: ToField<
|
|
11
|
+
value: ToField<'u64'>;
|
|
46
12
|
}
|
|
47
13
|
export type SupplyReified<T extends PhantomTypeArgument> = Reified<Supply<T>, SupplyFields<T>>;
|
|
14
|
+
export type SupplyJSONField<T extends PhantomTypeArgument> = {
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
export type SupplyJSON<T extends PhantomTypeArgument> = {
|
|
18
|
+
$typeName: typeof Supply.$typeName;
|
|
19
|
+
$typeArgs: [PhantomToTypeStr<T>];
|
|
20
|
+
} & SupplyJSONField<T>;
|
|
21
|
+
/**
|
|
22
|
+
* A Supply of T. Used for minting and burning.
|
|
23
|
+
* Wrapped into a `TreasuryCap` in the `Coin` module.
|
|
24
|
+
*/
|
|
48
25
|
export declare class Supply<T extends PhantomTypeArgument> implements StructClass {
|
|
49
26
|
__StructClass: true;
|
|
50
|
-
static readonly $typeName
|
|
27
|
+
static readonly $typeName: `0x2::balance::Supply`;
|
|
51
28
|
static readonly $numTypeParams = 1;
|
|
52
29
|
static readonly $isPhantom: readonly [true];
|
|
53
|
-
readonly $typeName
|
|
54
|
-
readonly $fullTypeName:
|
|
30
|
+
readonly $typeName: typeof Supply.$typeName;
|
|
31
|
+
readonly $fullTypeName: `0x2::balance::Supply<${PhantomToTypeStr<T>}>`;
|
|
55
32
|
readonly $typeArgs: [PhantomToTypeStr<T>];
|
|
56
|
-
readonly $isPhantom:
|
|
57
|
-
readonly value: ToField<
|
|
33
|
+
readonly $isPhantom: typeof Supply.$isPhantom;
|
|
34
|
+
readonly value: ToField<'u64'>;
|
|
58
35
|
private constructor();
|
|
59
36
|
static reified<T extends PhantomReified<PhantomTypeArgument>>(T: T): SupplyReified<ToPhantomTypeArgument<T>>;
|
|
60
37
|
static get r(): typeof Supply.reified;
|
|
61
38
|
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<Supply<ToPhantomTypeArgument<T>>>>;
|
|
62
39
|
static get p(): typeof Supply.phantom;
|
|
63
|
-
static
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
private static instantiateBcs;
|
|
41
|
+
private static cachedBcs;
|
|
42
|
+
static get bcs(): ReturnType<typeof Supply.instantiateBcs>;
|
|
66
43
|
static fromFields<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, fields: Record<string, any>): Supply<ToPhantomTypeArgument<T>>;
|
|
67
44
|
static fromFieldsWithTypes<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, item: FieldsWithTypes): Supply<ToPhantomTypeArgument<T>>;
|
|
68
45
|
static fromBcs<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, data: Uint8Array): Supply<ToPhantomTypeArgument<T>>;
|
|
69
|
-
toJSONField():
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
toJSON(): {
|
|
73
|
-
value: string;
|
|
74
|
-
$typeName: string;
|
|
75
|
-
$typeArgs: [PhantomToTypeStr<T>];
|
|
76
|
-
};
|
|
46
|
+
toJSONField(): SupplyJSONField<T>;
|
|
47
|
+
toJSON(): SupplyJSON<T>;
|
|
77
48
|
static fromJSONField<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, field: any): Supply<ToPhantomTypeArgument<T>>;
|
|
78
49
|
static fromJSON<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, json: Record<string, any>): Supply<ToPhantomTypeArgument<T>>;
|
|
79
|
-
static
|
|
50
|
+
static fromCoreObject<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, obj: SuiClientTypes.Object<{
|
|
51
|
+
content: true;
|
|
52
|
+
}>): Supply<ToPhantomTypeArgument<T>>;
|
|
53
|
+
static fetch<T extends PhantomReified<PhantomTypeArgument>>(client: ClientWithCoreApi, typeArg: T, id: string): Promise<Supply<ToPhantomTypeArgument<T>>>;
|
|
54
|
+
}
|
|
55
|
+
export declare function isBalance(type: string): boolean;
|
|
56
|
+
export interface BalanceFields<T extends PhantomTypeArgument> {
|
|
57
|
+
value: ToField<'u64'>;
|
|
58
|
+
}
|
|
59
|
+
export type BalanceReified<T extends PhantomTypeArgument> = Reified<Balance<T>, BalanceFields<T>>;
|
|
60
|
+
export type BalanceJSONField<T extends PhantomTypeArgument> = {
|
|
61
|
+
value: string;
|
|
62
|
+
};
|
|
63
|
+
export type BalanceJSON<T extends PhantomTypeArgument> = {
|
|
64
|
+
$typeName: typeof Balance.$typeName;
|
|
65
|
+
$typeArgs: [PhantomToTypeStr<T>];
|
|
66
|
+
} & BalanceJSONField<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Storable balance - an inner struct of a Coin type.
|
|
69
|
+
* Can be used to store coins which don't need the key ability.
|
|
70
|
+
*/
|
|
71
|
+
export declare class Balance<T extends PhantomTypeArgument> implements StructClass {
|
|
72
|
+
__StructClass: true;
|
|
73
|
+
static readonly $typeName: `0x2::balance::Balance`;
|
|
74
|
+
static readonly $numTypeParams = 1;
|
|
75
|
+
static readonly $isPhantom: readonly [true];
|
|
76
|
+
readonly $typeName: typeof Balance.$typeName;
|
|
77
|
+
readonly $fullTypeName: `0x2::balance::Balance<${PhantomToTypeStr<T>}>`;
|
|
78
|
+
readonly $typeArgs: [PhantomToTypeStr<T>];
|
|
79
|
+
readonly $isPhantom: typeof Balance.$isPhantom;
|
|
80
|
+
readonly value: ToField<'u64'>;
|
|
81
|
+
private constructor();
|
|
82
|
+
static reified<T extends PhantomReified<PhantomTypeArgument>>(T: T): BalanceReified<ToPhantomTypeArgument<T>>;
|
|
83
|
+
static get r(): typeof Balance.reified;
|
|
84
|
+
static phantom<T extends PhantomReified<PhantomTypeArgument>>(T: T): PhantomReified<ToTypeStr<Balance<ToPhantomTypeArgument<T>>>>;
|
|
85
|
+
static get p(): typeof Balance.phantom;
|
|
86
|
+
private static instantiateBcs;
|
|
87
|
+
private static cachedBcs;
|
|
88
|
+
static get bcs(): ReturnType<typeof Balance.instantiateBcs>;
|
|
89
|
+
static fromFields<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, fields: Record<string, any>): Balance<ToPhantomTypeArgument<T>>;
|
|
90
|
+
static fromFieldsWithTypes<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, item: FieldsWithTypes): Balance<ToPhantomTypeArgument<T>>;
|
|
91
|
+
static fromBcs<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, data: Uint8Array): Balance<ToPhantomTypeArgument<T>>;
|
|
92
|
+
toJSONField(): BalanceJSONField<T>;
|
|
93
|
+
toJSON(): BalanceJSON<T>;
|
|
94
|
+
static fromJSONField<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, field: any): Balance<ToPhantomTypeArgument<T>>;
|
|
95
|
+
static fromJSON<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, json: Record<string, any>): Balance<ToPhantomTypeArgument<T>>;
|
|
96
|
+
static fromCoreObject<T extends PhantomReified<PhantomTypeArgument>>(typeArg: T, obj: SuiClientTypes.Object<{
|
|
97
|
+
content: true;
|
|
98
|
+
}>): Balance<ToPhantomTypeArgument<T>>;
|
|
99
|
+
static fetch<T extends PhantomReified<PhantomTypeArgument>>(client: ClientWithCoreApi, typeArg: T, id: string): Promise<Balance<ToPhantomTypeArgument<T>>>;
|
|
80
100
|
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A storable handler for Balances in general. Is used in the `Coin`
|
|
3
|
+
* module to allow balance operations and can be used to implement
|
|
4
|
+
* custom coins with `Supply` and `Balance`s.
|
|
5
|
+
*/
|
|
6
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
7
|
+
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from '../../../_framework/reified.js';
|
|
8
|
+
import { composeSuiType, compressSuiType, parseTypeName, } from '../../../_framework/util.js';
|
|
9
|
+
/* ============================== Supply =============================== */
|
|
10
|
+
export function isSupply(type) {
|
|
11
|
+
type = compressSuiType(type);
|
|
12
|
+
return type.startsWith(`0x2::balance::Supply` + '<');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Supply of T. Used for minting and burning.
|
|
16
|
+
* Wrapped into a `TreasuryCap` in the `Coin` module.
|
|
17
|
+
*/
|
|
18
|
+
export class Supply {
|
|
19
|
+
__StructClass = true;
|
|
20
|
+
static $typeName = `0x2::balance::Supply`;
|
|
21
|
+
static $numTypeParams = 1;
|
|
22
|
+
static $isPhantom = [true];
|
|
23
|
+
$typeName = Supply.$typeName;
|
|
24
|
+
$fullTypeName;
|
|
25
|
+
$typeArgs;
|
|
26
|
+
$isPhantom = Supply.$isPhantom;
|
|
27
|
+
value;
|
|
28
|
+
constructor(typeArgs, fields) {
|
|
29
|
+
this.$fullTypeName = composeSuiType(Supply.$typeName, ...typeArgs);
|
|
30
|
+
this.$typeArgs = typeArgs;
|
|
31
|
+
this.value = fields.value;
|
|
32
|
+
}
|
|
33
|
+
static reified(T) {
|
|
34
|
+
const reifiedBcs = Supply.bcs;
|
|
35
|
+
return {
|
|
36
|
+
get typeName() {
|
|
37
|
+
return Supply.$typeName;
|
|
38
|
+
},
|
|
39
|
+
get fullTypeName() {
|
|
40
|
+
return composeSuiType(Supply.$typeName, ...[extractType(T)]);
|
|
41
|
+
},
|
|
42
|
+
get typeArgs() {
|
|
43
|
+
return [extractType(T)];
|
|
44
|
+
},
|
|
45
|
+
isPhantom: Supply.$isPhantom,
|
|
46
|
+
reifiedTypeArgs: [T],
|
|
47
|
+
fromFields: (fields) => Supply.fromFields(T, fields),
|
|
48
|
+
fromFieldsWithTypes: (item) => Supply.fromFieldsWithTypes(T, item),
|
|
49
|
+
fromBcs: (data) => Supply.fromFields(T, reifiedBcs.parse(data)),
|
|
50
|
+
bcs: reifiedBcs,
|
|
51
|
+
fromJSONField: (field) => Supply.fromJSONField(T, field),
|
|
52
|
+
fromJSON: (json) => Supply.fromJSON(T, json),
|
|
53
|
+
fromCoreObject: (obj) => Supply.fromCoreObject(T, obj),
|
|
54
|
+
fetch: async (client, id) => Supply.fetch(client, T, id),
|
|
55
|
+
new: (fields) => {
|
|
56
|
+
return new Supply([extractType(T)], fields);
|
|
57
|
+
},
|
|
58
|
+
kind: 'StructClassReified',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
static get r() {
|
|
62
|
+
return Supply.reified;
|
|
63
|
+
}
|
|
64
|
+
static phantom(T) {
|
|
65
|
+
return phantom(Supply.reified(T));
|
|
66
|
+
}
|
|
67
|
+
static get p() {
|
|
68
|
+
return Supply.phantom;
|
|
69
|
+
}
|
|
70
|
+
static instantiateBcs() {
|
|
71
|
+
return bcs.struct('Supply', {
|
|
72
|
+
value: bcs.u64(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
static cachedBcs = null;
|
|
76
|
+
static get bcs() {
|
|
77
|
+
if (!Supply.cachedBcs) {
|
|
78
|
+
Supply.cachedBcs = Supply.instantiateBcs();
|
|
79
|
+
}
|
|
80
|
+
return Supply.cachedBcs;
|
|
81
|
+
}
|
|
82
|
+
static fromFields(typeArg, fields) {
|
|
83
|
+
return Supply.reified(typeArg).new({
|
|
84
|
+
value: decodeFromFields('u64', fields.value),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static fromFieldsWithTypes(typeArg, item) {
|
|
88
|
+
if (!isSupply(item.type)) {
|
|
89
|
+
throw new Error('not a Supply type');
|
|
90
|
+
}
|
|
91
|
+
assertFieldsWithTypesArgsMatch(item, [typeArg]);
|
|
92
|
+
return Supply.reified(typeArg).new({
|
|
93
|
+
value: decodeFromFieldsWithTypes('u64', item.fields.value),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static fromBcs(typeArg, data) {
|
|
97
|
+
return Supply.fromFields(typeArg, Supply.bcs.parse(data));
|
|
98
|
+
}
|
|
99
|
+
toJSONField() {
|
|
100
|
+
return {
|
|
101
|
+
value: this.value.toString(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
106
|
+
}
|
|
107
|
+
static fromJSONField(typeArg, field) {
|
|
108
|
+
return Supply.reified(typeArg).new({
|
|
109
|
+
value: decodeFromJSONField('u64', field.value),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
static fromJSON(typeArg, json) {
|
|
113
|
+
if (json.$typeName !== Supply.$typeName) {
|
|
114
|
+
throw new Error(`not a Supply json object: expected '${Supply.$typeName}' but got '${json.$typeName}'`);
|
|
115
|
+
}
|
|
116
|
+
assertReifiedTypeArgsMatch(composeSuiType(Supply.$typeName, ...[extractType(typeArg)]), json.$typeArgs, [typeArg]);
|
|
117
|
+
return Supply.fromJSONField(typeArg, json);
|
|
118
|
+
}
|
|
119
|
+
static fromCoreObject(typeArg, obj) {
|
|
120
|
+
if (!isSupply(obj.type)) {
|
|
121
|
+
throw new Error(`object at ${obj.objectId} is not a Supply object`);
|
|
122
|
+
}
|
|
123
|
+
const gotTypeArgs = parseTypeName(obj.type).typeArgs;
|
|
124
|
+
if (gotTypeArgs.length !== 1) {
|
|
125
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
126
|
+
}
|
|
127
|
+
for (let i = 0; i < 1; i++) {
|
|
128
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
129
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
130
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
131
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return Supply.fromBcs(typeArg, obj.content);
|
|
135
|
+
}
|
|
136
|
+
static async fetch(client, typeArg, id) {
|
|
137
|
+
const { object } = await client.core.getObject({
|
|
138
|
+
objectId: id,
|
|
139
|
+
include: { content: true },
|
|
140
|
+
});
|
|
141
|
+
if (!isSupply(object.type)) {
|
|
142
|
+
throw new Error(`object at id ${id} is not a Supply object`);
|
|
143
|
+
}
|
|
144
|
+
const gotTypeArgs = parseTypeName(object.type).typeArgs;
|
|
145
|
+
if (gotTypeArgs.length !== 1) {
|
|
146
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
147
|
+
}
|
|
148
|
+
for (let i = 0; i < 1; i++) {
|
|
149
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
150
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
151
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
152
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return Supply.fromBcs(typeArg, object.content);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/* ============================== Balance =============================== */
|
|
159
|
+
export function isBalance(type) {
|
|
160
|
+
type = compressSuiType(type);
|
|
161
|
+
return type.startsWith(`0x2::balance::Balance` + '<');
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Storable balance - an inner struct of a Coin type.
|
|
165
|
+
* Can be used to store coins which don't need the key ability.
|
|
166
|
+
*/
|
|
167
|
+
export class Balance {
|
|
168
|
+
__StructClass = true;
|
|
169
|
+
static $typeName = `0x2::balance::Balance`;
|
|
170
|
+
static $numTypeParams = 1;
|
|
171
|
+
static $isPhantom = [true];
|
|
172
|
+
$typeName = Balance.$typeName;
|
|
173
|
+
$fullTypeName;
|
|
174
|
+
$typeArgs;
|
|
175
|
+
$isPhantom = Balance.$isPhantom;
|
|
176
|
+
value;
|
|
177
|
+
constructor(typeArgs, fields) {
|
|
178
|
+
this.$fullTypeName = composeSuiType(Balance.$typeName, ...typeArgs);
|
|
179
|
+
this.$typeArgs = typeArgs;
|
|
180
|
+
this.value = fields.value;
|
|
181
|
+
}
|
|
182
|
+
static reified(T) {
|
|
183
|
+
const reifiedBcs = Balance.bcs;
|
|
184
|
+
return {
|
|
185
|
+
get typeName() {
|
|
186
|
+
return Balance.$typeName;
|
|
187
|
+
},
|
|
188
|
+
get fullTypeName() {
|
|
189
|
+
return composeSuiType(Balance.$typeName, ...[extractType(T)]);
|
|
190
|
+
},
|
|
191
|
+
get typeArgs() {
|
|
192
|
+
return [extractType(T)];
|
|
193
|
+
},
|
|
194
|
+
isPhantom: Balance.$isPhantom,
|
|
195
|
+
reifiedTypeArgs: [T],
|
|
196
|
+
fromFields: (fields) => Balance.fromFields(T, fields),
|
|
197
|
+
fromFieldsWithTypes: (item) => Balance.fromFieldsWithTypes(T, item),
|
|
198
|
+
fromBcs: (data) => Balance.fromFields(T, reifiedBcs.parse(data)),
|
|
199
|
+
bcs: reifiedBcs,
|
|
200
|
+
fromJSONField: (field) => Balance.fromJSONField(T, field),
|
|
201
|
+
fromJSON: (json) => Balance.fromJSON(T, json),
|
|
202
|
+
fromCoreObject: (obj) => Balance.fromCoreObject(T, obj),
|
|
203
|
+
fetch: async (client, id) => Balance.fetch(client, T, id),
|
|
204
|
+
new: (fields) => {
|
|
205
|
+
return new Balance([extractType(T)], fields);
|
|
206
|
+
},
|
|
207
|
+
kind: 'StructClassReified',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
static get r() {
|
|
211
|
+
return Balance.reified;
|
|
212
|
+
}
|
|
213
|
+
static phantom(T) {
|
|
214
|
+
return phantom(Balance.reified(T));
|
|
215
|
+
}
|
|
216
|
+
static get p() {
|
|
217
|
+
return Balance.phantom;
|
|
218
|
+
}
|
|
219
|
+
static instantiateBcs() {
|
|
220
|
+
return bcs.struct('Balance', {
|
|
221
|
+
value: bcs.u64(),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
static cachedBcs = null;
|
|
225
|
+
static get bcs() {
|
|
226
|
+
if (!Balance.cachedBcs) {
|
|
227
|
+
Balance.cachedBcs = Balance.instantiateBcs();
|
|
228
|
+
}
|
|
229
|
+
return Balance.cachedBcs;
|
|
230
|
+
}
|
|
231
|
+
static fromFields(typeArg, fields) {
|
|
232
|
+
return Balance.reified(typeArg).new({
|
|
233
|
+
value: decodeFromFields('u64', fields.value),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
static fromFieldsWithTypes(typeArg, item) {
|
|
237
|
+
if (!isBalance(item.type)) {
|
|
238
|
+
throw new Error('not a Balance type');
|
|
239
|
+
}
|
|
240
|
+
assertFieldsWithTypesArgsMatch(item, [typeArg]);
|
|
241
|
+
return Balance.reified(typeArg).new({
|
|
242
|
+
value: decodeFromFieldsWithTypes('u64', item.fields.value),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
static fromBcs(typeArg, data) {
|
|
246
|
+
return Balance.fromFields(typeArg, Balance.bcs.parse(data));
|
|
247
|
+
}
|
|
248
|
+
toJSONField() {
|
|
249
|
+
return {
|
|
250
|
+
value: this.value.toString(),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
toJSON() {
|
|
254
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
255
|
+
}
|
|
256
|
+
static fromJSONField(typeArg, field) {
|
|
257
|
+
return Balance.reified(typeArg).new({
|
|
258
|
+
value: decodeFromJSONField('u64', field.value),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
static fromJSON(typeArg, json) {
|
|
262
|
+
if (json.$typeName !== Balance.$typeName) {
|
|
263
|
+
throw new Error(`not a Balance json object: expected '${Balance.$typeName}' but got '${json.$typeName}'`);
|
|
264
|
+
}
|
|
265
|
+
assertReifiedTypeArgsMatch(composeSuiType(Balance.$typeName, ...[extractType(typeArg)]), json.$typeArgs, [typeArg]);
|
|
266
|
+
return Balance.fromJSONField(typeArg, json);
|
|
267
|
+
}
|
|
268
|
+
static fromCoreObject(typeArg, obj) {
|
|
269
|
+
if (!isBalance(obj.type)) {
|
|
270
|
+
throw new Error(`object at ${obj.objectId} is not a Balance object`);
|
|
271
|
+
}
|
|
272
|
+
const gotTypeArgs = parseTypeName(obj.type).typeArgs;
|
|
273
|
+
if (gotTypeArgs.length !== 1) {
|
|
274
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
275
|
+
}
|
|
276
|
+
for (let i = 0; i < 1; i++) {
|
|
277
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
278
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
279
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
280
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return Balance.fromBcs(typeArg, obj.content);
|
|
284
|
+
}
|
|
285
|
+
static async fetch(client, typeArg, id) {
|
|
286
|
+
const { object } = await client.core.getObject({
|
|
287
|
+
objectId: id,
|
|
288
|
+
include: { content: true },
|
|
289
|
+
});
|
|
290
|
+
if (!isBalance(object.type)) {
|
|
291
|
+
throw new Error(`object at id ${id} is not a Balance object`);
|
|
292
|
+
}
|
|
293
|
+
const gotTypeArgs = parseTypeName(object.type).typeArgs;
|
|
294
|
+
if (gotTypeArgs.length !== 1) {
|
|
295
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
296
|
+
}
|
|
297
|
+
for (let i = 0; i < 1; i++) {
|
|
298
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
299
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
300
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
301
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return Balance.fromBcs(typeArg, object.content);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** Sui object identifiers */
|
|
2
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
3
|
+
import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from '../../../_framework/reified';
|
|
4
|
+
import { FieldsWithTypes } from '../../../_framework/util';
|
|
5
|
+
export declare function isID(type: string): boolean;
|
|
6
|
+
export interface IDFields {
|
|
7
|
+
bytes: ToField<'address'>;
|
|
8
|
+
}
|
|
9
|
+
export type IDReified = Reified<ID, IDFields>;
|
|
10
|
+
export type IDJSONField = {
|
|
11
|
+
bytes: string;
|
|
12
|
+
};
|
|
13
|
+
export type IDJSON = {
|
|
14
|
+
$typeName: typeof ID.$typeName;
|
|
15
|
+
$typeArgs: [];
|
|
16
|
+
} & IDJSONField;
|
|
17
|
+
/**
|
|
18
|
+
* An object ID. This is used to reference Sui Objects.
|
|
19
|
+
* This is *not* guaranteed to be globally unique--anyone can create an `ID` from a `UID` or
|
|
20
|
+
* from an object, and ID's can be freely copied and dropped.
|
|
21
|
+
* Here, the values are not globally unique because there can be multiple values of type `ID`
|
|
22
|
+
* with the same underlying bytes. For example, `object::id(&obj)` can be called as many times
|
|
23
|
+
* as you want for a given `obj`, and each `ID` value will be identical.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ID implements StructClass {
|
|
26
|
+
__StructClass: true;
|
|
27
|
+
static readonly $typeName: `0x2::object::ID`;
|
|
28
|
+
static readonly $numTypeParams = 0;
|
|
29
|
+
static readonly $isPhantom: readonly [];
|
|
30
|
+
readonly $typeName: typeof ID.$typeName;
|
|
31
|
+
readonly $fullTypeName: `0x2::object::ID`;
|
|
32
|
+
readonly $typeArgs: [];
|
|
33
|
+
readonly $isPhantom: typeof ID.$isPhantom;
|
|
34
|
+
readonly bytes: ToField<'address'>;
|
|
35
|
+
private constructor();
|
|
36
|
+
static reified(): IDReified;
|
|
37
|
+
static get r(): IDReified;
|
|
38
|
+
static phantom(): PhantomReified<ToTypeStr<ID>>;
|
|
39
|
+
static get p(): PhantomReified<ToTypeStr<ID>>;
|
|
40
|
+
private static instantiateBcs;
|
|
41
|
+
private static cachedBcs;
|
|
42
|
+
static get bcs(): ReturnType<typeof ID.instantiateBcs>;
|
|
43
|
+
static fromFields(fields: Record<string, any>): ID;
|
|
44
|
+
static fromFieldsWithTypes(item: FieldsWithTypes): ID;
|
|
45
|
+
static fromBcs(data: Uint8Array): ID;
|
|
46
|
+
toJSONField(): IDJSONField;
|
|
47
|
+
toJSON(): IDJSON;
|
|
48
|
+
static fromJSONField(field: any): ID;
|
|
49
|
+
static fromJSON(json: Record<string, any>): ID;
|
|
50
|
+
static fromCoreObject(obj: SuiClientTypes.Object<{
|
|
51
|
+
content: true;
|
|
52
|
+
}>): ID;
|
|
53
|
+
static fetch(client: ClientWithCoreApi, id: string): Promise<ID>;
|
|
54
|
+
}
|
|
55
|
+
export declare function isUID(type: string): boolean;
|
|
56
|
+
export interface UIDFields {
|
|
57
|
+
id: ToField<ID>;
|
|
58
|
+
}
|
|
59
|
+
export type UIDReified = Reified<UID, UIDFields>;
|
|
60
|
+
export type UIDJSONField = {
|
|
61
|
+
id: string;
|
|
62
|
+
};
|
|
63
|
+
export type UIDJSON = {
|
|
64
|
+
$typeName: typeof UID.$typeName;
|
|
65
|
+
$typeArgs: [];
|
|
66
|
+
} & UIDJSONField;
|
|
67
|
+
/**
|
|
68
|
+
* Globally unique IDs that define an object's ID in storage. Any Sui Object, that is a struct
|
|
69
|
+
* with the `key` ability, must have `id: UID` as its first field.
|
|
70
|
+
* These are globally unique in the sense that no two values of type `UID` are ever equal, in
|
|
71
|
+
* other words for any two values `id1: UID` and `id2: UID`, `id1` != `id2`.
|
|
72
|
+
* This is a privileged type that can only be derived from a `TxContext`.
|
|
73
|
+
* `UID` doesn't have the `drop` ability, so deleting a `UID` requires a call to `delete`.
|
|
74
|
+
*/
|
|
75
|
+
export declare class UID implements StructClass {
|
|
76
|
+
__StructClass: true;
|
|
77
|
+
static readonly $typeName: `0x2::object::UID`;
|
|
78
|
+
static readonly $numTypeParams = 0;
|
|
79
|
+
static readonly $isPhantom: readonly [];
|
|
80
|
+
readonly $typeName: typeof UID.$typeName;
|
|
81
|
+
readonly $fullTypeName: `0x2::object::UID`;
|
|
82
|
+
readonly $typeArgs: [];
|
|
83
|
+
readonly $isPhantom: typeof UID.$isPhantom;
|
|
84
|
+
readonly id: ToField<ID>;
|
|
85
|
+
private constructor();
|
|
86
|
+
static reified(): UIDReified;
|
|
87
|
+
static get r(): UIDReified;
|
|
88
|
+
static phantom(): PhantomReified<ToTypeStr<UID>>;
|
|
89
|
+
static get p(): PhantomReified<ToTypeStr<UID>>;
|
|
90
|
+
private static instantiateBcs;
|
|
91
|
+
private static cachedBcs;
|
|
92
|
+
static get bcs(): ReturnType<typeof UID.instantiateBcs>;
|
|
93
|
+
static fromFields(fields: Record<string, any>): UID;
|
|
94
|
+
static fromFieldsWithTypes(item: FieldsWithTypes): UID;
|
|
95
|
+
static fromBcs(data: Uint8Array): UID;
|
|
96
|
+
toJSONField(): UIDJSONField;
|
|
97
|
+
toJSON(): UIDJSON;
|
|
98
|
+
static fromJSONField(field: any): UID;
|
|
99
|
+
static fromJSON(json: Record<string, any>): UID;
|
|
100
|
+
static fromCoreObject(obj: SuiClientTypes.Object<{
|
|
101
|
+
content: true;
|
|
102
|
+
}>): UID;
|
|
103
|
+
static fetch(client: ClientWithCoreApi, id: string): Promise<UID>;
|
|
104
|
+
}
|