@suigar/mcp 0.1.0 → 0.2.0-beta.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/CHANGELOG.md +37 -0
- package/LICENSE +201 -0
- package/README.md +79 -110
- package/dist/app/index.html +181 -0
- package/dist/bin.mjs +3 -7
- package/dist/bin.mjs.map +1 -0
- package/dist/client.d.mts +41 -11
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +107 -34
- package/dist/client.mjs.map +1 -0
- package/dist/dry-run.mjs +163 -0
- package/dist/dry-run.mjs.map +1 -0
- package/dist/format.mjs +24 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.d.mts +5 -9
- package/dist/index.mjs +4 -8
- package/dist/schemas.d.mts +642 -0
- package/dist/schemas.d.mts.map +1 -0
- package/dist/schemas.mjs +113 -0
- package/dist/schemas.mjs.map +1 -0
- package/dist/server.d.mts +21 -69
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +172 -411
- package/dist/server.mjs.map +1 -0
- package/dist/tools.d.mts +14 -155
- package/dist/tools.d.mts.map +1 -0
- package/dist/tools.mjs +297 -553
- package/dist/tools.mjs.map +1 -0
- package/dist/types.d.mts +109 -83
- package/dist/types.d.mts.map +1 -0
- package/package.json +83 -61
- package/dist/bin.cjs +0 -11
- package/dist/bin.d.cts +0 -1
- package/dist/client.cjs +0 -46
- package/dist/client.d.cts +0 -17
- package/dist/coin.cjs +0 -86
- package/dist/coin.d.cts +0 -35
- package/dist/coin.d.mts +0 -35
- package/dist/coin.mjs +0 -86
- package/dist/config.cjs +0 -183
- package/dist/config.d.cts +0 -15
- package/dist/config.d.mts +0 -15
- package/dist/config.mjs +0 -174
- package/dist/index.cjs +0 -53
- package/dist/index.d.cts +0 -10
- package/dist/mcp-support.cjs +0 -62
- package/dist/mcp-support.d.cts +0 -16
- package/dist/mcp-support.d.mts +0 -16
- package/dist/mcp-support.mjs +0 -60
- package/dist/metadata.cjs +0 -51
- package/dist/metadata.d.cts +0 -52
- package/dist/metadata.d.mts +0 -52
- package/dist/metadata.mjs +0 -47
- package/dist/server.cjs +0 -433
- package/dist/server.d.cts +0 -73
- package/dist/tools.cjs +0 -617
- package/dist/tools.d.cts +0 -158
- package/dist/transactions.cjs +0 -294
- package/dist/transactions.d.cts +0 -40
- package/dist/transactions.d.mts +0 -40
- package/dist/transactions.mjs +0 -286
- package/dist/types.d.cts +0 -111
- package/node_modules/@suigar/currency-registry/dist/index.cjs +0 -121
- package/node_modules/@suigar/currency-registry/dist/index.d.cts +0 -50
- package/node_modules/@suigar/currency-registry/dist/index.d.mts +0 -50
- package/node_modules/@suigar/currency-registry/dist/index.mjs +0 -110
- package/node_modules/@suigar/currency-registry/package.json +0 -31
- package/node_modules/@suigar/game-registry/dist/index.cjs +0 -310
- package/node_modules/@suigar/game-registry/dist/index.d.cts +0 -65
- package/node_modules/@suigar/game-registry/dist/index.d.mts +0 -65
- package/node_modules/@suigar/game-registry/dist/index.mjs +0 -292
- package/node_modules/@suigar/game-registry/package.json +0 -31
- package/node_modules/@suigar/sui-rpc-pool/dist/index.cjs +0 -45590
- package/node_modules/@suigar/sui-rpc-pool/dist/index.d.cts +0 -465
- package/node_modules/@suigar/sui-rpc-pool/dist/index.d.mts +0 -465
- package/node_modules/@suigar/sui-rpc-pool/dist/index.mjs +0 -45570
- package/node_modules/@suigar/sui-rpc-pool/package.json +0 -31
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.mjs","names":[],"sources":["../src/tools.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { GAMES } from '@suigar/sdk/games';\nimport type {\n\tCoinSide,\n\tGame,\n\tPvPCoinflipAction,\n\tStandardGame,\n} from '@suigar/sdk/games';\nimport {\n\tbuildTransactionResult,\n\tcreateSuigarClient,\n\tresolveDefaultCoinType,\n\tresolveOwnerAddress,\n} from './client.js';\nimport type { SuigarClientBundle } from './client.js';\nimport type {\n\tCoinflipInput,\n\tConfigIdInput,\n\tLimboInput,\n\tPvpCoinflipCancelInput,\n\tPvpCoinflipCreateInput,\n\tPvpCoinflipJoinInput,\n\tRangeInput,\n\tReadConfigInput,\n\tReadGameMetadataInput,\n} from './schemas.js';\nimport type {\n\tBuilderMode,\n\tJsonValue,\n\tReadConfigResult,\n\tReadGameMetadataResult,\n\tReadOnlyPlan,\n\tResolvedMcpConfig,\n\tToolTextResult,\n} from './types.js';\n\nconst GAME_LABELS = {\n\tcoinflip: 'Coinflip',\n\tlimbo: 'Limbo',\n\tplinko: 'Plinko',\n\trange: 'Range',\n\twheel: 'Wheel',\n\t'pvp-coinflip': 'PvP Coinflip',\n} as const satisfies Record<Game, string>;\n\nconst GAME_TO_PACKAGE_KEY = {\n\tcoinflip: 'coinflip',\n\tlimbo: 'limbo',\n\tplinko: 'plinko',\n\trange: 'range',\n\twheel: 'wheel',\n\t'pvp-coinflip': 'pvpCoinflip',\n} as const satisfies Record<Game, keyof ResolvedMcpConfig['sdk']['packageIds']>;\n\nconst GAME_TO_TOOLS = {\n\tcoinflip: ['build_coinflip_transaction'],\n\tlimbo: ['build_limbo_transaction'],\n\tplinko: ['build_plinko_transaction'],\n\trange: ['build_range_transaction'],\n\twheel: ['build_wheel_transaction'],\n\t'pvp-coinflip': [\n\t\t'build_pvp_coinflip_create_transaction',\n\t\t'build_pvp_coinflip_join_transaction',\n\t\t'build_pvp_coinflip_cancel_transaction',\n\t],\n} as const satisfies Record<Game, readonly string[]>;\n\nconst json = (value: unknown) =>\n\tJSON.stringify(\n\t\tvalue,\n\t\t(_key, item) => (typeof item === 'bigint' ? item.toString() : item),\n\t\t2,\n\t);\n\nconst asTextResponse = <T extends ToolTextResult['structuredContent']>(\n\tstructuredContent: T,\n): ToolTextResult => ({\n\tcontent: [{ type: 'text', text: json(structuredContent) }],\n\tstructuredContent,\n});\n\nconst currencyAmountPattern = /^(?:\\d+|\\d+\\.\\d+|\\.\\d+)$/u;\n\nconst coinMetadataForAmount = (\n\tconfig: ResolvedMcpConfig,\n\tcoinType?: string,\n) => {\n\tconst resolvedCoinType = resolveDefaultCoinType(config, coinType);\n\tconst coin = Object.values(config.sdk.coins).find(\n\t\t(metadata) =>\n\t\t\tresolveDefaultCoinType(config, metadata.coinType) === resolvedCoinType,\n\t);\n\n\tif (!coin) {\n\t\tthrow new RangeError(\n\t\t\t`Unable to resolve decimals for coin type ${resolvedCoinType}. Add the coin to config.coins before using currency-denominated amounts.`,\n\t\t);\n\t}\n\n\treturn {\n\t\tcoinType: resolvedCoinType,\n\t\tdecimals: coin.decimals,\n\t};\n};\n\nconst toCurrencyAmountText = (value: unknown, fieldName: string): string => {\n\tif (typeof value === 'number' && Number.isFinite(value) && value >= 0) {\n\t\treturn String(value);\n\t}\n\tif (typeof value === 'string' && currencyAmountPattern.test(value.trim())) {\n\t\treturn value.trim();\n\t}\n\tthrow new TypeError(\n\t\t`Missing or invalid ${fieldName}. Provide a non-negative currency amount such as 1, 2, or 1.5.`,\n\t);\n};\n\nconst toBaseUnits = (\n\tvalue: unknown,\n\tfieldName: string,\n\tdecimals: number,\n): bigint => {\n\tconst amount = toCurrencyAmountText(value, fieldName);\n\tconst [rawWhole, rawFraction = ''] = amount.split('.');\n\tconst whole = rawWhole === '' ? '0' : rawWhole;\n\tconst overflow = rawFraction.slice(decimals);\n\tif (/[^0]/u.test(overflow)) {\n\t\tthrow new RangeError(\n\t\t\t`${fieldName} has more fractional digits than the configured coin decimals (${decimals}).`,\n\t\t);\n\t}\n\tconst fraction = rawFraction.slice(0, decimals).padEnd(decimals, '0');\n\treturn BigInt(whole) * 10n ** BigInt(decimals) + BigInt(fraction || '0');\n};\n\nconst toPositiveInteger = (\n\tvalue: unknown,\n\tfieldName: string,\n): number | bigint => {\n\tif (typeof value === 'number' && Number.isSafeInteger(value) && value > 0) {\n\t\treturn value;\n\t}\n\tif (typeof value === 'string' && /^[1-9]\\d*$/u.test(value)) {\n\t\treturn BigInt(value);\n\t}\n\tthrow new TypeError(\n\t\t`Missing or invalid ${fieldName}. Provide a positive integer.`,\n\t);\n};\n\nconst requireString = (value: unknown, fieldName: string): string => {\n\tif (typeof value === 'string' && value.trim()) {\n\t\treturn value.trim();\n\t}\n\tthrow new TypeError(`Missing required field: ${fieldName}.`);\n};\n\nconst requireNumber = (value: unknown, fieldName: string): number => {\n\tif (typeof value === 'number' && Number.isFinite(value)) {\n\t\treturn value;\n\t}\n\tthrow new TypeError(`Missing or invalid numeric field: ${fieldName}.`);\n};\n\nconst getMode = (mode: BuilderMode | undefined): BuilderMode => mode ?? 'build';\n\nconst getConfigInput = (input: ReadConfigInput) => ({\n\tnetwork: input.network,\n\tproviderUrl: input.providerUrl,\n\tconfig: input.config,\n\tpartner: input.partner,\n});\n\nconst supportedGames = () =>\n\tGAMES.map((id) => ({\n\t\tid,\n\t\tlabel: GAME_LABELS[id],\n\t\ttools: [...GAME_TO_TOOLS[id]],\n\t}));\n\nconst getPackageId = (config: ResolvedMcpConfig, game: Game) =>\n\tconfig.sdk.packageIds[GAME_TO_PACKAGE_KEY[game]];\n\nconst getTarget = (\n\tconfig: ResolvedMcpConfig,\n\tgame: Game,\n\taction?: PvPCoinflipAction,\n) => {\n\tconst packageId = getPackageId(config, game);\n\tif (game === 'pvp-coinflip') {\n\t\tconst functionName =\n\t\t\taction === 'join'\n\t\t\t\t? 'join_game'\n\t\t\t\t: action === 'cancel'\n\t\t\t\t\t? 'cancel_game'\n\t\t\t\t\t: 'create_game';\n\t\treturn `${packageId}::pvp_coinflip::${functionName}`;\n\t}\n\treturn `${packageId}::${game}::play`;\n};\n\nconst readOnlyPlan = ({\n\tinput,\n\tgame,\n\taction,\n\trequiredInputs,\n\tnotes,\n}: {\n\tinput:\n\t\t| CoinflipInput\n\t\t| LimboInput\n\t\t| ConfigIdInput\n\t\t| RangeInput\n\t\t| PvpCoinflipCreateInput\n\t\t| PvpCoinflipJoinInput\n\t\t| PvpCoinflipCancelInput;\n\tgame: Game;\n\taction?: PvPCoinflipAction;\n\trequiredInputs: string[];\n\tnotes: string[];\n}): ReadOnlyPlan => {\n\tconst { config } = createSuigarClient(getConfigInput(input));\n\tconst coinType = resolveDefaultCoinType(config, input.coinType);\n\treturn {\n\t\tmode: 'read-only',\n\t\tnetwork: config.network,\n\t\tgame,\n\t\taction,\n\t\tconfig,\n\t\tplan: {\n\t\t\ttarget: getTarget(config, game, action),\n\t\t\ttypeArguments: [coinType],\n\t\t\trequiredInputs,\n\t\t\tnotes,\n\t\t},\n\t};\n};\n\nconst commonOptions = async (\n\tinput:\n\t\t| CoinflipInput\n\t\t| LimboInput\n\t\t| ConfigIdInput\n\t\t| RangeInput\n\t\t| PvpCoinflipCreateInput\n\t\t| PvpCoinflipJoinInput\n\t\t| PvpCoinflipCancelInput,\n\tbundle: SuigarClientBundle,\n) => {\n\treturn {\n\t\towner: await resolveOwnerAddress(\n\t\t\trequireString(input.owner, 'owner'),\n\t\t\tbundle,\n\t\t),\n\t\tcoinType: resolveDefaultCoinType(bundle.config, input.coinType),\n\t\tmetadata: input.metadata,\n\t\tgasBudget: input.gasBudget,\n\t\tuseGasCoin: input.useGasCoin,\n\t};\n};\n\nconst stakeOptions = async (\n\tinput: CoinflipInput | LimboInput | ConfigIdInput | RangeInput,\n\tbundle: SuigarClientBundle,\n) => {\n\tconst { decimals } = coinMetadataForAmount(bundle.config, input.coinType);\n\treturn {\n\t\t...(await commonOptions(input, bundle)),\n\t\tstake: toBaseUnits(input.stake, 'stake', decimals),\n\t\t...(input.cashStake == null\n\t\t\t? {}\n\t\t\t: { cashStake: toBaseUnits(input.cashStake, 'cashStake', decimals) }),\n\t\t...(input.betCount == null\n\t\t\t? {}\n\t\t\t: { betCount: toPositiveInteger(input.betCount, 'betCount') }),\n\t};\n};\n\nconst executeTransactionTool = async ({\n\tinput,\n\tgame,\n\taction,\n\tcreateTransaction,\n\tstake,\n\tstakeDisplay,\n\tgameInputs,\n}: {\n\tinput:\n\t\t| CoinflipInput\n\t\t| LimboInput\n\t\t| ConfigIdInput\n\t\t| RangeInput\n\t\t| PvpCoinflipCreateInput\n\t\t| PvpCoinflipJoinInput\n\t\t| PvpCoinflipCancelInput;\n\tgame: Game;\n\taction?: PvPCoinflipAction;\n\tcreateTransaction: (bundle: SuigarClientBundle) => Promise<Transaction>;\n\tstake?: number | bigint;\n\tstakeDisplay?: string;\n\tgameInputs?: Record<string, JsonValue>;\n}) => {\n\tconst mode = getMode(input.mode);\n\tif (mode === 'read-only') {\n\t\tthrow new Error(\n\t\t\t'read-only mode must be handled before transaction execution.',\n\t\t);\n\t}\n\n\tconst bundle = createSuigarClient(getConfigInput(input));\n\tconst coin = coinMetadataForAmount(bundle.config, input.coinType);\n\tconst baseStake =\n\t\tstake ??\n\t\t(stakeDisplay == null\n\t\t\t? undefined\n\t\t\t: toBaseUnits(stakeDisplay, 'stake', coin.decimals));\n\tconst transaction = await createTransaction(bundle);\n\treturn asTextResponse(\n\t\tawait buildTransactionResult({\n\t\t\tmode,\n\t\t\ttransaction,\n\t\t\tconfig: bundle.config,\n\t\t\tclient: bundle.client,\n\t\t\tcontext: {\n\t\t\t\tgame,\n\t\t\t\taction,\n\t\t\t\tcoinType: coin.coinType,\n\t\t\t\tstake: baseStake,\n\t\t\t\tstakeDisplay,\n\t\t\t\tcoinDecimals: coin.decimals,\n\t\t\t\tgameInputs,\n\t\t\t},\n\t\t}),\n\t);\n};\n\nexport const readConfigTool = async (input: ReadConfigInput = {}) => {\n\tconst { config } = createSuigarClient(getConfigInput(input));\n\treturn asTextResponse({\n\t\tnetwork: config.network,\n\t\tconfig,\n\t\tsupportedGames: supportedGames(),\n\t} satisfies ReadConfigResult);\n};\n\nexport const readGameMetadataTool = async (\n\tinput: ReadGameMetadataInput = {},\n) => {\n\tconst { config } = createSuigarClient(getConfigInput(input));\n\tconst game = input.game ?? null;\n\tconst coinType = resolveDefaultCoinType(config, input.coinType);\n\treturn asTextResponse({\n\t\tnetwork: config.network,\n\t\tconfig,\n\t\tsupportedGames: supportedGames(),\n\t\tgame: game\n\t\t\t? {\n\t\t\t\t\tid: game,\n\t\t\t\t\tlabel: GAME_LABELS[game],\n\t\t\t\t\tpackageId: getPackageId(config, game),\n\t\t\t\t\tcoinType,\n\t\t\t\t\tnotes: [\n\t\t\t\t\t\tgame === 'pvp-coinflip'\n\t\t\t\t\t\t\t? 'PvP coinflip uses dedicated create, join, and cancel transaction builders.'\n\t\t\t\t\t\t\t: 'Standard games use client.suigar.tx.createBetTransaction().',\n\t\t\t\t\t\t'Transactions are unsigned and are never executed by the MCP server.',\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t: null,\n\t} satisfies ReadGameMetadataResult);\n};\n\nexport const buildCoinflipTransactionTool = async (\n\tinput: CoinflipInput = {},\n) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'coinflip',\n\t\t\t\trequiredInputs: ['owner', 'stake', 'side'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Uses the configured SweetHouse object, Pyth price info, clock, and randomness objects.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst side = requireString(input.side, 'side') as CoinSide;\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'coinflip',\n\t\tstakeDisplay: toCurrencyAmountText(input.stake, 'stake'),\n\t\tgameInputs: { side },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createBetTransaction('coinflip', {\n\t\t\t\t...(await stakeOptions(input, bundle)),\n\t\t\t\tside,\n\t\t\t}),\n\t});\n};\n\nexport const buildLimboTransactionTool = async (input: LimboInput = {}) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'limbo',\n\t\t\t\trequiredInputs: ['owner', 'stake', 'targetMultiplier'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Target multiplier is encoded by @suigar/sdk using the public fixed-point utility defaults.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst targetMultiplier = requireNumber(\n\t\tinput.targetMultiplier,\n\t\t'targetMultiplier',\n\t);\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'limbo',\n\t\tstakeDisplay: toCurrencyAmountText(input.stake, 'stake'),\n\t\tgameInputs: { targetMultiplier },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createBetTransaction('limbo', {\n\t\t\t\t...(await stakeOptions(input, bundle)),\n\t\t\t\ttargetMultiplier,\n\t\t\t}),\n\t});\n};\n\nconst buildConfigIdTransactionTool = async (\n\tinput: ConfigIdInput,\n\tgame: Extract<StandardGame, 'plinko' | 'wheel'>,\n) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame,\n\t\t\t\trequiredInputs: ['owner', 'stake', 'configId'],\n\t\t\t\tnotes: ['Config id selects the on-chain game configuration.'],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst configId = requireNumber(input.configId, 'configId');\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame,\n\t\tstakeDisplay: toCurrencyAmountText(input.stake, 'stake'),\n\t\tgameInputs: { configId },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createBetTransaction(game, {\n\t\t\t\t...(await stakeOptions(input, bundle)),\n\t\t\t\tconfigId,\n\t\t\t}),\n\t});\n};\n\nexport const buildPlinkoTransactionTool = (input: ConfigIdInput = {}) =>\n\tbuildConfigIdTransactionTool(input, 'plinko');\n\nexport const buildWheelTransactionTool = (input: ConfigIdInput = {}) =>\n\tbuildConfigIdTransactionTool(input, 'wheel');\n\nexport const buildRangeTransactionTool = async (input: RangeInput = {}) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'range',\n\t\t\t\trequiredInputs: ['owner', 'stake', 'leftPoint', 'rightPoint'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Range points are normalized by @suigar/sdk before Move call construction.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst leftPoint = requireNumber(input.leftPoint, 'leftPoint');\n\tconst rightPoint = requireNumber(input.rightPoint, 'rightPoint');\n\tconst outOfRange = Boolean(input.outOfRange);\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'range',\n\t\tstakeDisplay: toCurrencyAmountText(input.stake, 'stake'),\n\t\tgameInputs: { leftPoint, rightPoint, outOfRange },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createBetTransaction('range', {\n\t\t\t\t...(await stakeOptions(input, bundle)),\n\t\t\t\tleftPoint,\n\t\t\t\trightPoint,\n\t\t\t\toutOfRange,\n\t\t\t}),\n\t});\n};\n\nexport const buildPvpCoinflipCreateTransactionTool = async (\n\tinput: PvpCoinflipCreateInput = {},\n) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'pvp-coinflip',\n\t\t\t\taction: 'create',\n\t\t\t\trequiredInputs: ['owner', 'stake', 'creatorSide'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Creates an unresolved PvP coinflip lobby without signing or executing the transaction.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst creatorSide = requireString(\n\t\tinput.creatorSide,\n\t\t'creatorSide',\n\t) as CoinSide;\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'pvp-coinflip',\n\t\taction: 'create',\n\t\tstakeDisplay: toCurrencyAmountText(input.stake, 'stake'),\n\t\tgameInputs: {\n\t\t\tcreatorSide,\n\t\t\t...(input.isPrivate == null ? {} : { isPrivate: input.isPrivate }),\n\t\t},\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createPvPCoinflipTransaction('create', {\n\t\t\t\t...(await commonOptions(input, bundle)),\n\t\t\t\tstake: toBaseUnits(\n\t\t\t\t\tinput.stake,\n\t\t\t\t\t'stake',\n\t\t\t\t\tcoinMetadataForAmount(bundle.config, input.coinType).decimals,\n\t\t\t\t),\n\t\t\t\tside: creatorSide,\n\t\t\t\tisPrivate: input.isPrivate,\n\t\t\t}),\n\t});\n};\n\nexport const buildPvpCoinflipJoinTransactionTool = async (\n\tinput: PvpCoinflipJoinInput = {},\n) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'pvp-coinflip',\n\t\t\t\taction: 'join',\n\t\t\t\trequiredInputs: ['owner', 'gameId'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Join resolves the live game object during transaction build so the SDK can source the matching stake.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst gameId = requireString(input.gameId, 'gameId');\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'pvp-coinflip',\n\t\taction: 'join',\n\t\tgameInputs: { gameId },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createPvPCoinflipTransaction('join', {\n\t\t\t\t...(await commonOptions(input, bundle)),\n\t\t\t\tgameId,\n\t\t\t}),\n\t});\n};\n\nexport const buildPvpCoinflipCancelTransactionTool = async (\n\tinput: PvpCoinflipCancelInput = {},\n) => {\n\tif (getMode(input.mode) === 'read-only') {\n\t\treturn asTextResponse(\n\t\t\treadOnlyPlan({\n\t\t\t\tinput,\n\t\t\t\tgame: 'pvp-coinflip',\n\t\t\t\taction: 'cancel',\n\t\t\t\trequiredInputs: ['owner', 'gameId'],\n\t\t\t\tnotes: [\n\t\t\t\t\t'Cancel only prepares the unsigned cancellation transaction for the game creator.',\n\t\t\t\t],\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst gameId = requireString(input.gameId, 'gameId');\n\treturn executeTransactionTool({\n\t\tinput,\n\t\tgame: 'pvp-coinflip',\n\t\taction: 'cancel',\n\t\tgameInputs: { gameId },\n\t\tcreateTransaction: async (bundle) =>\n\t\t\tbundle.client.suigar.tx.createPvPCoinflipTransaction('cancel', {\n\t\t\t\t...(await commonOptions(input, bundle)),\n\t\t\t\tgameId,\n\t\t\t}),\n\t});\n};\n"],"mappings":";;;AAuCA,MAAM,cAAc;CACnB,UAAU;CACV,OAAO;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,gBAAgB;AACjB;AAEA,MAAM,sBAAsB;CAC3B,UAAU;CACV,OAAO;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,gBAAgB;AACjB;AAEA,MAAM,gBAAgB;CACrB,UAAU,CAAC,4BAA4B;CACvC,OAAO,CAAC,yBAAyB;CACjC,QAAQ,CAAC,0BAA0B;CACnC,OAAO,CAAC,yBAAyB;CACjC,OAAO,CAAC,yBAAyB;CACjC,gBAAgB;EACf;EACA;EACA;CACD;AACD;AAEA,MAAM,QAAQ,UACb,KAAK,UACJ,QACC,MAAM,SAAU,OAAO,SAAS,WAAW,KAAK,SAAS,IAAI,MAC9D,CACD;AAED,MAAM,kBACL,uBACqB;CACrB,SAAS,CAAC;EAAE,MAAM;EAAQ,MAAM,KAAK,iBAAiB;CAAE,CAAC;CACzD;AACD;AAEA,MAAM,wBAAwB;AAE9B,MAAM,yBACL,QACA,aACI;CACJ,MAAM,mBAAmB,uBAAuB,QAAQ,QAAQ;CAChE,MAAM,OAAO,OAAO,OAAO,OAAO,IAAI,KAAK,CAAC,CAAC,MAC3C,aACA,uBAAuB,QAAQ,SAAS,QAAQ,MAAM,gBACxD;CAEA,IAAI,CAAC,MACJ,MAAM,IAAI,WACT,4CAA4C,iBAAiB,0EAC9D;CAGD,OAAO;EACN,UAAU;EACV,UAAU,KAAK;CA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AAU;GAC9D,GAAI,MAAM,cAAc,OAAO,MAAM;GACrC;EACD,CAAC;CACH,CAAC;AACF"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,111 +1,137 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SuiCompatClient } from "@suigar/sui-rpc-pool";
|
|
1
|
+
import { SuigarClient, SuigarNetwork, suigar } from "@suigar/sdk";
|
|
2
|
+
import { Game, PvPCoinflipAction } from "@suigar/sdk/games";
|
|
3
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
5
4
|
|
|
6
5
|
//#region src/types.d.ts
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
siteUrl: string;
|
|
20
|
-
suigarPackageId: string;
|
|
21
|
-
coinflipPackageId: string;
|
|
22
|
-
pvpCoinflipPackageId: string;
|
|
23
|
-
plinkoPackageId: string;
|
|
24
|
-
limboPackageId: string;
|
|
25
|
-
rangePackageId: string;
|
|
26
|
-
wheelPackageId: string;
|
|
27
|
-
sweethouseId: string;
|
|
28
|
-
suiCoinType: string;
|
|
29
|
-
usdcCoinType: string;
|
|
30
|
-
suiPythPriceInfoObjectId: string;
|
|
31
|
-
usdcPythPriceInfoObjectId: string;
|
|
32
|
-
coinflipSettingsId: string;
|
|
33
|
-
pvpCoinflipSettingsId: string;
|
|
34
|
-
plinkoSettingsId: string;
|
|
35
|
-
limboSettingsId: string;
|
|
36
|
-
rangeSettingsId: string;
|
|
37
|
-
wheelSettingsId: string;
|
|
38
|
-
pvpCoinflipRegistryId: string;
|
|
6
|
+
type SuigarConfig = ReturnType<SuigarClient['getConfig']>;
|
|
7
|
+
type SuigarConfigOverrides = NonNullable<Parameters<typeof suigar>[0]>['config'];
|
|
8
|
+
type RawDryRunResult = SuiClientTypes.SimulateTransactionResult<{
|
|
9
|
+
effects: true;
|
|
10
|
+
events: true;
|
|
11
|
+
balanceChanges: true;
|
|
12
|
+
}>;
|
|
13
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
14
|
+
[key: string]: JsonValue;
|
|
15
|
+
};
|
|
16
|
+
type DryRunResult = {
|
|
17
|
+
[key: string]: JsonValue;
|
|
39
18
|
};
|
|
40
|
-
type
|
|
19
|
+
type BuilderMode = 'build' | 'dry-run' | 'read-only';
|
|
20
|
+
type SuigarMcpConfigInput = {
|
|
41
21
|
network?: SuigarNetwork;
|
|
42
22
|
providerUrl?: string;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
type ConfigInspection = {
|
|
47
|
-
config: SuigarConfig;
|
|
48
|
-
configuredCurrencies: ConfiguredCurrencyEntry[];
|
|
49
|
-
availableGames: Array<GameDefinition & {
|
|
50
|
-
mcpSupport: GameMcpSupport;
|
|
51
|
-
}>;
|
|
52
|
-
missingValues: Array<keyof SuigarConfig>;
|
|
53
|
-
mcp: {
|
|
54
|
-
serverName: string;
|
|
55
|
-
supportedToolNames: SuigarMcpToolName[];
|
|
56
|
-
};
|
|
23
|
+
config?: SuigarConfigOverrides;
|
|
24
|
+
partner?: string;
|
|
57
25
|
};
|
|
58
|
-
type
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} | {
|
|
63
|
-
kind: 'object-ids';
|
|
64
|
-
objectIds: string[];
|
|
65
|
-
split?: boolean;
|
|
26
|
+
type ResolvedMcpConfig = {
|
|
27
|
+
network: SuigarNetwork;
|
|
28
|
+
providerUrl: string;
|
|
29
|
+
sdk: SuigarConfig;
|
|
66
30
|
};
|
|
67
|
-
type
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
coinType: string;
|
|
72
|
-
stake: number | bigint;
|
|
73
|
-
cashStake?: number | bigint;
|
|
74
|
-
betCount?: number | bigint;
|
|
75
|
-
metadata?: BetMetadataInput;
|
|
76
|
-
partner?: string;
|
|
77
|
-
gasBudget?: number | bigint;
|
|
78
|
-
coinSource?: BetCoinSource;
|
|
79
|
-
sender?: string;
|
|
80
|
-
allowGasCoinShortcut?: boolean;
|
|
31
|
+
type TransactionCommandSummary = {
|
|
32
|
+
kind: string;
|
|
33
|
+
target?: string;
|
|
34
|
+
typeArguments?: string[];
|
|
81
35
|
};
|
|
82
36
|
type TransactionSummary = {
|
|
83
37
|
sender: string | null;
|
|
84
38
|
gasBudget: string | null;
|
|
39
|
+
gasBudgetDisplay: string | null;
|
|
85
40
|
gasPrice: string | null;
|
|
86
41
|
commandCount: number;
|
|
87
|
-
commands:
|
|
88
|
-
kind: string;
|
|
89
|
-
target?: string;
|
|
90
|
-
typeArguments?: string[];
|
|
91
|
-
}>;
|
|
42
|
+
commands: TransactionCommandSummary[];
|
|
92
43
|
inputs: number;
|
|
93
44
|
objectInputs: string[];
|
|
94
|
-
game?:
|
|
45
|
+
game?: Game;
|
|
46
|
+
action?: PvPCoinflipAction;
|
|
95
47
|
coinType?: string;
|
|
96
48
|
stake?: string;
|
|
49
|
+
stakeDisplay?: string;
|
|
50
|
+
coinDecimals?: number;
|
|
51
|
+
gameInputs?: {
|
|
52
|
+
[key: string]: JsonValue;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type FormattedAmount = {
|
|
56
|
+
raw: string;
|
|
57
|
+
display: string;
|
|
58
|
+
};
|
|
59
|
+
type DryRunEventSummary = {
|
|
60
|
+
type: string;
|
|
61
|
+
game?: Game;
|
|
62
|
+
eventName?: string;
|
|
63
|
+
fields: {
|
|
64
|
+
[key: string]: JsonValue;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
type DryRunSummary = {
|
|
68
|
+
success: boolean;
|
|
69
|
+
error: string | null;
|
|
70
|
+
gasUsed: {
|
|
71
|
+
computation: FormattedAmount | null;
|
|
72
|
+
storage: FormattedAmount | null;
|
|
73
|
+
rebate: FormattedAmount | null;
|
|
74
|
+
nonRefundableStorageFee: FormattedAmount | null;
|
|
75
|
+
net: FormattedAmount | null;
|
|
76
|
+
};
|
|
77
|
+
balanceChanges: Array<{
|
|
78
|
+
address: string;
|
|
79
|
+
coinType: string;
|
|
80
|
+
amount: FormattedAmount;
|
|
81
|
+
}>;
|
|
82
|
+
events: DryRunEventSummary[];
|
|
97
83
|
};
|
|
98
84
|
type ReadOnlyPlan = {
|
|
99
85
|
mode: 'read-only';
|
|
100
86
|
network: SuigarNetwork;
|
|
101
|
-
game:
|
|
102
|
-
|
|
87
|
+
game: Game;
|
|
88
|
+
action?: PvPCoinflipAction;
|
|
89
|
+
config: ResolvedMcpConfig;
|
|
103
90
|
plan: {
|
|
104
91
|
target: string | null;
|
|
105
92
|
typeArguments: string[];
|
|
106
|
-
|
|
93
|
+
requiredInputs: string[];
|
|
107
94
|
notes: string[];
|
|
108
95
|
};
|
|
109
96
|
};
|
|
97
|
+
type BuildTransactionResult = {
|
|
98
|
+
mode: 'build' | 'dry-run';
|
|
99
|
+
network: SuigarNetwork;
|
|
100
|
+
config: ResolvedMcpConfig;
|
|
101
|
+
summary: TransactionSummary;
|
|
102
|
+
transactionBytesBase64?: string;
|
|
103
|
+
dryRun?: DryRunResult;
|
|
104
|
+
dryRunSummary?: DryRunSummary;
|
|
105
|
+
errors?: string[];
|
|
106
|
+
};
|
|
107
|
+
type ReadConfigResult = {
|
|
108
|
+
network: SuigarNetwork;
|
|
109
|
+
config: ResolvedMcpConfig;
|
|
110
|
+
supportedGames: Array<{
|
|
111
|
+
id: Game;
|
|
112
|
+
label: string;
|
|
113
|
+
tools: string[];
|
|
114
|
+
}>;
|
|
115
|
+
};
|
|
116
|
+
type ReadGameMetadataResult = ReadConfigResult & {
|
|
117
|
+
game: {
|
|
118
|
+
id: Game;
|
|
119
|
+
label: string;
|
|
120
|
+
packageId: string;
|
|
121
|
+
coinType: string;
|
|
122
|
+
action?: PvPCoinflipAction;
|
|
123
|
+
notes: string[];
|
|
124
|
+
} | null;
|
|
125
|
+
};
|
|
126
|
+
type ToolStructuredResult = ReadConfigResult | ReadGameMetadataResult | ReadOnlyPlan | BuildTransactionResult;
|
|
127
|
+
type ToolTextResult = {
|
|
128
|
+
content: [{
|
|
129
|
+
type: 'text';
|
|
130
|
+
text: string;
|
|
131
|
+
}];
|
|
132
|
+
structuredContent: ToolStructuredResult;
|
|
133
|
+
_meta?: Record<string, unknown>;
|
|
134
|
+
};
|
|
110
135
|
//#endregion
|
|
111
|
-
export {
|
|
136
|
+
export { BuildTransactionResult, BuilderMode, DryRunEventSummary, DryRunResult, DryRunSummary, FormattedAmount, JsonValue, RawDryRunResult, ReadConfigResult, ReadGameMetadataResult, ReadOnlyPlan, ResolvedMcpConfig, SuigarConfig, SuigarConfigOverrides, SuigarMcpConfigInput, ToolStructuredResult, ToolTextResult, TransactionCommandSummary, TransactionSummary };
|
|
137
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAOY,YAAA,GAAe,UAAU,CAAC,YAAA;AAAA,KAC1B,qBAAA,GAAwB,WAAA,CACnC,UAAA,QAAkB,MAAA;AAAA,KAEP,eAAA,GAAkB,cAAA,CAAe,yBAAyB;EACrE,OAAA;EACA,MAAA;EACA,cAAA;AAAA;AAAA,KAGW,SAAA,sCACwB,SAAA;EAAA,CAAiB,GAAA,WAAc,SAAS;AAAA;AAAA,KAEhE,YAAA;EAAA,CAAkB,GAAA,WAAc,SAAS;AAAA;AAAA,KAEzC,WAAA;AAAA,KAEA,oBAAA;EACX,OAAA,GAAU,aAAA;EACV,WAAA;EACA,MAAA,GAAS,qBAAqB;EAC9B,OAAA;AAAA;AAAA,KAGW,iBAAA;EACX,OAAA,EAAS,aAAA;EACT,WAAA;EACA,GAAA,EAAK,YAAY;AAAA;AAAA,KAGN,yBAAA;EACX,IAAA;EACA,MAAA;EACA,aAAA;AAAA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;AAAA,KAIU,sBAAA,GAAyB,gBAAA;EACpC,IAAA;IACC,EAAA,EAAI,IAAA;IACJ,KAAA;IACA,SAAA;IACA,QAAA;IACA,MAAA,GAAS,iBAAA;IACT,KAAA;EAAA;AAAA;AAAA,KAIU,oBAAA,GACT,gBAAA,GACA,sBAAA,GACA,YAAA,GACA,sBAAA;AAAA,KAES,cAAA;EACX,OAAA;IAAY,IAAA;IAAc,IAAA;EAAA;EAC1B,iBAAA,EAAmB,oBAAA;EACnB,KAAA,GAAQ,MAAM;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,62 +1,84 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
2
|
+
"name": "@suigar/mcp",
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
|
+
"description": "MCP server and MCP App for building and inspecting Suigar transactions on Sui.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"suigar",
|
|
7
|
+
"sui",
|
|
8
|
+
"mcp",
|
|
9
|
+
"mcp-app",
|
|
10
|
+
"typescript",
|
|
11
|
+
"move",
|
|
12
|
+
"web3",
|
|
13
|
+
"games"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"CHANGELOG.md",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/index.mjs",
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs",
|
|
29
|
+
"default": "./dist/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./server": {
|
|
32
|
+
"types": "./dist/server.d.mts",
|
|
33
|
+
"import": "./dist/server.mjs",
|
|
34
|
+
"default": "./dist/server.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"bin": {
|
|
38
|
+
"suigar": "./dist/bin.mjs"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^22.18.0 || >=24.0.0"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/Suigar-Gaming/sdk.git",
|
|
46
|
+
"directory": "packages/mcp"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/Suigar-Gaming/sdk/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://docs.suigar.com/mcp",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@modelcontextprotocol/ext-apps": "1.7.4",
|
|
57
|
+
"@modelcontextprotocol/sdk": "1.29.0",
|
|
58
|
+
"@mysten/sui": "^2.20.1",
|
|
59
|
+
"zod": "4.4.3",
|
|
60
|
+
"@suigar/sdk": "^2.0.0-beta.22"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/node": "^24.0.0",
|
|
64
|
+
"tsdown": "^0.22.3",
|
|
65
|
+
"typescript": "^6.0.3",
|
|
66
|
+
"vite": "^8.1.0",
|
|
67
|
+
"vite-plugin-singlefile": "^2.3.3",
|
|
68
|
+
"vitest": "^4.1.9"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"start:local": "pnpm --filter @suigar/sdk build:ci && pnpm build && node dist/bin.mjs",
|
|
72
|
+
"build": "pnpm clean && tsdown && vite build",
|
|
73
|
+
"build:ci": "pnpm build",
|
|
74
|
+
"clean": "rm -rf dist",
|
|
75
|
+
"test": "vitest run",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
77
|
+
"eslint": "eslint .",
|
|
78
|
+
"eslint:fix": "eslint . --fix",
|
|
79
|
+
"prettier": "prettier --check --ignore-unknown .",
|
|
80
|
+
"prettier:fix": "prettier --write --ignore-unknown .",
|
|
81
|
+
"lint": "pnpm eslint && pnpm prettier",
|
|
82
|
+
"lint:fix": "pnpm eslint:fix && pnpm prettier:fix"
|
|
83
|
+
}
|
|
84
|
+
}
|
package/dist/bin.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const require_server = require("./server.cjs");
|
|
3
|
-
//#region src/bin.ts
|
|
4
|
-
const main = async () => {
|
|
5
|
-
await require_server.startSuigarMcpServer();
|
|
6
|
-
};
|
|
7
|
-
main().catch((error) => {
|
|
8
|
-
console.error(error);
|
|
9
|
-
process.exitCode = 1;
|
|
10
|
-
});
|
|
11
|
-
//#endregion
|
package/dist/bin.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/client.cjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const require_config = require("./config.cjs");
|
|
2
|
-
let _suigar_sui_rpc_pool = require("@suigar/sui-rpc-pool");
|
|
3
|
-
//#region src/client.ts
|
|
4
|
-
const createReadOnlyClientBundle = (configInput = {}) => {
|
|
5
|
-
const config = require_config.resolveSuigarConfig(configInput);
|
|
6
|
-
const runtime = (0, _suigar_sui_rpc_pool.getOrCreateResilientSuiClientRuntime)({
|
|
7
|
-
network: config.network,
|
|
8
|
-
providerUrl: config.providerUrl
|
|
9
|
-
});
|
|
10
|
-
return {
|
|
11
|
-
config,
|
|
12
|
-
runtime,
|
|
13
|
-
client: runtime.createCompatClient(),
|
|
14
|
-
rawClient: runtime.getGrpcClient()
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
const serializeTransactionToBase64 = async (transaction, client) => {
|
|
18
|
-
const bytes = await transaction.build({ client });
|
|
19
|
-
return Buffer.from(bytes).toString("base64");
|
|
20
|
-
};
|
|
21
|
-
const sanitizeForJson = (value) => {
|
|
22
|
-
if (typeof value === "bigint") return value.toString();
|
|
23
|
-
if (value instanceof Uint8Array) return Buffer.from(value).toString("base64");
|
|
24
|
-
if (Array.isArray(value)) return value.map((entry) => sanitizeForJson(entry));
|
|
25
|
-
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, sanitizeForJson(entry)]));
|
|
26
|
-
return value;
|
|
27
|
-
};
|
|
28
|
-
const dryRunTransaction = async (transaction, configInput = {}) => {
|
|
29
|
-
const { rawClient } = createReadOnlyClientBundle(configInput);
|
|
30
|
-
const bytes = await transaction.build({ client: rawClient });
|
|
31
|
-
return sanitizeForJson(await rawClient.simulateTransaction({
|
|
32
|
-
transaction: bytes,
|
|
33
|
-
include: {
|
|
34
|
-
effects: true,
|
|
35
|
-
events: true,
|
|
36
|
-
balanceChanges: true,
|
|
37
|
-
objectChanges: true,
|
|
38
|
-
input: true
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
//#endregion
|
|
43
|
-
exports.createReadOnlyClientBundle = createReadOnlyClientBundle;
|
|
44
|
-
exports.dryRunTransaction = dryRunTransaction;
|
|
45
|
-
exports.sanitizeForJson = sanitizeForJson;
|
|
46
|
-
exports.serializeTransactionToBase64 = serializeTransactionToBase64;
|
package/dist/client.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SuigarConfig, SuigarConfigInput } from "./types.cjs";
|
|
2
|
-
import { SuiCompatClient } from "@suigar/sui-rpc-pool";
|
|
3
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
4
|
-
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
5
|
-
|
|
6
|
-
//#region src/client.d.ts
|
|
7
|
-
declare const createReadOnlyClientBundle: (configInput?: SuigarConfigInput) => {
|
|
8
|
-
config: SuigarConfig;
|
|
9
|
-
runtime: import("@suigar/sui-rpc-pool").ResilientSuiClientRuntime;
|
|
10
|
-
client: SuiCompatClient;
|
|
11
|
-
rawClient: SuiGrpcClient;
|
|
12
|
-
};
|
|
13
|
-
declare const serializeTransactionToBase64: (transaction: Transaction, client: SuiGrpcClient) => Promise<string>;
|
|
14
|
-
declare const sanitizeForJson: (value: unknown) => unknown;
|
|
15
|
-
declare const dryRunTransaction: (transaction: Transaction, configInput?: SuigarConfigInput) => Promise<unknown>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { createReadOnlyClientBundle, dryRunTransaction, sanitizeForJson, serializeTransactionToBase64 };
|
package/dist/coin.cjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
let _suigar_currency_registry = require("@suigar/currency-registry");
|
|
2
|
-
let _mysten_sui_utils = require("@mysten/sui/utils");
|
|
3
|
-
let _suigar_sdk_utils = require("@suigar/sdk/utils");
|
|
4
|
-
//#region src/coin.ts
|
|
5
|
-
const DEFAULT_PAGE_LIMIT = 50;
|
|
6
|
-
const NETWORK_GAS_COIN_TYPE = (0, _suigar_currency_registry.normalizeCoinType)(_mysten_sui_utils.SUI_TYPE_ARG);
|
|
7
|
-
const mergeCoinObjects = (tx, coinIds) => {
|
|
8
|
-
if (coinIds.length === 0) throw new Error("No coin objects available");
|
|
9
|
-
const primaryCoin = tx.object(coinIds[0]);
|
|
10
|
-
if (coinIds.length > 1) tx.mergeCoins(primaryCoin, coinIds.slice(1).map((coinId) => tx.object(coinId)));
|
|
11
|
-
return primaryCoin;
|
|
12
|
-
};
|
|
13
|
-
const selectCoinsForAmount = async ({ client, owner, coinType, requiredAmount, pageLimit = DEFAULT_PAGE_LIMIT }) => {
|
|
14
|
-
if (requiredAmount <= 0n) return [];
|
|
15
|
-
let cursor = null;
|
|
16
|
-
let total = 0n;
|
|
17
|
-
const coins = [];
|
|
18
|
-
const normalizedCoinType = (0, _suigar_currency_registry.normalizeCoinType)(coinType);
|
|
19
|
-
do {
|
|
20
|
-
const response = await client.getCoins({
|
|
21
|
-
owner,
|
|
22
|
-
coinType: normalizedCoinType,
|
|
23
|
-
cursor,
|
|
24
|
-
limit: pageLimit
|
|
25
|
-
});
|
|
26
|
-
for (const coin of response.data ?? []) {
|
|
27
|
-
try {
|
|
28
|
-
const balance = BigInt(coin.balance);
|
|
29
|
-
coins.push({
|
|
30
|
-
coinObjectId: coin.coinObjectId,
|
|
31
|
-
balance
|
|
32
|
-
});
|
|
33
|
-
total += balance;
|
|
34
|
-
} catch {}
|
|
35
|
-
if (total >= requiredAmount) break;
|
|
36
|
-
}
|
|
37
|
-
cursor = response.hasNextPage && total < requiredAmount ? response.nextCursor : null;
|
|
38
|
-
} while (cursor);
|
|
39
|
-
if (coins.length === 0) throw new Error(`No usable gameplay coin objects were found for ${normalizedCoinType} at owner ${owner}`);
|
|
40
|
-
if (total < requiredAmount) throw new Error("Insufficient balance for this bet");
|
|
41
|
-
coins.sort((left, right) => {
|
|
42
|
-
if (left.balance === right.balance) return 0;
|
|
43
|
-
return left.balance > right.balance ? -1 : 1;
|
|
44
|
-
});
|
|
45
|
-
const selectedCoinIds = [];
|
|
46
|
-
let selectedTotal = 0n;
|
|
47
|
-
for (const coin of coins) {
|
|
48
|
-
selectedCoinIds.push(coin.coinObjectId);
|
|
49
|
-
selectedTotal += coin.balance;
|
|
50
|
-
if (selectedTotal >= requiredAmount) break;
|
|
51
|
-
}
|
|
52
|
-
return selectedCoinIds;
|
|
53
|
-
};
|
|
54
|
-
const resolveBetCoin = async ({ tx, coinType, amount, suiCoinType: _suiCoinType, coinSource, client, owner, allowGasCoinShortcut = true }) => {
|
|
55
|
-
const normalizedCoinType = (0, _suigar_currency_registry.normalizeCoinType)(coinType);
|
|
56
|
-
const resolvedAmount = (0, _suigar_sdk_utils.toBigInt)(amount);
|
|
57
|
-
if (resolvedAmount < 0n) throw new Error("Amount must be non-negative");
|
|
58
|
-
if (resolvedAmount === 0n) return tx.moveCall({
|
|
59
|
-
target: "0x2::coin::zero",
|
|
60
|
-
typeArguments: [normalizedCoinType],
|
|
61
|
-
arguments: []
|
|
62
|
-
});
|
|
63
|
-
if (coinSource?.kind === "object-ids") {
|
|
64
|
-
const primaryCoin = mergeCoinObjects(tx, coinSource.objectIds);
|
|
65
|
-
if (coinSource.split === false) return primaryCoin;
|
|
66
|
-
const [coin] = tx.splitCoins(primaryCoin, [tx.pure.u64(resolvedAmount)]);
|
|
67
|
-
return coin;
|
|
68
|
-
}
|
|
69
|
-
if (coinSource?.kind === "gas" && normalizedCoinType !== NETWORK_GAS_COIN_TYPE) throw new Error(`Gas coin sourcing is only supported for the native SUI gas coin (${NETWORK_GAS_COIN_TYPE})`);
|
|
70
|
-
if ((coinSource?.kind === "gas" || allowGasCoinShortcut) && normalizedCoinType === NETWORK_GAS_COIN_TYPE) {
|
|
71
|
-
if (coinSource?.kind === "gas" && coinSource.split === false) return tx.gas;
|
|
72
|
-
const [coin] = tx.splitCoins(tx.gas, [tx.pure.u64(resolvedAmount)]);
|
|
73
|
-
return coin;
|
|
74
|
-
}
|
|
75
|
-
if (!client || !owner) throw new Error(`A read-only client and owner address are required to source non-native coin ${normalizedCoinType}`);
|
|
76
|
-
const primaryCoin = mergeCoinObjects(tx, await selectCoinsForAmount({
|
|
77
|
-
client,
|
|
78
|
-
owner,
|
|
79
|
-
coinType: normalizedCoinType,
|
|
80
|
-
requiredAmount: resolvedAmount
|
|
81
|
-
}));
|
|
82
|
-
const [coin] = tx.splitCoins(primaryCoin, [tx.pure.u64(resolvedAmount)]);
|
|
83
|
-
return coin;
|
|
84
|
-
};
|
|
85
|
-
//#endregion
|
|
86
|
-
exports.resolveBetCoin = resolveBetCoin;
|
package/dist/coin.d.cts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BetCoinSource, CoinReadClient } from "./types.cjs";
|
|
2
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
-
|
|
4
|
-
//#region src/coin.d.ts
|
|
5
|
-
declare const resolveBetCoin: ({
|
|
6
|
-
tx,
|
|
7
|
-
coinType,
|
|
8
|
-
amount,
|
|
9
|
-
suiCoinType: _suiCoinType,
|
|
10
|
-
coinSource,
|
|
11
|
-
client,
|
|
12
|
-
owner,
|
|
13
|
-
allowGasCoinShortcut
|
|
14
|
-
}: {
|
|
15
|
-
tx: Transaction;
|
|
16
|
-
coinType: string;
|
|
17
|
-
amount: number | bigint;
|
|
18
|
-
suiCoinType?: string;
|
|
19
|
-
coinSource?: BetCoinSource;
|
|
20
|
-
client?: CoinReadClient;
|
|
21
|
-
owner?: string;
|
|
22
|
-
allowGasCoinShortcut?: boolean;
|
|
23
|
-
}) => Promise<{
|
|
24
|
-
NestedResult: [number, number];
|
|
25
|
-
$kind: "NestedResult";
|
|
26
|
-
} | import("@mysten/sui/transactions").TransactionResult | {
|
|
27
|
-
$kind: "Input";
|
|
28
|
-
Input: number;
|
|
29
|
-
type?: "object";
|
|
30
|
-
} | {
|
|
31
|
-
$kind: "GasCoin";
|
|
32
|
-
GasCoin: true;
|
|
33
|
-
}>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { resolveBetCoin };
|