@slvr-labs/sdk 0.1.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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +849 -0
  3. package/dist/connect.d.ts +47 -0
  4. package/dist/connect.d.ts.map +1 -0
  5. package/dist/connect.js +56 -0
  6. package/dist/connect.js.map +1 -0
  7. package/dist/contracts/autoCommit.d.ts +151 -0
  8. package/dist/contracts/autoCommit.d.ts.map +1 -0
  9. package/dist/contracts/autoCommit.js +426 -0
  10. package/dist/contracts/autoCommit.js.map +1 -0
  11. package/dist/contracts/hub.d.ts +50 -0
  12. package/dist/contracts/hub.d.ts.map +1 -0
  13. package/dist/contracts/hub.js +118 -0
  14. package/dist/contracts/hub.js.map +1 -0
  15. package/dist/contracts/index.d.ts +8 -0
  16. package/dist/contracts/index.d.ts.map +1 -0
  17. package/dist/contracts/index.js +18 -0
  18. package/dist/contracts/index.js.map +1 -0
  19. package/dist/contracts/jackpot.d.ts +21 -0
  20. package/dist/contracts/jackpot.d.ts.map +1 -0
  21. package/dist/contracts/jackpot.js +44 -0
  22. package/dist/contracts/jackpot.js.map +1 -0
  23. package/dist/contracts/lottery.d.ts +256 -0
  24. package/dist/contracts/lottery.d.ts.map +1 -0
  25. package/dist/contracts/lottery.js +767 -0
  26. package/dist/contracts/lottery.js.map +1 -0
  27. package/dist/contracts/registry.d.ts +53 -0
  28. package/dist/contracts/registry.d.ts.map +1 -0
  29. package/dist/contracts/registry.js +143 -0
  30. package/dist/contracts/registry.js.map +1 -0
  31. package/dist/contracts/staking.d.ts +101 -0
  32. package/dist/contracts/staking.d.ts.map +1 -0
  33. package/dist/contracts/staking.js +306 -0
  34. package/dist/contracts/staking.js.map +1 -0
  35. package/dist/contracts/token.d.ts +95 -0
  36. package/dist/contracts/token.d.ts.map +1 -0
  37. package/dist/contracts/token.js +273 -0
  38. package/dist/contracts/token.js.map +1 -0
  39. package/dist/deployments.d.ts +117 -0
  40. package/dist/deployments.d.ts.map +1 -0
  41. package/dist/deployments.js +74 -0
  42. package/dist/deployments.js.map +1 -0
  43. package/dist/errors.d.ts +39 -0
  44. package/dist/errors.d.ts.map +1 -0
  45. package/dist/errors.js +67 -0
  46. package/dist/errors.js.map +1 -0
  47. package/dist/ev.d.ts +123 -0
  48. package/dist/ev.d.ts.map +1 -0
  49. package/dist/ev.js +111 -0
  50. package/dist/ev.js.map +1 -0
  51. package/dist/events.d.ts +418 -0
  52. package/dist/events.d.ts.map +1 -0
  53. package/dist/events.js +87 -0
  54. package/dist/events.js.map +1 -0
  55. package/dist/index.d.ts +248 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +436 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/oracle.d.ts +48 -0
  60. package/dist/oracle.d.ts.map +1 -0
  61. package/dist/oracle.js +77 -0
  62. package/dist/oracle.js.map +1 -0
  63. package/dist/price.d.ts +52 -0
  64. package/dist/price.d.ts.map +1 -0
  65. package/dist/price.js +78 -0
  66. package/dist/price.js.map +1 -0
  67. package/dist/transaction.d.ts +54 -0
  68. package/dist/transaction.d.ts.map +1 -0
  69. package/dist/transaction.js +105 -0
  70. package/dist/transaction.js.map +1 -0
  71. package/dist/types.d.ts +162 -0
  72. package/dist/types.d.ts.map +1 -0
  73. package/dist/types.js +23 -0
  74. package/dist/types.js.map +1 -0
  75. package/dist/utils.d.ts +58 -0
  76. package/dist/utils.d.ts.map +1 -0
  77. package/dist/utils.js +110 -0
  78. package/dist/utils.js.map +1 -0
  79. package/examples/.env.example +22 -0
  80. package/examples/README.md +417 -0
  81. package/examples/automated-betting.ts +232 -0
  82. package/examples/combined-strategy.ts +227 -0
  83. package/examples/constants.ts +35 -0
  84. package/examples/custom-strategy-example.ts +231 -0
  85. package/examples/expected-value-strategy.ts +255 -0
  86. package/examples/fixed-squares-strategy.ts +176 -0
  87. package/examples/index.ts +30 -0
  88. package/examples/least-allocated-strategy.ts +224 -0
  89. package/examples/local-test.ts +172 -0
  90. package/examples/quickstart-bet.ts +72 -0
  91. package/examples/quickstart-read.ts +87 -0
  92. package/examples/simple-example.ts +122 -0
  93. package/examples/strategy-base.ts +283 -0
  94. package/package.json +71 -0
  95. package/skills/slvr-bot/SKILL.md +193 -0
  96. package/skills/slvr-bot/references/api.md +117 -0
