@varla/sdk 1.10.4 → 1.10.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.
@@ -1,4 +1,5 @@
1
1
  export * from "./tx.js";
2
+ export * from "./utils.js";
2
3
  export * from "./oracle.js";
3
4
  export * from "./core.js";
4
5
  export * from "./erc20.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAEA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAEA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
@@ -1,5 +1,6 @@
1
1
  // Note: explicit .js extension is required for Node ESM resolution.
2
2
  export * from "./tx.js";
3
+ export * from "./utils.js";
3
4
  export * from "./oracle.js";
4
5
  export * from "./core.js";
5
6
  export * from "./erc20.js";
@@ -38,4 +38,114 @@ export declare function prepareOracleUpdatePrices(params: {
38
38
  account: Address;
39
39
  items: readonly OraclePriceUpdateItem[];
40
40
  }): Promise<SimulatedTx>;
41
+ export type OracleLikeForSeeding = {
42
+ address: Address;
43
+ read: {
44
+ isConfigured: (args: readonly [bigint]) => Promise<boolean>;
45
+ getOppositePositionId: (args: readonly [bigint]) => Promise<bigint>;
46
+ isNegRisk: (args: readonly [bigint]) => Promise<boolean>;
47
+ getNegRiskMarketId: (args: readonly [bigint]) => Promise<`0x${string}`>;
48
+ };
49
+ };
50
+ export type OracleSeedPlan = {
51
+ /** New positions to configure via configurePositionsBatch */
52
+ configurePositions: MarketConfigItem[];
53
+ /** Opposite pairs to configure (skips already-correct pairs) */
54
+ configureOpposites: Array<{
55
+ yesPositionId: bigint;
56
+ noPositionId: bigint;
57
+ }>;
58
+ /** NegRisk mapping updates (only positionIds that are missing or mismatched) */
59
+ configureNegRisk: Array<{
60
+ marketId: `0x${string}`;
61
+ positionIds: bigint[];
62
+ }>;
63
+ };
64
+ export declare function planOracleSeed(params: {
65
+ oracle: OracleLikeForSeeding;
66
+ markets?: ReadonlyArray<MarketConfigItem>;
67
+ opposites?: ReadonlyArray<{
68
+ yesPositionId: bigint;
69
+ noPositionId: bigint;
70
+ }>;
71
+ negRisk?: ReadonlyArray<{
72
+ marketId: `0x${string}`;
73
+ positionIds: ReadonlyArray<bigint>;
74
+ }>;
75
+ }): Promise<OracleSeedPlan>;
76
+ export type OracleSeedExecResult = {
77
+ plan: OracleSeedPlan;
78
+ simulations: {
79
+ configurePositions?: SimulatedTx;
80
+ configureOpposites: SimulatedTx[];
81
+ configureNegRisk: SimulatedTx[];
82
+ };
83
+ };
84
+ export type MarketConfigItemJson = {
85
+ positionId: string | number;
86
+ riskTier: number;
87
+ conditionId: `0x${string}`;
88
+ resolutionTime: string | number;
89
+ };
90
+ export type OppositePairItemJson = {
91
+ yesPositionId: string | number;
92
+ noPositionId: string | number;
93
+ };
94
+ export type NegRiskMarketItemJson = {
95
+ marketId: `0x${string}`;
96
+ positionIds: Array<string | number>;
97
+ };
98
+ /**
99
+ * High-level helper for backends/frontends: seed using already-parsed JSON.
100
+ *
101
+ * This is environment-agnostic (browser-safe).
102
+ */
103
+ export type SeedOracleFromJsonResult = {
104
+ plan: OracleSeedPlan;
105
+ } | {
106
+ plan: OracleSeedPlan;
107
+ prepared: OracleSeedExecResult;
108
+ };
109
+ export declare function seedOracleFromJson(params: {
110
+ oracle: OracleLikeForSeeding;
111
+ marketsJson?: readonly MarketConfigItemJson[];
112
+ oppositesJson?: readonly OppositePairItemJson[];
113
+ negRiskJson?: readonly NegRiskMarketItemJson[];
114
+ /**
115
+ * Optional: if provided, also prepares simulateContract requests.
116
+ * If omitted, only returns the diff plan.
117
+ */
118
+ prepare?: {
119
+ publicClient: Pick<PublicClient, "simulateContract">;
120
+ oracleAddress: Address;
121
+ account: Address;
122
+ };
123
+ }): Promise<SeedOracleFromJsonResult>;
124
+ /**
125
+ * Node-only convenience helper: read JSON files from disk and seed.
126
+ *
127
+ * This uses dynamic imports so bundlers don’t pull `node:fs` into frontend builds.
128
+ */
129
+ export declare function seedOracleFromJsonFiles(params: {
130
+ oracle: OracleLikeForSeeding;
131
+ marketsPath?: string;
132
+ oppositesPath?: string;
133
+ negRiskPath?: string;
134
+ prepare?: {
135
+ publicClient: Pick<PublicClient, "simulateContract">;
136
+ oracleAddress: Address;
137
+ account: Address;
138
+ };
139
+ }): Promise<SeedOracleFromJsonResult>;
140
+ /**
141
+ * Given a plan (usually from `planOracleSeed`), prepare all necessary tx requests via simulate.
142
+ *
143
+ * NOTE: This does not send txs; use `sendTx({ walletClient, request: sim.request })`.
144
+ */
145
+ export declare function prepareOracleSeedPlan(params: {
146
+ publicClient: Pick<PublicClient, "simulateContract">;
147
+ oracleAddress: Address;
148
+ account: Address;
149
+ plan: OracleSeedPlan;
150
+ }): Promise<OracleSeedExecResult>;
41
151
  //# sourceMappingURL=oracle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oracle.d.ts","sourceRoot":"","sources":["../../src/actions/oracle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIlD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,KAAK,MAAM,EAA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GAAG,OAAO,CAAC,oBAAoB,CAAC,CAiDhC"}
