timelock-sdk 0.0.109 → 0.0.111
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/{client-61tvmrlq.d.cts → client-BioBT1mO.d.cts} +49 -48
- package/dist/{client-BcsbWPvK.d.ts → client-Di3SarC6.d.ts} +49 -48
- package/dist/client.cjs +142 -102
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +142 -102
- package/dist/client.js.map +1 -1
- package/dist/package.d.cts +1 -1
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-B_cHjOOB.cjs";
|
|
2
|
-
import { B as usePerpsOperator, F as useUserOperators, G as useExtendOption, H as useMintPerp, I as useOperatorPerms, J as useMintOption, K as useOptionPremium, L as useActiveUserPerps, P as useSetOperatorPerms, R as useClosedUserPerps, U as OptionTimelineData, V as useClosePerp, W as useOptionTimeline, Y as useMaxPositionSize, _t as useCurrentMarket, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, d as usePriceAtTick, dt as useMarketData, f as UniswapPoolData, ft as useExerciseOption, gt as TimelockProvider, h as useCurrentPrice, ht as useClosedUserOptions, i as useVaultData, l as useBurnLiquidity, m as useCurrentTick, mt as useActiveUserOptions, n as useLens, o as useMintLiquidity, p as usePoolData, pt as OptionData, q as useOptionPnl, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as useTimelockConfig, z as useUserPerps } from "./client-
|
|
2
|
+
import { B as usePerpsOperator, F as useUserOperators, G as useExtendOption, H as useMintPerp, I as useOperatorPerms, J as useMintOption, K as useOptionPremium, L as useActiveUserPerps, P as useSetOperatorPerms, R as useClosedUserPerps, U as OptionTimelineData, V as useClosePerp, W as useOptionTimeline, Y as useMaxPositionSize, _t as useCurrentMarket, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, d as usePriceAtTick, dt as useMarketData, f as UniswapPoolData, ft as useExerciseOption, gt as TimelockProvider, h as useCurrentPrice, ht as useClosedUserOptions, i as useVaultData, l as useBurnLiquidity, m as useCurrentTick, mt as useActiveUserOptions, n as useLens, o as useMintLiquidity, p as usePoolData, pt as OptionData, q as useOptionPnl, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as useTimelockConfig, z as useUserPerps } from "./client-BioBT1mO.cjs";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./uniswapMathLens-ChJFZ6hc.js";
|
|
2
|
-
import { B as usePerpsOperator, F as useUserOperators, G as useExtendOption, H as useMintPerp, I as useOperatorPerms, J as useMintOption, K as useOptionPremium, L as useActiveUserPerps, P as useSetOperatorPerms, R as useClosedUserPerps, U as OptionTimelineData, V as useClosePerp, W as useOptionTimeline, Y as useMaxPositionSize, _t as useCurrentMarket, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, d as usePriceAtTick, dt as useMarketData, f as UniswapPoolData, ft as useExerciseOption, gt as TimelockProvider, h as useCurrentPrice, ht as useClosedUserOptions, i as useVaultData, l as useBurnLiquidity, m as useCurrentTick, mt as useActiveUserOptions, n as useLens, o as useMintLiquidity, p as usePoolData, pt as OptionData, q as useOptionPnl, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as useTimelockConfig, z as useUserPerps } from "./client-
|
|
2
|
+
import { B as usePerpsOperator, F as useUserOperators, G as useExtendOption, H as useMintPerp, I as useOperatorPerms, J as useMintOption, K as useOptionPremium, L as useActiveUserPerps, P as useSetOperatorPerms, R as useClosedUserPerps, U as OptionTimelineData, V as useClosePerp, W as useOptionTimeline, Y as useMaxPositionSize, _t as useCurrentMarket, a as batchGetAmountsFromLiquidity, c as useLiquidityBlocks, d as usePriceAtTick, dt as useMarketData, f as UniswapPoolData, ft as useExerciseOption, gt as TimelockProvider, h as useCurrentPrice, ht as useClosedUserOptions, i as useVaultData, l as useBurnLiquidity, m as useCurrentTick, mt as useActiveUserOptions, n as useLens, o as useMintLiquidity, p as usePoolData, pt as OptionData, q as useOptionPnl, r as useVaultTVL, s as LiquidityBlockData, t as useApproval, u as usePriceHistory, vt as useTimelockConfig, z as useUserPerps } from "./client-Di3SarC6.js";
|
|
3
3
|
export { LiquidityBlockData, OptionData, OptionTimelineData, TimelockProvider, UniswapPoolData, batchGetAmountsFromLiquidity, useActiveUserOptions, useActiveUserPerps, useApproval, useBurnLiquidity, useClosePerp, useClosedUserOptions, useClosedUserPerps, useCurrentMarket, useCurrentPrice, useCurrentTick, useExerciseOption, useExtendOption, useLens, useLiquidityBlocks, useMarketData, useMaxPositionSize, useMintLiquidity, useMintOption, useMintPerp, useOperatorPerms, useOptionPnl, useOptionPremium, useOptionTimeline, usePerpsOperator, usePoolData, usePriceAtTick, usePriceHistory, useSetOperatorPerms, useTimelockConfig, useUserOperators, useUserPerps, useVaultData, useVaultTVL };
|
package/dist/client.js
CHANGED
|
@@ -280,6 +280,102 @@ function getSdk(client, withWrapper = defaultWrapper) {
|
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/lib/perpsOperator.ts
|
|
285
|
+
var PerpsOperator = class {
|
|
286
|
+
#baseUrl;
|
|
287
|
+
auth;
|
|
288
|
+
constructor(baseUrl) {
|
|
289
|
+
this.#baseUrl = baseUrl;
|
|
290
|
+
}
|
|
291
|
+
#request = async (path, body) => {
|
|
292
|
+
const url = new URL(path, this.#baseUrl);
|
|
293
|
+
const res = await fetch(url, {
|
|
294
|
+
method: body ? "POST" : "GET",
|
|
295
|
+
headers: {
|
|
296
|
+
Connection: "keep-alive",
|
|
297
|
+
"Content-Type": "application/json",
|
|
298
|
+
"Keep-Alive": "timeout=120"
|
|
299
|
+
},
|
|
300
|
+
body: body ? JSON.stringify(body) : void 0
|
|
301
|
+
});
|
|
302
|
+
if (res.ok) {
|
|
303
|
+
const { data } = await res.json();
|
|
304
|
+
return data;
|
|
305
|
+
}
|
|
306
|
+
const resText = await res.text();
|
|
307
|
+
try {
|
|
308
|
+
const error = JSON.parse(resText);
|
|
309
|
+
throw new Error(`${res.status} ${res.statusText}: ${error.error}`);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
throw new Error(`${res.status} ${res.statusText}: ${resText}`);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
getOperatorAddr = async () => {
|
|
315
|
+
const { address } = await this.#request("api/operator/address");
|
|
316
|
+
return address;
|
|
317
|
+
};
|
|
318
|
+
genAuthMessage = async (userAddr) => {
|
|
319
|
+
const { message } = await this.#request("api/auth/gen", { userAddr });
|
|
320
|
+
return message;
|
|
321
|
+
};
|
|
322
|
+
validateAuthMessage = async (message, signature) => {
|
|
323
|
+
const { address, createdAt, validUntil } = await this.#request("api/auth/validate", {
|
|
324
|
+
message,
|
|
325
|
+
signature
|
|
326
|
+
});
|
|
327
|
+
return {
|
|
328
|
+
address,
|
|
329
|
+
createdAt,
|
|
330
|
+
validUntil
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
setAuth = (message, signature) => {
|
|
334
|
+
this.auth = {
|
|
335
|
+
message,
|
|
336
|
+
signature
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
getUserPerps = async (userAddr, marketAddr, type, offset = 0, limit = 1e3) => {
|
|
340
|
+
const params = new URLSearchParams({
|
|
341
|
+
offset: offset.toString(),
|
|
342
|
+
limit: limit.toString()
|
|
343
|
+
});
|
|
344
|
+
if (type) params.append("type", type);
|
|
345
|
+
if (marketAddr) params.append("marketAddr", marketAddr);
|
|
346
|
+
const url = `api/positions/${userAddr}?${params.toString()}`;
|
|
347
|
+
return (await this.#request(url)).map((p) => ({
|
|
348
|
+
...p,
|
|
349
|
+
optionId: BigInt(p.optionId)
|
|
350
|
+
}));
|
|
351
|
+
};
|
|
352
|
+
mintPerp = async (body) => {
|
|
353
|
+
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
354
|
+
const { txHash, optionId } = await this.#request("api/positions/mint", {
|
|
355
|
+
...body,
|
|
356
|
+
amount: body.amount.toString(),
|
|
357
|
+
auth: this.auth
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
txHash,
|
|
361
|
+
optionId: BigInt(optionId)
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
exercisePerp = async (body) => {
|
|
365
|
+
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
366
|
+
const { txHash, optionId } = await this.#request("api/positions/exercise", {
|
|
367
|
+
...body,
|
|
368
|
+
optionId: body.optionId.toString(),
|
|
369
|
+
liquidities: body.liquidities.map((l) => l.toString()),
|
|
370
|
+
auth: this.auth
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
txHash,
|
|
374
|
+
optionId: BigInt(optionId)
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
|
|
283
379
|
//#endregion
|
|
284
380
|
//#region src/providers/TimelockProvider.tsx
|
|
285
381
|
const TimelockContext = createContext(void 0);
|
|
@@ -290,11 +386,15 @@ const TimelockProvider = ({ children, marketData, envioGraphqlUrl, perpsOperator
|
|
|
290
386
|
const graphqlClient = useMemo(() => {
|
|
291
387
|
if (envioGraphqlUrl) return getSdk(new GraphQLClient(envioGraphqlUrl));
|
|
292
388
|
}, [envioGraphqlUrl]);
|
|
389
|
+
const perpsOperator = useMemo(() => {
|
|
390
|
+
if (perpsOperatorUrl) return new PerpsOperator(perpsOperatorUrl);
|
|
391
|
+
}, [perpsOperatorUrl]);
|
|
293
392
|
const contextValue = useMemo(() => ({
|
|
294
393
|
marketData: marketData || {},
|
|
295
394
|
lensAddr,
|
|
296
395
|
uniswapMathLensAddr,
|
|
297
396
|
envioGraphqlUrl,
|
|
397
|
+
perpsOperator,
|
|
298
398
|
graphqlClient,
|
|
299
399
|
perpsOperatorUrl
|
|
300
400
|
}), [
|
|
@@ -302,6 +402,7 @@ const TimelockProvider = ({ children, marketData, envioGraphqlUrl, perpsOperator
|
|
|
302
402
|
lensAddr,
|
|
303
403
|
uniswapMathLensAddr,
|
|
304
404
|
envioGraphqlUrl,
|
|
405
|
+
perpsOperator,
|
|
305
406
|
graphqlClient,
|
|
306
407
|
perpsOperatorUrl
|
|
307
408
|
]);
|
|
@@ -410,7 +511,16 @@ const useExerciseOption = (marketAddr) => {
|
|
|
410
511
|
]
|
|
411
512
|
});
|
|
412
513
|
await waitForTransactionReceipt(client, { hash });
|
|
413
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
514
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
515
|
+
"userOptions",
|
|
516
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
517
|
+
true
|
|
518
|
+
] });
|
|
519
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
520
|
+
"userOptions",
|
|
521
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
522
|
+
false
|
|
523
|
+
] });
|
|
414
524
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
415
525
|
return hash;
|
|
416
526
|
};
|
|
@@ -543,7 +653,16 @@ const useMintOption = (marketAddr) => {
|
|
|
543
653
|
]
|
|
544
654
|
});
|
|
545
655
|
await waitForTransactionReceipt(client, { hash });
|
|
546
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
656
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
657
|
+
"userOptions",
|
|
658
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
659
|
+
true
|
|
660
|
+
] });
|
|
661
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
662
|
+
"userOptions",
|
|
663
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
664
|
+
false
|
|
665
|
+
] });
|
|
547
666
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
548
667
|
return hash;
|
|
549
668
|
};
|
|
@@ -793,102 +912,6 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
793
912
|
};
|
|
794
913
|
};
|
|
795
914
|
|
|
796
|
-
//#endregion
|
|
797
|
-
//#region src/lib/perpsOperator.ts
|
|
798
|
-
var PerpsOperator = class {
|
|
799
|
-
#baseUrl;
|
|
800
|
-
auth;
|
|
801
|
-
constructor(baseUrl) {
|
|
802
|
-
this.#baseUrl = baseUrl;
|
|
803
|
-
}
|
|
804
|
-
#request = async (path, body) => {
|
|
805
|
-
const url = new URL(path, this.#baseUrl);
|
|
806
|
-
const res = await fetch(url, {
|
|
807
|
-
method: body ? "POST" : "GET",
|
|
808
|
-
headers: {
|
|
809
|
-
Connection: "keep-alive",
|
|
810
|
-
"Content-Type": "application/json",
|
|
811
|
-
"Keep-Alive": "timeout=120"
|
|
812
|
-
},
|
|
813
|
-
body: body ? JSON.stringify(body) : void 0
|
|
814
|
-
});
|
|
815
|
-
if (res.ok) {
|
|
816
|
-
const { data } = await res.json();
|
|
817
|
-
return data;
|
|
818
|
-
}
|
|
819
|
-
const resText = await res.text();
|
|
820
|
-
try {
|
|
821
|
-
const error = JSON.parse(resText);
|
|
822
|
-
throw new Error(`${res.status} ${res.statusText}: ${error.error}`);
|
|
823
|
-
} catch (error) {
|
|
824
|
-
throw new Error(`${res.status} ${res.statusText}: ${resText}`);
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
getOperatorAddr = async () => {
|
|
828
|
-
const { address } = await this.#request("api/operator/address");
|
|
829
|
-
return address;
|
|
830
|
-
};
|
|
831
|
-
genAuthMessage = async (userAddr) => {
|
|
832
|
-
const { message } = await this.#request("api/auth/gen", { userAddr });
|
|
833
|
-
return message;
|
|
834
|
-
};
|
|
835
|
-
validateAuthMessage = async (message, signature) => {
|
|
836
|
-
const { address, createdAt, validUntil } = await this.#request("api/auth/validate", {
|
|
837
|
-
message,
|
|
838
|
-
signature
|
|
839
|
-
});
|
|
840
|
-
return {
|
|
841
|
-
address,
|
|
842
|
-
createdAt,
|
|
843
|
-
validUntil
|
|
844
|
-
};
|
|
845
|
-
};
|
|
846
|
-
setAuth = (message, signature) => {
|
|
847
|
-
this.auth = {
|
|
848
|
-
message,
|
|
849
|
-
signature
|
|
850
|
-
};
|
|
851
|
-
};
|
|
852
|
-
getUserPerps = async (userAddr, marketAddr, type, offset = 0, limit = 1e3) => {
|
|
853
|
-
const params = new URLSearchParams({
|
|
854
|
-
offset: offset.toString(),
|
|
855
|
-
limit: limit.toString()
|
|
856
|
-
});
|
|
857
|
-
if (type) params.append("type", type);
|
|
858
|
-
if (marketAddr) params.append("marketAddr", marketAddr);
|
|
859
|
-
const url = `api/positions/${userAddr}?${params.toString()}`;
|
|
860
|
-
return (await this.#request(url)).map((p) => ({
|
|
861
|
-
...p,
|
|
862
|
-
optionId: BigInt(p.optionId)
|
|
863
|
-
}));
|
|
864
|
-
};
|
|
865
|
-
mintPerp = async (body) => {
|
|
866
|
-
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
867
|
-
const { txHash, optionId } = await this.#request("api/positions/mint", {
|
|
868
|
-
...body,
|
|
869
|
-
amount: body.amount.toString(),
|
|
870
|
-
auth: this.auth
|
|
871
|
-
});
|
|
872
|
-
return {
|
|
873
|
-
txHash,
|
|
874
|
-
optionId: BigInt(optionId)
|
|
875
|
-
};
|
|
876
|
-
};
|
|
877
|
-
exercisePerp = async (body) => {
|
|
878
|
-
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
879
|
-
const { txHash, optionId } = await this.#request("api/positions/exercise", {
|
|
880
|
-
...body,
|
|
881
|
-
optionId: body.optionId.toString(),
|
|
882
|
-
liquidities: body.liquidities.map((l) => l.toString()),
|
|
883
|
-
auth: this.auth
|
|
884
|
-
});
|
|
885
|
-
return {
|
|
886
|
-
txHash,
|
|
887
|
-
optionId: BigInt(optionId)
|
|
888
|
-
};
|
|
889
|
-
};
|
|
890
|
-
};
|
|
891
|
-
|
|
892
915
|
//#endregion
|
|
893
916
|
//#region src/hooks/perps/usePerpsOperator.ts
|
|
894
917
|
const ZHex = z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex string").transform((v) => v);
|
|
@@ -921,9 +944,8 @@ const clearSignature = (userAddr) => {
|
|
|
921
944
|
};
|
|
922
945
|
const usePerpsOperator = () => {
|
|
923
946
|
const { address: userAddr } = useAccount();
|
|
924
|
-
const { perpsOperatorUrl } = useTimelockConfig();
|
|
947
|
+
const { perpsOperatorUrl, perpsOperator: operator } = useTimelockConfig();
|
|
925
948
|
const { signMessageAsync } = useSignMessage();
|
|
926
|
-
const operator = useMemo(() => perpsOperatorUrl ? new PerpsOperator(perpsOperatorUrl) : void 0, [perpsOperatorUrl]);
|
|
927
949
|
const { data: address } = useQuery({
|
|
928
950
|
queryKey: ["perpsOperatorAddr", perpsOperatorUrl || "--"],
|
|
929
951
|
queryFn: () => operator === null || operator === void 0 ? void 0 : operator.getOperatorAddr(),
|
|
@@ -1075,7 +1097,16 @@ const useMintPerp = (marketAddr) => {
|
|
|
1075
1097
|
duration,
|
|
1076
1098
|
strikeTick: validStrikeTick
|
|
1077
1099
|
});
|
|
1078
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1100
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
1101
|
+
"userOptions",
|
|
1102
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1103
|
+
true
|
|
1104
|
+
] });
|
|
1105
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
1106
|
+
"userOptions",
|
|
1107
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1108
|
+
false
|
|
1109
|
+
] });
|
|
1079
1110
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1080
1111
|
};
|
|
1081
1112
|
return useMutation({ mutationFn: mintPerp });
|
|
@@ -1091,7 +1122,16 @@ const useClosePerp = () => {
|
|
|
1091
1122
|
if (!operator) throw new Error("Operator not connected");
|
|
1092
1123
|
if (!operator.auth) await signMessage();
|
|
1093
1124
|
await operator.exercisePerp(body);
|
|
1094
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
1125
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
1126
|
+
"userOptions",
|
|
1127
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1128
|
+
true
|
|
1129
|
+
] });
|
|
1130
|
+
queryClient.invalidateQueries({ queryKey: [
|
|
1131
|
+
"userOptions",
|
|
1132
|
+
address === null || address === void 0 ? void 0 : address.toLowerCase(),
|
|
1133
|
+
false
|
|
1134
|
+
] });
|
|
1095
1135
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
1096
1136
|
} });
|
|
1097
1137
|
};
|