@rhinestone/service-sdk 0.2.3 → 0.2.5
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/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +40 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/serialization.d.ts +29 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +106 -0
- package/package.json +6 -2
package/dist/chains.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG1D,KAAK,mBAAmB,GAAG,IAAI,CAC7B,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG1D,KAAK,mBAAmB,GAAG,IAAI,CAC7B,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;AA+CD,wBAAsB,eAAe,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,CAAC,CAM3B"}
|
package/dist/chains.js
CHANGED
|
@@ -2,22 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.estimateGasFees = estimateGasFees;
|
|
4
4
|
const chains_1 = require("viem/chains");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// Chains that price fees from eth_feeHistory instead of viem's default
|
|
6
|
+
// estimator (which sources the tip from the unspecified eth_maxPriorityFeePerGas
|
|
7
|
+
// oracle). L2s are intentionally absent — their sequencers include ~zero-tip
|
|
8
|
+
// txs, so the default is fine and a floor would just overpay.
|
|
9
|
+
const HISTORICAL_FEE_CHAINS = new Set([chains_1.sepolia.id, chains_1.mainnet.id]);
|
|
10
|
+
const DEFAULT_FEE_CONFIG = {
|
|
11
|
+
historyBlocks: 1,
|
|
12
|
+
baseFeeMultiplier: 2n,
|
|
13
|
+
// p50, not p75. The mainnet stalls we saw were caused by a *zero* tip, not by
|
|
14
|
+
// tipping below p75 — once the tip is non-zero a fill is reliably included, so
|
|
15
|
+
// a higher percentile buys no extra speed, only cost.
|
|
16
|
+
//
|
|
17
|
+
// Example — bundle 4225…447075 (2026-06-04): the fill broadcast with tip 0 and
|
|
18
|
+
// sat ~3 min. It was mineable (maxFee >= baseFee) for ~12 of its 16 stuck
|
|
19
|
+
// blocks yet still skipped, because a zero-tip tx earns the builder nothing
|
|
20
|
+
// (base fee is burned). The market was tipping p50 ~0.07-0.98 gwei the whole
|
|
21
|
+
// time — any non-zero tip would have gotten it in.
|
|
22
|
+
//
|
|
23
|
+
// At ~$1,800/ETH and ~383k gas/fill the tip runs ~$0.14 at p50 vs ~$0.68 at
|
|
24
|
+
// p75 (~5x), on *every* mainnet fill — not just the rare stuck one.
|
|
25
|
+
rewardPercentile: 50,
|
|
26
|
+
tipFloorWei: 100000000n, // 0.1 gwei (~$0.07/fill); see rewardPercentile
|
|
27
|
+
};
|
|
28
|
+
// Per-chain overrides; any omitted field falls back to DEFAULT_FEE_CONFIG.
|
|
29
|
+
const FEE_CONFIG_OVERRIDES = {
|
|
30
|
+
// Testnet — leave as-is: aggressive percentile, no floor (not real money).
|
|
31
|
+
[chains_1.sepolia.id]: { rewardPercentile: 75, tipFloorWei: 0n },
|
|
32
|
+
};
|
|
7
33
|
async function estimateGasFees(client, chainId) {
|
|
8
|
-
if (chainId
|
|
9
|
-
return
|
|
34
|
+
if (!HISTORICAL_FEE_CHAINS.has(chainId)) {
|
|
35
|
+
return client.estimateFeesPerGas();
|
|
10
36
|
}
|
|
11
|
-
|
|
37
|
+
const config = { ...DEFAULT_FEE_CONFIG, ...FEE_CONFIG_OVERRIDES[chainId] };
|
|
38
|
+
return estimateFeeHistoryGasFees(client, config);
|
|
12
39
|
}
|
|
13
|
-
|
|
40
|
+
// Priority fee = the latest block's reward at `rewardPercentile`, floored at
|
|
41
|
+
// `tipFloorWei`; maxFeePerGas = baseFee * baseFeeMultiplier + priorityFee.
|
|
42
|
+
async function estimateFeeHistoryGasFees(client, config) {
|
|
14
43
|
const feeHistory = await client.getFeeHistory({
|
|
15
|
-
blockCount:
|
|
16
|
-
rewardPercentiles: [
|
|
44
|
+
blockCount: config.historyBlocks,
|
|
45
|
+
rewardPercentiles: [config.rewardPercentile],
|
|
17
46
|
});
|
|
18
|
-
const
|
|
47
|
+
const reward = feeHistory.reward?.at(-1)?.[0] ?? 0n;
|
|
48
|
+
const priorityFee = reward > config.tipFloorWei ? reward : config.tipFloorWei;
|
|
19
49
|
const baseFee = feeHistory.baseFeePerGas.at(-1) ?? 0n;
|
|
20
|
-
const maxFeePerGas = baseFee *
|
|
50
|
+
const maxFeePerGas = baseFee * config.baseFeeMultiplier + priorityFee;
|
|
21
51
|
return {
|
|
22
52
|
maxFeePerGas,
|
|
23
53
|
maxPriorityFeePerGas: priorityFee,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './serialization';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./serialization"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const DEFAULT_BIGINT_CONVERSION_MAX_DEPTH = 100;
|
|
2
|
+
export interface ConvertBigIntFieldsOptions {
|
|
3
|
+
/** Maximum object/array nesting depth before conversion throws. */
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
/** Convert finite numbers to strings too. Defaults to false. */
|
|
6
|
+
convertFiniteNumbers?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** JSON.stringify replacer that converts bigint values to strings. */
|
|
9
|
+
export declare const bigintReplacer: (_: string, value: unknown) => unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Recursively converts bigint values to decimal strings.
|
|
12
|
+
*
|
|
13
|
+
* Intended for JSON-like plain objects/arrays. Pass `convertFiniteNumbers: true`
|
|
14
|
+
* for canonical-signing payloads that need number-like fields encoded as strings.
|
|
15
|
+
*
|
|
16
|
+
* Throws on circular references or excessive nesting instead of silently
|
|
17
|
+
* producing lossy placeholder values.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertBigIntFields(value: unknown, options?: ConvertBigIntFieldsOptions): unknown;
|
|
20
|
+
/**
|
|
21
|
+
* JSON.stringify with guarded bigint conversion.
|
|
22
|
+
*
|
|
23
|
+
* Preserves JSON.stringify semantics for `toJSON` (for example, Date -> ISO
|
|
24
|
+
* string) while adding bigint conversion plus circular/depth guards.
|
|
25
|
+
*/
|
|
26
|
+
export declare function stringifyBigIntFields(value: unknown, options?: ConvertBigIntFieldsOptions & {
|
|
27
|
+
space?: string | number;
|
|
28
|
+
}): string;
|
|
29
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mCAAmC,MAAM,CAAA;AAEtD,MAAM,WAAW,0BAA0B;IACzC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,sEAAsE;AACtE,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,OAAO,OAAO,YACF,CAAA;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAWT;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,0BAA0B,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,GACrE,MAAM,CAMR"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bigintReplacer = exports.DEFAULT_BIGINT_CONVERSION_MAX_DEPTH = void 0;
|
|
4
|
+
exports.convertBigIntFields = convertBigIntFields;
|
|
5
|
+
exports.stringifyBigIntFields = stringifyBigIntFields;
|
|
6
|
+
exports.DEFAULT_BIGINT_CONVERSION_MAX_DEPTH = 100;
|
|
7
|
+
/** JSON.stringify replacer that converts bigint values to strings. */
|
|
8
|
+
const bigintReplacer = (_, value) => typeof value === 'bigint' ? value.toString() : value;
|
|
9
|
+
exports.bigintReplacer = bigintReplacer;
|
|
10
|
+
/**
|
|
11
|
+
* Recursively converts bigint values to decimal strings.
|
|
12
|
+
*
|
|
13
|
+
* Intended for JSON-like plain objects/arrays. Pass `convertFiniteNumbers: true`
|
|
14
|
+
* for canonical-signing payloads that need number-like fields encoded as strings.
|
|
15
|
+
*
|
|
16
|
+
* Throws on circular references or excessive nesting instead of silently
|
|
17
|
+
* producing lossy placeholder values.
|
|
18
|
+
*/
|
|
19
|
+
function convertBigIntFields(value, options = {}) {
|
|
20
|
+
const maxDepth = normalizeMaxDepth(options.maxDepth);
|
|
21
|
+
const convertFiniteNumbers = options.convertFiniteNumbers ?? false;
|
|
22
|
+
return convertBigIntFieldsInner(value, new WeakSet(), 0, maxDepth, convertFiniteNumbers);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* JSON.stringify with guarded bigint conversion.
|
|
26
|
+
*
|
|
27
|
+
* Preserves JSON.stringify semantics for `toJSON` (for example, Date -> ISO
|
|
28
|
+
* string) while adding bigint conversion plus circular/depth guards.
|
|
29
|
+
*/
|
|
30
|
+
function stringifyBigIntFields(value, options = {}) {
|
|
31
|
+
return JSON.stringify(value, createGuardedBigIntReplacer(options), options.space);
|
|
32
|
+
}
|
|
33
|
+
function createGuardedBigIntReplacer(options) {
|
|
34
|
+
const maxDepth = normalizeMaxDepth(options.maxDepth);
|
|
35
|
+
const convertFiniteNumbers = options.convertFiniteNumbers ?? false;
|
|
36
|
+
const ancestors = [];
|
|
37
|
+
return function guardedBigIntReplacer(_key, value) {
|
|
38
|
+
if (typeof value === 'bigint') {
|
|
39
|
+
return value.toString();
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
return convertFiniteNumbers && Number.isFinite(value)
|
|
43
|
+
? value.toString()
|
|
44
|
+
: value;
|
|
45
|
+
}
|
|
46
|
+
if (value === null || typeof value !== 'object') {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
50
|
+
ancestors.pop();
|
|
51
|
+
}
|
|
52
|
+
if (ancestors.includes(value)) {
|
|
53
|
+
throw new Error('convertBigIntFields: circular reference detected');
|
|
54
|
+
}
|
|
55
|
+
if (ancestors.length >= maxDepth) {
|
|
56
|
+
throw new Error(`convertBigIntFields: max depth exceeded (${maxDepth})`);
|
|
57
|
+
}
|
|
58
|
+
ancestors.push(value);
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function convertBigIntFieldsInner(value, seen, depth, maxDepth, convertFiniteNumbers) {
|
|
63
|
+
if (value === null || value === undefined) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
if (typeof value === 'bigint') {
|
|
67
|
+
return value.toString();
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === 'number') {
|
|
70
|
+
return convertFiniteNumbers && Number.isFinite(value)
|
|
71
|
+
? value.toString()
|
|
72
|
+
: value;
|
|
73
|
+
}
|
|
74
|
+
if (typeof value !== 'object') {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
if (seen.has(value)) {
|
|
78
|
+
throw new Error('convertBigIntFields: circular reference detected');
|
|
79
|
+
}
|
|
80
|
+
if (depth >= maxDepth) {
|
|
81
|
+
throw new Error(`convertBigIntFields: max depth exceeded (${maxDepth})`);
|
|
82
|
+
}
|
|
83
|
+
seen.add(value);
|
|
84
|
+
try {
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return value.map((item) => convertBigIntFieldsInner(item, seen, depth + 1, maxDepth, convertFiniteNumbers));
|
|
87
|
+
}
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const key in value) {
|
|
90
|
+
if (Object.hasOwn(value, key)) {
|
|
91
|
+
result[key] = convertBigIntFieldsInner(value[key], seen, depth + 1, maxDepth, convertFiniteNumbers);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
seen.delete(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function normalizeMaxDepth(maxDepth) {
|
|
101
|
+
const resolved = maxDepth ?? exports.DEFAULT_BIGINT_CONVERSION_MAX_DEPTH;
|
|
102
|
+
if (!Number.isInteger(resolved) || resolved < 0) {
|
|
103
|
+
throw new TypeError('convertBigIntFields: maxDepth must be a non-negative integer');
|
|
104
|
+
}
|
|
105
|
+
return resolved;
|
|
106
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinestone/service-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Shared SDK for Rhinestone services",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Rhinestone",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./dist/index.js",
|
|
16
16
|
"./chains": "./dist/chains.js",
|
|
17
|
-
"./opentelemetry": "./dist/opentelemetry/index.js"
|
|
17
|
+
"./opentelemetry": "./dist/opentelemetry/index.js",
|
|
18
|
+
"./serialization": "./dist/serialization.js"
|
|
18
19
|
},
|
|
19
20
|
"typesVersions": {
|
|
20
21
|
"*": {
|
|
@@ -23,6 +24,9 @@
|
|
|
23
24
|
],
|
|
24
25
|
"opentelemetry": [
|
|
25
26
|
"dist/opentelemetry/index.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"serialization": [
|
|
29
|
+
"dist/serialization.d.ts"
|
|
26
30
|
]
|
|
27
31
|
}
|
|
28
32
|
},
|