@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.
Files changed (84) hide show
  1. package/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
  2. package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
  3. package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
  4. package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
  5. package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
  6. package/_generated/_dependencies/std/option/structs.js +155 -0
  7. package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
  8. package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
  9. package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
  10. package/_generated/_dependencies/sui/bag/structs.js +154 -0
  11. package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
  12. package/_generated/_dependencies/sui/balance/structs.js +306 -0
  13. package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
  14. package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
  15. package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
  16. package/_generated/_dependencies/sui/object-table/structs.js +164 -0
  17. package/_generated/_envs/index.d.ts +3 -0
  18. package/_generated/_envs/index.js +18 -0
  19. package/_generated/_envs/mainnet.d.ts +2 -0
  20. package/_generated/_envs/mainnet.js +490 -0
  21. package/_generated/_framework/env.d.ts +137 -0
  22. package/_generated/_framework/env.js +261 -0
  23. package/_generated/_framework/reified.d.ts +68 -36
  24. package/_generated/_framework/reified.js +110 -98
  25. package/_generated/_framework/util.d.ts +4 -4
  26. package/_generated/_framework/util.js +82 -79
  27. package/_generated/_framework/vector.d.ts +11 -9
  28. package/_generated/_framework/vector.js +10 -10
  29. package/_generated/suilend/cell/structs.d.ts +24 -22
  30. package/_generated/suilend/cell/structs.js +68 -24
  31. package/_generated/suilend/decimal/structs.d.ts +28 -24
  32. package/_generated/suilend/decimal/structs.js +45 -24
  33. package/_generated/suilend/index.d.ts +5 -6
  34. package/_generated/suilend/index.js +10 -19
  35. package/_generated/suilend/lending-market/functions.d.ts +1123 -149
  36. package/_generated/suilend/lending-market/functions.js +1121 -207
  37. package/_generated/suilend/lending-market/structs.d.ts +985 -1290
  38. package/_generated/suilend/lending-market/structs.js +2482 -1282
  39. package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
  40. package/_generated/suilend/lending-market-registry/functions.js +30 -6
  41. package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
  42. package/_generated/suilend/liquidity-mining/structs.js +449 -319
  43. package/_generated/suilend/obligation/structs.d.ts +406 -918
  44. package/_generated/suilend/obligation/structs.js +786 -596
  45. package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
  46. package/_generated/suilend/rate-limiter/functions.js +139 -21
  47. package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
  48. package/_generated/suilend/rate-limiter/structs.js +98 -48
  49. package/_generated/suilend/reserve/structs.d.ts +611 -904
  50. package/_generated/suilend/reserve/structs.js +1528 -736
  51. package/_generated/suilend/reserve-config/functions.d.ts +718 -96
  52. package/_generated/suilend/reserve-config/functions.js +751 -157
  53. package/_generated/suilend/reserve-config/structs.d.ts +148 -163
  54. package/_generated/suilend/reserve-config/structs.js +260 -94
  55. package/client.d.ts +2 -2
  56. package/client.js +22 -39
  57. package/lib/initialize.d.ts +76 -76
  58. package/lib/initialize.js +10 -10
  59. package/lib/proCompatible.js +5 -5
  60. package/package.json +1 -1
  61. package/parsers/lendingMarket.d.ts +9 -9
  62. package/parsers/obligation.d.ts +14 -14
  63. package/parsers/obligation.js +4 -4
  64. package/parsers/rateLimiter.d.ts +1 -1
  65. package/parsers/reserve.d.ts +12 -12
  66. package/parsers/reserve.js +2 -2
  67. package/strategies.d.ts +14 -14
  68. package/utils/simulate.d.ts +1 -1
  69. package/utils/simulate.js +5 -5
  70. package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
  71. package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
  72. package/_generated/_dependencies/source/0x1/index.js +0 -3
  73. package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
  74. package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
  75. package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
  76. package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
  77. package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
  78. package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
  79. package/_generated/_dependencies/source/0x2/index.js +0 -3
  80. package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
  81. package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
  82. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
  83. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
  84. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