@@ -44,3 +44,182 @@ export async function prepareOracleUpdatePrices(params) {
44
44
  account: params.account,
45
45
  }));
46
46
  }
47
+ export async function planOracleSeed(params) {
48
+ const plan = {
49
+ configurePositions: [],
50
+ configureOpposites: [],
51
+ configureNegRisk: [],
52
+ };
53
+ // ---------------------
54
+ // markets (configure)
55
+ // ---------------------
56
+ if (params.markets && params.markets.length > 0) {
57
+ // Idempotent: only configure markets not already configured.
58
+ for (const it of params.markets) {
59
+ const ok = await params.oracle.read.isConfigured([it.positionId]);
60
+ if (!ok)
61
+ plan.configurePositions.push({ ...it });
62
+ }
63
+ }
64
+ // ---------------------
65
+ // opposites
66
+ // ---------------------
67
+ if (params.opposites && params.opposites.length > 0) {
68
+ for (const p of params.opposites) {
69
+ const curYes = await params.oracle.read.getOppositePositionId([p.yesPositionId]);
70
+ const curNo = await params.oracle.read.getOppositePositionId([p.noPositionId]);
71
+ if (curYes === p.noPositionId && curNo === p.yesPositionId)
72
+ continue;
73
+ plan.configureOpposites.push({
74
+ yesPositionId: p.yesPositionId,
75
+ noPositionId: p.noPositionId,
76
+ });
77
+ }
78
+ }
79
+ // ---------------------
80
+ // negRisk
81
+ // ---------------------
82
+ if (params.negRisk && params.negRisk.length > 0) {
83
+ for (const m of params.negRisk) {
84
+ const missing = [];
85
+ for (const pid of m.positionIds) {
86
+ const isNeg = await params.oracle.read.isNegRisk([pid]);
87
+ if (!isNeg) {
88
+ missing.push(pid);
89
+ continue;
90
+ }
91
+ const curMarketId = await params.oracle.read.getNegRiskMarketId([pid]);
92
+ if (curMarketId.toLowerCase() !== m.marketId.toLowerCase()) {
93
+ missing.push(pid);
94
+ }
95
+ }
96
+ if (missing.length > 0) {
97
+ plan.configureNegRisk.push({ marketId: m.marketId, positionIds: missing });
98
+ }
99
+ }
100
+ }
101
+ return plan;
102
+ }
103
+ function toBigIntU256(x) {
104
+ if (typeof x === "number")
105
+ return BigInt(x);
106
+ if (x.startsWith("0x"))
107
+ return BigInt(x);
108
+ return BigInt(x);
109
+ }
110
+ function normalizeMarketsJson(items) {
111
+ return items.map((it) => ({
112
+ positionId: toBigIntU256(it.positionId),
113
+ riskTier: it.riskTier,
114
+ conditionId: it.conditionId,
115
+ resolutionTime: toBigIntU256(it.resolutionTime),
116
+ }));
117
+ }
118
+ function normalizeOppositesJson(items) {
119
+ return items.map((it) => ({
120
+ yesPositionId: toBigIntU256(it.yesPositionId),
121
+ noPositionId: toBigIntU256(it.noPositionId),
122
+ }));
123
+ }
124
+ function normalizeNegRiskJson(items) {
125
+ return items.map((it) => ({
126
+ marketId: it.marketId,
127
+ positionIds: it.positionIds.map(toBigIntU256),
128
+ }));
129
+ }
130
+ export async function seedOracleFromJson(params) {
131
+ const markets = params.marketsJson ? normalizeMarketsJson(params.marketsJson) : undefined;
132
+ const opposites = params.oppositesJson ? normalizeOppositesJson(params.oppositesJson) : undefined;
133
+ const negRisk = params.negRiskJson ? normalizeNegRiskJson(params.negRiskJson) : undefined;
134
+ const plan = await planOracleSeed({ oracle: params.oracle, markets, opposites, negRisk });
135
+ if (!params.prepare)
136
+ return { plan };
137
+ const prepared = await prepareOracleSeedPlan({
138
+ publicClient: params.prepare.publicClient,
139
+ oracleAddress: params.prepare.oracleAddress,
140
+ account: params.prepare.account,
141
+ plan,
142
+ });
143
+ return { plan, prepared };
144
+ }
145
+ /**
146
+ * Node-only convenience helper: read JSON files from disk and seed.
147
+ *
148
+ * This uses dynamic imports so bundlers don’t pull `node:fs` into frontend builds.
149
+ */
150
+ export async function seedOracleFromJsonFiles(params) {
151
+ let readFileSync;
152
+ try {
153
+ // Node 18+/Bun supports `node:fs`.
154
+ ({ readFileSync } = (await import("node:fs")));
155
+ }
156
+ catch {
157
+ throw new Error("seedOracleFromJsonFiles() is Node-only. In browsers, load JSON via fetch and call seedOracleFromJson().");
158
+ }
159
+ if (!readFileSync) {
160
+ throw new Error("Failed to load node:fs readFileSync");
161
+ }
162
+ const marketsJson = params.marketsPath
163
+ ? JSON.parse(readFileSync(params.marketsPath, "utf8"))
164
+ : undefined;
165
+ const oppositesJson = params.oppositesPath
166
+ ? JSON.parse(readFileSync(params.oppositesPath, "utf8"))
167
+ : undefined;
168
+ const negRiskJson = params.negRiskPath
169
+ ? JSON.parse(readFileSync(params.negRiskPath, "utf8"))
170
+ : undefined;
171
+ return seedOracleFromJson({
172
+ oracle: params.oracle,
173
+ marketsJson,
174
+ oppositesJson,
175
+ negRiskJson,
176
+ prepare: params.prepare,
177
+ });
178
+ }
179
+ /**
180
+ * Given a plan (usually from `planOracleSeed`), prepare all necessary tx requests via simulate.
181
+ *
182
+ * NOTE: This does not send txs; use `sendTx({ walletClient, request: sim.request })`.
183
+ */
184
+ export async function prepareOracleSeedPlan(params) {
185
+ const { plan } = params;
186
+ const configurePositions = plan.configurePositions.length > 0
187
+ ? await prepareOracleConfigurePositionsBatch({
188
+ publicClient: params.publicClient,
189
+ oracleAddress: params.oracleAddress,
190
+ account: params.account,
191
+ items: plan.configurePositions,
192
+ })
193
+ : undefined;
194
+ const configureOpposites = [];
195
+ for (const p of plan.configureOpposites) {
196
+ configureOpposites.push(await prepareOracleConfigureOppositePositions({
197
+ publicClient: params.publicClient,
198
+ oracleAddress: params.oracleAddress,
199
+ account: params.account,
200
+ yesPositionId: p.yesPositionId,
201
+ noPositionId: p.noPositionId,
202
+ }));
203
+ }
204
+ const configureNegRisk = [];
205
+ for (const m of plan.configureNegRisk) {
206
+ // Avoid useless batch calls.
207
+ if (m.positionIds.length === 0)
208
+ continue;
209
+ configureNegRisk.push(await prepareOracleConfigureNegRiskPositionsBatch({
210
+ publicClient: params.publicClient,
211
+ oracleAddress: params.oracleAddress,
212
+ account: params.account,
213
+ positionIds: m.positionIds,
214
+ marketId: m.marketId,
215
+ }));
216
+ }
217
+ return {
218
+ plan,
219
+ simulations: {
220
+ configurePositions,
221
+ configureOpposites,
222
+ configureNegRisk,
223
+ },
224
+ };
225
+ }
@@ -0,0 +1,9 @@
1
+ import type { Hex } from "viem";
2
+ /**
3
+ * Compute a 4-byte function selector from a Solidity function signature.
4
+ *
5
+ * Example:
6
+ * - "borrow(uint256)" -> 0x....
7
+ */
8
+ export declare function selectorFromSignature(signature: string): Hex;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/actions/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGhC;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAG5D"}
@@ -0,0 +1,12 @@
1
+ // Note: explicit .js extension is required for Node ESM resolution.
2
+ import { keccak256, toBytes } from "viem";
3
+ /**
4
+ * Compute a 4-byte function selector from a Solidity function signature.
5
+ *
6
+ * Example:
7
+ * - "borrow(uint256)" -> 0x....
8
+ */
9
+ export function selectorFromSignature(signature) {
10
+ const hash = keccak256(toBytes(signature));
11
+ return `0x${hash.slice(2, 10)}`;
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varla/sdk",
3
- "version": "1.10.4",
3
+ "version": "1.10.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,