@xgamesfun/solana 0.24.0 → 0.25.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 (99) hide show
  1. package/DISCLAIMER.md +1 -1
  2. package/NOTICE +4 -4
  3. package/README.md +100 -52
  4. package/bin/xsolana.mjs +32 -11
  5. package/examples/blind-forge.json +2 -4
  6. package/examples/coin-flip-arena.json +2 -5
  7. package/examples/duel-arena.json +1 -4
  8. package/examples/fair-presale.json +1 -3
  9. package/examples/hero-trials.json +14 -2
  10. package/examples/ideas.json +788 -788
  11. package/examples/nft-raffle.json +1 -0
  12. package/examples/partner-vault.json +19 -3
  13. package/examples/sacrifice-raffle.json +2 -10
  14. package/examples/shelter-fair.json +1 -0
  15. package/examples/stakers-draw.json +4 -7
  16. package/examples/trade-in-shop.json +2 -3
  17. package/js/approve/details.mjs +117 -48
  18. package/js/approve/ed25519.mjs +5 -1
  19. package/js/approve/live-check.mjs +83 -26
  20. package/js/approve/page.html +217 -78
  21. package/js/approve/page.js +43 -15
  22. package/js/approve/server.mjs +276 -74
  23. package/js/chain/base58.js +7 -1
  24. package/js/chain/borsh.js +15 -11
  25. package/js/chain/bytes.js +11 -8
  26. package/js/chain/core.js +21 -5
  27. package/js/chain/curve.js +1 -1
  28. package/js/chain/lookup.js +118 -36
  29. package/js/chain/mint.js +6 -2
  30. package/js/chain/pda.js +2 -2
  31. package/js/chain/programs.js +6 -6
  32. package/js/chain/rpc.js +40 -14
  33. package/js/chain/token.js +13 -2
  34. package/js/chain/token2022.js +55 -16
  35. package/js/chain/tx.js +32 -22
  36. package/js/client/accounts.js +270 -80
  37. package/js/client/compressed.js +4 -3
  38. package/js/client/grant.js +165 -40
  39. package/js/client/idl/loot.js +1 -1
  40. package/js/client/idl/loot.json +104 -16
  41. package/js/client/ix.js +2121 -457
  42. package/js/client/pda.js +20 -18
  43. package/js/client/policy.js +12 -5
  44. package/js/client/random.js +2 -2
  45. package/js/client/sizes.js +220 -65
  46. package/js/client/traits.js +14 -5
  47. package/js/connect/connect.mjs +59 -17
  48. package/js/economy/check.mjs +3884 -690
  49. package/js/economy/cost.mjs +381 -57
  50. package/js/economy/examples.mjs +176 -35
  51. package/js/economy/explain.mjs +468 -110
  52. package/js/economy/guide.mjs +282 -59
  53. package/js/economy/legal.mjs +12 -6
  54. package/js/economy/live.mjs +62 -20
  55. package/js/economy/model.mjs +320 -97
  56. package/js/economy/plan.mjs +1022 -203
  57. package/js/economy/review.mjs +760 -0
  58. package/js/economy/schema.json +134 -372
  59. package/js/economy/secrets.mjs +17 -7
  60. package/js/economy/simulate.mjs +771 -178
  61. package/js/economy/trust.mjs +15 -0
  62. package/js/economy/txsize.mjs +15 -3
  63. package/js/economy/validate.mjs +61 -24
  64. package/js/index.js +1 -0
  65. package/js/mcp/server.mjs +43 -15
  66. package/js/mcp/tools.mjs +318 -80
  67. package/js/play/index.js +1960 -461
  68. package/js/play/keys.js +35 -9
  69. package/js/results/index.js +225 -32
  70. package/js/results/server.js +230 -0
  71. package/js/results/wire.js +64 -16
  72. package/package.json +6 -4
  73. package/release.json +5 -5
  74. package/skills/xsolana-economy/SKILL.md +52 -22
  75. package/skills/xsolana-economy/references/after-launch.md +32 -21
  76. package/skills/xsolana-economy/references/apps.md +47 -36
  77. package/skills/xsolana-economy/references/sentence-to-spec.md +149 -129
  78. package/skills/xsolana-economy/references/telling-the-person.md +15 -6
  79. package/skills/xsolana-economy/references/trust-and-cheating.md +126 -0
  80. package/types/chain/core.d.ts +1 -1
  81. package/types/chain/lookup.d.ts +1 -1
  82. package/types/client/accounts.d.ts +24 -3
  83. package/types/client/grant.d.ts +2 -2
  84. package/types/client/idl/loot.d.ts +22 -0
  85. package/types/client/ix.d.ts +54 -45
  86. package/types/client/pda.d.ts +3 -1
  87. package/types/economy/cost.d.mts +1 -1
  88. package/types/economy/explain.d.mts +3 -0
  89. package/types/economy/guide.d.mts +5 -0
  90. package/types/economy/model.d.mts +48 -3
  91. package/types/economy/plan.d.mts +44 -2
  92. package/types/economy/review.d.mts +45 -0
  93. package/types/economy/trust.d.mts +8 -0
  94. package/types/index.d.ts +1 -0
  95. package/types/mcp/tools.d.mts +62 -0
  96. package/types/play/index.d.ts +14 -25
  97. package/types/results/index.d.ts +8 -7
  98. package/types/results/server.d.ts +126 -0
  99. package/types/results/wire.d.ts +1 -1
