@kodiak-finance/orderly-hooks 2.8.10-rc.0 → 2.8.10-rc.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/dist/index.d.mts +1 -25
- package/dist/index.d.ts +1 -25
- package/dist/index.js +105 -182
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -182
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -140,20 +140,20 @@ var useAccountInstance = () => {
|
|
|
140
140
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
|
-
const
|
|
144
|
-
let
|
|
145
|
-
if (!
|
|
146
|
-
|
|
143
|
+
const account9 = useConstant__default.default(() => {
|
|
144
|
+
let account10 = orderlyCore.SimpleDI.get("account");
|
|
145
|
+
if (!account10) {
|
|
146
|
+
account10 = new orderlyCore.Account(
|
|
147
147
|
configStore,
|
|
148
148
|
keyStore,
|
|
149
149
|
// getWalletAdapter,
|
|
150
150
|
walletAdapters
|
|
151
151
|
);
|
|
152
|
-
orderlyCore.SimpleDI.registerByName("account",
|
|
152
|
+
orderlyCore.SimpleDI.registerByName("account", account10);
|
|
153
153
|
}
|
|
154
|
-
return
|
|
154
|
+
return account10;
|
|
155
155
|
});
|
|
156
|
-
return
|
|
156
|
+
return account9;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
159
|
// src/useMutation.ts
|
|
@@ -179,7 +179,7 @@ var useMutation = (url, method = "POST", options) => {
|
|
|
179
179
|
if (!url.startsWith("http")) {
|
|
180
180
|
fullUrl = `${apiBaseUrl}${url}`;
|
|
181
181
|
}
|
|
182
|
-
const
|
|
182
|
+
const account9 = useAccountInstance();
|
|
183
183
|
const { trigger, data, error, reset, isMutating } = useSWRMutation__default.default(
|
|
184
184
|
fullUrl,
|
|
185
185
|
// method === "POST" ? fetcher : deleteFetcher,
|
|
@@ -197,7 +197,7 @@ var useMutation = (url, method = "POST", options) => {
|
|
|
197
197
|
url: newUrl,
|
|
198
198
|
data: data2
|
|
199
199
|
};
|
|
200
|
-
const signer =
|
|
200
|
+
const signer = account9.signer;
|
|
201
201
|
const signature = await signer.sign(payload, orderlyUtils.getTimestamp());
|
|
202
202
|
return trigger(
|
|
203
203
|
{
|
|
@@ -206,7 +206,7 @@ var useMutation = (url, method = "POST", options) => {
|
|
|
206
206
|
method,
|
|
207
207
|
signature: {
|
|
208
208
|
...signature,
|
|
209
|
-
"orderly-account-id":
|
|
209
|
+
"orderly-account-id": account9.accountId
|
|
210
210
|
}
|
|
211
211
|
},
|
|
212
212
|
options2
|
|
@@ -220,9 +220,9 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
220
220
|
try {
|
|
221
221
|
const extendedFetcher = async (args) => {
|
|
222
222
|
const url = Array.isArray(args) ? args[0] : args;
|
|
223
|
-
const
|
|
223
|
+
const account9 = orderlyCore.SimpleDI.get("account");
|
|
224
224
|
const fullUrl = `${apiBaseUrl}${url}`;
|
|
225
|
-
const signer =
|
|
225
|
+
const signer = account9.signer;
|
|
226
226
|
const payload = {
|
|
227
227
|
method: "GET",
|
|
228
228
|
url
|
|
@@ -231,7 +231,7 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
231
231
|
return fetcher4(fullUrl, {
|
|
232
232
|
headers: {
|
|
233
233
|
...signature,
|
|
234
|
-
"orderly-account-id":
|
|
234
|
+
"orderly-account-id": account9.accountId
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
237
|
};
|
|
@@ -304,25 +304,25 @@ var useWS = () => {
|
|
|
304
304
|
const { configStore } = React2.useContext(OrderlyContext);
|
|
305
305
|
const ws = useConstant__default.default(() => {
|
|
306
306
|
let websocketClient = orderlyCore.SimpleDI.get(WS_NAME);
|
|
307
|
-
const
|
|
307
|
+
const account9 = orderlyCore.SimpleDI.get(orderlyCore.Account.instanceName);
|
|
308
308
|
if (!websocketClient) {
|
|
309
309
|
websocketClient = new orderlyNet.WS({
|
|
310
310
|
networkId: configStore.get("networkId"),
|
|
311
311
|
publicUrl: configStore.get("publicWsUrl"),
|
|
312
312
|
privateUrl: configStore.get("privateWsUrl"),
|
|
313
313
|
onSigntureRequest: async () => {
|
|
314
|
-
const signer =
|
|
314
|
+
const signer = account9.signer;
|
|
315
315
|
const timestamp = orderlyUtils.getTimestamp();
|
|
316
316
|
const result = await signer.signText(timestamp.toString());
|
|
317
317
|
return { ...result, timestamp };
|
|
318
318
|
}
|
|
319
319
|
});
|
|
320
|
-
if ((
|
|
321
|
-
websocketClient.openPrivate(
|
|
320
|
+
if ((account9.stateValue.status === orderlyTypes.AccountStatusEnum.EnableTrading || account9.stateValue.status === orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) && account9.accountId) {
|
|
321
|
+
websocketClient.openPrivate(account9.accountId);
|
|
322
322
|
}
|
|
323
|
-
|
|
324
|
-
if ((nextState.status === orderlyTypes.AccountStatusEnum.EnableTrading || nextState.status === orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) &&
|
|
325
|
-
websocketClient.openPrivate(
|
|
323
|
+
account9.on("change:status", (nextState) => {
|
|
324
|
+
if ((nextState.status === orderlyTypes.AccountStatusEnum.EnableTrading || nextState.status === orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) && account9.accountId) {
|
|
325
|
+
websocketClient.openPrivate(account9.accountId);
|
|
326
326
|
} else {
|
|
327
327
|
websocketClient.closePrivate(3887, "switch account");
|
|
328
328
|
}
|
|
@@ -349,63 +349,63 @@ var useAccount = () => {
|
|
|
349
349
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
350
350
|
);
|
|
351
351
|
}
|
|
352
|
-
const
|
|
353
|
-
const [state, setState] = React2.useState(
|
|
352
|
+
const account9 = useAccountInstance();
|
|
353
|
+
const [state, setState] = React2.useState(account9.stateValue);
|
|
354
354
|
const { track: track2 } = useTrack();
|
|
355
355
|
const statusChangeHandler = (nextState) => {
|
|
356
356
|
setState(() => nextState);
|
|
357
357
|
};
|
|
358
358
|
React2.useEffect(() => {
|
|
359
|
-
|
|
359
|
+
account9.on("change:status", statusChangeHandler);
|
|
360
360
|
return () => {
|
|
361
|
-
|
|
361
|
+
account9.off("change:status", statusChangeHandler);
|
|
362
362
|
};
|
|
363
|
-
}, [
|
|
363
|
+
}, [account9]);
|
|
364
364
|
const createOrderlyKey = React2.useCallback(
|
|
365
365
|
async (remember) => {
|
|
366
366
|
track2(orderlyTypes.TrackerEventName.signinSuccess, {
|
|
367
|
-
network:
|
|
367
|
+
network: account9.chainId,
|
|
368
368
|
wallet: state.connectWallet?.name
|
|
369
369
|
});
|
|
370
|
-
return
|
|
371
|
-
return
|
|
370
|
+
return account9.createOrderlyKey(remember ? 365 : 30).then((res) => {
|
|
371
|
+
return account9.restoreSubAccount().then((_) => {
|
|
372
372
|
return res;
|
|
373
373
|
});
|
|
374
374
|
});
|
|
375
375
|
},
|
|
376
|
-
[
|
|
376
|
+
[account9, state]
|
|
377
377
|
);
|
|
378
378
|
const ws = useWS();
|
|
379
379
|
const switchAccount = React2.useCallback(
|
|
380
380
|
async (accountId) => {
|
|
381
381
|
ws.closePrivate(3887, "switch account");
|
|
382
|
-
return
|
|
382
|
+
return account9.switchAccount(accountId);
|
|
383
383
|
},
|
|
384
|
-
[
|
|
384
|
+
[account9]
|
|
385
385
|
);
|
|
386
386
|
const createAccount = React2.useCallback(async () => {
|
|
387
|
-
return
|
|
388
|
-
}, [
|
|
387
|
+
return account9.createAccount();
|
|
388
|
+
}, [account9]);
|
|
389
389
|
const createSubAccount = React2.useCallback(
|
|
390
390
|
async (description) => {
|
|
391
|
-
return
|
|
391
|
+
return account9.createSubAccount(description);
|
|
392
392
|
},
|
|
393
|
-
[
|
|
393
|
+
[account9]
|
|
394
394
|
);
|
|
395
395
|
const updateSubAccount = React2.useCallback(
|
|
396
396
|
async (value) => {
|
|
397
|
-
return
|
|
397
|
+
return account9.updateSubAccount(value);
|
|
398
398
|
},
|
|
399
|
-
[
|
|
399
|
+
[account9]
|
|
400
400
|
);
|
|
401
401
|
const refreshSubAccountBalances = React2.useCallback(() => {
|
|
402
|
-
return
|
|
403
|
-
}, [
|
|
402
|
+
return account9.refreshSubAccountBalances();
|
|
403
|
+
}, [account9]);
|
|
404
404
|
const isSubAccount = React2.useMemo(() => {
|
|
405
405
|
return state.accountId !== state.mainAccountId;
|
|
406
406
|
}, [state]);
|
|
407
407
|
return {
|
|
408
|
-
account:
|
|
408
|
+
account: account9,
|
|
409
409
|
state,
|
|
410
410
|
isSubAccount,
|
|
411
411
|
isMainAccount: !isSubAccount,
|
|
@@ -891,7 +891,7 @@ var useGetReferralCode = (accountId) => {
|
|
|
891
891
|
};
|
|
892
892
|
function useSubAccountQuery(query, options) {
|
|
893
893
|
const { formatter, accountId, ...swrOptions } = options || {};
|
|
894
|
-
const { state, account:
|
|
894
|
+
const { state, account: account9 } = useAccount();
|
|
895
895
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
896
896
|
return useSWR__namespace.default(
|
|
897
897
|
() => accountId && (state.status >= orderlyTypes.AccountStatusEnum.EnableTrading || state.status === orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) ? [query, accountId] : null,
|
|
@@ -900,13 +900,13 @@ function useSubAccountQuery(query, options) {
|
|
|
900
900
|
},
|
|
901
901
|
{
|
|
902
902
|
...swrOptions,
|
|
903
|
-
use: [...middleware, signatureMiddleware2(
|
|
903
|
+
use: [...middleware, signatureMiddleware2(account9, accountId)],
|
|
904
904
|
onError: () => {
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
);
|
|
908
908
|
}
|
|
909
|
-
function signatureMiddleware2(
|
|
909
|
+
function signatureMiddleware2(account9, accountId) {
|
|
910
910
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
911
911
|
return (useSWRNext) => {
|
|
912
912
|
return (key, fetcher4, config) => {
|
|
@@ -914,7 +914,7 @@ function signatureMiddleware2(account10, accountId) {
|
|
|
914
914
|
const extendedFetcher = async (args) => {
|
|
915
915
|
const url = Array.isArray(args) ? args[0] : args;
|
|
916
916
|
const fullUrl = `${apiBaseUrl}${url}`;
|
|
917
|
-
const signer =
|
|
917
|
+
const signer = account9.signer;
|
|
918
918
|
const payload = {
|
|
919
919
|
method: "GET",
|
|
920
920
|
url
|
|
@@ -6147,7 +6147,7 @@ var useMaxWithdrawal = (token) => {
|
|
|
6147
6147
|
// src/orderly/useWithdraw.ts
|
|
6148
6148
|
var useWithdraw = (options) => {
|
|
6149
6149
|
const { srcChainId, token = "", decimals } = options;
|
|
6150
|
-
const { account:
|
|
6150
|
+
const { account: account9, state } = useAccount();
|
|
6151
6151
|
const { unsettledPnL, availableBalance, freeCollateral } = useCollateral();
|
|
6152
6152
|
const networkId = useConfig("networkId");
|
|
6153
6153
|
const [_, { findByChainId }] = useChains(void 0);
|
|
@@ -6188,7 +6188,7 @@ var useWithdraw = (options) => {
|
|
|
6188
6188
|
}, [targetChain]);
|
|
6189
6189
|
const withdraw = React2.useCallback(
|
|
6190
6190
|
(inputs) => {
|
|
6191
|
-
return
|
|
6191
|
+
return account9.assetsManager.withdraw({ ...inputs, decimals: decimals ?? 6 }).then((res) => {
|
|
6192
6192
|
if (res.success) {
|
|
6193
6193
|
track2(orderlyTypes.TrackerEventName.withdrawSuccess, {
|
|
6194
6194
|
wallet: state?.connectWallet?.name,
|
|
@@ -6208,7 +6208,7 @@ var useWithdraw = (options) => {
|
|
|
6208
6208
|
});
|
|
6209
6209
|
},
|
|
6210
6210
|
[
|
|
6211
|
-
|
|
6211
|
+
account9.assetsManager,
|
|
6212
6212
|
decimals,
|
|
6213
6213
|
state?.connectWallet?.name,
|
|
6214
6214
|
targetChain?.network_infos.name
|
|
@@ -6235,7 +6235,7 @@ var useDeposit = (options) => {
|
|
|
6235
6235
|
const [balance, setBalance] = React2.useState("0");
|
|
6236
6236
|
const [allowance, setAllowance] = React2.useState("0");
|
|
6237
6237
|
const balanceRef = React2.useRef("");
|
|
6238
|
-
const { account:
|
|
6238
|
+
const { account: account9, state } = useAccount();
|
|
6239
6239
|
const { track: track2 } = useTrack();
|
|
6240
6240
|
const prevAddress = React2.useRef();
|
|
6241
6241
|
const getBalanceListener = React2.useRef();
|
|
@@ -6274,18 +6274,18 @@ var useDeposit = (options) => {
|
|
|
6274
6274
|
let balance2;
|
|
6275
6275
|
try {
|
|
6276
6276
|
if (address && orderlyTypes.isNativeTokenChecker(address)) {
|
|
6277
|
-
balance2 = await
|
|
6277
|
+
balance2 = await account9.assetsManager.getNativeBalance({
|
|
6278
6278
|
decimals
|
|
6279
6279
|
});
|
|
6280
6280
|
} else {
|
|
6281
|
-
balance2 = await
|
|
6281
|
+
balance2 = await account9.assetsManager.getBalance(address, {
|
|
6282
6282
|
decimals
|
|
6283
6283
|
});
|
|
6284
6284
|
}
|
|
6285
6285
|
} catch (err) {
|
|
6286
6286
|
if (ignoreBalanceError({
|
|
6287
6287
|
token: options.srcToken,
|
|
6288
|
-
chainNamespace:
|
|
6288
|
+
chainNamespace: account9.walletAdapter?.chainNamespace,
|
|
6289
6289
|
err
|
|
6290
6290
|
})) {
|
|
6291
6291
|
return "0";
|
|
@@ -6294,7 +6294,7 @@ var useDeposit = (options) => {
|
|
|
6294
6294
|
}
|
|
6295
6295
|
return balance2;
|
|
6296
6296
|
},
|
|
6297
|
-
[options.srcToken,
|
|
6297
|
+
[options.srcToken, account9]
|
|
6298
6298
|
);
|
|
6299
6299
|
const fetchBalances = React2.useCallback(async (tokens) => {
|
|
6300
6300
|
const tasks = [];
|
|
@@ -6303,7 +6303,7 @@ var useDeposit = (options) => {
|
|
|
6303
6303
|
continue;
|
|
6304
6304
|
}
|
|
6305
6305
|
tasks.push(
|
|
6306
|
-
|
|
6306
|
+
account9.assetsManager.getBalance(token.address, {
|
|
6307
6307
|
decimals: token?.decimals
|
|
6308
6308
|
})
|
|
6309
6309
|
);
|
|
@@ -6321,7 +6321,7 @@ var useDeposit = (options) => {
|
|
|
6321
6321
|
if (orderlyTypes.isNativeTokenChecker(address))
|
|
6322
6322
|
return;
|
|
6323
6323
|
prevAddress.current = key;
|
|
6324
|
-
const allowance2 = await
|
|
6324
|
+
const allowance2 = await account9.assetsManager.getAllowance({
|
|
6325
6325
|
address,
|
|
6326
6326
|
vaultAddress: vaultAddress2,
|
|
6327
6327
|
decimals
|
|
@@ -6336,7 +6336,7 @@ var useDeposit = (options) => {
|
|
|
6336
6336
|
if (!address || orderlyTypes.isNativeTokenChecker(address))
|
|
6337
6337
|
return;
|
|
6338
6338
|
prevAddress.current = address;
|
|
6339
|
-
const allowance2 = await
|
|
6339
|
+
const allowance2 = await account9.assetsManager.getAllowance({
|
|
6340
6340
|
address,
|
|
6341
6341
|
decimals,
|
|
6342
6342
|
vaultAddress
|
|
@@ -6381,9 +6381,9 @@ var useDeposit = (options) => {
|
|
|
6381
6381
|
return;
|
|
6382
6382
|
setBalanceRevalidating(true);
|
|
6383
6383
|
queryBalance(options.address, options.decimals);
|
|
6384
|
-
if (
|
|
6384
|
+
if (account9.walletAdapter?.chainNamespace === orderlyTypes.ChainNamespace.solana) {
|
|
6385
6385
|
setAllowance(
|
|
6386
|
-
|
|
6386
|
+
account9.walletAdapter.formatUnits(orderlyTypes.MaxUint256, options.decimals)
|
|
6387
6387
|
);
|
|
6388
6388
|
return;
|
|
6389
6389
|
}
|
|
@@ -6403,14 +6403,14 @@ var useDeposit = (options) => {
|
|
|
6403
6403
|
state.status,
|
|
6404
6404
|
options.address,
|
|
6405
6405
|
options.decimals,
|
|
6406
|
-
|
|
6406
|
+
account9.address,
|
|
6407
6407
|
vaultAddress
|
|
6408
6408
|
]);
|
|
6409
6409
|
const updateAllowanceWhenTxSuccess = React2.useCallback(
|
|
6410
6410
|
(txHash) => {
|
|
6411
|
-
return
|
|
6411
|
+
return account9.walletAdapter?.pollTransactionReceiptWithBackoff(txHash).then((receipt) => {
|
|
6412
6412
|
if (receipt.status === 1) {
|
|
6413
|
-
|
|
6413
|
+
account9.assetsManager.getAllowance({
|
|
6414
6414
|
address: options.address,
|
|
6415
6415
|
decimals: options.decimals,
|
|
6416
6416
|
vaultAddress
|
|
@@ -6420,7 +6420,7 @@ var useDeposit = (options) => {
|
|
|
6420
6420
|
}
|
|
6421
6421
|
});
|
|
6422
6422
|
},
|
|
6423
|
-
[
|
|
6423
|
+
[account9, options.address, options.decimals, vaultAddress]
|
|
6424
6424
|
);
|
|
6425
6425
|
const enquireAllowance = React2.useCallback(async () => {
|
|
6426
6426
|
if (isNativeToken) {
|
|
@@ -6429,7 +6429,7 @@ var useDeposit = (options) => {
|
|
|
6429
6429
|
if (!options.address) {
|
|
6430
6430
|
throw new Error("address is required");
|
|
6431
6431
|
}
|
|
6432
|
-
const _allowance = await
|
|
6432
|
+
const _allowance = await account9.assetsManager.getAllowance({
|
|
6433
6433
|
address: options.address,
|
|
6434
6434
|
vaultAddress,
|
|
6435
6435
|
decimals: options.decimals
|
|
@@ -6440,7 +6440,7 @@ var useDeposit = (options) => {
|
|
|
6440
6440
|
}
|
|
6441
6441
|
return _allowance;
|
|
6442
6442
|
}, [
|
|
6443
|
-
|
|
6443
|
+
account9,
|
|
6444
6444
|
options.address,
|
|
6445
6445
|
options.decimals,
|
|
6446
6446
|
vaultAddress,
|
|
@@ -6461,17 +6461,17 @@ var useDeposit = (options) => {
|
|
|
6461
6461
|
);
|
|
6462
6462
|
const resetApprove = React2.useCallback(
|
|
6463
6463
|
async (tokenAddress, decimal, vaultAddress2) => {
|
|
6464
|
-
const result = await
|
|
6464
|
+
const result = await account9.assetsManager.approve({
|
|
6465
6465
|
address: tokenAddress,
|
|
6466
6466
|
amount: "0",
|
|
6467
6467
|
vaultAddress: vaultAddress2,
|
|
6468
6468
|
decimals: decimal
|
|
6469
6469
|
});
|
|
6470
|
-
const txResult = await
|
|
6470
|
+
const txResult = await account9.walletAdapter?.pollTransactionReceiptWithBackoff(
|
|
6471
6471
|
result.hash
|
|
6472
6472
|
);
|
|
6473
6473
|
if (txResult && txResult.status === 1) {
|
|
6474
|
-
|
|
6474
|
+
account9.assetsManager.getAllowance({
|
|
6475
6475
|
address: tokenAddress,
|
|
6476
6476
|
decimals: decimal,
|
|
6477
6477
|
vaultAddress: vaultAddress2
|
|
@@ -6498,7 +6498,7 @@ var useDeposit = (options) => {
|
|
|
6498
6498
|
);
|
|
6499
6499
|
}
|
|
6500
6500
|
}
|
|
6501
|
-
return
|
|
6501
|
+
return account9.assetsManager.approve({
|
|
6502
6502
|
address: options.address,
|
|
6503
6503
|
amount,
|
|
6504
6504
|
vaultAddress,
|
|
@@ -6509,7 +6509,7 @@ var useDeposit = (options) => {
|
|
|
6509
6509
|
});
|
|
6510
6510
|
},
|
|
6511
6511
|
[
|
|
6512
|
-
|
|
6512
|
+
account9,
|
|
6513
6513
|
options.srcChainId,
|
|
6514
6514
|
options.srcToken,
|
|
6515
6515
|
allowance,
|
|
@@ -6531,7 +6531,7 @@ var useDeposit = (options) => {
|
|
|
6531
6531
|
address: options.address,
|
|
6532
6532
|
vaultAddress
|
|
6533
6533
|
};
|
|
6534
|
-
const depositPromise = isNativeToken ?
|
|
6534
|
+
const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
|
|
6535
6535
|
return depositPromise.then((result) => {
|
|
6536
6536
|
updateAllowanceWhenTxSuccess(result.hash);
|
|
6537
6537
|
setBalance((value) => new orderlyUtils.Decimal(value).sub(quantity).toString());
|
|
@@ -6551,7 +6551,7 @@ var useDeposit = (options) => {
|
|
|
6551
6551
|
});
|
|
6552
6552
|
}, [
|
|
6553
6553
|
state,
|
|
6554
|
-
|
|
6554
|
+
account9,
|
|
6555
6555
|
quantity,
|
|
6556
6556
|
depositFee,
|
|
6557
6557
|
targetChain,
|
|
@@ -6566,7 +6566,7 @@ var useDeposit = (options) => {
|
|
|
6566
6566
|
if (getBalanceListener.current) {
|
|
6567
6567
|
clearTimeout(getBalanceListener.current);
|
|
6568
6568
|
}
|
|
6569
|
-
const time = timeout ?? (
|
|
6569
|
+
const time = timeout ?? (account9.walletAdapter?.chainNamespace === orderlyTypes.ChainNamespace.solana ? 1e4 : 3e3);
|
|
6570
6570
|
if (balanceRef.current === "") {
|
|
6571
6571
|
setBalanceRevalidating(true);
|
|
6572
6572
|
}
|
|
@@ -6590,7 +6590,7 @@ var useDeposit = (options) => {
|
|
|
6590
6590
|
};
|
|
6591
6591
|
const getDepositFee = React2.useCallback(
|
|
6592
6592
|
async (quantity2) => {
|
|
6593
|
-
return
|
|
6593
|
+
return account9.assetsManager.getDepositFee({
|
|
6594
6594
|
amount: quantity2,
|
|
6595
6595
|
chain: targetChain?.network_infos,
|
|
6596
6596
|
decimals: options.decimals,
|
|
@@ -6598,7 +6598,7 @@ var useDeposit = (options) => {
|
|
|
6598
6598
|
address: options.address
|
|
6599
6599
|
});
|
|
6600
6600
|
},
|
|
6601
|
-
[
|
|
6601
|
+
[account9, targetChain, options.decimals, options.srcToken, options.address]
|
|
6602
6602
|
);
|
|
6603
6603
|
const enquiryDepositFee = React2.useCallback(() => {
|
|
6604
6604
|
if (isNaN(Number(quantity)) || !quantity || Number(quantity) === 0) {
|
|
@@ -6661,10 +6661,10 @@ function ignoreBalanceError(options) {
|
|
|
6661
6661
|
// src/orderly/useConvert.ts
|
|
6662
6662
|
var useConvert = (options) => {
|
|
6663
6663
|
const { token = "" } = options;
|
|
6664
|
-
const { account:
|
|
6664
|
+
const { account: account9 } = useAccount();
|
|
6665
6665
|
const maxAmount = useMaxWithdrawal(token);
|
|
6666
6666
|
const convert = async (inputs) => {
|
|
6667
|
-
return
|
|
6667
|
+
return account9.assetsManager.convert({
|
|
6668
6668
|
...inputs,
|
|
6669
6669
|
converted_asset: token
|
|
6670
6670
|
});
|
|
@@ -6694,7 +6694,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
|
|
|
6694
6694
|
if (!url.startsWith("http")) {
|
|
6695
6695
|
fullUrl = `${apiBaseUrl}${url}`;
|
|
6696
6696
|
}
|
|
6697
|
-
const
|
|
6697
|
+
const account9 = useAccountInstance();
|
|
6698
6698
|
const { trigger, reset, data, error, isMutating } = useSWRMutation__default.default(
|
|
6699
6699
|
fullUrl,
|
|
6700
6700
|
// method === "POST" ? fetcher : deleteFetcher,
|
|
@@ -6713,7 +6713,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
|
|
|
6713
6713
|
url: newUrl,
|
|
6714
6714
|
data: data2
|
|
6715
6715
|
};
|
|
6716
|
-
const signer =
|
|
6716
|
+
const signer = account9.signer;
|
|
6717
6717
|
const signature = await signer.sign(payload, orderlyUtils.getTimestamp());
|
|
6718
6718
|
return trigger(
|
|
6719
6719
|
{
|
|
@@ -6722,7 +6722,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
|
|
|
6722
6722
|
method,
|
|
6723
6723
|
signature: {
|
|
6724
6724
|
...signature,
|
|
6725
|
-
"orderly-account-id": accountId || _accountId ||
|
|
6725
|
+
"orderly-account-id": accountId || _accountId || account9.accountId
|
|
6726
6726
|
}
|
|
6727
6727
|
},
|
|
6728
6728
|
restOptions2
|
|
@@ -6769,11 +6769,11 @@ var useTransfer = (options) => {
|
|
|
6769
6769
|
};
|
|
6770
6770
|
var useInternalTransfer = () => {
|
|
6771
6771
|
const [submitting, setSubmitting] = React2.useState(false);
|
|
6772
|
-
const { account:
|
|
6772
|
+
const { account: account9 } = useAccount();
|
|
6773
6773
|
const transfer = React2.useCallback(
|
|
6774
6774
|
async (inputs) => {
|
|
6775
6775
|
setSubmitting(true);
|
|
6776
|
-
return
|
|
6776
|
+
return account9.assetsManager.internalTransfer(inputs).then((res) => {
|
|
6777
6777
|
if (res.success) {
|
|
6778
6778
|
return res;
|
|
6779
6779
|
}
|
|
@@ -6784,7 +6784,7 @@ var useInternalTransfer = () => {
|
|
|
6784
6784
|
setSubmitting(false);
|
|
6785
6785
|
});
|
|
6786
6786
|
},
|
|
6787
|
-
[
|
|
6787
|
+
[account9]
|
|
6788
6788
|
);
|
|
6789
6789
|
return {
|
|
6790
6790
|
submitting,
|
|
@@ -9043,7 +9043,7 @@ function calcByPrice(positions3, markPrice, indexPrice) {
|
|
|
9043
9043
|
var useSubAccountWS = (options) => {
|
|
9044
9044
|
const { accountId } = options;
|
|
9045
9045
|
const { configStore } = React2.useContext(OrderlyContext);
|
|
9046
|
-
const { state, account:
|
|
9046
|
+
const { state, account: account9 } = useAccount();
|
|
9047
9047
|
const websocketClient = React2.useRef(
|
|
9048
9048
|
new orderlyNet.WS({
|
|
9049
9049
|
networkId: configStore.get("networkId"),
|
|
@@ -9051,7 +9051,7 @@ var useSubAccountWS = (options) => {
|
|
|
9051
9051
|
// publicUrl: configStore.get("publicWsUrl"),
|
|
9052
9052
|
privateUrl: configStore.get("privateWsUrl"),
|
|
9053
9053
|
onSigntureRequest: async () => {
|
|
9054
|
-
const signer =
|
|
9054
|
+
const signer = account9.signer;
|
|
9055
9055
|
const timestamp = orderlyUtils.getTimestamp();
|
|
9056
9056
|
const result = await signer.signText(timestamp.toString());
|
|
9057
9057
|
return { ...result, timestamp };
|
|
@@ -9635,82 +9635,6 @@ var useSymbolLeverage = (symbol) => {
|
|
|
9635
9635
|
isLoading: isMutating
|
|
9636
9636
|
};
|
|
9637
9637
|
};
|
|
9638
|
-
var useEffectiveLeverage = (inputs) => {
|
|
9639
|
-
const {
|
|
9640
|
-
symbol,
|
|
9641
|
-
positionQty = 0,
|
|
9642
|
-
positionPrice,
|
|
9643
|
-
orderQty = 0,
|
|
9644
|
-
orderPrice,
|
|
9645
|
-
selectedLeverage: inputSelectedLeverage
|
|
9646
|
-
} = inputs;
|
|
9647
|
-
const accountInfo = useAccountInfo2();
|
|
9648
|
-
const symbolsInfo = useSymbolsInfo();
|
|
9649
|
-
const maxLeverage = useMaxLeverage(symbol);
|
|
9650
|
-
const markPriceData = useMarkPrice(symbol);
|
|
9651
|
-
const markPrice = markPriceData?.data ?? 0;
|
|
9652
|
-
return React2.useMemo(() => {
|
|
9653
|
-
const effectivePositionPrice = positionPrice ?? markPrice;
|
|
9654
|
-
const effectiveOrderPrice = orderPrice ?? markPrice;
|
|
9655
|
-
const positionNotional = Math.abs(
|
|
9656
|
-
new orderlyUtils.Decimal(positionQty).mul(effectivePositionPrice).toNumber()
|
|
9657
|
-
);
|
|
9658
|
-
const orderNotional = Math.abs(
|
|
9659
|
-
new orderlyUtils.Decimal(orderQty).mul(effectiveOrderPrice).toNumber()
|
|
9660
|
-
);
|
|
9661
|
-
const symbolInfo = symbolsInfo[symbol];
|
|
9662
|
-
const baseIMR = symbolInfo("base_imr");
|
|
9663
|
-
const selectedLeverage = inputSelectedLeverage ?? maxLeverage;
|
|
9664
|
-
if (baseIMR === void 0 || baseIMR === null) {
|
|
9665
|
-
return {
|
|
9666
|
-
selectedLeverage,
|
|
9667
|
-
effectiveLeverage: maxLeverage,
|
|
9668
|
-
displayLeverage: Math.min(selectedLeverage, maxLeverage),
|
|
9669
|
-
imr: 1 / maxLeverage,
|
|
9670
|
-
isConstrained: false,
|
|
9671
|
-
constraintMessage: void 0
|
|
9672
|
-
};
|
|
9673
|
-
}
|
|
9674
|
-
const imrFactor = accountInfo?.imr_factor?.[symbol] ?? 0;
|
|
9675
|
-
const calculatedIMR = orderlyPerp.account.IMR({
|
|
9676
|
-
maxLeverage,
|
|
9677
|
-
baseIMR,
|
|
9678
|
-
IMR_Factor: imrFactor,
|
|
9679
|
-
positionNotional,
|
|
9680
|
-
ordersNotional: orderNotional,
|
|
9681
|
-
IMR_factor_power: 4 / 5
|
|
9682
|
-
});
|
|
9683
|
-
const effectiveLeverage = 1 / calculatedIMR;
|
|
9684
|
-
const displayLeverage = Math.min(selectedLeverage, effectiveLeverage);
|
|
9685
|
-
const isConstrained = effectiveLeverage < selectedLeverage;
|
|
9686
|
-
let constraintMessage;
|
|
9687
|
-
if (isConstrained) {
|
|
9688
|
-
const totalNotional = new orderlyUtils.Decimal(positionNotional).add(orderNotional);
|
|
9689
|
-
constraintMessage = `For this position size ($${totalNotional.toFixed(
|
|
9690
|
-
2
|
|
9691
|
-
)}), the maximum effective leverage is ${Math.floor(effectiveLeverage)}x`;
|
|
9692
|
-
}
|
|
9693
|
-
return {
|
|
9694
|
-
selectedLeverage,
|
|
9695
|
-
effectiveLeverage,
|
|
9696
|
-
displayLeverage,
|
|
9697
|
-
imr: calculatedIMR,
|
|
9698
|
-
isConstrained,
|
|
9699
|
-
constraintMessage
|
|
9700
|
-
};
|
|
9701
|
-
}, [
|
|
9702
|
-
symbol,
|
|
9703
|
-
symbolsInfo,
|
|
9704
|
-
accountInfo,
|
|
9705
|
-
positionQty,
|
|
9706
|
-
positionPrice,
|
|
9707
|
-
orderQty,
|
|
9708
|
-
orderPrice,
|
|
9709
|
-
markPrice,
|
|
9710
|
-
inputSelectedLeverage,
|
|
9711
|
-
maxLeverage
|
|
9712
|
-
]);
|
|
9713
|
-
};
|
|
9714
9638
|
var useAssetsHistory = (options, config) => {
|
|
9715
9639
|
const ee = useEventEmitter();
|
|
9716
9640
|
const getKey = () => {
|
|
@@ -10057,7 +9981,7 @@ var useStorageLedgerAddress = () => {
|
|
|
10057
9981
|
var usePrivateDataObserver = (options) => {
|
|
10058
9982
|
const ws = useWS();
|
|
10059
9983
|
const ee = useEventEmitter();
|
|
10060
|
-
const { state, account:
|
|
9984
|
+
const { state, account: account9 } = useAccount();
|
|
10061
9985
|
const { setAccountInfo, restoreHolding, cleanAll } = useAppStore(
|
|
10062
9986
|
(state2) => state2.actions
|
|
10063
9987
|
);
|
|
@@ -10090,9 +10014,9 @@ var usePrivateDataObserver = (options) => {
|
|
|
10090
10014
|
positionsActions.clearAll();
|
|
10091
10015
|
}
|
|
10092
10016
|
};
|
|
10093
|
-
|
|
10017
|
+
account9.on(orderlyCore.EVENT_NAMES.statusChanged, handler);
|
|
10094
10018
|
return () => {
|
|
10095
|
-
|
|
10019
|
+
account9.off(orderlyCore.EVENT_NAMES.statusChanged, handler);
|
|
10096
10020
|
};
|
|
10097
10021
|
}, []);
|
|
10098
10022
|
React2.useEffect(() => {
|
|
@@ -10113,7 +10037,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
10113
10037
|
}
|
|
10114
10038
|
);
|
|
10115
10039
|
React2.useEffect(() => {
|
|
10116
|
-
if (!
|
|
10040
|
+
if (!account9.accountId)
|
|
10117
10041
|
return;
|
|
10118
10042
|
const unsubscribe = ws.privateSubscribe(
|
|
10119
10043
|
{
|
|
@@ -10132,7 +10056,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
10132
10056
|
}
|
|
10133
10057
|
);
|
|
10134
10058
|
return () => unsubscribe?.();
|
|
10135
|
-
}, [
|
|
10059
|
+
}, [account9.accountId]);
|
|
10136
10060
|
const isHoldingInit = React2.useRef(false);
|
|
10137
10061
|
React2.useEffect(() => {
|
|
10138
10062
|
isHoldingInit.current = false;
|
|
@@ -10460,7 +10384,7 @@ var DataCenterProvider = ({
|
|
|
10460
10384
|
return /* @__PURE__ */ jsxRuntime.jsx(DataCenterContext.Provider, { value: memoizedValue, children });
|
|
10461
10385
|
};
|
|
10462
10386
|
var OrderlyConfigProvider = (props) => {
|
|
10463
|
-
const [
|
|
10387
|
+
const [account9, setAccount] = React2__default.default.useState(null);
|
|
10464
10388
|
const {
|
|
10465
10389
|
configStore,
|
|
10466
10390
|
keyStore,
|
|
@@ -10517,9 +10441,9 @@ var OrderlyConfigProvider = (props) => {
|
|
|
10517
10441
|
return orderbookDefaultSymbolDepths || DEFAULT_SYMBOL_DEPTHS;
|
|
10518
10442
|
}, [orderbookDefaultSymbolDepths]);
|
|
10519
10443
|
React2.useLayoutEffect(() => {
|
|
10520
|
-
let
|
|
10521
|
-
if (!
|
|
10522
|
-
|
|
10444
|
+
let account10 = orderlyCore.SimpleDI.get(orderlyCore.Account.instanceName);
|
|
10445
|
+
if (!account10) {
|
|
10446
|
+
account10 = new orderlyCore.Account(
|
|
10523
10447
|
innerConfigStore,
|
|
10524
10448
|
innerKeyStore,
|
|
10525
10449
|
// innerGetWalletAdapter,
|
|
@@ -10528,9 +10452,9 @@ var OrderlyConfigProvider = (props) => {
|
|
|
10528
10452
|
contracts
|
|
10529
10453
|
}
|
|
10530
10454
|
);
|
|
10531
|
-
orderlyCore.SimpleDI.registerByName(orderlyCore.Account.instanceName,
|
|
10455
|
+
orderlyCore.SimpleDI.registerByName(orderlyCore.Account.instanceName, account10);
|
|
10532
10456
|
}
|
|
10533
|
-
setAccount(
|
|
10457
|
+
setAccount(account10);
|
|
10534
10458
|
}, []);
|
|
10535
10459
|
const filteredChains = React2.useMemo(() => {
|
|
10536
10460
|
if (typeof chainFilter === "function") {
|
|
@@ -10571,7 +10495,7 @@ var OrderlyConfigProvider = (props) => {
|
|
|
10571
10495
|
amplitudeConfig,
|
|
10572
10496
|
orderMetadata
|
|
10573
10497
|
]);
|
|
10574
|
-
if (!
|
|
10498
|
+
if (!account9) {
|
|
10575
10499
|
return null;
|
|
10576
10500
|
}
|
|
10577
10501
|
return /* @__PURE__ */ jsxRuntime.jsx(OrderlyProvider, { value: memoizedValue, children: /* @__PURE__ */ jsxRuntime.jsx(StatusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children }) }) });
|
|
@@ -11751,9 +11675,9 @@ var useAllBrokers = () => {
|
|
|
11751
11675
|
};
|
|
11752
11676
|
var useCurEpochEstimate = (type) => {
|
|
11753
11677
|
const [data, setData] = React2.useState(void 0);
|
|
11754
|
-
const { account:
|
|
11678
|
+
const { account: account9 } = useAccount();
|
|
11755
11679
|
const brokers = useAllBrokers();
|
|
11756
|
-
const address =
|
|
11680
|
+
const address = account9.address;
|
|
11757
11681
|
const path2 = type === "normal" /* normal */ ? `/v1/public/trading_rewards/current_epoch_estimate?address=${address}` : `/v1/public/market_making_rewards/current_epoch_estimate?address=${address}`;
|
|
11758
11682
|
const { data: estimateData } = useQuery(address !== void 0 ? path2 : "", {
|
|
11759
11683
|
formatter: (res) => {
|
|
@@ -16713,14 +16637,14 @@ var DistributionId = /* @__PURE__ */ ((DistributionId2) => {
|
|
|
16713
16637
|
})(DistributionId || {});
|
|
16714
16638
|
var useGetClaimed = (id) => {
|
|
16715
16639
|
const [data, setData] = React2.useState(0);
|
|
16716
|
-
const { account:
|
|
16717
|
-
const address =
|
|
16640
|
+
const { account: account9 } = useAccount();
|
|
16641
|
+
const address = account9.address;
|
|
16718
16642
|
const env = useGetEnv();
|
|
16719
16643
|
const refresh = React2.useCallback(() => {
|
|
16720
16644
|
const params = getContractByEnv(env);
|
|
16721
16645
|
if (typeof address === "undefined")
|
|
16722
16646
|
return;
|
|
16723
|
-
|
|
16647
|
+
account9.walletAdapter?.callOnChain(
|
|
16724
16648
|
// @ts-ignore
|
|
16725
16649
|
{ public_rpc_url: params.orderlyChainRpcUrl },
|
|
16726
16650
|
params.orderlyContract,
|
|
@@ -16745,8 +16669,8 @@ var useGetClaimed = (id) => {
|
|
|
16745
16669
|
|
|
16746
16670
|
// src/trading-rewards/useWalletRewardsHistory.ts
|
|
16747
16671
|
var useWalletRewardsHistory = (type) => {
|
|
16748
|
-
const { account:
|
|
16749
|
-
const address =
|
|
16672
|
+
const { account: account9 } = useAccount();
|
|
16673
|
+
const address = account9.address;
|
|
16750
16674
|
const path2 = type === "normal" /* normal */ ? `/v1/public/trading_rewards/wallet_rewards_history?address=${address}` : `/v1/public/market_making_rewards/group_rewards_history?address=${address}`;
|
|
16751
16675
|
const {
|
|
16752
16676
|
data,
|
|
@@ -16794,7 +16718,7 @@ function useTradingRewardsStatus(isMMRewards) {
|
|
|
16794
16718
|
};
|
|
16795
16719
|
}
|
|
16796
16720
|
var useApiKeyManager = (queryParams) => {
|
|
16797
|
-
const { account:
|
|
16721
|
+
const { account: account9, state, isSubAccount } = useAccount();
|
|
16798
16722
|
const { keyInfo } = queryParams || {};
|
|
16799
16723
|
const keyInfoPrams = getQueryParamsFromObject(keyInfo);
|
|
16800
16724
|
const { data, mutate: mutate5, error, isLoading } = usePrivateQuery(
|
|
@@ -16831,13 +16755,13 @@ var useApiKeyManager = (queryParams) => {
|
|
|
16831
16755
|
}, []);
|
|
16832
16756
|
const generateOrderlyKey = (scope) => {
|
|
16833
16757
|
if (isSubAccount) {
|
|
16834
|
-
return
|
|
16758
|
+
return account9?.createSubAccountApiKey(365, {
|
|
16835
16759
|
tag: "manualCreated",
|
|
16836
16760
|
scope,
|
|
16837
16761
|
subAccountId: state.accountId
|
|
16838
16762
|
});
|
|
16839
16763
|
}
|
|
16840
|
-
return
|
|
16764
|
+
return account9?.createApiKey(365, {
|
|
16841
16765
|
tag: "manualCreated",
|
|
16842
16766
|
scope
|
|
16843
16767
|
});
|
|
@@ -17964,7 +17888,6 @@ exports.useDaily = useDaily;
|
|
|
17964
17888
|
exports.useDeposit = useDeposit;
|
|
17965
17889
|
exports.useDistribution = useDistribution;
|
|
17966
17890
|
exports.useDistributionHistory = useDistributionHistory;
|
|
17967
|
-
exports.useEffectiveLeverage = useEffectiveLeverage;
|
|
17968
17891
|
exports.useEpochInfo = useEpochInfo;
|
|
17969
17892
|
exports.useEventEmitter = useEventEmitter;
|
|
17970
17893
|
exports.useFeeState = useFeeState;
|