@xgamesfun/solana 0.20.1 → 0.24.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.
Files changed (70) hide show
  1. package/README.md +10 -10
  2. package/examples/coin-flip-arena.json +2 -7
  3. package/examples/elements-set.json +2 -9
  4. package/examples/expedition-guild.json +1 -8
  5. package/examples/guild-missions.json +3 -10
  6. package/examples/halving-seasons.json +4 -9
  7. package/examples/hero-trials.json +1 -4
  8. package/examples/merge-2048.json +5 -5
  9. package/examples/paper-hands-farm.json +4 -16
  10. package/examples/partner-vault.json +1 -4
  11. package/examples/stakers-draw.json +1 -8
  12. package/examples/star-fleet.json +1 -8
  13. package/examples/starforce.json +6 -6
  14. package/js/approve/details.mjs +8 -7
  15. package/js/approve/server.mjs +20 -5
  16. package/js/chain/borsh.js +9 -0
  17. package/js/chain/core.js +14 -2
  18. package/js/chain/lookup.js +8 -2
  19. package/js/chain/rpc.js +4 -2
  20. package/js/client/accounts.js +448 -116
  21. package/js/client/grant.js +125 -66
  22. package/js/client/idl/loot.js +1 -1
  23. package/js/client/idl/loot.json +2360 -2218
  24. package/js/client/index.js +1 -0
  25. package/js/client/ix.js +1204 -473
  26. package/js/client/pda.js +20 -16
  27. package/js/client/policy.js +44 -23
  28. package/js/client/random.js +70 -0
  29. package/js/client/sizes.js +255 -12
  30. package/js/economy/check.mjs +455 -210
  31. package/js/economy/cost.mjs +45 -30
  32. package/js/economy/examples.mjs +2 -2
  33. package/js/economy/explain.mjs +24 -20
  34. package/js/economy/guide.mjs +31 -30
  35. package/js/economy/live.mjs +30 -7
  36. package/js/economy/model.mjs +171 -56
  37. package/js/economy/plan.mjs +380 -112
  38. package/js/economy/schema.json +291 -143
  39. package/js/economy/simulate.mjs +154 -87
  40. package/js/mcp/tools.mjs +14 -8
  41. package/js/play/index.js +1121 -375
  42. package/js/play/keys.js +167 -0
  43. package/package.json +1 -1
  44. package/release.json +5 -5
  45. package/skills/xsolana-economy/SKILL.md +15 -11
  46. package/skills/xsolana-economy/references/after-launch.md +37 -27
  47. package/skills/xsolana-economy/references/apps.md +55 -19
  48. package/skills/xsolana-economy/references/sentence-to-spec.md +30 -22
  49. package/skills/xsolana-economy/references/telling-the-person.md +52 -11
  50. package/types/chain/core.d.ts +3 -1
  51. package/types/chain/lookup.d.ts +5 -2
  52. package/types/chain/rpc.d.ts +3 -1
  53. package/types/client/accounts.d.ts +195 -55
  54. package/types/client/grant.d.ts +72 -27
  55. package/types/client/idl/loot.d.ts +590 -559
  56. package/types/client/index.d.ts +1 -0
  57. package/types/client/ix.d.ts +3862 -234
  58. package/types/client/pda.d.ts +19 -15
  59. package/types/client/policy.d.ts +39 -14
  60. package/types/client/random.d.ts +26 -0
  61. package/types/client/sizes.d.ts +93 -5
  62. package/types/economy/check.d.mts +5 -10
  63. package/types/economy/cost.d.mts +2 -1
  64. package/types/economy/live.d.mts +16 -1
  65. package/types/economy/model.d.mts +105 -37
  66. package/types/economy/plan.d.mts +193 -192
  67. package/types/economy/simulate.d.mts +21 -13
  68. package/types/mcp/tools.d.mts +21 -13
  69. package/types/play/index.d.ts +450 -39
  70. package/types/play/keys.d.ts +51 -0
@@ -1,11 +1,12 @@
1
1
  // Grants: the bytes every voucher signer signs and `claim_grant` rebuilds, the approved list's Merkle tree, the
2
2
  // Ed25519 precompile instruction that carries a voucher's signature, and the claim itself. Browser-safe.
3
3
  //
