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.cjs
CHANGED
|
@@ -151,16 +151,21 @@ const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
|
|
|
151
151
|
const chainId = (0, wagmi.useChainId)();
|
|
152
152
|
const lensAddr = require_numberUtils.timelockLenses[chainId];
|
|
153
153
|
const uniswapMathLensAddr = require_numberUtils.uniswapMathLenses[chainId];
|
|
154
|
+
const graphqlClient = (0, react.useMemo)(() => {
|
|
155
|
+
if (envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(envioGraphqlUrl));
|
|
156
|
+
}, [envioGraphqlUrl]);
|
|
154
157
|
const contextValue = (0, react.useMemo)(() => ({
|
|
155
158
|
marketData: marketData || {},
|
|
156
159
|
lensAddr,
|
|
157
160
|
uniswapMathLensAddr,
|
|
158
|
-
envioGraphqlUrl
|
|
161
|
+
envioGraphqlUrl,
|
|
162
|
+
graphqlClient
|
|
159
163
|
}), [
|
|
160
164
|
marketData,
|
|
161
165
|
lensAddr,
|
|
162
166
|
uniswapMathLensAddr,
|
|
163
|
-
envioGraphqlUrl
|
|
167
|
+
envioGraphqlUrl,
|
|
168
|
+
graphqlClient
|
|
164
169
|
]);
|
|
165
170
|
return /* @__PURE__ */ react.default.createElement(TimelockMarketContext.Provider, { value: contextValue }, children);
|
|
166
171
|
};
|
|
@@ -172,34 +177,27 @@ const useCurrentMarket = () => {
|
|
|
172
177
|
const useTimelockConfig = () => {
|
|
173
178
|
const context = (0, react.useContext)(TimelockMarketContext);
|
|
174
179
|
if (context === void 0) throw new Error("useConfig must be used within a TimelockMarketProvider");
|
|
175
|
-
|
|
176
|
-
if (context.envioGraphqlUrl) return getSdk(new graphql_request.GraphQLClient(context.envioGraphqlUrl));
|
|
177
|
-
}, [context.envioGraphqlUrl]);
|
|
178
|
-
return {
|
|
179
|
-
lensAddr: context.lensAddr,
|
|
180
|
-
uniswapMathLensAddr: context.uniswapMathLensAddr,
|
|
181
|
-
envioGraphqlUrl: context.envioGraphqlUrl,
|
|
182
|
-
graphqlClient
|
|
183
|
-
};
|
|
180
|
+
return context;
|
|
184
181
|
};
|
|
185
182
|
|
|
186
183
|
//#endregion
|
|
187
184
|
//#region src/hooks/market/useMarketData.ts
|
|
188
|
-
const selectMarket = (data) => ({
|
|
189
|
-
...data.TimelockMarket[0],
|
|
190
|
-
pool: data.TimelockMarket[0].pool,
|
|
191
|
-
vault: data.TimelockMarket[0].vault,
|
|
192
|
-
optionAsset: data.TimelockMarket[0].optionAsset,
|
|
193
|
-
payoutAsset: data.TimelockMarket[0].payoutAsset,
|
|
194
|
-
optionsCount: BigInt(data.TimelockMarket[0].optionsCount),
|
|
195
|
-
tradersCount: BigInt(data.TimelockMarket[0].tradersCount)
|
|
196
|
-
});
|
|
197
185
|
const useMarketData = (marketAddr) => {
|
|
198
186
|
const { graphqlClient } = useTimelockConfig();
|
|
199
187
|
const { data } = (0, __tanstack_react_query.useQuery)({
|
|
200
188
|
queryKey: ["marketData", marketAddr || "--"],
|
|
201
|
-
queryFn: () =>
|
|
202
|
-
|
|
189
|
+
queryFn: async () => {
|
|
190
|
+
const result = await graphqlClient.GetMarketData({ marketAddr: marketAddr.toLowerCase() });
|
|
191
|
+
return {
|
|
192
|
+
...result.TimelockMarket[0],
|
|
193
|
+
pool: result.TimelockMarket[0].pool,
|
|
194
|
+
vault: result.TimelockMarket[0].vault,
|
|
195
|
+
optionAsset: result.TimelockMarket[0].optionAsset,
|
|
196
|
+
payoutAsset: result.TimelockMarket[0].payoutAsset,
|
|
197
|
+
optionsCount: BigInt(result.TimelockMarket[0].optionsCount),
|
|
198
|
+
tradersCount: BigInt(result.TimelockMarket[0].tradersCount)
|
|
199
|
+
};
|
|
200
|
+
},
|
|
203
201
|
enabled: !!marketAddr && !!graphqlClient
|
|
204
202
|
});
|
|
205
203
|
return data || {};
|
|
@@ -448,25 +446,6 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
|
|
|
448
446
|
|
|
449
447
|
//#endregion
|
|
450
448
|
//#region src/hooks/market/useUserOptions.ts
|
|
451
|
-
const selectOptions = (data) => {
|
|
452
|
-
if (!(data === null || data === void 0 ? void 0 : data.UserOption)) return [];
|
|
453
|
-
return data.UserOption.map((option) => ({
|
|
454
|
-
...option,
|
|
455
|
-
id: BigInt(option.id),
|
|
456
|
-
marketAddr: option.marketAddr,
|
|
457
|
-
optionType: option.optionType,
|
|
458
|
-
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
459
|
-
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
460
|
-
premiumPaid: BigInt(option.premiumPaid),
|
|
461
|
-
realizedPayout: BigInt(option.realizedPayout),
|
|
462
|
-
liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
|
|
463
|
-
liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
|
|
464
|
-
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
465
|
-
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
466
|
-
strikePrice: BigInt(option.strikePrice),
|
|
467
|
-
entryPrice: BigInt(option.entryPrice)
|
|
468
|
-
})).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
469
|
-
};
|
|
470
449
|
const useUserOptions = (user, active = false) => {
|
|
471
450
|
const { graphqlClient } = useTimelockConfig();
|
|
472
451
|
const { data,...rest } = (0, __tanstack_react_query.useQuery)({
|
|
@@ -475,8 +454,25 @@ const useUserOptions = (user, active = false) => {
|
|
|
475
454
|
user || "--",
|
|
476
455
|
active
|
|
477
456
|
],
|
|
478
|
-
queryFn: () =>
|
|
479
|
-
|
|
457
|
+
queryFn: async () => {
|
|
458
|
+
if (!graphqlClient) return [];
|
|
459
|
+
return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
|
|
460
|
+
...option,
|
|
461
|
+
id: BigInt(option.id),
|
|
462
|
+
marketAddr: option.marketAddr,
|
|
463
|
+
optionType: option.optionType,
|
|
464
|
+
createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
|
|
465
|
+
expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
|
|
466
|
+
premiumPaid: BigInt(option.premiumPaid),
|
|
467
|
+
realizedPayout: BigInt(option.realizedPayout),
|
|
468
|
+
liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
|
|
469
|
+
liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
|
|
470
|
+
positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
|
|
471
|
+
positionSizeCurrent: BigInt(option.positionSizeCurrent),
|
|
472
|
+
strikePrice: BigInt(option.strikePrice),
|
|
473
|
+
entryPrice: BigInt(option.entryPrice)
|
|
474
|
+
})).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
475
|
+
},
|
|
480
476
|
enabled: !!user && !!graphqlClient
|
|
481
477
|
});
|
|
482
478
|
return {
|