@totalis/hip4-client 0.0.0-stage → 0.65.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/CHANGELOG.md +1541 -0
- package/LICENSE +202 -0
- package/README.md +143 -2
- package/dist/api-keys.d.ts +118 -0
- package/dist/api-keys.js +104 -0
- package/dist/audience-contract.d.ts +52 -0
- package/dist/audience-contract.js +1 -0
- package/dist/base.d.ts +41 -0
- package/dist/base.js +60 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +15 -0
- package/dist/controller.d.ts +50 -0
- package/dist/controller.js +60 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/flow-errors.d.ts +61 -0
- package/dist/flow-errors.js +70 -0
- package/dist/generated/account-read.d.ts +2009 -0
- package/dist/generated/account-read.js +1 -0
- package/dist/generated/api-keys.d.ts +1303 -0
- package/dist/generated/api-keys.js +1 -0
- package/dist/generated/browse.d.ts +938 -0
- package/dist/generated/browse.js +1 -0
- package/dist/generated/client.d.ts +73 -0
- package/dist/generated/client.js +1 -0
- package/dist/generated/errors.d.ts +404 -0
- package/dist/generated/errors.js +1342 -0
- package/dist/generated/maker.d.ts +47 -0
- package/dist/generated/maker.js +1 -0
- package/dist/generated/openapi.d.ts +8044 -0
- package/dist/generated/openapi.js +1 -0
- package/dist/generated/operator.d.ts +7 -0
- package/dist/generated/operator.js +1 -0
- package/dist/generated/realtime.d.ts +1416 -0
- package/dist/generated/realtime.js +1 -0
- package/dist/generated/vault-abi.d.ts +39 -0
- package/dist/generated/vault-abi.js +56 -0
- package/dist/generated/version.d.ts +23 -0
- package/dist/generated/version.js +143 -0
- package/dist/hypercore.d.ts +111 -0
- package/dist/hypercore.js +132 -0
- package/dist/maker.d.ts +205 -0
- package/dist/maker.js +608 -0
- package/dist/money.d.ts +59 -0
- package/dist/money.js +66 -0
- package/dist/operator.d.ts +4 -0
- package/dist/operator.js +4 -0
- package/dist/pagination.d.ts +20 -0
- package/dist/pagination.js +27 -0
- package/dist/partner.d.ts +59 -0
- package/dist/partner.js +57 -0
- package/dist/realtime.d.ts +19 -0
- package/dist/realtime.js +10 -0
- package/dist/request.d.ts +112 -0
- package/dist/request.js +187 -0
- package/dist/signer.d.ts +51 -0
- package/dist/signer.js +90 -0
- package/dist/stream.d.ts +133 -0
- package/dist/stream.js +318 -0
- package/dist/totalis.d.ts +656 -0
- package/dist/totalis.js +1160 -0
- package/dist/typed-data.d.ts +330 -0
- package/dist/typed-data.js +340 -0
- package/dist/ui.d.ts +54 -0
- package/dist/ui.js +77 -0
- package/dist/wallet-session.d.ts +45 -0
- package/dist/wallet-session.js +61 -0
- package/examples/browser-wallet.html +69 -0
- package/examples/browser-wallet.mjs +57 -0
- package/examples/node-bot.mjs +57 -0
- package/examples/onboard.mjs +132 -0
- package/examples/partner-frontend.mjs +44 -0
- package/examples/partner-server.mjs +22 -0
- package/package.json +104 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Argument lists of the vault functions a maker's controller calls. */
|
|
2
|
+
export declare const controllerFunctions: {
|
|
3
|
+
readonly openMakerVault: readonly [{
|
|
4
|
+
readonly name: "quoteSigner";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}];
|
|
7
|
+
readonly depositMaker: readonly [{
|
|
8
|
+
readonly name: "makerId";
|
|
9
|
+
readonly type: "uint64";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "expectedController";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "amount";
|
|
15
|
+
readonly type: "uint128";
|
|
16
|
+
}];
|
|
17
|
+
readonly requestMakerWithdraw: readonly [{
|
|
18
|
+
readonly name: "makerId";
|
|
19
|
+
readonly type: "uint64";
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "amount";
|
|
22
|
+
readonly type: "uint128";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "to";
|
|
25
|
+
readonly type: "address";
|
|
26
|
+
}];
|
|
27
|
+
readonly executeMakerWithdraw: readonly [{
|
|
28
|
+
readonly name: "makerId";
|
|
29
|
+
readonly type: "uint64";
|
|
30
|
+
}];
|
|
31
|
+
readonly cancelMakerWithdraw: readonly [{
|
|
32
|
+
readonly name: "makerId";
|
|
33
|
+
readonly type: "uint64";
|
|
34
|
+
}];
|
|
35
|
+
readonly resetDiscount: readonly [{
|
|
36
|
+
readonly name: "makerId";
|
|
37
|
+
readonly type: "uint64";
|
|
38
|
+
}];
|
|
39
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Generated by scripts/generate.mjs from protocol/hyperevm/ParlayVault.abi.json; do not edit.
|
|
2
|
+
/** Argument lists of the vault functions a maker's controller calls. */
|
|
3
|
+
export const controllerFunctions = {
|
|
4
|
+
"openMakerVault": [
|
|
5
|
+
{
|
|
6
|
+
"name": "quoteSigner",
|
|
7
|
+
"type": "address"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"depositMaker": [
|
|
11
|
+
{
|
|
12
|
+
"name": "makerId",
|
|
13
|
+
"type": "uint64"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "expectedController",
|
|
17
|
+
"type": "address"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "amount",
|
|
21
|
+
"type": "uint128"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"requestMakerWithdraw": [
|
|
25
|
+
{
|
|
26
|
+
"name": "makerId",
|
|
27
|
+
"type": "uint64"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "amount",
|
|
31
|
+
"type": "uint128"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "to",
|
|
35
|
+
"type": "address"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"executeMakerWithdraw": [
|
|
39
|
+
{
|
|
40
|
+
"name": "makerId",
|
|
41
|
+
"type": "uint64"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"cancelMakerWithdraw": [
|
|
45
|
+
{
|
|
46
|
+
"name": "makerId",
|
|
47
|
+
"type": "uint64"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"resetDiscount": [
|
|
51
|
+
{
|
|
52
|
+
"name": "makerId",
|
|
53
|
+
"type": "uint64"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const sdkVersion = "163.0.0-operation-failure-reason";
|
|
2
|
+
export declare const openapiSha256 = "5f8993120c0337a57ed69b23baa03a3808ca741b7e0153ed92278be2f4d8a304";
|
|
3
|
+
export declare const realtimeSha256 = "47efae07a9fe89b2560e54037ddc0e71aa9bfeff0127da84ddee6557681a1330";
|
|
4
|
+
export declare const jsonSchemaSha256: {
|
|
5
|
+
readonly "account.schema.json": "b7b080ad906842c1772694cd1bff0ea181015514251f3a4a774c344b72c94300";
|
|
6
|
+
readonly "common.schema.json": "42fb090805f4e1237245f2c3b44d62d727dd972e4e7019cadcceb89aa3b4c2cb";
|
|
7
|
+
readonly "core-exit.schema.json": "8ba71470c5ce0b46ca104edf00f5be21ade4088a0c281609deef638aab275e3b";
|
|
8
|
+
readonly "error.schema.json": "ba31ea39df90d314a6c008b31f2f91159790dd35a53fa67f364fd03b452cad00";
|
|
9
|
+
readonly "hypercore.schema.json": "00fb9ec8ce1a593e185ee4c21ef8689fc78fa8f97bb2c8f2df62babaffc99629";
|
|
10
|
+
readonly "identity.schema.json": "112e1324739aed33198d792e5fb0ddbc52ad3e0ebbc1ba73473da0220e97267d";
|
|
11
|
+
readonly "maker-access.schema.json": "49698ee0235e42064aae0397db1e0f646bdc10d9dfa10121714ba06dd69fee3b";
|
|
12
|
+
readonly "maker-action.schema.json": "47c6951d4a11c0efa945a755dc8e03d59f26392431b51c690324d0f56f3d47ba";
|
|
13
|
+
readonly "maker-telemetry.schema.json": "85b111ce0f4935299d1116071b43de12e775bef4e0c283c12f19046d34374a9c";
|
|
14
|
+
readonly "market-data.schema.json": "b57a68ae336bce36bcdddf9a58260c85475a6c0cbaed60a281bd967c7c887706";
|
|
15
|
+
readonly "product-metadata.schema.json": "7c8ffbde878a0aedaed16814fcfd2e80038054b140886cc8736bb7b508042631";
|
|
16
|
+
readonly "quote.schema.json": "416387c9467e0fbfcc45227ccfeba4bb11e2457c390455a7c03226e6f4dff1de";
|
|
17
|
+
readonly "realtime.schema.json": "47efae07a9fe89b2560e54037ddc0e71aa9bfeff0127da84ddee6557681a1330";
|
|
18
|
+
};
|
|
19
|
+
export declare const operations: {
|
|
20
|
+
readonly client: readonly ["abandonCoreExit", "acceptQuote", "activeCoreExits", "admitOwnMaker", "admitPartnerWallet", "bindEmbeddedWallet", "cancelRfq", "createCashout", "createCoreExit", "createDeposit", "createRfq", "createWalletChallenge", "createWalletSession", "createWithdrawal", "endWalletSession", "generateUsername", "getAcceptance", "getAccountActivity", "getAccountPnl", "getAccountPosition", "getBalances", "getCoreExit", "getDeployment", "getHypercorePortfolio", "getHypercoreSettlementCredits", "getIdentity", "getMakerActivity", "getMakerCapital", "getMakerExposure", "getMakerPerformance", "getMakerPosition", "getMakerQuotes", "getMakerTelemetry", "getMakerVaultFundingTransaction", "getMakerWithdrawal", "getMarket", "getMarketDataConfig", "getMarketDefinitions", "getMarketHistory", "getMarketRecurringRound", "getMarketReferenceCloses", "getMarketStats", "getOperation", "getOwnMaker", "getProfitLeaderboard", "getQuestion", "getQuestionRecurringRound", "getRfq", "getSeries", "getSuggestedCombo", "getTaxonomy", "getUsernameAvailability", "getVolumeLeaderboard", "getWithdrawal", "listAccountActivity", "listAccountPositions", "listControlledMakers", "listDiscovery", "listMakerActivity", "listMakerPositions", "listMakerQuoteHistory", "listMarkets", "listOperations", "listQuotes", "recordAcquisition", "searchCatalog", "setAvatar", "setUsername", "stream", "streamMarkets"];
|
|
21
|
+
readonly maker: readonly ["cancelQuote", "confirmQuote", "createCollateralReduction", "createQuote", "getAccountActivity", "getAccountPosition", "getCollateralReduction", "getDeployment", "getMakerActivity", "getMakerCapital", "getMakerExposure", "getMakerPerformance", "getMakerPosition", "getMakerQuotes", "getMakerTelemetry", "getMakerTelemetryPublication", "getMakerVaultFundingTransaction", "getMakerWithdrawal", "getMarket", "getMarketHistory", "getMarketRecurringRound", "getMarketReferenceCloses", "getOperation", "getQuestion", "getQuestionRecurringRound", "getRfq", "getSeries", "getTaxonomy", "listAccountActivity", "listAccountPositions", "listDiscovery", "listMakerAcceptances", "listMakerActivity", "listMakerPositions", "listMakerQuoteHistory", "listMarkets", "listOperations", "listRfqs", "publishMakerTelemetry", "releaseQuoteLease", "renewQuoteLease", "searchCatalog", "stream", "submitMakerSelfFundedTransaction"];
|
|
22
|
+
readonly operator: readonly ["live", "ready"];
|
|
23
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Generated by scripts/generate.mjs; do not edit.
|
|
2
|
+
export const sdkVersion = "163.0.0-operation-failure-reason";
|
|
3
|
+
export const openapiSha256 = "5f8993120c0337a57ed69b23baa03a3808ca741b7e0153ed92278be2f4d8a304";
|
|
4
|
+
export const realtimeSha256 = "47efae07a9fe89b2560e54037ddc0e71aa9bfeff0127da84ddee6557681a1330";
|
|
5
|
+
export const jsonSchemaSha256 = {
|
|
6
|
+
"account.schema.json": "b7b080ad906842c1772694cd1bff0ea181015514251f3a4a774c344b72c94300",
|
|
7
|
+
"common.schema.json": "42fb090805f4e1237245f2c3b44d62d727dd972e4e7019cadcceb89aa3b4c2cb",
|
|
8
|
+
"core-exit.schema.json": "8ba71470c5ce0b46ca104edf00f5be21ade4088a0c281609deef638aab275e3b",
|
|
9
|
+
"error.schema.json": "ba31ea39df90d314a6c008b31f2f91159790dd35a53fa67f364fd03b452cad00",
|
|
10
|
+
"hypercore.schema.json": "00fb9ec8ce1a593e185ee4c21ef8689fc78fa8f97bb2c8f2df62babaffc99629",
|
|
11
|
+
"identity.schema.json": "112e1324739aed33198d792e5fb0ddbc52ad3e0ebbc1ba73473da0220e97267d",
|
|
12
|
+
"maker-access.schema.json": "49698ee0235e42064aae0397db1e0f646bdc10d9dfa10121714ba06dd69fee3b",
|
|
13
|
+
"maker-action.schema.json": "47c6951d4a11c0efa945a755dc8e03d59f26392431b51c690324d0f56f3d47ba",
|
|
14
|
+
"maker-telemetry.schema.json": "85b111ce0f4935299d1116071b43de12e775bef4e0c283c12f19046d34374a9c",
|
|
15
|
+
"market-data.schema.json": "b57a68ae336bce36bcdddf9a58260c85475a6c0cbaed60a281bd967c7c887706",
|
|
16
|
+
"product-metadata.schema.json": "7c8ffbde878a0aedaed16814fcfd2e80038054b140886cc8736bb7b508042631",
|
|
17
|
+
"quote.schema.json": "416387c9467e0fbfcc45227ccfeba4bb11e2457c390455a7c03226e6f4dff1de",
|
|
18
|
+
"realtime.schema.json": "47efae07a9fe89b2560e54037ddc0e71aa9bfeff0127da84ddee6557681a1330"
|
|
19
|
+
};
|
|
20
|
+
export const operations = {
|
|
21
|
+
"client": [
|
|
22
|
+
"abandonCoreExit",
|
|
23
|
+
"acceptQuote",
|
|
24
|
+
"activeCoreExits",
|
|
25
|
+
"admitOwnMaker",
|
|
26
|
+
"admitPartnerWallet",
|
|
27
|
+
"bindEmbeddedWallet",
|
|
28
|
+
"cancelRfq",
|
|
29
|
+
"createCashout",
|
|
30
|
+
"createCoreExit",
|
|
31
|
+
"createDeposit",
|
|
32
|
+
"createRfq",
|
|
33
|
+
"createWalletChallenge",
|
|
34
|
+
"createWalletSession",
|
|
35
|
+
"createWithdrawal",
|
|
36
|
+
"endWalletSession",
|
|
37
|
+
"generateUsername",
|
|
38
|
+
"getAcceptance",
|
|
39
|
+
"getAccountActivity",
|
|
40
|
+
"getAccountPnl",
|
|
41
|
+
"getAccountPosition",
|
|
42
|
+
"getBalances",
|
|
43
|
+
"getCoreExit",
|
|
44
|
+
"getDeployment",
|
|
45
|
+
"getHypercorePortfolio",
|
|
46
|
+
"getHypercoreSettlementCredits",
|
|
47
|
+
"getIdentity",
|
|
48
|
+
"getMakerActivity",
|
|
49
|
+
"getMakerCapital",
|
|
50
|
+
"getMakerExposure",
|
|
51
|
+
"getMakerPerformance",
|
|
52
|
+
"getMakerPosition",
|
|
53
|
+
"getMakerQuotes",
|
|
54
|
+
"getMakerTelemetry",
|
|
55
|
+
"getMakerVaultFundingTransaction",
|
|
56
|
+
"getMakerWithdrawal",
|
|
57
|
+
"getMarket",
|
|
58
|
+
"getMarketDataConfig",
|
|
59
|
+
"getMarketDefinitions",
|
|
60
|
+
"getMarketHistory",
|
|
61
|
+
"getMarketRecurringRound",
|
|
62
|
+
"getMarketReferenceCloses",
|
|
63
|
+
"getMarketStats",
|
|
64
|
+
"getOperation",
|
|
65
|
+
"getOwnMaker",
|
|
66
|
+
"getProfitLeaderboard",
|
|
67
|
+
"getQuestion",
|
|
68
|
+
"getQuestionRecurringRound",
|
|
69
|
+
"getRfq",
|
|
70
|
+
"getSeries",
|
|
71
|
+
"getSuggestedCombo",
|
|
72
|
+
"getTaxonomy",
|
|
73
|
+
"getUsernameAvailability",
|
|
74
|
+
"getVolumeLeaderboard",
|
|
75
|
+
"getWithdrawal",
|
|
76
|
+
"listAccountActivity",
|
|
77
|
+
"listAccountPositions",
|
|
78
|
+
"listControlledMakers",
|
|
79
|
+
"listDiscovery",
|
|
80
|
+
"listMakerActivity",
|
|
81
|
+
"listMakerPositions",
|
|
82
|
+
"listMakerQuoteHistory",
|
|
83
|
+
"listMarkets",
|
|
84
|
+
"listOperations",
|
|
85
|
+
"listQuotes",
|
|
86
|
+
"recordAcquisition",
|
|
87
|
+
"searchCatalog",
|
|
88
|
+
"setAvatar",
|
|
89
|
+
"setUsername",
|
|
90
|
+
"stream",
|
|
91
|
+
"streamMarkets"
|
|
92
|
+
],
|
|
93
|
+
"maker": [
|
|
94
|
+
"cancelQuote",
|
|
95
|
+
"confirmQuote",
|
|
96
|
+
"createCollateralReduction",
|
|
97
|
+
"createQuote",
|
|
98
|
+
"getAccountActivity",
|
|
99
|
+
"getAccountPosition",
|
|
100
|
+
"getCollateralReduction",
|
|
101
|
+
"getDeployment",
|
|
102
|
+
"getMakerActivity",
|
|
103
|
+
"getMakerCapital",
|
|
104
|
+
"getMakerExposure",
|
|
105
|
+
"getMakerPerformance",
|
|
106
|
+
"getMakerPosition",
|
|
107
|
+
"getMakerQuotes",
|
|
108
|
+
"getMakerTelemetry",
|
|
109
|
+
"getMakerTelemetryPublication",
|
|
110
|
+
"getMakerVaultFundingTransaction",
|
|
111
|
+
"getMakerWithdrawal",
|
|
112
|
+
"getMarket",
|
|
113
|
+
"getMarketHistory",
|
|
114
|
+
"getMarketRecurringRound",
|
|
115
|
+
"getMarketReferenceCloses",
|
|
116
|
+
"getOperation",
|
|
117
|
+
"getQuestion",
|
|
118
|
+
"getQuestionRecurringRound",
|
|
119
|
+
"getRfq",
|
|
120
|
+
"getSeries",
|
|
121
|
+
"getTaxonomy",
|
|
122
|
+
"listAccountActivity",
|
|
123
|
+
"listAccountPositions",
|
|
124
|
+
"listDiscovery",
|
|
125
|
+
"listMakerAcceptances",
|
|
126
|
+
"listMakerActivity",
|
|
127
|
+
"listMakerPositions",
|
|
128
|
+
"listMakerQuoteHistory",
|
|
129
|
+
"listMarkets",
|
|
130
|
+
"listOperations",
|
|
131
|
+
"listRfqs",
|
|
132
|
+
"publishMakerTelemetry",
|
|
133
|
+
"releaseQuoteLease",
|
|
134
|
+
"renewQuoteLease",
|
|
135
|
+
"searchCatalog",
|
|
136
|
+
"stream",
|
|
137
|
+
"submitMakerSelfFundedTransaction"
|
|
138
|
+
],
|
|
139
|
+
"operator": [
|
|
140
|
+
"live",
|
|
141
|
+
"ready"
|
|
142
|
+
]
|
|
143
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type Hex, type TypedData, type TypedDataSigner } from "./typed-data.js";
|
|
2
|
+
/** The Hyperliquid network a deployment's chain (`GET /v1/deployment` `chain_id`) signs for and submits to. */
|
|
3
|
+
export type HyperliquidNetwork = {
|
|
4
|
+
readonly chain: "Mainnet" | "Testnet";
|
|
5
|
+
/** The signing domain chain the HyperEVM bridge names: the deployment's own chain. */
|
|
6
|
+
readonly signatureChainId: Hex;
|
|
7
|
+
readonly exchangeUrl: string;
|
|
8
|
+
readonly usdcToken: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function hyperliquidNetwork(chainId: string | number): HyperliquidNetwork;
|
|
11
|
+
/** HyperCore's USDC system address: a `sendAsset` to it credits the sender's own HyperEVM address. */
|
|
12
|
+
export declare const hyperevmUsdcBridge = "0x2000000000000000000000000000000000000000";
|
|
13
|
+
/** Core USDC (6 decimals) kept behind a bridge: Core charges its gas in USDC when the account holds no HYPE. */
|
|
14
|
+
export declare const bridgeGasBuffer = 50000n;
|
|
15
|
+
export type SendAssetAction = {
|
|
16
|
+
readonly type: "sendAsset";
|
|
17
|
+
readonly hyperliquidChain: "Mainnet" | "Testnet";
|
|
18
|
+
readonly signatureChainId: Hex;
|
|
19
|
+
readonly destination: string;
|
|
20
|
+
readonly sourceDex: string;
|
|
21
|
+
readonly destinationDex: string;
|
|
22
|
+
readonly token: string;
|
|
23
|
+
readonly amount: string;
|
|
24
|
+
readonly fromSubAccount: string;
|
|
25
|
+
readonly nonce: number;
|
|
26
|
+
};
|
|
27
|
+
export type HypercoreSignature = {
|
|
28
|
+
readonly r: Hex;
|
|
29
|
+
readonly s: Hex;
|
|
30
|
+
readonly v: 27 | 28;
|
|
31
|
+
};
|
|
32
|
+
/** A signed user action exactly as Hyperliquid's `/exchange` takes it. Plain JSON: persist it before the first send. */
|
|
33
|
+
export type SignedSendAsset = {
|
|
34
|
+
readonly action: SendAssetAction;
|
|
35
|
+
readonly nonce: number;
|
|
36
|
+
readonly signature: HypercoreSignature;
|
|
37
|
+
};
|
|
38
|
+
export declare function sendAssetTypedData(action: SendAssetAction): TypedData;
|
|
39
|
+
/** Millisecond time, strictly increasing within this process: Hyperliquid spends each nonce once. */
|
|
40
|
+
export declare function hypercoreNonce(now?: number): number;
|
|
41
|
+
/** 6-decimal USDC base units as Hyperliquid's decimal text: 1500000n is "1.5". */
|
|
42
|
+
export declare function usdcText(amount: bigint): string;
|
|
43
|
+
/** Hyperliquid's decimal USDC text as 6-decimal base units: "1.5" is 1500000n. */
|
|
44
|
+
export declare function usdcUnits(text: string): bigint;
|
|
45
|
+
/**
|
|
46
|
+
* USDC an entry's bridge sent from HyperCore to its HyperEVM wallet:
|
|
47
|
+
* `amount` in USDC base units, `landed` `"yes"` on Hyperliquid's `ok` and
|
|
48
|
+
* `"unknown"` otherwise (read the balances). When the entry does not trade,
|
|
49
|
+
* this cash is in the wallet, not on HyperCore: the next entry spends it
|
|
50
|
+
* first, or `returnToCore` moves it back.
|
|
51
|
+
*/
|
|
52
|
+
export type BridgedCash = {
|
|
53
|
+
readonly amount: string;
|
|
54
|
+
readonly landed: "yes" | "unknown";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The Core to HyperEVM USDC bridge: a `sendAsset` of `amount` (6-decimal base
|
|
58
|
+
* units) to the system address, from Core spot by default. `sourceDex: ""`
|
|
59
|
+
* sends from perps, which Hyperliquid documents but Totalis has not proven live.
|
|
60
|
+
*/
|
|
61
|
+
export declare function bridgeAction(network: HyperliquidNetwork, amount: bigint, options?: {
|
|
62
|
+
readonly nonce?: number;
|
|
63
|
+
readonly sourceDex?: "spot" | "";
|
|
64
|
+
}): SendAssetAction;
|
|
65
|
+
/** A 65-byte signature as Hyperliquid's `{ r, s, v }`. */
|
|
66
|
+
export declare function hypercoreSignature(signature: string): HypercoreSignature;
|
|
67
|
+
export declare function signSendAsset(signer: TypedDataSigner, action: SendAssetAction): Promise<SignedSendAsset>;
|
|
68
|
+
/**
|
|
69
|
+
* Carries a signed action to Hyperliquid: your own Hyperliquid client or a
|
|
70
|
+
* relay. Return Hyperliquid's answer, either its `{ status, response }` body
|
|
71
|
+
* or its plain error text (as a relay that reports a refusal as an HTTP error
|
|
72
|
+
* gives it); throw when no answer arrived, so the bytes are resent.
|
|
73
|
+
*/
|
|
74
|
+
export type HypercoreTransport = (signed: SignedSendAsset, signal?: AbortSignal) => Promise<unknown>;
|
|
75
|
+
/** POST to the action's own network's `/exchange`. A body that is not JSON (a gateway error) throws: no answer. */
|
|
76
|
+
export declare function hyperliquidExchange(fetchImpl?: typeof fetch): HypercoreTransport;
|
|
77
|
+
/**
|
|
78
|
+
* What one Hyperliquid answer settles. A user-signed action spends its nonce
|
|
79
|
+
* even when refused, so the first answer is final: `ok` executed; `processed`
|
|
80
|
+
* means this nonce can no longer land and its outcome is on the ledger (a
|
|
81
|
+
* duplicate, or a nonce that fell out of Hyperliquid's window);
|
|
82
|
+
* `refused` can never land; `unknown` (no answer, or not one of these) means
|
|
83
|
+
* resend the same bytes until one arrives.
|
|
84
|
+
*/
|
|
85
|
+
export type HypercoreAnswer = {
|
|
86
|
+
readonly kind: "ok";
|
|
87
|
+
} | {
|
|
88
|
+
readonly kind: "processed";
|
|
89
|
+
} | {
|
|
90
|
+
readonly kind: "refused";
|
|
91
|
+
readonly error: string;
|
|
92
|
+
} | {
|
|
93
|
+
readonly kind: "unknown";
|
|
94
|
+
};
|
|
95
|
+
/** Classify Hyperliquid's `{ status, response }` body, or its plain error text. */
|
|
96
|
+
export declare function classifyHypercoreAnswer(body: unknown): HypercoreAnswer;
|
|
97
|
+
/** One send; a transport failure is `unknown`. */
|
|
98
|
+
export declare function submitHypercore(signed: SignedSendAsset, transport?: HypercoreTransport, signal?: AbortSignal): Promise<HypercoreAnswer>;
|
|
99
|
+
/**
|
|
100
|
+
* Resend the identical signed action while the answer is unknown, until
|
|
101
|
+
* Hyperliquid answers or `signal` / `deadline` stops it, which returns
|
|
102
|
+
* `unknown`. `deadline` is in ms on `now`, epoch ms by default, and is
|
|
103
|
+
* checked before every send. Never signs anything.
|
|
104
|
+
*/
|
|
105
|
+
export declare function settleHypercore(signed: SignedSendAsset, options?: {
|
|
106
|
+
readonly transport?: HypercoreTransport;
|
|
107
|
+
readonly signal?: AbortSignal;
|
|
108
|
+
readonly deadline?: number;
|
|
109
|
+
readonly now?: () => number;
|
|
110
|
+
readonly retryDelayMs?: number;
|
|
111
|
+
}): Promise<HypercoreAnswer>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { sleep } from "./request.js";
|
|
2
|
+
import { canonicalSignature } from "./typed-data.js";
|
|
3
|
+
const networks = {
|
|
4
|
+
"999": { chain: "Mainnet", signatureChainId: "0x3e7", exchangeUrl: "https://api.hyperliquid.xyz/exchange", usdcToken: "USDC:0x6d1e7cde53ba9467b783cb7c530ce054" },
|
|
5
|
+
"998": { chain: "Testnet", signatureChainId: "0x3e6", exchangeUrl: "https://api.hyperliquid-testnet.xyz/exchange", usdcToken: "USDC:0xeb62eee3685fc4c43992febcd9e75443" },
|
|
6
|
+
};
|
|
7
|
+
export function hyperliquidNetwork(chainId) {
|
|
8
|
+
const key = String(chainId);
|
|
9
|
+
if (key === "999" || key === "998")
|
|
10
|
+
return networks[key];
|
|
11
|
+
throw new RangeError(`chain ${key} has no Hyperliquid network`);
|
|
12
|
+
}
|
|
13
|
+
/** HyperCore's USDC system address: a `sendAsset` to it credits the sender's own HyperEVM address. */
|
|
14
|
+
export const hyperevmUsdcBridge = "0x2000000000000000000000000000000000000000";
|
|
15
|
+
/** Core USDC (6 decimals) kept behind a bridge: Core charges its gas in USDC when the account holds no HYPE. */
|
|
16
|
+
export const bridgeGasBuffer = 50000n;
|
|
17
|
+
const sendAssetFields = [
|
|
18
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
19
|
+
{ name: "destination", type: "string" },
|
|
20
|
+
{ name: "sourceDex", type: "string" },
|
|
21
|
+
{ name: "destinationDex", type: "string" },
|
|
22
|
+
{ name: "token", type: "string" },
|
|
23
|
+
{ name: "amount", type: "string" },
|
|
24
|
+
{ name: "fromSubAccount", type: "string" },
|
|
25
|
+
{ name: "nonce", type: "uint64" },
|
|
26
|
+
];
|
|
27
|
+
export function sendAssetTypedData(action) {
|
|
28
|
+
const { type: _type, signatureChainId, nonce, ...fields } = action;
|
|
29
|
+
return {
|
|
30
|
+
domain: { name: "HyperliquidSignTransaction", version: "1", chainId: BigInt(signatureChainId), verifyingContract: "0x0000000000000000000000000000000000000000" },
|
|
31
|
+
types: { "HyperliquidTransaction:SendAsset": sendAssetFields },
|
|
32
|
+
primaryType: "HyperliquidTransaction:SendAsset",
|
|
33
|
+
message: { ...fields, nonce: BigInt(nonce) },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let lastNonce = 0;
|
|
37
|
+
/** Millisecond time, strictly increasing within this process: Hyperliquid spends each nonce once. */
|
|
38
|
+
export function hypercoreNonce(now = Date.now()) {
|
|
39
|
+
lastNonce = Math.max(now, lastNonce + 1);
|
|
40
|
+
return lastNonce;
|
|
41
|
+
}
|
|
42
|
+
/** 6-decimal USDC base units as Hyperliquid's decimal text: 1500000n is "1.5". */
|
|
43
|
+
export function usdcText(amount) {
|
|
44
|
+
const whole = amount / 1000000n;
|
|
45
|
+
const fraction = (amount % 1000000n).toString().padStart(6, "0").replace(/0+$/, "");
|
|
46
|
+
return fraction === "" ? whole.toString() : `${whole}.${fraction}`;
|
|
47
|
+
}
|
|
48
|
+
/** Hyperliquid's decimal USDC text as 6-decimal base units: "1.5" is 1500000n. */
|
|
49
|
+
export function usdcUnits(text) {
|
|
50
|
+
const [whole = "0", fraction = ""] = text.split(".");
|
|
51
|
+
return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0").slice(0, 6));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The Core to HyperEVM USDC bridge: a `sendAsset` of `amount` (6-decimal base
|
|
55
|
+
* units) to the system address, from Core spot by default. `sourceDex: ""`
|
|
56
|
+
* sends from perps, which Hyperliquid documents but Totalis has not proven live.
|
|
57
|
+
*/
|
|
58
|
+
export function bridgeAction(network, amount, options = {}) {
|
|
59
|
+
if (amount <= 0n)
|
|
60
|
+
throw new RangeError("bridge amount must be positive");
|
|
61
|
+
return {
|
|
62
|
+
type: "sendAsset", hyperliquidChain: network.chain, signatureChainId: network.signatureChainId,
|
|
63
|
+
destination: hyperevmUsdcBridge, sourceDex: options.sourceDex ?? "spot", destinationDex: "spot",
|
|
64
|
+
token: network.usdcToken, amount: usdcText(amount), fromSubAccount: "", nonce: options.nonce ?? hypercoreNonce(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const parity = (v) => v === 27 || v === 28;
|
|
68
|
+
/** A 65-byte signature as Hyperliquid's `{ r, s, v }`. */
|
|
69
|
+
export function hypercoreSignature(signature) {
|
|
70
|
+
const raw = canonicalSignature(signature);
|
|
71
|
+
const v = Number.parseInt(raw.slice(130), 16);
|
|
72
|
+
if (raw.length !== 132 || !parity(v))
|
|
73
|
+
throw new TypeError("a Hyperliquid signature must be 65 bytes");
|
|
74
|
+
return { r: `0x${raw.slice(2, 66)}`, s: `0x${raw.slice(66, 130)}`, v };
|
|
75
|
+
}
|
|
76
|
+
export async function signSendAsset(signer, action) {
|
|
77
|
+
return { action, nonce: action.nonce, signature: hypercoreSignature(await signer.signTypedData(sendAssetTypedData(action))) };
|
|
78
|
+
}
|
|
79
|
+
/** POST to the action's own network's `/exchange`. A body that is not JSON (a gateway error) throws: no answer. */
|
|
80
|
+
export function hyperliquidExchange(fetchImpl = (input, init) => globalThis.fetch(input, init)) {
|
|
81
|
+
return async (signed, signal) => {
|
|
82
|
+
const network = signed.action.hyperliquidChain === "Mainnet" ? networks["999"] : networks["998"];
|
|
83
|
+
const response = await fetchImpl(network.exchangeUrl, {
|
|
84
|
+
method: "POST", headers: { "Content-Type": "application/json" },
|
|
85
|
+
body: JSON.stringify({ action: signed.action, nonce: signed.nonce, signature: signed.signature }),
|
|
86
|
+
...(signal === undefined ? {} : { signal }),
|
|
87
|
+
});
|
|
88
|
+
const body = JSON.parse(await response.text());
|
|
89
|
+
return body;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
93
|
+
/** Classify Hyperliquid's `{ status, response }` body, or its plain error text. */
|
|
94
|
+
export function classifyHypercoreAnswer(body) {
|
|
95
|
+
const error = typeof body === "string" ? body : isRecord(body) && body.status === "err" && typeof body.response === "string" ? body.response : undefined;
|
|
96
|
+
if (error !== undefined) {
|
|
97
|
+
if (error.trim() === "")
|
|
98
|
+
return { kind: "unknown" };
|
|
99
|
+
return /^Invalid nonce: (duplicate nonce|nonce too low)/.test(error) ? { kind: "processed" } : { kind: "refused", error };
|
|
100
|
+
}
|
|
101
|
+
return isRecord(body) && body.status === "ok" ? { kind: "ok" } : { kind: "unknown" };
|
|
102
|
+
}
|
|
103
|
+
const exchange = hyperliquidExchange();
|
|
104
|
+
/** One send; a transport failure is `unknown`. */
|
|
105
|
+
export async function submitHypercore(signed, transport = exchange, signal) {
|
|
106
|
+
try {
|
|
107
|
+
return classifyHypercoreAnswer(await transport(signed, signal));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return { kind: "unknown" };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Resend the identical signed action while the answer is unknown, until
|
|
115
|
+
* Hyperliquid answers or `signal` / `deadline` stops it, which returns
|
|
116
|
+
* `unknown`. `deadline` is in ms on `now`, epoch ms by default, and is
|
|
117
|
+
* checked before every send. Never signs anything.
|
|
118
|
+
*/
|
|
119
|
+
export async function settleHypercore(signed, options = {}) {
|
|
120
|
+
const { transport = exchange, deadline, now = Date.now, retryDelayMs = 500 } = options;
|
|
121
|
+
const stops = [options.signal, deadline === undefined ? undefined : AbortSignal.timeout(Math.max(0, Math.ceil(deadline - now())))].filter((signal) => signal !== undefined);
|
|
122
|
+
const stop = stops.length === 0 ? undefined : AbortSignal.any(stops);
|
|
123
|
+
for (;;) {
|
|
124
|
+
if (stop?.aborted || deadline !== undefined && now() >= deadline)
|
|
125
|
+
return { kind: "unknown" };
|
|
126
|
+
const answer = await submitHypercore(signed, transport, stop);
|
|
127
|
+
if (answer.kind !== "unknown")
|
|
128
|
+
return answer;
|
|
129
|
+
if (!(await sleep(retryDelayMs, stop).then(() => true, () => false)))
|
|
130
|
+
return { kind: "unknown" };
|
|
131
|
+
}
|
|
132
|
+
}
|