Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@google-cloud/storage": "^6.10.1",
"@maticnetwork/maticjs": "^3.6.0",
"@maticnetwork/maticjs-ethers": "^1.0.3",
"@nktkas/hyperliquid": "^0.25.4",
"@nktkas/hyperliquid": "^0.25.9",
"@openzeppelin/hardhat-upgrades": "^1.28.0",
"@solana-program/address-lookup-table": "^0.7.0",
"@solana-program/compute-budget": "^0.8.0",
Expand Down
51 changes: 51 additions & 0 deletions scripts/hyperliquidExchangeApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as hl from "@nktkas/hyperliquid";
import { SymbolConverter } from "@nktkas/hyperliquid/script/src/utils/mod";

async function run() {
const subsClient = new hl.SubscriptionClient({
transport: new hl.WebSocketTransport(),
});

const httpTransport = new hl.HttpTransport(); // or `WebSocketTransport`
const converter = await SymbolConverter.create({ transport: httpTransport });
const spotPairId = converter.getSpotPairId("USDT0/USDC");
console.log(`Printing fills for spot pair ${spotPairId}`);
// Log out all historical fills for user and also log
// for each new one.
await subsClient.userFills({ user: "0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D" }, (data) => {
for (const fill of data.fills) {
if (fill.coin === spotPairId) {
console.log(fill);
// e.g. USDT-USDC sell limit order fill (sell USDT for USDC)
// {
// coin: '@166',
// px: '0.99987',
// sz: '12.0',
// side: 'A',
// time: 1762442654786,
// startPosition: '20.75879498',
// dir: 'Sell',
// closedPnl: '-0.00266345',
// hash: '0x12bac8ba533cb3641434042ef5f8990207c6009fee3fd236b683740d12308d4e',
// oid: 225184674691,
// crossed: false,
// fee: '0.00095987',
// tid: 854069469806140,
// feeToken: 'USDC',
// twapId: null
// }
}
}
});
}

if (require.main === module) {
run()
.then(async () => {
process.exitCode = 0;
})
.catch(async (error) => {
console.error("Process exited with", error);
process.exitCode = 128;
});
}
17 changes: 17 additions & 0 deletions src/hyperliquid/HyperliquidExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ export class HyperliquidExecutor {
});
}

private async finalizeLimitOrders(finalToken: EvmAddress, quoteNonces: string[], limitOrderOutputs: BigNumber[]) {
// limitOrderOutputs is the amount of final tokens received for each limit order associated with a quoteNonce.
const l2TokenInfo = this._getTokenInfo(finalToken, this.chainId);
const dstHandler = l2TokenInfo.symbol === "USDC" ? this.dstCctpMessenger : this.dstOftMessenger;

const mrkdwn = `finalToken: ${l2TokenInfo.symbol}\n quoteNonces: ${quoteNonces}\n limitOrderOuts: ${limitOrderOutputs}`;
this.clients.multiCallerClient.enqueueTransaction({
contract: dstHandler,
chainId: this.chainId,
method: "finalizeSwapFlows",
args: [finalToken.toNative(), quoteNonces, limitOrderOutputs],
message: `Finalized ${quoteNonces.length} limit orders and sending output tokens to the user.`,
mrkdwn,
nonMulticall: true, // Cannot multicall this since it is a permissioned action.
});
}

private _getTokenInfo(token: EvmAddress, chainId: number) {
const tokenInfo = getTokenInfo(token, chainId);
const updatedSymbol = tokenInfo.symbol === "USDT" ? "USDT0" : tokenInfo.symbol;
Expand Down
18 changes: 12 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,11 @@
protobufjs "^7.2.4"
yargs "^17.7.2"

"@henrygd/[email protected]":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@henrygd/semaphore/-/semaphore-0.1.0.tgz#92edf8e441b4f565d046d5de8c8d92437b5df26d"
integrity sha512-5wRPsfP9iWnOTFRd7QKdHlWTgY9xw9GAHSkQP/Q05ZTKUBdfTj44BhsnADPfvBoUQVGDtP2Nd0UShVdeTLuLwA==

"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"
Expand Down Expand Up @@ -1633,13 +1638,14 @@
resolved "https://registry.yarnpkg.com/@multiformats/base-x/-/base-x-4.0.1.tgz#95ff0fa58711789d53aefb2590a8b7a4e715d121"
integrity sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw==

"@nktkas/hyperliquid@^0.25.4":
version "0.25.4"
resolved "https://registry.yarnpkg.com/@nktkas/hyperliquid/-/hyperliquid-0.25.4.tgz#1d29e85e4ef6e6d02fffcb15293c582757948620"
integrity sha512-o2qGBfB+8pRwfx1ypug7pH70utIwiNt2efsgRqWHjjvd/ZAj10o9et9i9QsFuQMywif2QuFCPfWYHoSF8YQZqg==
"@nktkas/hyperliquid@^0.25.9":
version "0.25.9"
resolved "https://registry.yarnpkg.com/@nktkas/hyperliquid/-/hyperliquid-0.25.9.tgz#69b8bef3065322ea5346f67067a43077e64f89e1"
integrity sha512-rNqRG4LWeCmnWUNV5XQAl+XLH7uzShvwXj3Z7JsWC45QgU8RlSv/MODUP9CE3Xv/avXWkEEhwy/BkLQkN85s+g==
dependencies:
"@henrygd/semaphore" "0.1.0"
"@msgpack/msgpack" "^3.1.2"
"@noble/hashes" "^2.0.0"
"@noble/hashes" "^2.0.1"
"@noble/secp256k1" "^3.0.0"
typescript-event-target "1.1.1"
valibot "1.1.0"
Expand Down Expand Up @@ -1721,7 +1727,7 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.8.0.tgz#cee43d801fcef9644b11b8194857695acd5f815a"
integrity sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==

"@noble/hashes@^2.0.0":
"@noble/hashes@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-2.0.1.tgz#fc1a928061d1232b0a52bb754393c37a5216c89e"
integrity sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw==
Expand Down