@slvr-labs/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/index.d.mts +2117 -0
- package/dist/index.d.ts +1903 -34
- package/dist/index.js +3091 -427
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3035 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +19 -11
- package/skills/slvr-bot/SKILL.md +9 -8
- package/skills/slvr-bot/references/api.md +8 -0
- package/dist/connect.d.ts +0 -47
- package/dist/connect.d.ts.map +0 -1
- package/dist/connect.js +0 -56
- package/dist/connect.js.map +0 -1
- package/dist/contracts/autoCommit.d.ts +0 -151
- package/dist/contracts/autoCommit.d.ts.map +0 -1
- package/dist/contracts/autoCommit.js +0 -426
- package/dist/contracts/autoCommit.js.map +0 -1
- package/dist/contracts/hub.d.ts +0 -50
- package/dist/contracts/hub.d.ts.map +0 -1
- package/dist/contracts/hub.js +0 -118
- package/dist/contracts/hub.js.map +0 -1
- package/dist/contracts/index.d.ts +0 -8
- package/dist/contracts/index.d.ts.map +0 -1
- package/dist/contracts/index.js +0 -18
- package/dist/contracts/index.js.map +0 -1
- package/dist/contracts/jackpot.d.ts +0 -21
- package/dist/contracts/jackpot.d.ts.map +0 -1
- package/dist/contracts/jackpot.js +0 -44
- package/dist/contracts/jackpot.js.map +0 -1
- package/dist/contracts/lottery.d.ts +0 -256
- package/dist/contracts/lottery.d.ts.map +0 -1
- package/dist/contracts/lottery.js +0 -767
- package/dist/contracts/lottery.js.map +0 -1
- package/dist/contracts/registry.d.ts +0 -53
- package/dist/contracts/registry.d.ts.map +0 -1
- package/dist/contracts/registry.js +0 -143
- package/dist/contracts/registry.js.map +0 -1
- package/dist/contracts/staking.d.ts +0 -101
- package/dist/contracts/staking.d.ts.map +0 -1
- package/dist/contracts/staking.js +0 -306
- package/dist/contracts/staking.js.map +0 -1
- package/dist/contracts/token.d.ts +0 -95
- package/dist/contracts/token.d.ts.map +0 -1
- package/dist/contracts/token.js +0 -273
- package/dist/contracts/token.js.map +0 -1
- package/dist/deployments.d.ts +0 -117
- package/dist/deployments.d.ts.map +0 -1
- package/dist/deployments.js +0 -74
- package/dist/deployments.js.map +0 -1
- package/dist/errors.d.ts +0 -39
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -67
- package/dist/errors.js.map +0 -1
- package/dist/ev.d.ts +0 -123
- package/dist/ev.d.ts.map +0 -1
- package/dist/ev.js +0 -111
- package/dist/ev.js.map +0 -1
- package/dist/events.d.ts +0 -418
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js +0 -87
- package/dist/events.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/oracle.d.ts +0 -48
- package/dist/oracle.d.ts.map +0 -1
- package/dist/oracle.js +0 -77
- package/dist/oracle.js.map +0 -1
- package/dist/price.d.ts +0 -52
- package/dist/price.d.ts.map +0 -1
- package/dist/price.js +0 -78
- package/dist/price.js.map +0 -1
- package/dist/transaction.d.ts +0 -54
- package/dist/transaction.d.ts.map +0 -1
- package/dist/transaction.js +0 -105
- package/dist/transaction.js.map +0 -1
- package/dist/types.d.ts +0 -162
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -23
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -58
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -110
- package/dist/utils.js.map +0 -1
package/dist/errors.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Custom error classes for the Slvr SDK
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TransactionError = exports.ValidationError = exports.ContractCallError = exports.WalletClientRequiredError = exports.SlvrSDKError = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Base error class for all SDK errors
|
|
9
|
-
*/
|
|
10
|
-
class SlvrSDKError extends Error {
|
|
11
|
-
constructor(message, code) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.code = code;
|
|
14
|
-
this.name = 'SlvrSDKError';
|
|
15
|
-
Object.setPrototypeOf(this, SlvrSDKError.prototype);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.SlvrSDKError = SlvrSDKError;
|
|
19
|
-
/**
|
|
20
|
-
* Error thrown when wallet client is required but not provided
|
|
21
|
-
*/
|
|
22
|
-
class WalletClientRequiredError extends SlvrSDKError {
|
|
23
|
-
constructor(operation) {
|
|
24
|
-
super(`Wallet client required for ${operation}`, 'WALLET_CLIENT_REQUIRED');
|
|
25
|
-
this.name = 'WalletClientRequiredError';
|
|
26
|
-
Object.setPrototypeOf(this, WalletClientRequiredError.prototype);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.WalletClientRequiredError = WalletClientRequiredError;
|
|
30
|
-
/**
|
|
31
|
-
* Error thrown when contract call fails
|
|
32
|
-
*/
|
|
33
|
-
class ContractCallError extends SlvrSDKError {
|
|
34
|
-
constructor(message, cause) {
|
|
35
|
-
super(message, 'CONTRACT_CALL_ERROR');
|
|
36
|
-
this.cause = cause;
|
|
37
|
-
this.name = 'ContractCallError';
|
|
38
|
-
Object.setPrototypeOf(this, ContractCallError.prototype);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ContractCallError = ContractCallError;
|
|
42
|
-
/**
|
|
43
|
-
* Error thrown when input validation fails
|
|
44
|
-
*/
|
|
45
|
-
class ValidationError extends SlvrSDKError {
|
|
46
|
-
constructor(message, field) {
|
|
47
|
-
super(message, 'VALIDATION_ERROR');
|
|
48
|
-
this.field = field;
|
|
49
|
-
this.name = 'ValidationError';
|
|
50
|
-
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.ValidationError = ValidationError;
|
|
54
|
-
/**
|
|
55
|
-
* Error thrown when transaction fails
|
|
56
|
-
*/
|
|
57
|
-
class TransactionError extends SlvrSDKError {
|
|
58
|
-
constructor(message, txHash, cause) {
|
|
59
|
-
super(message, 'TRANSACTION_ERROR');
|
|
60
|
-
this.txHash = txHash;
|
|
61
|
-
this.cause = cause;
|
|
62
|
-
this.name = 'TransactionError';
|
|
63
|
-
Object.setPrototypeOf(this, TransactionError.prototype);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.TransactionError = TransactionError;
|
|
67
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAkB,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAS;QAExD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAND,oCAMC;AAED;;GAEG;AACH,MAAa,yBAA0B,SAAQ,YAAY;IACzD,YAAY,SAAiB;QAC3B,KAAK,CAAC,8BAA8B,SAAS,EAAE,EAAE,wBAAwB,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC;CACF;AAND,8DAMC;AAED;;GAEG;AACH,MAAa,iBAAkB,SAAQ,YAAY;IACjD,YAAY,OAAe,EAAkB,KAAe;QAC1D,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;QADK,UAAK,GAAL,KAAK,CAAU;QAE1D,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAND,8CAMC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,OAAe,EAAkB,KAAc;QACzD,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QADQ,UAAK,GAAL,KAAK,CAAS;QAEzD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AACH,MAAa,gBAAiB,SAAQ,YAAY;IAChD,YACE,OAAe,EACC,MAAsB,EACtB,KAAe;QAE/B,KAAK,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAHpB,WAAM,GAAN,MAAM,CAAgB;QACtB,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAVD,4CAUC"}
|
package/dist/ev.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Expected-value math for SLVR grid mining.
|
|
3
|
-
*
|
|
4
|
-
* This is a direct port of the protocol's "grid-mining edge" model — the same
|
|
5
|
-
* math the web calculator uses — so an SDK bot and the site agree.
|
|
6
|
-
*
|
|
7
|
-
* ## The model
|
|
8
|
-
*
|
|
9
|
-
* The winning square each round is chosen **uniformly** at random over the
|
|
10
|
-
* {@link GRID_SIZE}-square grid (`randomnessValue % 25`), independent of how much
|
|
11
|
-
* was wagered where. Wagers only decide how the pot is split *among* the winners.
|
|
12
|
-
*
|
|
13
|
-
* The strategy this models is **grid mining**: spread your stake across the grid
|
|
14
|
-
* in proportion to the current pot so you always hold a `share = stake / pot`
|
|
15
|
-
* slice of whichever square wins. Under that strategy, per round:
|
|
16
|
-
*
|
|
17
|
-
* - **ETH is a wash minus the protocol fee.** The whole pot minus the fee is paid
|
|
18
|
-
* pro-rata to the winning square, and your slice of it equals your slice of the
|
|
19
|
-
* pot — i.e. you get back `(1 - fee) * stake` in expectation. So your ETH cost
|
|
20
|
-
* ("bleed") is exactly `feeFraction * stake`.
|
|
21
|
-
* - **SLVR is mined pro-rata:** `slvrMined = share * emissionPerRound`. (Whether a
|
|
22
|
-
* round is "single-miner" — winner-take-all SLVR — changes the *variance*, not
|
|
23
|
-
* the mean, so it does not affect EV.)
|
|
24
|
-
* - **Jackpot** pays your `share` of the pool with probability `1 / jackpotOdds`.
|
|
25
|
-
*
|
|
26
|
-
* Net EV per round (in ETH):
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
29
|
-
* netEth = slvrMined * slvrPriceEth * realize // SLVR value (realize = 1 - refineFee when cashing out)
|
|
30
|
-
* - feeFraction * stake // ETH bleed
|
|
31
|
-
* + (1 / jackpotOdds) * share * jackpotPool
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* Because both the SLVR reward and the bleed scale with `stake`, **the edge does
|
|
35
|
-
* not depend on how much you bet** — only on `pot` vs `slvrPriceEth`. A smaller
|
|
36
|
-
* pot means a bigger `share`, so mining is profitable while the pot is *below* the
|
|
37
|
-
* {@link GridMiningEv.breakEvenPot break-even pot}.
|
|
38
|
-
*/
|
|
39
|
-
/** Grid size — the winning square is `randomnessValue % GRID_SIZE`. */
|
|
40
|
-
export declare const GRID_SIZE = 25;
|
|
41
|
-
/** Probability any one square wins a round (uniform selection). */
|
|
42
|
-
export declare const SINGLE_SQUARE_WIN_PROBABILITY: number;
|
|
43
|
-
/** Default protocol fee in basis points (10%), taken out of the pot before winners. */
|
|
44
|
-
export declare const PROTOCOL_FEE_BPS = 1000;
|
|
45
|
-
/** Default SLVR refining fee in basis points (10%), charged when you cash SLVR out to ETH. */
|
|
46
|
-
export declare const REFINING_FEE_BPS = 1000;
|
|
47
|
-
/** Default jackpot odds — the jackpot fires when `randomnessValue % JACKPOT_ODDS == 0`. */
|
|
48
|
-
export declare const JACKPOT_ODDS = 625;
|
|
49
|
-
/**
|
|
50
|
-
* Inputs to {@link computeGridMiningEv}. All ETH-denominated values are plain
|
|
51
|
-
* numbers in whole ETH (not wei) and `slvrPriceEth` is ETH per SLVR — use
|
|
52
|
-
* `Number(formatEther(...))` to convert on-chain `bigint` wei.
|
|
53
|
-
*/
|
|
54
|
-
export interface GridMiningEvInput {
|
|
55
|
-
/** ETH you would commit to the round. */
|
|
56
|
-
stake: number;
|
|
57
|
-
/** Total ETH currently wagered in the round (the pot). */
|
|
58
|
-
pot: number;
|
|
59
|
-
/** SLVR minted to the winning square this round (the emission target). */
|
|
60
|
-
emissionPerRound: number;
|
|
61
|
-
/** Price of SLVR in ETH (ETH per SLVR). */
|
|
62
|
-
slvrPriceEth: number;
|
|
63
|
-
/** Protocol fee in bps. Defaults to {@link PROTOCOL_FEE_BPS} (1000 = 10%). */
|
|
64
|
-
feeBps?: number;
|
|
65
|
-
/**
|
|
66
|
-
* If `true`, value mined SLVR net of the refining fee (you intend to cash out
|
|
67
|
-
* to ETH). If `false` (default), value it at full price (you hold/stake it).
|
|
68
|
-
*/
|
|
69
|
-
cashOut?: boolean;
|
|
70
|
-
/** Refining fee in bps, applied only when `cashOut` is true. Defaults to {@link REFINING_FEE_BPS}. */
|
|
71
|
-
refineFeeBps?: number;
|
|
72
|
-
/** ETH currently in the jackpot pool. Defaults to 0 (jackpot ignored). */
|
|
73
|
-
jackpotPool?: number;
|
|
74
|
-
/** Jackpot odds (1-in-N per round). Defaults to {@link JACKPOT_ODDS} (625). */
|
|
75
|
-
jackpotOdds?: number;
|
|
76
|
-
}
|
|
77
|
-
/** Result of {@link computeGridMiningEv}. All ETH-denominated. */
|
|
78
|
-
export interface GridMiningEv {
|
|
79
|
-
/** Your fraction of the pot, `stake / pot`. */
|
|
80
|
-
share: number;
|
|
81
|
-
/** ETH lost per round to the protocol fee, `feeFraction * stake`. */
|
|
82
|
-
ethBleed: number;
|
|
83
|
-
/** SLVR mined per round, `share * emissionPerRound`. */
|
|
84
|
-
slvrMined: number;
|
|
85
|
-
/** ETH value of the mined SLVR after the realize factor. */
|
|
86
|
-
slvrValueEth: number;
|
|
87
|
-
/** Expected jackpot contribution per round, in ETH. */
|
|
88
|
-
jackpotEvEth: number;
|
|
89
|
-
/** Net EV per round excluding the jackpot, in ETH. */
|
|
90
|
-
netEthNoJackpot: number;
|
|
91
|
-
/** Net EV per round including the jackpot, in ETH. */
|
|
92
|
-
netEth: number;
|
|
93
|
-
/** Net EV as a fraction of stake (`netEth / stake`) — the per-round edge. */
|
|
94
|
-
edgeRatio: number;
|
|
95
|
-
/** Pot size at which `netEth` crosses zero. Mining is profitable below this. */
|
|
96
|
-
breakEvenPot: number;
|
|
97
|
-
/** SLVR price (ETH) at which `netEth` crosses zero for the current pot. */
|
|
98
|
-
breakEvenSlvrPriceEth: number;
|
|
99
|
-
/** Whether the round is +EV (`netEth > 0`). */
|
|
100
|
-
profitable: boolean;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Compute the per-round expected value of grid mining for a given stake, pot,
|
|
104
|
-
* emission and SLVR price. Pure function — does no I/O.
|
|
105
|
-
*
|
|
106
|
-
* @throws {Error} if `stake` or `pot` is not positive.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* import { computeGridMiningEv } from '@slvr-labs/sdk';
|
|
111
|
-
*
|
|
112
|
-
* const ev = computeGridMiningEv({
|
|
113
|
-
* stake: 0.1, // 0.1 ETH per round
|
|
114
|
-
* pot: 0.5, // 0.5 ETH in the pot
|
|
115
|
-
* emissionPerRound: 1, // 1 SLVR minted/round
|
|
116
|
-
* slvrPriceEth: 0.0005, // SLVR price in ETH
|
|
117
|
-
* jackpotPool: 5, // 5 ETH jackpot
|
|
118
|
-
* });
|
|
119
|
-
* if (ev.profitable) console.log(`+${ev.netEth} ETH/round, edge ${(ev.edgeRatio * 100).toFixed(1)}%`);
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export declare function computeGridMiningEv(input: GridMiningEvInput): GridMiningEv;
|
|
123
|
-
//# sourceMappingURL=ev.d.ts.map
|
package/dist/ev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ev.d.ts","sourceRoot":"","sources":["../src/ev.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,uEAAuE;AACvE,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,mEAAmE;AACnE,eAAO,MAAM,6BAA6B,QAAgB,CAAC;AAE3D,uFAAuF;AACvF,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,2FAA2F;AAC3F,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,CAAC;IACzB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sGAAsG;IACtG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,YAAY,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,qBAAqB,EAAE,MAAM,CAAC;IAC9B,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAwD1E"}
|
package/dist/ev.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Expected-value math for SLVR grid mining.
|
|
4
|
-
*
|
|
5
|
-
* This is a direct port of the protocol's "grid-mining edge" model — the same
|
|
6
|
-
* math the web calculator uses — so an SDK bot and the site agree.
|
|
7
|
-
*
|
|
8
|
-
* ## The model
|
|
9
|
-
*
|
|
10
|
-
* The winning square each round is chosen **uniformly** at random over the
|
|
11
|
-
* {@link GRID_SIZE}-square grid (`randomnessValue % 25`), independent of how much
|
|
12
|
-
* was wagered where. Wagers only decide how the pot is split *among* the winners.
|
|
13
|
-
*
|
|
14
|
-
* The strategy this models is **grid mining**: spread your stake across the grid
|
|
15
|
-
* in proportion to the current pot so you always hold a `share = stake / pot`
|
|
16
|
-
* slice of whichever square wins. Under that strategy, per round:
|
|
17
|
-
*
|
|
18
|
-
* - **ETH is a wash minus the protocol fee.** The whole pot minus the fee is paid
|
|
19
|
-
* pro-rata to the winning square, and your slice of it equals your slice of the
|
|
20
|
-
* pot — i.e. you get back `(1 - fee) * stake` in expectation. So your ETH cost
|
|
21
|
-
* ("bleed") is exactly `feeFraction * stake`.
|
|
22
|
-
* - **SLVR is mined pro-rata:** `slvrMined = share * emissionPerRound`. (Whether a
|
|
23
|
-
* round is "single-miner" — winner-take-all SLVR — changes the *variance*, not
|
|
24
|
-
* the mean, so it does not affect EV.)
|
|
25
|
-
* - **Jackpot** pays your `share` of the pool with probability `1 / jackpotOdds`.
|
|
26
|
-
*
|
|
27
|
-
* Net EV per round (in ETH):
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
30
|
-
* netEth = slvrMined * slvrPriceEth * realize // SLVR value (realize = 1 - refineFee when cashing out)
|
|
31
|
-
* - feeFraction * stake // ETH bleed
|
|
32
|
-
* + (1 / jackpotOdds) * share * jackpotPool
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* Because both the SLVR reward and the bleed scale with `stake`, **the edge does
|
|
36
|
-
* not depend on how much you bet** — only on `pot` vs `slvrPriceEth`. A smaller
|
|
37
|
-
* pot means a bigger `share`, so mining is profitable while the pot is *below* the
|
|
38
|
-
* {@link GridMiningEv.breakEvenPot break-even pot}.
|
|
39
|
-
*/
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.JACKPOT_ODDS = exports.REFINING_FEE_BPS = exports.PROTOCOL_FEE_BPS = exports.SINGLE_SQUARE_WIN_PROBABILITY = exports.GRID_SIZE = void 0;
|
|
42
|
-
exports.computeGridMiningEv = computeGridMiningEv;
|
|
43
|
-
/** Grid size — the winning square is `randomnessValue % GRID_SIZE`. */
|
|
44
|
-
exports.GRID_SIZE = 25;
|
|
45
|
-
/** Probability any one square wins a round (uniform selection). */
|
|
46
|
-
exports.SINGLE_SQUARE_WIN_PROBABILITY = 1 / exports.GRID_SIZE;
|
|
47
|
-
/** Default protocol fee in basis points (10%), taken out of the pot before winners. */
|
|
48
|
-
exports.PROTOCOL_FEE_BPS = 1000;
|
|
49
|
-
/** Default SLVR refining fee in basis points (10%), charged when you cash SLVR out to ETH. */
|
|
50
|
-
exports.REFINING_FEE_BPS = 1000;
|
|
51
|
-
/** Default jackpot odds — the jackpot fires when `randomnessValue % JACKPOT_ODDS == 0`. */
|
|
52
|
-
exports.JACKPOT_ODDS = 625;
|
|
53
|
-
/**
|
|
54
|
-
* Compute the per-round expected value of grid mining for a given stake, pot,
|
|
55
|
-
* emission and SLVR price. Pure function — does no I/O.
|
|
56
|
-
*
|
|
57
|
-
* @throws {Error} if `stake` or `pot` is not positive.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* import { computeGridMiningEv } from '@slvr-labs/sdk';
|
|
62
|
-
*
|
|
63
|
-
* const ev = computeGridMiningEv({
|
|
64
|
-
* stake: 0.1, // 0.1 ETH per round
|
|
65
|
-
* pot: 0.5, // 0.5 ETH in the pot
|
|
66
|
-
* emissionPerRound: 1, // 1 SLVR minted/round
|
|
67
|
-
* slvrPriceEth: 0.0005, // SLVR price in ETH
|
|
68
|
-
* jackpotPool: 5, // 5 ETH jackpot
|
|
69
|
-
* });
|
|
70
|
-
* if (ev.profitable) console.log(`+${ev.netEth} ETH/round, edge ${(ev.edgeRatio * 100).toFixed(1)}%`);
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
function computeGridMiningEv(input) {
|
|
74
|
-
const { stake, pot, emissionPerRound, slvrPriceEth, feeBps = exports.PROTOCOL_FEE_BPS, cashOut = false, refineFeeBps = exports.REFINING_FEE_BPS, jackpotPool = 0, jackpotOdds = exports.JACKPOT_ODDS, } = input;
|
|
75
|
-
if (!(stake > 0))
|
|
76
|
-
throw new Error(`stake must be positive (got ${stake})`);
|
|
77
|
-
if (!(pot > 0))
|
|
78
|
-
throw new Error(`pot must be positive (got ${pot})`);
|
|
79
|
-
const feeFraction = feeBps / 10000;
|
|
80
|
-
const realize = cashOut ? 1 - refineFeeBps / 10000 : 1;
|
|
81
|
-
const share = stake / pot;
|
|
82
|
-
const ethBleed = feeFraction * stake;
|
|
83
|
-
const slvrMined = share * emissionPerRound;
|
|
84
|
-
const slvrValueEth = slvrMined * slvrPriceEth * realize;
|
|
85
|
-
// Jackpot is ignored when odds are non-finite/non-positive or the pool is empty.
|
|
86
|
-
const jackpotEvEth = jackpotOdds > 0 && Number.isFinite(jackpotOdds) ? (1 / jackpotOdds) * share * jackpotPool : 0;
|
|
87
|
-
const netEthNoJackpot = slvrValueEth - ethBleed;
|
|
88
|
-
const netEth = netEthNoJackpot + jackpotEvEth;
|
|
89
|
-
// Solve netEth == 0 for pot and for slvrPriceEth (both independent of stake).
|
|
90
|
-
// netEth = (stake/pot)*(emit*price*realize + jackpotPool/odds) - feeFraction*stake
|
|
91
|
-
const perShareEthReward = emissionPerRound * slvrPriceEth * realize +
|
|
92
|
-
(jackpotOdds > 0 && Number.isFinite(jackpotOdds) ? jackpotPool / jackpotOdds : 0);
|
|
93
|
-
const breakEvenPot = feeFraction > 0 ? perShareEthReward / feeFraction : Infinity;
|
|
94
|
-
// Solve for the SLVR price that makes netEth == 0 at the current pot.
|
|
95
|
-
const slvrRewardDenom = share * emissionPerRound * realize;
|
|
96
|
-
const breakEvenSlvrPriceEth = slvrRewardDenom > 0 ? (ethBleed - jackpotEvEth) / slvrRewardDenom : Infinity;
|
|
97
|
-
return {
|
|
98
|
-
share,
|
|
99
|
-
ethBleed,
|
|
100
|
-
slvrMined,
|
|
101
|
-
slvrValueEth,
|
|
102
|
-
jackpotEvEth,
|
|
103
|
-
netEthNoJackpot,
|
|
104
|
-
netEth,
|
|
105
|
-
edgeRatio: netEth / stake,
|
|
106
|
-
breakEvenPot,
|
|
107
|
-
breakEvenSlvrPriceEth,
|
|
108
|
-
profitable: netEth > 0,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=ev.js.map
|
package/dist/ev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ev.js","sourceRoot":"","sources":["../src/ev.ts"],"names":[],"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