@nktkas/hyperliquid 0.25.6 → 0.25.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.
- package/CONTRIBUTING.md +26 -19
- package/README.md +106 -9
- package/esm/bin/cli.js +1 -0
- package/esm/bin/cli.js.map +1 -1
- package/esm/src/api/_common_schemas.d.ts +19 -0
- package/esm/src/api/_common_schemas.d.ts.map +1 -1
- package/esm/src/api/_common_schemas.js +15 -0
- package/esm/src/api/_common_schemas.js.map +1 -1
- package/esm/src/api/exchange/_base/_execute.d.ts +6 -7
- package/esm/src/api/exchange/_base/_execute.d.ts.map +1 -1
- package/esm/src/api/exchange/_base/_execute.js +67 -43
- package/esm/src/api/exchange/_base/_execute.js.map +1 -1
- package/esm/src/api/exchange/_base/_types.d.ts +0 -7
- package/esm/src/api/exchange/_base/_types.d.ts.map +1 -1
- package/esm/src/api/exchange/_base/mod.d.ts +0 -2
- package/esm/src/api/exchange/_base/mod.d.ts.map +1 -1
- package/esm/src/api/exchange/_base/mod.js +0 -2
- package/esm/src/api/exchange/_base/mod.js.map +1 -1
- package/esm/src/api/exchange/agentEnableDexAbstraction.d.ts.map +1 -1
- package/esm/src/api/exchange/agentEnableDexAbstraction.js +14 -7
- package/esm/src/api/exchange/agentEnableDexAbstraction.js.map +1 -1
- package/esm/src/api/exchange/approveAgent.d.ts.map +1 -1
- package/esm/src/api/exchange/approveAgent.js +16 -8
- package/esm/src/api/exchange/approveAgent.js.map +1 -1
- package/esm/src/api/exchange/approveBuilderFee.d.ts.map +1 -1
- package/esm/src/api/exchange/approveBuilderFee.js +16 -8
- package/esm/src/api/exchange/approveBuilderFee.js.map +1 -1
- package/esm/src/api/exchange/batchModify.d.ts.map +1 -1
- package/esm/src/api/exchange/batchModify.js +16 -10
- package/esm/src/api/exchange/batchModify.js.map +1 -1
- package/esm/src/api/exchange/cDeposit.d.ts.map +1 -1
- package/esm/src/api/exchange/cDeposit.js +16 -8
- package/esm/src/api/exchange/cDeposit.js.map +1 -1
- package/esm/src/api/exchange/cSignerAction.d.ts.map +1 -1
- package/esm/src/api/exchange/cSignerAction.js +15 -8
- package/esm/src/api/exchange/cSignerAction.js.map +1 -1
- package/esm/src/api/exchange/cValidatorAction.d.ts.map +1 -1
- package/esm/src/api/exchange/cValidatorAction.js +15 -8
- package/esm/src/api/exchange/cValidatorAction.js.map +1 -1
- package/esm/src/api/exchange/cWithdraw.d.ts.map +1 -1
- package/esm/src/api/exchange/cWithdraw.js +16 -8
- package/esm/src/api/exchange/cWithdraw.js.map +1 -1
- package/esm/src/api/exchange/cancel.d.ts.map +1 -1
- package/esm/src/api/exchange/cancel.js +16 -10
- package/esm/src/api/exchange/cancel.js.map +1 -1
- package/esm/src/api/exchange/cancelByCloid.d.ts.map +1 -1
- package/esm/src/api/exchange/cancelByCloid.js +16 -10
- package/esm/src/api/exchange/cancelByCloid.js.map +1 -1
- package/esm/src/api/exchange/claimRewards.d.ts.map +1 -1
- package/esm/src/api/exchange/claimRewards.js +14 -7
- package/esm/src/api/exchange/claimRewards.js.map +1 -1
- package/esm/src/api/exchange/convertToMultiSigUser.d.ts.map +1 -1
- package/esm/src/api/exchange/convertToMultiSigUser.js +16 -8
- package/esm/src/api/exchange/convertToMultiSigUser.js.map +1 -1
- package/esm/src/api/exchange/createSubAccount.d.ts.map +1 -1
- package/esm/src/api/exchange/createSubAccount.js +15 -8
- package/esm/src/api/exchange/createSubAccount.js.map +1 -1
- package/esm/src/api/exchange/createVault.d.ts.map +1 -1
- package/esm/src/api/exchange/createVault.js +15 -8
- package/esm/src/api/exchange/createVault.js.map +1 -1
- package/esm/src/api/exchange/evmUserModify.d.ts +1 -1
- package/esm/src/api/exchange/evmUserModify.d.ts.map +1 -1
- package/esm/src/api/exchange/evmUserModify.js +16 -9
- package/esm/src/api/exchange/evmUserModify.js.map +1 -1
- package/esm/src/api/exchange/linkStakingUser.d.ts +112 -0
- package/esm/src/api/exchange/linkStakingUser.d.ts.map +1 -0
- package/esm/src/api/exchange/linkStakingUser.js +99 -0
- package/esm/src/api/exchange/linkStakingUser.js.map +1 -0
- package/esm/src/api/exchange/modify.d.ts.map +1 -1
- package/esm/src/api/exchange/modify.js +16 -10
- package/esm/src/api/exchange/modify.js.map +1 -1
- package/esm/src/api/exchange/multiSig.d.ts.map +1 -1
- package/esm/src/api/exchange/multiSig.js +17 -16
- package/esm/src/api/exchange/multiSig.js.map +1 -1
- package/esm/src/api/exchange/noop.d.ts.map +1 -1
- package/esm/src/api/exchange/noop.js +14 -7
- package/esm/src/api/exchange/noop.js.map +1 -1
- package/esm/src/api/exchange/order.d.ts.map +1 -1
- package/esm/src/api/exchange/order.js +16 -10
- package/esm/src/api/exchange/order.js.map +1 -1
- package/esm/src/api/exchange/perpDeploy.d.ts.map +1 -1
- package/esm/src/api/exchange/perpDeploy.js +15 -8
- package/esm/src/api/exchange/perpDeploy.js.map +1 -1
- package/esm/src/api/exchange/registerReferrer.d.ts.map +1 -1
- package/esm/src/api/exchange/registerReferrer.js +15 -8
- package/esm/src/api/exchange/registerReferrer.js.map +1 -1
- package/esm/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
- package/esm/src/api/exchange/reserveRequestWeight.js +15 -8
- package/esm/src/api/exchange/reserveRequestWeight.js.map +1 -1
- package/esm/src/api/exchange/scheduleCancel.js +16 -10
- package/esm/src/api/exchange/scheduleCancel.js.map +1 -1
- package/esm/src/api/exchange/sendAsset.d.ts.map +1 -1
- package/esm/src/api/exchange/sendAsset.js +16 -8
- package/esm/src/api/exchange/sendAsset.js.map +1 -1
- package/esm/src/api/exchange/setDisplayName.d.ts.map +1 -1
- package/esm/src/api/exchange/setDisplayName.js +15 -8
- package/esm/src/api/exchange/setDisplayName.js.map +1 -1
- package/esm/src/api/exchange/setReferrer.d.ts.map +1 -1
- package/esm/src/api/exchange/setReferrer.js +15 -8
- package/esm/src/api/exchange/setReferrer.js.map +1 -1
- package/esm/src/api/exchange/spotDeploy.d.ts.map +1 -1
- package/esm/src/api/exchange/spotDeploy.js +15 -8
- package/esm/src/api/exchange/spotDeploy.js.map +1 -1
- package/esm/src/api/exchange/spotSend.d.ts.map +1 -1
- package/esm/src/api/exchange/spotSend.js +16 -8
- package/esm/src/api/exchange/spotSend.js.map +1 -1
- package/esm/src/api/exchange/spotUser.d.ts.map +1 -1
- package/esm/src/api/exchange/spotUser.js +15 -8
- package/esm/src/api/exchange/spotUser.js.map +1 -1
- package/esm/src/api/exchange/subAccountModify.d.ts.map +1 -1
- package/esm/src/api/exchange/subAccountModify.js +15 -8
- package/esm/src/api/exchange/subAccountModify.js.map +1 -1
- package/esm/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
- package/esm/src/api/exchange/subAccountSpotTransfer.js +15 -8
- package/esm/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
- package/esm/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
- package/esm/src/api/exchange/subAccountTransfer.js +15 -8
- package/esm/src/api/exchange/subAccountTransfer.js.map +1 -1
- package/esm/src/api/exchange/tokenDelegate.d.ts.map +1 -1
- package/esm/src/api/exchange/tokenDelegate.js +16 -8
- package/esm/src/api/exchange/tokenDelegate.js.map +1 -1
- package/esm/src/api/exchange/twapCancel.d.ts.map +1 -1
- package/esm/src/api/exchange/twapCancel.js +16 -10
- package/esm/src/api/exchange/twapCancel.js.map +1 -1
- package/esm/src/api/exchange/twapOrder.d.ts.map +1 -1
- package/esm/src/api/exchange/twapOrder.js +16 -10
- package/esm/src/api/exchange/twapOrder.js.map +1 -1
- package/esm/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
- package/esm/src/api/exchange/updateIsolatedMargin.js +16 -10
- package/esm/src/api/exchange/updateIsolatedMargin.js.map +1 -1
- package/esm/src/api/exchange/updateLeverage.d.ts.map +1 -1
- package/esm/src/api/exchange/updateLeverage.js +16 -10
- package/esm/src/api/exchange/updateLeverage.js.map +1 -1
- package/esm/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
- package/esm/src/api/exchange/usdClassTransfer.js +16 -8
- package/esm/src/api/exchange/usdClassTransfer.js.map +1 -1
- package/esm/src/api/exchange/usdSend.d.ts.map +1 -1
- package/esm/src/api/exchange/usdSend.js +16 -8
- package/esm/src/api/exchange/usdSend.js.map +1 -1
- package/esm/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
- package/esm/src/api/exchange/userDexAbstraction.js +16 -8
- package/esm/src/api/exchange/userDexAbstraction.js.map +1 -1
- package/esm/src/api/exchange/vaultDistribute.d.ts.map +1 -1
- package/esm/src/api/exchange/vaultDistribute.js +15 -8
- package/esm/src/api/exchange/vaultDistribute.js.map +1 -1
- package/esm/src/api/exchange/vaultModify.d.ts.map +1 -1
- package/esm/src/api/exchange/vaultModify.js +15 -8
- package/esm/src/api/exchange/vaultModify.js.map +1 -1
- package/esm/src/api/exchange/vaultTransfer.d.ts.map +1 -1
- package/esm/src/api/exchange/vaultTransfer.js +15 -8
- package/esm/src/api/exchange/vaultTransfer.js.map +1 -1
- package/esm/src/api/exchange/withdraw3.d.ts.map +1 -1
- package/esm/src/api/exchange/withdraw3.js +16 -8
- package/esm/src/api/exchange/withdraw3.js.map +1 -1
- package/esm/src/api/exchange/~client.d.ts +31 -3
- package/esm/src/api/exchange/~client.d.ts.map +1 -1
- package/esm/src/api/exchange/~client.js +27 -4
- package/esm/src/api/exchange/~client.js.map +1 -1
- package/esm/src/api/exchange/~mod.d.ts +1 -0
- package/esm/src/api/exchange/~mod.d.ts.map +1 -1
- package/esm/src/api/exchange/~mod.js +1 -0
- package/esm/src/api/exchange/~mod.js.map +1 -1
- package/esm/src/api/info/allPerpMetas.d.ts +5 -0
- package/esm/src/api/info/allPerpMetas.d.ts.map +1 -1
- package/esm/src/api/info/meta.d.ts +5 -0
- package/esm/src/api/info/meta.d.ts.map +1 -1
- package/esm/src/api/info/meta.js +2 -0
- package/esm/src/api/info/meta.js.map +1 -1
- package/esm/src/api/info/metaAndAssetCtxs.d.ts +5 -0
- package/esm/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
- package/esm/src/api/info/perpDexs.d.ts +4 -0
- package/esm/src/api/info/perpDexs.d.ts.map +1 -1
- package/esm/src/api/info/perpDexs.js +5 -0
- package/esm/src/api/info/perpDexs.js.map +1 -1
- package/esm/src/api/info/spotClearinghouseState.d.ts +0 -5
- package/esm/src/api/info/spotClearinghouseState.d.ts.map +1 -1
- package/esm/src/api/info/spotClearinghouseState.js +2 -14
- package/esm/src/api/info/spotClearinghouseState.js.map +1 -1
- package/esm/src/api/info/userFees.d.ts +27 -2
- package/esm/src/api/info/userFees.d.ts.map +1 -1
- package/esm/src/api/info/userFees.js +29 -1
- package/esm/src/api/info/userFees.js.map +1 -1
- package/esm/src/api/info/webData2.d.ts +152 -23
- package/esm/src/api/info/webData2.d.ts.map +1 -1
- package/esm/src/api/info/webData2.js +3 -54
- package/esm/src/api/info/webData2.js.map +1 -1
- package/esm/src/api/info/~client.d.ts +11 -3
- package/esm/src/api/info/~client.d.ts.map +1 -1
- package/esm/src/api/subscription/spotState.d.ts +91 -0
- package/esm/src/api/subscription/spotState.d.ts.map +1 -0
- package/esm/src/api/subscription/spotState.js +58 -0
- package/esm/src/api/subscription/spotState.js.map +1 -0
- package/esm/src/api/subscription/webData2.d.ts +9 -4
- package/esm/src/api/subscription/webData2.d.ts.map +1 -1
- package/esm/src/api/subscription/webData2.js +1 -1
- package/esm/src/api/subscription/webData2.js.map +1 -1
- package/esm/src/api/subscription/webData3.d.ts +541 -0
- package/esm/src/api/subscription/webData3.d.ts.map +1 -0
- package/esm/src/api/subscription/webData3.js +94 -0
- package/esm/src/api/subscription/webData3.js.map +1 -0
- package/esm/src/api/subscription/~client.d.ts +44 -0
- package/esm/src/api/subscription/~client.d.ts.map +1 -1
- package/esm/src/api/subscription/~client.js +46 -0
- package/esm/src/api/subscription/~client.js.map +1 -1
- package/esm/src/api/subscription/~mod.d.ts +2 -0
- package/esm/src/api/subscription/~mod.d.ts.map +1 -1
- package/esm/src/api/subscription/~mod.js +2 -0
- package/esm/src/api/subscription/~mod.js.map +1 -1
- package/esm/src/signing/_signTypedData.d.ts +1 -1
- package/esm/src/signing/_signTypedData.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData.js +1 -1
- package/esm/src/signing/_signTypedData.js.map +1 -1
- package/esm/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
- package/esm/src/utils/_eip712.d.ts.map +1 -0
- package/esm/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -11
- package/esm/src/utils/_eip712.js.map +1 -0
- package/esm/src/utils/_format.d.ts +28 -0
- package/esm/src/utils/_format.d.ts.map +1 -0
- package/esm/src/utils/_format.js +157 -0
- package/esm/src/utils/_format.js.map +1 -0
- package/esm/src/utils/_recover.d.ts +89 -0
- package/esm/src/utils/_recover.d.ts.map +1 -0
- package/esm/src/utils/_recover.js +119 -0
- package/esm/src/utils/_recover.js.map +1 -0
- package/esm/src/utils/_symbolConverter.d.ts +13 -0
- package/esm/src/utils/_symbolConverter.d.ts.map +1 -1
- package/esm/src/utils/_symbolConverter.js +17 -0
- package/esm/src/utils/_symbolConverter.js.map +1 -1
- package/esm/src/utils/mod.d.ts +2 -0
- package/esm/src/utils/mod.d.ts.map +1 -1
- package/esm/src/utils/mod.js +2 -0
- package/esm/src/utils/mod.js.map +1 -1
- package/package.json +3 -2
- package/script/bin/cli.js +1 -0
- package/script/bin/cli.js.map +1 -1
- package/script/src/api/_common_schemas.d.ts +19 -0
- package/script/src/api/_common_schemas.d.ts.map +1 -1
- package/script/src/api/_common_schemas.js +16 -1
- package/script/src/api/_common_schemas.js.map +1 -1
- package/script/src/api/exchange/_base/_execute.d.ts +6 -7
- package/script/src/api/exchange/_base/_execute.d.ts.map +1 -1
- package/script/src/api/exchange/_base/_execute.js +67 -43
- package/script/src/api/exchange/_base/_execute.js.map +1 -1
- package/script/src/api/exchange/_base/_types.d.ts +0 -7
- package/script/src/api/exchange/_base/_types.d.ts.map +1 -1
- package/script/src/api/exchange/_base/mod.d.ts +0 -2
- package/script/src/api/exchange/_base/mod.d.ts.map +1 -1
- package/script/src/api/exchange/_base/mod.js +0 -2
- package/script/src/api/exchange/_base/mod.js.map +1 -1
- package/script/src/api/exchange/agentEnableDexAbstraction.d.ts.map +1 -1
- package/script/src/api/exchange/agentEnableDexAbstraction.js +14 -7
- package/script/src/api/exchange/agentEnableDexAbstraction.js.map +1 -1
- package/script/src/api/exchange/approveAgent.d.ts.map +1 -1
- package/script/src/api/exchange/approveAgent.js +15 -7
- package/script/src/api/exchange/approveAgent.js.map +1 -1
- package/script/src/api/exchange/approveBuilderFee.d.ts.map +1 -1
- package/script/src/api/exchange/approveBuilderFee.js +15 -7
- package/script/src/api/exchange/approveBuilderFee.js.map +1 -1
- package/script/src/api/exchange/batchModify.d.ts.map +1 -1
- package/script/src/api/exchange/batchModify.js +16 -10
- package/script/src/api/exchange/batchModify.js.map +1 -1
- package/script/src/api/exchange/cDeposit.d.ts.map +1 -1
- package/script/src/api/exchange/cDeposit.js +15 -7
- package/script/src/api/exchange/cDeposit.js.map +1 -1
- package/script/src/api/exchange/cSignerAction.d.ts.map +1 -1
- package/script/src/api/exchange/cSignerAction.js +15 -8
- package/script/src/api/exchange/cSignerAction.js.map +1 -1
- package/script/src/api/exchange/cValidatorAction.d.ts.map +1 -1
- package/script/src/api/exchange/cValidatorAction.js +15 -8
- package/script/src/api/exchange/cValidatorAction.js.map +1 -1
- package/script/src/api/exchange/cWithdraw.d.ts.map +1 -1
- package/script/src/api/exchange/cWithdraw.js +15 -7
- package/script/src/api/exchange/cWithdraw.js.map +1 -1
- package/script/src/api/exchange/cancel.d.ts.map +1 -1
- package/script/src/api/exchange/cancel.js +16 -10
- package/script/src/api/exchange/cancel.js.map +1 -1
- package/script/src/api/exchange/cancelByCloid.d.ts.map +1 -1
- package/script/src/api/exchange/cancelByCloid.js +16 -10
- package/script/src/api/exchange/cancelByCloid.js.map +1 -1
- package/script/src/api/exchange/claimRewards.d.ts.map +1 -1
- package/script/src/api/exchange/claimRewards.js +14 -7
- package/script/src/api/exchange/claimRewards.js.map +1 -1
- package/script/src/api/exchange/convertToMultiSigUser.d.ts.map +1 -1
- package/script/src/api/exchange/convertToMultiSigUser.js +15 -7
- package/script/src/api/exchange/convertToMultiSigUser.js.map +1 -1
- package/script/src/api/exchange/createSubAccount.d.ts.map +1 -1
- package/script/src/api/exchange/createSubAccount.js +15 -8
- package/script/src/api/exchange/createSubAccount.js.map +1 -1
- package/script/src/api/exchange/createVault.d.ts.map +1 -1
- package/script/src/api/exchange/createVault.js +15 -8
- package/script/src/api/exchange/createVault.js.map +1 -1
- package/script/src/api/exchange/evmUserModify.d.ts +1 -1
- package/script/src/api/exchange/evmUserModify.d.ts.map +1 -1
- package/script/src/api/exchange/evmUserModify.js +16 -9
- package/script/src/api/exchange/evmUserModify.js.map +1 -1
- package/script/src/api/exchange/linkStakingUser.d.ts +112 -0
- package/script/src/api/exchange/linkStakingUser.d.ts.map +1 -0
- package/script/src/api/exchange/linkStakingUser.js +136 -0
- package/script/src/api/exchange/linkStakingUser.js.map +1 -0
- package/script/src/api/exchange/modify.d.ts.map +1 -1
- package/script/src/api/exchange/modify.js +16 -10
- package/script/src/api/exchange/modify.js.map +1 -1
- package/script/src/api/exchange/multiSig.d.ts.map +1 -1
- package/script/src/api/exchange/multiSig.js +17 -16
- package/script/src/api/exchange/multiSig.js.map +1 -1
- package/script/src/api/exchange/noop.d.ts.map +1 -1
- package/script/src/api/exchange/noop.js +14 -7
- package/script/src/api/exchange/noop.js.map +1 -1
- package/script/src/api/exchange/order.d.ts.map +1 -1
- package/script/src/api/exchange/order.js +16 -10
- package/script/src/api/exchange/order.js.map +1 -1
- package/script/src/api/exchange/perpDeploy.d.ts.map +1 -1
- package/script/src/api/exchange/perpDeploy.js +15 -8
- package/script/src/api/exchange/perpDeploy.js.map +1 -1
- package/script/src/api/exchange/registerReferrer.d.ts.map +1 -1
- package/script/src/api/exchange/registerReferrer.js +15 -8
- package/script/src/api/exchange/registerReferrer.js.map +1 -1
- package/script/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
- package/script/src/api/exchange/reserveRequestWeight.js +15 -8
- package/script/src/api/exchange/reserveRequestWeight.js.map +1 -1
- package/script/src/api/exchange/scheduleCancel.js +16 -10
- package/script/src/api/exchange/scheduleCancel.js.map +1 -1
- package/script/src/api/exchange/sendAsset.d.ts.map +1 -1
- package/script/src/api/exchange/sendAsset.js +15 -7
- package/script/src/api/exchange/sendAsset.js.map +1 -1
- package/script/src/api/exchange/setDisplayName.d.ts.map +1 -1
- package/script/src/api/exchange/setDisplayName.js +15 -8
- package/script/src/api/exchange/setDisplayName.js.map +1 -1
- package/script/src/api/exchange/setReferrer.d.ts.map +1 -1
- package/script/src/api/exchange/setReferrer.js +15 -8
- package/script/src/api/exchange/setReferrer.js.map +1 -1
- package/script/src/api/exchange/spotDeploy.d.ts.map +1 -1
- package/script/src/api/exchange/spotDeploy.js +15 -8
- package/script/src/api/exchange/spotDeploy.js.map +1 -1
- package/script/src/api/exchange/spotSend.d.ts.map +1 -1
- package/script/src/api/exchange/spotSend.js +15 -7
- package/script/src/api/exchange/spotSend.js.map +1 -1
- package/script/src/api/exchange/spotUser.d.ts.map +1 -1
- package/script/src/api/exchange/spotUser.js +15 -8
- package/script/src/api/exchange/spotUser.js.map +1 -1
- package/script/src/api/exchange/subAccountModify.d.ts.map +1 -1
- package/script/src/api/exchange/subAccountModify.js +15 -8
- package/script/src/api/exchange/subAccountModify.js.map +1 -1
- package/script/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
- package/script/src/api/exchange/subAccountSpotTransfer.js +15 -8
- package/script/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
- package/script/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
- package/script/src/api/exchange/subAccountTransfer.js +15 -8
- package/script/src/api/exchange/subAccountTransfer.js.map +1 -1
- package/script/src/api/exchange/tokenDelegate.d.ts.map +1 -1
- package/script/src/api/exchange/tokenDelegate.js +15 -7
- package/script/src/api/exchange/tokenDelegate.js.map +1 -1
- package/script/src/api/exchange/twapCancel.d.ts.map +1 -1
- package/script/src/api/exchange/twapCancel.js +16 -10
- package/script/src/api/exchange/twapCancel.js.map +1 -1
- package/script/src/api/exchange/twapOrder.d.ts.map +1 -1
- package/script/src/api/exchange/twapOrder.js +16 -10
- package/script/src/api/exchange/twapOrder.js.map +1 -1
- package/script/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
- package/script/src/api/exchange/updateIsolatedMargin.js +16 -10
- package/script/src/api/exchange/updateIsolatedMargin.js.map +1 -1
- package/script/src/api/exchange/updateLeverage.d.ts.map +1 -1
- package/script/src/api/exchange/updateLeverage.js +16 -10
- package/script/src/api/exchange/updateLeverage.js.map +1 -1
- package/script/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
- package/script/src/api/exchange/usdClassTransfer.js +15 -7
- package/script/src/api/exchange/usdClassTransfer.js.map +1 -1
- package/script/src/api/exchange/usdSend.d.ts.map +1 -1
- package/script/src/api/exchange/usdSend.js +15 -7
- package/script/src/api/exchange/usdSend.js.map +1 -1
- package/script/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
- package/script/src/api/exchange/userDexAbstraction.js +15 -7
- package/script/src/api/exchange/userDexAbstraction.js.map +1 -1
- package/script/src/api/exchange/vaultDistribute.d.ts.map +1 -1
- package/script/src/api/exchange/vaultDistribute.js +15 -8
- package/script/src/api/exchange/vaultDistribute.js.map +1 -1
- package/script/src/api/exchange/vaultModify.d.ts.map +1 -1
- package/script/src/api/exchange/vaultModify.js +15 -8
- package/script/src/api/exchange/vaultModify.js.map +1 -1
- package/script/src/api/exchange/vaultTransfer.d.ts.map +1 -1
- package/script/src/api/exchange/vaultTransfer.js +15 -8
- package/script/src/api/exchange/vaultTransfer.js.map +1 -1
- package/script/src/api/exchange/withdraw3.d.ts.map +1 -1
- package/script/src/api/exchange/withdraw3.js +15 -7
- package/script/src/api/exchange/withdraw3.js.map +1 -1
- package/script/src/api/exchange/~client.d.ts +31 -3
- package/script/src/api/exchange/~client.d.ts.map +1 -1
- package/script/src/api/exchange/~client.js +29 -6
- package/script/src/api/exchange/~client.js.map +1 -1
- package/script/src/api/exchange/~mod.d.ts +1 -0
- package/script/src/api/exchange/~mod.d.ts.map +1 -1
- package/script/src/api/exchange/~mod.js +1 -0
- package/script/src/api/exchange/~mod.js.map +1 -1
- package/script/src/api/info/allPerpMetas.d.ts +5 -0
- package/script/src/api/info/allPerpMetas.d.ts.map +1 -1
- package/script/src/api/info/meta.d.ts +5 -0
- package/script/src/api/info/meta.d.ts.map +1 -1
- package/script/src/api/info/meta.js +2 -0
- package/script/src/api/info/meta.js.map +1 -1
- package/script/src/api/info/metaAndAssetCtxs.d.ts +5 -0
- package/script/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
- package/script/src/api/info/perpDexs.d.ts +4 -0
- package/script/src/api/info/perpDexs.d.ts.map +1 -1
- package/script/src/api/info/perpDexs.js +5 -0
- package/script/src/api/info/perpDexs.js.map +1 -1
- package/script/src/api/info/spotClearinghouseState.d.ts +0 -5
- package/script/src/api/info/spotClearinghouseState.d.ts.map +1 -1
- package/script/src/api/info/spotClearinghouseState.js +2 -14
- package/script/src/api/info/spotClearinghouseState.js.map +1 -1
- package/script/src/api/info/userFees.d.ts +27 -2
- package/script/src/api/info/userFees.d.ts.map +1 -1
- package/script/src/api/info/userFees.js +29 -1
- package/script/src/api/info/userFees.js.map +1 -1
- package/script/src/api/info/webData2.d.ts +152 -23
- package/script/src/api/info/webData2.d.ts.map +1 -1
- package/script/src/api/info/webData2.js +2 -53
- package/script/src/api/info/webData2.js.map +1 -1
- package/script/src/api/info/~client.d.ts +11 -3
- package/script/src/api/info/~client.d.ts.map +1 -1
- package/script/src/api/subscription/spotState.d.ts +91 -0
- package/script/src/api/subscription/spotState.d.ts.map +1 -0
- package/script/src/api/subscription/spotState.js +95 -0
- package/script/src/api/subscription/spotState.js.map +1 -0
- package/script/src/api/subscription/webData2.d.ts +9 -4
- package/script/src/api/subscription/webData2.d.ts.map +1 -1
- package/script/src/api/subscription/webData2.js +1 -1
- package/script/src/api/subscription/webData2.js.map +1 -1
- package/script/src/api/subscription/webData3.d.ts +541 -0
- package/script/src/api/subscription/webData3.d.ts.map +1 -0
- package/script/src/api/subscription/webData3.js +131 -0
- package/script/src/api/subscription/webData3.js.map +1 -0
- package/script/src/api/subscription/~client.d.ts +44 -0
- package/script/src/api/subscription/~client.d.ts.map +1 -1
- package/script/src/api/subscription/~client.js +46 -0
- package/script/src/api/subscription/~client.js.map +1 -1
- package/script/src/api/subscription/~mod.d.ts +2 -0
- package/script/src/api/subscription/~mod.d.ts.map +1 -1
- package/script/src/api/subscription/~mod.js +2 -0
- package/script/src/api/subscription/~mod.js.map +1 -1
- package/script/src/signing/_signTypedData.d.ts +1 -1
- package/script/src/signing/_signTypedData.d.ts.map +1 -1
- package/script/src/signing/_signTypedData.js +1 -1
- package/script/src/signing/_signTypedData.js.map +1 -1
- package/script/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
- package/script/src/utils/_eip712.d.ts.map +1 -0
- package/script/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -9
- package/script/src/utils/_eip712.js.map +1 -0
- package/script/src/utils/_format.d.ts +28 -0
- package/script/src/utils/_format.d.ts.map +1 -0
- package/script/src/utils/_format.js +161 -0
- package/script/src/utils/_format.js.map +1 -0
- package/script/src/utils/_recover.d.ts +89 -0
- package/script/src/utils/_recover.d.ts.map +1 -0
- package/script/src/utils/_recover.js +156 -0
- package/script/src/utils/_recover.js.map +1 -0
- package/script/src/utils/_symbolConverter.d.ts +13 -0
- package/script/src/utils/_symbolConverter.d.ts.map +1 -1
- package/script/src/utils/_symbolConverter.js +17 -0
- package/script/src/utils/_symbolConverter.js.map +1 -1
- package/script/src/utils/mod.d.ts +2 -0
- package/script/src/utils/mod.d.ts.map +1 -1
- package/script/src/utils/mod.js +2 -0
- package/script/src/utils/mod.js.map +1 -1
- package/src/bin/cli.ts +1 -0
- package/src/src/api/_common_schemas.ts +34 -0
- package/src/src/api/exchange/_base/_execute.ts +73 -49
- package/src/src/api/exchange/_base/_types.ts +0 -7
- package/src/src/api/exchange/_base/mod.ts +0 -2
- package/src/src/api/exchange/agentEnableDexAbstraction.ts +14 -9
- package/src/src/api/exchange/approveAgent.ts +15 -12
- package/src/src/api/exchange/approveBuilderFee.ts +15 -12
- package/src/src/api/exchange/batchModify.ts +16 -13
- package/src/src/api/exchange/cDeposit.ts +15 -12
- package/src/src/api/exchange/cSignerAction.ts +15 -10
- package/src/src/api/exchange/cValidatorAction.ts +15 -10
- package/src/src/api/exchange/cWithdraw.ts +15 -12
- package/src/src/api/exchange/cancel.ts +16 -13
- package/src/src/api/exchange/cancelByCloid.ts +16 -13
- package/src/src/api/exchange/claimRewards.ts +14 -9
- package/src/src/api/exchange/convertToMultiSigUser.ts +15 -12
- package/src/src/api/exchange/createSubAccount.ts +15 -10
- package/src/src/api/exchange/createVault.ts +15 -10
- package/src/src/api/exchange/evmUserModify.ts +16 -11
- package/src/src/api/exchange/linkStakingUser.ts +157 -0
- package/src/src/api/exchange/modify.ts +16 -13
- package/src/src/api/exchange/multiSig.ts +17 -23
- package/src/src/api/exchange/noop.ts +14 -9
- package/src/src/api/exchange/order.ts +16 -13
- package/src/src/api/exchange/perpDeploy.ts +15 -10
- package/src/src/api/exchange/registerReferrer.ts +15 -10
- package/src/src/api/exchange/reserveRequestWeight.ts +15 -10
- package/src/src/api/exchange/scheduleCancel.ts +16 -13
- package/src/src/api/exchange/sendAsset.ts +15 -12
- package/src/src/api/exchange/setDisplayName.ts +15 -10
- package/src/src/api/exchange/setReferrer.ts +15 -10
- package/src/src/api/exchange/spotDeploy.ts +15 -10
- package/src/src/api/exchange/spotSend.ts +15 -12
- package/src/src/api/exchange/spotUser.ts +15 -10
- package/src/src/api/exchange/subAccountModify.ts +15 -10
- package/src/src/api/exchange/subAccountSpotTransfer.ts +15 -10
- package/src/src/api/exchange/subAccountTransfer.ts +15 -10
- package/src/src/api/exchange/tokenDelegate.ts +15 -12
- package/src/src/api/exchange/twapCancel.ts +16 -13
- package/src/src/api/exchange/twapOrder.ts +16 -13
- package/src/src/api/exchange/updateIsolatedMargin.ts +16 -13
- package/src/src/api/exchange/updateLeverage.ts +16 -13
- package/src/src/api/exchange/usdClassTransfer.ts +15 -12
- package/src/src/api/exchange/usdSend.ts +15 -12
- package/src/src/api/exchange/userDexAbstraction.ts +15 -12
- package/src/src/api/exchange/vaultDistribute.ts +15 -10
- package/src/src/api/exchange/vaultModify.ts +15 -10
- package/src/src/api/exchange/vaultTransfer.ts +15 -10
- package/src/src/api/exchange/withdraw3.ts +15 -12
- package/src/src/api/exchange/~client.ts +30 -5
- package/src/src/api/exchange/~mod.ts +1 -0
- package/src/src/api/info/meta.ts +7 -0
- package/src/src/api/info/perpDexs.ts +10 -0
- package/src/src/api/info/spotClearinghouseState.ts +3 -33
- package/src/src/api/info/userFees.ts +46 -1
- package/src/src/api/info/webData2.ts +3 -104
- package/src/src/api/subscription/spotState.ts +96 -0
- package/src/src/api/subscription/webData2.ts +1 -1
- package/src/src/api/subscription/webData3.ts +179 -0
- package/src/src/api/subscription/~client.ts +50 -0
- package/src/src/api/subscription/~mod.ts +2 -0
- package/src/src/signing/_signTypedData.ts +1 -1
- package/src/src/utils/{_minimalEIP712Signer.ts → _eip712.ts} +22 -29
- package/src/src/utils/_format.ts +173 -0
- package/src/src/utils/_recover.ts +178 -0
- package/src/src/utils/_symbolConverter.ts +18 -0
- package/src/src/utils/mod.ts +2 -0
- package/esm/src/api/exchange/_base/_sequential.d.ts +0 -30
- package/esm/src/api/exchange/_base/_sequential.d.ts.map +0 -1
- package/esm/src/api/exchange/_base/_sequential.js +0 -69
- package/esm/src/api/exchange/_base/_sequential.js.map +0 -1
- package/esm/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
- package/esm/src/utils/_minimalEIP712Signer.js.map +0 -1
- package/script/src/api/exchange/_base/_sequential.d.ts +0 -30
- package/script/src/api/exchange/_base/_sequential.d.ts.map +0 -1
- package/script/src/api/exchange/_base/_sequential.js +0 -72
- package/script/src/api/exchange/_base/_sequential.js.map +0 -1
- package/script/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
- package/script/src/utils/_minimalEIP712Signer.js.map +0 -1
- package/src/src/api/exchange/_base/_sequential.ts +0 -82
|
@@ -16,6 +16,7 @@ import { l2Book } from "./l2Book.js";
|
|
|
16
16
|
import { notification } from "./notification.js";
|
|
17
17
|
import { openOrders } from "./openOrders.js";
|
|
18
18
|
import { orderUpdates } from "./orderUpdates.js";
|
|
19
|
+
import { spotState } from "./spotState.js";
|
|
19
20
|
import { trades } from "./trades.js";
|
|
20
21
|
import { userEvents } from "./userEvents.js";
|
|
21
22
|
import { userFills } from "./userFills.js";
|
|
@@ -25,6 +26,7 @@ import { userNonFundingLedgerUpdates } from "./userNonFundingLedgerUpdates.js";
|
|
|
25
26
|
import { userTwapHistory } from "./userTwapHistory.js";
|
|
26
27
|
import { userTwapSliceFills } from "./userTwapSliceFills.js";
|
|
27
28
|
import { webData2 } from "./webData2.js";
|
|
29
|
+
import { webData3 } from "./webData3.js";
|
|
28
30
|
|
|
29
31
|
export type {
|
|
30
32
|
ActiveAssetCtxEvent as WsActiveAssetCtxEvent,
|
|
@@ -67,6 +69,7 @@ export type {
|
|
|
67
69
|
OrderUpdatesEvent as WsOrderUpdatesEvent,
|
|
68
70
|
OrderUpdatesParameters as WsOrderUpdatesParameters,
|
|
69
71
|
} from "./orderUpdates.js";
|
|
72
|
+
export type { SpotStateEvent as WsSpotStateEvent, SpotStateParameters as WsSpotStateParameters } from "./spotState.js";
|
|
70
73
|
export type { TradesEvent as WsTradesEvent, TradesParameters as WsTradesParameters } from "./trades.js";
|
|
71
74
|
export type {
|
|
72
75
|
UserEventsEvent as WsUserEventsEvent,
|
|
@@ -94,6 +97,7 @@ export type {
|
|
|
94
97
|
UserTwapSliceFillsParameters as WsUserTwapSliceFillsParameters,
|
|
95
98
|
} from "./userTwapSliceFills.js";
|
|
96
99
|
export type { WebData2Event as WsWebData2Event, WebData2Parameters as WsWebData2Parameters } from "./webData2.js";
|
|
100
|
+
export type { WebData3Event as WsWebData3Event, WebData3Parameters as WsWebData3Parameters } from "./webData3.js";
|
|
97
101
|
|
|
98
102
|
export type { SubscriptionRequestConfig } from "./_types.js";
|
|
99
103
|
|
|
@@ -452,6 +456,29 @@ export class SubscriptionClient<
|
|
|
452
456
|
return orderUpdates(this, ...args);
|
|
453
457
|
}
|
|
454
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Subscribe to spot state updates for a specific user.
|
|
461
|
+
* @param params - Parameters specific to the API subscription.
|
|
462
|
+
* @param listener - A callback function to be called when the event is received.
|
|
463
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
464
|
+
*
|
|
465
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
466
|
+
*
|
|
467
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
471
|
+
*
|
|
472
|
+
* const transport = new hl.WebSocketTransport();
|
|
473
|
+
*
|
|
474
|
+
* const client = new hl.SubscriptionClient({ transport });
|
|
475
|
+
* const sub = await client.spotState({ user: "0x..." }, (data) => console.log(data));
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
spotState(...args: OmitFirst<OverloadedParameters<typeof spotState>>) {
|
|
479
|
+
return spotState(this, ...args);
|
|
480
|
+
}
|
|
481
|
+
|
|
455
482
|
/**
|
|
456
483
|
* Subscribe to real-time trade updates for a specific asset.
|
|
457
484
|
* @param params - Parameters specific to the API subscription.
|
|
@@ -660,4 +687,27 @@ export class SubscriptionClient<
|
|
|
660
687
|
webData2(...args: OmitFirst<OverloadedParameters<typeof webData2>>) {
|
|
661
688
|
return webData2(this, ...args);
|
|
662
689
|
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Subscribe to comprehensive user and market data updates.
|
|
693
|
+
* @param params - Parameters specific to the API subscription.
|
|
694
|
+
* @param listener - A callback function to be called when the event is received.
|
|
695
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
696
|
+
*
|
|
697
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
698
|
+
*
|
|
699
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
700
|
+
* @example
|
|
701
|
+
* ```ts
|
|
702
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
703
|
+
*
|
|
704
|
+
* const transport = new hl.WebSocketTransport();
|
|
705
|
+
*
|
|
706
|
+
* const client = new hl.SubscriptionClient({ transport });
|
|
707
|
+
* const sub = await client.webData3({ user: "0x..." }, (data) => console.log(data));
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
webData3(...args: OmitFirst<OverloadedParameters<typeof webData3>>) {
|
|
711
|
+
return webData3(this, ...args);
|
|
712
|
+
}
|
|
663
713
|
}
|
|
@@ -40,6 +40,7 @@ export * from "./l2Book.js";
|
|
|
40
40
|
export * from "./notification.js";
|
|
41
41
|
export * from "./openOrders.js";
|
|
42
42
|
export * from "./orderUpdates.js";
|
|
43
|
+
export * from "./spotState.js";
|
|
43
44
|
export * from "./trades.js";
|
|
44
45
|
export * from "./userEvents.js";
|
|
45
46
|
export * from "./userFills.js";
|
|
@@ -49,3 +50,4 @@ export * from "./userNonFundingLedgerUpdates.js";
|
|
|
49
50
|
export * from "./userTwapHistory.js";
|
|
50
51
|
export * from "./userTwapSliceFills.js";
|
|
51
52
|
export * from "./webData2.js";
|
|
53
|
+
export * from "./webData3.js";
|
|
@@ -218,7 +218,7 @@ export async function getWalletChainId(wallet: AbstractWallet): Promise<`0x${str
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
/** Get the wallet address from various wallet types. */
|
|
221
|
+
/** Get the lowercase wallet address from various wallet types. */
|
|
222
222
|
export async function getWalletAddress(wallet: AbstractWallet): Promise<`0x${string}`> {
|
|
223
223
|
if (isAbstractViemWallet(wallet)) {
|
|
224
224
|
if ("address" in wallet && wallet.address) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// -------------------- EIP-712 --------------------
|
|
2
|
-
|
|
3
1
|
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
4
2
|
import * as secp from "@noble/secp256k1";
|
|
5
3
|
|
|
@@ -19,7 +17,7 @@ export interface Domain {
|
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/** Signs typed data with a private key. */
|
|
22
|
-
async function signTypedData(args: {
|
|
20
|
+
export async function signTypedData(args: {
|
|
23
21
|
privateKey: string | Uint8Array;
|
|
24
22
|
domain?: Domain;
|
|
25
23
|
types: Types;
|
|
@@ -36,20 +34,18 @@ async function signTypedData(args: {
|
|
|
36
34
|
|
|
37
35
|
const hash = hashTypedData({ domain, types, primaryType, message });
|
|
38
36
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
privateKey instanceof Uint8Array ? privateKey : secp.etc.hexToBytes(cleanHex(privateKey)),
|
|
42
|
-
{ prehash: false, format: "recovered" },
|
|
43
|
-
);
|
|
37
|
+
const pk = typeof privateKey === "string" ? secp.etc.hexToBytes(cleanHex(privateKey)) : privateKey;
|
|
38
|
+
const sigr = await secp.signAsync(hash, pk, { prehash: false, format: "recovered" });
|
|
44
39
|
|
|
45
|
-
const r = secp.etc.bytesToHex(
|
|
46
|
-
const s = secp.etc.bytesToHex(
|
|
47
|
-
const v = (
|
|
40
|
+
const r = secp.etc.bytesToHex(sigr.slice(1, 33));
|
|
41
|
+
const s = secp.etc.bytesToHex(sigr.slice(33, 65));
|
|
42
|
+
const v = (sigr[0] + 27).toString(16).padStart(2, "0");
|
|
48
43
|
|
|
49
44
|
return `0x${r}${s}${v}`;
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
/** Hashes typed data according to EIP-712. */
|
|
48
|
+
export function hashTypedData(args: {
|
|
53
49
|
domain: Domain;
|
|
54
50
|
types: Types;
|
|
55
51
|
primaryType: string;
|
|
@@ -211,7 +207,7 @@ function cleanHex(hex: string): string {
|
|
|
211
207
|
return hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
212
208
|
}
|
|
213
209
|
|
|
214
|
-
// --------------------
|
|
210
|
+
// -------------------- For SDK --------------------
|
|
215
211
|
|
|
216
212
|
import type { AbstractViemLocalAccount } from "../signing/mod.js";
|
|
217
213
|
|
|
@@ -221,30 +217,27 @@ export class PrivateKeyEIP712Signer implements AbstractViemLocalAccount {
|
|
|
221
217
|
address: `0x${string}`;
|
|
222
218
|
constructor(privateKey: string | Uint8Array) {
|
|
223
219
|
this.#privateKey = privateKey;
|
|
224
|
-
this.address = privateKeyToAddress(privateKey); // and validate the key
|
|
225
|
-
}
|
|
226
|
-
signTypedData(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
},
|
|
233
|
-
): Promise<`0x${string}`> {
|
|
220
|
+
this.address = privateKeyToAddress(privateKey); // and validate the private key
|
|
221
|
+
}
|
|
222
|
+
signTypedData(params: {
|
|
223
|
+
domain: Domain;
|
|
224
|
+
types: Types;
|
|
225
|
+
primaryType: string;
|
|
226
|
+
message: Record<string, unknown>;
|
|
227
|
+
}): Promise<`0x${string}`> {
|
|
234
228
|
return signTypedData({ privateKey: this.#privateKey, ...params });
|
|
235
229
|
}
|
|
236
230
|
}
|
|
237
231
|
|
|
238
232
|
function privateKeyToAddress(privateKey: string | Uint8Array): `0x${string}` {
|
|
239
233
|
const pk = typeof privateKey === "string" ? secp.etc.hexToBytes(cleanHex(privateKey)) : privateKey;
|
|
240
|
-
|
|
241
234
|
const publicKey = secp.getPublicKey(pk, false);
|
|
242
|
-
|
|
235
|
+
return publicKeyToAddress(publicKey);
|
|
236
|
+
}
|
|
243
237
|
|
|
238
|
+
function publicKeyToAddress(publicKey: Uint8Array): `0x${string}` {
|
|
239
|
+
const publicKeyWithoutPrefix = publicKey.slice(1);
|
|
244
240
|
const hash = keccak_256(publicKeyWithoutPrefix);
|
|
245
|
-
|
|
246
241
|
const addressBytes = hash.slice(-20);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return `0x${address}`;
|
|
242
|
+
return `0x${secp.etc.bytesToHex(addressBytes)}`;
|
|
250
243
|
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format price according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
|
|
3
|
+
* - Maximum 5 significant figures
|
|
4
|
+
* - Maximum 6 (for perp) or 8 (for spot) - `szDecimals` decimal places
|
|
5
|
+
* - Integer prices are always allowed regardless of significant figures
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { formatPrice } from "@nktkas/hyperliquid/utils";
|
|
9
|
+
*
|
|
10
|
+
* // `true` for perp (default), `false` for spot
|
|
11
|
+
* // ⌄⌄⌄⌄⌄
|
|
12
|
+
* const price = formatPrice("0.0000123456789", 0, false); // → "0.00001234"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function formatPrice(price: string | number, szDecimals: number, isPerp: boolean = true): string {
|
|
16
|
+
price = price.toString().trim();
|
|
17
|
+
assertNumberString(price);
|
|
18
|
+
|
|
19
|
+
// Integer prices are always allowed
|
|
20
|
+
if (/^-?\d+$/.test(price)) return trimZeros(price);
|
|
21
|
+
|
|
22
|
+
// Apply decimal limit: max 6 (perp) or 8 (spot) - szDecimals
|
|
23
|
+
const maxDecimals = Math.max((isPerp ? 6 : 8) - szDecimals, 0);
|
|
24
|
+
price = StringMath.toFixedTruncate(price, maxDecimals);
|
|
25
|
+
|
|
26
|
+
// Apply sig figs limit: max 5 significant figures
|
|
27
|
+
price = StringMath.toPrecisionTruncate(price, 5);
|
|
28
|
+
|
|
29
|
+
return price;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Format size according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
|
|
34
|
+
* - Truncate decimal places to `szDecimals`
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { formatSize } from "@nktkas/hyperliquid/utils";
|
|
38
|
+
*
|
|
39
|
+
* const size = formatSize("1.23456789", 5); // → "1.23456"
|
|
40
|
+
* ```
|
|
41
|
+
* @note May return 0 if the value is not suitable, but when closing a position, a size of 0 means the full size.
|
|
42
|
+
*/
|
|
43
|
+
export function formatSize(size: string | number, szDecimals: number): string {
|
|
44
|
+
size = size.toString().trim();
|
|
45
|
+
assertNumberString(size);
|
|
46
|
+
|
|
47
|
+
// Apply decimal limit: szDecimals
|
|
48
|
+
size = StringMath.toFixedTruncate(size, szDecimals);
|
|
49
|
+
|
|
50
|
+
return size;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** String-based Math operations for arbitrary precision */
|
|
54
|
+
const StringMath = {
|
|
55
|
+
/** Floor log10 (magnitude): position of most significant digit */
|
|
56
|
+
log10Floor(value: string): number {
|
|
57
|
+
const abs = value[0] === "-" ? value.slice(1) : value;
|
|
58
|
+
|
|
59
|
+
// Check if zero or invalid
|
|
60
|
+
const num = Number(abs);
|
|
61
|
+
if (num === 0 || isNaN(num)) return -Infinity;
|
|
62
|
+
|
|
63
|
+
const [int, dec] = abs.split(".");
|
|
64
|
+
|
|
65
|
+
// Number >= 1: magnitude = length of integer part - 1
|
|
66
|
+
if (Number(int) !== 0) {
|
|
67
|
+
const trimmed = int.replace(/^0+/, "");
|
|
68
|
+
return trimmed.length - 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Number < 1: count leading zeros in decimal part
|
|
72
|
+
const leadingZeros = dec.match(/^0*/)?.[0].length ?? 0;
|
|
73
|
+
return -(leadingZeros + 1);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
/** Multiply by 10^exp: shift decimal point left (negative) or right (positive) */
|
|
77
|
+
multiplyByPow10(value: string, exp: number): string {
|
|
78
|
+
if (!Number.isInteger(exp)) throw new RangeError("Exponent must be an integer");
|
|
79
|
+
if (exp === 0) return trimZeros(value);
|
|
80
|
+
|
|
81
|
+
const neg = value[0] === "-";
|
|
82
|
+
const abs = neg ? value.slice(1) : value;
|
|
83
|
+
const [intRaw, dec = ""] = abs.split(".");
|
|
84
|
+
// Normalize empty integer part to "0" (handles ".5" → "0.5")
|
|
85
|
+
const int = intRaw || "0";
|
|
86
|
+
|
|
87
|
+
let result: string;
|
|
88
|
+
|
|
89
|
+
if (exp > 0) {
|
|
90
|
+
// Shift right: move digits from decimal to integer
|
|
91
|
+
if (exp >= dec.length) {
|
|
92
|
+
result = int + dec + "0".repeat(exp - dec.length);
|
|
93
|
+
} else {
|
|
94
|
+
result = int + dec.slice(0, exp) + "." + dec.slice(exp);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
// Shift left: move digits from integer to decimal
|
|
98
|
+
const absExp = -exp;
|
|
99
|
+
if (absExp >= int.length) {
|
|
100
|
+
result = "0." + "0".repeat(absExp - int.length) + int + dec;
|
|
101
|
+
} else {
|
|
102
|
+
result = int.slice(0, -absExp) + "." + int.slice(-absExp) + dec;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return trimZeros((neg ? "-" : "") + result);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/** Returns the integer part of a number by removing any fractional digits */
|
|
110
|
+
trunc(value: string): string {
|
|
111
|
+
const dotIndex = value.indexOf(".");
|
|
112
|
+
return dotIndex === -1 ? value : value.slice(0, dotIndex) || "0";
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/** Truncate to a certain number of significant figures */
|
|
116
|
+
toPrecisionTruncate(value: string, precision: number): string {
|
|
117
|
+
if (!Number.isInteger(precision)) throw new RangeError("Precision must be an integer");
|
|
118
|
+
if (precision < 1) throw new RangeError("Precision must be positive");
|
|
119
|
+
if (/^-?0+(\.0*)?$/.test(value)) return "0"; // zero is special case (don't work with log10)
|
|
120
|
+
|
|
121
|
+
const neg = value[0] === "-";
|
|
122
|
+
const abs = neg ? value.slice(1) : value;
|
|
123
|
+
|
|
124
|
+
// Calculate how much to shift: align most significant digit to ones place + (maxSigFigs-1)
|
|
125
|
+
const magnitude = StringMath.log10Floor(abs);
|
|
126
|
+
const shiftAmount = precision - magnitude - 1;
|
|
127
|
+
|
|
128
|
+
// Shift right, truncate integer part, shift back
|
|
129
|
+
const shifted = StringMath.multiplyByPow10(abs, shiftAmount);
|
|
130
|
+
const truncated = StringMath.trunc(shifted);
|
|
131
|
+
const result = StringMath.multiplyByPow10(truncated, -shiftAmount);
|
|
132
|
+
|
|
133
|
+
// build final result and trim zeros
|
|
134
|
+
return trimZeros(neg ? "-" + result : result);
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/** Truncate to a certain number of decimal places */
|
|
138
|
+
toFixedTruncate(value: string, decimals: number): string {
|
|
139
|
+
if (!Number.isInteger(decimals)) throw new RangeError("Decimals must be an integer");
|
|
140
|
+
if (decimals < 0) throw new RangeError("Decimals must be non-negative");
|
|
141
|
+
|
|
142
|
+
// Match number with up to `decimals` decimal places
|
|
143
|
+
const regex = new RegExp(`^-?(?:\\d+)?(?:\\.\\d{0,${decimals}})?`);
|
|
144
|
+
const result = value.match(regex)?.[0];
|
|
145
|
+
|
|
146
|
+
if (!result) {
|
|
147
|
+
throw new TypeError("Invalid number format");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Trim zeros after truncation
|
|
151
|
+
return trimZeros(result);
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
function trimZeros(value: string): string {
|
|
156
|
+
return value
|
|
157
|
+
// remove leading zeros
|
|
158
|
+
.replace(/^(-?)0+(?=\d)/, "$1") // "00123" → "123", "-00.5" → "-0.5"
|
|
159
|
+
// remove trailing zeros
|
|
160
|
+
.replace(/\.0*$|(\.\d+?)0+$/, "$1") // "1.2000" → "1.2", "5.0" → "5"
|
|
161
|
+
// add leading zero if starts with decimal point
|
|
162
|
+
.replace(/^(-?)\./, "$10.") // ".5" → "0.5", "-.5" → "-0.5"
|
|
163
|
+
// add "0" if string is empty after trimming
|
|
164
|
+
.replace(/^-?$/, "0") // "" → "0", "-" → "0"
|
|
165
|
+
// normalize negative zero
|
|
166
|
+
.replace(/^-0$/, "0"); // "-0" → "0"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function assertNumberString(value: string): void {
|
|
170
|
+
if (!/^-?(\d+\.?\d*|\.\d*)$/.test(value)) {
|
|
171
|
+
throw new TypeError("Invalid number format");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
2
|
+
import * as secp from "@noble/secp256k1";
|
|
3
|
+
import { createL1ActionHash, type Signature } from "../signing/mod.js";
|
|
4
|
+
import { hashTypedData } from "./_eip712.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recover the Ethereum address that signed an L1 action.
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { recoverUserFromL1Action } from "@nktkas/hyperliquid/utils";
|
|
11
|
+
*
|
|
12
|
+
* const action = {
|
|
13
|
+
* type: "cancel",
|
|
14
|
+
* cancels: [{ a: 0, o: 12345 }],
|
|
15
|
+
* };
|
|
16
|
+
* const nonce = 1700000000000;
|
|
17
|
+
* const signature = {
|
|
18
|
+
* r: "0x...",
|
|
19
|
+
* s: "0x...",
|
|
20
|
+
* v: 27,
|
|
21
|
+
* } as const;
|
|
22
|
+
*
|
|
23
|
+
* const address = await recoverUserFromL1Action({ action, nonce, signature });
|
|
24
|
+
* console.log(`Signer address: ${address}`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export async function recoverUserFromL1Action(params: {
|
|
28
|
+
/** The action that was signed (hash depends on key order). */
|
|
29
|
+
action: Record<string, unknown>;
|
|
30
|
+
/** The timestamp in ms used when signing. */
|
|
31
|
+
nonce: number;
|
|
32
|
+
/** The signature to recover the address from. */
|
|
33
|
+
signature: Signature;
|
|
34
|
+
/** Indicates if the action is for the testnet. (default: false) */
|
|
35
|
+
isTestnet?: boolean;
|
|
36
|
+
/** Optional vault address used in the action. */
|
|
37
|
+
vaultAddress?: `0x${string}`;
|
|
38
|
+
/** Optional expiration time in ms used in the action. */
|
|
39
|
+
expiresAfter?: number;
|
|
40
|
+
}): Promise<`0x${string}`> {
|
|
41
|
+
const {
|
|
42
|
+
action,
|
|
43
|
+
signature,
|
|
44
|
+
nonce,
|
|
45
|
+
isTestnet = false,
|
|
46
|
+
vaultAddress,
|
|
47
|
+
expiresAfter,
|
|
48
|
+
} = params;
|
|
49
|
+
|
|
50
|
+
// 1. Create the action hash
|
|
51
|
+
const actionHash = createL1ActionHash({ action, nonce, vaultAddress, expiresAfter });
|
|
52
|
+
|
|
53
|
+
// 2. Hash the typed data according to EIP-712
|
|
54
|
+
const hash = hashTypedData({
|
|
55
|
+
domain: {
|
|
56
|
+
name: "Exchange",
|
|
57
|
+
version: "1",
|
|
58
|
+
chainId: 1337,
|
|
59
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
60
|
+
},
|
|
61
|
+
types: {
|
|
62
|
+
Agent: [
|
|
63
|
+
{ name: "source", type: "string" },
|
|
64
|
+
{ name: "connectionId", type: "bytes32" },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
primaryType: "Agent",
|
|
68
|
+
message: {
|
|
69
|
+
source: isTestnet ? "b" : "a",
|
|
70
|
+
connectionId: actionHash,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// 3. Convert signature to recovery format (v, r, s)
|
|
75
|
+
const sigr = secp.etc.concatBytes(
|
|
76
|
+
new Uint8Array([signature.v - 27]),
|
|
77
|
+
secp.etc.hexToBytes(signature.r.slice(2)),
|
|
78
|
+
secp.etc.hexToBytes(signature.s.slice(2)),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// 4. Recover the public key from the signature and hash
|
|
82
|
+
const compressedPubKey = await secp.recoverPublicKeyAsync(sigr, hash, { prehash: false });
|
|
83
|
+
const uncompressedPubKey = secp.Point.fromBytes(compressedPubKey).toBytes(false);
|
|
84
|
+
|
|
85
|
+
// 5. Convert the public key to an Ethereum address
|
|
86
|
+
return publicKeyToAddress(uncompressedPubKey);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Recover the Ethereum address that signed a user-signed action.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { recoverUserFromUserSigned } from "@nktkas/hyperliquid/utils";
|
|
94
|
+
*
|
|
95
|
+
* const action = {
|
|
96
|
+
* type: "approveAgent",
|
|
97
|
+
* signatureChainId: "0x66eee" as const,
|
|
98
|
+
* hyperliquidChain: "Mainnet",
|
|
99
|
+
* agentAddress: "0x...",
|
|
100
|
+
* agentName: "Agent",
|
|
101
|
+
* nonce: 1700000000000,
|
|
102
|
+
* };
|
|
103
|
+
* const types = {
|
|
104
|
+
* HyperliquidTransaction: [
|
|
105
|
+
* { name: "hyperliquidChain", type: "string" },
|
|
106
|
+
* // ... other fields
|
|
107
|
+
* ],
|
|
108
|
+
* };
|
|
109
|
+
* const signature = {
|
|
110
|
+
* r: "0x...",
|
|
111
|
+
* s: "0x...",
|
|
112
|
+
* v: 27,
|
|
113
|
+
* } as const;
|
|
114
|
+
*
|
|
115
|
+
* const address = await recoverUserFromUserSigned({ action, types, signature });
|
|
116
|
+
* console.log(`Signer address: ${address}`);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export async function recoverUserFromUserSigned(params: {
|
|
120
|
+
/** The action that was signed (hex strings must be in lower case). */
|
|
121
|
+
action:
|
|
122
|
+
& {
|
|
123
|
+
signatureChainId: `0x${string}`;
|
|
124
|
+
[key: string]: unknown;
|
|
125
|
+
}
|
|
126
|
+
& (
|
|
127
|
+
| { nonce: number; time?: undefined }
|
|
128
|
+
| { time: number; nonce?: undefined }
|
|
129
|
+
);
|
|
130
|
+
/** The types of the action (hash depends on key order). */
|
|
131
|
+
types: {
|
|
132
|
+
[key: string]: {
|
|
133
|
+
name: string;
|
|
134
|
+
type: string;
|
|
135
|
+
}[];
|
|
136
|
+
};
|
|
137
|
+
/** The signature to recover the address from. */
|
|
138
|
+
signature: Signature;
|
|
139
|
+
}): Promise<`0x${string}`> {
|
|
140
|
+
const { action, types, signature } = params;
|
|
141
|
+
|
|
142
|
+
// 1. Hash the typed data according to EIP-712
|
|
143
|
+
const hash = hashTypedData({
|
|
144
|
+
domain: {
|
|
145
|
+
name: "HyperliquidSignTransaction",
|
|
146
|
+
version: "1",
|
|
147
|
+
chainId: parseInt(action.signatureChainId),
|
|
148
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
149
|
+
},
|
|
150
|
+
types,
|
|
151
|
+
primaryType: Object.keys(types)[0],
|
|
152
|
+
message: action,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// 2. Convert signature to recovery format (v, r, s)
|
|
156
|
+
const sigr = secp.etc.concatBytes(
|
|
157
|
+
new Uint8Array([signature.v - 27]),
|
|
158
|
+
secp.etc.hexToBytes(signature.r.slice(2)),
|
|
159
|
+
secp.etc.hexToBytes(signature.s.slice(2)),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// 3. Recover the public key from the signature and hash
|
|
163
|
+
const compressedPubKey = await secp.recoverPublicKeyAsync(sigr, hash, { prehash: false });
|
|
164
|
+
const uncompressedPubKey = secp.Point.fromBytes(compressedPubKey).toBytes(false);
|
|
165
|
+
|
|
166
|
+
// 4. Convert the public key to an Ethereum address
|
|
167
|
+
return publicKeyToAddress(uncompressedPubKey);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Convert a public key to an Ethereum address. */
|
|
171
|
+
function publicKeyToAddress(publicKey: Uint8Array): `0x${string}` {
|
|
172
|
+
// Remove the 0x04 prefix from uncompressed public key
|
|
173
|
+
const publicKeyWithoutPrefix = publicKey.slice(1);
|
|
174
|
+
// Hash the public key and take the last 20 bytes as the address
|
|
175
|
+
const hash = keccak_256(publicKeyWithoutPrefix);
|
|
176
|
+
const addressBytes = hash.slice(-20);
|
|
177
|
+
return `0x${secp.etc.bytesToHex(addressBytes)}`;
|
|
178
|
+
}
|
|
@@ -25,6 +25,9 @@ export interface SymbolConverterOptions {
|
|
|
25
25
|
* const transport = new HttpTransport(); // or `WebSocketTransport`
|
|
26
26
|
* const converter = await SymbolConverter.create({ transport });
|
|
27
27
|
*
|
|
28
|
+
* // By default, dexs are not loaded; specify them when creating an instance
|
|
29
|
+
* // const converter = await SymbolConverter.create({ transport, dexs: ["test"] });
|
|
30
|
+
*
|
|
28
31
|
* const btcId = converter.getAssetId("BTC"); // perpetual → 0
|
|
29
32
|
* const hypeUsdcId = converter.getAssetId("HYPE/USDC"); // spot market → 10107
|
|
30
33
|
* const dexAbcId = converter.getAssetId("test:ABC"); // builder dex (if enabled) → 110000
|
|
@@ -32,6 +35,8 @@ export interface SymbolConverterOptions {
|
|
|
32
35
|
* const btcSzDecimals = converter.getSzDecimals("BTC"); // perpetual → 5
|
|
33
36
|
* const hypeUsdcSzDecimals = converter.getSzDecimals("HYPE/USDC"); // spot market → 2
|
|
34
37
|
* const dexAbcSzDecimals = converter.getSzDecimals("test:ABC"); // builder dex (if enabled) → 0
|
|
38
|
+
*
|
|
39
|
+
* const spotPairId = converter.getSpotPairId("HFUN/USDC"); // → "@2"
|
|
35
40
|
* ```
|
|
36
41
|
*/
|
|
37
42
|
export class SymbolConverter {
|
|
@@ -39,6 +44,7 @@ export class SymbolConverter {
|
|
|
39
44
|
private readonly dexOption: DexOption;
|
|
40
45
|
private readonly nameToAssetId = new Map<string, number>();
|
|
41
46
|
private readonly nameToSzDecimals = new Map<string, number>();
|
|
47
|
+
private readonly nameToSpotPairId = new Map<string, string>();
|
|
42
48
|
|
|
43
49
|
private constructor(options: SymbolConverterOptions) {
|
|
44
50
|
this.transport = options.transport;
|
|
@@ -86,6 +92,7 @@ export class SymbolConverter {
|
|
|
86
92
|
|
|
87
93
|
this.nameToAssetId.clear();
|
|
88
94
|
this.nameToSzDecimals.clear();
|
|
95
|
+
this.nameToSpotPairId.clear();
|
|
89
96
|
|
|
90
97
|
this.processDefaultPerps(perpMetaData);
|
|
91
98
|
this.processSpotAssets(spotMetaData);
|
|
@@ -158,6 +165,7 @@ export class SymbolConverter {
|
|
|
158
165
|
const baseQuoteKey = `${baseToken.name}/${quoteToken.name}`;
|
|
159
166
|
this.nameToAssetId.set(baseQuoteKey, assetId);
|
|
160
167
|
this.nameToSzDecimals.set(baseQuoteKey, baseToken.szDecimals);
|
|
168
|
+
this.nameToSpotPairId.set(baseQuoteKey, market.name);
|
|
161
169
|
});
|
|
162
170
|
}
|
|
163
171
|
|
|
@@ -182,4 +190,14 @@ export class SymbolConverter {
|
|
|
182
190
|
getSzDecimals(name: string): number | undefined {
|
|
183
191
|
return this.nameToSzDecimals.get(name);
|
|
184
192
|
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Get spot pair ID for info endpoints and subscriptions (e.g., l2book, trades).
|
|
196
|
+
*
|
|
197
|
+
* Accepts spot markets in the "BASE/QUOTE" format (e.g., "HFUN/USDC").
|
|
198
|
+
* @example "HFUN/USDC" → "@2", "PURR/USDC" → "PURR/USDC"
|
|
199
|
+
*/
|
|
200
|
+
getSpotPairId(name: string): string | undefined {
|
|
201
|
+
return this.nameToSpotPairId.get(name);
|
|
202
|
+
}
|
|
185
203
|
}
|
package/src/src/utils/mod.ts
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sequential request execution to prevent nonce race conditions.
|
|
3
|
-
*
|
|
4
|
-
* Problem: When multiple requests are sent rapidly, they may execute in different order
|
|
5
|
-
* on the transport layer, causing nonce errors (e.g., server receives nonce 101 before 100).
|
|
6
|
-
*
|
|
7
|
-
* Solution: Queue ensures requests execute sequentially in order.
|
|
8
|
-
*/
|
|
9
|
-
import type { ExchangeRequestConfig, MultiSignRequestConfig } from "./_types.js";
|
|
10
|
-
/**
|
|
11
|
-
* Request queue for sequential execution of requests.
|
|
12
|
-
* Ensures that requests are executed in order, preventing them from arriving at the server out of sequence.
|
|
13
|
-
*/
|
|
14
|
-
declare class RequestQueue {
|
|
15
|
-
private queue;
|
|
16
|
-
/**
|
|
17
|
-
* Enqueue a request to be executed sequentially.
|
|
18
|
-
* @param fn - The function to execute.
|
|
19
|
-
* @returns A promise that resolves with the result of the function.
|
|
20
|
-
*/
|
|
21
|
-
enqueue<T>(fn: () => Promise<T>): Promise<T>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get or create a request queue for the given config.
|
|
25
|
-
* Uses a global Map keyed by wallet address to ensure the same wallet uses the same queue
|
|
26
|
-
* regardless of whether called via client or direct function.
|
|
27
|
-
*/
|
|
28
|
-
export declare function getRequestQueue(config: ExchangeRequestConfig | MultiSignRequestConfig): Promise<RequestQueue | undefined>;
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=_sequential.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_sequential.d.ts","sourceRoot":"","sources":["../../../../../src/src/api/exchange/_base/_sequential.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGjF;;;GAGG;AACH,cAAM,YAAY;IAChB,OAAO,CAAC,KAAK,CAAuC;IAEpD;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAK7C;AAmBD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAAG,sBAAsB,GACrD,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CA0BnC"}
|