4
- // voucherBytes "loot-grant-v4" | program (32) | grant (32) | incarnation (u64 LE) | wallet (32) | person_hash (32) | round (16) | expires (i64 LE) | amount (u64 LE)
4
+ // voucherBytes "loot-grant-v5" | sha256(program (32) | grant (32) | incarnation (u64 LE) | wallet (32) | person_hash (32) |
5
+ // expires (i64 LE) | count (u32 LE) | (round (16) | amount (u64 LE)) × count): a wallet's wins of several rounds
5
6
  // listLeaf sha256("loot-list-v3" | wallet (32) | person_hash (32) | round (16) | amount (u64 LE)): a wallet's win of one round
6
7
  //
7
- // `amount`: the tokens this claim gives, up to the grant's fixed amount (a rank's reward, a share); 0 for the grant's
8
- // prize as it is.
8
+ // `amount`: the tokens a round gives, up to the grant's fixed amount (a rank's reward, a share); 0 for the grant's
9
+ // prize as it is. A round pays a wallet once per grant incarnation, whoever signs it again, whenever.
9
10
  // keyLeaf sha256("loot-key-v1" | voucher key (32)): a key under a grant's key root (a promo code's)
10
11
  // merkleRoot a node = sha256(min(a, b) | max(a, b)) (byte-wise); an odd node at a level goes up unchanged
11
12
  // merkleProof the siblings from the leaf up (a promoted level adds none)
@@ -15,21 +16,25 @@
15
16
  // the tests (js/test/client.test.mjs).
16
17
  import { addressBytes } from '../chain/base58.js';
17
18
  import { compareBytes, concat, fromHex, intLE, readUintLE, toBigInt, uintLE, utf8 } from '../chain/bytes.js';
19
+ import { meta } from '../chain/programs.js';
18
20
  import { sha256 } from '../chain/sha256.js';
19
- import { ASSOCIATED_TOKEN_PROGRAM, gateAccounts, lootIx, prizeMetas, prizeNonce } from './ix.js';
21
+ import { recordKey16 } from './accounts.js';
22
+ import { ASSOCIATED_TOKEN_PROGRAM, gateAccounts, lootIx, prizeMetas, prizeNonce, tailOf } from './ix.js';
20
23
  import { LOOT_PROGRAM, pda } from './pda.js';
21
24
  import IDL from './idl/loot.js';
22
25
 
23
- export const VOUCHER_DOMAIN = 'loot-grant-v4';
26
+ export const VOUCHER_DOMAIN = 'loot-grant-v5';
24
27
  export const LIST_DOMAIN = 'loot-list-v3';
25
28
  export const KEY_DOMAIN = 'loot-key-v1';
26
- /** 13 + 32 × 4 + 8 + 16 + 8. */
27
- export const VOUCHER_BYTES = 181;
29
+ /** What a voucher key signs: the prefix (13 bytes), then the sha256 of the voucher's body. */
30
+ export const VOUCHER_BYTES = 45;
31
+ /** A grant claim's compute limit: its rounds' records and prizes can pass the 200,000 a transaction has by default. */
32
+ export const CLAIM_COMPUTE_UNITS = 400_000;
28
33
  export const ZERO_HASH = new Uint8Array(32);
29
34
  export const ED25519_PROGRAM = 'Ed25519SigVerify111111111111111111111111111';
30
- /** The seconds of the day a grant's daily limit counts claims in (the IDL's `DAY_SECONDS`). */
35
+ /** The seconds of a UTC day (the IDL's `DAY_SECONDS`): a limit's window of a day (`PerWallet.window`). */
31
36
  const DAY_SECONDS = Number(IDL.constants.find((c) => c.name === 'DAY_SECONDS').value);
32
- /** The day the program counts `per_day` in. */
37
+ /** The day a window of `DAY_SECONDS` counts in, from the unix epoch. */
33
38
  export const dayOf = (unixSeconds) => Math.floor(Number(unixSeconds) / DAY_SECONDS);
34
39
 
35
40
  /** 32 bytes from a base58 address, 32 bytes or 64 hex characters. */
