@varla/sdk 1.0.0 → 1.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.
- package/README.md +164 -0
- package/dist/batch.d.ts +26 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/batch.js +34 -0
- package/dist/contracts.d.ts +37676 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +139 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +3 -0
- package/dist/events/logs.d.ts +17 -0
- package/dist/events/logs.d.ts.map +1 -0
- package/dist/events/logs.js +25 -0
- package/dist/events/oracleRegistrySync.d.ts +33 -0
- package/dist/events/oracleRegistrySync.d.ts.map +1 -0
- package/dist/events/oracleRegistrySync.js +93 -0
- package/dist/generated.d.ts +8499 -0
- package/dist/generated.d.ts.map +1 -0
- package/dist/generated.js +22 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/views/adapters.d.ts +19 -0
- package/dist/views/adapters.d.ts.map +1 -0
- package/dist/views/adapters.js +11 -0
- package/dist/views/core.d.ts +33 -0
- package/dist/views/core.d.ts.map +1 -0
- package/dist/views/core.js +50 -0
- package/dist/views/index.d.ts +5 -0
- package/dist/views/index.d.ts.map +1 -0
- package/dist/views/index.js +5 -0
- package/dist/views/oracle.d.ts +26 -0
- package/dist/views/oracle.d.ts.map +1 -0
- package/dist/views/oracle.js +41 -0
- package/dist/views/pool.d.ts +16 -0
- package/dist/views/pool.d.ts.map +1 -0
- package/dist/views/pool.js +32 -0
- package/package.json +15 -4
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @varla/sdk
|
|
2
|
+
|
|
3
|
+
Published SDK package for Varla.
|
|
4
|
+
|
|
5
|
+
This package is the single source of truth for:
|
|
6
|
+
- contract **ABIs**
|
|
7
|
+
- per-chain deployed **addresses**
|
|
8
|
+
- shared **types** used by Varla offchain services and apps
|
|
9
|
+
|
|
10
|
+
It also provides **typed read-only contract bindings** (via `viem`) for convenient access to
|
|
11
|
+
on-chain *view* functions.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# bun
|
|
17
|
+
bun add @varla/sdk
|
|
18
|
+
|
|
19
|
+
# npm
|
|
20
|
+
npm i @varla/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
## Testing (SDK)
|
|
26
|
+
|
|
27
|
+
Run from `packages/sdk`:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Primary suite: regenerate artifacts + build + run bun tests (includes RPC-backed integration tests)
|
|
31
|
+
bun test
|
|
32
|
+
|
|
33
|
+
# Quick: build + run bun tests (skips regeneration)
|
|
34
|
+
bun run test:quick
|
|
35
|
+
|
|
36
|
+
# Only RPC-backed integration tests (Polygon + BSC)
|
|
37
|
+
bun run test:rpc
|
|
38
|
+
|
|
39
|
+
# Only non-RPC smoke tests
|
|
40
|
+
bun run test:smoke
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### RPC configuration
|
|
44
|
+
|
|
45
|
+
By default, RPC-backed tests use public endpoints with fallback & retries.
|
|
46
|
+
For more reliability (recommended in CI), set:
|
|
47
|
+
|
|
48
|
+
- `POLYGON_RPC_URL`
|
|
49
|
+
- `BSC_RPC_URL`
|
|
50
|
+
|
|
51
|
+
Note: public RPC providers can change policies over time (rate limits, API keys). If tests become flaky,
|
|
52
|
+
set explicit RPC URLs via env.
|
|
53
|
+
|
|
54
|
+
### Addresses
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import * as addresses from "@varla/sdk/addresses";
|
|
58
|
+
|
|
59
|
+
// e.g.
|
|
60
|
+
// addresses.polygon.core
|
|
61
|
+
// addresses.bsc.pool
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### ABIs
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import * as abi from "@varla/sdk/abi";
|
|
68
|
+
|
|
69
|
+
// e.g.
|
|
70
|
+
// abi.VARLACORE_ABI
|
|
71
|
+
// abi.POLYMARKETCTFADAPTER_ABI
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Types
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import type { AddressBook } from "@varla/sdk";
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Read-only contract bindings (viem)
|
|
81
|
+
|
|
82
|
+
The SDK does not ship RPC URLs.
|
|
83
|
+
Consumers provide their own `viem` `PublicClient`.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { createPublicClient, http } from "viem";
|
|
87
|
+
import { polygon } from "viem/chains";
|
|
88
|
+
import { getVarlaContracts } from "@varla/sdk";
|
|
89
|
+
|
|
90
|
+
const client = createPublicClient({
|
|
91
|
+
chain: polygon,
|
|
92
|
+
transport: http(process.env.POLYGON_RPC_URL!),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const c = getVarlaContracts({ chain: "polygon", client });
|
|
96
|
+
|
|
97
|
+
// Typed reads (inferred from ABI)
|
|
98
|
+
const stats = await c.pool.read.getPoolStats();
|
|
99
|
+
const hf = await c.core.read.getHealthFactor(["0xYourUserAddress"]); // note viem args are arrays
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Higher-level views (facades)
|
|
103
|
+
|
|
104
|
+
These are convenience helpers built on top of the contract bindings.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { readOracleRegistry, readPoolSnapshot } from "@varla/sdk";
|
|
108
|
+
|
|
109
|
+
// Fetch all oracle-configured positionIds (uses multicall + chunking)
|
|
110
|
+
const positionIds = await readOracleRegistry({
|
|
111
|
+
oracle: c.oracle,
|
|
112
|
+
client,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Read pool snapshot (wraps getPoolStats)
|
|
116
|
+
const pool = await readPoolSnapshot({ pool: c.pool });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### Optional deployments
|
|
120
|
+
|
|
121
|
+
Some deployments are chain-specific (e.g. adapters). These are exposed as optional properties:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
if (c.polymarketCtfAdapter) {
|
|
125
|
+
// polygon
|
|
126
|
+
}
|
|
127
|
+
if (c.opinionCtfExecutionEngineAdapter) {
|
|
128
|
+
// bsc
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If you want to enforce presence for backends, use `getRequiredVarlaContracts`:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { getRequiredVarlaContracts } from "@varla/sdk";
|
|
136
|
+
|
|
137
|
+
const c = getRequiredVarlaContracts({
|
|
138
|
+
chain: "polygon",
|
|
139
|
+
client,
|
|
140
|
+
require: ["liquidator", "mergeLiquidator"],
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Generic token helpers (ERC20 / ERC1155)
|
|
145
|
+
|
|
146
|
+
Useful when you discover token addresses via Varla views:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { getErc20, getErc1155 } from "@varla/sdk";
|
|
150
|
+
|
|
151
|
+
const collateral = await c.core.read.collateralToken();
|
|
152
|
+
const usdc = getErc20({ client, address: collateral });
|
|
153
|
+
const decimals = await usdc.read.decimals();
|
|
154
|
+
|
|
155
|
+
const positionsToken = await c.core.read.positionsToken();
|
|
156
|
+
const ctf = getErc1155({ client, address: positionsToken });
|
|
157
|
+
const bal = await ctf.read.balanceOf(["0xUser", 123n]);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## How it’s built
|
|
161
|
+
|
|
162
|
+
On publish, this repo regenerates artifacts from the tracked `deployments/*` and Hardhat `artifacts/*`.
|
|
163
|
+
|
|
164
|
+
The published output is `dist/` and is exported via package `exports`.
|
package/dist/batch.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Abi, Address, PublicClient } from "viem";
|
|
2
|
+
export type MulticallChunkOptions = {
|
|
3
|
+
/** Number of calls per multicall batch. */
|
|
4
|
+
chunkSize?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Small utility to chunk an array.
|
|
8
|
+
*/
|
|
9
|
+
export declare function chunk<T>(items: readonly T[], chunkSize: number): T[][];
|
|
10
|
+
/**
|
|
11
|
+
* Executes `client.multicall` in chunks.
|
|
12
|
+
*
|
|
13
|
+
* - Keeps requests bounded for public RPC providers.
|
|
14
|
+
* - Preserves order.
|
|
15
|
+
*/
|
|
16
|
+
export declare function multicallChunks<TAbi extends Abi>(params: {
|
|
17
|
+
client: PublicClient;
|
|
18
|
+
contracts: readonly {
|
|
19
|
+
address: Address;
|
|
20
|
+
abi: Abi;
|
|
21
|
+
functionName: string;
|
|
22
|
+
args?: readonly unknown[] | undefined;
|
|
23
|
+
}[];
|
|
24
|
+
chunkSize?: number;
|
|
25
|
+
}): Promise<Awaited<ReturnType<PublicClient["multicall"]>>>;
|
|
26
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,MAAM,MAAM,qBAAqB,GAAG;IAClC,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAKtE;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,IAAI,SAAS,GAAG,EAAE,MAAM,EAAE;IAC9D,MAAM,EAAE,YAAY,CAAC;IAIrB,SAAS,EAAE,SAAS;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,GAAG,EAAE,GAAG,CAAC;QACT,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;KACvC,EAAE,CAAC;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAiB1D"}
|
package/dist/batch.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
+
/**
|
|
3
|
+
* Small utility to chunk an array.
|
|
4
|
+
*/
|
|
5
|
+
export function chunk(items, chunkSize) {
|
|
6
|
+
if (chunkSize <= 0)
|
|
7
|
+
throw new Error(`chunkSize must be > 0 (got ${chunkSize})`);
|
|
8
|
+
const out = [];
|
|
9
|
+
for (let i = 0; i < items.length; i += chunkSize)
|
|
10
|
+
out.push(items.slice(i, i + chunkSize));
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Executes `client.multicall` in chunks.
|
|
15
|
+
*
|
|
16
|
+
* - Keeps requests bounded for public RPC providers.
|
|
17
|
+
* - Preserves order.
|
|
18
|
+
*/
|
|
19
|
+
export async function multicallChunks(params) {
|
|
20
|
+
const { client } = params;
|
|
21
|
+
const chunkSize = params.chunkSize ?? 128;
|
|
22
|
+
const calls = params.contracts;
|
|
23
|
+
if (calls.length === 0)
|
|
24
|
+
return [];
|
|
25
|
+
// Note: we avoid a generic chunk() here because TS can sometimes lose the
|
|
26
|
+
// `client.multicall` contract-call type across the generic boundary.
|
|
27
|
+
const out = [];
|
|
28
|
+
for (let i = 0; i < calls.length; i += chunkSize) {
|
|
29
|
+
const slice = calls.slice(i, i + chunkSize);
|
|
30
|
+
const res = await client.multicall({ contracts: slice });
|
|
31
|
+
out.push(...res);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|