Skip to content

Commit 4989e58

Browse files
authored
fix: allow specifying an explicit timestamp for hyperliquid withdrawals (#132)
1 parent 2158d7a commit 4989e58

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/api/queries/payload-ids/v1.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const Schema = {
4040
currencyHyperliquidSymbol: Type.String({
4141
description: "The Hyperliquid symbol for the currency",
4242
}),
43+
currentTime: Type.Number({
44+
description:
45+
"The timestamp to be used for the Hyperliquid transaction",
46+
}),
4347
}),
4448
),
4549
},

src/api/requests/withdrawals/v2.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ const Schema = {
4444
currencyHyperliquidSymbol: Type.String({
4545
description: "The Hyperliquid symbol for the currency",
4646
}),
47-
})
47+
currentTime: Type.Number({
48+
description:
49+
"The timestamp to be used for the Hyperliquid transaction",
50+
}),
51+
}),
4852
),
4953
},
5054
{
5155
description:
5256
"Additional data needed for generating the withdrawal request",
53-
}
54-
)
57+
},
58+
),
5559
),
5660
owner: Type.String({
5761
description: "The address of the owner (that triggered the withdrawal)",
@@ -71,12 +75,12 @@ const Schema = {
7175
}),
7276
signer: Type.String({ description: "The signer of the withdrawal" }),
7377
submitWithdrawalRequestParams: Type.Optional(
74-
SubmitWithdrawalRequestParamsSchema
78+
SubmitWithdrawalRequestParamsSchema,
7579
),
7680
signature: Type.Optional(
7781
Type.String({
7882
description: "The allocator signature for the withdrawal",
79-
})
83+
}),
8084
),
8185
}),
8286
...ErrorResponse,
@@ -89,16 +93,16 @@ export default {
8993
schema: Schema,
9094
handler: async (
9195
req: FastifyRequestTypeBox<typeof Schema>,
92-
reply: FastifyReplyTypeBox<typeof Schema>
96+
reply: FastifyReplyTypeBox<typeof Schema>,
9397
) => {
9498
// make sure we got EVM sig
9599
const signatureVmType = await getChain(req.body.ownerChainId).then(
96-
(c) => c.vmType
100+
(c) => c.vmType,
97101
);
98102
if (signatureVmType !== "ethereum-vm") {
99103
throw externalError(
100104
"Only 'ethereum-vm' signatures are supported",
101-
"UNSUPPORTED_SIGNATURE"
105+
"UNSUPPORTED_SIGNATURE",
102106
);
103107
}
104108

@@ -109,7 +113,7 @@ export default {
109113
req.body.spender as `0x${string}`, // withdrawalAddress
110114
BigInt(req.body.amount),
111115
req.body.nonce as `0x${string}`,
112-
]
116+
],
113117
);
114118

115119
// authentify the proof of withdrawal address balance
@@ -133,7 +137,7 @@ export default {
133137
JSON.stringify({
134138
msg: "Executing `withdrawal` request (v2)",
135139
request: req.body,
136-
})
140+
}),
137141
);
138142

139143
const requestHandler = new RequestHandlerService();
@@ -148,7 +152,7 @@ export default {
148152
msg: "Executed `withdrawal` request",
149153
request: req.body,
150154
result,
151-
})
155+
}),
152156
);
153157

154158
return reply.status(200).send(result);

src/services/request-handler/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type AdditionalDataBitcoinVm = {
6363

6464
type AdditionalDataHyperliquidVm = {
6565
currencyHyperliquidSymbol: string;
66+
currentTime?: number;
6667
};
6768

6869
type AllocatorSubmitRequestParams = {
@@ -849,15 +850,21 @@ export class RequestHandlerService {
849850
case "hyperliquid-vm": {
850851
const isNativeCurrency = currency === getVmTypeNativeCurrency(vmType);
851852

853+
// TODO: We probably shouldn't be letting the user choose the time in order
854+
// to preserve the assumption that the time is always incrementing. However
855+
// at the moment we need these for deterministic payload ids.
856+
const currentTime = BigInt(
857+
additionalData!["hyperliquid-vm"]!.currentTime ?? Date.now(),
858+
);
852859
const currencyDex =
853860
currency.slice(34) === ""
854861
? "spot"
855862
: Buffer.from(currency.slice(34), "hex").toString("ascii");
856863
const data = isNativeCurrency
857-
? encodeAbiParameters([{ type: "uint64" }], [BigInt(Date.now())])
864+
? encodeAbiParameters([{ type: "uint64" }], [currentTime])
858865
: encodeAbiParameters(
859866
[{ type: "uint64" }, { type: "string" }, { type: "string" }],
860-
[BigInt(Date.now()), currencyDex, currencyDex],
867+
[currentTime, currencyDex, currencyDex],
861868
);
862869

863870
return {

0 commit comments

Comments
 (0)