@varla/sdk 1.1.0 → 1.1.1
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/events/decode.d.ts +14 -0
- package/dist/events/decode.d.ts.map +1 -0
- package/dist/events/decode.js +26 -0
- package/dist/events/defs.d.ts +24 -0
- package/dist/events/defs.d.ts.map +1 -0
- package/dist/events/defs.js +61 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -0
- package/dist/events/oracleRegistrySync.d.ts +6 -6
- package/dist/events/oracleRegistrySync.d.ts.map +1 -1
- package/dist/events/oracleRegistrySync.js +94 -30
- package/dist/events/recent.d.ts +19 -0
- package/dist/events/recent.d.ts.map +1 -0
- package/dist/events/recent.js +24 -0
- package/dist/views/accessManager.d.ts +51 -0
- package/dist/views/accessManager.d.ts.map +1 -0
- package/dist/views/accessManager.js +44 -0
- package/dist/views/admin.d.ts +13606 -0
- package/dist/views/admin.d.ts.map +1 -0
- package/dist/views/admin.js +25 -0
- package/dist/views/index.d.ts +3 -0
- package/dist/views/index.d.ts.map +1 -1
- package/dist/views/index.js +3 -0
- package/dist/views/liquidators.d.ts +40 -0
- package/dist/views/liquidators.d.ts.map +1 -0
- package/dist/views/liquidators.js +20 -0
- package/package.json +2 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AbiEvent, Log } from "viem";
|
|
2
|
+
export type DecodedEvent<TArgs = Record<string, unknown>> = {
|
|
3
|
+
args: TArgs;
|
|
4
|
+
eventName: string;
|
|
5
|
+
log: Log;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Decode logs for a single event definition. Returns only successfully decoded entries.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeEventLogs(params: {
|
|
11
|
+
event: AbiEvent;
|
|
12
|
+
logs: Log[];
|
|
13
|
+
}): DecodedEvent[];
|
|
14
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/events/decode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAG1C,MAAM,MAAM,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,GAAG,EAAE,CAAC;CACb,GAAG,YAAY,EAAE,CAsBjB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
+
import { decodeEventLog } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* Decode logs for a single event definition. Returns only successfully decoded entries.
|
|
5
|
+
*/
|
|
6
|
+
export function decodeEventLogs(params) {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const log of params.logs) {
|
|
9
|
+
try {
|
|
10
|
+
const decoded = decodeEventLog({
|
|
11
|
+
abi: [params.event],
|
|
12
|
+
data: log.data,
|
|
13
|
+
topics: log.topics,
|
|
14
|
+
});
|
|
15
|
+
out.push({
|
|
16
|
+
args: decoded.args,
|
|
17
|
+
eventName: decoded.eventName,
|
|
18
|
+
log,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// ignore logs that don't decode cleanly (RPCs can return unrelated logs when address is omitted)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AbiEvent } from "viem";
|
|
2
|
+
export declare const ORACLE_EVENTS: {
|
|
3
|
+
readonly PositionConfigured: AbiEvent;
|
|
4
|
+
readonly OppositePositionsConfigured: AbiEvent;
|
|
5
|
+
readonly NegRiskPositionConfigured: AbiEvent;
|
|
6
|
+
readonly NegRiskPositionsBatchConfigured: AbiEvent;
|
|
7
|
+
readonly PriceUpdated: AbiEvent;
|
|
8
|
+
readonly PositionInvalidated: AbiEvent;
|
|
9
|
+
readonly PositionValidated: AbiEvent;
|
|
10
|
+
};
|
|
11
|
+
export declare const CORE_EVENTS: {
|
|
12
|
+
readonly Deposit: AbiEvent;
|
|
13
|
+
readonly Withdraw: AbiEvent;
|
|
14
|
+
readonly Borrow: AbiEvent;
|
|
15
|
+
readonly Repay: AbiEvent;
|
|
16
|
+
readonly Liquidate: AbiEvent;
|
|
17
|
+
readonly LiquidationDebtRepaid: AbiEvent;
|
|
18
|
+
};
|
|
19
|
+
export declare const POOL_EVENTS: {
|
|
20
|
+
readonly Draw: AbiEvent;
|
|
21
|
+
readonly Repay: AbiEvent;
|
|
22
|
+
readonly AccrueInterest: AbiEvent;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../src/events/defs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AASrC,eAAO,MAAM,aAAa;iCAIlB,QAAQ;0CAIR,QAAQ;wCAIR,QAAQ;8CAIR,QAAQ;2BAIR,QAAQ;kCAIR,QAAQ;gCAIR,QAAQ;CACN,CAAC;AAMX,eAAO,MAAM,WAAW;sBAC+C,QAAQ;uBACN,QAAQ;qBACZ,QAAQ;oBACV,QAAQ;wBACA,QAAQ;oCAI3E,QAAQ;CACN,CAAC;AAMX,eAAO,MAAM,WAAW;mBACyC,QAAQ;oBACN,QAAQ;6BAInE,QAAQ;CACN,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
+
import { getAbiItem } from "viem";
|
|
3
|
+
import { abis } from "../generated.js";
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Oracle
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export const ORACLE_EVENTS = {
|
|
8
|
+
PositionConfigured: getAbiItem({
|
|
9
|
+
abi: abis.VARLAORACLE_ABI,
|
|
10
|
+
name: "PositionConfigured",
|
|
11
|
+
}),
|
|
12
|
+
OppositePositionsConfigured: getAbiItem({
|
|
13
|
+
abi: abis.VARLAORACLE_ABI,
|
|
14
|
+
name: "OppositePositionsConfigured",
|
|
15
|
+
}),
|
|
16
|
+
NegRiskPositionConfigured: getAbiItem({
|
|
17
|
+
abi: abis.VARLAORACLE_ABI,
|
|
18
|
+
name: "NegRiskPositionConfigured",
|
|
19
|
+
}),
|
|
20
|
+
NegRiskPositionsBatchConfigured: getAbiItem({
|
|
21
|
+
abi: abis.VARLAORACLE_ABI,
|
|
22
|
+
name: "NegRiskPositionsBatchConfigured",
|
|
23
|
+
}),
|
|
24
|
+
PriceUpdated: getAbiItem({
|
|
25
|
+
abi: abis.VARLAORACLE_ABI,
|
|
26
|
+
name: "PriceUpdated",
|
|
27
|
+
}),
|
|
28
|
+
PositionInvalidated: getAbiItem({
|
|
29
|
+
abi: abis.VARLAORACLE_ABI,
|
|
30
|
+
name: "PositionInvalidated",
|
|
31
|
+
}),
|
|
32
|
+
PositionValidated: getAbiItem({
|
|
33
|
+
abi: abis.VARLAORACLE_ABI,
|
|
34
|
+
name: "PositionValidated",
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Core
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
export const CORE_EVENTS = {
|
|
41
|
+
Deposit: getAbiItem({ abi: abis.VARLACORE_ABI, name: "Deposit" }),
|
|
42
|
+
Withdraw: getAbiItem({ abi: abis.VARLACORE_ABI, name: "Withdraw" }),
|
|
43
|
+
Borrow: getAbiItem({ abi: abis.VARLACORE_ABI, name: "Borrow" }),
|
|
44
|
+
Repay: getAbiItem({ abi: abis.VARLACORE_ABI, name: "Repay" }),
|
|
45
|
+
Liquidate: getAbiItem({ abi: abis.VARLACORE_ABI, name: "Liquidate" }),
|
|
46
|
+
LiquidationDebtRepaid: getAbiItem({
|
|
47
|
+
abi: abis.VARLACORE_ABI,
|
|
48
|
+
name: "LiquidationDebtRepaid",
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Pool
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
export const POOL_EVENTS = {
|
|
55
|
+
Draw: getAbiItem({ abi: abis.VARLAPOOL_ABI, name: "Draw" }),
|
|
56
|
+
Repay: getAbiItem({ abi: abis.VARLAPOOL_ABI, name: "Repay" }),
|
|
57
|
+
AccrueInterest: getAbiItem({
|
|
58
|
+
abi: abis.VARLAPOOL_ABI,
|
|
59
|
+
name: "AccrueInterest",
|
|
60
|
+
}),
|
|
61
|
+
};
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
|
package/dist/events/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Address, PublicClient } from "viem";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Production-friendly registry sync for VarlaOracle.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Note: `configurePositionsBatch` emits `PositionConfigured` per position.
|
|
5
|
+
* - Discovers configured `positionIds` from `PositionConfigured` events.
|
|
6
|
+
* - Optionally enriches opposites / negRisk info from events (cheap), then hydrates
|
|
7
|
+
* canonical state from contract views via multicall.
|
|
10
8
|
*/
|
|
11
9
|
export type OracleRegistryEntry = {
|
|
12
10
|
positionId: bigint;
|
|
13
11
|
conditionId: `0x${string}`;
|
|
14
12
|
resolutionTime: bigint;
|
|
13
|
+
riskTier: number;
|
|
15
14
|
isNegRisk: boolean;
|
|
16
15
|
negRiskMarketId: `0x${string}`;
|
|
17
16
|
oppositePositionId: bigint;
|
|
@@ -21,6 +20,7 @@ export type SyncOracleRegistryViaEventsParams = {
|
|
|
21
20
|
oracleAddress: Address;
|
|
22
21
|
fromBlock: bigint;
|
|
23
22
|
toBlock: bigint;
|
|
23
|
+
/** Max number of blocks per request. */
|
|
24
24
|
blockRange?: bigint;
|
|
25
25
|
multicallChunkSize?: number;
|
|
26
26
|
/** Limit how many discovered ids to hydrate (useful for testing). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracleRegistrySync.d.ts","sourceRoot":"","sources":["../../src/events/oracleRegistrySync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"oracleRegistrySync.d.ts","sourceRoot":"","sources":["../../src/events/oracleRegistrySync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQlD;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,KAAK,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAcF,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,mBAAmB,EAAE,CAAA;CAAE,CAAC,CAuJpE"}
|
|
@@ -1,39 +1,84 @@
|
|
|
1
1
|
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
-
import { decodeEventLog, getAbiItem } from "viem";
|
|
3
2
|
import { multicallChunks } from "../batch.js";
|
|
4
3
|
import { abis } from "../generated.js";
|
|
4
|
+
import { decodeEventLogs } from "./decode.js";
|
|
5
|
+
import { ORACLE_EVENTS } from "./defs.js";
|
|
5
6
|
import { getEventLogsChunked } from "./logs.js";
|
|
7
|
+
function uniqBigints(values) {
|
|
8
|
+
const set = new Set();
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const v of values) {
|
|
11
|
+
const k = v.toString();
|
|
12
|
+
if (set.has(k))
|
|
13
|
+
continue;
|
|
14
|
+
set.add(k);
|
|
15
|
+
out.push(v);
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
6
19
|
export async function syncOracleRegistryViaEvents(params) {
|
|
7
20
|
const abi = abis.VARLAORACLE_ABI;
|
|
8
|
-
|
|
9
|
-
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// 1) Discover ids (PositionConfigured)
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
const configuredLogs = await getEventLogsChunked({
|
|
10
25
|
client: params.client,
|
|
11
26
|
address: params.oracleAddress,
|
|
12
|
-
event:
|
|
27
|
+
event: ORACLE_EVENTS.PositionConfigured,
|
|
13
28
|
fromBlock: params.fromBlock,
|
|
14
29
|
toBlock: params.toBlock,
|
|
15
30
|
blockRange: params.blockRange,
|
|
16
31
|
});
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
const configuredDecoded = decodeEventLogs({
|
|
33
|
+
event: ORACLE_EVENTS.PositionConfigured,
|
|
34
|
+
logs: configuredLogs,
|
|
35
|
+
});
|
|
36
|
+
let ids = uniqBigints(configuredDecoded.map((d) => d.args.positionId));
|
|
37
|
+
if (params.maxIds)
|
|
38
|
+
ids = ids.slice(0, params.maxIds);
|
|
39
|
+
if (ids.length === 0)
|
|
40
|
+
return { positionIds: [], entries: [] };
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// 2) Optional enrichment from events (non-authoritative)
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
const oppositeById = new Map();
|
|
45
|
+
{
|
|
46
|
+
const logs = await getEventLogsChunked({
|
|
47
|
+
client: params.client,
|
|
48
|
+
address: params.oracleAddress,
|
|
49
|
+
event: ORACLE_EVENTS.OppositePositionsConfigured,
|
|
50
|
+
fromBlock: params.fromBlock,
|
|
51
|
+
toBlock: params.toBlock,
|
|
52
|
+
blockRange: params.blockRange,
|
|
24
53
|
});
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
break;
|
|
54
|
+
const decoded = decodeEventLogs({ event: ORACLE_EVENTS.OppositePositionsConfigured, logs });
|
|
55
|
+
for (const d of decoded) {
|
|
56
|
+
const yes = d.args.yesPositionId;
|
|
57
|
+
const no = d.args.noPositionId;
|
|
58
|
+
oppositeById.set(yes.toString(), no);
|
|
59
|
+
oppositeById.set(no.toString(), yes);
|
|
32
60
|
}
|
|
33
61
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
const negRiskMarketById = new Map();
|
|
63
|
+
{
|
|
64
|
+
const logs = await getEventLogsChunked({
|
|
65
|
+
client: params.client,
|
|
66
|
+
address: params.oracleAddress,
|
|
67
|
+
event: ORACLE_EVENTS.NegRiskPositionConfigured,
|
|
68
|
+
fromBlock: params.fromBlock,
|
|
69
|
+
toBlock: params.toBlock,
|
|
70
|
+
blockRange: params.blockRange,
|
|
71
|
+
});
|
|
72
|
+
const decoded = decodeEventLogs({ event: ORACLE_EVENTS.NegRiskPositionConfigured, logs });
|
|
73
|
+
for (const d of decoded) {
|
|
74
|
+
const pid = d.args.positionId;
|
|
75
|
+
const marketId = d.args.marketId;
|
|
76
|
+
negRiskMarketById.set(pid.toString(), marketId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// 3) Hydrate canonical state from views (authoritative)
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
37
82
|
const calls = ids.flatMap((pid) => [
|
|
38
83
|
{
|
|
39
84
|
address: params.oracleAddress,
|
|
@@ -47,6 +92,12 @@ export async function syncOracleRegistryViaEvents(params) {
|
|
|
47
92
|
functionName: "getResolutionTime",
|
|
48
93
|
args: [pid],
|
|
49
94
|
},
|
|
95
|
+
{
|
|
96
|
+
address: params.oracleAddress,
|
|
97
|
+
abi,
|
|
98
|
+
functionName: "getRiskTier",
|
|
99
|
+
args: [pid],
|
|
100
|
+
},
|
|
50
101
|
{
|
|
51
102
|
address: params.oracleAddress,
|
|
52
103
|
abi,
|
|
@@ -66,27 +117,40 @@ export async function syncOracleRegistryViaEvents(params) {
|
|
|
66
117
|
args: [pid],
|
|
67
118
|
},
|
|
68
119
|
]);
|
|
69
|
-
const
|
|
120
|
+
const chunkSize = params.multicallChunkSize ?? 128;
|
|
121
|
+
const res = await multicallChunks({
|
|
122
|
+
client: params.client,
|
|
123
|
+
contracts: calls,
|
|
124
|
+
chunkSize,
|
|
125
|
+
});
|
|
70
126
|
const entries = [];
|
|
71
|
-
// 5 results per pid.
|
|
72
127
|
for (let i = 0; i < ids.length; i++) {
|
|
73
|
-
const base = i *
|
|
128
|
+
const base = i * 6;
|
|
74
129
|
const r0 = res[base + 0];
|
|
75
130
|
const r1 = res[base + 1];
|
|
76
131
|
const r2 = res[base + 2];
|
|
77
132
|
const r3 = res[base + 3];
|
|
78
133
|
const r4 = res[base + 4];
|
|
79
|
-
|
|
80
|
-
|
|
134
|
+
const r5 = res[base + 5];
|
|
135
|
+
for (const r of [r0, r1, r2, r3, r4, r5]) {
|
|
136
|
+
if (r.status !== "success") {
|
|
81
137
|
throw new Error(`Oracle registry multicall failed: ${String(r.error)}`);
|
|
138
|
+
}
|
|
82
139
|
}
|
|
140
|
+
const pid = ids[i];
|
|
141
|
+
const pidKey = pid.toString();
|
|
142
|
+
// Prefer on-chain view results (authoritative), but fall back to event-enriched values
|
|
143
|
+
// if they look more complete.
|
|
144
|
+
const opposite = r3.result || (oppositeById.get(pidKey) ?? 0n);
|
|
145
|
+
const market = r5.result || (negRiskMarketById.get(pidKey) ?? "0x" + "0".repeat(64));
|
|
83
146
|
entries.push({
|
|
84
|
-
positionId:
|
|
147
|
+
positionId: pid,
|
|
85
148
|
conditionId: r0.result,
|
|
86
149
|
resolutionTime: r1.result,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
150
|
+
riskTier: Number(r2.result),
|
|
151
|
+
oppositePositionId: opposite,
|
|
152
|
+
isNegRisk: r4.result,
|
|
153
|
+
negRiskMarketId: market,
|
|
90
154
|
});
|
|
91
155
|
}
|
|
92
156
|
return { positionIds: ids, entries };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Address, AbiEvent, PublicClient } from "viem";
|
|
2
|
+
export type GetRecentEventsParams = {
|
|
3
|
+
client: PublicClient;
|
|
4
|
+
address: Address;
|
|
5
|
+
event: AbiEvent;
|
|
6
|
+
/** Look back N blocks from the current head. */
|
|
7
|
+
lookbackBlocks?: bigint;
|
|
8
|
+
/** Chunk size for log fetching. */
|
|
9
|
+
blockRange?: bigint;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Frontend-friendly helper: fetch and decode recent events by looking back from head.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getRecentEvents(params: GetRecentEventsParams): Promise<{
|
|
15
|
+
fromBlock: bigint;
|
|
16
|
+
toBlock: bigint;
|
|
17
|
+
decoded: import("./decode.js").DecodedEvent<Record<string, unknown>>[];
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=recent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recent.d.ts","sourceRoot":"","sources":["../../src/events/recent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAO,MAAM,MAAM,CAAC;AAKjE,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;IAChB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB;;;;GAmBlE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
+
import { getEventLogsChunked } from "./logs.js";
|
|
3
|
+
import { decodeEventLogs } from "./decode.js";
|
|
4
|
+
/**
|
|
5
|
+
* Frontend-friendly helper: fetch and decode recent events by looking back from head.
|
|
6
|
+
*/
|
|
7
|
+
export async function getRecentEvents(params) {
|
|
8
|
+
const head = await params.client.getBlockNumber();
|
|
9
|
+
const lookback = params.lookbackBlocks ?? 2000n;
|
|
10
|
+
const fromBlock = head > lookback ? head - lookback : 0n;
|
|
11
|
+
const logs = await getEventLogsChunked({
|
|
12
|
+
client: params.client,
|
|
13
|
+
address: params.address,
|
|
14
|
+
event: params.event,
|
|
15
|
+
fromBlock,
|
|
16
|
+
toBlock: head,
|
|
17
|
+
blockRange: params.blockRange,
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
fromBlock,
|
|
21
|
+
toBlock: head,
|
|
22
|
+
decoded: decodeEventLogs({ event: params.event, logs }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
export type ReadAccessManagerBasics = {
|
|
3
|
+
adminRole: bigint;
|
|
4
|
+
publicRole: bigint;
|
|
5
|
+
};
|
|
6
|
+
type AccessManagerLike = {
|
|
7
|
+
read: {
|
|
8
|
+
ADMIN_ROLE: () => Promise<number | bigint>;
|
|
9
|
+
PUBLIC_ROLE: () => Promise<number | bigint>;
|
|
10
|
+
hasRole: (args: readonly [bigint, Address]) => Promise<readonly [boolean, number]>;
|
|
11
|
+
getRoleAdmin: (args: readonly [bigint]) => Promise<number | bigint>;
|
|
12
|
+
getRoleGrantDelay: (args: readonly [bigint]) => Promise<number | bigint>;
|
|
13
|
+
getRoleGuardian: (args: readonly [bigint]) => Promise<number | bigint>;
|
|
14
|
+
getTargetFunctionRole: (args: readonly [Address, Hex]) => Promise<number | bigint>;
|
|
15
|
+
getTargetAdminDelay: (args: readonly [Address]) => Promise<number | bigint>;
|
|
16
|
+
isTargetClosed: (args: readonly [Address]) => Promise<boolean>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function readAccessManagerBasics(params: {
|
|
20
|
+
accessManager: AccessManagerLike;
|
|
21
|
+
}): Promise<ReadAccessManagerBasics>;
|
|
22
|
+
export declare function readRoleSummary(params: {
|
|
23
|
+
accessManager: AccessManagerLike;
|
|
24
|
+
role: bigint;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
role: bigint;
|
|
27
|
+
admin: bigint;
|
|
28
|
+
guardian: bigint;
|
|
29
|
+
grantDelay: bigint;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function readTargetConfig(params: {
|
|
32
|
+
accessManager: AccessManagerLike;
|
|
33
|
+
target: Address;
|
|
34
|
+
selector: Hex;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
target: Address;
|
|
37
|
+
selector: Hex;
|
|
38
|
+
role: bigint;
|
|
39
|
+
adminDelay: bigint;
|
|
40
|
+
isClosed: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
export declare function readHasRole(params: {
|
|
43
|
+
accessManager: AccessManagerLike;
|
|
44
|
+
role: bigint;
|
|
45
|
+
account: Address;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
isMember: boolean;
|
|
48
|
+
executionDelay: bigint;
|
|
49
|
+
}>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=accessManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessManager.d.ts","sourceRoot":"","sources":["../../src/views/accessManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE;QAEJ,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QAC3C,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QAG5C,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACnF,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACpE,iBAAiB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACzE,eAAe,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACvE,qBAAqB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACnF,mBAAmB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QAC5E,cAAc,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAChE,CAAC;CACH,CAAC;AAMF,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,iBAAiB,CAAC;CAClC,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAMnC;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,aAAa,EAAE,iBAAiB,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAYjF;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,aAAa,EAAE,iBAAiB,CAAC;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC;CACf,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAanG;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,aAAa,EAAE,iBAAiB,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC,CAKzD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
+
function toBigInt(v) {
|
|
3
|
+
return typeof v === "bigint" ? v : BigInt(v);
|
|
4
|
+
}
|
|
5
|
+
export async function readAccessManagerBasics(params) {
|
|
6
|
+
const [adminRole, publicRole] = await Promise.all([
|
|
7
|
+
params.accessManager.read.ADMIN_ROLE(),
|
|
8
|
+
params.accessManager.read.PUBLIC_ROLE(),
|
|
9
|
+
]);
|
|
10
|
+
return { adminRole: toBigInt(adminRole), publicRole: toBigInt(publicRole) };
|
|
11
|
+
}
|
|
12
|
+
export async function readRoleSummary(params) {
|
|
13
|
+
const [admin, guardian, grantDelay] = await Promise.all([
|
|
14
|
+
params.accessManager.read.getRoleAdmin([params.role]),
|
|
15
|
+
params.accessManager.read.getRoleGuardian([params.role]),
|
|
16
|
+
params.accessManager.read.getRoleGrantDelay([params.role]),
|
|
17
|
+
]);
|
|
18
|
+
return {
|
|
19
|
+
role: params.role,
|
|
20
|
+
admin: toBigInt(admin),
|
|
21
|
+
guardian: toBigInt(guardian),
|
|
22
|
+
grantDelay: toBigInt(grantDelay),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export async function readTargetConfig(params) {
|
|
26
|
+
const [role, adminDelay, isClosed] = await Promise.all([
|
|
27
|
+
params.accessManager.read.getTargetFunctionRole([params.target, params.selector]),
|
|
28
|
+
params.accessManager.read.getTargetAdminDelay([params.target]),
|
|
29
|
+
params.accessManager.read.isTargetClosed([params.target]),
|
|
30
|
+
]);
|
|
31
|
+
return {
|
|
32
|
+
target: params.target,
|
|
33
|
+
selector: params.selector,
|
|
34
|
+
role: toBigInt(role),
|
|
35
|
+
adminDelay: toBigInt(adminDelay),
|
|
36
|
+
isClosed,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function readHasRole(params) {
|
|
40
|
+
const r = await params.accessManager.read.hasRole([params.role, params.account]);
|
|
41
|
+
const isMember = r.isMember ?? r[0];
|
|
42
|
+
const executionDelay = r.executionDelay ?? r[1];
|
|
43
|
+
return { isMember, executionDelay: BigInt(executionDelay) };
|
|
44
|
+
}
|