@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.
Files changed (55) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/bin.cjs +1 -1
  3. package/dist/bin.mjs +1 -1
  4. package/dist/index.cjs +43 -50
  5. package/dist/index.d.cts +818 -8
  6. package/dist/index.d.mts +818 -8
  7. package/dist/index.mjs +1 -8
  8. package/{node_modules/@suigar/sui-rpc-pool/dist/index.cjs → dist/server-BD-123-u.mjs} +2084 -671
  9. package/{node_modules/@suigar/sui-rpc-pool/dist/index.mjs → dist/server-Cmo8UaHE.cjs} +2341 -645
  10. package/dist/server.cjs +3 -432
  11. package/dist/server.mjs +1 -430
  12. package/package.json +75 -61
  13. package/dist/client.cjs +0 -46
  14. package/dist/client.d.cts +0 -17
  15. package/dist/client.d.mts +0 -17
  16. package/dist/client.mjs +0 -43
  17. package/dist/coin.cjs +0 -86
  18. package/dist/coin.d.cts +0 -35
  19. package/dist/coin.d.mts +0 -35
  20. package/dist/coin.mjs +0 -86
  21. package/dist/config.cjs +0 -183
  22. package/dist/config.d.cts +0 -15
  23. package/dist/config.d.mts +0 -15
  24. package/dist/config.mjs +0 -174
  25. package/dist/mcp-support.cjs +0 -62
  26. package/dist/mcp-support.d.cts +0 -16
  27. package/dist/mcp-support.d.mts +0 -16
  28. package/dist/mcp-support.mjs +0 -60
  29. package/dist/metadata.cjs +0 -51
  30. package/dist/metadata.d.cts +0 -52
  31. package/dist/metadata.d.mts +0 -52
  32. package/dist/metadata.mjs +0 -47
  33. package/dist/tools.cjs +0 -617
  34. package/dist/tools.d.cts +0 -158
  35. package/dist/tools.d.mts +0 -158
  36. package/dist/tools.mjs +0 -608
  37. package/dist/transactions.cjs +0 -294
  38. package/dist/transactions.d.cts +0 -40
  39. package/dist/transactions.d.mts +0 -40
  40. package/dist/transactions.mjs +0 -286
  41. package/dist/types.d.cts +0 -111
  42. package/dist/types.d.mts +0 -111
  43. package/node_modules/@suigar/currency-registry/dist/index.cjs +0 -121
  44. package/node_modules/@suigar/currency-registry/dist/index.d.cts +0 -50
  45. package/node_modules/@suigar/currency-registry/dist/index.d.mts +0 -50
  46. package/node_modules/@suigar/currency-registry/dist/index.mjs +0 -110
  47. package/node_modules/@suigar/currency-registry/package.json +0 -31
  48. package/node_modules/@suigar/game-registry/dist/index.cjs +0 -310
  49. package/node_modules/@suigar/game-registry/dist/index.d.cts +0 -65
  50. package/node_modules/@suigar/game-registry/dist/index.d.mts +0 -65
  51. package/node_modules/@suigar/game-registry/dist/index.mjs +0 -292
  52. package/node_modules/@suigar/game-registry/package.json +0 -31
  53. package/node_modules/@suigar/sui-rpc-pool/dist/index.d.cts +0 -465
  54. package/node_modules/@suigar/sui-rpc-pool/dist/index.d.mts +0 -465
  55. package/node_modules/@suigar/sui-rpc-pool/package.json +0 -31