@@ -54,26 +59,33 @@ function roundBytes(value) {
54
59
  /** An i64 little-endian (two's complement), as the program reads `expires`. */
55
60
  export const i64LE = (value) => intLE(value, 8);
56
61
 
62
+ /** A claim's rounds: [{ id (16 bytes or 32 hex characters), amount }], or one `round` and its `amount`. */
63
+ const roundsOf = (rounds, round, amount) => (rounds ?? [{ id: round, amount }]).map((r) => ({ id: roundBytes(r.id ?? r.round ?? new Uint8Array(16)), amount: toBigInt(r.amount ?? 0) }));
64
+
65
+ /** A voucher's body, which its key signs the sha256 of (`voucherBytes`). */
66
+ export function voucherBody({ program = LOOT_PROGRAM, grant, incarnation, wallet, personHash, expires, rounds, round, amount = 0n }) {
67
+ const list = roundsOf(rounds, round, amount);
68
+ return concat(bytes32(program, 'program'), bytes32(grant, 'grant'), uintLE(incarnation, 8), bytes32(wallet, 'wallet'), personBytes(personHash), i64LE(expires), uintLE(list.length, 4), ...list.flatMap((r) => [r.id, uintLE(r.amount, 8)]));
69
+ }
70
+
57
71
  /**
58
- * The 181 bytes a voucher key signs and `claim_grant` rebuilds from its own accounts and arguments. `round` names the
59
- * win (the project round, draw or giveaway it was won in): the program pays a wallet each round once per grant incarnation.
72
+ * The 45 bytes a voucher key signs and `claim_grant` rebuilds from its own accounts and arguments: the prefix, then the
73
+ * sha256 of the voucher's body (`voucherBody`), so a voucher of many rounds is as short to check as one of one. `rounds`
74
+ * ([{ id, amount }], or one `round` and its `amount`) names the wins (the project round, draw or giveaway each was won
75
+ * in): the program pays a wallet each round once per grant incarnation.
60
76
  */
61
- export function voucherBytes({ program = LOOT_PROGRAM, grant, incarnation, wallet, personHash, round, expires, amount = 0n }) {
62
- const out = concat(utf8(VOUCHER_DOMAIN), bytes32(program, 'program'), bytes32(grant, 'grant'), uintLE(incarnation, 8), bytes32(wallet, 'wallet'), personBytes(personHash), roundBytes(round), i64LE(expires), uintLE(amount, 8));
63
- if (out.length !== VOUCHER_BYTES) throw new Error(`a voucher is ${VOUCHER_BYTES} bytes, not ${out.length}`);
64
- return out;
65
- }
77
+ export const voucherBytes = (fields) => concat(utf8(VOUCHER_DOMAIN), sha256(voucherBody(fields)));
66
78
 
67
- /** The fields back from voucher bytes (addresses as bytes). */
68
- export function readVoucher(bytes) {
69
- if (!(bytes instanceof Uint8Array) || bytes.length !== VOUCHER_BYTES) throw new RangeError(`a voucher is ${VOUCHER_BYTES} bytes`);
70
- const n = VOUCHER_DOMAIN.length;
71
- if (new TextDecoder().decode(bytes.subarray(0, n)) !== VOUCHER_DOMAIN) throw new Error(`not a ${VOUCHER_DOMAIN} voucher`);
72
- const at = (i, len) => bytes.slice(i, i + len);
73
- let expires = 0n;
74
- for (let i = 7; i >= 0; i--) expires = (expires << 8n) | BigInt(bytes[n + 152 + i]);
79
+ /** The fields back from a voucher's body (`voucherBody`; addresses as bytes, rounds as [{ id, amount }]). */
80
+ export function readVoucher(body) {
81
+ if (!(body instanceof Uint8Array) || body.length < 148) throw new RangeError('a voucher body is at least 148 bytes');
82
+ const at = (i, len) => body.slice(i, i + len);
83
+ let expires = readUintLE(body, 136, 8);
75
84
  if (expires >= 1n << 63n) expires -= 1n << 64n;
76
- return { program: at(n, 32), grant: at(n + 32, 32), incarnation: readUintLE(bytes, n + 64, 8), wallet: at(n + 72, 32), personHash: at(n + 104, 32), round: at(n + 136, 16), expires, amount: readUintLE(bytes, n + 160, 8) };
85
+ const count = Number(readUintLE(body, 144, 4));
86
+ if (body.length !== 148 + 24 * count) throw new RangeError('a voucher body holds 24 bytes a round');
87
+ const rounds = Array.from({ length: count }, (_, i) => ({ id: at(148 + 24 * i, 16), amount: readUintLE(body, 164 + 24 * i, 8) }));
88
+ return { program: at(0, 32), grant: at(32, 32), incarnation: readUintLE(body, 64, 8), wallet: at(72, 32), personHash: at(104, 32), expires, rounds };
77
89
  }
78
90
 
79
91
  /** A voucher key's leaf under a grant's `key_root`. */
@@ -178,63 +190,110 @@ export function ed25519Ix({ publicKey, signature, message }) {
178
190
  return { programId: ED25519_PROGRAM, keys: [], data };
179
191
  }
180
192
 
193
+ /** The kinds of a grant's limit records (`limitKey`). */
194
+ const KINDS = Object.freeze({ wallet: 'wallet', person: 'person', badge: 'badge', code: 'code' });
195
+
196
+ /** The key of a grant's limit record of `kind` ('wallet', 'person', 'badge', 'code') for `subject` (an address or 32
197
+ * bytes): sha256(kind | subject)[..16]. */
198
+ export const limitKey = (kind, subject) => recordKey16(utf8(KINDS[kind] ?? kind), bytes32(subject, 'subject'));
199
+
200
+ /** The key of a wallet's record of a round a grant paid it: sha256(round | wallet)[..16]. */
201
+ export const roundKey = (round, wallet) => recordKey16(roundBytes(round), bytes32(wallet, 'wallet'));
202
+
203
+ /** The shard a record's key falls in, of a grant's `2^bits`: the top `bits` bits of its first byte. */
204
+ export const shardOf = (key, bits) => (Number(bits) ? key[0] >> (8 - Number(bits)) : 0);
205
+
206
+ /** The rounds shard a wallet's paid rounds are kept in: its own limit record's. */
207
+ export const walletShard = (grant, wallet) => shardOf(limitKey('wallet', wallet), grant.shard_bits);
208
+
209
+ /** Whether a grant paid `wallet` for `round`, from the wallet's decoded rounds shard (`decodeList`, null for none). */
210
+ export const roundPaid = (list, wallet, round) => Boolean(list?.records.some((r) => compareBytes(r, roundKey(round, wallet)) === 0));
211
+
212
+ /**
213
+ * The fewest shard bits (0 to 8) that keep each of a grant's lists under ~100,000 records over its life: `wallets` ×
214
+ * the rounds each may claim (`rounds`). A 10,000-wallet airdrop takes 0 (one shard).
215
+ */
216
+ export function shardBitsFor(wallets, rounds = 1) {
217
+ const records = Number(wallets) * Math.max(1, Number(rounds));
218
+ let bits = 0;
219
+ while (bits < 8 && records / 2 ** bits > 100_000) bits += 1;
220
+ return bits;
221
+ }
222
+
181
223
  /**
182
224
  * The claim of grant `id` for `wallet`, sent and signed by `signer` (anyone: the play host, the owner's server, the
183
- * player). The grant's funds pay its rent through the signer; what they can't cover, the signer pays. The signer pays
184
- * the player fee with its own SOL. `grant` is the decoded Grant; `count` the wallet's receipt count before this claim (0 for a
185
- * first claim); `poolMint` the mint of a Payout's pool, read from the pool.
186
- * A voucher claim goes right after `ed25519Ix` in the same transaction, `voucherKey` the key that signed it (its
187
- * counter is passed when the grant limits keys; a key under the key root carries its `proof`); a list claim carries
188
- * its `proof`; an open grant (no keys, no key root, no list) needs neither. What passes its gate (`shown`, or
189
- * `listProof` for a list gate) comes first. Its prize (`grant.gives`, `prizeMetas`)
190
- * follows: `poolMint` for tokens from a pool, `item` (the decoded Item) for a collectible or a compressed NFT of one, `nft` for an NFT of a stash;
191
- * a roll's order at `nonce` (`prizeNonce(grant, round, count)` by default), then the rolled box's prize mints
192
- * (`rollMints`: `boxes` maps the box's id to its decoded LootBox, null for one never written; `rollPools` each pool its
193
- * prizes name to its mint, null for one never opened). The grant's funds pay what it opens.
225
+ * player). The grant's funds pay its records through the signer; what they can't cover, the signer pays. The signer pays
226
+ * the player fee, and a roll's order, with its own SOL. `grant` is the decoded Grant.
227
+ *
228
+ * A voucher claim goes right after `ed25519Ix` in the same transaction, `voucherKey` the key that signed it (a key under
229
+ * the key root carries its proof as `proofs[0]`); a list claim carries a proof for each round (`proofs`); an open grant
230
+ * (no keys, no key root, no list) names no round and pays one prize (`count`: the wallet's claims before it, for its
231
+ * roll's nonce). `rounds` ([{ id, amount }], or one `round` and its `amount`) are the wins it names: each paid once, so
232
+ * one already paid is skipped (`paidRounds`: the wallet's decoded rounds shard, `decodeList`, to leave out its prize's
233
+ * accounts). What passes its gate (`shown`, or `listProof` for a list gate) comes first, then each shard of the grant's
234
+ * claims it counts in, then each round's prize (`grant.gives`, `prizeMetas`): `poolMint` for tokens from a pool, `item`
235
+ * (the decoded Item) for a collectible or a compressed NFT of one, `nft` for an NFT of a stash; round `i`'s roll at
236
+ * `prizeRollNonce(nonce + i)` (`nonce`: `prizeNonce` of the grant, the wallet and its rounds by default), its box and
237
+ * order only (`askRollIx` then asks for it, in the same transaction when it fits). Send it with a compute limit of
238
+ * `CLAIM_COMPUTE_UNITS`.
194
239
  */
195
- export function claimGrantIx({ project, id, grant, wallet, signer, count = 0, round, expires, personHash, amount = 0n, proof = [], poolMint, item, nft, boxes = {}, rollPools = {}, shown, listProof, programs, voucherKey, nonce, extra = [] }) {
240
+ export function claimGrantIx({ project, id, grant, wallet, signer, count = 0, rounds, round, expires, personHash, amount = 0n, proofs, proof = [], paidRounds = null, poolMint, item, nft, shown, listProof, programs, voucherKey, nonce, extra = [] }) {
196
241
  if (!signer) throw new Error('A claim needs its signer: whoever sends it');
197
242
  // Every claim is its winning wallet's own: the wallet signs it, whatever proves it (a voucher, a list, an open
198
243
  // grant), so nobody claims for a player (WalletMustSign). `signer` pays the fees and what the claim opens: the
199
244
  // wallet itself, or anyone who pays for it.
200
245
  const address = pda.grant(project, id);
201
246
  const person = personBytes(personHash);
202
- const hasPerson = person.some((b) => b !== 0);
203
- // A person a voucher names is counted when the grant limits persons; an open grant gated by an NFT
204
- // counts the NFT shown, at a badge's address (a grant never does both; both go in `person_receipt`).
247
+ const listed = Uint8Array.from(grant.list_root ?? []).some((b) => b !== 0);
248
+ // A claim by voucher or list names its rounds; an open one names none.
249
+ const named = Boolean(voucherKey) || listed || rounds != null || round != null;
250
+ const list = named ? roundsOf(rounds, round ?? new Uint8Array(16), amount) : [];
251
+ // The limit records it counts in: the wallet's, a person's a voucher names, the NFT an open claim of an open grant
252
+ // gated by one shows (a badge), a voucher key's; each shard of the grant's claims once, by shard number.
253
+ const bits = Number(grant.shard_bits ?? 0);
254
+ const keys = [limitKey('wallet', wallet)];
255
+ if (person.some((b) => b !== 0) && Number(grant.limits?.per_person ?? 0) > 0) keys.push(limitKey('person', person));
205
256
  const badge = typeof shown === 'string' ? shown : shown?.asset ?? shown?.mint ?? shown?.compressed;
206
- const counted = hasPerson && Number(grant.limits?.per_person ?? 0) > 0
207
- ? pda.person(address, grant.incarnation, person)
208
- : grant.open && grant.gate?.Holds && badge ? pda.badge(address, grant.incarnation, badge) : null;
209
- const accounts = {
210
- project,
211
- grant: address,
212
- signer,
213
- wallet,
214
- wallet_receipt: pda.grantReceipt(address, grant.incarnation, wallet),
215
- person_receipt: counted,
216
- code_receipt: voucherKey && Number(grant.limits?.per_key ?? 0) ? pda.code(address, grant.incarnation, voucherKey) : null,
217
- token_program: undefined,
218
- token_2022_program: undefined,
219
- associated_token_program: ASSOCIATED_TOKEN_PROGRAM,
220
- };
221
- const roundAt = roundBytes(round ?? new Uint8Array(16));
222
- nonce = toBigInt(nonce ?? prizeNonce(address, roundAt, toBigInt(count)));
223
- // The prize's accounts, after an NFT the wallet shows: `poolMint` a pool's mint, `item` the decoded Item of a
224
- // collectible (its next serial), `nft` an NFT's kind as `piece` takes it.
257
+ if (!named && grant.open && grant.gate?.Holds && badge) keys.push(limitKey('badge', badge));
258
+ if (voucherKey && Number(grant.limits?.per_key ?? 0) > 0) keys.push(limitKey('code', voucherKey));
259
+ const shards = [...new Set(keys.map((k) => shardOf(k, bits)))].sort((x, y) => x - y).map((shard) => meta(pda.claims(address, grant.incarnation, shard), false, true));
260
+ nonce = toBigInt(nonce ?? (named ? prizeNonce(address, wallet, ...list.map((r) => r.id)) : prizeNonce(address, wallet, toBigInt(count))));
261
+ // Each round not paid yet gives the grant's prize, or the amount of its tokens the round names, in order; collectibles
262
+ // of one item each at its next serial.
225
263
  const gives = grant.gives;
226
264
  const pool = gives.Tokens?.from.Pool?.[0];
227
265
  const itemId = gives.Item?.[0] ?? gives.Compressed?.item;
228
266
  if (pool !== undefined && !poolMint) throw new Error('A payout claim needs its pool’s mint (poolMint), read from the pool');
229
- const prize = prizeMetas({
230
- project, prize: gives, winner: wallet, nonce, programs,
231
- poolMints: pool !== undefined ? { [pool]: poolMint } : {}, items: itemId !== undefined ? { [itemId]: item } : {}, nft,
232
- strict: true, boxes, rollPools,
267
+ const seen = new Set();
268
+ const owed = (named ? list.map((r, i) => ({ ...r, i })) : [{ amount: 0n, i: 0 }]).filter((r) => {
269
+ if (!named) return true;
270
+ const hex = Array.from(r.id, (b) => b.toString(16).padStart(2, '0')).join('');
271
+ if (seen.has(hex) || roundPaid(paidRounds, wallet, r.id)) return false;
272
+ seen.add(hex);
273
+ return true;
233
274
  });
275
+ const prizes = owed.flatMap((r, made) => prizeMetas({
276
+ project, prize: r.amount > 0n && gives.Tokens ? { Tokens: { ...gives.Tokens, amount: r.amount } } : gives, winner: wallet, nonce: BigInt.asUintN(64, nonce + BigInt(r.i)), programs,
277
+ poolMints: pool !== undefined ? { [pool]: poolMint } : {}, items: itemId !== undefined ? { [itemId]: item } : {}, nft, made,
278
+ }));
279
+ proofs ??= listed && !voucherKey ? [proof] : proof.length ? [proof] : [];
234
280
  return lootIx(
235
281
  'claim_grant',
236
- { round: roundAt, expires: toBigInt(expires ?? 0), person_hash: person, amount: toBigInt(amount), proof: proof.map((p) => bytes32(p, 'proof')), nonce },
237
- accounts,
238
- { remaining: [...gateAccounts(project, { gate: grant.gate, wallet, shown, listProof }), ...prize, ...extra], signer: ['wallet'] },
282
+ { rounds: list, expires: toBigInt(expires ?? 0), person_hash: person, proofs: proofs.map((p) => p.map((x) => bytes32(x, 'proof'))), nonce },
283
+ {
284
+ project, grant: address, signer, wallet,
285
+ rounds: named ? pda.rounds(address, grant.incarnation, shardOf(keys[0], bits)) : null,
286
+ token_program: undefined, token_2022_program: undefined, associated_token_program: ASSOCIATED_TOKEN_PROGRAM,
287
+ },
288
+ { remaining: [...gateAccounts(project, { gate: grant.gate, wallet, shown, listProof }), ...shards, ...prizes, ...tailOf(extra)], signer: ['wallet'] },
239
289
  );
240
290
  }
291
+
292
+ /**
293
+ * Anyone closes shard `shard` of a grant's rounds (`rounds`) or claims once the grant is closed or made again
294
+ * (`incarnation` the one the shard is of): its rent goes to the project's `owner`.
295
+ */
296
+ export const closeShardIx = ({ project, id, incarnation, rounds = false, shard, owner }) => {
297
+ const grant = pda.grant(project, id);
298
+ return lootIx('close_shard', { id, incarnation: toBigInt(incarnation), rounds, shard }, { project, grant, shard: (rounds ? pda.rounds : pda.claims)(grant, incarnation, shard), owner });
299
+ };