@@ -1,84 +0,0 @@
1
- import * as reified from "../../../../_framework/reified";
2
- import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
3
- import { FieldsWithTypes } from "../../../../_framework/util";
4
- import { Vector } from "../../../../_framework/vector";
5
- import { PKG_V13 } from "../index";
6
- import { SuiGrpcClient } from "@mysten/sui/grpc";
7
- export declare function isChar(type: string): boolean;
8
- export interface CharFields {
9
- byte: ToField<"u8">;
10
- }
11
- export type CharReified = Reified<Char, CharFields>;
12
- export declare class Char implements StructClass {
13
- __StructClass: true;
14
- static readonly $typeName = "0x1::ascii::Char";
15
- static readonly $numTypeParams = 0;
16
- static readonly $isPhantom: readonly [];
17
- readonly $typeName = "0x1::ascii::Char";
18
- readonly $fullTypeName: `${typeof PKG_V13}::ascii::Char`;
19
- readonly $typeArgs: [];
20
- readonly $isPhantom: readonly [];
21
- readonly byte: ToField<"u8">;
22
- private constructor();
23
- static reified(): CharReified;
24
- static get r(): reified.StructClassReified<Char, CharFields>;
25
- static phantom(): PhantomReified<ToTypeStr<Char>>;
26
- static get p(): reified.PhantomReified<"0x1::ascii::Char">;
27
- static get bcs(): import("@mysten/bcs").BcsStruct<{
28
- byte: import("@mysten/bcs").BcsType<number, number, "u8">;
29
- }, string>;
30
- static fromFields(fields: Record<string, any>): Char;
31
- static fromFieldsWithTypes(item: FieldsWithTypes): Char;
32
- static fromBcs(data: Uint8Array): Char;
33
- toJSONField(): {
34
- byte: number;
35
- };
36
- toJSON(): {
37
- byte: number;
38
- $typeName: string;
39
- $typeArgs: [];
40
- };
41
- static fromJSONField(field: any): Char;
42
- static fromJSON(json: Record<string, any>): Char;
43
- static fetch(client: SuiGrpcClient, id: string): Promise<Char>;
44
- }
45
- export declare function isString(type: string): boolean;
46
- export interface StringFields {
47
- bytes: ToField<Vector<"u8">>;
48
- }
49
- export type StringReified = Reified<String, StringFields>;
50
- export declare class String implements StructClass {
51
- __StructClass: true;
52
- static readonly $typeName = "0x1::ascii::String";
53
- static readonly $numTypeParams = 0;
54
- static readonly $isPhantom: readonly [];
55
- readonly $typeName = "0x1::ascii::String";
56
- readonly $fullTypeName: `${typeof PKG_V13}::ascii::String`;
57
- readonly $typeArgs: [];
58
- readonly $isPhantom: readonly [];
59
- readonly bytes: ToField<Vector<"u8">>;
60
- private constructor();
61
- static reified(): StringReified;
62
- static get r(): reified.StructClassReified<String, StringFields>;
63
- static phantom(): PhantomReified<ToTypeStr<String>>;
64
- static get p(): reified.PhantomReified<"0x1::ascii::String">;
65
- static get bcs(): import("@mysten/bcs").BcsStruct<{
66
- bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
67
- length: number;
68
- }, string>;
69
- }, string>;
70
- static fromFields(fields: Record<string, any>): String;
71
- static fromFieldsWithTypes(item: FieldsWithTypes): String;
72
- static fromBcs(data: Uint8Array): String;
73
- toJSONField(): {
74
- bytes: number[];
75
- };
76
- toJSON(): {
77
- bytes: number[];
78
- $typeName: string;
79
- $typeArgs: [];
80
- };
81
- static fromJSONField(field: any): String;
82
- static fromJSON(json: Record<string, any>): String;
83
- static fetch(client: SuiGrpcClient, id: string): Promise<String>;
84
- }
@@ -1,3 +0,0 @@
1
- export declare const PACKAGE_ID = "0x1";
2
- export declare const PUBLISHED_AT = "0x1";
3
- export declare const PKG_V13 = "0x1";
@@ -1,3 +0,0 @@
1
- export const PACKAGE_ID = "0x1";
2
- export const PUBLISHED_AT = "0x1";
3
- export const PKG_V13 = "0x1";
@@ -1,110 +0,0 @@
1
- import * as reified from "../../../../_framework/reified.js";
2
- import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs, } from "../../../../_framework/reified.js";
3
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
4
- import { PKG_V13 } from "../index.js";
5
- import { bcs } from "@mysten/sui/bcs";
6
- /* ============================== Option =============================== */
7
- export function isOption(type) {
8
- type = compressSuiType(type);
9
- return type.startsWith(`${PKG_V13}::option::Option` + "<");
10
- }
11
- export class Option {
12
- __StructClass = true;
13
- static $typeName = `${PKG_V13}::option::Option`;
14
- static $numTypeParams = 1;
15
- static $isPhantom = [false];
16
- __inner = null; // for type checking in reified.ts
17
- $typeName = Option.$typeName;
18
- $fullTypeName;
19
- $typeArgs;
20
- $isPhantom = Option.$isPhantom;
21
- vec;
22
- constructor(typeArgs, fields) {
23
- this.$fullTypeName = composeSuiType(Option.$typeName, ...typeArgs);
24
- this.$typeArgs = typeArgs;
25
- this.vec = fields.vec;
26
- }
27
- static reified(Element) {
28
- return {
29
- typeName: Option.$typeName,
30
- fullTypeName: composeSuiType(Option.$typeName, ...[extractType(Element)]),
31
- typeArgs: [extractType(Element)],
32
- isPhantom: Option.$isPhantom,
33
- reifiedTypeArgs: [Element],
34
- fromFields: (fields) => Option.fromFields(Element, fields),
35
- fromFieldsWithTypes: (item) => Option.fromFieldsWithTypes(Element, item),
36
- fromBcs: (data) => Option.fromBcs(Element, data),
37
- bcs: Option.bcs(toBcs(Element)),
38
- fromJSONField: (field) => Option.fromJSONField(Element, field),
39
- fromJSON: (json) => Option.fromJSON(Element, json),
40
- fetch: async (client, id) => Option.fetch(client, Element, id),
41
- new: (fields) => {
42
- return new Option([extractType(Element)], fields);
43
- },
44
- kind: "StructClassReified",
45
- };
46
- }
47
- static get r() {
48
- return Option.reified;
49
- }
50
- static phantom(Element) {
51
- return phantom(Option.reified(Element));
52
- }
53
- static get p() {
54
- return Option.phantom;
55
- }
56
- static get bcs() {
57
- return (Element) => bcs.struct(`Option<${Element.name}>`, {
58
- vec: bcs.vector(Element),
59
- });
60
- }
61
- static fromFields(typeArg, fields) {
62
- return Option.reified(typeArg).new({
63
- vec: decodeFromFields(reified.vector(typeArg), fields.vec),
64
- });
65
- }
66
- static fromFieldsWithTypes(typeArg, item) {
67
- if (!isOption(item.type)) {
68
- throw new Error("not a Option type");
69
- }
70
- assertFieldsWithTypesArgsMatch(item, [typeArg]);
71
- return Option.reified(typeArg).new({
72
- vec: decodeFromFieldsWithTypes(reified.vector(typeArg), item.fields.vec),
73
- });
74
- }
75
- static fromBcs(typeArg, data) {
76
- const typeArgs = [typeArg];
77
- return Option.fromFields(typeArg, Option.bcs(toBcs(typeArgs[0])).parse(data));
78
- }
79
- toJSONField() {
80
- return {
81
- vec: fieldToJSON(`vector<${this.$typeArgs[0]}>`, this.vec),
82
- };
83
- }
84
- toJSON() {
85
- return {
86
- $typeName: this.$typeName,
87
- $typeArgs: this.$typeArgs,
88
- ...this.toJSONField(),
89
- };
90
- }
91
- static fromJSONField(typeArg, field) {
92
- return Option.reified(typeArg).new({
93
- vec: decodeFromJSONField(reified.vector(typeArg), field.vec),
94
- });
95
- }
96
- static fromJSON(typeArg, json) {
97
- if (json.$typeName !== Option.$typeName) {
98
- throw new Error("not a WithTwoGenerics json object");
99
- }
100
- assertReifiedTypeArgsMatch(composeSuiType(Option.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
101
- return Option.fromJSONField(typeArg, json);
102
- }
103
- static async fetch(client, typeArg, id) {
104
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
105
- if (!isOption(object.type)) {
106
- throw new Error(`object at id ${id} is not a Option object`);
107
- }
108
- return Option.fromBcs(typeArg, object.content);
109
- }
110
- }
@@ -1,47 +0,0 @@
1
- import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
2
- import { FieldsWithTypes } from "../../../../_framework/util";
3
- import { String } from "../ascii/structs";
4
- import { PKG_V13 } from "../index";
5
- import { SuiGrpcClient } from "@mysten/sui/grpc";
6
- export declare function isTypeName(type: string): boolean;
7
- export interface TypeNameFields {
8
- name: ToField<String>;
9
- }
10
- export type TypeNameReified = Reified<TypeName, TypeNameFields>;
11
- export declare class TypeName implements StructClass {
12
- __StructClass: true;
13
- static readonly $typeName = "0x1::type_name::TypeName";
14
- static readonly $numTypeParams = 0;
15
- static readonly $isPhantom: readonly [];
16
- readonly $typeName = "0x1::type_name::TypeName";
17
- readonly $fullTypeName: `${typeof PKG_V13}::type_name::TypeName`;
18
- readonly $typeArgs: [];
19
- readonly $isPhantom: readonly [];
20
- readonly name: ToField<String>;
21
- private constructor();
22
- static reified(): TypeNameReified;
23
- static get r(): import("../../../../_framework/reified").StructClassReified<TypeName, TypeNameFields>;
24
- static phantom(): PhantomReified<ToTypeStr<TypeName>>;
25
- static get p(): PhantomReified<"0x1::type_name::TypeName">;
26
- static get bcs(): import("@mysten/bcs").BcsStruct<{
27
- name: import("@mysten/bcs").BcsStruct<{
28
- bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
29
- length: number;
30
- }, string>;
31
- }, string>;
32
- }, string>;
33
- static fromFields(fields: Record<string, any>): TypeName;
34
- static fromFieldsWithTypes(item: FieldsWithTypes): TypeName;
35
- static fromBcs(data: Uint8Array): TypeName;
36
- toJSONField(): {
37
- name: string;
38
- };
39
- toJSON(): {
40
- name: string;
41
- $typeName: string;
42
- $typeArgs: [];
43
- };
44
- static fromJSONField(field: any): TypeName;
45
- static fromJSON(json: Record<string, any>): TypeName;
46
- static fetch(client: SuiGrpcClient, id: string): Promise<TypeName>;
47
- }
@@ -1,52 +0,0 @@
1
- import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
2
- import { FieldsWithTypes } from "../../../../_framework/util";
3
- import { PKG_V30 } from "../index";
4
- import { UID } from "../object/structs";
5
- import { SuiGrpcClient } from "@mysten/sui/grpc";
6
- export declare function isBag(type: string): boolean;
7
- export interface BagFields {
8
- id: ToField<UID>;
9
- size: ToField<"u64">;
10
- }
11
- export type BagReified = Reified<Bag, BagFields>;
12
- export declare class Bag implements StructClass {
13
- __StructClass: true;
14
- static readonly $typeName = "0x2::bag::Bag";
15
- static readonly $numTypeParams = 0;
16
- static readonly $isPhantom: readonly [];
17
- readonly $typeName = "0x2::bag::Bag";
18
- readonly $fullTypeName: `${typeof PKG_V30}::bag::Bag`;
19
- readonly $typeArgs: [];
20
- readonly $isPhantom: readonly [];
21
- readonly id: ToField<UID>;
22
- readonly size: ToField<"u64">;
23
- private constructor();
24
- static reified(): BagReified;
25
- static get r(): import("../../../../_framework/reified").StructClassReified<Bag, BagFields>;
26
- static phantom(): PhantomReified<ToTypeStr<Bag>>;
27
- static get p(): PhantomReified<"0x2::bag::Bag">;
28
- static get bcs(): import("@mysten/bcs").BcsStruct<{
29
- id: import("@mysten/bcs").BcsStruct<{
30
- id: import("@mysten/bcs").BcsStruct<{
31
- bytes: import("@mysten/bcs").BcsType<string, string, string>;
32
- }, string>;
33
- }, string>;
34
- size: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
35
- }, string>;
36
- static fromFields(fields: Record<string, any>): Bag;
37
- static fromFieldsWithTypes(item: FieldsWithTypes): Bag;
38
- static fromBcs(data: Uint8Array): Bag;
39
- toJSONField(): {
40
- id: string;
41
- size: string;
42
- };
43
- toJSON(): {
44
- id: string;
45
- size: string;
46
- $typeName: string;
47
- $typeArgs: [];
48
- };
49
- static fromJSONField(field: any): Bag;
50
- static fromJSON(json: Record<string, any>): Bag;
51
- static fetch(client: SuiGrpcClient, id: string): Promise<Bag>;
52
- }
@@ -1,113 +0,0 @@
1
- import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, } from "../../../../_framework/reified.js";
2
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
3
- import { PKG_V30 } from "../index.js";
4
- import { UID } from "../object/structs.js";
5
- import { bcs } from "@mysten/sui/bcs";
6
- /* ============================== Bag =============================== */
7
- export function isBag(type) {
8
- type = compressSuiType(type);
9
- return type === `${PKG_V30}::bag::Bag`;
10
- }
11
- export class Bag {
12
- __StructClass = true;
13
- static $typeName = `${PKG_V30}::bag::Bag`;
14
- static $numTypeParams = 0;
15
- static $isPhantom = [];
16
- $typeName = Bag.$typeName;
17
- $fullTypeName;
18
- $typeArgs;
19
- $isPhantom = Bag.$isPhantom;
20
- id;
21
- size;
22
- constructor(typeArgs, fields) {
23
- this.$fullTypeName = composeSuiType(Bag.$typeName, ...typeArgs);
24
- this.$typeArgs = typeArgs;
25
- this.id = fields.id;
26
- this.size = fields.size;
27
- }
28
- static reified() {
29
- return {
30
- typeName: Bag.$typeName,
31
- fullTypeName: composeSuiType(Bag.$typeName, ...[]),
32
- typeArgs: [],
33
- isPhantom: Bag.$isPhantom,
34
- reifiedTypeArgs: [],
35
- fromFields: (fields) => Bag.fromFields(fields),
36
- fromFieldsWithTypes: (item) => Bag.fromFieldsWithTypes(item),
37
- fromBcs: (data) => Bag.fromBcs(data),
38
- bcs: Bag.bcs,
39
- fromJSONField: (field) => Bag.fromJSONField(field),
40
- fromJSON: (json) => Bag.fromJSON(json),
41
- fetch: async (client, id) => Bag.fetch(client, id),
42
- new: (fields) => {
43
- return new Bag([], fields);
44
- },
45
- kind: "StructClassReified",
46
- };
47
- }
48
- static get r() {
49
- return Bag.reified();
50
- }
51
- static phantom() {
52
- return phantom(Bag.reified());
53
- }
54
- static get p() {
55
- return Bag.phantom();
56
- }
57
- static get bcs() {
58
- return bcs.struct("Bag", {
59
- id: UID.bcs,
60
- size: bcs.u64(),
61
- });
62
- }
63
- static fromFields(fields) {
64
- return Bag.reified().new({
65
- id: decodeFromFields(UID.reified(), fields.id),
66
- size: decodeFromFields("u64", fields.size),
67
- });
68
- }
69
- static fromFieldsWithTypes(item) {
70
- if (!isBag(item.type)) {
71
- throw new Error("not a Bag type");
72
- }
73
- return Bag.reified().new({
74
- id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
75
- size: decodeFromFieldsWithTypes("u64", item.fields.size),
76
- });
77
- }
78
- static fromBcs(data) {
79
- return Bag.fromFields(Bag.bcs.parse(data));
80
- }
81
- toJSONField() {
82
- return {
83
- id: this.id,
84
- size: this.size.toString(),
85
- };
86
- }
87
- toJSON() {
88
- return {
89
- $typeName: this.$typeName,
90
- $typeArgs: this.$typeArgs,
91
- ...this.toJSONField(),
92
- };
93
- }
94
- static fromJSONField(field) {
95
- return Bag.reified().new({
96
- id: decodeFromJSONField(UID.reified(), field.id),
97
- size: decodeFromJSONField("u64", field.size),
98
- });
99
- }
100
- static fromJSON(json) {
101
- if (json.$typeName !== Bag.$typeName) {
102
- throw new Error("not a WithTwoGenerics json object");
103
- }
104
- return Bag.fromJSONField(json);
105
- }
106
- static async fetch(client, id) {
107
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
108
- if (!isBag(object.type)) {
109
- throw new Error(`object at id ${id} is not a Bag object`);
110
- }
111
- return Bag.fromBcs(object.content);
112
- }
113
- }
@@ -1,210 +0,0 @@
1
- import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from "../../../../_framework/reified.js";
2
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
3
- import { PKG_V30 } from "../index.js";
4
- import { bcs } from "@mysten/sui/bcs";
5
- /* ============================== Balance =============================== */
6
- export function isBalance(type) {
7
- type = compressSuiType(type);
8
- return type.startsWith(`${PKG_V30}::balance::Balance` + "<");
9
- }
10
- export class Balance {
11
- __StructClass = true;
12
- static $typeName = `${PKG_V30}::balance::Balance`;
13
- static $numTypeParams = 1;
14
- static $isPhantom = [true];
15
- $typeName = Balance.$typeName;
16
- $fullTypeName;
17
- $typeArgs;
18
- $isPhantom = Balance.$isPhantom;
19
- value;
20
- constructor(typeArgs, fields) {
21
- this.$fullTypeName = composeSuiType(Balance.$typeName, ...typeArgs);
22
- this.$typeArgs = typeArgs;
23
- this.value = fields.value;
24
- }
25
- static reified(T) {
26
- return {
27
- typeName: Balance.$typeName,
28
- fullTypeName: composeSuiType(Balance.$typeName, ...[extractType(T)]),
29
- typeArgs: [extractType(T)],
30
- isPhantom: Balance.$isPhantom,
31
- reifiedTypeArgs: [T],
32
- fromFields: (fields) => Balance.fromFields(T, fields),
33
- fromFieldsWithTypes: (item) => Balance.fromFieldsWithTypes(T, item),
34
- fromBcs: (data) => Balance.fromBcs(T, data),
35
- bcs: Balance.bcs,
36
- fromJSONField: (field) => Balance.fromJSONField(T, field),
37
- fromJSON: (json) => Balance.fromJSON(T, json),
38
- fetch: async (client, id) => Balance.fetch(client, T, id),
39
- new: (fields) => {
40
- return new Balance([extractType(T)], fields);
41
- },
42
- kind: "StructClassReified",
43
- };
44
- }
45
- static get r() {
46
- return Balance.reified;
47
- }
48
- static phantom(T) {
49
- return phantom(Balance.reified(T));
50
- }
51
- static get p() {
52
- return Balance.phantom;
53
- }
54
- static get bcs() {
55
- return bcs.struct("Balance", {
56
- value: bcs.u64(),
57
- });
58
- }
59
- static fromFields(typeArg, fields) {
60
- return Balance.reified(typeArg).new({
61
- value: decodeFromFields("u64", fields.value),
62
- });
63
- }
64
- static fromFieldsWithTypes(typeArg, item) {
65
- if (!isBalance(item.type)) {
66
- throw new Error("not a Balance type");
67
- }
68
- assertFieldsWithTypesArgsMatch(item, [typeArg]);
69
- return Balance.reified(typeArg).new({
70
- value: decodeFromFieldsWithTypes("u64", item.fields.value),
71
- });
72
- }
73
- static fromBcs(typeArg, data) {
74
- return Balance.fromFields(typeArg, Balance.bcs.parse(data));
75
- }
76
- toJSONField() {
77
- return {
78
- value: this.value.toString(),
79
- };
80
- }
81
- toJSON() {
82
- return {
83
- $typeName: this.$typeName,
84
- $typeArgs: this.$typeArgs,
85
- ...this.toJSONField(),
86
- };
87
- }
88
- static fromJSONField(typeArg, field) {
89
- return Balance.reified(typeArg).new({
90
- value: decodeFromJSONField("u64", field.value),
91
- });
92
- }
93
- static fromJSON(typeArg, json) {
94
- if (json.$typeName !== Balance.$typeName) {
95
- throw new Error("not a WithTwoGenerics json object");
96
- }
97
- assertReifiedTypeArgsMatch(composeSuiType(Balance.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
98
- return Balance.fromJSONField(typeArg, json);
99
- }
100
- static async fetch(client, typeArg, id) {
101
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
102
- if (!isBalance(object.type)) {
103
- throw new Error(`object at id ${id} is not a Balance object`);
104
- }
105
- return Balance.fromBcs(typeArg, object.content);
106
- }
107
- }
108
- /* ============================== Supply =============================== */
109
- export function isSupply(type) {
110
- type = compressSuiType(type);
111
- return type.startsWith(`${PKG_V30}::balance::Supply` + "<");
112
- }
113
- export class Supply {
114
- __StructClass = true;
115
- static $typeName = `${PKG_V30}::balance::Supply`;
116
- static $numTypeParams = 1;
117
- static $isPhantom = [true];
118
- $typeName = Supply.$typeName;
119
- $fullTypeName;
120
- $typeArgs;
121
- $isPhantom = Supply.$isPhantom;
122
- value;
123
- constructor(typeArgs, fields) {
124
- this.$fullTypeName = composeSuiType(Supply.$typeName, ...typeArgs);
125
- this.$typeArgs = typeArgs;
126
- this.value = fields.value;
127
- }
128
- static reified(T) {
129
- return {
130
- typeName: Supply.$typeName,
131
- fullTypeName: composeSuiType(Supply.$typeName, ...[extractType(T)]),
132
- typeArgs: [extractType(T)],
133
- isPhantom: Supply.$isPhantom,
134
- reifiedTypeArgs: [T],
135
- fromFields: (fields) => Supply.fromFields(T, fields),
136
- fromFieldsWithTypes: (item) => Supply.fromFieldsWithTypes(T, item),
137
- fromBcs: (data) => Supply.fromBcs(T, data),
138
- bcs: Supply.bcs,
139
- fromJSONField: (field) => Supply.fromJSONField(T, field),
140
- fromJSON: (json) => Supply.fromJSON(T, json),
141
- fetch: async (client, id) => Supply.fetch(client, T, id),
142
- new: (fields) => {
143
- return new Supply([extractType(T)], fields);
144
- },
145
- kind: "StructClassReified",
146
- };
147
- }
148
- static get r() {
149
- return Supply.reified;
150
- }
151
- static phantom(T) {
152
- return phantom(Supply.reified(T));
153
- }
154
- static get p() {
155
- return Supply.phantom;
156
- }
157
- static get bcs() {
158
- return bcs.struct("Supply", {
159
- value: bcs.u64(),
160
- });
161
- }
162
- static fromFields(typeArg, fields) {
163
- return Supply.reified(typeArg).new({
164
- value: decodeFromFields("u64", fields.value),
165
- });
166
- }
167
- static fromFieldsWithTypes(typeArg, item) {
168
- if (!isSupply(item.type)) {
169
- throw new Error("not a Supply type");
170
- }
171
- assertFieldsWithTypesArgsMatch(item, [typeArg]);
172
- return Supply.reified(typeArg).new({
173
- value: decodeFromFieldsWithTypes("u64", item.fields.value),
174
- });
175
- }
176
- static fromBcs(typeArg, data) {
177
- return Supply.fromFields(typeArg, Supply.bcs.parse(data));
178
- }
179
- toJSONField() {
180
- return {
181
- value: this.value.toString(),
182
- };
183
- }
184
- toJSON() {
185
- return {
186
- $typeName: this.$typeName,
187
- $typeArgs: this.$typeArgs,
188
- ...this.toJSONField(),
189
- };
190
- }
191
- static fromJSONField(typeArg, field) {
192
- return Supply.reified(typeArg).new({
193
- value: decodeFromJSONField("u64", field.value),
194
- });
195
- }
196
- static fromJSON(typeArg, json) {
197
- if (json.$typeName !== Supply.$typeName) {
198
- throw new Error("not a WithTwoGenerics json object");
199
- }
200
- assertReifiedTypeArgsMatch(composeSuiType(Supply.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
201
- return Supply.fromJSONField(typeArg, json);
202
- }
203
- static async fetch(client, typeArg, id) {
204
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
205
- if (!isSupply(object.type)) {
206
- throw new Error(`object at id ${id} is not a Supply object`);
207
- }
208
- return Supply.fromBcs(typeArg, object.content);
209
- }
210
- }
@@ -1,3 +0,0 @@
1
- export declare const PACKAGE_ID = "0x2";
2
- export declare const PUBLISHED_AT = "0x2";
3
- export declare const PKG_V30 = "0x2";
@@ -1,3 +0,0 @@
1
- export const PACKAGE_ID = "0x2";
2
- export const PUBLISHED_AT = "0x2";
3
- export const PKG_V30 = "0x2";