@suigar/sdk 2.0.0-beta.13 → 2.0.0-beta.15
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 +23 -4
- package/README.md +22 -8
- package/dist/client.d.mts +258 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +291 -0
- package/dist/client.mjs.map +1 -0
- package/dist/configs/package.mainnet.mjs +23 -0
- package/dist/configs/package.mainnet.mjs.map +1 -0
- package/dist/configs/package.mjs +19 -0
- package/dist/configs/package.mjs.map +1 -0
- package/dist/configs/package.testnet.mjs +23 -0
- package/dist/configs/package.testnet.mjs.map +1 -0
- package/dist/configs/registry.mainnet.mjs +6 -0
- package/dist/configs/registry.mainnet.mjs.map +1 -0
- package/dist/configs/registry.mjs +11 -0
- package/dist/configs/registry.mjs.map +1 -0
- package/dist/configs/registry.testnet.mjs +6 -0
- package/dist/configs/registry.testnet.mjs.map +1 -0
- package/dist/contracts/coinflip/coinflip.mjs +46 -0
- package/dist/contracts/coinflip/coinflip.mjs.map +1 -0
- package/dist/contracts/core/core.d.mts +55 -0
- package/dist/contracts/core/core.d.mts.map +1 -0
- package/dist/contracts/core/core.mjs +22 -0
- package/dist/contracts/core/core.mjs.map +1 -0
- package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
- package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
- package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
- package/dist/contracts/core/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
- package/dist/contracts/core/float.d.mts +14 -0
- package/dist/contracts/core/float.d.mts.map +1 -0
- package/dist/contracts/core/float.mjs +15 -0
- package/dist/contracts/core/float.mjs.map +1 -0
- package/dist/contracts/core/i64.mjs +10 -0
- package/dist/contracts/core/i64.mjs.map +1 -0
- package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
- package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
- package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
- package/dist/contracts/limbo/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
- package/dist/contracts/limbo/limbo.mjs +53 -0
- package/dist/contracts/limbo/limbo.mjs.map +1 -0
- package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
- package/dist/contracts/plinko/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
- package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
- package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
- package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
- package/dist/contracts/plinko/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
- package/dist/contracts/plinko/plinko.mjs +59 -0
- package/dist/contracts/plinko/plinko.mjs.map +1 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs +10 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.mjs.map +1 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs +10 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.mjs.map +1 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
- package/dist/contracts/pvp-coinflip/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
- package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts +34 -0
- package/dist/contracts/pvp-coinflip/pvp_coinflip.d.mts.map +1 -0
- package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs +131 -0
- package/dist/contracts/pvp-coinflip/pvp_coinflip.mjs.map +1 -0
- package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
- package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
- package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
- package/dist/contracts/range/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
- package/dist/contracts/range/range.mjs +53 -0
- package/dist/contracts/range/range.mjs.map +1 -0
- package/dist/contracts/utils/index.d.mts +33 -0
- package/dist/contracts/utils/index.d.mts.map +1 -0
- package/dist/contracts/utils/index.mjs +119 -0
- package/dist/contracts/utils/index.mjs.map +1 -0
- package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs +26 -0
- package/dist/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs.map +1 -0
- package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs +15 -0
- package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs.map +1 -0
- package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs +10 -0
- package/dist/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.mjs.map +1 -0
- package/dist/contracts/wheel/wheel.mjs +59 -0
- package/dist/contracts/wheel/wheel.mjs.map +1 -0
- package/dist/games.d.mts +3 -0
- package/dist/games.mjs +1 -0
- package/dist/helpers/config.mjs +51 -0
- package/dist/helpers/config.mjs.map +1 -0
- package/dist/helpers/game-settings.mjs +19 -0
- package/dist/helpers/game-settings.mjs.map +1 -0
- package/dist/helpers/metadata.mjs +42 -0
- package/dist/helpers/metadata.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/transactions/coinflip.mjs +27 -0
- package/dist/transactions/coinflip.mjs.map +1 -0
- package/dist/transactions/limbo.mjs +31 -0
- package/dist/transactions/limbo.mjs.map +1 -0
- package/dist/transactions/plinko.mjs +29 -0
- package/dist/transactions/plinko.mjs.map +1 -0
- package/dist/transactions/pvp-coinflip.mjs +70 -0
- package/dist/transactions/pvp-coinflip.mjs.map +1 -0
- package/dist/transactions/range.mjs +33 -0
- package/dist/transactions/range.mjs.map +1 -0
- package/dist/transactions/shared.mjs +49 -0
- package/dist/transactions/shared.mjs.map +1 -0
- package/dist/transactions/wheel.mjs +29 -0
- package/dist/transactions/wheel.mjs.map +1 -0
- package/dist/ttl-cache.mjs +60 -0
- package/dist/ttl-cache.mjs.map +1 -0
- package/dist/types/bet-metadata.type.d.mts +7 -0
- package/dist/types/bet-metadata.type.d.mts.map +1 -0
- package/dist/types/build-game-transaction-options.type.d.mts +9 -0
- package/dist/types/build-game-transaction-options.type.d.mts.map +1 -0
- package/dist/types/game-details.type.d.mts +73 -0
- package/dist/types/game-details.type.d.mts.map +1 -0
- package/dist/types/game-details.type.mjs +59 -0
- package/dist/types/game-details.type.mjs.map +1 -0
- package/dist/types/game-settings.type.d.mts +201 -0
- package/dist/types/game-settings.type.d.mts.map +1 -0
- package/dist/types/game-settings.type.mjs +37 -0
- package/dist/types/game-settings.type.mjs.map +1 -0
- package/dist/types/game.type.d.mts +15 -0
- package/dist/types/game.type.d.mts.map +1 -0
- package/dist/types/game.type.mjs +19 -0
- package/dist/types/game.type.mjs.map +1 -0
- package/dist/types/index.d.mts +7 -0
- package/dist/types/move-float.type.d.mts +7 -0
- package/dist/types/move-float.type.d.mts.map +1 -0
- package/dist/types/network.type.d.mts +1 -0
- package/dist/types/network.type.mjs +6 -0
- package/dist/types/network.type.mjs.map +1 -0
- package/dist/types/suigar-config.type.d.mts +33 -0
- package/dist/types/suigar-config.type.d.mts.map +1 -0
- package/dist/types/transaction-options.type.d.mts +63 -0
- package/dist/types/transaction-options.type.d.mts.map +1 -0
- package/dist/utils/constants.d.mts +8 -0
- package/dist/utils/constants.d.mts.map +1 -0
- package/dist/utils/constants.mjs +10 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/numeric.d.mts +86 -0
- package/dist/utils/numeric.d.mts.map +1 -0
- package/dist/utils/numeric.mjs +148 -0
- package/dist/utils/numeric.mjs.map +1 -0
- package/dist/utils/parser.d.mts +54 -0
- package/dist/utils/parser.d.mts.map +1 -0
- package/dist/utils/parser.mjs +94 -0
- package/dist/utils/parser.mjs.map +1 -0
- package/dist/utils.d.mts +4 -0
- package/dist/utils.mjs +4 -0
- package/package.json +16 -17
- package/dist/chunk-7N55D2TV.js +0 -343
- package/dist/games-BHYRg31e.d.cts +0 -98
- package/dist/games-BHYRg31e.d.ts +0 -98
- package/dist/games.cjs +0 -2
- package/dist/games.d.cts +0 -2
- package/dist/games.d.ts +0 -2
- package/dist/games.js +0 -1
- package/dist/index-3P_LBbDM.d.cts +0 -25
- package/dist/index-3P_LBbDM.d.ts +0 -25
- package/dist/index.cjs +0 -1692
- package/dist/index.d.cts +0 -457
- package/dist/index.d.ts +0 -457
- package/dist/index.js +0 -1470
- package/dist/utils.cjs +0 -243
- package/dist/utils.d.cts +0 -180
- package/dist/utils.d.ts +0 -180
- package/dist/utils.js +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { MoveStruct, normalizeMoveArguments } from "../utils/index.mjs";
|
|
2
|
+
import { Float } from "./deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs";
|
|
3
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
4
|
+
//#region src/contracts/range/range.ts
|
|
5
|
+
/**************************************************************
|
|
6
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
7
|
+
**************************************************************/
|
|
8
|
+
const $moduleName = "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416::range";
|
|
9
|
+
const RangeSettingsKey = new MoveStruct({
|
|
10
|
+
name: `${$moduleName}::RangeSettingsKey`,
|
|
11
|
+
fields: { dummy_field: bcs.bool() }
|
|
12
|
+
});
|
|
13
|
+
const Parameters = new MoveStruct({
|
|
14
|
+
name: `${$moduleName}::Parameters<phantom T0>`,
|
|
15
|
+
fields: {
|
|
16
|
+
id: bcs.Address,
|
|
17
|
+
min_stake: bcs.u64(),
|
|
18
|
+
max_stake: bcs.u64(),
|
|
19
|
+
min_zone_size: bcs.u64(),
|
|
20
|
+
max_zone_size: bcs.u64(),
|
|
21
|
+
max_number_of_games: bcs.u64(),
|
|
22
|
+
min_rtp: Float,
|
|
23
|
+
max_rtp: Float
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function play(options) {
|
|
27
|
+
const packageAddress = options.package ?? "0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416";
|
|
28
|
+
const argumentsTypes = [
|
|
29
|
+
null,
|
|
30
|
+
"u64",
|
|
31
|
+
null,
|
|
32
|
+
"u64",
|
|
33
|
+
"u64",
|
|
34
|
+
"u64",
|
|
35
|
+
"bool",
|
|
36
|
+
"vector<0x1::string::String>",
|
|
37
|
+
"vector<vector<u8>>",
|
|
38
|
+
null,
|
|
39
|
+
"0x2::clock::Clock",
|
|
40
|
+
"0x2::random::Random"
|
|
41
|
+
];
|
|
42
|
+
return (tx) => tx.moveCall({
|
|
43
|
+
package: packageAddress,
|
|
44
|
+
module: "range",
|
|
45
|
+
function: "play",
|
|
46
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
47
|
+
typeArguments: options.typeArguments
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Parameters, RangeSettingsKey, play };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=range.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.mjs","names":["float.Float"],"sources":["../../../src/contracts/range/range.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { bcs } from '@mysten/sui/bcs';\nimport { type Transaction } from '@mysten/sui/transactions';\nimport {\n\tMoveStruct,\n\tnormalizeMoveArguments,\n\ttype RawTransactionArgument,\n} from '../utils/index.js';\nimport * as float from './deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.js';\n\nconst $moduleName =\n\t'0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416::range';\nexport const RangeSettingsKey = new MoveStruct({\n\tname: `${$moduleName}::RangeSettingsKey`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const Parameters = new MoveStruct({\n\tname: `${$moduleName}::Parameters<phantom T0>`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\tmin_stake: bcs.u64(),\n\t\tmax_stake: bcs.u64(),\n\t\tmin_zone_size: bcs.u64(),\n\t\tmax_zone_size: bcs.u64(),\n\t\tmax_number_of_games: bcs.u64(),\n\t\tmin_rtp: float.Float,\n\t\tmax_rtp: float.Float,\n\t},\n});\nexport interface PlayOptions {\n\tpackage?: string;\n\targuments: [\n\t\tRawTransactionArgument<string>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<string>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<boolean>,\n\t\tRawTransactionArgument<Array<string>>,\n\t\tRawTransactionArgument<Array<Array<number>>>,\n\t\tRawTransactionArgument<string>,\n\t];\n\ttypeArguments: [string];\n}\nexport function play(options: PlayOptions) {\n\tconst packageAddress =\n\t\toptions.package ??\n\t\t'0x096a4cf18b3661e76b2c62b90785418345d52f45b272448794f123a4cb6b6416';\n\tconst argumentsTypes = [\n\t\tnull,\n\t\t'u64',\n\t\tnull,\n\t\t'u64',\n\t\t'u64',\n\t\t'u64',\n\t\t'bool',\n\t\t'vector<0x1::string::String>',\n\t\t'vector<vector<u8>>',\n\t\tnull,\n\t\t'0x2::clock::Clock',\n\t\t'0x2::random::Random',\n\t] satisfies (string | null)[];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'range',\n\t\t\tfunction: 'play',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\n"],"mappings":";;;;;;;AAYA,MAAM,cACL;AACD,MAAa,mBAAmB,IAAI,WAAW;CAC9C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,aAAa,IAAI,WAAW;CACxC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EACR,WAAW,IAAI,KAAK;EACpB,WAAW,IAAI,KAAK;EACpB,eAAe,IAAI,KAAK;EACxB,eAAe,IAAI,KAAK;EACxB,qBAAqB,IAAI,KAAK;EAC9B,SAASA;EACT,SAASA;EACT;CACD,CAAC;AAiBF,SAAgB,KAAK,SAAsB;CAC1C,MAAM,iBACL,QAAQ,WACR;CACD,MAAM,iBAAiB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,QAAQ,OACP,GAAG,SAAS;EACX,SAAS;EACT,QAAQ;EACR,UAAU;EACV,WAAW,uBAAuB,QAAQ,WAAW,eAAe;EACpE,eAAe,QAAQ;EACvB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BcsStruct, BcsType } from "@mysten/sui/bcs";
|
|
2
|
+
import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
3
|
+
|
|
4
|
+
//#region src/contracts/utils/index.d.ts
|
|
5
|
+
type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> = SuiClientTypes.GetObjectOptions<Include> & {
|
|
6
|
+
client: ClientWithCoreApi;
|
|
7
|
+
};
|
|
8
|
+
type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> = SuiClientTypes.GetObjectsOptions<Include> & {
|
|
9
|
+
client: ClientWithCoreApi;
|
|
10
|
+
};
|
|
11
|
+
declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
12
|
+
get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
13
|
+
objectId,
|
|
14
|
+
...options
|
|
15
|
+
}: GetOptions<Include>): Promise<SuiClientTypes.Object<Include & {
|
|
16
|
+
content: true;
|
|
17
|
+
json: true;
|
|
18
|
+
}> & {
|
|
19
|
+
json: BcsStruct<T>['$inferType'];
|
|
20
|
+
}>;
|
|
21
|
+
getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
|
|
22
|
+
client,
|
|
23
|
+
...options
|
|
24
|
+
}: GetManyOptions<Include>): Promise<Array<SuiClientTypes.Object<Include & {
|
|
25
|
+
content: true;
|
|
26
|
+
json: true;
|
|
27
|
+
}> & {
|
|
28
|
+
json: BcsStruct<T>['$inferType'];
|
|
29
|
+
}>>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { MoveStruct };
|
|
33
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/contracts/utils/index.ts"],"mappings":";;;;KAqBY,UAAA,iBACK,IAAA,CAAK,cAAA,CAAe,aAAA,qBACjC,cAAA,CAAe,gBAAA,CAAiB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAE7C,cAAA,iBACK,IAAA,CAAK,cAAA,CAAe,aAAA,qBACjC,cAAA,CAAe,iBAAA,CAAkB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,cA8I7C,UAAA,WACF,MAAA,SAAe,OAAA,oDAEhB,SAAA,CAAU,CAAA,EAAG,IAAA;EAChB,GAAA,iBACW,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IAEpC,QAAA;IAAA,GACG;EAAA,GACD,UAAA,CAAW,OAAA,IAAW,OAAA,CACxB,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;EAeZ,OAAA,iBACW,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IAEpC,MAAA;IAAA,GACG;EAAA,GACD,cAAA,CAAe,OAAA,IAAW,OAAA,CAC5B,KAAA,CACC,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
2
|
+
import { BcsStruct, TypeTagSerializer, bcs } from "@mysten/sui/bcs";
|
|
3
|
+
import { isArgument } from "@mysten/sui/transactions";
|
|
4
|
+
//#region src/contracts/utils/index.ts
|
|
5
|
+
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
|
|
6
|
+
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
|
|
7
|
+
function getPureBcsSchema(typeTag) {
|
|
8
|
+
const parsedTag = typeof typeTag === "string" ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
9
|
+
if ("u8" in parsedTag) return bcs.U8;
|
|
10
|
+
else if ("u16" in parsedTag) return bcs.U16;
|
|
11
|
+
else if ("u32" in parsedTag) return bcs.U32;
|
|
12
|
+
else if ("u64" in parsedTag) return bcs.U64;
|
|
13
|
+
else if ("u128" in parsedTag) return bcs.U128;
|
|
14
|
+
else if ("u256" in parsedTag) return bcs.U256;
|
|
15
|
+
else if ("address" in parsedTag) return bcs.Address;
|
|
16
|
+
else if ("bool" in parsedTag) return bcs.Bool;
|
|
17
|
+
else if ("vector" in parsedTag) {
|
|
18
|
+
const type = getPureBcsSchema(parsedTag.vector);
|
|
19
|
+
return type ? bcs.vector(type) : null;
|
|
20
|
+
} else if ("struct" in parsedTag) {
|
|
21
|
+
const structTag = parsedTag.struct;
|
|
22
|
+
const pkg = normalizeSuiAddress(structTag.address);
|
|
23
|
+
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
24
|
+
if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") return bcs.String;
|
|
25
|
+
if (structTag.module === "option" && structTag.name === "Option") {
|
|
26
|
+
const inner = structTag.typeParams[0];
|
|
27
|
+
const type = inner ? getPureBcsSchema(inner) : null;
|
|
28
|
+
return type ? bcs.option(type) : null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === "object" && (structTag.name === "ID" || structTag.name === "UID")) return bcs.Address;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
36
|
+
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
37
|
+
if (parameterNames && argLen !== parameterNames.length) throw new Error(`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`);
|
|
38
|
+
const normalizedArgs = [];
|
|
39
|
+
let index = 0;
|
|
40
|
+
for (const argType of argTypes) {
|
|
41
|
+
if (argType === "0x2::clock::Clock") {
|
|
42
|
+
normalizedArgs.push((tx) => tx.object.clock());
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (argType === "0x2::random::Random") {
|
|
46
|
+
normalizedArgs.push((tx) => tx.object.random());
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (argType === "0x2::deny_list::DenyList") {
|
|
50
|
+
normalizedArgs.push((tx) => tx.object.denyList());
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (argType === "0x3::sui_system::SuiSystemState") {
|
|
54
|
+
normalizedArgs.push((tx) => tx.object.system());
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
let arg;
|
|
58
|
+
if (Array.isArray(args)) {
|
|
59
|
+
if (index >= args.length) throw new Error(`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`);
|
|
60
|
+
arg = args[index];
|
|
61
|
+
} else {
|
|
62
|
+
if (!parameterNames) throw new Error(`Expected arguments to be passed as an array`);
|
|
63
|
+
const name = parameterNames[index];
|
|
64
|
+
arg = args[name];
|
|
65
|
+
if (arg === void 0) throw new Error(`Parameter ${name} is required`);
|
|
66
|
+
}
|
|
67
|
+
index += 1;
|
|
68
|
+
if (typeof arg === "function" || isArgument(arg)) {
|
|
69
|
+
normalizedArgs.push(arg);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const bcsType = argType === null ? null : getPureBcsSchema(argType);
|
|
73
|
+
if (bcsType) {
|
|
74
|
+
const bytes = bcsType.serialize(arg);
|
|
75
|
+
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (typeof arg === "string") {
|
|
79
|
+
normalizedArgs.push((tx) => tx.object(arg));
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
|
|
83
|
+
}
|
|
84
|
+
return normalizedArgs;
|
|
85
|
+
}
|
|
86
|
+
var MoveStruct = class extends BcsStruct {
|
|
87
|
+
async get({ objectId, ...options }) {
|
|
88
|
+
const [res] = await this.getMany({
|
|
89
|
+
...options,
|
|
90
|
+
objectIds: [objectId]
|
|
91
|
+
});
|
|
92
|
+
if (!res) throw new Error(`No object found for id ${objectId}`);
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
async getMany({ client, ...options }) {
|
|
96
|
+
return (await client.core.getObjects({
|
|
97
|
+
...options,
|
|
98
|
+
include: {
|
|
99
|
+
...options.include,
|
|
100
|
+
content: true
|
|
101
|
+
}
|
|
102
|
+
})).objects.map((obj) => {
|
|
103
|
+
if (obj instanceof Error) throw obj;
|
|
104
|
+
return {
|
|
105
|
+
...obj,
|
|
106
|
+
json: this.parse(obj.content)
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function stringify(val) {
|
|
112
|
+
if (typeof val === "object") return JSON.stringify(val, (val) => val);
|
|
113
|
+
if (typeof val === "bigint") return val.toString();
|
|
114
|
+
return val;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { MoveStruct, normalizeMoveArguments };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\tBcsEnum,\n\tBcsStruct,\n\tBcsTuple,\n\tTypeTagSerializer,\n\ttype BcsType,\n\ttype TypeTag,\n} from '@mysten/sui/bcs';\nimport {\n\ttype ClientWithCoreApi,\n\ttype SuiClientTypes,\n} from '@mysten/sui/client';\nimport { isArgument, type TransactionArgument } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<\n\tInclude extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},\n> = SuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<\n\tInclude extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},\n> = SuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(\n\ttypeTag: string | TypeTag,\n): BcsType<any> | null {\n\tconst parsedTag =\n\t\ttypeof typeTag === 'string'\n\t\t\t? TypeTagSerializer.parseFromStr(typeTag)\n\t\t\t: typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\tasync get<\n\t\tInclude extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {},\n\t>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<\n\t\tInclude extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {},\n\t>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MoveStruct } from "../../../utils/index.mjs";
|
|
2
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
3
|
+
//#region src/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts
|
|
4
|
+
/**************************************************************
|
|
5
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
6
|
+
**************************************************************/
|
|
7
|
+
const $moduleName = "0x2::vec_map";
|
|
8
|
+
function Entry(...typeParameters) {
|
|
9
|
+
return new MoveStruct({
|
|
10
|
+
name: `${$moduleName}::Entry<${typeParameters[0].name}, ${typeParameters[1].name}>`,
|
|
11
|
+
fields: {
|
|
12
|
+
key: typeParameters[0],
|
|
13
|
+
value: typeParameters[1]
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function VecMap(...typeParameters) {
|
|
18
|
+
return new MoveStruct({
|
|
19
|
+
name: `${$moduleName}::VecMap<${typeParameters[0].name}, ${typeParameters[1].name}>`,
|
|
20
|
+
fields: { contents: bcs.vector(Entry(typeParameters[0], typeParameters[1])) }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { VecMap };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=vec_map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vec_map.mjs","names":[],"sources":["../../../../../src/contracts/wheel/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { bcs, type BcsType } from '@mysten/sui/bcs';\nimport { MoveStruct } from '../../../utils/index.js';\n\nconst $moduleName = '0x2::vec_map';\nexport function Entry<T0 extends BcsType<any>, T1 extends BcsType<any>>(\n\t...typeParameters: [T0, T1]\n) {\n\treturn new MoveStruct({\n\t\tname: `${$moduleName}::Entry<${typeParameters[0].name as T0['name']}, ${typeParameters[1].name as T1['name']}>`,\n\t\tfields: {\n\t\t\tkey: typeParameters[0],\n\t\t\tvalue: typeParameters[1],\n\t\t},\n\t});\n}\nexport function VecMap<T0 extends BcsType<any>, T1 extends BcsType<any>>(\n\t...typeParameters: [T0, T1]\n) {\n\treturn new MoveStruct({\n\t\tname: `${$moduleName}::VecMap<${typeParameters[0].name as T0['name']}, ${typeParameters[1].name as T1['name']}>`,\n\t\tfields: {\n\t\t\tcontents: bcs.vector(Entry(typeParameters[0], typeParameters[1])),\n\t\t},\n\t});\n}\n"],"mappings":";;;;;;AAMA,MAAM,cAAc;AACpB,SAAgB,MACf,GAAG,gBACF;CACD,OAAO,IAAI,WAAW;EACrB,MAAM,GAAG,YAAY,UAAU,eAAe,GAAG,KAAmB,IAAI,eAAe,GAAG,KAAmB;EAC7G,QAAQ;GACP,KAAK,eAAe;GACpB,OAAO,eAAe;GACtB;EACD,CAAC;;AAEH,SAAgB,OACf,GAAG,gBACF;CACD,OAAO,IAAI,WAAW;EACrB,MAAM,GAAG,YAAY,WAAW,eAAe,GAAG,KAAmB,IAAI,eAAe,GAAG,KAAmB;EAC9G,QAAQ,EACP,UAAU,IAAI,OAAO,MAAM,eAAe,IAAI,eAAe,GAAG,CAAC,EACjE;EACD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MoveStruct } from "../../../utils/index.mjs";
|
|
2
|
+
import { I64 } from "./i64.mjs";
|
|
3
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
4
|
+
const Float = new MoveStruct({
|
|
5
|
+
name: `0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float::Float`,
|
|
6
|
+
fields: {
|
|
7
|
+
is_negative: bcs.bool(),
|
|
8
|
+
exp: I64,
|
|
9
|
+
mant: bcs.u64()
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Float };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=float.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"float.mjs","names":["i64.I64"],"sources":["../../../../../src/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { bcs } from '@mysten/sui/bcs';\nimport { MoveStruct } from '../../../utils/index.js';\nimport * as i64 from './i64.js';\n\nconst $moduleName =\n\t'0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::float';\nexport const Float = new MoveStruct({\n\tname: `${$moduleName}::Float`,\n\tfields: {\n\t\tis_negative: bcs.bool(),\n\t\texp: i64.I64,\n\t\tmant: bcs.u64(),\n\t},\n});\n"],"mappings":";;;AASA,MAAa,QAAQ,IAAI,WAAW;CACnC,MAAM;CACN,QAAQ;EACP,aAAa,IAAI,MAAM;EACvB,KAAKA;EACL,MAAM,IAAI,KAAK;EACf;CACD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MoveStruct } from "../../../utils/index.mjs";
|
|
2
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
3
|
+
const I64 = new MoveStruct({
|
|
4
|
+
name: `0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64::I64`,
|
|
5
|
+
fields: { bits: bcs.u64() }
|
|
6
|
+
});
|
|
7
|
+
//#endregion
|
|
8
|
+
export { I64 };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=i64.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i64.mjs","names":[],"sources":["../../../../../src/contracts/wheel/deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/i64.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { bcs } from '@mysten/sui/bcs';\nimport { MoveStruct } from '../../../utils/index.js';\n\nconst $moduleName =\n\t'0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc::i64';\nexport const I64 = new MoveStruct({\n\tname: `${$moduleName}::I64`,\n\tfields: {\n\t\tbits: bcs.u64(),\n\t},\n});\n"],"mappings":";;AAQA,MAAa,MAAM,IAAI,WAAW;CACjC,MAAM;CACN,QAAQ,EACP,MAAM,IAAI,KAAK,EACf;CACD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { MoveStruct, normalizeMoveArguments } from "../utils/index.mjs";
|
|
2
|
+
import { VecMap } from "./deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.mjs";
|
|
3
|
+
import { Float } from "./deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.mjs";
|
|
4
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
5
|
+
//#region src/contracts/wheel/wheel.ts
|
|
6
|
+
/**************************************************************
|
|
7
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
8
|
+
**************************************************************/
|
|
9
|
+
const $moduleName = "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7::wheel";
|
|
10
|
+
const WheelSettingsKey = new MoveStruct({
|
|
11
|
+
name: `${$moduleName}::WheelSettingsKey`,
|
|
12
|
+
fields: { dummy_field: bcs.bool() }
|
|
13
|
+
});
|
|
14
|
+
const WheelConfig = new MoveStruct({
|
|
15
|
+
name: `${$moduleName}::WheelConfig`,
|
|
16
|
+
fields: {
|
|
17
|
+
num_cases: bcs.u8(),
|
|
18
|
+
multipliers: bcs.vector(Float),
|
|
19
|
+
min_stake: bcs.u64(),
|
|
20
|
+
max_stake: bcs.u64(),
|
|
21
|
+
is_playable: bcs.bool()
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const Parameters = new MoveStruct({
|
|
25
|
+
name: `${$moduleName}::Parameters<phantom T0>`,
|
|
26
|
+
fields: {
|
|
27
|
+
id: bcs.Address,
|
|
28
|
+
min_stake: bcs.u64(),
|
|
29
|
+
max_stake: bcs.u64(),
|
|
30
|
+
max_number_of_spins: bcs.u64(),
|
|
31
|
+
configs: VecMap(bcs.u8(), WheelConfig)
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
function play(options) {
|
|
35
|
+
const packageAddress = options.package ?? "0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7";
|
|
36
|
+
const argumentsTypes = [
|
|
37
|
+
null,
|
|
38
|
+
"u64",
|
|
39
|
+
null,
|
|
40
|
+
"u64",
|
|
41
|
+
"u8",
|
|
42
|
+
"vector<0x1::string::String>",
|
|
43
|
+
"vector<vector<u8>>",
|
|
44
|
+
null,
|
|
45
|
+
"0x2::clock::Clock",
|
|
46
|
+
"0x2::random::Random"
|
|
47
|
+
];
|
|
48
|
+
return (tx) => tx.moveCall({
|
|
49
|
+
package: packageAddress,
|
|
50
|
+
module: "wheel",
|
|
51
|
+
function: "play",
|
|
52
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
|
|
53
|
+
typeArguments: options.typeArguments
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Parameters, WheelSettingsKey, play };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=wheel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wheel.mjs","names":["float.Float","vec_map.VecMap"],"sources":["../../../src/contracts/wheel/wheel.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport { bcs } from '@mysten/sui/bcs';\nimport { type Transaction } from '@mysten/sui/transactions';\nimport {\n\tMoveStruct,\n\tnormalizeMoveArguments,\n\ttype RawTransactionArgument,\n} from '../utils/index.js';\nimport * as vec_map from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js';\nimport * as float from './deps/0xf391858d2a08473e8d4defcc8df89976bd7b123d3865c6b9341b237f7853dbbc/float.js';\n\nconst $moduleName =\n\t'0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7::wheel';\nexport const WheelSettingsKey = new MoveStruct({\n\tname: `${$moduleName}::WheelSettingsKey`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const WheelConfig = new MoveStruct({\n\tname: `${$moduleName}::WheelConfig`,\n\tfields: {\n\t\tnum_cases: bcs.u8(),\n\t\tmultipliers: bcs.vector(float.Float),\n\t\tmin_stake: bcs.u64(),\n\t\tmax_stake: bcs.u64(),\n\t\tis_playable: bcs.bool(),\n\t},\n});\nexport const Parameters = new MoveStruct({\n\tname: `${$moduleName}::Parameters<phantom T0>`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\tmin_stake: bcs.u64(),\n\t\tmax_stake: bcs.u64(),\n\t\tmax_number_of_spins: bcs.u64(),\n\t\tconfigs: vec_map.VecMap(bcs.u8(), WheelConfig),\n\t},\n});\nexport interface PlayOptions {\n\tpackage?: string;\n\targuments: [\n\t\tRawTransactionArgument<string>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<string>,\n\t\tRawTransactionArgument<number | bigint>,\n\t\tRawTransactionArgument<number>,\n\t\tRawTransactionArgument<Array<string>>,\n\t\tRawTransactionArgument<Array<Array<number>>>,\n\t\tRawTransactionArgument<string>,\n\t];\n\ttypeArguments: [string];\n}\nexport function play(options: PlayOptions) {\n\tconst packageAddress =\n\t\toptions.package ??\n\t\t'0x0997852ded7e13301c42317004bc49704a893aa82997c5706cebee59053a31b7';\n\tconst argumentsTypes = [\n\t\tnull,\n\t\t'u64',\n\t\tnull,\n\t\t'u64',\n\t\t'u8',\n\t\t'vector<0x1::string::String>',\n\t\t'vector<vector<u8>>',\n\t\tnull,\n\t\t'0x2::clock::Clock',\n\t\t'0x2::random::Random',\n\t] satisfies (string | null)[];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'wheel',\n\t\t\tfunction: 'play',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,cACL;AACD,MAAa,mBAAmB,IAAI,WAAW;CAC9C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,cAAc,IAAI,WAAW;CACzC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,WAAW,IAAI,IAAI;EACnB,aAAa,IAAI,OAAOA,MAAY;EACpC,WAAW,IAAI,KAAK;EACpB,WAAW,IAAI,KAAK;EACpB,aAAa,IAAI,MAAM;EACvB;CACD,CAAC;AACF,MAAa,aAAa,IAAI,WAAW;CACxC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EACR,WAAW,IAAI,KAAK;EACpB,WAAW,IAAI,KAAK;EACpB,qBAAqB,IAAI,KAAK;EAC9B,SAASC,OAAe,IAAI,IAAI,EAAE,YAAY;EAC9C;CACD,CAAC;AAeF,SAAgB,KAAK,SAAsB;CAC1C,MAAM,iBACL,QAAQ,WACR;CACD,MAAM,iBAAiB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,QAAQ,OACP,GAAG,SAAS;EACX,SAAS;EACT,QAAQ;EACR,UAAU;EACV,WAAW,uBAAuB,QAAQ,WAAW,eAAe;EACpE,eAAe,QAAQ;EACvB,CAAC"}
|
package/dist/games.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CoinSide } from "./types/game.type.mjs";
|
|
2
|
+
import { BuildCancelPvPCoinflipTransactionOptions, BuildCoinflipTransactionOptions, BuildCreatePvPCoinflipTransactionOptions, BuildJoinPvPCoinflipTransactionOptions, BuildLimboTransactionOptions, BuildPlinkoTransactionOptions, BuildRangeTransactionOptions, BuildWheelTransactionOptions, PvPCoinflipAction } from "./types/transaction-options.type.mjs";
|
|
3
|
+
export { type BuildCancelPvPCoinflipTransactionOptions, type BuildCoinflipTransactionOptions, type BuildCreatePvPCoinflipTransactionOptions, type BuildJoinPvPCoinflipTransactionOptions, type BuildLimboTransactionOptions, type BuildPlinkoTransactionOptions, type BuildRangeTransactionOptions, type BuildWheelTransactionOptions, type CoinSide, type PvPCoinflipAction };
|
package/dist/games.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { COIN_TYPES, PACKAGE_IDS, PRICE_INFO_OBJECT_IDS } from "../configs/package.mjs";
|
|
2
|
+
import { REGISTRY_IDS } from "../configs/registry.mjs";
|
|
3
|
+
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
4
|
+
//#region src/helpers/config.ts
|
|
5
|
+
const DEFAULT_CACHE_TTL_MS = 1800 * 1e3;
|
|
6
|
+
function resolveSuigarConfig(network) {
|
|
7
|
+
const packageIds = PACKAGE_IDS[network];
|
|
8
|
+
const registryIds = REGISTRY_IDS[network];
|
|
9
|
+
const coinTypes = COIN_TYPES[network];
|
|
10
|
+
const priceInfoObjectIds = PRICE_INFO_OBJECT_IDS[network];
|
|
11
|
+
return {
|
|
12
|
+
packageIds: { ...packageIds },
|
|
13
|
+
registryIds: { ...registryIds },
|
|
14
|
+
coinTypes: {
|
|
15
|
+
sui: normalizeStructTag(coinTypes.sui),
|
|
16
|
+
usdc: normalizeStructTag(coinTypes.usdc)
|
|
17
|
+
},
|
|
18
|
+
priceInfoObjectIds: {
|
|
19
|
+
sui: priceInfoObjectIds.sui,
|
|
20
|
+
usdc: priceInfoObjectIds.usdc
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function assertConfiguredBetGame(config, game) {
|
|
25
|
+
if (!resolveGamePackageId(config, game)) throw new Error(`Missing required config for ${game}: packageIds.${game}`);
|
|
26
|
+
}
|
|
27
|
+
function resolveGamePackageId(config, game) {
|
|
28
|
+
switch (game) {
|
|
29
|
+
case "coinflip": return config.packageIds.coinflip;
|
|
30
|
+
case "limbo": return config.packageIds.limbo;
|
|
31
|
+
case "plinko": return config.packageIds.plinko;
|
|
32
|
+
case "pvp-coinflip": return config.packageIds.pvpCoinflip;
|
|
33
|
+
case "range": return config.packageIds.range;
|
|
34
|
+
case "wheel": return config.packageIds.wheel;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function resolvePriceInfoObjectId(config, coinType) {
|
|
38
|
+
const supportedCoin = resolveSupportedCoin(config, normalizeStructTag(coinType));
|
|
39
|
+
const objectId = config.priceInfoObjectIds[supportedCoin];
|
|
40
|
+
if (!objectId) throw new Error(`Missing price info object configuration for coin type ${coinType}`);
|
|
41
|
+
return objectId;
|
|
42
|
+
}
|
|
43
|
+
function resolveSupportedCoin(config, coinType) {
|
|
44
|
+
const [supportedCoin] = Object.entries(config.coinTypes).find(([_, value]) => value === coinType) ?? [];
|
|
45
|
+
if (!supportedCoin) throw new RangeError(`Unsupported coin type ${coinType}. Supported coin types: ${Object.values(config.coinTypes).join(", ")}`);
|
|
46
|
+
return supportedCoin;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { DEFAULT_CACHE_TTL_MS, assertConfiguredBetGame, resolveGamePackageId, resolvePriceInfoObjectId, resolveSuigarConfig };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/helpers/config.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport { normalizeStructTag } from '@mysten/sui/utils';\nimport {\n\tCOIN_TYPES,\n\tPACKAGE_IDS,\n\tPRICE_INFO_OBJECT_IDS,\n\tREGISTRY_IDS,\n} from '../configs/index.js';\nimport type { Game, SuigarCoin, SuigarConfig, SuiNetwork } from '../types';\n\nexport const DEFAULT_CACHE_TTL_MS = 30 * 60 * 1000;\n\nexport function resolveSuigarConfig(network: SuiNetwork): SuigarConfig {\n\tconst packageIds = PACKAGE_IDS[network];\n\tconst registryIds = REGISTRY_IDS[network];\n\tconst coinTypes = COIN_TYPES[network];\n\tconst priceInfoObjectIds = PRICE_INFO_OBJECT_IDS[network];\n\n\treturn {\n\t\tpackageIds: { ...packageIds },\n\t\tregistryIds: { ...registryIds },\n\t\tcoinTypes: {\n\t\t\tsui: normalizeStructTag(coinTypes.sui),\n\t\t\tusdc: normalizeStructTag(coinTypes.usdc),\n\t\t},\n\t\tpriceInfoObjectIds: {\n\t\t\tsui: priceInfoObjectIds.sui,\n\t\t\tusdc: priceInfoObjectIds.usdc,\n\t\t},\n\t};\n}\n\nexport function assertConfiguredBetGame(\n\tconfig: SuigarConfig,\n\tgame: Game,\n): void {\n\tif (!resolveGamePackageId(config, game)) {\n\t\tthrow new Error(`Missing required config for ${game}: packageIds.${game}`);\n\t}\n}\n\nexport function resolveGamePackageId(config: SuigarConfig, game: Game): string {\n\tswitch (game) {\n\t\tcase 'coinflip':\n\t\t\treturn config.packageIds.coinflip;\n\t\tcase 'limbo':\n\t\t\treturn config.packageIds.limbo;\n\t\tcase 'plinko':\n\t\t\treturn config.packageIds.plinko;\n\t\tcase 'pvp-coinflip':\n\t\t\treturn config.packageIds.pvpCoinflip;\n\t\tcase 'range':\n\t\t\treturn config.packageIds.range;\n\t\tcase 'wheel':\n\t\t\treturn config.packageIds.wheel;\n\t}\n}\n\nexport function resolvePriceInfoObjectId(\n\tconfig: SuigarConfig,\n\tcoinType: string,\n): string {\n\tconst normalizedCoinType = normalizeStructTag(coinType);\n\tconst supportedCoin = resolveSupportedCoin(config, normalizedCoinType);\n\tconst objectId = config.priceInfoObjectIds[supportedCoin];\n\n\tif (!objectId) {\n\t\tthrow new Error(\n\t\t\t`Missing price info object configuration for coin type ${coinType}`,\n\t\t);\n\t}\n\n\treturn objectId;\n}\n\nfunction resolveSupportedCoin(\n\tconfig: SuigarConfig,\n\tcoinType: string,\n): SuigarCoin {\n\tconst [supportedCoin] =\n\t\tObject.entries(config.coinTypes).find(([_, value]) => value === coinType) ??\n\t\t[];\n\n\tif (!supportedCoin) {\n\t\tthrow new RangeError(\n\t\t\t`Unsupported coin type ${coinType}. Supported coin types: ${Object.values(\n\t\t\t\tconfig.coinTypes,\n\t\t\t).join(', ')}`,\n\t\t);\n\t}\n\n\treturn supportedCoin as SuigarCoin;\n}\n"],"mappings":";;;;AAYA,MAAa,uBAAuB,OAAU;AAE9C,SAAgB,oBAAoB,SAAmC;CACtE,MAAM,aAAa,YAAY;CAC/B,MAAM,cAAc,aAAa;CACjC,MAAM,YAAY,WAAW;CAC7B,MAAM,qBAAqB,sBAAsB;CAEjD,OAAO;EACN,YAAY,EAAE,GAAG,YAAY;EAC7B,aAAa,EAAE,GAAG,aAAa;EAC/B,WAAW;GACV,KAAK,mBAAmB,UAAU,IAAI;GACtC,MAAM,mBAAmB,UAAU,KAAK;GACxC;EACD,oBAAoB;GACnB,KAAK,mBAAmB;GACxB,MAAM,mBAAmB;GACzB;EACD;;AAGF,SAAgB,wBACf,QACA,MACO;CACP,IAAI,CAAC,qBAAqB,QAAQ,KAAK,EACtC,MAAM,IAAI,MAAM,+BAA+B,KAAK,eAAe,OAAO;;AAI5E,SAAgB,qBAAqB,QAAsB,MAAoB;CAC9E,QAAQ,MAAR;EACC,KAAK,YACJ,OAAO,OAAO,WAAW;EAC1B,KAAK,SACJ,OAAO,OAAO,WAAW;EAC1B,KAAK,UACJ,OAAO,OAAO,WAAW;EAC1B,KAAK,gBACJ,OAAO,OAAO,WAAW;EAC1B,KAAK,SACJ,OAAO,OAAO,WAAW;EAC1B,KAAK,SACJ,OAAO,OAAO,WAAW;;;AAI5B,SAAgB,yBACf,QACA,UACS;CAET,MAAM,gBAAgB,qBAAqB,QADhB,mBAAmB,SACuB,CAAC;CACtE,MAAM,WAAW,OAAO,mBAAmB;CAE3C,IAAI,CAAC,UACJ,MAAM,IAAI,MACT,yDAAyD,WACzD;CAGF,OAAO;;AAGR,SAAS,qBACR,QACA,UACa;CACb,MAAM,CAAC,iBACN,OAAO,QAAQ,OAAO,UAAU,CAAC,MAAM,CAAC,GAAG,WAAW,UAAU,SAAS,IACzE,EAAE;CAEH,IAAI,CAAC,eACJ,MAAM,IAAI,WACT,yBAAyB,SAAS,0BAA0B,OAAO,OAClE,OAAO,UACP,CAAC,KAAK,KAAK,GACZ;CAGF,OAAO"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from "@mysten/sui/utils";
|
|
2
|
+
//#region src/helpers/game-settings.ts
|
|
3
|
+
function replaceStructTagAddress(structName, address) {
|
|
4
|
+
return normalizeStructTag({
|
|
5
|
+
...parseStructTag(structName),
|
|
6
|
+
address
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function resolveGameSettingsKeyType(structName, packageId) {
|
|
10
|
+
return replaceStructTagAddress(structName, packageId);
|
|
11
|
+
}
|
|
12
|
+
function resolveCoinTypeNameForTypeNameKey(structName) {
|
|
13
|
+
const { address } = parseStructTag(structName);
|
|
14
|
+
return replaceStructTagAddress(structName, normalizeSuiAddress(address).replace(/^0x/, ""));
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { resolveCoinTypeNameForTypeNameKey, resolveGameSettingsKeyType };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=game-settings.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game-settings.mjs","names":[],"sources":["../../src/helpers/game-settings.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n} from '@mysten/sui/utils';\n\nfunction replaceStructTagAddress(structName: string, address: string): string {\n\treturn normalizeStructTag({\n\t\t...parseStructTag(structName),\n\t\taddress,\n\t});\n}\n\nexport function resolveGameSettingsKeyType(\n\tstructName: string,\n\tpackageId: string,\n): string {\n\treturn replaceStructTagAddress(structName, packageId);\n}\n\nexport function resolveCoinTypeNameForTypeNameKey(structName: string): string {\n\tconst { address } = parseStructTag(structName);\n\n\treturn replaceStructTagAddress(\n\t\tstructName,\n\t\tnormalizeSuiAddress(address).replace(/^0x/, ''),\n\t);\n}\n"],"mappings":";;AASA,SAAS,wBAAwB,YAAoB,SAAyB;CAC7E,OAAO,mBAAmB;EACzB,GAAG,eAAe,WAAW;EAC7B;EACA,CAAC;;AAGH,SAAgB,2BACf,YACA,WACS;CACT,OAAO,wBAAwB,YAAY,UAAU;;AAGtD,SAAgB,kCAAkC,YAA4B;CAC7E,MAAM,EAAE,YAAY,eAAe,WAAW;CAE9C,OAAO,wBACN,YACA,oBAAoB,QAAQ,CAAC,QAAQ,OAAO,GAAG,CAC/C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { fromHex } from "@mysten/sui/utils";
|
|
2
|
+
//#region src/helpers/metadata.ts
|
|
3
|
+
const PARTNER_METADATA_KEY = "partner";
|
|
4
|
+
const RESERVED_METADATA_KEYS = new Set([PARTNER_METADATA_KEY, "referrer"]);
|
|
5
|
+
const textEncoder = new TextEncoder();
|
|
6
|
+
function encodeString(value) {
|
|
7
|
+
try {
|
|
8
|
+
return fromHex(value);
|
|
9
|
+
} catch {
|
|
10
|
+
return textEncoder.encode(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function encodeMetadataValue(value) {
|
|
14
|
+
if (value instanceof Uint8Array) return Array.from(value);
|
|
15
|
+
if (Array.isArray(value)) return value;
|
|
16
|
+
return Array.from(encodeString(String(value)));
|
|
17
|
+
}
|
|
18
|
+
function encodeBetMetadata(metadata, partner) {
|
|
19
|
+
const keys = [];
|
|
20
|
+
const values = [];
|
|
21
|
+
for (const [key, value] of Object.entries(metadata ?? {})) {
|
|
22
|
+
if (RESERVED_METADATA_KEYS.has(key)) {
|
|
23
|
+
console.warn(`Metadata key "${key}" is reserved and will be ignored when parsing metadata.`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (value == null) continue;
|
|
27
|
+
keys.push(key);
|
|
28
|
+
values.push(encodeMetadataValue(value));
|
|
29
|
+
}
|
|
30
|
+
if (partner?.trim()) {
|
|
31
|
+
keys.unshift(PARTNER_METADATA_KEY);
|
|
32
|
+
values.unshift(encodeMetadataValue(partner));
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
keys,
|
|
36
|
+
values
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { encodeBetMetadata };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=metadata.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.mjs","names":[],"sources":["../../src/helpers/metadata.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/sui/utils';\nimport type {\n\tBetMetadataInput,\n\tBetMetadataValue,\n\tEncodedBetMetadata,\n} from '../types';\n\nconst PARTNER_METADATA_KEY = 'partner';\n\nconst RESERVED_METADATA_KEYS = new Set([PARTNER_METADATA_KEY, 'referrer']);\nconst textEncoder = new TextEncoder();\n\nfunction encodeString(value: string) {\n\ttry {\n\t\treturn fromHex(value);\n\t} catch {\n\t\treturn textEncoder.encode(value);\n\t}\n}\n\nfunction encodeMetadataValue(value: BetMetadataValue) {\n\tif (value instanceof Uint8Array) {\n\t\treturn Array.from(value);\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value;\n\t}\n\n\treturn Array.from(encodeString(String(value)));\n}\n\nexport function encodeBetMetadata(\n\tmetadata?: BetMetadataInput,\n\tpartner?: string,\n): EncodedBetMetadata {\n\tconst keys: string[] = [];\n\tconst values: number[][] = [];\n\n\tfor (const [key, value] of Object.entries(metadata ?? {})) {\n\t\tif (RESERVED_METADATA_KEYS.has(key)) {\n\t\t\tconsole.warn(\n\t\t\t\t`Metadata key \"${key}\" is reserved and will be ignored when parsing metadata.`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (value == null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tkeys.push(key);\n\t\tvalues.push(encodeMetadataValue(value));\n\t}\n\n\tif (partner?.trim()) {\n\t\tkeys.unshift(PARTNER_METADATA_KEY);\n\t\tvalues.unshift(encodeMetadataValue(partner));\n\t}\n\n\treturn {\n\t\tkeys,\n\t\tvalues,\n\t};\n}\n"],"mappings":";;AAUA,MAAM,uBAAuB;AAE7B,MAAM,yBAAyB,IAAI,IAAI,CAAC,sBAAsB,WAAW,CAAC;AAC1E,MAAM,cAAc,IAAI,aAAa;AAErC,SAAS,aAAa,OAAe;CACpC,IAAI;EACH,OAAO,QAAQ,MAAM;SACd;EACP,OAAO,YAAY,OAAO,MAAM;;;AAIlC,SAAS,oBAAoB,OAAyB;CACrD,IAAI,iBAAiB,YACpB,OAAO,MAAM,KAAK,MAAM;CAGzB,IAAI,MAAM,QAAQ,MAAM,EACvB,OAAO;CAGR,OAAO,MAAM,KAAK,aAAa,OAAO,MAAM,CAAC,CAAC;;AAG/C,SAAgB,kBACf,UACA,SACqB;CACrB,MAAM,OAAiB,EAAE;CACzB,MAAM,SAAqB,EAAE;CAE7B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,YAAY,EAAE,CAAC,EAAE;EAC1D,IAAI,uBAAuB,IAAI,IAAI,EAAE;GACpC,QAAQ,KACP,iBAAiB,IAAI,0DACrB;GACD;;EAGD,IAAI,SAAS,MACZ;EAGD,KAAK,KAAK,IAAI;EACd,OAAO,KAAK,oBAAoB,MAAM,CAAC;;CAGxC,IAAI,SAAS,MAAM,EAAE;EACpB,KAAK,QAAQ,qBAAqB;EAClC,OAAO,QAAQ,oBAAoB,QAAQ,CAAC;;CAG7C,OAAO;EACN;EACA;EACA"}
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { play } from "../contracts/coinflip/coinflip.mjs";
|
|
2
|
+
import { buildSharedStandardGameBetTransaction } from "./shared.mjs";
|
|
3
|
+
//#region src/transactions/coinflip.ts
|
|
4
|
+
function buildCoinflipTransaction(options) {
|
|
5
|
+
return buildSharedStandardGameBetTransaction({
|
|
6
|
+
...options,
|
|
7
|
+
game: "coinflip",
|
|
8
|
+
buildRewardCoin: ({ tx, config, coinType, stake, betCount, metadata, priceInfoObjectId, betCoin }) => play({
|
|
9
|
+
package: config.packageIds.coinflip,
|
|
10
|
+
typeArguments: [coinType],
|
|
11
|
+
arguments: [
|
|
12
|
+
config.packageIds.sweetHouse,
|
|
13
|
+
stake,
|
|
14
|
+
betCoin,
|
|
15
|
+
betCount,
|
|
16
|
+
options.side === "tails",
|
|
17
|
+
metadata.keys,
|
|
18
|
+
metadata.values,
|
|
19
|
+
priceInfoObjectId
|
|
20
|
+
]
|
|
21
|
+
})(tx)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { buildCoinflipTransaction };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=coinflip.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coinflip.mjs","names":[],"sources":["../../src/transactions/coinflip.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Transaction } from '@mysten/sui/transactions';\nimport { play } from '../contracts/coinflip/coinflip.js';\nimport type { BuildCoinflipTransactionOptions, WithPartner } from '../types';\nimport { buildSharedStandardGameBetTransaction } from './shared.js';\n\nexport function buildCoinflipTransaction(\n\toptions: WithPartner<BuildCoinflipTransactionOptions>,\n): Transaction {\n\treturn buildSharedStandardGameBetTransaction({\n\t\t...options,\n\t\tgame: 'coinflip',\n\t\tbuildRewardCoin: ({\n\t\t\ttx,\n\t\t\tconfig,\n\t\t\tcoinType,\n\t\t\tstake,\n\t\t\tbetCount,\n\t\t\tmetadata,\n\t\t\tpriceInfoObjectId,\n\t\t\tbetCoin,\n\t\t}) =>\n\t\t\tplay({\n\t\t\t\tpackage: config.packageIds.coinflip,\n\t\t\t\ttypeArguments: [coinType],\n\t\t\t\targuments: [\n\t\t\t\t\tconfig.packageIds.sweetHouse,\n\t\t\t\t\tstake,\n\t\t\t\t\tbetCoin,\n\t\t\t\t\tbetCount,\n\t\t\t\t\toptions.side === 'tails',\n\t\t\t\t\tmetadata.keys,\n\t\t\t\t\tmetadata.values,\n\t\t\t\t\tpriceInfoObjectId,\n\t\t\t\t],\n\t\t\t})(tx),\n\t});\n}\n"],"mappings":";;;AAQA,SAAgB,yBACf,SACc;CACd,OAAO,sCAAsC;EAC5C,GAAG;EACH,MAAM;EACN,kBAAkB,EACjB,IACA,QACA,UACA,OACA,UACA,UACA,mBACA,cAEA,KAAK;GACJ,SAAS,OAAO,WAAW;GAC3B,eAAe,CAAC,SAAS;GACzB,WAAW;IACV,OAAO,WAAW;IAClB;IACA;IACA;IACA,QAAQ,SAAS;IACjB,SAAS;IACT,SAAS;IACT;IACA;GACD,CAAC,CAAC,GAAG;EACP,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "../utils/constants.mjs";
|
|
2
|
+
import { buildSharedStandardGameBetTransaction } from "./shared.mjs";
|
|
3
|
+
import { play } from "../contracts/limbo/limbo.mjs";
|
|
4
|
+
//#region src/transactions/limbo.ts
|
|
5
|
+
function buildLimboTransaction(options) {
|
|
6
|
+
const scale = options.scale ?? 100;
|
|
7
|
+
const numerator = Math.round(options.targetMultiplier * scale);
|
|
8
|
+
return buildSharedStandardGameBetTransaction({
|
|
9
|
+
...options,
|
|
10
|
+
game: "limbo",
|
|
11
|
+
buildRewardCoin: ({ tx, config, coinType, stake, betCount, metadata, priceInfoObjectId, betCoin }) => play({
|
|
12
|
+
package: config.packageIds.limbo,
|
|
13
|
+
typeArguments: [coinType],
|
|
14
|
+
arguments: [
|
|
15
|
+
config.packageIds.sweetHouse,
|
|
16
|
+
stake,
|
|
17
|
+
betCoin,
|
|
18
|
+
betCount,
|
|
19
|
+
BigInt(numerator),
|
|
20
|
+
BigInt(scale),
|
|
21
|
+
metadata.keys,
|
|
22
|
+
metadata.values,
|
|
23
|
+
priceInfoObjectId
|
|
24
|
+
]
|
|
25
|
+
})(tx)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { buildLimboTransaction };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=limbo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limbo.mjs","names":[],"sources":["../../src/transactions/limbo.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Transaction } from '@mysten/sui/transactions';\nimport { play } from '../contracts/limbo/limbo.js';\nimport type { BuildLimboTransactionOptions, WithPartner } from '../types';\nimport { DEFAULT_LIMBO_MULTIPLIER_SCALE } from '../utils/index.js';\nimport { buildSharedStandardGameBetTransaction } from './shared.js';\n\nexport function buildLimboTransaction(\n\toptions: WithPartner<BuildLimboTransactionOptions>,\n): Transaction {\n\tconst scale = options.scale ?? DEFAULT_LIMBO_MULTIPLIER_SCALE;\n\tconst numerator = Math.round(options.targetMultiplier * scale);\n\n\treturn buildSharedStandardGameBetTransaction({\n\t\t...options,\n\t\tgame: 'limbo',\n\t\tbuildRewardCoin: ({\n\t\t\ttx,\n\t\t\tconfig,\n\t\t\tcoinType,\n\t\t\tstake,\n\t\t\tbetCount,\n\t\t\tmetadata,\n\t\t\tpriceInfoObjectId,\n\t\t\tbetCoin,\n\t\t}) =>\n\t\t\tplay({\n\t\t\t\tpackage: config.packageIds.limbo,\n\t\t\t\ttypeArguments: [coinType],\n\t\t\t\targuments: [\n\t\t\t\t\tconfig.packageIds.sweetHouse,\n\t\t\t\t\tstake,\n\t\t\t\t\tbetCoin,\n\t\t\t\t\tbetCount,\n\t\t\t\t\tBigInt(numerator),\n\t\t\t\t\tBigInt(scale),\n\t\t\t\t\tmetadata.keys,\n\t\t\t\t\tmetadata.values,\n\t\t\t\t\tpriceInfoObjectId,\n\t\t\t\t],\n\t\t\t})(tx),\n\t});\n}\n"],"mappings":";;;;AASA,SAAgB,sBACf,SACc;CACd,MAAM,QAAQ,QAAQ,SAAA;CACtB,MAAM,YAAY,KAAK,MAAM,QAAQ,mBAAmB,MAAM;CAE9D,OAAO,sCAAsC;EAC5C,GAAG;EACH,MAAM;EACN,kBAAkB,EACjB,IACA,QACA,UACA,OACA,UACA,UACA,mBACA,cAEA,KAAK;GACJ,SAAS,OAAO,WAAW;GAC3B,eAAe,CAAC,SAAS;GACzB,WAAW;IACV,OAAO,WAAW;IAClB;IACA;IACA;IACA,OAAO,UAAU;IACjB,OAAO,MAAM;IACb,SAAS;IACT,SAAS;IACT;IACA;GACD,CAAC,CAAC,GAAG;EACP,CAAC"}
|