@suigar/mcp 0.1.0 → 0.1.1
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 +19 -0
- package/dist/bin.cjs +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/index.cjs +43 -50
- package/dist/index.d.cts +818 -8
- package/dist/index.d.mts +818 -8
- package/dist/index.mjs +1 -8
- package/{node_modules/@suigar/sui-rpc-pool/dist/index.cjs → dist/server-BD-123-u.mjs} +2084 -671
- package/{node_modules/@suigar/sui-rpc-pool/dist/index.mjs → dist/server-Cmo8UaHE.cjs} +2341 -645
- package/dist/server.cjs +3 -432
- package/dist/server.mjs +1 -430
- package/package.json +75 -61
- package/dist/client.cjs +0 -46
- package/dist/client.d.cts +0 -17
- package/dist/client.d.mts +0 -17
- package/dist/client.mjs +0 -43
- 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/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/tools.cjs +0 -617
- package/dist/tools.d.cts +0 -158
- package/dist/tools.d.mts +0 -158
- package/dist/tools.mjs +0 -608
- 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/dist/types.d.mts +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.d.cts +0 -465
- package/node_modules/@suigar/sui-rpc-pool/dist/index.d.mts +0 -465
- package/node_modules/@suigar/sui-rpc-pool/package.json +0 -31
package/dist/client.mjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { resolveSuigarConfig } from "./config.mjs";
|
|
2
|
-
import { getOrCreateResilientSuiClientRuntime } from "@suigar/sui-rpc-pool";
|
|
3
|
-
//#region src/client.ts
|
|
4
|
-
const createReadOnlyClientBundle = (configInput = {}) => {
|
|
5
|
-
const config = resolveSuigarConfig(configInput);
|
|
6
|
-
const runtime = 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
|
-
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 };
|
package/dist/coin.d.mts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BetCoinSource, CoinReadClient } from "./types.mjs";
|
|
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 };
|
package/dist/coin.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { normalizeCoinType } from "@suigar/currency-registry";
|
|
2
|
-
import { SUI_TYPE_ARG } from "@mysten/sui/utils";
|
|
3
|
-
import { toBigInt } from "@suigar/sdk/utils";
|
|
4
|
-
//#region src/coin.ts
|
|
5
|
-
const DEFAULT_PAGE_LIMIT = 50;
|
|
6
|
-
const NETWORK_GAS_COIN_TYPE = normalizeCoinType(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 = 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 = normalizeCoinType(coinType);
|
|
56
|
-
const resolvedAmount = 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
|
-
export { resolveBetCoin };
|
package/dist/config.cjs
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
const require_mcp_support = require("./mcp-support.cjs");
|
|
2
|
-
let _suigar_currency_registry = require("@suigar/currency-registry");
|
|
3
|
-
let _suigar_game_registry = require("@suigar/game-registry");
|
|
4
|
-
let _mysten_sui_grpc = require("@mysten/sui/grpc");
|
|
5
|
-
let _suigar_sdk = require("@suigar/sdk");
|
|
6
|
-
//#region src/config.ts
|
|
7
|
-
const EMPTY = "";
|
|
8
|
-
const DEFAULT_NETWORK = "testnet";
|
|
9
|
-
const DEFAULT_SUI_COIN_TYPE = "0x2::sui::SUI";
|
|
10
|
-
const SDK_CONFIG_NETWORKS = /* @__PURE__ */ new Set(["mainnet", "testnet"]);
|
|
11
|
-
const DEFAULT_GRAPHQL_URL = (network) => `https://graphql.${network}.sui.io/graphql`;
|
|
12
|
-
const DEFAULT_PROVIDER_URL = (network) => {
|
|
13
|
-
switch (network) {
|
|
14
|
-
case "mainnet": return "https://fullnode.mainnet.sui.io:443";
|
|
15
|
-
case "devnet": return "https://fullnode.devnet.sui.io:443";
|
|
16
|
-
case "localnet": return "http://127.0.0.1:9000";
|
|
17
|
-
default: return "https://fullnode.testnet.sui.io:443";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const parseApiLikeUrl = (value) => value?.trim().replace(/\/+$/, "") ?? EMPTY;
|
|
21
|
-
const trim = (value) => value?.trim() ?? EMPTY;
|
|
22
|
-
const pickFirst = (...values) => {
|
|
23
|
-
for (const value of values) if (typeof value === "string" && value.trim().length > 0) return value.trim();
|
|
24
|
-
return EMPTY;
|
|
25
|
-
};
|
|
26
|
-
const env = (...keys) => pickFirst(...keys.map((key) => process.env[key]));
|
|
27
|
-
const normalizeNetwork = (value) => {
|
|
28
|
-
const normalized = value?.trim().toLowerCase();
|
|
29
|
-
return normalized ? normalized : DEFAULT_NETWORK;
|
|
30
|
-
};
|
|
31
|
-
const resolveSdkConfig = (network) => {
|
|
32
|
-
if (!SDK_CONFIG_NETWORKS.has(network)) return null;
|
|
33
|
-
try {
|
|
34
|
-
return new _mysten_sui_grpc.SuiGrpcClient({
|
|
35
|
-
baseUrl: DEFAULT_PROVIDER_URL(network),
|
|
36
|
-
network
|
|
37
|
-
}).$extend((0, _suigar_sdk.suigar)()).suigar.getConfig();
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const resolveSharedPackageId = (input) => pickFirst(input.suigarPackageId, env("SUIGAR_PACKAGE_ID", "VITE_SUIGAR_PACKAGE_ID"));
|
|
43
|
-
const resolveSuigarConfig = (input = {}) => {
|
|
44
|
-
const mergedInput = {
|
|
45
|
-
...input.config ?? {},
|
|
46
|
-
...input
|
|
47
|
-
};
|
|
48
|
-
const network = normalizeNetwork(mergedInput.network ?? env("SUIGAR_NETWORK", "VITE_NETWORK", "NETWORK"));
|
|
49
|
-
const sdkConfig = resolveSdkConfig(network);
|
|
50
|
-
const explicitSharedPackageId = resolveSharedPackageId(mergedInput);
|
|
51
|
-
const sharedPackageId = pickFirst(explicitSharedPackageId, sdkConfig?.packageIds.core);
|
|
52
|
-
return {
|
|
53
|
-
network,
|
|
54
|
-
providerUrl: pickFirst(mergedInput.providerUrl, env("SUIGAR_PROVIDER_URL", "VITE_SUI_GRPC_URL")) || DEFAULT_PROVIDER_URL(network),
|
|
55
|
-
graphqlUrl: pickFirst(mergedInput.graphqlUrl, env("SUIGAR_GRAPHQL_URL", "VITE_SUI_GRAPHQL_URL")) || DEFAULT_GRAPHQL_URL(network),
|
|
56
|
-
siteUrl: pickFirst(mergedInput.siteUrl, env("SUIGAR_SITE_URL", "VITE_SITE_URL")) || "https://suigar.com",
|
|
57
|
-
suigarPackageId: sharedPackageId,
|
|
58
|
-
coinflipPackageId: pickFirst(mergedInput.coinflipPackageId, env("COINFLIP_PACKAGE_ID", "VITE_COINFLIP_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.coinflip),
|
|
59
|
-
pvpCoinflipPackageId: pickFirst(mergedInput.pvpCoinflipPackageId, env("PVP_COINFLIP_PACKAGE_ID", "VITE_PVP_COINFLIP_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.pvpCoinflip),
|
|
60
|
-
plinkoPackageId: pickFirst(mergedInput.plinkoPackageId, env("PLINKO_PACKAGE_ID", "VITE_PLINKO_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.plinko),
|
|
61
|
-
limboPackageId: pickFirst(mergedInput.limboPackageId, env("LIMBO_PACKAGE_ID", "VITE_LIMBO_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.limbo),
|
|
62
|
-
rangePackageId: pickFirst(mergedInput.rangePackageId, env("RANGE_PACKAGE_ID", "VITE_RANGE_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.range),
|
|
63
|
-
wheelPackageId: pickFirst(mergedInput.wheelPackageId, env("WHEEL_PACKAGE_ID", "VITE_WHEEL_PACKAGE_ID"), explicitSharedPackageId, sdkConfig?.packageIds.wheel),
|
|
64
|
-
sweethouseId: pickFirst(mergedInput.sweethouseId, env("SWEETHOUSE_ID", "VITE_SWEETHOUSE_ID"), sdkConfig?.packageIds.sweetHouse),
|
|
65
|
-
suiCoinType: pickFirst(mergedInput.suiCoinType, env("SUI_COIN_TYPE", "VITE_SUI_COIN_TYPE"), sdkConfig?.coinTypes.sui) || DEFAULT_SUI_COIN_TYPE,
|
|
66
|
-
usdcCoinType: pickFirst(mergedInput.usdcCoinType, env("USDC_COIN_TYPE", "VITE_USDC_COIN_TYPE"), sdkConfig?.coinTypes.usdc),
|
|
67
|
-
suiPythPriceInfoObjectId: pickFirst(mergedInput.suiPythPriceInfoObjectId, env("SUI_PYTH_PRICE_INFO_OBJECT_ID", "VITE_SUI_PYTH_PRICE_INFO_OBJECT_ID"), sdkConfig?.priceInfoObjectIds.sui),
|
|
68
|
-
usdcPythPriceInfoObjectId: pickFirst(mergedInput.usdcPythPriceInfoObjectId, env("USDC_PYTH_PRICE_INFO_OBJECT_ID", "VITE_USDC_PYTH_PRICE_INFO_OBJECT_ID"), sdkConfig?.priceInfoObjectIds.usdc),
|
|
69
|
-
coinflipSettingsId: pickFirst(mergedInput.coinflipSettingsId, env("COINFLIP_SETTINGS_ID", "VITE_COINFLIP_SETTINGS_ID")),
|
|
70
|
-
pvpCoinflipSettingsId: pickFirst(mergedInput.pvpCoinflipSettingsId, env("PVP_COINFLIP_SETTINGS_ID", "VITE_PVP_COINFLIP_SETTINGS_ID")),
|
|
71
|
-
plinkoSettingsId: pickFirst(mergedInput.plinkoSettingsId, env("PLINKO_SETTINGS_ID", "VITE_PLINKO_SETTINGS_ID")),
|
|
72
|
-
limboSettingsId: pickFirst(mergedInput.limboSettingsId, env("LIMBO_SETTINGS_ID", "VITE_LIMBO_SETTINGS_ID")),
|
|
73
|
-
rangeSettingsId: pickFirst(mergedInput.rangeSettingsId, env("RANGE_SETTINGS_ID", "VITE_RANGE_SETTINGS_ID")),
|
|
74
|
-
wheelSettingsId: pickFirst(mergedInput.wheelSettingsId, env("WHEEL_SETTINGS_ID", "VITE_WHEEL_SETTINGS_ID")),
|
|
75
|
-
pvpCoinflipRegistryId: pickFirst(mergedInput.pvpCoinflipRegistryId, env("PVP_COINFLIP_REGISTRY_ID", "VITE_PVP_COINFLIP_REGISTRY_ID"), sdkConfig?.registryIds.pvpCoinflip)
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
const REQUIRED_CONFIG_KEYS_BY_GAME = {
|
|
79
|
-
coinflip: [
|
|
80
|
-
"coinflipPackageId",
|
|
81
|
-
"sweethouseId",
|
|
82
|
-
"suiCoinType",
|
|
83
|
-
"suiPythPriceInfoObjectId"
|
|
84
|
-
],
|
|
85
|
-
limbo: [
|
|
86
|
-
"limboPackageId",
|
|
87
|
-
"sweethouseId",
|
|
88
|
-
"suiCoinType",
|
|
89
|
-
"suiPythPriceInfoObjectId"
|
|
90
|
-
],
|
|
91
|
-
plinko: [
|
|
92
|
-
"plinkoPackageId",
|
|
93
|
-
"sweethouseId",
|
|
94
|
-
"suiCoinType",
|
|
95
|
-
"suiPythPriceInfoObjectId"
|
|
96
|
-
],
|
|
97
|
-
wheel: [
|
|
98
|
-
"wheelPackageId",
|
|
99
|
-
"sweethouseId",
|
|
100
|
-
"suiCoinType",
|
|
101
|
-
"suiPythPriceInfoObjectId"
|
|
102
|
-
],
|
|
103
|
-
range: [
|
|
104
|
-
"rangePackageId",
|
|
105
|
-
"sweethouseId",
|
|
106
|
-
"suiCoinType",
|
|
107
|
-
"suiPythPriceInfoObjectId"
|
|
108
|
-
],
|
|
109
|
-
"pvp-coinflip": [
|
|
110
|
-
"pvpCoinflipPackageId",
|
|
111
|
-
"sweethouseId",
|
|
112
|
-
"suiCoinType"
|
|
113
|
-
]
|
|
114
|
-
};
|
|
115
|
-
const getRequiredConfigKeysForGame = (game) => REQUIRED_CONFIG_KEYS_BY_GAME[game];
|
|
116
|
-
const inspectResolvedConfig = (input = {}) => {
|
|
117
|
-
const config = resolveSuigarConfig(input);
|
|
118
|
-
const configuredCurrencies = (0, _suigar_currency_registry.buildConfiguredCurrencies)({
|
|
119
|
-
suiCoinType: config.suiCoinType,
|
|
120
|
-
usdcCoinType: config.usdcCoinType
|
|
121
|
-
});
|
|
122
|
-
const missingValues = Object.entries(config).flatMap(([key, value]) => trim(value) ? [] : [key]);
|
|
123
|
-
return {
|
|
124
|
-
config,
|
|
125
|
-
configuredCurrencies,
|
|
126
|
-
availableGames: (0, _suigar_game_registry.getActiveGames)().map((game) => ({
|
|
127
|
-
...game,
|
|
128
|
-
mcpSupport: require_mcp_support.getMcpSupportForGame(game.id)
|
|
129
|
-
})),
|
|
130
|
-
missingValues,
|
|
131
|
-
mcp: require_mcp_support.buildMcpSupportCatalog()
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
const resolvePythPriceInfoId = (coinType, configInput = {}) => {
|
|
135
|
-
const config = resolveSuigarConfig(configInput);
|
|
136
|
-
const normalizedCoinType = (0, _suigar_currency_registry.normalizeCoinTypeKey)(coinType);
|
|
137
|
-
if (normalizedCoinType === (0, _suigar_currency_registry.normalizeCoinTypeKey)(config.suiCoinType) && config.suiPythPriceInfoObjectId) return config.suiPythPriceInfoObjectId;
|
|
138
|
-
if ([config.usdcCoinType].filter((value) => Boolean(trim(value))).map((value) => (0, _suigar_currency_registry.normalizeCoinTypeKey)(value)).includes(normalizedCoinType) && config.usdcPythPriceInfoObjectId) return config.usdcPythPriceInfoObjectId;
|
|
139
|
-
if ((0, _suigar_currency_registry.resolveCurrencyMetadata)(coinType, inspectResolvedConfig(config).configuredCurrencies).symbol === "USDC" && config.usdcPythPriceInfoObjectId) return config.usdcPythPriceInfoObjectId;
|
|
140
|
-
throw new Error(`Missing Pyth price object configuration for coin type ${coinType}`);
|
|
141
|
-
};
|
|
142
|
-
const resolveGamePackageId = (game, configInput = {}) => {
|
|
143
|
-
const config = resolveSuigarConfig(configInput);
|
|
144
|
-
switch (game) {
|
|
145
|
-
case "coinflip": return config.coinflipPackageId;
|
|
146
|
-
case "limbo": return config.limboPackageId;
|
|
147
|
-
case "plinko": return config.plinkoPackageId;
|
|
148
|
-
case "wheel": return config.wheelPackageId;
|
|
149
|
-
case "range": return config.rangePackageId;
|
|
150
|
-
case "pvp-coinflip": return config.pvpCoinflipPackageId;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const resolveGameSettingsId = (game, configInput = {}) => {
|
|
154
|
-
const config = resolveSuigarConfig(configInput);
|
|
155
|
-
switch (game) {
|
|
156
|
-
case "coinflip": return config.coinflipSettingsId;
|
|
157
|
-
case "limbo": return config.limboSettingsId;
|
|
158
|
-
case "plinko": return config.plinkoSettingsId;
|
|
159
|
-
case "wheel": return config.wheelSettingsId;
|
|
160
|
-
case "range": return config.rangeSettingsId;
|
|
161
|
-
case "pvp-coinflip": return config.pvpCoinflipSettingsId;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const assertRequiredConfig = (game, configInput = {}) => {
|
|
165
|
-
const inspection = inspectResolvedConfig(configInput);
|
|
166
|
-
const missing = getRequiredConfigKeysForGame(game).filter((key) => !trim(inspection.config[key]));
|
|
167
|
-
if (missing.length > 0) throw new Error(`Missing required config for ${game}: ${missing.join(", ")}`);
|
|
168
|
-
return inspection.config;
|
|
169
|
-
};
|
|
170
|
-
const buildProviderUrl = (network) => DEFAULT_PROVIDER_URL(network);
|
|
171
|
-
const buildGraphqlUrl = (network) => DEFAULT_GRAPHQL_URL(network);
|
|
172
|
-
const parseApiUrl = parseApiLikeUrl;
|
|
173
|
-
//#endregion
|
|
174
|
-
exports.assertRequiredConfig = assertRequiredConfig;
|
|
175
|
-
exports.buildGraphqlUrl = buildGraphqlUrl;
|
|
176
|
-
exports.buildProviderUrl = buildProviderUrl;
|
|
177
|
-
exports.getRequiredConfigKeysForGame = getRequiredConfigKeysForGame;
|
|
178
|
-
exports.inspectResolvedConfig = inspectResolvedConfig;
|
|
179
|
-
exports.parseApiUrl = parseApiUrl;
|
|
180
|
-
exports.resolveGamePackageId = resolveGamePackageId;
|
|
181
|
-
exports.resolveGameSettingsId = resolveGameSettingsId;
|
|
182
|
-
exports.resolvePythPriceInfoId = resolvePythPriceInfoId;
|
|
183
|
-
exports.resolveSuigarConfig = resolveSuigarConfig;
|
package/dist/config.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CasinoBetGameId, ConfigInspection, SuigarConfig, SuigarConfigInput, SupportedGameId } from "./types.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
declare const resolveSuigarConfig: (input?: SuigarConfigInput) => SuigarConfig;
|
|
5
|
-
declare const getRequiredConfigKeysForGame: (game: SupportedGameId) => Array<keyof SuigarConfig>;
|
|
6
|
-
declare const inspectResolvedConfig: (input?: SuigarConfigInput) => ConfigInspection;
|
|
7
|
-
declare const resolvePythPriceInfoId: (coinType: string, configInput?: SuigarConfigInput) => string;
|
|
8
|
-
declare const resolveGamePackageId: (game: SupportedGameId, configInput?: SuigarConfigInput) => string | null;
|
|
9
|
-
declare const resolveGameSettingsId: (game: CasinoBetGameId | "pvp-coinflip", configInput?: SuigarConfigInput) => string | null;
|
|
10
|
-
declare const assertRequiredConfig: (game: SupportedGameId, configInput?: SuigarConfigInput) => SuigarConfig;
|
|
11
|
-
declare const buildProviderUrl: (network: string) => "https://fullnode.mainnet.sui.io:443" | "https://fullnode.devnet.sui.io:443" | "http://127.0.0.1:9000" | "https://fullnode.testnet.sui.io:443";
|
|
12
|
-
declare const buildGraphqlUrl: (network: string) => string;
|
|
13
|
-
declare const parseApiUrl: (value: string | undefined) => string;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { assertRequiredConfig, buildGraphqlUrl, buildProviderUrl, getRequiredConfigKeysForGame, inspectResolvedConfig, parseApiUrl, resolveGamePackageId, resolveGameSettingsId, resolvePythPriceInfoId, resolveSuigarConfig };
|
package/dist/config.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CasinoBetGameId, ConfigInspection, SuigarConfig, SuigarConfigInput, SupportedGameId } from "./types.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
declare const resolveSuigarConfig: (input?: SuigarConfigInput) => SuigarConfig;
|
|
5
|
-
declare const getRequiredConfigKeysForGame: (game: SupportedGameId) => Array<keyof SuigarConfig>;
|
|
6
|
-
declare const inspectResolvedConfig: (input?: SuigarConfigInput) => ConfigInspection;
|
|
7
|
-
declare const resolvePythPriceInfoId: (coinType: string, configInput?: SuigarConfigInput) => string;
|
|
8
|
-
declare const resolveGamePackageId: (game: SupportedGameId, configInput?: SuigarConfigInput) => string | null;
|
|
9
|
-
declare const resolveGameSettingsId: (game: CasinoBetGameId | "pvp-coinflip", configInput?: SuigarConfigInput) => string | null;
|
|
10
|
-
declare const assertRequiredConfig: (game: SupportedGameId, configInput?: SuigarConfigInput) => SuigarConfig;
|
|
11
|
-
declare const buildProviderUrl: (network: string) => "https://fullnode.mainnet.sui.io:443" | "https://fullnode.devnet.sui.io:443" | "http://127.0.0.1:9000" | "https://fullnode.testnet.sui.io:443";
|
|
12
|
-
declare const buildGraphqlUrl: (network: string) => string;
|
|
13
|
-
declare const parseApiUrl: (value: string | undefined) => string;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { assertRequiredConfig, buildGraphqlUrl, buildProviderUrl, getRequiredConfigKeysForGame, inspectResolvedConfig, parseApiUrl, resolveGamePackageId, resolveGameSettingsId, resolvePythPriceInfoId, resolveSuigarConfig };
|