@1stdex/first-sdk 1.0.6 → 1.0.8

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.
Files changed (43) hide show
  1. package/dist/cjs/calls/approval/order.js +0 -5
  2. package/dist/cjs/calls/approval/order.js.map +1 -1
  3. package/dist/cjs/calls/batch/index.js +6 -0
  4. package/dist/cjs/calls/batch/index.js.map +1 -0
  5. package/dist/cjs/calls/batch/prepare-order-with-setup.js +117 -0
  6. package/dist/cjs/calls/batch/prepare-order-with-setup.js.map +1 -0
  7. package/dist/cjs/calls/index.js +3 -1
  8. package/dist/cjs/calls/index.js.map +1 -1
  9. package/dist/cjs/views/index.js +6 -1
  10. package/dist/cjs/views/index.js.map +1 -1
  11. package/dist/cjs/views/setup.js +160 -0
  12. package/dist/cjs/views/setup.js.map +1 -0
  13. package/dist/cjs/views/vault.js +5 -3
  14. package/dist/cjs/views/vault.js.map +1 -1
  15. package/dist/esm/calls/approval/order.js +0 -5
  16. package/dist/esm/calls/approval/order.js.map +1 -1
  17. package/dist/esm/calls/batch/index.js +2 -0
  18. package/dist/esm/calls/batch/index.js.map +1 -0
  19. package/dist/esm/calls/batch/prepare-order-with-setup.js +148 -0
  20. package/dist/esm/calls/batch/prepare-order-with-setup.js.map +1 -0
  21. package/dist/esm/calls/index.js +1 -0
  22. package/dist/esm/calls/index.js.map +1 -1
  23. package/dist/esm/views/index.js +1 -0
  24. package/dist/esm/views/index.js.map +1 -1
  25. package/dist/esm/views/setup.js +235 -0
  26. package/dist/esm/views/setup.js.map +1 -0
  27. package/dist/esm/views/vault.js +6 -4
  28. package/dist/esm/views/vault.js.map +1 -1
  29. package/dist/tsconfig.build.tsbuildinfo +1 -1
  30. package/dist/types/calls/approval/order.d.ts +2 -2
  31. package/dist/types/calls/approval/order.d.ts.map +1 -1
  32. package/dist/types/calls/batch/index.d.ts +3 -0
  33. package/dist/types/calls/batch/index.d.ts.map +1 -0
  34. package/dist/types/calls/batch/prepare-order-with-setup.d.ts +53 -0
  35. package/dist/types/calls/batch/prepare-order-with-setup.d.ts.map +1 -0
  36. package/dist/types/calls/index.d.ts +2 -0
  37. package/dist/types/calls/index.d.ts.map +1 -1
  38. package/dist/types/views/index.d.ts +1 -0
  39. package/dist/types/views/index.d.ts.map +1 -1
  40. package/dist/types/views/setup.d.ts +133 -0
  41. package/dist/types/views/setup.d.ts.map +1 -0
  42. package/dist/types/views/vault.d.ts.map +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,235 @@
