Skip to content

Commit 38625d3

Browse files
committed
Merge branch 'main' into staging
2 parents 3161537 + a10214f commit 38625d3

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/services/request-handler/index.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type AdditionalDataBitcoinVm = {
5858
transactionFee: string;
5959
};
6060

61+
type AdditionalDataHyperliquidVm = {
62+
currencyHyperliquidSymbol: string;
63+
};
64+
6165
type WithdrawalRequest = {
6266
mode?: "offchain" | "onchain";
6367
ownerChainId: string;
@@ -68,6 +72,7 @@ type WithdrawalRequest = {
6872
recipient: string;
6973
additionalData?: {
7074
"bitcoin-vm"?: AdditionalDataBitcoinVm;
75+
"hyperliquid-vm"?: AdditionalDataHyperliquidVm;
7176
};
7277
};
7378

@@ -463,15 +468,39 @@ export class RequestHandlerService {
463468
const { contract, publicClient, walletClient } =
464469
await getOnchainAllocator();
465470

466-
const currentTime = BigInt(Date.now());
471+
const isNativeCurrency =
472+
request.currency === getVmTypeNativeCurrency(chain.vmType);
473+
if (!isNativeCurrency) {
474+
const additionalData = request.additionalData?.["hyperliquid-vm"];
475+
if (!additionalData) {
476+
throw externalError(
477+
"Additional data is required for generating the withdrawal request"
478+
);
479+
}
480+
}
467481

468-
// TODO: Add support for "sendAsset"
469-
const data = encodeAbiParameters([{ type: "uint64" }], [currentTime]);
482+
const currencyDex =
483+
request.currency.slice(34) === ""
484+
? "spot"
485+
: Buffer.from(request.currency.slice(34), "hex").toString(
486+
"ascii"
487+
);
488+
const data = isNativeCurrency
489+
? encodeAbiParameters([{ type: "uint64" }], [BigInt(Date.now())])
490+
: encodeAbiParameters(
491+
[{ type: "uint64" }, { type: "string" }, { type: "string" }],
492+
[BigInt(Date.now()), currencyDex, currencyDex]
493+
);
470494

471495
payloadParams = {
472496
chainId: chain.metadata.allocatorChainId!,
473497
depository: chain.depository!,
474-
currency: request.currency.toLowerCase(),
498+
currency: isNativeCurrency
499+
? ""
500+
: `${
501+
request.additionalData!["hyperliquid-vm"]!
502+
.currencyHyperliquidSymbol
503+
}:${request.currency.toLowerCase()}`,
475504
amount: request.amount,
476505
spender: walletClient.account.address.toLowerCase(),
477506
receiver: request.recipient.toLowerCase(),

0 commit comments

Comments
 (0)