timelock-sdk 0.0.28 → 0.0.30
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.cjs +39 -43
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +133 -128
- package/dist/client.d.ts +72 -67
- package/dist/client.js +40 -44
- package/dist/client.js.map +1 -1
- package/dist/{index-DW-OoI-q.d.ts → index-CRhFaRiq.d.ts} +92 -92
- package/dist/package.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -7,7 +7,7 @@ import { singleOwnerVaultAbi, uniswapV3PoolAbi } from "./uniswapV3Pool-Copswrde.
|
|
|
7
7
|
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
8
8
|
import React, { createContext, useContext, useMemo } from "react";
|
|
9
9
|
import { useAccount, useChainId, useClient, useReadContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
10
|
-
import { GraphQLClient } from "graphql-request";
|
|
10
|
+
import { GraphQLClient, RequestOptions } from "graphql-request";
|
|
11
11
|
import gql from "graphql-tag";
|
|
12
12
|
import { waitForTransactionReceipt } from "viem/actions";
|
|
13
13
|
import { useQuery } from "@tanstack/react-query";
|
|
@@ -144,16 +144,21 @@ const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
|
|
|
144
144
|
const chainId = useChainId();
|
|
145
145
|
const lensAddr = timelockLenses[chainId];
|
|
146
146
|
const uniswapMathLensAddr = uniswapMathLenses[chainId];
|
|
147
|
+
const graphqlClient = useMemo(() => {
|
|
148
|
+
if (envioGraphqlUrl) return getSdk(new GraphQLClient(envioGraphqlUrl));
|
|
149
|
+
}, [envioGraphqlUrl]);
|
|
147
150
|
const contextValue = useMemo(() => ({
|
|
148
151
|
marketData: marketData || {},
|
|
149
152
|
lensAddr,
|
|
150
153
|
uniswapMathLensAddr,
|
|
151
|
-
envioGraphqlUrl
|
|
154
|
+
envioGraphqlUrl,
|
|
155
|
+
graphqlClient
|
|
152
156
|
}), [
|
|
153
157
|
marketData,
|
|
154
158
|
lensAddr,
|
|
155
159
|
uniswapMathLensAddr,
|
|
156
|
-
envioGraphqlUrl
|
|
160
|
+
envioGraphqlUrl,
|
|
161
|
+
graphqlClient
|
|
157
162
|
]);
|
|
158
163
|
return /* @__PURE__ */ React.createElement(TimelockMarketContext.Provider, { value: contextValue }, children);
|
|
159
164
|
};
|
|
@@ -165,34 +170,27 @@ const useCurrentMarket = () => {
|
|
|
165
170
|
const useTimelockConfig = () => {
|
|
166
171
|
const context = useContext(TimelockMarketContext);
|
|
167
172
|
if (context === void 0) throw new Error("useConfig must be used within a TimelockMarketProvider");
|
|
168
|
-
|
|
169
|
-
if (context.envioGraphqlUrl) return getSdk(new GraphQLClient(context.envioGraphqlUrl));
|
|
170
|
-
}, [context.envioGraphqlUrl]);
|
|
171
|
-
return {
|
|
172
|
-
lensAddr: context.lensAddr,
|
|
173
|
-
uniswapMathLensAddr: context.uniswapMathLensAddr,
|
|
174
|
-
envioGraphqlUrl: context.envioGraphqlUrl,
|
|
175
|
-
graphqlClient
|
|
176
|
-
};
|
|
173
|
+
return context;
|
|
177
174
|
};
|
|
178
175
|
|
|
179
176
|
//#endregion
|
|
180
177
|
//#region src/hooks/market/useMarketData.ts
|
|
181
|
-
const selectMarket = (data) => ({
|
|
182
|
-
...data.TimelockMarket[0],
|
|
183
|
-
pool: data.TimelockMarket[0].pool,
|
|
184
|
-
vault: data.TimelockMarket[0].vault,
|
|
185
|
-
optionAsset: data.TimelockMarket[0].optionAsset,
|
|
186
|
-
payoutAsset: data.TimelockMarket[0].payoutAsset,
|
|
187
|
-
optionsCount: BigInt(data.TimelockMarket[0].optionsCount),
|
|
188
|
-
tradersCount: BigInt(data.TimelockMarket[0].tradersCount)
|
|
189
|
-
});
|
|
190
178
|
const useMarketData = (marketAddr) => {
|
|
191
179
|
const { graphqlClient } = useTimelockConfig();
|
|
192
180
|
const { data } = useQuery({
|
|
193
181
|
queryKey: ["marketData", marketAddr || "--"],
|
|
194
|
-
queryFn: () =>
|
|
195
|
-
|
|
182
|
+
queryFn: async () => {
|
|
183
|
+
const result = await graphqlClient.GetMarketData({ marketAddr: marketAddr.toLowerCase() });
|
|
184
|
+
return {
|
|
185
|
+
...result.TimelockMarket[0],
|
|
186
|
+
pool: result.TimelockMarket[0].pool,
|
|
187
|
+
vault: result.TimelockMarket[0].vault,
|
|
188
|
+
optionAsset: result.TimelockMarket[0].optionAsset,
|
|
189
|
+
payoutAsset: result.TimelockMarket[0].payoutAsset,
|
|
190
|
+
optionsCount: BigInt(result.TimelockMarket[0].optionsCount),
|
|
191
|
+
tradersCount: BigInt(result.TimelockMarket[0].tradersCount)
|
|
192
|
+
};
|
|
193
|
+
},
|
|
196
194
|
enabled: !!marketAddr && !!graphqlClient
|
|
197
195
|
});
|
|
198
196
|
return data || {};
|
|
@@ -441,25 +439,6 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
|
|
|
441
439
|
|
|
442
440
|
//#endregion
|
|
443
441
|
//#region src/hooks/market/useUserOptions.ts
|
|
444
|
-
const selectOptions = (data) => {
|
|
445
|
-
if (!(data === null || data === void 0 ? void 0 : data.UserOption)) return [];
|
|
446
|
-
return data.UserOption.map((option) => ({
|
|
447
|
-
...option,
|
|
448
|
-
id: BigInt(option.id),
|
|
449
|
-
marketAddr: option.marketAddr,
|
|
450
|
-
optionType: option.optionType,
|
|
451
|
-
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
452
|
-
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
453
|
-
premiumPaid: BigInt(option.premiumPaid),
|
|
454
|
-
realizedPayout: BigInt(option.realizedPayout),
|
|
455
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
|
|
456
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
|
|
457
|
-
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
458
|
-
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
459
|
-
strikePrice: BigInt(option.strikePrice),
|
|
460
|
-
entryPrice: BigInt(option.entryPrice)
|
|
461
|
-
})).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
462
|
-
};
|
|
463
442
|
const useUserOptions = (user, active = false) => {
|
|
464
443
|
const { graphqlClient } = useTimelockConfig();
|
|
465
444
|
const { data,...rest } = useQuery({
|
|
@@ -468,8 +447,25 @@ const useUserOptions = (user, active = false) => {
|
|
|
468
447
|
user || "--",
|
|
469
448
|
active
|
|
470
449
|
],
|
|
471
|
-
queryFn: () =>
|
|
472
|
-
|
|
450
|
+
queryFn: async () => {
|
|
451
|
+
if (!graphqlClient) return [];
|
|
452
|
+
return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
|
|
453
|
+
...option,
|
|
454
|
+
id: BigInt(option.id),
|
|
455
|
+
marketAddr: option.marketAddr,
|
|
456
|
+
optionType: option.optionType,
|
|
457
|
+
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
458
|
+
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
459
|
+
premiumPaid: BigInt(option.premiumPaid),
|
|
460
|
+
realizedPayout: BigInt(option.realizedPayout),
|
|
461
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
|
|
462
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
|
|
463
|
+
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
464
|
+
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
465
|
+
strikePrice: BigInt(option.strikePrice),
|
|
466
|
+
entryPrice: BigInt(option.entryPrice)
|
|
467
|
+
})).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
468
|
+
},
|
|
473
469
|
enabled: !!user && !!graphqlClient
|
|
474
470
|
});
|
|
475
471
|
return {
|