package/dist/types.d.cts DELETED
@@ -1,111 +0,0 @@
1
- import { GameMcpSupport, SuigarMcpToolName } from "./mcp-support.cjs";
2
- import { ConfiguredCurrencyEntry } from "@suigar/currency-registry";
3
- import { GameDefinition } from "@suigar/game-registry";
4
- import { SuiCompatClient } from "@suigar/sui-rpc-pool";
5
-
6
- //#region src/types.d.ts
7
- type SuigarNetwork = 'mainnet' | 'testnet' | 'devnet' | 'localnet' | (string & {});
8
- type BetMetadataPrimitive = string | number | boolean | bigint;
9
- type BetMetadataInputValue = BetMetadataPrimitive | Uint8Array | number[];
10
- type BetMetadataInput = Record<string, BetMetadataInputValue>;
11
- type CoinSide = 'heads' | 'tails';
12
- type BuilderMode = 'build' | 'dry-run' | 'read-only';
13
- type CasinoBetGameId = 'coinflip' | 'limbo' | 'plinko' | 'wheel' | 'range';
14
- type SupportedGameId = CasinoBetGameId | 'pvp-coinflip';
15
- type SuigarConfig = {
16
- network: SuigarNetwork;
17
- providerUrl: string;
18
- graphqlUrl: string;
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;
39
- };
40
- type SuigarConfigInput = Partial<SuigarConfig> & {
41
- network?: SuigarNetwork;
42
- providerUrl?: string;
43
- graphqlUrl?: string;
44
- config?: Partial<SuigarConfig>;
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
- };
57
- };
58
- type CoinReadClient = Pick<SuiCompatClient, 'getCoins' | 'getReferenceGasPrice'>;
59
- type BetCoinSource = {
60
- kind: 'gas';
61
- split?: boolean;
62
- } | {
63
- kind: 'object-ids';
64
- objectIds: string[];
65
- split?: boolean;
66
- };
67
- type SharedBuildOptions = {
68
- config?: SuigarConfigInput;
69
- client?: CoinReadClient;
70
- owner: string;
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;
81
- };
82
- type TransactionSummary = {
83
- sender: string | null;
84
- gasBudget: string | null;
85
- gasPrice: string | null;
86
- commandCount: number;
87
- commands: Array<{
88
- kind: string;
89
- target?: string;
90
- typeArguments?: string[];
91
- }>;
92
- inputs: number;
93
- objectInputs: string[];
94
- game?: SupportedGameId;
95
- coinType?: string;
96
- stake?: string;
97
- };
98
- type ReadOnlyPlan = {
99
- mode: 'read-only';
100
- network: SuigarNetwork;
101
- game: SupportedGameId;
102
- config: ConfigInspection;
103
- plan: {
104
- target: string | null;
105
- typeArguments: string[];
106
- requiredConfigKeys: Array<keyof SuigarConfig>;
107
- notes: string[];
108
- };
109
- };
110
- //#endregion
111
- export { BetCoinSource, BetMetadataInput, BetMetadataInputValue, BetMetadataPrimitive, BuilderMode, CasinoBetGameId, CoinReadClient, CoinSide, ConfigInspection, ReadOnlyPlan, SharedBuildOptions, SuigarConfig, SuigarConfigInput, SuigarNetwork, SupportedGameId, TransactionSummary };
package/dist/types.d.mts DELETED
@@ -1,111 +0,0 @@
1
- import { GameMcpSupport, SuigarMcpToolName } from "./mcp-support.mjs";
2
- import { ConfiguredCurrencyEntry } from "@suigar/currency-registry";
3
- import { GameDefinition } from "@suigar/game-registry";
4
- import { SuiCompatClient } from "@suigar/sui-rpc-pool";
5
-
6
- //#region src/types.d.ts
7
- type SuigarNetwork = 'mainnet' | 'testnet' | 'devnet' | 'localnet' | (string & {});
8
- type BetMetadataPrimitive = string | number | boolean | bigint;
9
- type BetMetadataInputValue = BetMetadataPrimitive | Uint8Array | number[];
10
- type BetMetadataInput = Record<string, BetMetadataInputValue>;
11
- type CoinSide = 'heads' | 'tails';
12
- type BuilderMode = 'build' | 'dry-run' | 'read-only';
13
- type CasinoBetGameId = 'coinflip' | 'limbo' | 'plinko' | 'wheel' | 'range';
14
- type SupportedGameId = CasinoBetGameId | 'pvp-coinflip';
15
- type SuigarConfig = {
16
- network: SuigarNetwork;
17
- providerUrl: string;
18
- graphqlUrl: string;
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;
39
- };
40
- type SuigarConfigInput = Partial<SuigarConfig> & {
41
- network?: SuigarNetwork;
42
- providerUrl?: string;
43
- graphqlUrl?: string;
44
- config?: Partial<SuigarConfig>;
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
- };
57
- };
58
- type CoinReadClient = Pick<SuiCompatClient, 'getCoins' | 'getReferenceGasPrice'>;
59
- type BetCoinSource = {
60
- kind: 'gas';
61
- split?: boolean;
62
- } | {
63
- kind: 'object-ids';
64
- objectIds: string[];
65
- split?: boolean;
66
- };
67
- type SharedBuildOptions = {
68
- config?: SuigarConfigInput;
69
- client?: CoinReadClient;
70
- owner: string;
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;
81
- };
82
- type TransactionSummary = {
83
- sender: string | null;
84
- gasBudget: string | null;
85
- gasPrice: string | null;
86
- commandCount: number;
87
- commands: Array<{
88
- kind: string;
89
- target?: string;
90
- typeArguments?: string[];
91
- }>;
92
- inputs: number;
93
- objectInputs: string[];
94
- game?: SupportedGameId;
95
- coinType?: string;
96
- stake?: string;
97
- };
98
- type ReadOnlyPlan = {
99
- mode: 'read-only';
100
- network: SuigarNetwork;
101
- game: SupportedGameId;
102
- config: ConfigInspection;
103
- plan: {
104
- target: string | null;
105
- typeArguments: string[];
106
- requiredConfigKeys: Array<keyof SuigarConfig>;
107
- notes: string[];
108
- };
109
- };
110
- //#endregion
111
- export { BetCoinSource, BetMetadataInput, BetMetadataInputValue, BetMetadataPrimitive, BuilderMode, CasinoBetGameId, CoinReadClient, CoinSide, ConfigInspection, ReadOnlyPlan, SharedBuildOptions, SuigarConfig, SuigarConfigInput, SuigarNetwork, SupportedGameId, TransactionSummary };
@@ -1,121 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/index.ts
3
- const CURRENCY_FAMILIES = [{
4
- id: "sui",
5
- symbol: "SUI",
6
- name: "Sui",
7
- decimals: 9,
8
- suffixes: ["::sui::sui", "::test_sui::test_sui"]
9
- }, {
10
- id: "usdc",
11
- symbol: "USDC",
12
- name: "USDC",
13
- decimals: 6,
14
- suffixes: ["::usdc::usdc", "::test_usdc::test_usdc"]
15
- }];
16
- const CONFIGURED_CURRENCY_SPECS = [{
17
- id: "sui",
18
- familyId: "sui",
19
- symbol: "SUI",
20
- name: "Sui",
21
- configKey: "suiCoinType"
22
- }, {
23
- id: "usdc",
24
- familyId: "usdc",
25
- symbol: "USDC",
26
- name: "USDC",
27
- configKey: "usdcCoinType"
28
- }];
29
- const DEFAULT_COIN_SYMBOL = "COIN";
30
- const DEFAULT_COIN_NAME = "Coin";
31
- const DEFAULT_COIN_DECIMALS = 9;
32
- const trimCoinType = (coinType) => typeof coinType === "string" ? coinType.trim() : "";
33
- const normalizeCoinType = (coinType) => {
34
- if (!coinType) return coinType;
35
- const parts = coinType.split("::");
36
- if (parts.length < 3) return `0x${((coinType.startsWith("0x") ? coinType.slice(2) : coinType).replace(/^0+/, "") || "0").toLowerCase()}`;
37
- const [rawAddress, module, ...rest] = parts;
38
- return [
39
- `0x${((rawAddress.startsWith("0x") ? rawAddress.slice(2) : rawAddress).replace(/^0+/, "") || "0").toLowerCase()}`,
40
- module,
41
- ...rest
42
- ].join("::");
43
- };
44
- const normalizeCoinTypeKey = (coinType) => {
45
- const trimmed = trimCoinType(coinType);
46
- return trimmed ? normalizeCoinType(trimmed).toLowerCase() : "";
47
- };
48
- const resolveFallbackSymbol = (coinType, fallback = DEFAULT_COIN_SYMBOL) => {
49
- const trimmed = trimCoinType(coinType);
50
- if (!trimmed) return fallback;
51
- const parts = trimmed.split("::").filter(Boolean);
52
- return (parts[parts.length - 1] ?? trimmed).replace(/\s+/g, "_").trim().toUpperCase() || fallback;
53
- };
54
- const dedupeCurrenciesByType = (currencies) => {
55
- const seen = /* @__PURE__ */ new Set();
56
- return currencies.filter((currency) => {
57
- const normalizedType = normalizeCoinTypeKey(currency.type);
58
- if (seen.has(normalizedType)) return false;
59
- seen.add(normalizedType);
60
- return true;
61
- });
62
- };
63
- const resolveCoinFamily = (coinType) => {
64
- const normalized = normalizeCoinTypeKey(coinType);
65
- if (!normalized) return null;
66
- for (const family of CURRENCY_FAMILIES) if (family.suffixes.some((suffix) => normalized.endsWith(suffix))) return family;
67
- return null;
68
- };
69
- const buildConfiguredCurrencies = (config) => dedupeCurrenciesByType(CONFIGURED_CURRENCY_SPECS.flatMap((spec) => {
70
- const type = trimCoinType(config[spec.configKey]);
71
- if (!type) return [];
72
- return [{
73
- id: spec.id,
74
- familyId: spec.familyId,
75
- symbol: spec.symbol,
76
- name: spec.name,
77
- type,
78
- normalizedType: normalizeCoinType(type),
79
- decimals: CURRENCY_FAMILIES.find((family) => family.id === spec.familyId)?.decimals ?? DEFAULT_COIN_DECIMALS
80
- }];
81
- }));
82
- const resolveConfiguredCurrency = (coinType, configuredCurrencies) => {
83
- const normalized = normalizeCoinTypeKey(coinType);
84
- if (!normalized) return null;
85
- return configuredCurrencies.find((currency) => normalizeCoinTypeKey(currency.type) === normalized) ?? null;
86
- };
87
- const resolveCurrencyMetadata = (coinType, configuredCurrencies = [], fallbacks = {}) => {
88
- const configuredCurrency = resolveConfiguredCurrency(coinType, configuredCurrencies);
89
- if (configuredCurrency) return {
90
- symbol: configuredCurrency.symbol,
91
- name: configuredCurrency.name,
92
- decimals: configuredCurrency.decimals
93
- };
94
- const family = resolveCoinFamily(coinType);
95
- if (family) return {
96
- symbol: family.symbol,
97
- name: family.name,
98
- decimals: family.decimals
99
- };
100
- const fallbackSymbol = resolveFallbackSymbol(coinType, fallbacks.symbol ?? DEFAULT_COIN_SYMBOL);
101
- return {
102
- symbol: fallbackSymbol,
103
- name: fallbacks.name ?? fallbackSymbol ?? DEFAULT_COIN_NAME,
104
- decimals: fallbacks.decimals ?? DEFAULT_COIN_DECIMALS
105
- };
106
- };
107
- const resolveCoinDecimals = (coinType, fallback = DEFAULT_COIN_DECIMALS) => resolveCurrencyMetadata(coinType, [], { decimals: fallback }).decimals;
108
- const resolveCoinSymbol = (coinType, fallback = DEFAULT_COIN_SYMBOL) => resolveCurrencyMetadata(coinType, [], { symbol: fallback }).symbol;
109
- const createCurrencyDecimalsMap = (currencies) => Object.fromEntries(currencies.map((currency) => [normalizeCoinTypeKey(currency.type), currency.decimals]).filter(([type]) => type.length > 0));
110
- //#endregion
111
- exports.CURRENCY_FAMILIES = CURRENCY_FAMILIES;
112
- exports.buildConfiguredCurrencies = buildConfiguredCurrencies;
113
- exports.createCurrencyDecimalsMap = createCurrencyDecimalsMap;
114
- exports.dedupeCurrenciesByType = dedupeCurrenciesByType;
115
- exports.normalizeCoinType = normalizeCoinType;
116
- exports.normalizeCoinTypeKey = normalizeCoinTypeKey;
117
- exports.resolveCoinDecimals = resolveCoinDecimals;
118
- exports.resolveCoinFamily = resolveCoinFamily;
119
- exports.resolveCoinSymbol = resolveCoinSymbol;
120
- exports.resolveConfiguredCurrency = resolveConfiguredCurrency;
121
- exports.resolveCurrencyMetadata = resolveCurrencyMetadata;
@@ -1,50 +0,0 @@
1
- //#region src/index.d.ts
2
- type CurrencyFamilyId = 'sui' | 'usdc';
3
- type CurrencyFamilyDefinition = {
4
- id: CurrencyFamilyId;
5
- symbol: string;
6
- name: string;
7
- decimals: number;
8
- suffixes: readonly string[];
9
- };
10
- type ConfiguredCurrencyId = 'sui' | 'usdc';
11
- type ConfiguredCurrencyEntry = {
12
- id: ConfiguredCurrencyId;
13
- familyId: CurrencyFamilyId;
14
- symbol: string;
15
- name: string;
16
- type: string;
17
- normalizedType: string;
18
- decimals: number;
19
- };
20
- type CurrencyConfigInput = {
21
- suiCoinType?: string | null;
22
- usdcCoinType?: string | null;
23
- };
24
- type CurrencyLike = {
25
- type: string;
26
- };
27
- type CurrencyMetadataLike = CurrencyLike & {
28
- symbol: string;
29
- name: string;
30
- decimals: number;
31
- };
32
- declare const CURRENCY_FAMILIES: readonly CurrencyFamilyDefinition[];
33
- declare const normalizeCoinType: (coinType: string) => string;
34
- declare const normalizeCoinTypeKey: (coinType?: string | null) => string;
35
- declare const dedupeCurrenciesByType: <T extends CurrencyLike>(currencies: readonly T[]) => T[];
36
- declare const resolveCoinFamily: (coinType?: string | null) => CurrencyFamilyDefinition | null;
37
- declare const buildConfiguredCurrencies: (config: CurrencyConfigInput) => ConfiguredCurrencyEntry[];
38
- declare const resolveConfiguredCurrency: <T extends CurrencyLike>(coinType: string | null | undefined, configuredCurrencies: readonly T[]) => T | null;
39
- declare const resolveCurrencyMetadata: <T extends CurrencyMetadataLike>(coinType?: string | null, configuredCurrencies?: readonly T[], fallbacks?: Partial<Omit<CurrencyMetadataLike, "type">>) => {
40
- symbol: string;
41
- name: string;
42
- decimals: number;
43
- };
44
- declare const resolveCoinDecimals: (coinType?: string | null, fallback?: number) => number;
45
- declare const resolveCoinSymbol: (coinType?: string | null, fallback?: string) => string;
46
- declare const createCurrencyDecimalsMap: <T extends Pick<CurrencyMetadataLike, "type" | "decimals">>(currencies: readonly T[]) => {
47
- [k: string]: number;
48
- };
49
- //#endregion
50
- export { CURRENCY_FAMILIES, ConfiguredCurrencyEntry, ConfiguredCurrencyId, CurrencyConfigInput, CurrencyFamilyDefinition, CurrencyFamilyId, CurrencyLike, CurrencyMetadataLike, buildConfiguredCurrencies, createCurrencyDecimalsMap, dedupeCurrenciesByType, normalizeCoinType, normalizeCoinTypeKey, resolveCoinDecimals, resolveCoinFamily, resolveCoinSymbol, resolveConfiguredCurrency, resolveCurrencyMetadata };
@@ -1,50 +0,0 @@
1
- //#region src/index.d.ts
2
- type CurrencyFamilyId = 'sui' | 'usdc';
3
- type CurrencyFamilyDefinition = {
4
- id: CurrencyFamilyId;
5
- symbol: string;
6
- name: string;
7
- decimals: number;
8
- suffixes: readonly string[];
9
- };
10
- type ConfiguredCurrencyId = 'sui' | 'usdc';
11
- type ConfiguredCurrencyEntry = {
12
- id: ConfiguredCurrencyId;
13
- familyId: CurrencyFamilyId;
14
- symbol: string;
15
- name: string;
16
- type: string;
17
- normalizedType: string;
18
- decimals: number;
19
- };
20
- type CurrencyConfigInput = {
21
- suiCoinType?: string | null;
22
- usdcCoinType?: string | null;
23
- };
24
- type CurrencyLike = {
25
- type: string;
26
- };
27
- type CurrencyMetadataLike = CurrencyLike & {
28
- symbol: string;
29
- name: string;
30
- decimals: number;
31
- };
32
- declare const CURRENCY_FAMILIES: readonly CurrencyFamilyDefinition[];
33
- declare const normalizeCoinType: (coinType: string) => string;
34
- declare const normalizeCoinTypeKey: (coinType?: string | null) => string;
35
- declare const dedupeCurrenciesByType: <T extends CurrencyLike>(currencies: readonly T[]) => T[];
36
- declare const resolveCoinFamily: (coinType?: string | null) => CurrencyFamilyDefinition | null;
37
- declare const buildConfiguredCurrencies: (config: CurrencyConfigInput) => ConfiguredCurrencyEntry[];
38
- declare const resolveConfiguredCurrency: <T extends CurrencyLike>(coinType: string | null | undefined, configuredCurrencies: readonly T[]) => T | null;
39
- declare const resolveCurrencyMetadata: <T extends CurrencyMetadataLike>(coinType?: string | null, configuredCurrencies?: readonly T[], fallbacks?: Partial<Omit<CurrencyMetadataLike, "type">>) => {
40
- symbol: string;
41
- name: string;
42
- decimals: number;
43
- };
44
- declare const resolveCoinDecimals: (coinType?: string | null, fallback?: number) => number;
45
- declare const resolveCoinSymbol: (coinType?: string | null, fallback?: string) => string;
46
- declare const createCurrencyDecimalsMap: <T extends Pick<CurrencyMetadataLike, "type" | "decimals">>(currencies: readonly T[]) => {
47
- [k: string]: number;
48
- };
49
- //#endregion
50
- export { CURRENCY_FAMILIES, ConfiguredCurrencyEntry, ConfiguredCurrencyId, CurrencyConfigInput, CurrencyFamilyDefinition, CurrencyFamilyId, CurrencyLike, CurrencyMetadataLike, buildConfiguredCurrencies, createCurrencyDecimalsMap, dedupeCurrenciesByType, normalizeCoinType, normalizeCoinTypeKey, resolveCoinDecimals, resolveCoinFamily, resolveCoinSymbol, resolveConfiguredCurrency, resolveCurrencyMetadata };
@@ -1,110 +0,0 @@
1
- //#region src/index.ts
2
- const CURRENCY_FAMILIES = [{
3
- id: "sui",
4
- symbol: "SUI",
5
- name: "Sui",
6
- decimals: 9,
7
- suffixes: ["::sui::sui", "::test_sui::test_sui"]
8
- }, {
9
- id: "usdc",
10
- symbol: "USDC",
11
- name: "USDC",
12
- decimals: 6,
13
- suffixes: ["::usdc::usdc", "::test_usdc::test_usdc"]
14
- }];
15
- const CONFIGURED_CURRENCY_SPECS = [{
16
- id: "sui",
17
- familyId: "sui",
18
- symbol: "SUI",
19
- name: "Sui",
20
- configKey: "suiCoinType"
21
- }, {
22
- id: "usdc",
23
- familyId: "usdc",
24
- symbol: "USDC",
25
- name: "USDC",
26
- configKey: "usdcCoinType"
27
- }];
28
- const DEFAULT_COIN_SYMBOL = "COIN";
29
- const DEFAULT_COIN_NAME = "Coin";
30
- const DEFAULT_COIN_DECIMALS = 9;
31
- const trimCoinType = (coinType) => typeof coinType === "string" ? coinType.trim() : "";
32
- const normalizeCoinType = (coinType) => {
33
- if (!coinType) return coinType;
34
- const parts = coinType.split("::");
35
- if (parts.length < 3) return `0x${((coinType.startsWith("0x") ? coinType.slice(2) : coinType).replace(/^0+/, "") || "0").toLowerCase()}`;
36
- const [rawAddress, module, ...rest] = parts;
37
- return [
38
- `0x${((rawAddress.startsWith("0x") ? rawAddress.slice(2) : rawAddress).replace(/^0+/, "") || "0").toLowerCase()}`,
39
- module,
40
- ...rest
41
- ].join("::");
42
- };
43
- const normalizeCoinTypeKey = (coinType) => {
44
- const trimmed = trimCoinType(coinType);
45
- return trimmed ? normalizeCoinType(trimmed).toLowerCase() : "";
46
- };
47
- const resolveFallbackSymbol = (coinType, fallback = DEFAULT_COIN_SYMBOL) => {
48
- const trimmed = trimCoinType(coinType);
49
- if (!trimmed) return fallback;
50
- const parts = trimmed.split("::").filter(Boolean);
51
- return (parts[parts.length - 1] ?? trimmed).replace(/\s+/g, "_").trim().toUpperCase() || fallback;
52
- };
53
- const dedupeCurrenciesByType = (currencies) => {
54
- const seen = /* @__PURE__ */ new Set();
55
- return currencies.filter((currency) => {
56
- const normalizedType = normalizeCoinTypeKey(currency.type);
57
- if (seen.has(normalizedType)) return false;
58
- seen.add(normalizedType);
59
- return true;
60
- });
61
- };
62
- const resolveCoinFamily = (coinType) => {
63
- const normalized = normalizeCoinTypeKey(coinType);
64
- if (!normalized) return null;
65
- for (const family of CURRENCY_FAMILIES) if (family.suffixes.some((suffix) => normalized.endsWith(suffix))) return family;
66
- return null;
67
- };
68
- const buildConfiguredCurrencies = (config) => dedupeCurrenciesByType(CONFIGURED_CURRENCY_SPECS.flatMap((spec) => {
69
- const type = trimCoinType(config[spec.configKey]);
70
- if (!type) return [];
71
- return [{
72
- id: spec.id,
73
- familyId: spec.familyId,
74
- symbol: spec.symbol,
75
- name: spec.name,
76
- type,
77
- normalizedType: normalizeCoinType(type),
78
- decimals: CURRENCY_FAMILIES.find((family) => family.id === spec.familyId)?.decimals ?? DEFAULT_COIN_DECIMALS
79
- }];
80
- }));
81
- const resolveConfiguredCurrency = (coinType, configuredCurrencies) => {
82
- const normalized = normalizeCoinTypeKey(coinType);
83
- if (!normalized) return null;
84
- return configuredCurrencies.find((currency) => normalizeCoinTypeKey(currency.type) === normalized) ?? null;
85
- };
86
- const resolveCurrencyMetadata = (coinType, configuredCurrencies = [], fallbacks = {}) => {
87
- const configuredCurrency = resolveConfiguredCurrency(coinType, configuredCurrencies);
88
- if (configuredCurrency) return {
89
- symbol: configuredCurrency.symbol,
90
- name: configuredCurrency.name,
91
- decimals: configuredCurrency.decimals
92
- };
93
- const family = resolveCoinFamily(coinType);
94
- if (family) return {
95
- symbol: family.symbol,
96
- name: family.name,
97
- decimals: family.decimals
98
- };
99
- const fallbackSymbol = resolveFallbackSymbol(coinType, fallbacks.symbol ?? DEFAULT_COIN_SYMBOL);
100
- return {
101
- symbol: fallbackSymbol,
102
- name: fallbacks.name ?? fallbackSymbol ?? DEFAULT_COIN_NAME,
103
- decimals: fallbacks.decimals ?? DEFAULT_COIN_DECIMALS
104
- };
105
- };
106
- const resolveCoinDecimals = (coinType, fallback = DEFAULT_COIN_DECIMALS) => resolveCurrencyMetadata(coinType, [], { decimals: fallback }).decimals;
107
- const resolveCoinSymbol = (coinType, fallback = DEFAULT_COIN_SYMBOL) => resolveCurrencyMetadata(coinType, [], { symbol: fallback }).symbol;
108
- const createCurrencyDecimalsMap = (currencies) => Object.fromEntries(currencies.map((currency) => [normalizeCoinTypeKey(currency.type), currency.decimals]).filter(([type]) => type.length > 0));
109
- //#endregion
110
- export { CURRENCY_FAMILIES, buildConfiguredCurrencies, createCurrencyDecimalsMap, dedupeCurrenciesByType, normalizeCoinType, normalizeCoinTypeKey, resolveCoinDecimals, resolveCoinFamily, resolveCoinSymbol, resolveConfiguredCurrency, resolveCurrencyMetadata };
@@ -1,31 +0,0 @@
1
- {
2
- "name": "@suigar/currency-registry",
3
- "version": "0.0.0",
4
- "description": "Shared currency metadata and coin helpers for Suigar",
5
- "private": true,
6
- "license": "UNLICENSED",
7
- "type": "module",
8
- "sideEffects": false,
9
- "main": "./dist/index.cjs",
10
- "module": "./dist/index.mjs",
11
- "types": "./dist/index.d.mts",
12
- "scripts": {
13
- "build": "tsdown",
14
- "clean": "rm -rf dist",
15
- "typecheck": "tsc --noEmit"
16
- },
17
- "exports": {
18
- ".": {
19
- "types": "./dist/index.d.mts",
20
- "require": "./dist/index.cjs",
21
- "import": "./dist/index.mjs"
22
- }
23
- },
24
- "files": [
25
- "dist"
26
- ],
27
- "devDependencies": {
28
- "tsdown": "catalog:tooling",
29
- "typescript": "catalog:tooling"
30
- }
31
- }