@levrbet/shared 0.3.9 → 0.3.10
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/core/contracts/clients/publicClients.d.ts +4 -13
- package/dist/core/contracts/clients/publicClients.js +26 -65
- package/dist/core/contracts/clients/publicClients.js.map +1 -1
- package/dist/core/types/oracle/market/markets.types.d.ts +7 -6
- package/dist/core/types/oracle/market/markets.types.js.map +1 -1
- package/dist/server/contracts/instances.d.ts +1 -1
- package/dist/server/contracts/instances.js +5 -2
- package/dist/server/contracts/instances.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,23 +2,14 @@ import type { Chain, PublicClient, Transport } from "viem";
|
|
|
2
2
|
import { LevrChain } from "../../types";
|
|
3
3
|
declare class PublicClientService {
|
|
4
4
|
private readonly defaultMulticallWait;
|
|
5
|
-
private readonly connectionTimeout;
|
|
6
5
|
/**
|
|
7
|
-
* Gets a premium public client
|
|
8
|
-
*
|
|
6
|
+
* Gets a premium public client with fallback transport using configured RPC URLs.
|
|
7
|
+
* Uses viem's fallback transport with automatic ranking based on latency & stability.
|
|
8
|
+
* Falls back to the default public client if no premium URLs are configured.
|
|
9
9
|
*/
|
|
10
|
-
getPremiumPubClient(chainId: LevrChain):
|
|
10
|
+
getPremiumPubClient(chainId: LevrChain): PublicClient<Transport, Chain>;
|
|
11
11
|
getPublicClient(chainId: LevrChain): PublicClient<Transport, Chain>;
|
|
12
|
-
private getPublicClientWithRpc;
|
|
13
12
|
private getPrivateRpcUrls;
|
|
14
|
-
/**
|
|
15
|
-
* Perform a health check on an RPC client with timeout
|
|
16
|
-
*/
|
|
17
|
-
private performHealthCheck;
|
|
18
|
-
/**
|
|
19
|
-
* Try to connect to a single RPC URL with health check and caching
|
|
20
|
-
*/
|
|
21
|
-
private tryRpcUrl;
|
|
22
13
|
}
|
|
23
14
|
export declare const publicClientService: PublicClientService;
|
|
24
15
|
export { PublicClientService };
|
|
@@ -21,38 +21,42 @@ const chains_1 = require("../chains");
|
|
|
21
21
|
class PublicClientService {
|
|
22
22
|
constructor() {
|
|
23
23
|
this.defaultMulticallWait = (0, ms_1.default)("300ms");
|
|
24
|
-
this.connectionTimeout = (0, ms_1.default)("5s");
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* Gets a premium public client
|
|
28
|
-
*
|
|
26
|
+
* Gets a premium public client with fallback transport using configured RPC URLs.
|
|
27
|
+
* Uses viem's fallback transport with automatic ranking based on latency & stability.
|
|
28
|
+
* Falls back to the default public client if no premium URLs are configured.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
getPremiumPubClient(chainId) {
|
|
31
31
|
const rpcUrls = this.getPrivateRpcUrls()[chainId];
|
|
32
|
-
if (rpcUrls.length === 0)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const client = await this.tryRpcUrl(chainId, url);
|
|
36
|
-
if (client)
|
|
37
|
-
return client;
|
|
32
|
+
if (rpcUrls.length === 0) {
|
|
33
|
+
console.warn(`No premium RPC URLs configured for chainId=${chainId}. Using default client.`);
|
|
34
|
+
return this.getPublicClient(chainId);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
failedUrlCount: rpcUrls.length,
|
|
42
|
-
});
|
|
43
|
-
return this.getPublicClient(chainId);
|
|
44
|
-
}
|
|
45
|
-
getPublicClient(chainId) {
|
|
36
|
+
// Create transports for each URL
|
|
37
|
+
const transports = rpcUrls.map((url) => (0, viem_1.http)(url, { timeout: (0, ms_1.default)("10s") }));
|
|
46
38
|
return (0, viem_1.createPublicClient)({
|
|
47
39
|
chain: chains_1.levrChainIdToChain[chainId],
|
|
48
|
-
transport: (0, viem_1.
|
|
40
|
+
transport: (0, viem_1.fallback)(transports, {
|
|
41
|
+
rank: {
|
|
42
|
+
interval: (0, ms_1.default)("30s"), // Ping interval for ranking
|
|
43
|
+
sampleCount: 10, // Number of samples for ranking
|
|
44
|
+
timeout: (0, ms_1.default)("5s"), // Timeout for health check pings
|
|
45
|
+
weights: {
|
|
46
|
+
latency: 0.3,
|
|
47
|
+
stability: 0.7,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
retryCount: 3,
|
|
51
|
+
retryDelay: 150,
|
|
52
|
+
}),
|
|
49
53
|
batch: { multicall: { wait: this.defaultMulticallWait } },
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
|
-
|
|
56
|
+
getPublicClient(chainId) {
|
|
53
57
|
return (0, viem_1.createPublicClient)({
|
|
54
58
|
chain: chains_1.levrChainIdToChain[chainId],
|
|
55
|
-
transport: (0, viem_1.http)(
|
|
59
|
+
transport: (0, viem_1.http)(),
|
|
56
60
|
batch: { multicall: { wait: this.defaultMulticallWait } },
|
|
57
61
|
});
|
|
58
62
|
}
|
|
@@ -65,59 +69,16 @@ class PublicClientService {
|
|
|
65
69
|
[types_1.LevrChain.MONAD_TESTNET]: RPC_URLS_10143.split(",").filter(Boolean),
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Perform a health check on an RPC client with timeout
|
|
70
|
-
*/
|
|
71
|
-
async performHealthCheck(client) {
|
|
72
|
-
let timeoutId;
|
|
73
|
-
try {
|
|
74
|
-
await Promise.race([
|
|
75
|
-
client.getBlockNumber(),
|
|
76
|
-
new Promise((_, reject) => {
|
|
77
|
-
timeoutId = setTimeout(() => {
|
|
78
|
-
reject(new Error("Connection timeout"));
|
|
79
|
-
}, this.connectionTimeout);
|
|
80
|
-
}),
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
// Clean up timeout to prevent resource leak
|
|
85
|
-
if (timeoutId)
|
|
86
|
-
clearTimeout(timeoutId);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Try to connect to a single RPC URL with health check and caching
|
|
91
|
-
*/
|
|
92
|
-
async tryRpcUrl(chainId, url) {
|
|
93
|
-
const client = this.getPublicClientWithRpc(chainId, url);
|
|
94
|
-
try {
|
|
95
|
-
await this.performHealthCheck(client);
|
|
96
|
-
return client;
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
console.error("RPC connection failed", {
|
|
100
|
-
chainId,
|
|
101
|
-
url,
|
|
102
|
-
error: error instanceof Error ? error.message : String(error),
|
|
103
|
-
timestamp: new Date().toISOString(),
|
|
104
|
-
});
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
72
|
}
|
|
109
73
|
exports.PublicClientService = PublicClientService;
|
|
110
74
|
__decorate([
|
|
111
75
|
(0, typescript_memoize_1.Memoize)(utils_1.argHash)
|
|
112
|
-
], PublicClientService.prototype, "
|
|
76
|
+
], PublicClientService.prototype, "getPremiumPubClient", null);
|
|
113
77
|
__decorate([
|
|
114
78
|
(0, typescript_memoize_1.Memoize)(utils_1.argHash)
|
|
115
|
-
], PublicClientService.prototype, "
|
|
79
|
+
], PublicClientService.prototype, "getPublicClient", null);
|
|
116
80
|
__decorate([
|
|
117
81
|
(0, typescript_memoize_1.Memoize)()
|
|
118
82
|
], PublicClientService.prototype, "getPrivateRpcUrls", null);
|
|
119
|
-
__decorate([
|
|
120
|
-
(0, typescript_memoize_1.MemoizeExpiring)((0, ms_1.default)("1m"), utils_1.argHash)
|
|
121
|
-
], PublicClientService.prototype, "tryRpcUrl", null);
|
|
122
83
|
exports.publicClientService = new PublicClientService();
|
|
123
84
|
//# sourceMappingURL=publicClients.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClients.js","sourceRoot":"","sources":["../../../../src/core/contracts/clients/publicClients.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAmB;AACnB,
|
|
1
|
+
{"version":3,"file":"publicClients.js","sourceRoot":"","sources":["../../../../src/core/contracts/clients/publicClients.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAmB;AACnB,2DAA4C;AAE5C,+BAAyD;AACzD,8CAAmB;AACnB,yCAA+D;A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AC,OAAkB;QAC9B,OAAO,IAAA,yBAAkB,EAAC;YACtB,KAAK,EAAE,2BAAkB,CAAC,OAAO,CAAC;YAClC,SAAS,EAAE,IAAA,WAAI,GAAE;YACjB,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,EAAE;SAC5D,CAAC,CAAA;IACN,CAAC;IAGO,iBAAiB;QACrB,MAAM,aAAa,GAAG,aAAC,CAAC,MAAM,CAAC;YAC3B,cAAc,EAAE,iCAAwB;SAC3C,CAAC,CAAA;QAEF,MAAM,EAAE,cAAc,EAAE,GAAG,eAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAErD,OAAO;YACH,CAAC,iBAAS,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;SACvE,CAAA;IACL,CAAC;CACJ;AAGQ,kDAAmB;AAtDxB;IADC,IAAA,4BAAO,EAAC,eAAO,CAAC;8DA6BhB;AAGD;IADC,IAAA,4BAAO,EAAC,eAAO,CAAC;0DAOhB;AAGO;IADP,IAAA,4BAAO,GAAE;4DAWT;AAGQ,QAAA,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GamePhase, MarketStatus, MarketType, Prisma } from "@prisma/client";
|
|
2
|
-
import { LevrMarketId } from "../../../contracts";
|
|
3
|
-
import { Bytes10, Bytes32 } from "../../../validators";
|
|
4
|
-
import { LevrChain } from "../../blockchain";
|
|
5
|
-
import { GameProvider } from "../game";
|
|
6
|
-
import {
|
|
1
|
+
import type { GamePhase, MarketStatus, MarketType, Prisma } from "@prisma/client";
|
|
2
|
+
import type { LevrMarketId } from "../../../contracts";
|
|
3
|
+
import type { Bytes10, Bytes32 } from "../../../validators";
|
|
4
|
+
import { type LevrChain } from "../../blockchain";
|
|
5
|
+
import type { GameProvider } from "../game";
|
|
6
|
+
import type { OddsData, PriceData } from "./odds.types";
|
|
7
7
|
export type MarketWithRelations = Prisma.MarketGetPayload<{
|
|
8
8
|
include: {
|
|
9
9
|
odds: true;
|
|
@@ -21,6 +21,7 @@ export interface MarketPriceBroadcast {
|
|
|
21
21
|
gamePhase: GamePhase;
|
|
22
22
|
gamePeriod: number;
|
|
23
23
|
gameClock: string | number;
|
|
24
|
+
levrMarketId: LevrMarketId;
|
|
24
25
|
gameMarketId: LevrGameMarketId;
|
|
25
26
|
nFactor: number;
|
|
26
27
|
providerObjectId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markets.types.js","sourceRoot":"","sources":["../../../../../src/core/types/oracle/market/markets.types.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"markets.types.js","sourceRoot":"","sources":["../../../../../src/core/types/oracle/market/markets.types.ts"],"names":[],"mappings":";;;AAGA,iDAAuD;AA+DvD,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAC9B,mEAAQ,CAAA;IACR,yEAAW,CAAA;IACX,mEAAQ,CAAA;AACZ,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC;AAeD;;;;;;;;;GASG;AACU,QAAA,SAAS,GAAG,CAAC,IAAI,iBAAI,CAAC,IAAI,CAAA,CAAC,iBAAiB;AAC5C,QAAA,SAAS,GAAG,CAAC,IAAI,iBAAI,CAAC,IAAI,CAAA,CAAC,iBAAiB;AAC5C,QAAA,YAAY,GAAG,CAAC,IAAI,iBAAI,CAAC,OAAO,CAAA,CAAC,iBAAiB;AAClD,QAAA,SAAS,GAAG,CAAC,IAAI,iBAAI,CAAC,IAAI,CAAA,CAAC,iBAAiB;AAC5C,QAAA,SAAS,GAAG,CAAC,IAAI,iBAAI,CAAC,IAAI,CAAA,CAAC,kBAAkB;AAC7C,QAAA,UAAU,GAAG,CAAC,IAAI,iBAAI,CAAC,KAAK,CAAA,CAAC,kBAAkB;AAE5D;;;;;GAKG;AACU,QAAA,aAAa,GAAG,iBAAS,GAAG,oBAAY,GAAG,iBAAS,CAAA,CAAC,kBAAkB;AACvE,QAAA,WAAW,GAAG,iBAAS,GAAG,kBAAU,CAAA,CAAC,kBAAkB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GetContractReturnType, PublicClient, WalletClient } from "viem";
|
|
2
|
-
import { abis,
|
|
2
|
+
import { type abis, type CustomWalletClient, type LevrChain, type LevrRelayerGroup } from "../../core";
|
|
3
3
|
interface ClientOptions {
|
|
4
4
|
relayer?: LevrRelayerGroup;
|
|
5
5
|
walletClient?: WalletClient;
|
|
@@ -22,7 +22,10 @@ async function getLevrContractWithRelayer(contractName, chainId, { relayer, publ
|
|
|
22
22
|
if (relayer && !walletClient)
|
|
23
23
|
walletClient = await ozRelayerService_1.default.getWalletClient(chainId, relayer);
|
|
24
24
|
if (!publicClient)
|
|
25
|
-
publicClient =
|
|
26
|
-
return (0, core_1.getLevrContract)(contractName, chainId, config_1.LEVR_ENV, {
|
|
25
|
+
publicClient = core_1.publicClientService.getPremiumPubClient(chainId);
|
|
26
|
+
return (0, core_1.getLevrContract)(contractName, chainId, config_1.LEVR_ENV, {
|
|
27
|
+
publicClient,
|
|
28
|
+
walletClient,
|
|
29
|
+
});
|
|
27
30
|
}
|
|
28
31
|
//# sourceMappingURL=instances.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../../../src/server/contracts/instances.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"instances.js","sourceRoot":"","sources":["../../../src/server/contracts/instances.ts"],"names":[],"mappings":";;;;;AA6BA,gEAWC;AAvCD,qCAOmB;AACnB,sCAAoC;AACpC,kFAAyD;AAQzD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,0BAA0B,CAC5C,YAAe,EACf,OAAkB,EAClB,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAiB;IAEtD,IAAI,OAAO,IAAI,CAAC,YAAY;QAAE,YAAY,GAAG,MAAM,0BAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACrG,IAAI,CAAC,YAAY;QAAE,YAAY,GAAG,0BAAmB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;IAClF,OAAO,IAAA,sBAAe,EAAC,YAAY,EAAE,OAAO,EAAE,iBAAQ,EAAE;QACpD,YAAY;QACZ,YAAY;KACf,CAAC,CAAA;AACN,CAAC"}
|