@@ -451,6 +451,68 @@ export declare const tools: ({
451
451
  from: any;
452
452
  text: string;
453
453
  }>;
454
+ } | {
455
+ name: string;
456
+ annotations: {
457
+ readOnlyHint: boolean;
458
+ destructiveHint: boolean;
459
+ idempotentHint: boolean;
460
+ openWorldHint: boolean;
461
+ };
462
+ description: string;
463
+ inputSchema: {
464
+ type: string;
465
+ properties: {
466
+ spec: {
467
+ type: string;
468
+ description: string;
469
+ };
470
+ file: {
471
+ type: string;
472
+ description: string;
473
+ };
474
+ example: {
475
+ type: string;
476
+ description: string;
477
+ };
478
+ };
479
+ additionalProperties: boolean;
480
+ required?: undefined;
481
+ };
482
+ handler(input: any, ctx: any): Promise<{
483
+ ok: boolean;
484
+ from: any;
485
+ refusals: any;
486
+ warnings: any;
487
+ text: string;
488
+ } | {
489
+ ok: boolean;
490
+ from: any;
491
+ routes: ({
492
+ kind: string;
493
+ key: any;
494
+ name: any;
495
+ trigger: string;
496
+ enforced: any[];
497
+ trusts: any[];
498
+ trust: any;
499
+ ceiling: string;
500
+ feeds: any[];
501
+ } | {
502
+ kind: string;
503
+ key: any;
504
+ name: any;
505
+ trigger: string;
506
+ enforced: any[];
507
+ trusts: any;
508
+ trust: null;
509
+ ceiling: string;
510
+ feeds: any[];
511
+ })[];
512
+ findings: any[];
513
+ tradeoffs: string;
514
+ text: string;
515
+ }>;
454
516
  } | {
455
517
  name: string;
456
518
  annotations: {
@@ -22,7 +22,7 @@ export declare const units: (amount: any, decimals: any) => bigint;
22
22
  * be made again from the wallet's signature is kept, encrypted (`browserStore()` in a browser; null keeps keys in memory
23
23
  * only).
24
24
  */
25
- export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, keyStore }: {
25
+ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, keyStore, }: {
26
26
  keyStore?: {
27
27
  get: (k: any) => string | null;
28
28
  set: (k: any, v: any) => void;
@@ -691,7 +691,9 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
691
691
  * nothing but the lottery can take it while a place names it; the winner gets it before any ticket money moves.
692
692
  * `price` (whole units of `currency`) a ticket, `drawsAt` (Unix seconds) its one draw, `minSold` the least tickets
693
693
  * (fewer: the round is cancelled and refunded), `shares` where the ticket money goes (the seller's own wallet by
694
- * default: the treasury). A seller runs it in a project of their own, whose owner they are.
694
+ * default: the treasury). Its one place takes no money, so it keeps no pot: the round pays from its own ticket
695
+ * money, and what the shares leave goes to the treasury too. A seller runs it in a project of their own, whose
696
+ * owner they are.
695
697
  */
696
698
  raffle(id: any, nft: any, { price, currency, drawsAt, minSold, perWallet, shares, ...others }?: Readonly<Record<string, any>>): Promise<any>;
697
699
  /** The raffle's owner takes the NFT back out of lottery `id`'s own stash once nothing promises it (the lottery ended, or no place names it). */
@@ -729,65 +731,60 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
729
731
  * collectible to take home, an auction they won (or one off by the clock: their bid back), a lottery place they
730
732
  * won, a draw that is due (anyone may reveal it, or ask again when the oracle never answered; it takes 0.0008
731
733
  * SOL), and a drawn lottery's unpaid places, which anyone may pay so the next round can open. [{ kind, says, … }];
732
- * pass one to `claim`.
734
+ * a winner's first claim of a contest of tokens carries `potUnits` and `prizeUnits`, its part as the decision wrote
735
+ * it (base units, as text). Pass one to `claim`.
733
736
  */
734
737
  claims(): Promise<({
735
- key?: undefined;
736
738
  tree?: undefined;
737
739
  kind: string;
738
740
  order: any;
739
741
  says: string;
740
- id?: undefined;
741
- side?: undefined;
742
742
  hold?: undefined;
743
+ key?: undefined;
743
744
  round?: undefined;
744
745
  pulls?: undefined;
745
746
  asset?: undefined;
746
747
  table?: undefined;
747
748
  } | {
748
- key?: undefined;
749
749
  tree?: undefined;
750
750
  order?: undefined;
751
751
  kind: string;
752
752
  id: any;
753
753
  side: any;
754
754
  says: string;
755
+ potUnits?: string | undefined;
756
+ prizeUnits?: string | undefined;
755
757
  hold?: undefined;
758
+ key?: undefined;
756
759
  round?: undefined;
757
760
  pulls?: undefined;
758
761
  asset?: undefined;
759
762
  table?: undefined;
760
763
  } | {
761
- key?: undefined;
762
764
  tree?: undefined;
763
765
  order?: undefined;
764
- id?: undefined;
765
- side?: undefined;
766
766
  kind: string;
767
767
  asset: any;
768
768
  hold: any;
769
769
  says: string;
770
+ key?: undefined;
770
771
  round?: undefined;
771
772
  pulls?: undefined;
772
773
  table?: undefined;
773
774
  } | {
774
- key?: undefined;
775
775
  order?: undefined;
776
- id?: undefined;
777
- side?: undefined;
778
776
  hold?: undefined;
779
777
  kind: string;
780
778
  asset: string;
781
779
  tree: string;
782
780
  says: string;
781
+ key?: undefined;
783
782
  round?: undefined;
784
783
  pulls?: undefined;
785
784
  table?: undefined;
786
785
  } | {
787
786
  tree?: undefined;
788
787
  order?: undefined;
789
- id?: undefined;
790
- side?: undefined;
791
788
  hold?: undefined;
792
789
  kind: string;
793
790
  key: any;
@@ -799,8 +796,6 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
799
796
  } | {
800
797
  tree?: undefined;
801
798
  order?: undefined;
802
- id?: undefined;
803
- side?: undefined;
804
799
  hold?: undefined;
805
800
  kind: string;
806
801
  key: any;
@@ -812,8 +807,6 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
812
807
  } | {
813
808
  tree?: undefined;
814
809
  order?: undefined;
815
- id?: undefined;
816
- side?: undefined;
817
810
  hold?: undefined;
818
811
  kind: string;
819
812
  key: any;
@@ -823,12 +816,10 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
823
816
  asset?: undefined;
824
817
  table?: undefined;
825
818
  } | {
826
- key?: undefined;
827
819
  tree?: undefined;
828
820
  order?: undefined;
829
- id?: undefined;
830
- side?: undefined;
831
821
  hold?: undefined;
822
+ key?: undefined;
832
823
  round?: undefined;
833
824
  pulls?: undefined;
834
825
  kind: string;
@@ -836,12 +827,10 @@ export declare function solanaApp({ spec, rpcUrl, rpc, wallet, programs, now, ke
836
827
  says: string;
837
828
  table?: undefined;
838
829
  } | {
839
- key?: undefined;
840
830
  tree?: undefined;
841
831
  order?: undefined;
842
- id?: undefined;
843
- side?: undefined;
844
832
  hold?: undefined;
833
+ key?: undefined;
845
834
  round?: undefined;
846
835
  pulls?: undefined;
847
836
  asset?: undefined;
@@ -1,5 +1,5 @@
1
- export { canonicalJson, CERT_KINDS, CLUSTERS, drawText, entryText, giveawayHostText, hostCertText, lockText, NO_GRANT, RESULT_DOMAIN, resultBytes, revokeGiveawayText, revokeText, rosterHash } from './wire.js';
2
- /** games.fun's results server, on its play host (devnet until the program's audit). */
1
+ export { canonicalJson, CERT_KINDS, CLUSTERS, drawText, entryText, giveawayHostText, hostCertText, lockText, NO_GRANT, RESULT_DOMAIN, resultBytes, revokeGiveawayText, revokeText, rosterHash, } from './wire.js';
2
+ /** xgames.fun's results server, on its play host (devnet until the program's audit). */
3
3
  export declare const RESULTS_SERVER = "https://play.xgames.fun/xsolana";
4
4
  /** A fresh round id: 16 random bytes, in hex. Make it when the round starts. */
5
5
  export declare const newRound: () => string;
@@ -28,7 +28,7 @@ export declare function signResult(signer: any, result: any, cluster?: string):
28
28
  * with the same result is safe: it is the same answer. Returns the server's answer, { result, vouchers }, or throws its
29
29
  * { code, why }.
30
30
  */
31
- export declare function report({ server, cert, signer, game, round, endedAt, winners, cluster, fetchImpl }: {
31
+ export declare function report({ server, cert, signer, game, round, endedAt, winners, cluster, fetchImpl, }: {
32
32
  cert: any;
33
33
  cluster?: string | undefined;
34
34
  endedAt: any;
@@ -58,7 +58,7 @@ export declare function fetchVouchers({ server, game, round, wallet, fetchImpl }
58
58
  * Returns { wallet, grant, incarnation, publicKey, signature, round, expires, personHash, amount } for js/play claimGrant,
59
59
  * plain JSON (`incarnation` and `amount` as decimal text), so a server can send it as it is.
60
60
  */
61
- export declare function signVoucher({ signer, game, grant, incarnation, wallet, round, now, seconds, personHash, amount }: {
61
+ export declare function signVoucher({ signer, game, grant, incarnation, wallet, round, now, seconds, personHash, amount, }: {
62
62
  amount?: bigint | undefined;
63
63
  game: any;
64
64
  grant: any;
@@ -95,7 +95,7 @@ export declare const draws: {
95
95
  signMessage: any;
96
96
  }) => Promise<any>;
97
97
  /** A player enters with their play-host token, or with their wallet's signature (`wallet`, `signMessage`). */
98
- enter: ({ server, game, draw, token, wallet, signMessage, cluster, fetchImpl }: {
98
+ enter: ({ server, game, draw, token, wallet, signMessage, cluster, fetchImpl, }: {
99
99
  cluster?: string | undefined;
100
100
  draw: any;
101
101
  fetchImpl?: typeof fetch | undefined;
@@ -106,7 +106,7 @@ export declare const draws: {
106
106
  wallet?: null | undefined;
107
107
  }) => Promise<any>;
108
108
  /** Locks the players the server holds now to `beacon`, a drand round still to come. Checks their hash itself. */
109
- lock: ({ server, game, draw, beacon, signMessage, by, cert, cluster, net, fetchImpl }: {
109
+ lock: ({ server, game, draw, beacon, signMessage, by, cert, cluster, net, fetchImpl, }: {
110
110
  beacon: any;
111
111
  by: any;
112
112
  cert?: null | undefined;
@@ -141,7 +141,7 @@ export declare const giveaways: {
141
141
  winners: any;
142
142
  }) => Promise<any>;
143
143
  /** Reports its result, signed by its session key. `grant`: the host's grant (each winner is paid from it). */
144
- report: ({ server, game, giveaway, session, endedAt, winners, grant, cluster, fetchImpl }: {
144
+ report: ({ server, game, giveaway, session, endedAt, winners, grant, cluster, fetchImpl, }: {
145
145
  cluster?: string | undefined;
146
146
  endedAt: any;
147
147
  fetchImpl?: typeof fetch | undefined;
@@ -153,3 +153,4 @@ export declare const giveaways: {
153
153
  winners: any;
154
154
  }) => Promise<any>;
155
155
  };
156
+ export { codeAddresses, codeKey, codeVoucher, collectiblesOf, holds, makeCodes, normalizeCode, proofRequest, proofText, readProof, verifyProof, } from './server.js';
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The game's collectibles `wallet` holds now, read from the chain (Metaplex Core assets of the live spec's collection
3
+ * and of the collections it names): [{ asset, item (its key in the spec, or null), itemId, name, uri, attributes,
4
+ * frozen }]. `rpc`: an RPC link or a `rpcClient`. Token Metadata and compressed NFTs are not read here.
5
+ */
6
+ export declare function collectiblesOf({ rpc, spec, wallet }: {
7
+ rpc: any;
8
+ spec: any;
9
+ wallet: any;
10
+ }): Promise<{
11
+ owner: string;
12
+ collection: string | null;
13
+ name: string;
14
+ uri: string;
15
+ attributes: {};
16
+ frozen: boolean;
17
+ soulbound: boolean;
18
+ asset: any;
19
+ itemId: number | null;
20
+ item: any;
21
+ }[]>;
22
+ /**
23
+ * Whether `wallet` holds at least `atLeast` of the game's collectible `item` (its key in the spec), or of any of the
24
+ * game's collectibles when `item` is left out. With `attribute`, only those whose number under it is at least
25
+ * `minimum` count (a level, a rarity). → the count it holds when that is enough, else 0.
26
+ */
27
+ export declare function holds({ rpc, spec, wallet, item, atLeast, attribute, minimum }: {
28
+ atLeast?: number | undefined;
29
+ attribute?: null | undefined;
30
+ item?: null | undefined;
31
+ minimum?: number | undefined;
32
+ rpc: any;
33
+ spec: any;
34
+ wallet: any;
35
+ }): Promise<number>;
36
+ /** The exact text a wallet signs to prove it is its owner's: fixed lines, so nothing else can be passed off as it. */
37
+ export declare const proofText: ({ cluster, game, wallet, purpose, nonce, expires }: {
38
+ cluster?: string | undefined;
39
+ expires: any;
40
+ game: any;
41
+ nonce: any;
42
+ purpose: any;
43
+ wallet: any;
44
+ }) => string;
45
+ /**
46
+ * A proof to ask of `wallet`, made by the server: { text, nonce, expires }. The server keeps `nonce` until `expires`
47
+ * (unix seconds, `seconds` from now) and takes each nonce once, so a signed proof can't be replayed.
48
+ */
49
+ export declare function proofRequest({ cluster, game, wallet, purpose, seconds, now, }: {
50
+ cluster?: string | undefined;
51
+ game: any;
52
+ now?: number | undefined;
53
+ purpose?: string | undefined;
54
+ seconds?: number | undefined;
55
+ wallet: any;
56
+ }): {
57
+ text: string;
58
+ nonce: string;
59
+ expires: number;
60
+ };
61
+ /** A proof text's fields, or null when it is not one. */
62
+ export declare function readProof(text: any): {
63
+ expires: any;
64
+ } | null;
65
+ /**
66
+ * Checks a wallet's signed proof: the text is a proof for this `game` (and `purpose`, when given), for `wallet`, not
67
+ * expired at `now`, and `signature` (base58, or 64 bytes) is that wallet's Ed25519 signature of it. → the proof's
68
+ * fields ({ wallet, nonce, expires, … }), or throws in words. Taking each nonce once is the caller's: check
69
+ * `fields.nonce` against the ones the server handed out and not yet used.
70
+ */
71
+ export declare function verifyProof({ text, signature, wallet, game, purpose, cluster, now, }: {
72
+ cluster?: string | undefined;
73
+ game: any;
74
+ now?: number | undefined;
75
+ purpose?: null | undefined;
76
+ signature: any;
77
+ text: any;
78
+ wallet: any;
79
+ }): Promise<{
80
+ expires: any;
81
+ }>;
82
+ /**
83
+ * `n` fresh promo codes, each `bits` of randomness (80 by default, 16 characters of Crockford base32, in groups of 4).
84
+ * A code's key is in the spec for anyone to read, so a short code can be found by trying them all offline: fewer than
85
+ * 64 bits is refused.
86
+ */
87
+ export declare function makeCodes(n: any, { bits, group }?: {
88
+ bits?: number | undefined;
89
+ group?: number | undefined;
90
+ }): string[];
91
+ /** A code as typed, read the forgiving way (Crockford): case, spaces and dashes don't matter, O reads 0, I and L read 1. */
92
+ export declare const normalizeCode: (code: any) => string;
93
+ /** The key a code stands for: { address, sign } (Ed25519, its seed sha256 of the domain and the code). */
94
+ export declare function codeKey(code: any, { domain }?: {
95
+ domain?: string | undefined;
96
+ }): Promise<{
97
+ address: string;
98
+ sign: (message: any) => Promise<Uint8Array<ArrayBuffer>>;
99
+ }>;
100
+ /** The public keys for a grant's `keys`, one per code, in order. */
101
+ export declare const codeAddresses: (codes: any, options: any) => Promise<any[]>;
102
+ /**
103
+ * A voucher a typed code signs for `wallet` (the page, or a server, makes it): the grant pays it once per code with
104
+ * `limits.perKey: 1`. Its round is the code's own, so one wallet can't use one code twice either. `incarnation` is the
105
+ * grant's, read from the chain; `now` the cluster's clock.
106
+ */
107
+ export declare function codeVoucher({ code, game, grant, incarnation, wallet, now, seconds, domain, }: {
108
+ code: any;
109
+ domain?: string | undefined;
110
+ game: any;
111
+ grant: any;
112
+ incarnation: any;
113
+ now: any;
114
+ seconds?: number | undefined;
115
+ wallet: any;
116
+ }): Promise<{
117
+ wallet: any;
118
+ grant: any;
119
+ incarnation: string;
120
+ publicKey: any;
121
+ signature: string;
122
+ round: any;
123
+ expires: number;
124
+ personHash: string;
125
+ amount: string;
126
+ }>;
@@ -56,7 +56,7 @@ export declare const revokeText: ({ cluster, game, host }: {
56
56
  * `slug`: the game's play-host name (its tokens' audience), or '-'; `rates`: the sha256 of the engine's rates (canonical
57
57
  * JSON), or 'default'.
58
58
  */
59
- export declare const drawText: ({ cluster, game, draw, engine, winners, prizes, payout, identity, slug, rates }: {
59
+ export declare const drawText: ({ cluster, game, draw, engine, winners, prizes, payout, identity, slug, rates, }: {
60
60
  cluster?: string | undefined;
61
61
  draw: any;
62
62
  engine: any;