package/dist/price.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SlvrPrice = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * Reads the SLVR price from the SLVR/ETH UniswapV2 pair.
7
+ *
8
+ * Mirrors the web app's price logic: it reads the pair's `getReserves()` and
9
+ * `token0()`, figures out which reserve is SLVR (never assumes ordering), and
10
+ * prices SLVR as `ethReserve / slvrReserve`. Both tokens are 18-decimal, so the
11
+ * raw reserve ratio is already ETH-per-SLVR.
12
+ *
13
+ * This is a **spot** price straight from reserves — no TWAP, no slippage model.
14
+ * Fine for sizing bets and EV estimates; do not use it as an oracle for anything
15
+ * that must resist manipulation.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { SlvrPrice } from '@slvr-labs/sdk';
20
+ * const price = new SlvrPrice(publicClient, pairAddress, slvrTokenAddress);
21
+ * const ethPerSlvr = await price.getPriceInEth();
22
+ * ```
23
+ */
24
+ class SlvrPrice {
25
+ constructor(publicClient, pairAddress, slvrTokenAddress) {
26
+ this.publicClient = publicClient;
27
+ this.pairAddress = pairAddress;
28
+ this.slvrTokenAddress = slvrTokenAddress;
29
+ }
30
+ /** Read the pair reserves and resolve which side is SLVR. */
31
+ async getReserves() {
32
+ const [reserves, token0] = await Promise.all([
33
+ this.publicClient.readContract({
34
+ address: this.pairAddress,
35
+ abi: SlvrPrice.PAIR_ABI,
36
+ functionName: 'getReserves',
37
+ }),
38
+ this.publicClient.readContract({
39
+ address: this.pairAddress,
40
+ abi: SlvrPrice.PAIR_ABI,
41
+ functionName: 'token0',
42
+ }),
43
+ ]);
44
+ const token0IsSlvr = token0.toLowerCase() === this.slvrTokenAddress.toLowerCase();
45
+ const slvrReserve = token0IsSlvr ? reserves[0] : reserves[1];
46
+ const ethReserve = token0IsSlvr ? reserves[1] : reserves[0];
47
+ return { slvrReserve, ethReserve, token0IsSlvr };
48
+ }
49
+ /**
50
+ * SLVR price in ETH (ETH per SLVR), as a floating-point number.
51
+ * @throws {Error} if the pair has no SLVR liquidity (zero reserve).
52
+ */
53
+ async getPriceInEth() {
54
+ const { slvrReserve, ethReserve } = await this.getReserves();
55
+ if (slvrReserve === 0n) {
56
+ throw new Error('SLVR/ETH pair has zero SLVR reserve; cannot price');
57
+ }
58
+ return Number(ethReserve) / Number(slvrReserve);
59
+ }
60
+ /**
61
+ * SLVR price in ETH as a WAD (1e18-scaled `bigint`), for callers that want to
62
+ * stay in integer math: `priceWad = ethReserve * 1e18 / slvrReserve`.
63
+ * @throws {Error} if the pair has no SLVR liquidity (zero reserve).
64
+ */
65
+ async getPriceInEthWad() {
66
+ const { slvrReserve, ethReserve } = await this.getReserves();
67
+ if (slvrReserve === 0n) {
68
+ throw new Error('SLVR/ETH pair has zero SLVR reserve; cannot price');
69
+ }
70
+ return (ethReserve * 10n ** 18n) / slvrReserve;
71
+ }
72
+ }
73
+ exports.SlvrPrice = SlvrPrice;
74
+ SlvrPrice.PAIR_ABI = (0, viem_1.parseAbi)([
75
+ 'function getReserves() view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)',
76
+ 'function token0() view returns (address)',
77
+ ]);
78
+ //# sourceMappingURL=price.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price.js","sourceRoot":"","sources":["../src/price.ts"],"names":[],"mappings":";;;AAAA,+BAAuD;AAcvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,SAAS;IAUpB,YAAY,YAA0B,EAAE,WAAoB,EAAE,gBAAyB;QACrF,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,WAAW,G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AW,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC7D,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,CAAC,UAAU,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC;IACjD,CAAC;;AA5DH,8BA6DC;AAxDyB,kBAAQ,GAAG,IAAA,eAAQ,EAAC;IAC1C,qGAAqG;IACrG,0CAA0C;CAC3C,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { PublicClient, WalletClient, Address } from 'viem';
2
+ /**
3
+ * Options for transaction execution
4
+ */
5
+ export interface TransactionOptions {
6
+ /** Maximum gas to use */
7
+ gas?: bigint;
8
+ /** Gas price (legacy) */
9
+ gasPrice?: bigint;
10
+ /** Max fee per gas (EIP-1559) */
11
+ maxFeePerGas?: bigint;
12
+ /** Max priority fee per gas (EIP-1559) */
13
+ maxPriorityFeePerGas?: bigint;
14
+ /** Whether to wait for transaction receipt */
15
+ waitForReceipt?: boolean;
16
+ /** Timeout for waiting for receipt (milliseconds) */
17
+ receiptTimeout?: number;
18
+ }
19
+ /**
20
+ * Estimate gas for a contract write operation
21
+ * @param publicClient Public client
22
+ * @param address Contract address
23
+ * @param abi Contract ABI
24
+ * @param functionName Function name
25
+ * @param args Function arguments
26
+ * @param value Optional value to send
27
+ * @param account Optional account address
28
+ * @returns Estimated gas
29
+ */
30
+ export declare function estimateGas(publicClient: PublicClient, address: Address, abi: readonly unknown[], functionName: string, args: unknown[], value?: bigint, account?: Address): Promise<bigint>;
31
+ /**
32
+ * Wait for transaction receipt with error handling
33
+ * @param publicClient Public client
34
+ * @param hash Transaction hash
35
+ * @param timeout Timeout in milliseconds
36
+ * @returns Transaction receipt
37
+ * @throws TransactionError if transaction fails or times out
38
+ */
39
+ export declare function waitForReceipt(publicClient: PublicClient, hash: `0x${string}`, timeout?: number): Promise<unknown>;
40
+ /**
41
+ * Execute a contract write with options
42
+ * @param walletClient Wallet client
43
+ * @param publicClient Public client
44
+ * @param address Contract address
45
+ * @param abi Contract ABI
46
+ * @param functionName Function name
47
+ * @param args Function arguments
48
+ * @param options Transaction options
49
+ * @returns Transaction hash or receipt
50
+ */
51
+ export declare function executeTransaction(walletClient: WalletClient, publicClient: PublicClient, address: Address, abi: readonly unknown[], functionName: string, args: unknown[], options?: TransactionOptions & {
52
+ value?: bigint;
53
+ }): Promise<`0x${string}` | unknown>;
54
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG3D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,8CAA8C;IAC9C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,SAAS,OAAO,EAAE,EACvB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,EAAE,EACf,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,KAAK,MAAM,EAAE,EACnB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,OAAO,CAAC,CA4BlB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,SAAS,OAAO,EAAE,EACvB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,EAAE,EACf,OAAO,GAAE,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GACpD,OAAO,CAAC,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,CAwClC"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateGas = estimateGas;
4
+ exports.waitForReceipt = waitForReceipt;
5
+ exports.executeTransaction = executeTransaction;
6
+ const errors_1 = require("./errors");
7
+ /**
8
+ * Estimate gas for a contract write operation
9
+ * @param publicClient Public client
10
+ * @param address Contract address
11
+ * @param abi Contract ABI
12
+ * @param functionName Function name
13
+ * @param args Function arguments
14
+ * @param value Optional value to send
15
+ * @param account Optional account address
16
+ * @returns Estimated gas
17
+ */
18
+ async function estimateGas(publicClient, address, abi, functionName, args, value, account) {
19
+ try {
20
+ const estimateParams = {
21
+ address,
22
+ abi,
23
+ functionName,
24
+ args,
25
+ };
26
+ if (value !== undefined) {
27
+ estimateParams.value = value;
28
+ }
29
+ if (account !== undefined) {
30
+ estimateParams.account = account;
31
+ }
32
+ const gas = await publicClient.estimateContractGas(estimateParams);
33
+ return gas;
34
+ }
35
+ catch (error) {
36
+ throw new errors_1.TransactionError(`Failed to estimate gas for ${functionName}: ${error instanceof Error ? error.message : String(error)}`, undefined, error);
37
+ }
38
+ }
39
+ /**
40
+ * Wait for transaction receipt with error handling
41
+ * @param publicClient Public client
42
+ * @param hash Transaction hash
43
+ * @param timeout Timeout in milliseconds
44
+ * @returns Transaction receipt
45
+ * @throws TransactionError if transaction fails or times out
46
+ */
47
+ async function waitForReceipt(publicClient, hash, timeout = 120000) {
48
+ try {
49
+ const receipt = await publicClient.waitForTransactionReceipt({
50
+ hash,
51
+ timeout,
52
+ });
53
+ // Check if transaction failed
54
+ if (receipt && typeof receipt === 'object' && 'status' in receipt) {
55
+ if (receipt.status === 'reverted') {
56
+ throw new errors_1.TransactionError(`Transaction reverted: ${hash}`, hash);
57
+ }
58
+ }
59
+ return receipt;
60
+ }
61
+ catch (error) {
62
+ if (error instanceof errors_1.TransactionError) {
63
+ throw error;
64
+ }
65
+ throw new errors_1.TransactionError(`Failed to wait for transaction receipt: ${error instanceof Error ? error.message : String(error)}`, hash, error);
66
+ }
67
+ }
68
+ /**
69
+ * Execute a contract write with options
70
+ * @param walletClient Wallet client
71
+ * @param publicClient Public client
72
+ * @param address Contract address
73
+ * @param abi Contract ABI
74
+ * @param functionName Function name
75
+ * @param args Function arguments
76
+ * @param options Transaction options
77
+ * @returns Transaction hash or receipt
78
+ */
79
+ async function executeTransaction(walletClient, publicClient, address, abi, functionName, args, options = {}) {
80
+ const { gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, waitForReceipt: waitForReceipt_, receiptTimeout, value, } = options;
81
+ const writeParams = {
82
+ address,
83
+ abi,
84
+ functionName,
85
+ args,
86
+ account: walletClient.account,
87
+ chain: null,
88
+ ...(value !== undefined && { value }),
89
+ ...(gas !== undefined && { gas }),
90
+ ...(gasPrice !== undefined && { gasPrice }),
91
+ ...(maxFeePerGas !== undefined && { maxFeePerGas }),
92
+ ...(maxPriorityFeePerGas !== undefined && { maxPriorityFeePerGas }),
93
+ };
94
+ try {
95
+ const hash = await walletClient.writeContract(writeParams);
96
+ if (waitForReceipt_) {
97
+ return await waitForReceipt(publicClient, hash, receiptTimeout);
98
+ }
99
+ return hash;
100
+ }
101
+ catch (error) {
102
+ throw new errors_1.TransactionError(`Failed to execute transaction: ${error instanceof Error ? error.message : String(error)}`, undefined, error);
103
+ }
104
+ }
105
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":";;AAgCA,kCA+BC;AAUD,wCAgCC;AAaD,gDAgDC;AArKD,qCAA4C;AAoB5C;;;;;;;;;;GAUG;AACI,KAAK,UAAU,WAAW,CAC/B,YAA0B,EAC1B,OAAgB,EAChB,GAAuB,EACvB,YAAoB,EACpB,IAAe,EACf,KAAc,EACd,OAAiB;IAEjB,IAAI,CAAC;QACH,MAAM,cAAc,GAAQ;YAC1B,OAAO;YACP,GAAG;YACH,YAAY;YACZ,IAAI;SACL,CAAC;QACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,cAAc,CAAC,KAAK,GAAG,KAAK,CAAC;QAC/B,CAAC;QACD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC;QACnC,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACnE,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,yBAAgB,CACxB,8BAA8B,YAAY,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACvG,SAAS,EACT,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,cAAc,CAClC,YAA0B,EAC1B,IAAmB,EACnB,UAAkB,MAAM;IAExB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,yBAAyB,CAAC;YAC3D,IAAI;Y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,CAAC;QAC3C,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC;QACnD,GAAG,CAAC,oBAAoB,KAAK,SAAS,IAAI,EAAE,oBAAoB,EAAE,CAAC;KAChB,CAAC;IAEtD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAE3D,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,MAAM,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,yBAAgB,CACxB,kCAAkC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC1F,SAAS,EACT,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,162 @@
1
+ import { Address, PublicClient, WalletClient } from 'viem';
2
+ /**
3
+ * Configuration for the Slvr SDK
4
+ */
5
+ export interface SlvrConfig {
6
+ /** Public client for read operations */
7
+ publicClient: PublicClient;
8
+ /** Wallet client for write operations (optional, required for transactions) */
9
+ walletClient?: WalletClient;
10
+ /** Contract addresses */
11
+ addresses: {
12
+ lottery: Address;
13
+ staking: Address;
14
+ token: Address;
15
+ autoCommit?: Address;
16
+ /** SlvrHub address (optional, for emission/staker/jackpot stats and keeper/admin ops) */
17
+ hub?: Address;
18
+ /** SlvrGameRegistry address (optional, for game weight/status stats) */
19
+ registry?: Address;
20
+ /** SlvrJackpot address (optional, for jackpot pool reads) */
21
+ jackpot?: Address;
22
+ /** SLVR/ETH UniswapV2 pair address (optional, enables `sdk.price` SLVR price reads) */
23
+ slvrEthPair?: Address;
24
+ /**
25
+ * Chainlink-style ETH/USD price feed address (optional, enables `sdk.ethUsd`
26
+ * and USD-denominated prices). Only set on chains that actually have a feed.
27
+ */
28
+ chainlinkEthUsd?: Address;
29
+ };
30
+ }
31
+ /**
32
+ * A SLVR price quote in both ETH and USD.
33
+ */
34
+ export interface PriceQuote {
35
+ /** Price in ETH (ETH per SLVR). */
36
+ eth: number;
37
+ /** Price in USD, or `null` if no ETH/USD source was available. */
38
+ usd: number | null;
39
+ }
40
+ /**
41
+ * Round information
42
+ */
43
+ export interface RoundInfo {
44
+ roundId: bigint;
45
+ requestedAt: bigint;
46
+ resolved: boolean;
47
+ randomnessId: `0x${string}`;
48
+ randomnessValue: bigint;
49
+ winningSquare: number;
50
+ jackpotHit: boolean;
51
+ singleMinerRound: boolean;
52
+ singleMinerWinner: Address;
53
+ totalWager: bigint;
54
+ fee: bigint;
55
+ winnerTotal: bigint;
56
+ potForWinners: bigint;
57
+ slvrForWinners: bigint;
58
+ payoutMulWad: bigint;
59
+ slvrMulWad: bigint;
60
+ totalUnclaimedSlvr: bigint;
61
+ }
62
+ /**
63
+ * Miner state information
64
+ */
65
+ export interface MinerState {
66
+ rewardsSlvr: bigint;
67
+ refinedAccrued: bigint;
68
+ indexSnapshot: bigint;
69
+ hasAccount: boolean;
70
+ }
71
+ /**
72
+ * Treasury state information
73
+ */
74
+ export interface TreasuryState {
75
+ minerIndex: bigint;
76
+ totalUnclaimed: bigint;
77
+ totalRefined: bigint;
78
+ jackpotPool: bigint;
79
+ }
80
+ /**
81
+ * Staking information for a staked veNFT tokenId
82
+ */
83
+ export interface StakingInfo {
84
+ /** Total tracked weight across all staked tokens */
85
+ totalWeight: bigint;
86
+ /** Tracked weight (balance) of this tokenId */
87
+ balance: bigint;
88
+ /** Claimable rewards for this tokenId */
89
+ rewards: bigint;
90
+ /** Accumulated reward per unit of weight (1e18 precision) */
91
+ rewardPerWeightStored: bigint;
92
+ }
93
+ /**
94
+ * AutoCommit plan information
95
+ */
96
+ export interface AutoCommitPlan {
97
+ enabled: boolean;
98
+ nextRoundId: bigint;
99
+ playsRemaining: number;
100
+ amountPerPlay: bigint;
101
+ balance: bigint;
102
+ autoClaim: boolean;
103
+ squares: number[];
104
+ bpsAlloc: number[];
105
+ planStartRoundId: bigint;
106
+ }
107
+ /**
108
+ * Game status in the registry (mirrors ISlvrGameRegistry.Status)
109
+ */
110
+ export declare enum GameStatus {
111
+ Pending = 0,
112
+ Active = 1,
113
+ Paused = 2,
114
+ Retired = 3
115
+ }
116
+ /**
117
+ * Game tier in the registry (mirrors ISlvrGameRegistry.Tier)
118
+ */
119
+ export declare enum GameTier {
120
+ Core = 0,
121
+ Community = 1,
122
+ Experimental = 2
123
+ }
124
+ /**
125
+ * Full registry record for a game (mirrors ISlvrGameRegistry.GameInfo)
126
+ */
127
+ export interface GameInfo {
128
+ game: Address;
129
+ gameType: `0x${string}`;
130
+ status: GameStatus;
131
+ tier: GameTier;
132
+ emissionWeight: number;
133
+ maxWeightBps: number;
134
+ exists: boolean;
135
+ }
136
+ /**
137
+ * Bet parameters
138
+ */
139
+ export interface BetParams {
140
+ roundId: bigint;
141
+ squares: number[];
142
+ amounts: bigint[];
143
+ beneficiary?: Address;
144
+ }
145
+ /**
146
+ * Claim parameters
147
+ */
148
+ export interface ClaimParams {
149
+ roundId: bigint;
150
+ }
151
+ /**
152
+ * Advanced claim parameters (unified claim function)
153
+ */
154
+ export interface ClaimParamsAdvanced {
155
+ user: Address;
156
+ roundId: bigint;
157
+ recipientNative?: Address;
158
+ recipientSlvr?: Address;
159
+ bypassFee?: boolean;
160
+ ethOnly?: boolean;
161
+ }
162
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,YAAY,EAAE,YAAY,CAAC;IAC3B,+EAA+E;IAC/E,YAA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MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GameTier = exports.GameStatus = void 0;
4
+ /**
5
+ * Game status in the registry (mirrors ISlvrGameRegistry.Status)
6
+ */
7
+ var GameStatus;
8
+ (function (GameStatus) {
9
+ GameStatus[GameStatus["Pending"] = 0] = "Pending";
10
+ GameStatus[GameStatus["Active"] = 1] = "Active";
11
+ GameStatus[GameStatus["Paused"] = 2] = "Paused";
12
+ GameStatus[GameStatus["Retired"] = 3] = "Retired";
13
+ })(GameStatus || (exports.GameStatus = GameStatus = {}));
14
+ /**
15
+ * Game tier in the registry (mirrors ISlvrGameRegistry.Tier)
16
+ */
17
+ var GameTier;
18
+ (function (GameTier) {
19
+ GameTier[GameTier["Core"] = 0] = "Core";
20
+ GameTier[GameTier["Community"] = 1] = "Community";
21
+ GameTier[GameTier["Experimental"] = 2] = "Experimental";
22
+ })(GameTier || (exports.GameTier = GameTier = {}));
23
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAkHA;;GAEG;AACH,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,iDAAW,CAAA;IACX,+CAAU,CAAA;IACV,+CAAU,CAAA;IACV,iDAAW,CAAA;AACb,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED;;GAEG;AACH,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,uCAAQ,CAAA;IACR,iDAAa,CAAA;IACb,uDAAgB,CAAA;AAClB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB"}
@@ -0,0 +1,58 @@
1
+ import { Address } from 'viem';
2
+ /**
3
+ * Validate and normalize an Ethereum address
4
+ * @param address Address to validate
5
+ * @param fieldName Field name for error message
6
+ * @returns Checksummed address
7
+ * @throws ValidationError if address is invalid
8
+ */
9
+ export declare function validateAddress(address: string, fieldName?: string): Address;
10
+ /**
11
+ * Validate that an amount is positive
12
+ * @param amount Amount to validate
13
+ * @param fieldName Field name for error message
14
+ * @throws ValidationError if amount is invalid
15
+ */
16
+ export declare function validateAmount(amount: bigint, fieldName?: string): void;
17
+ /**
18
+ * Validate square indices are within valid range
19
+ * @param squares Array of square indices
20
+ * @param gridSize Grid size (default 25)
21
+ * @throws ValidationError if squares are invalid
22
+ */
23
+ export declare function validateSquares(squares: number[], gridSize?: number): void;
24
+ /**
25
+ * Validate that arrays have matching lengths
26
+ * @param arrays Arrays to validate
27
+ * @param fieldNames Field names for error message
28
+ * @throws ValidationError if arrays don't match
29
+ */
30
+ export declare function validateArrayLengths(arrays: unknown[][], fieldNames: string[]): void;
31
+ /**
32
+ * Validate basis points (0-10000)
33
+ * @param bps Basis points value
34
+ * @param fieldName Field name for error message
35
+ * @throws ValidationError if bps is invalid
36
+ */
37
+ export declare function validateBps(bps: number, fieldName?: string): void;
38
+ /**
39
+ * Validate that basis points array sums to 10000
40
+ * @param bpsArray Array of basis points
41
+ * @param fieldName Field name for error message
42
+ * @throws ValidationError if bps don't sum to 10000
43
+ */
44
+ export declare function validateBpsSum(bpsArray: number[], fieldName?: string): void;
45
+ /**
46
+ * Wait for transaction receipt with timeout
47
+ * @param publicClient Public client
48
+ * @param hash Transaction hash
49
+ * @param timeout Timeout in milliseconds (default 120000 = 2 minutes)
50
+ * @returns Transaction receipt
51
+ */
52
+ export declare function waitForTransactionReceipt(publicClient: {
53
+ waitForTransactionReceipt?: (args: {
54
+ hash: `0x${string}`;
55
+ timeout?: number;
56
+ }) => Promise<unknown>;
57
+ }, hash: `0x${string}`, timeout?: number): Promise<unknown>;
58
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAyB,MAAM,MAAM,CAAC;AAGtD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,OAAO,CAKvF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiB,GAAG,IAAI,CAOjF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,MAAW,GAAG,IAAI,CAa9E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,CAgBpF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc,GAAG,IAAI,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,GAAE,MAAmB,GAAG,IAAI,CAQvF;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE;IAAE,yBAAyB,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,EACnH,IAAI,EAAE,KAAK,MAAM,EAAE,EACnB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,OAAO,CAAC,CAKlB"}
package/dist/utils.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAddress = validateAddress;
4
+ exports.validateAmount = validateAmount;
5
+ exports.validateSquares = validateSquares;
6
+ exports.validateArrayLengths = validateArrayLengths;
7
+ exports.validateBps = validateBps;
8
+ exports.validateBpsSum = validateBpsSum;
9
+ exports.waitForTransactionReceipt = waitForTransactionReceipt;
10
+ const viem_1 = require("viem");
11
+ const errors_1 = require("./errors");
12
+ /**
13
+ * Validate and normalize an Ethereum address
14
+ * @param address Address to validate
15
+ * @param fieldName Field name for error message
16
+ * @returns Checksummed address
17
+ * @throws ValidationError if address is invalid
18
+ */
19
+ function validateAddress(address, fieldName = 'address') {
20
+ if (!(0, viem_1.isAddress)(address)) {
21
+ throw new errors_1.ValidationError(`Invalid ${fieldName}: ${address}`, fieldName);
22
+ }
23
+ return (0, viem_1.getAddress)(address);
24
+ }
25
+ /**
26
+ * Validate that an amount is positive
27
+ * @param amount Amount to validate
28
+ * @param fieldName Field name for error message
29
+ * @throws ValidationError if amount is invalid
30
+ */
31
+ function validateAmount(amount, fieldName = 'amount') {
32
+ if (amount < 0n) {
33
+ throw new errors_1.ValidationError(`${fieldName} must be non-negative`, fieldName);
34
+ }
35
+ if (amount === 0n) {
36
+ throw new errors_1.ValidationError(`${fieldName} must be greater than zero`, fieldName);
37
+ }
38
+ }
39
+ /**
40
+ * Validate square indices are within valid range
41
+ * @param squares Array of square indices
42
+ * @param gridSize Grid size (default 25)
43
+ * @throws ValidationError if squares are invalid
44
+ */
45
+ function validateSquares(squares, gridSize = 25) {
46
+ if (squares.length === 0) {
47
+ throw new errors_1.ValidationError('At least one square must be provided', 'squares');
48
+ }
49
+ for (const square of squares) {
50
+ if (!Number.isInteger(square) || square < 0 || square >= gridSize) {
51
+ throw new errors_1.ValidationError(`Invalid square index: ${square}. Must be between 0 and ${gridSize - 1}`, 'squares');
52
+ }
53
+ }
54
+ }
55
+ /**
56
+ * Validate that arrays have matching lengths
57
+ * @param arrays Arrays to validate
58
+ * @param fieldNames Field names for error message
59
+ * @throws ValidationError if arrays don't match
60
+ */
61
+ function validateArrayLengths(arrays, fieldNames) {
62
+ if (arrays.length < 2) {
63
+ return;
64
+ }
65
+ const firstLength = arrays[0]?.length ?? 0;
66
+ for (let i = 1; i < arrays.length; i++) {
67
+ const currentArray = arrays[i];
68
+ const currentFieldName = fieldNames[i];
69
+ if (!currentArray || currentArray.length !== firstLength) {
70
+ throw new errors_1.ValidationError(`Array length mismatch: ${fieldNames[0]} has ${firstLength} items, but ${currentFieldName ?? `array ${i}`} has ${currentArray?.length ?? 0} items`, currentFieldName);
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Validate basis points (0-10000)
76
+ * @param bps Basis points value
77
+ * @param fieldName Field name for error message
78
+ * @throws ValidationError if bps is invalid
79
+ */
80
+ function validateBps(bps, fieldName = 'bps') {
81
+ if (!Number.isInteger(bps) || bps < 0 || bps > 10000) {
82
+ throw new errors_1.ValidationError(`${fieldName} must be an integer between 0 and 10000 (got ${bps})`, fieldName);
83
+ }
84
+ }
85
+ /**
86
+ * Validate that basis points array sums to 10000
87
+ * @param bpsArray Array of basis points
88
+ * @param fieldName Field name for error message
89
+ * @throws ValidationError if bps don't sum to 10000
90
+ */
91
+ function validateBpsSum(bpsArray, fieldName = 'bpsAlloc') {
92
+ const sum = bpsArray.reduce((acc, bps) => acc + bps, 0);
93
+ if (sum !== 10000) {
94
+ throw new errors_1.ValidationError(`${fieldName} must sum to 10000 (got ${sum})`, fieldName);
95
+ }
96
+ }
97
+ /**
98
+ * Wait for transaction receipt with timeout
99
+ * @param publicClient Public client
100
+ * @param hash Transaction hash
101
+ * @param timeout Timeout in milliseconds (default 120000 = 2 minutes)
102
+ * @returns Transaction receipt
103
+ */
104
+ async function waitForTransactionReceipt(publicClient, hash, timeout = 120000) {
105
+ if (!publicClient.waitForTransactionReceipt) {
106
+ throw new Error('Public client does not support waitForTransactionReceipt');
107
+ }
108
+ return await publicClient.waitForTransactionReceipt({ hash, timeout });
109
+ }
110
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAUA,0CAKC;AAQD,wCAOC;AAQD,0CAaC;AAQD,oDAgBC;AAQD,kCAOC;AAQD,wCAQC;AASD,8DASC;AA5HD,+BAAsD;AACtD,qCAA2C;AAE3C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,YAAoB,SAAS;IAC5E,IAAI,CAAC,IAAA,gBAAS,EAAC,OAAO,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,wBAAe,CAAC,WAAW,SAAS,KAAK,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,IAAA,iBAAU,EAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,YAAoB,QAAQ;IACzE,IAAI,MAAM,GAAG,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,wBAAe,CAAC,GAAG,SAAS,uBAAuB,EAAE,SAAS,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,wBAAe,CAAC,GAAG,SAAS,4BAA4B,EAAE,SAAS,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,OAAiB,EAAE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AAK;IAChE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,KAAK,EAAE,CAAC;QACrD,MAAM,IAAI,wBAAe,CACvB,GAAG,SAAS,gDAAgD,GAAG,GAAG,EAClE,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAkB,EAAE,YAAoB,UAAU;IAC/E,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;IACxD,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,wBAAe,CACvB,GAAG,SAAS,2BAA2B,GAAG,GAAG,EAC7C,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,yBAAyB,CAC7C,YAAmH,EACnH,IAAmB,EACnB,UAAkB,MAAM;IAExB,IAAI,CAAC,YAAY,CAAC,yBAAyB,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,MAAM,YAAY,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,22 @@
1
+ # Copy this file to `.env` and fill in your values.
2
+ #
3
+ # cp .env.example .env
4
+ #
5
+ # The examples read these from the environment. The simplest way to run with them
6
+ # set is inline (no .env needed at all):
7
+ #
8
+ # PRIVATE_KEY=0x... npx ts-node examples/quickstart-bet.ts
9
+ #
10
+ # If you prefer a .env file, load it into your shell before running, e.g.:
11
+ #
12
+ # set -a; source .env; set +a
13
+ # npx ts-node examples/quickstart-bet.ts
14
+
15
+ # Your wallet private key, hex with 0x prefix. REQUIRED for examples that bet.
16
+ # Use a fresh / burner key funded with a small amount of ETH — never a key that
17
+ # holds real value, and never commit the filled-in .env.
18
+ PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000000
19
+
20
+ # Optional: ETH/USD price override for USD display. Leave unset to use the
21
+ # on-chain Chainlink feed (wired for Robinhood Chain).
22
+ # ETH_USD=1815.98