@panoptic-eng/sdk 1.0.1 → 1.0.2
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/README.md +134 -4
- package/dist/index.js +49 -5
- package/dist/index.js.map +1 -1
- package/dist/test/index.js +1 -1513
- package/dist/test/index.js.map +1 -1
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -1,9 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @panoptic-eng/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for interacting with Panoptic v2 protocol.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- **Node.js** `>=20.19.0 <23.0.0` (see `.nvmrc` in repo root)
|
|
8
|
+
- **pnpm** package manager
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
### 1. Install Node.js (via nvm)
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
# Install nvm if you don't have it
|
|
16
|
+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
|
17
|
+
|
|
18
|
+
# Restart terminal, then install the correct Node version
|
|
19
|
+
nvm install
|
|
20
|
+
nvm use
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 2. Install pnpm
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
# Option A: via corepack (recommended, built into Node 16.13+)
|
|
27
|
+
corepack enable
|
|
28
|
+
|
|
29
|
+
# Option B: via npm
|
|
30
|
+
npm install -g pnpm
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Install dependencies
|
|
34
|
+
|
|
35
|
+
From the monorepo root:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pnpm install
|
|
6
39
|
pnpm add @panoptic-eng/sdk react viem wagmi
|
|
7
40
|
```
|
|
8
41
|
|
|
9
|
-
|
|
42
|
+
### 4. Generate types
|
|
43
|
+
|
|
44
|
+
The SDK uses code generation for contract ABIs and GraphQL types:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
cd packages/sdk
|
|
48
|
+
pnpm codegen
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This runs:
|
|
52
|
+
- `codegen:graphql` - Generates TypeScript types from GraphQL schema
|
|
53
|
+
- `codegen:wagmi` - Generates TypeScript types from contract ABIs
|
|
54
|
+
|
|
55
|
+
### 5. Set up environment (for fork tests)
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
cp .env.template .env
|
|
59
|
+
# Add your Alchemy API key to .env
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
# Build the SDK
|
|
66
|
+
pnpm build
|
|
67
|
+
|
|
68
|
+
# Watch mode (rebuilds on changes)
|
|
69
|
+
pnpm dev
|
|
70
|
+
|
|
71
|
+
# Type checking
|
|
72
|
+
pnpm typecheck
|
|
73
|
+
|
|
74
|
+
# Linting
|
|
75
|
+
pnpm lint
|
|
76
|
+
pnpm lint:fix
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Testing
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
# Run unit tests
|
|
83
|
+
pnpm test
|
|
84
|
+
|
|
85
|
+
# Run fork tests (requires ALCHEMY_API_KEY)
|
|
86
|
+
pnpm test:fork
|
|
87
|
+
|
|
88
|
+
# Watch mode for fork tests
|
|
89
|
+
pnpm test:fork:watch
|
|
90
|
+
|
|
91
|
+
# Run all tests (unit + fork)
|
|
92
|
+
pnpm test:examples
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Project Structure
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
packages/sdk/
|
|
99
|
+
├── src/
|
|
100
|
+
│ ├── panoptic/
|
|
101
|
+
│ │ └── v2/ # Panoptic v2 SDK
|
|
102
|
+
│ │ ├── clients/ # Client utilities (getBlockMeta, etc.)
|
|
103
|
+
│ │ ├── errors/ # Error types
|
|
104
|
+
│ │ ├── simulations/ # Transaction simulations
|
|
105
|
+
│ │ ├── sync/ # Position sync and tracking
|
|
106
|
+
│ │ ├── types/ # TypeScript types
|
|
107
|
+
│ │ ├── utils/ # Utility functions
|
|
108
|
+
│ │ └── examples/ # Example implementations
|
|
109
|
+
│ │ ├── basic/ # Basic read/write examples
|
|
110
|
+
│ │ ├── liquidation-bot/ # Liquidation bot example
|
|
111
|
+
│ │ └── oracle-poker/ # Oracle poker bot example
|
|
112
|
+
│ └── generated/ # Auto-generated contract types
|
|
113
|
+
├── contracts/ # Contract ABIs (synced from contracts repo)
|
|
114
|
+
├── graphql/ # GraphQL schema and queries
|
|
115
|
+
└── scripts/ # Build and sync scripts
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Contract ABIs
|
|
119
|
+
|
|
120
|
+
Contract ABIs are synced from the main contracts repository. See [ABI_GENERATION.md](./ABI_GENERATION.md) for details.
|
|
121
|
+
|
|
122
|
+
To sync ABIs:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm sync-contracts
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Usage
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import {
|
|
132
|
+
simulateOpenPosition,
|
|
133
|
+
simulateClosePosition,
|
|
134
|
+
getBlockMeta,
|
|
135
|
+
TokenIdBuilder,
|
|
136
|
+
} from '@panoptic-eng/sdk'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See the [examples](./src/panoptic/v2/examples/) directory for usage patterns.
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseError, ContractFunctionRevertedError, encodeAbiParameters, encodeFunctionData, encodePacked, keccak256, maxUint256, parseAbi, zeroAddress } from "viem";
|
|
2
2
|
import { readContract, simulateContract, writeContract } from "viem/actions";
|
|
3
|
-
import { useCallback, useMemo } from "react";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { useAccount, useReadContract, useSimulateContract, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { GraphQLClient } from "graphql-request";
|
|
@@ -19916,11 +19916,22 @@ const useExecuteWithdrawal = ({ vaultAddress, desiredAssets, queuedWithdrawals,
|
|
|
19916
19916
|
const wait = useWaitForTransactionReceipt({
|
|
19917
19917
|
hash: write.data,
|
|
19918
19918
|
query: {
|
|
19919
|
-
meta: { onSuccess: onWaitSuccess },
|
|
19920
19919
|
refetchOnWindowFocus: false,
|
|
19921
19920
|
refetchOnMount: false
|
|
19922
19921
|
}
|
|
19923
19922
|
});
|
|
19923
|
+
const handledRequestHashRef = useRef(void 0);
|
|
19924
|
+
useEffect(() => {
|
|
19925
|
+
const requestHash = write.data;
|
|
19926
|
+
if (!wait.isSuccess || requestHash == null) return;
|
|
19927
|
+
if (handledRequestHashRef.current === requestHash) return;
|
|
19928
|
+
handledRequestHashRef.current = requestHash;
|
|
19929
|
+
onWaitSuccess?.();
|
|
19930
|
+
}, [
|
|
19931
|
+
onWaitSuccess,
|
|
19932
|
+
wait.isSuccess,
|
|
19933
|
+
write.data
|
|
19934
|
+
]);
|
|
19924
19935
|
const act = useCallback(() => {
|
|
19925
19936
|
const request = simulate.data?.request;
|
|
19926
19937
|
return request != null ? write.writeContract(request) : void 0;
|
|
@@ -20426,7 +20437,6 @@ const useRequestDeposit = ({ vaultAddress, assets, tokenAddress, onWaitSuccess }
|
|
|
20426
20437
|
const approveWait = useWaitForTransactionReceipt({
|
|
20427
20438
|
hash: approveWrite.data,
|
|
20428
20439
|
query: {
|
|
20429
|
-
meta: { onSuccess: refetchAllowance },
|
|
20430
20440
|
refetchOnWindowFocus: false,
|
|
20431
20441
|
refetchOnMount: false
|
|
20432
20442
|
}
|
|
@@ -20446,11 +20456,34 @@ const useRequestDeposit = ({ vaultAddress, assets, tokenAddress, onWaitSuccess }
|
|
|
20446
20456
|
const wait = useWaitForTransactionReceipt({
|
|
20447
20457
|
hash: write.data,
|
|
20448
20458
|
query: {
|
|
20449
|
-
meta: { onSuccess: onWaitSuccess },
|
|
20450
20459
|
refetchOnWindowFocus: false,
|
|
20451
20460
|
refetchOnMount: false
|
|
20452
20461
|
}
|
|
20453
20462
|
});
|
|
20463
|
+
const handledApproveHashRef = useRef(void 0);
|
|
20464
|
+
const handledRequestHashRef = useRef(void 0);
|
|
20465
|
+
useEffect(() => {
|
|
20466
|
+
const approveHash = approveWrite.data;
|
|
20467
|
+
if (!approveWait.isSuccess || approveHash == null) return;
|
|
20468
|
+
if (handledApproveHashRef.current === approveHash) return;
|
|
20469
|
+
handledApproveHashRef.current = approveHash;
|
|
20470
|
+
refetchAllowance();
|
|
20471
|
+
}, [
|
|
20472
|
+
approveWait.isSuccess,
|
|
20473
|
+
approveWrite.data,
|
|
20474
|
+
refetchAllowance
|
|
20475
|
+
]);
|
|
20476
|
+
useEffect(() => {
|
|
20477
|
+
const requestHash = write.data;
|
|
20478
|
+
if (!wait.isSuccess || requestHash == null) return;
|
|
20479
|
+
if (handledRequestHashRef.current === requestHash) return;
|
|
20480
|
+
handledRequestHashRef.current = requestHash;
|
|
20481
|
+
onWaitSuccess?.();
|
|
20482
|
+
}, [
|
|
20483
|
+
onWaitSuccess,
|
|
20484
|
+
wait.isSuccess,
|
|
20485
|
+
write.data
|
|
20486
|
+
]);
|
|
20454
20487
|
const act = useCallback(() => {
|
|
20455
20488
|
if (tokenNeedsApproval) {
|
|
20456
20489
|
const request$1 = approveSimulate.data?.request;
|
|
@@ -20717,11 +20750,22 @@ const useRequestWithdrawal = ({ vaultAddress, desiredAssets, sharePrice, walletS
|
|
|
20717
20750
|
const wait = useWaitForTransactionReceipt({
|
|
20718
20751
|
hash: write.data,
|
|
20719
20752
|
query: {
|
|
20720
|
-
meta: { onSuccess: onWaitSuccess },
|
|
20721
20753
|
refetchOnWindowFocus: false,
|
|
20722
20754
|
refetchOnMount: false
|
|
20723
20755
|
}
|
|
20724
20756
|
});
|
|
20757
|
+
const handledRequestHashRef = useRef(void 0);
|
|
20758
|
+
useEffect(() => {
|
|
20759
|
+
const requestHash = write.data;
|
|
20760
|
+
if (!wait.isSuccess || requestHash == null) return;
|
|
20761
|
+
if (handledRequestHashRef.current === requestHash) return;
|
|
20762
|
+
handledRequestHashRef.current = requestHash;
|
|
20763
|
+
onWaitSuccess?.();
|
|
20764
|
+
}, [
|
|
20765
|
+
onWaitSuccess,
|
|
20766
|
+
wait.isSuccess,
|
|
20767
|
+
write.data
|
|
20768
|
+
]);
|
|
20725
20769
|
const act = useCallback(() => {
|
|
20726
20770
|
const request = simulate.data?.request;
|
|
20727
20771
|
return request != null ? write.writeContract(request) : void 0;
|