timelock-sdk 0.0.110 → 0.0.112
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-191_W3kB.d.cts} +91 -84
- package/dist/{client--yJ0Oalw.d.ts → client-Bcn8F-k3.d.ts} +250 -243
- package/dist/client.cjs +125 -105
- 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 +126 -106
- 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-191_W3kB.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-Bcn8F-k3.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
|
@@ -6,7 +6,7 @@ import { A as getErc20, D as token1ToToken0, E as token0ToToken1, F as uniswapMa
|
|
|
6
6
|
import { n as uniswapV3PoolAbi, t as singleOwnerVaultAbi } from "./singleOwnerVault-BeJChjfJ.js";
|
|
7
7
|
import { encodeAbiParameters, encodeFunctionData, erc20Abi, maxUint256, zeroAddress } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useEffect, useMemo } from "react";
|
|
9
|
-
import { useAccount, useChainId, useClient, useReadContract, useSignMessage, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
9
|
+
import { useAccount, useBalance, useChainId, useClient, useReadContract, useSignMessage, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
10
10
|
import { GraphQLClient, RequestOptions } from "graphql-request";
|
|
11
11
|
import gql from "graphql-tag";
|
|
12
12
|
import { waitForTransactionReceipt } from "viem/actions";
|
|
@@ -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
|
]);
|
|
@@ -811,102 +912,6 @@ const useOptionTimeline = (marketAddr, optionId) => {
|
|
|
811
912
|
};
|
|
812
913
|
};
|
|
813
914
|
|
|
814
|
-
//#endregion
|
|
815
|
-
//#region src/lib/perpsOperator.ts
|
|
816
|
-
var PerpsOperator = class {
|
|
817
|
-
#baseUrl;
|
|
818
|
-
auth;
|
|
819
|
-
constructor(baseUrl) {
|
|
820
|
-
this.#baseUrl = baseUrl;
|
|
821
|
-
}
|
|
822
|
-
#request = async (path, body) => {
|
|
823
|
-
const url = new URL(path, this.#baseUrl);
|
|
824
|
-
const res = await fetch(url, {
|
|
825
|
-
method: body ? "POST" : "GET",
|
|
826
|
-
headers: {
|
|
827
|
-
Connection: "keep-alive",
|
|
828
|
-
"Content-Type": "application/json",
|
|
829
|
-
"Keep-Alive": "timeout=120"
|
|
830
|
-
},
|
|
831
|
-
body: body ? JSON.stringify(body) : void 0
|
|
832
|
-
});
|
|
833
|
-
if (res.ok) {
|
|
834
|
-
const { data } = await res.json();
|
|
835
|
-
return data;
|
|
836
|
-
}
|
|
837
|
-
const resText = await res.text();
|
|
838
|
-
try {
|
|
839
|
-
const error = JSON.parse(resText);
|
|
840
|
-
throw new Error(`${res.status} ${res.statusText}: ${error.error}`);
|
|
841
|
-
} catch (error) {
|
|
842
|
-
throw new Error(`${res.status} ${res.statusText}: ${resText}`);
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
getOperatorAddr = async () => {
|
|
846
|
-
const { address } = await this.#request("api/operator/address");
|
|
847
|
-
return address;
|
|
848
|
-
};
|
|
849
|
-
genAuthMessage = async (userAddr) => {
|
|
850
|
-
const { message } = await this.#request("api/auth/gen", { userAddr });
|
|
851
|
-
return message;
|
|
852
|
-
};
|
|
853
|
-
validateAuthMessage = async (message, signature) => {
|
|
854
|
-
const { address, createdAt, validUntil } = await this.#request("api/auth/validate", {
|
|
855
|
-
message,
|
|
856
|
-
signature
|
|
857
|
-
});
|
|
858
|
-
return {
|
|
859
|
-
address,
|
|
860
|
-
createdAt,
|
|
861
|
-
validUntil
|
|
862
|
-
};
|
|
863
|
-
};
|
|
864
|
-
setAuth = (message, signature) => {
|
|
865
|
-
this.auth = {
|
|
866
|
-
message,
|
|
867
|
-
signature
|
|
868
|
-
};
|
|
869
|
-
};
|
|
870
|
-
getUserPerps = async (userAddr, marketAddr, type, offset = 0, limit = 1e3) => {
|
|
871
|
-
const params = new URLSearchParams({
|
|
872
|
-
offset: offset.toString(),
|
|
873
|
-
limit: limit.toString()
|
|
874
|
-
});
|
|
875
|
-
if (type) params.append("type", type);
|
|
876
|
-
if (marketAddr) params.append("marketAddr", marketAddr);
|
|
877
|
-
const url = `api/positions/${userAddr}?${params.toString()}`;
|
|
878
|
-
return (await this.#request(url)).map((p) => ({
|
|
879
|
-
...p,
|
|
880
|
-
optionId: BigInt(p.optionId)
|
|
881
|
-
}));
|
|
882
|
-
};
|
|
883
|
-
mintPerp = async (body) => {
|
|
884
|
-
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
885
|
-
const { txHash, optionId } = await this.#request("api/positions/mint", {
|
|
886
|
-
...body,
|
|
887
|
-
amount: body.amount.toString(),
|
|
888
|
-
auth: this.auth
|
|
889
|
-
});
|
|
890
|
-
return {
|
|
891
|
-
txHash,
|
|
892
|
-
optionId: BigInt(optionId)
|
|
893
|
-
};
|
|
894
|
-
};
|
|
895
|
-
exercisePerp = async (body) => {
|
|
896
|
-
if (!this.auth) throw new Error("Authentication required. Call setAuth() with authMessage and signature before exercising perps.");
|
|
897
|
-
const { txHash, optionId } = await this.#request("api/positions/exercise", {
|
|
898
|
-
...body,
|
|
899
|
-
optionId: body.optionId.toString(),
|
|
900
|
-
liquidities: body.liquidities.map((l) => l.toString()),
|
|
901
|
-
auth: this.auth
|
|
902
|
-
});
|
|
903
|
-
return {
|
|
904
|
-
txHash,
|
|
905
|
-
optionId: BigInt(optionId)
|
|
906
|
-
};
|
|
907
|
-
};
|
|
908
|
-
};
|
|
909
|
-
|
|
910
915
|
//#endregion
|
|
911
916
|
//#region src/hooks/perps/usePerpsOperator.ts
|
|
912
917
|
const ZHex = z.string().regex(/^0x[a-fA-F0-9]+$/, "Invalid hex string").transform((v) => v);
|
|
@@ -939,9 +944,8 @@ const clearSignature = (userAddr) => {
|
|
|
939
944
|
};
|
|
940
945
|
const usePerpsOperator = () => {
|
|
941
946
|
const { address: userAddr } = useAccount();
|
|
942
|
-
const { perpsOperatorUrl } = useTimelockConfig();
|
|
947
|
+
const { perpsOperatorUrl, perpsOperator: operator } = useTimelockConfig();
|
|
943
948
|
const { signMessageAsync } = useSignMessage();
|
|
944
|
-
const operator = useMemo(() => perpsOperatorUrl ? new PerpsOperator(perpsOperatorUrl) : void 0, [perpsOperatorUrl]);
|
|
945
949
|
const { data: address } = useQuery({
|
|
946
950
|
queryKey: ["perpsOperatorAddr", perpsOperatorUrl || "--"],
|
|
947
951
|
queryFn: () => operator === null || operator === void 0 ? void 0 : operator.getOperatorAddr(),
|
|
@@ -1166,6 +1170,11 @@ const useClosedUserPerps = (marketAddr, userAddr) => {
|
|
|
1166
1170
|
//#endregion
|
|
1167
1171
|
//#region src/hooks/operators/useOperatorPerms.ts
|
|
1168
1172
|
const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
|
|
1173
|
+
const { payoutAsset } = useMarketData(marketAddr);
|
|
1174
|
+
const { data: payoutAssetBalance } = useBalance({
|
|
1175
|
+
address: userAddr,
|
|
1176
|
+
token: payoutAsset
|
|
1177
|
+
});
|
|
1169
1178
|
const { data,...rest } = useReadContract({
|
|
1170
1179
|
abi: optionsMarketAbi,
|
|
1171
1180
|
address: marketAddr,
|
|
@@ -1173,14 +1182,25 @@ const useOperatorPerms = (marketAddr, userAddr, operatorAddr) => {
|
|
|
1173
1182
|
args: [userAddr, operatorAddr],
|
|
1174
1183
|
query: { enabled: !!userAddr && !!operatorAddr }
|
|
1175
1184
|
});
|
|
1185
|
+
const [canExtend, canExercise, canTransfer, canMint, spendingApproval] = data || [];
|
|
1186
|
+
const min = (a, b) => a < b ? a : b;
|
|
1187
|
+
const effectiveApproval = spendingApproval && payoutAssetBalance ? min(spendingApproval, payoutAssetBalance.value) : 0n;
|
|
1176
1188
|
return {
|
|
1177
|
-
data:
|
|
1178
|
-
canExtend
|
|
1179
|
-
canExercise
|
|
1180
|
-
canTransfer
|
|
1181
|
-
canMint
|
|
1182
|
-
spendingApproval
|
|
1183
|
-
|
|
1189
|
+
data: useMemo(() => ({
|
|
1190
|
+
canExtend,
|
|
1191
|
+
canExercise,
|
|
1192
|
+
canTransfer,
|
|
1193
|
+
canMint,
|
|
1194
|
+
spendingApproval,
|
|
1195
|
+
effectiveApproval
|
|
1196
|
+
}), [
|
|
1197
|
+
canExtend,
|
|
1198
|
+
canExercise,
|
|
1199
|
+
canTransfer,
|
|
1200
|
+
canMint,
|
|
1201
|
+
spendingApproval,
|
|
1202
|
+
effectiveApproval
|
|
1203
|
+
]),
|
|
1184
1204
|
...rest
|
|
1185
1205
|
};
|
|
1186
1206
|
};
|