@waterx/sdk 2.4.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -21
- package/dist/src/{utils → account}/account-request.d.ts +2 -2
- package/dist/src/{user → account}/account.d.ts +23 -21
- package/dist/src/{user → account}/account.js +5 -5
- package/dist/src/account/client.d.ts +42 -0
- package/dist/src/account/client.js +17 -0
- package/dist/src/account/config.d.ts +151 -0
- package/dist/src/account/config.js +8 -0
- package/dist/src/account/constants.d.ts +5 -0
- package/dist/src/account/constants.js +5 -0
- package/dist/src/account/fetch/referral.d.ts +15 -0
- package/dist/src/account/fetch/referral.js +51 -0
- package/dist/src/account/fetch/simulate.d.ts +34 -0
- package/dist/src/account/fetch/simulate.js +43 -0
- package/dist/src/{utils/consolidate-balance.d.ts → account/funding/balance.d.ts} +3 -8
- package/dist/src/{utils/consolidate-balance.js → account/funding/balance.js} +6 -1
- package/dist/src/account/funding/consolidate.d.ts +46 -0
- package/dist/src/account/funding/consolidate.js +137 -0
- package/dist/src/{user → account/funding}/credit.d.ts +10 -10
- package/dist/src/{user → account/funding}/credit.js +6 -6
- package/dist/src/{user → account/funding}/custody.d.ts +4 -4
- package/dist/src/{user → account/funding}/custody.js +2 -2
- package/dist/src/{utils → account/funding}/wormhole.d.ts +4 -4
- package/dist/src/{utils → account/funding}/wormhole.js +1 -1
- package/dist/src/account/index.d.ts +29 -0
- package/dist/src/account/index.js +29 -0
- package/dist/src/{user → account}/referral.d.ts +3 -3
- package/dist/src/{user → account}/referral.js +1 -1
- package/dist/src/base-client.d.ts +74 -0
- package/dist/src/base-client.js +97 -0
- package/dist/src/constants.d.ts +4 -42
- package/dist/src/constants.js +8 -47
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +0 -26
- package/dist/src/generated/bucket_v2_framework/liability.js +0 -28
- package/dist/src/generated/waterx_account/account.d.ts +50 -15
- package/dist/src/generated/waterx_account/account.js +51 -15
- package/dist/src/generated/waterx_oracle/oracle.d.ts +7 -1
- package/dist/src/generated/waterx_oracle/oracle.js +7 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.d.ts +19 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.d.ts +3 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/sui/balance.d.ts +3 -1
- package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.d.ts +6 -1
- package/dist/src/generated/waterx_prediction/events.d.ts +288 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/events.js +39 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.d.ts +6 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/order.d.ts +34 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/position.d.ts +16 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/view.d.ts +69 -4
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.d.ts +162 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.js +99 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +102 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +99 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +5 -5
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +1 -2
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +23 -23
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +3 -6
- package/dist/src/oracle/aggregate.d.ts +74 -0
- package/dist/src/oracle/aggregate.js +112 -0
- package/dist/src/oracle/config.d.ts +99 -0
- package/dist/src/oracle/config.js +23 -0
- package/dist/src/oracle/host.d.ts +32 -0
- package/dist/src/oracle/host.js +10 -0
- package/dist/src/oracle/index.d.ts +16 -0
- package/dist/src/oracle/index.js +18 -0
- package/dist/src/oracle/pyth.d.ts +52 -0
- package/dist/src/oracle/pyth.js +220 -0
- package/dist/src/oracle/rules/constant-rule.d.ts +9 -0
- package/dist/src/oracle/rules/constant-rule.js +14 -0
- package/dist/src/oracle/rules/pyth-rule.d.ts +11 -0
- package/dist/src/oracle/rules/pyth-rule.js +20 -0
- package/dist/src/oracle/rules/sponsor.d.ts +28 -0
- package/dist/src/oracle/rules/sponsor.js +48 -0
- package/dist/src/oracle/rules/supra-rule.d.ts +11 -0
- package/dist/src/oracle/rules/supra-rule.js +22 -0
- package/dist/src/perp/client.d.ts +78 -0
- package/dist/src/perp/client.js +108 -0
- package/dist/src/{client.d.ts → perp/config-view.d.ts} +15 -60
- package/dist/src/{client.js → perp/config-view.js} +23 -95
- package/dist/src/perp/config.d.ts +126 -0
- package/dist/src/{config.js → perp/config.js} +11 -12
- package/dist/src/perp/constants.d.ts +49 -0
- package/dist/src/perp/constants.js +61 -0
- package/dist/src/perp/fetch/account.d.ts +43 -0
- package/dist/src/perp/fetch/account.js +64 -0
- package/dist/src/perp/fetch/bridge.d.ts +90 -0
- package/dist/src/perp/fetch/bridge.js +127 -0
- package/dist/src/perp/fetch/custody.d.ts +32 -0
- package/dist/src/perp/fetch/custody.js +62 -0
- package/dist/src/perp/fetch/market.d.ts +30 -0
- package/dist/src/perp/fetch/market.js +68 -0
- package/dist/src/perp/fetch/positions.d.ts +70 -0
- package/dist/src/perp/fetch/positions.js +185 -0
- package/dist/src/perp/fetch/simulate.d.ts +12 -0
- package/dist/src/perp/fetch/simulate.js +13 -0
- package/dist/src/perp/fetch.d.ts +23 -0
- package/dist/src/perp/fetch.js +23 -0
- package/dist/src/{index.d.ts → perp/index.d.ts} +22 -22
- package/dist/src/{index.js → perp/index.js} +22 -22
- package/dist/src/perp/tx-builders/common.d.ts +83 -0
- package/dist/src/perp/tx-builders/common.js +70 -0
- package/dist/src/perp/tx-builders/credit.d.ts +65 -0
- package/dist/src/perp/tx-builders/credit.js +62 -0
- package/dist/src/perp/tx-builders/rewards.d.ts +30 -0
- package/dist/src/perp/tx-builders/rewards.js +34 -0
- package/dist/src/perp/tx-builders/trading.d.ts +51 -0
- package/dist/src/perp/tx-builders/trading.js +59 -0
- package/dist/src/perp/tx-builders/wlp.d.ts +90 -0
- package/dist/src/perp/tx-builders/wlp.js +120 -0
- package/dist/src/perp/tx-builders.d.ts +23 -0
- package/dist/src/perp/tx-builders.js +23 -0
- package/dist/src/perp/user/index.d.ts +8 -0
- package/dist/src/perp/user/index.js +8 -0
- package/dist/src/{user → perp/user}/order.d.ts +7 -7
- package/dist/src/{user → perp/user}/order.js +3 -3
- package/dist/src/{user → perp/user}/staking.d.ts +4 -4
- package/dist/src/{user → perp/user}/staking.js +2 -2
- package/dist/src/{user → perp/user}/trading.d.ts +13 -13
- package/dist/src/{user → perp/user}/trading.js +2 -2
- package/dist/src/{user → perp/user}/wlp.d.ts +7 -7
- package/dist/src/{user → perp/user}/wlp.js +3 -3
- package/dist/src/prediction/account.js +40 -76
- package/dist/src/prediction/client.d.ts +8 -38
- package/dist/src/prediction/client.js +11 -67
- package/dist/src/prediction/config.d.ts +16 -2
- package/dist/src/prediction/config.js +10 -4
- package/dist/src/prediction/index.d.ts +11 -11
- package/dist/src/prediction/index.js +10 -10
- package/dist/src/prediction/prediction.d.ts +45 -0
- package/dist/src/prediction/prediction.js +71 -0
- package/dist/src/prediction/tx-builders.d.ts +4 -4
- package/dist/src/prediction/tx-builders.js +2 -2
- package/dist/src/prediction/user/index.d.ts +2 -2
- package/dist/src/prediction/user/index.js +1 -1
- package/dist/src/prediction/user/position.d.ts +2 -2
- package/dist/src/prediction/user/position.js +1 -1
- package/dist/src/prediction/utils/bcs.d.ts +5 -0
- package/dist/src/prediction/utils/bcs.js +5 -0
- package/dist/src/prediction/utils/index.d.ts +7 -0
- package/dist/src/prediction/utils/index.js +7 -0
- package/dist/src/sdk.d.ts +10 -6
- package/dist/src/sdk.js +9 -5
- package/dist/src/unified-client.d.ts +140 -145
- package/dist/src/unified-client.js +98 -40
- package/dist/src/utils/config.d.ts +1 -1
- package/package.json +22 -5
- package/dist/src/config.d.ts +0 -292
- package/dist/src/fetch.d.ts +0 -254
- package/dist/src/fetch.js +0 -564
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
- package/dist/src/prediction/generated/utils/index.d.ts +0 -30
- package/dist/src/prediction/generated/utils/index.js +0 -160
- package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
- package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
- package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
- package/dist/src/prediction/generated/waterx_account/events.js +0 -137
- package/dist/src/prediction/generated/waterx_account/version.js +0 -8
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
- package/dist/src/tx-builders.d.ts +0 -296
- package/dist/src/tx-builders.js +0 -461
- package/dist/src/user/index.d.ts +0 -8
- package/dist/src/user/index.js +0 -8
- package/dist/src/utils/pyth.d.ts +0 -124
- package/dist/src/utils/pyth.js +0 -392
- /package/dist/src/{utils → account}/account-request.js +0 -0
- /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
- /package/dist/src/{core → account}/waterx-account.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type BcsType, type TypeTag, BcsStruct, BcsEnum, BcsTuple } from '@mysten/sui/bcs';
|
|
2
|
-
import { type TransactionArgument } from '@mysten/sui/transactions';
|
|
3
|
-
import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
|
|
4
|
-
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
5
|
-
export type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> = SuiClientTypes.GetObjectOptions<Include> & {
|
|
6
|
-
client: ClientWithCoreApi;
|
|
7
|
-
};
|
|
8
|
-
export type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> = SuiClientTypes.GetObjectsOptions<Include> & {
|
|
9
|
-
client: ClientWithCoreApi;
|
|
10
|
-
};
|
|
11
|
-
export declare function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null;
|
|
12
|
-
export declare function normalizeMoveArguments(args: unknown[] | object, argTypes: readonly (string | null)[], parameterNames?: string[]): TransactionArgument[];
|
|
13
|
-
export declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
14
|
-
get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({ objectId, ...options }: GetOptions<Include>): Promise<SuiClientTypes.Object<Include & {
|
|
15
|
-
content: true;
|
|
16
|
-
json: true;
|
|
17
|
-
}> & {
|
|
18
|
-
json: BcsStruct<T>['$inferType'];
|
|
19
|
-
}>;
|
|
20
|
-
getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({ client, ...options }: GetManyOptions<Include>): Promise<Array<SuiClientTypes.Object<Include & {
|
|
21
|
-
content: true;
|
|
22
|
-
json: true;
|
|
23
|
-
}> & {
|
|
24
|
-
json: BcsStruct<T>['$inferType'];
|
|
25
|
-
}>>;
|
|
26
|
-
}
|
|
27
|
-
export declare class MoveEnum<T extends Record<string, BcsType<any> | null>, const Name extends string> extends BcsEnum<T, Name> {
|
|
28
|
-
}
|
|
29
|
-
export declare class MoveTuple<const T extends readonly BcsType<any>[], const Name extends string> extends BcsTuple<T, Name> {
|
|
30
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { bcs, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple, } from '@mysten/sui/bcs';
|
|
2
|
-
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
3
|
-
import { isArgument } from '@mysten/sui/transactions';
|
|
4
|
-
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');
|
|
5
|
-
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');
|
|
6
|
-
export function getPureBcsSchema(typeTag) {
|
|
7
|
-
const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
8
|
-
if ('u8' in parsedTag) {
|
|
9
|
-
return bcs.U8;
|
|
10
|
-
}
|
|
11
|
-
else if ('u16' in parsedTag) {
|
|
12
|
-
return bcs.U16;
|
|
13
|
-
}
|
|
14
|
-
else if ('u32' in parsedTag) {
|
|
15
|
-
return bcs.U32;
|
|
16
|
-
}
|
|
17
|
-
else if ('u64' in parsedTag) {
|
|
18
|
-
return bcs.U64;
|
|
19
|
-
}
|
|
20
|
-
else if ('u128' in parsedTag) {
|
|
21
|
-
return bcs.U128;
|
|
22
|
-
}
|
|
23
|
-
else if ('u256' in parsedTag) {
|
|
24
|
-
return bcs.U256;
|
|
25
|
-
}
|
|
26
|
-
else if ('address' in parsedTag) {
|
|
27
|
-
return bcs.Address;
|
|
28
|
-
}
|
|
29
|
-
else if ('bool' in parsedTag) {
|
|
30
|
-
return bcs.Bool;
|
|
31
|
-
}
|
|
32
|
-
else if ('vector' in parsedTag) {
|
|
33
|
-
const type = getPureBcsSchema(parsedTag.vector);
|
|
34
|
-
return type ? bcs.vector(type) : null;
|
|
35
|
-
}
|
|
36
|
-
else if ('struct' in parsedTag) {
|
|
37
|
-
const structTag = parsedTag.struct;
|
|
38
|
-
const pkg = normalizeSuiAddress(structTag.address);
|
|
39
|
-
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
40
|
-
if ((structTag.module === 'ascii' || structTag.module === 'string') &&
|
|
41
|
-
structTag.name === 'String') {
|
|
42
|
-
return bcs.String;
|
|
43
|
-
}
|
|
44
|
-
if (structTag.module === 'option' && structTag.name === 'Option') {
|
|
45
|
-
const inner = structTag.typeParams[0];
|
|
46
|
-
const type = inner ? getPureBcsSchema(inner) : null;
|
|
47
|
-
return type ? bcs.option(type) : null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (pkg === SUI_FRAMEWORK_ADDRESS &&
|
|
51
|
-
structTag.module === 'object' &&
|
|
52
|
-
(structTag.name === 'ID' || structTag.name === 'UID')) {
|
|
53
|
-
return bcs.Address;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
export function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
59
|
-
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
60
|
-
if (parameterNames && argLen !== parameterNames.length) {
|
|
61
|
-
throw new Error(`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`);
|
|
62
|
-
}
|
|
63
|
-
const normalizedArgs = [];
|
|
64
|
-
let index = 0;
|
|
65
|
-
for (const argType of argTypes) {
|
|
66
|
-
if (argType === '0x2::clock::Clock') {
|
|
67
|
-
normalizedArgs.push((tx) => tx.object.clock());
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (argType === '0x2::random::Random') {
|
|
71
|
-
normalizedArgs.push((tx) => tx.object.random());
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (argType === '0x2::deny_list::DenyList') {
|
|
75
|
-
normalizedArgs.push((tx) => tx.object.denyList());
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (argType === '0x3::sui_system::SuiSystemState') {
|
|
79
|
-
normalizedArgs.push((tx) => tx.object.system());
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
let arg;
|
|
83
|
-
if (Array.isArray(args)) {
|
|
84
|
-
if (index >= args.length) {
|
|
85
|
-
throw new Error(`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`);
|
|
86
|
-
}
|
|
87
|
-
arg = args[index];
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (!parameterNames) {
|
|
91
|
-
throw new Error(`Expected arguments to be passed as an array`);
|
|
92
|
-
}
|
|
93
|
-
const name = parameterNames[index];
|
|
94
|
-
arg = args[name];
|
|
95
|
-
if (arg === undefined) {
|
|
96
|
-
throw new Error(`Parameter ${name} is required`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
index += 1;
|
|
100
|
-
if (typeof arg === 'function' || isArgument(arg)) {
|
|
101
|
-
normalizedArgs.push(arg);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const bcsType = argType === null ? null : getPureBcsSchema(argType);
|
|
105
|
-
if (bcsType) {
|
|
106
|
-
const bytes = bcsType.serialize(arg);
|
|
107
|
-
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (typeof arg === 'string') {
|
|
111
|
-
normalizedArgs.push((tx) => tx.object(arg));
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
|
|
115
|
-
}
|
|
116
|
-
return normalizedArgs;
|
|
117
|
-
}
|
|
118
|
-
export class MoveStruct extends BcsStruct {
|
|
119
|
-
async get({ objectId, ...options }) {
|
|
120
|
-
const [res] = await this.getMany({
|
|
121
|
-
...options,
|
|
122
|
-
objectIds: [objectId],
|
|
123
|
-
});
|
|
124
|
-
if (!res) {
|
|
125
|
-
throw new Error(`No object found for id ${objectId}`);
|
|
126
|
-
}
|
|
127
|
-
return res;
|
|
128
|
-
}
|
|
129
|
-
async getMany({ client, ...options }) {
|
|
130
|
-
const response = (await client.core.getObjects({
|
|
131
|
-
...options,
|
|
132
|
-
include: {
|
|
133
|
-
...options.include,
|
|
134
|
-
content: true,
|
|
135
|
-
},
|
|
136
|
-
}));
|
|
137
|
-
return response.objects.map((obj) => {
|
|
138
|
-
if (obj instanceof Error) {
|
|
139
|
-
throw obj;
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
...obj,
|
|
143
|
-
json: this.parse(obj.content),
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export class MoveEnum extends BcsEnum {
|
|
149
|
-
}
|
|
150
|
-
export class MoveTuple extends BcsTuple {
|
|
151
|
-
}
|
|
152
|
-
function stringify(val) {
|
|
153
|
-
if (typeof val === 'object') {
|
|
154
|
-
return JSON.stringify(val, (val) => val);
|
|
155
|
-
}
|
|
156
|
-
if (typeof val === 'bigint') {
|
|
157
|
-
return val.toString();
|
|
158
|
-
}
|
|
159
|
-
return val;
|
|
160
|
-
}
|