1
+ import { createPublicClient, http, erc20Abi, parseUnits, formatUnits, } from 'viem';
2
+ import { CHAIN_MAP } from '../constants/chain-configs/chain';
3
+ import { CONTRACT_ADDRESSES } from '../constants/chain-configs/addresses';
4
+ import { BOOK_MANAGER_ABI } from '../constants/abis/core/book-manager-abi';
5
+ import { getVault } from './vault';
6
+ import { fetchCurrency } from '../entities/currency/apis';
7
+ import { DEX_VAULT_ABI } from '../constants/abis/core/dex-vault-abi';
8
+ /**
9
+ * Check if an operator is approved for a user.
10
+ *
11
+ * @param chainId The chain ID.
12
+ * @param userAddress The user address.
13
+ * @param operator The operator address (defaults to Controller).
14
+ * @param options Optional RPC URL.
15
+ * @returns Promise resolving to true if operator is approved.
16
+ * @example
17
+ * import { isOrderOperatorApproved } from '@clober/v2-sdk'
18
+ *
19
+ * const isApproved = await isOrderOperatorApproved({
20
+ * chainId: 421614,
21
+ * userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69'
22
+ * })
23
+ */
24
+ export const isOrderOperatorApproved = async ({ chainId, userAddress, operator, options, }) => {
25
+ const publicClient = createPublicClient({
26
+ chain: CHAIN_MAP[chainId],
27
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
28
+ });
29
+ const operatorAddress = operator || CONTRACT_ADDRESSES[chainId].Controller;
30
+ return publicClient.readContract({
31
+ address: CONTRACT_ADDRESSES[chainId].BookManager,
32
+ abi: BOOK_MANAGER_ABI,
33
+ functionName: 'isOrderOperator',
34
+ args: [userAddress, operatorAddress],
35
+ });
36
+ };
37
+ /**
38
+ * Check token allowances for trading.
39
+ * Returns which allowances are sufficient (above threshold).
40
+ *
41
+ * @param chainId The chain ID.
42
+ * @param userAddress The user address.
43
+ * @param tokenAddress The token address.
44
+ * @param options Optional RPC URL.
45
+ * @returns Promise resolving to allowance status object.
46
+ * @example
47
+ * import { checkTokenAllowances } from '@clober/v2-sdk'
48
+ *
49
+ * const status = await checkTokenAllowances({
50
+ * chainId: 421614,
51
+ * userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
52
+ * tokenAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0'
53
+ * })
54
+ * if (!status.tokenToController) {
55
+ * // Need to set token allowances
56
+ * }
57
+ */
58
+ export const checkTokenAllowances = async ({ chainId, userAddress, tokenAddress, options, }) => {
59
+ const publicClient = createPublicClient({
60
+ chain: CHAIN_MAP[chainId],
61
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
62
+ });
63
+ const controllerAddress = CONTRACT_ADDRESSES[chainId].Controller;
64
+ const bookManagerAddress = CONTRACT_ADDRESSES[chainId].BookManager;
65
+ const [currency, vault] = await Promise.all([
66
+ fetchCurrency(publicClient, chainId, tokenAddress),
67
+ getVault({ chainId, tokenAddress, ...(options && { options }) }),
68
+ ]);
69
+ const threshold = 2n ** 256n - 1n - 10n ** BigInt(currency.decimals) * 1000000n;
70
+ const results = await publicClient.multicall({
71
+ contracts: [
72
+ {
73
+ address: tokenAddress,
74
+ abi: erc20Abi,
75
+ functionName: 'allowance',
76
+ args: [userAddress, controllerAddress],
77
+ },
78
+ {
79
+ address: vault.address,
80
+ abi: erc20Abi,
81
+ functionName: 'allowance',
82
+ args: [userAddress, controllerAddress],
83
+ },
84
+ {
85
+ address: vault.address,
86
+ abi: erc20Abi,
87
+ functionName: 'allowance',
88
+ args: [userAddress, bookManagerAddress],
89
+ },
90
+ ],
91
+ });
92
+ const tokenToController = results[0].result || 0n;
93
+ const vaultToController = results[1].result || 0n;
94
+ const vaultToBookManager = results[2].result || 0n;
95
+ return {
96
+ tokenToController: tokenToController > threshold,
97
+ vaultToController: vaultToController > threshold,
98
+ vaultToBookManager: vaultToBookManager > threshold,
99
+ };
100
+ };
101
+ /**
102
+ * Check if vault deposit is needed for an order.
103
+ * Compares vault available balance against required amount.
104
+ *
105
+ * @param chainId The chain ID.
106
+ * @param userAddress The user address.
107
+ * @param tokenAddress The token address.
108
+ * @param requiredAmount The amount needed (decimal-adjusted string, e.g., "100.5").
109
+ * @param options Optional RPC URL.
110
+ * @returns Promise resolving to true if deposit is needed.
111
+ * @example
112
+ * import { needsVaultDeposit } from '@clober/v2-sdk'
113
+ *
114
+ * const needsDeposit = await needsVaultDeposit({
115
+ * chainId: 421614,
116
+ * userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
117
+ * tokenAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
118
+ * requiredAmount: "100"
119
+ * })
120
+ */
121
+ export const needsVaultDeposit = async ({ chainId, userAddress, tokenAddress, requiredAmount, options, }) => {
122
+ const publicClient = createPublicClient({
123
+ chain: CHAIN_MAP[chainId],
124
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
125
+ });
126
+ const [currency, vault] = await Promise.all([
127
+ fetchCurrency(publicClient, chainId, tokenAddress),
128
+ getVault({ chainId, tokenAddress, ...(options && { options }) }),
129
+ ]);
130
+ const vaultAvailable = await publicClient.readContract({
131
+ address: vault.address,
132
+ abi: DEX_VAULT_ABI,
133
+ functionName: 'maxWithdraw',
134
+ args: [userAddress],
135
+ });
136
+ const required = parseUnits(requiredAmount, currency.decimals);
137
+ return vaultAvailable < required;
138
+ };
139
+ /**
140
+ * Get complete order setup status in a single call.
141
+ * Checks operator approval, token allowances, and vault balance.
142
+ *
143
+ * @param chainId The chain ID.
144
+ * @param userAddress The user address.
145
+ * @param tokenAddress The token address.
146
+ * @param requiredAmount The amount needed for the order (decimal-adjusted string).
147
+ * @param options Optional RPC URL and operator address.
148
+ * @returns Promise resolving to complete setup status.
149
+ * @example
150
+ * import { getOrderSetupStatus } from '@clober/v2-sdk'
151
+ *
152
+ * const status = await getOrderSetupStatus({
153
+ * chainId: 421614,
154
+ * userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
155
+ * tokenAddress: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
156
+ * requiredAmount: "100"
157
+ * })
158
+ *
159
+ * if (!status.operatorApproved) await setOrderOperatorApproval(...)
160
+ * if (!status.allAllowancesSet) await setTokenAllowances(...)
161
+ * if (status.needsDeposit) await depositToVault(...)
162
+ */
163
+ export const getOrderSetupStatus = async ({ chainId, userAddress, tokenAddress, requiredAmount, options, }) => {
164
+ const publicClient = createPublicClient({
165
+ chain: CHAIN_MAP[chainId],
166
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
167
+ });
168
+ const controllerAddress = CONTRACT_ADDRESSES[chainId].Controller;
169
+ const bookManagerAddress = CONTRACT_ADDRESSES[chainId].BookManager;
170
+ const operatorAddress = options?.operator || controllerAddress;
171
+ const [currency, vault] = await Promise.all([
172
+ fetchCurrency(publicClient, chainId, tokenAddress),
173
+ getVault({ chainId, tokenAddress, ...(options && { options }) }),
174
+ ]);
175
+ const threshold = 2n ** 256n - 1n - 10n ** BigInt(currency.decimals) * 1000000n;
176
+ const required = parseUnits(requiredAmount, currency.decimals);
177
+ // Single multicall for all checks
178
+ const results = await publicClient.multicall({
179
+ contracts: [
180
+ {
181
+ address: CONTRACT_ADDRESSES[chainId].BookManager,
182
+ abi: BOOK_MANAGER_ABI,
183
+ functionName: 'isOrderOperator',
184
+ args: [userAddress, operatorAddress],
185
+ },
186
+ {
187
+ address: tokenAddress,
188
+ abi: erc20Abi,
189
+ functionName: 'allowance',
190
+ args: [userAddress, controllerAddress],
191
+ },
192
+ {
193
+ address: vault.address,
194
+ abi: erc20Abi,
195
+ functionName: 'allowance',
196
+ args: [userAddress, controllerAddress],
197
+ },
198
+ {
199
+ address: vault.address,
200
+ abi: erc20Abi,
201
+ functionName: 'allowance',
202
+ args: [userAddress, bookManagerAddress],
203
+ },
204
+ {
205
+ address: vault.address,
206
+ abi: DEX_VAULT_ABI,
207
+ functionName: 'maxWithdraw',
208
+ args: [userAddress],
209
+ },
210
+ ],
211
+ });
212
+ const operatorApproved = results[0].result || false;
213
+ const tokenAllowance = results[1].result || 0n;
214
+ const vaultToController = results[2].result || 0n;
215
+ const vaultToBookManager = results[3].result || 0n;
216
+ const vaultAvailable = results[4].result || 0n;
217
+ const tokenToController = tokenAllowance > threshold;
218
+ const vaultToControllerOk = vaultToController > threshold;
219
+ const vaultToBookManagerOk = vaultToBookManager > threshold;
220
+ return {
221
+ operatorApproved,
222
+ tokenAllowances: {
223
+ tokenToController,
224
+ vaultToController: vaultToControllerOk,
225
+ vaultToBookManager: vaultToBookManagerOk,
226
+ allSet: tokenToController && vaultToControllerOk && vaultToBookManagerOk,
227
+ },
228
+ vaultBalance: {
229
+ currency,
230
+ value: formatUnits(vaultAvailable, currency.decimals),
231
+ },
232
+ needsDeposit: vaultAvailable < required,
233
+ };
234
+ };
235
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/views/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAa,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,E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mB,IAAI,oBAAoB;SACzE;QACD,YAAY,EAAE;YACZ,QAAQ;YACR,KAAK,EAAE,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC;SACtD;QACD,YAAY,EAAE,cAAc,GAAG,QAAQ;KACxC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { createPublicClient, http } from 'viem';
1
+ import { createPublicClient, http, isAddressEqual, zeroAddress } from 'viem';
2
2
  import { CHAIN_MAP } from '../constants/chain-configs/chain';
3
3
  import { CONTRACT_ADDRESSES } from '../constants/chain-configs/addresses';
4
4
  import { BOOK_MANAGER_ABI } from '../constants/abis/core/book-manager-abi';
@@ -28,8 +28,10 @@ export const getVault = async ({ chainId, tokenAddress, options, }) => {
28
28
  functionName: 'getVault',
29
29
  args: [tokenAddress],
30
30
  });
31
- return {
32
- address: vaultAddress,
33
- };
31
+ if (isAddressEqual(vaultAddress, zeroAddress)) {
32
+ throw new Error(`Vault not found for token ${tokenAddress} on chain ${chainId}. ` +
33
+ `The vault has not been registered yet. Deploy a vault contract for this token and register it using the setVault() function.`);
34
+ }
35
+ return { address: vaultAddress };
34
36
  };
35
37
  //# sourceMappingURL=vault.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vault.js","sourceRoot":"","sources":["../../../src/views/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAAa,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,EAC7B,OAAO,EACP,YAAY,EACZ,OAAO,GAOR,EAAkB,EAAE;IACnB,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,K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