├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── deno_tests.yml │ ├── publish_jsr.yml │ └── publish_npm.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── build └── npm.ts ├── deno.json ├── mod.ts ├── src ├── base.ts ├── clients │ ├── exchange.ts │ ├── info.ts │ ├── multiSign.ts │ └── subscription.ts ├── signing.ts ├── transports │ ├── base.ts │ ├── http │ │ └── http_transport.ts │ └── websocket │ │ ├── _hyperliquid_event_target.ts │ │ ├── _reconnecting_websocket.ts │ │ ├── _websocket_async_request.ts │ │ └── websocket_transport.ts └── types │ ├── exchange │ ├── requests.ts │ └── responses.ts │ ├── explorer │ ├── requests.ts │ └── responses.ts │ ├── info │ ├── accounts.ts │ ├── assets.ts │ ├── delegations.ts │ ├── markets.ts │ ├── orders.ts │ ├── requests.ts │ └── vaults.ts │ ├── mod.ts │ └── subscriptions │ ├── requests.ts │ └── responses.ts └── tests ├── _utils ├── schema │ ├── addStrictAdditionalProperties.ts │ ├── resolveAllOf.ts │ ├── resolveRef.ts │ ├── schemaCoverage.ts │ └── schemaGenerator.ts └── utils.ts ├── clients ├── exchange │ ├── _guessSignatureChainId.test.ts │ ├── _validateResponse.test.ts │ ├── approveAgent.test.ts │ ├── approveBuilderFee.test.ts │ ├── batchModify.test.ts │ ├── cDeposit.test.ts │ ├── cSignerAction.test.ts │ ├── cValidatorAction.test.ts │ ├── cWithdraw.test.ts │ ├── cancel.test.ts │ ├── cancelByCloid.test.ts │ ├── claimRewards.test.ts │ ├── convertToMultiSigUser.test.ts │ ├── createSubAccount.test.ts │ ├── createVault.test.ts │ ├── evmUserModify.test.ts │ ├── modify.test.ts │ ├── multiSig.test.ts │ ├── order.test.ts │ ├── perpDeploy.test.ts │ ├── perpDexClassTransfer.test.ts │ ├── registerReferrer.test.ts │ ├── reserveRequestWeight.test.ts │ ├── scheduleCancel.test.ts │ ├── setDisplayName.test.ts │ ├── setReferrer.test.ts │ ├── spotDeploy.test.ts │ ├── spotSend.test.ts │ ├── spotUser.test.ts │ ├── subAccountSpotTransfer.test.ts │ ├── subAccountTransfer.test.ts │ ├── tokenDelegate.test.ts │ ├── twapCancel.test.ts │ ├── twapOrder.test.ts │ ├── updateIsolatedMargin.test.ts │ ├── updateLeverage.test.ts │ ├── usdClassTransfer.test.ts │ ├── usdSend.test.ts │ ├── vaultDistribute.test.ts │ ├── vaultModify.test.ts │ ├── vaultTransfer.test.ts │ └── withdraw3.test.ts ├── info │ ├── allMids.test.ts │ ├── blockDetails.test.ts │ ├── candleSnapshot.test.ts │ ├── clearinghouseState.test.ts │ ├── delegations.test.ts │ ├── delegatorHistory.test.ts │ ├── delegatorRewards.test.ts │ ├── delegatorSummary.test.ts │ ├── extraAgents.test.ts │ ├── frontendOpenOrders.test.ts │ ├── fundingHistory.test.ts │ ├── historicalOrders.test.ts │ ├── isVip.test.ts │ ├── l2Book.test.ts │ ├── legalCheck.test.ts │ ├── maxBuilderFee.test.ts │ ├── meta.test.ts │ ├── metaAndAssetCtxs.test.ts │ ├── openOrders.test.ts │ ├── orderStatus.test.ts │ ├── perpDeployAuctionStatus.test.ts │ ├── perpDex.test.ts │ ├── perpsAtOpenInterestCap.test.ts │ ├── portfolio.test.ts │ ├── preTransferCheck.test.ts │ ├── predictedFundings.test.ts │ ├── referral.test.ts │ ├── spotClearinghouseState.test.ts │ ├── spotDeployState.test.ts │ ├── spotMeta.test.ts │ ├── spotMetaAndAssetCtxs.test.ts │ ├── subAccounts.test.ts │ ├── tokenDetails.test.ts │ ├── twapHistory.test.ts │ ├── txDetails.test.ts │ ├── userDetails.test.ts │ ├── userFees.test.ts │ ├── userFills.test.ts │ ├── userFillsByTime.test.ts │ ├── userFunding.test.ts │ ├── userNonFundingLedgerUpdates.test.ts │ ├── userRateLimit.test.ts │ ├── userRole.test.ts │ ├── userToMultiSigSigners.test.ts │ ├── userTwapSliceFills.test.ts │ ├── userTwapSliceFillsByTime.test.ts │ ├── userVaultEquities.test.ts │ ├── validatorSummaries.test.ts │ ├── vaultDetails.test.ts │ └── vaultSummaries.test.ts ├── multiSign │ ├── approveAgent.test.ts │ ├── approveBuilderFee.test.ts │ ├── batchModify.test.ts │ ├── cDeposit.test.ts │ ├── cSignerAction.test.ts │ ├── cValidatorAction.test.ts │ ├── cWithdraw.test.ts │ ├── cancel.test.ts │ ├── cancelByCloid.test.ts │ ├── claimRewards.test.ts │ ├── convertToMultiSigUser.test.ts │ ├── createSubAccount.test.ts │ ├── createVault.test.ts │ ├── evmUserModify.test.ts │ ├── modify.test.ts │ ├── order.test.ts │ ├── perpDeploy.test.ts │ ├── perpDexClassTransfer.test.ts │ ├── registerReferrer.test.ts │ ├── reserveRequestWeight.test.ts │ ├── scheduleCancel.test.ts │ ├── setDisplayName.test.ts │ ├── setReferrer.test.ts │ ├── spotDeploy.test.ts │ ├── spotSend.test.ts │ ├── spotUser.test.ts │ ├── subAccountSpotTransfer.test.ts │ ├── subAccountTransfer.test.ts │ ├── tokenDelegate.test.ts │ ├── twapCancel.test.ts │ ├── twapOrder.test.ts │ ├── updateIsolatedMargin.test.ts │ ├── updateLeverage.test.ts │ ├── usdClassTransfer.test.ts │ ├── usdSend.test.ts │ ├── vaultDistribute.test.ts │ ├── vaultModify.test.ts │ ├── vaultTransfer.test.ts │ └── withdraw3.test.ts └── subscription │ ├── activeAssetCtx.test.ts │ ├── activeAssetData.test.ts │ ├── allMids.test.ts │ ├── bbo.test.ts │ ├── candle.test.ts │ ├── explorerBlock.test.ts │ ├── explorerTxs.test.ts │ ├── l2Book.test.ts │ ├── notification.test.ts │ ├── orderUpdates.test.ts │ ├── trades.test.ts │ ├── userEvents.test.ts │ ├── userFills.test.ts │ ├── userFundings.test.ts │ ├── userNonFundingLedgerUpdates.test.ts │ ├── userTwapHistory.test.ts │ ├── userTwapSliceFills.test.ts │ └── webData2.test.ts ├── signing └── sign_wallet.test.ts └── transports ├── http └── http_transport.test.ts └── websocket ├── _hyperliquid_event_target.test.ts ├── _reconnecting_websocket.test.ts ├── _websocket_async_request.test.ts └── websocket_transport.test.ts /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a bug 4 | title: 'Bug: ' 5 | labels: bug 6 | assignees: nktkas 7 | --- 8 | 9 | **Bug Description** 10 | 11 | 12 | 13 | **Code to Reproduce** 14 | 15 | 16 | 17 | 18 | **Environment** 19 | 20 | - `@nktkas/hyperliquid` version: 21 | - Runtime environment and its version: 22 | 23 | **Additional Context (optional)** 24 | 25 | 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: 'Feature: ' 5 | labels: enhancement 6 | assignees: nktkas 7 | --- 8 | 9 | **Description of the Desired Feature** 10 | 11 | 12 | 13 | **Motivation and Use Case** 14 | 15 | 16 | 17 | **Proposed Solution (optional)** 18 | 19 | 20 | 21 | **Additional Information (optional)** 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/deno_tests.yml: -------------------------------------------------------------------------------- 1 | name: Run Deno Tests 2 | on: 3 | workflow_dispatch: 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: denoland/setup-deno@v2 12 | with: 13 | deno-version: v2.x # Run with latest stable Deno 14 | 15 | # Check if the code is formatted according to Deno's default formatting conventions. 16 | - name: deno fmt 17 | run: | 18 | git config --global core.autocrlf false 19 | git config --global core.eol lf 20 | deno fmt --check 21 | 22 | # Scan the code for syntax errors and style issues. 23 | - name: deno lint 24 | run: deno lint 25 | 26 | # Run all test files in the repository and collect code coverage. 27 | - name: deno test + coverage 28 | run: deno test -A --coverage --coverage-raw-data-only -- ${{ secrets.PRIVATE_KEY }} 29 | 30 | # This generates a report from the collected coverage in `deno test --coverage`. 31 | - name: Create coverage report 32 | run: deno coverage --exclude=./tests --lcov --output=cov.lcov 33 | 34 | - name: Upload coverage to Coveralls.io 35 | uses: coverallsapp/github-action@v2 36 | -------------------------------------------------------------------------------- /.github/workflows/publish_jsr.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package to JSR 2 | on: 3 | workflow_dispatch: 4 | 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | 9 | permissions: 10 | contents: read 11 | id-token: write 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: Publish package 17 | run: npx jsr publish 18 | -------------------------------------------------------------------------------- /.github/workflows/publish_npm.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package to npm 2 | on: 3 | workflow_dispatch: 4 | 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | 9 | permissions: 10 | id-token: write 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: denoland/setup-deno@v2 15 | with: 16 | deno-version: v2.x # Run with latest stable Deno 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: "22.x" # Run with latest stable Node.js 20 | registry-url: "https://registry.npmjs.org" # Use npm registry 21 | 22 | - name: Build package 23 | run: | 24 | VERSION=$(jq -r '.version' deno.json) 25 | deno run -A ./build/npm.ts $VERSION 26 | 27 | - name: Publish package 28 | env: 29 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 30 | run: | 31 | cd ./build/npm 32 | npm publish --provenance 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to @nktkas/hyperliquid 2 | 3 | Welcome, and thank you for taking time in contributing to SDK! You can contribute to SDK in different ways: 4 | 5 | - Submit new features 6 | - Report and fix bugs 7 | - Review code 8 | 9 | ## Development Setup 10 | 11 | You will need [Deno](https://deno.land/) 2.0+. 12 | 13 | 1. Fork this repository to your own GitHub account. 14 | 2. Clone the repository to your local device. 15 | 3. Create a new branch `git checkout -b BRANCH_NAME`. 16 | 4. Change code. 17 | 5. [Push your branch to Github after all tests passed.](#Testing) 18 | 6. Make a [pull request](https://github.com/nktkas/hyperliquid/pulls). 19 | 7. Merge to master branch by our maintainers. 20 | 21 | ## Testing 22 | 23 | You can run most tests with the following command: 24 | 25 | ```bash 26 | deno test -A 27 | ``` 28 | 29 | However, for complete testing, you will need a private key from a testnet account with funds: 30 | 31 | ```bash 32 | deno test -A -- YOUR_PRIVATE_KEY 33 | ``` 34 | 35 | ## Coding Guidelines 36 | 37 | - **TypeScript**: Ensure your code passes TypeScript compilation without errors. Try not to ignore typescript errors and 38 | avoid creating unsafe types. 39 | - **Style**: Follow Deno formatting convention ([deno fmt](https://docs.deno.com/runtime/reference/cli/fmt/)) and code 40 | style ([deno lint](https://docs.deno.com/runtime/reference/cli/lint/)). 41 | - **Dependencies**: Try to use trusted small dependencies (e.g. [@noble](https://github.com/paulmillr/noble-hashes) or 42 | [deno @std](https://github.com/denoland/std)). 43 | - **Docs**: Update or add JSDoc comments where appropriate. 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024-2025 nktkas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## For Issues in Hyperliquid 4 | 5 | If you have discovered a vulnerability or security issue related to the Hyperliquid service (e.g., buffer overflow, SQL 6 | injection, cross-site scripting, etc.), please refer to the 7 | [Hyperliquid Security Policy](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/SECURITY.md). 8 | -------------------------------------------------------------------------------- /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nktkas/hyperliquid", 3 | "version": "0.22.1", 4 | "exports": { 5 | ".": "./mod.ts", 6 | "./types": "./src/types/mod.ts", 7 | "./signing": "./src/signing.ts" 8 | }, 9 | "imports": { 10 | "@derzade/typescript-event-target": "jsr:@derzade/typescript-event-target@1.1.1", 11 | "@noble/hashes/sha3": "jsr:@noble/hashes@^1.8.0/sha3", 12 | "@std/async/delay": "jsr:@std/async@^1.0.12/delay", 13 | "@std/bytes/concat": "jsr:@std/bytes@^1.0.5/concat", 14 | "@std/encoding/hex": "jsr:@std/encoding@^1.0.9/hex", 15 | "@std/msgpack/encode": "jsr:@std/msgpack@^1.0.3/encode" 16 | }, 17 | "fmt": { 18 | "indentWidth": 4, 19 | "lineWidth": 120 20 | }, 21 | "publish": { 22 | "exclude": [ 23 | ".github", 24 | "build", 25 | "tests" 26 | ] 27 | }, 28 | "license": "MIT", 29 | "lock": false 30 | } 31 | -------------------------------------------------------------------------------- /mod.ts: -------------------------------------------------------------------------------- 1 | // Base interfaces 2 | export * from "./src/base.ts"; 3 | export * from "./src/transports/base.ts"; 4 | 5 | // Signing 6 | export type { 7 | AbstractEthersSigner, 8 | AbstractEthersV5Signer, 9 | AbstractViemWalletClient, 10 | AbstractWindowEthereum, 11 | } from "./src/signing.ts"; 12 | 13 | // Clients 14 | export * from "./src/clients/exchange.ts"; 15 | export * from "./src/clients/info.ts"; 16 | export * from "./src/clients/multiSign.ts"; 17 | export * from "./src/clients/subscription.ts"; 18 | 19 | // Transports 20 | export * from "./src/transports/http/http_transport.ts"; 21 | export * from "./src/transports/websocket/websocket_transport.ts"; 22 | 23 | // Types 24 | export type * from "./src/types/exchange/responses.ts"; 25 | export type * from "./src/types/explorer/responses.ts"; 26 | export type * from "./src/types/info/accounts.ts"; 27 | export type * from "./src/types/info/assets.ts"; 28 | export type * from "./src/types/info/delegations.ts"; 29 | export type * from "./src/types/info/markets.ts"; 30 | export type * from "./src/types/info/orders.ts"; 31 | export type * from "./src/types/info/vaults.ts"; 32 | export type * from "./src/types/subscriptions/responses.ts"; 33 | -------------------------------------------------------------------------------- /src/base.ts: -------------------------------------------------------------------------------- 1 | export type Hex = `0x${string}`; 2 | 3 | export type MaybePromise = T | Promise; 4 | 5 | /** Base error class for all SDK errors. */ 6 | export class HyperliquidError extends Error { 7 | constructor(message?: string) { 8 | super(message); 9 | this.name = "HyperliquidError"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/transports/base.ts: -------------------------------------------------------------------------------- 1 | import { HyperliquidError } from "../base.ts"; 2 | 3 | /** 4 | * Interface representing a REST transport. 5 | * 6 | * Handles communication with Hyperliquid API endpoints. 7 | * 8 | * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint | Info endpoint} 9 | * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint | Exchange endpoint} 10 | * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests | Websocket post requests} 11 | */ 12 | export interface IRequestTransport extends Partial { 13 | /** 14 | * Sends a request to the Hyperliquid API. 15 | * @param endpoint - The API endpoint to send the request to. 16 | * @param payload - The payload to send with the request. 17 | * @param signal - An ptional abort signal. 18 | * @returns A promise that resolves with parsed JSON response body. 19 | */ 20 | request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise; 21 | } 22 | 23 | /** 24 | * Interface representing an event subscription transport. 25 | * Handles WebSocket subscriptions for real-time updates. 26 | * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Websocket subscriptions} 27 | */ 28 | export interface ISubscriptionTransport extends Partial { 29 | /** 30 | * Subscribes to a Hyperliquid event channel. 31 | * @param channel - The event channel to listen to. 32 | * @param payload - The payload to send with the subscription request. 33 | * @param listener - The function to call when the event is dispatched. 34 | * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle. 35 | */ 36 | subscribe(channel: string, payload: unknown, listener: (data: CustomEvent) => void): Promise; 37 | } 38 | 39 | /** Controls event subscription lifecycle. */ 40 | export interface Subscription { 41 | /** Unsubscribes from the event and sends an unsubscribe request to the server. */ 42 | unsubscribe(): Promise; 43 | /** Signal that aborts when resubscription fails during reconnection. */ 44 | resubscribeSignal?: AbortSignal; 45 | } 46 | 47 | /** Base class for all transport-related errors. */ 48 | export class TransportError extends HyperliquidError { 49 | constructor(message?: string) { 50 | super(message); 51 | this.name = "TransportError"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/types/explorer/requests.ts: -------------------------------------------------------------------------------- 1 | import type { Hex } from "../../base.ts"; 2 | 3 | /** 4 | * Block details by block height. 5 | * @returns {BlockDetailsResponse} Block details response. 6 | * @see null - no documentation 7 | */ 8 | export interface BlockDetailsRequest { 9 | /** Type of request. */ 10 | type: "blockDetails"; 11 | /** Block height. */ 12 | height: number; 13 | } 14 | 15 | /** 16 | * Transaction details by transaction hash. 17 | * @returns {TxDetailsResponse} Transaction details response. 18 | * @see null - no documentation 19 | */ 20 | export interface TxDetailsRequest { 21 | /** Type of request. */ 22 | type: "txDetails"; 23 | /** Transaction hash. */ 24 | hash: Hex; 25 | } 26 | 27 | /** 28 | * User details by user's address. 29 | * @returns {UserDetailsResponse} User details response. 30 | * @see null - no documentation 31 | */ 32 | export interface UserDetailsRequest { 33 | /** Type of request. */ 34 | type: "userDetails"; 35 | /** User's address. */ 36 | user: Hex; 37 | } 38 | -------------------------------------------------------------------------------- /src/types/explorer/responses.ts: -------------------------------------------------------------------------------- 1 | import type { Hex } from "../../base.ts"; 2 | 3 | /** Transaction details. */ 4 | export interface TxDetails { 5 | /** Action performed in transaction. */ 6 | action: { 7 | /** Action type. */ 8 | type: string; 9 | /** Additional action parameters. */ 10 | [key: string]: unknown; 11 | }; 12 | /** Block number where transaction was included. */ 13 | block: number; 14 | /** Error message if transaction failed. */ 15 | error: string | null; 16 | /** Transaction hash. */ 17 | hash: Hex; 18 | /** Transaction creation timestamp. */ 19 | time: number; 20 | /** Creator's address. */ 21 | user: Hex; 22 | } 23 | 24 | /** Response containing transaction information. */ 25 | export interface TxDetailsResponse { 26 | /** Type of response. */ 27 | type: "txDetails"; 28 | /** The details of a transaction. */ 29 | tx: TxDetails; 30 | } 31 | 32 | /** Block details. */ 33 | export interface BlockDetails { 34 | /** Block creation timestamp. */ 35 | blockTime: number; 36 | /** Block hash. */ 37 | hash: Hex; 38 | /** Block height in chain. */ 39 | height: number; 40 | /** Total transactions in block. */ 41 | numTxs: number; 42 | /** Block proposer address. */ 43 | proposer: Hex; 44 | /** List of transactions. */ 45 | txs: TxDetails[]; 46 | } 47 | 48 | /** Response containing block information. */ 49 | export interface BlockDetailsResponse { 50 | /** Type of response. */ 51 | type: "blockDetails"; 52 | /** The details of a block. */ 53 | blockDetails: BlockDetails; 54 | } 55 | 56 | /** Response containing user details. */ 57 | export interface UserDetailsResponse { 58 | /** Type of response. */ 59 | type: "userDetails"; 60 | /** The transactions of a user. */ 61 | txs: TxDetails[]; 62 | } 63 | -------------------------------------------------------------------------------- /src/types/info/markets.ts: -------------------------------------------------------------------------------- 1 | import type { Hex } from "../../base.ts"; 2 | 3 | /** Status of the deploy auction. */ 4 | export interface DeployAuctionStatus { 5 | /** Current gas. */ 6 | currentGas: string | null; 7 | /** Duration in seconds. */ 8 | durationSeconds: number; 9 | /** Ending gas. */ 10 | endGas: string | null; 11 | /** Starting gas. */ 12 | startGas: string; 13 | /** Auction start time (seconds since epoch). */ 14 | startTimeSeconds: number; 15 | } 16 | 17 | /** Deploy state for spot tokens. */ 18 | export interface SpotDeployState { 19 | /** Array of deploy states for tokens. */ 20 | states: { 21 | /** Token ID. */ 22 | token: number; 23 | /** Token specification. */ 24 | spec: { 25 | /** Name of the token. */ 26 | name: string; 27 | /** Minimum decimal places for order sizes. */ 28 | szDecimals: number; 29 | /** Number of decimals for the token's smallest unit. */ 30 | weiDecimals: number; 31 | }; 32 | /** Full name of the token. */ 33 | fullName: string | null; 34 | /** Deployer trading fee share for the token. */ 35 | deployerTradingFeeShare: string; 36 | /** Spot indices for the token. */ 37 | spots: number[]; 38 | /** Maximum supply of the token. */ 39 | maxSupply: string | null; 40 | /** Hyperliquidity genesis balance of the token. */ 41 | hyperliquidityGenesisBalance: string; 42 | /** Total genesis balance (in wei) for the token. */ 43 | totalGenesisBalanceWei: string; 44 | /** User genesis balances for the token. */ 45 | userGenesisBalances: [Hex, string][]; 46 | /** Existing token genesis balances for the token. */ 47 | existingTokenGenesisBalances: [number, string][]; 48 | /** Blacklisted users for the token. */ 49 | blacklistUsers: Hex[]; 50 | }[]; 51 | /** Status of the deploy auction. */ 52 | gasAuction: DeployAuctionStatus; 53 | } 54 | -------------------------------------------------------------------------------- /src/types/mod.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This module contains all types related to the Hyperliquid API. 3 | * 4 | * @example 5 | * ```ts 6 | * import type { OrderParams } from "@nktkas/hyperliquid/types"; 7 | * 8 | * const myOrder: OrderParams = { 9 | * a: 0, // Asset index 10 | * b: true, // Buy order 11 | * p: "30000", // Price 12 | * s: "0.1", // Size 13 | * r: false, // Not reduce-only 14 | * t: { 15 | * limit: { 16 | * tif: "Gtc", // Good-til-cancelled 17 | * }, 18 | * }, 19 | * }; 20 | * ``` 21 | * 22 | * @module 23 | */ 24 | 25 | export type { Hex } from "../base.ts"; 26 | 27 | export type * from "./exchange/requests.ts"; 28 | export type * from "./exchange/responses.ts"; 29 | 30 | export type * from "./explorer/requests.ts"; 31 | export type * from "./explorer/responses.ts"; 32 | 33 | export type * from "./info/accounts.ts"; 34 | export type * from "./info/assets.ts"; 35 | export type * from "./info/delegations.ts"; 36 | export type * from "./info/markets.ts"; 37 | export type * from "./info/orders.ts"; 38 | export type * from "./info/requests.ts"; 39 | export type * from "./info/vaults.ts"; 40 | 41 | export type * from "./subscriptions/responses.ts"; 42 | export type * from "./subscriptions/requests.ts"; 43 | -------------------------------------------------------------------------------- /tests/_utils/schema/addStrictAdditionalProperties.ts: -------------------------------------------------------------------------------- 1 | import type { SchemaObject } from "npm:ajv@8"; 2 | 3 | /** 4 | * Adds additionalProperties: false to all object type schemas recursively. 5 | * This makes the schema stricter by not allowing properties not explicitly defined. 6 | * 7 | * @param schema The JSON schema to modify 8 | * @returns The modified schema with additionalProperties: false added to object types 9 | */ 10 | export function addStrictAdditionalProperties(schema: SchemaObject): SchemaObject { 11 | // Base case: if schema is not an object or is null, return it as is 12 | if (typeof schema !== "object" || schema === null) { 13 | return schema; 14 | } 15 | 16 | // Create a new object to avoid modifying the input 17 | const result = structuredClone(schema); 18 | 19 | // If this is an object type schema, add additionalProperties: false 20 | if ( 21 | schema.type === "object" || 22 | (Array.isArray(schema.type) && schema.type.includes("object")) || 23 | schema.properties 24 | ) { 25 | // Only set additionalProperties if it's not already defined 26 | if (result.additionalProperties === undefined) { 27 | result.additionalProperties = false; 28 | } 29 | } 30 | 31 | // Recursively process nested schemas 32 | if (schema.properties) { 33 | result.properties = Object.entries(schema.properties) 34 | .reduce>((acc, [key, propSchema]) => { 35 | acc[key] = addStrictAdditionalProperties(propSchema); 36 | return acc; 37 | }, {}); 38 | } 39 | 40 | // Process array items 41 | if (schema.items) { 42 | if (Array.isArray(schema.items)) { 43 | // Handle tuple validation 44 | result.items = schema.items.map((item) => addStrictAdditionalProperties(item)); 45 | } else { 46 | // Handle array validation 47 | result.items = addStrictAdditionalProperties(schema.items); 48 | } 49 | } 50 | 51 | // Process allOf 52 | if (schema.allOf) { 53 | result.allOf = schema.allOf.map((subschema: SchemaObject) => addStrictAdditionalProperties(subschema)); 54 | } 55 | 56 | // Process anyOf 57 | if (schema.anyOf) { 58 | result.anyOf = schema.anyOf.map((subschema: SchemaObject) => addStrictAdditionalProperties(subschema)); 59 | } 60 | 61 | // Process oneOf 62 | if (schema.oneOf) { 63 | result.oneOf = schema.oneOf.map((subschema: SchemaObject) => addStrictAdditionalProperties(subschema)); 64 | } 65 | 66 | return result; 67 | } 68 | -------------------------------------------------------------------------------- /tests/_utils/schema/schemaGenerator.ts: -------------------------------------------------------------------------------- 1 | import * as TJS from "npm:typescript-json-schema@^0.65.1"; 2 | import { fromFileUrl } from "jsr:@std/path@1/from-file-url"; 3 | import type { SchemaObject } from "npm:ajv@8"; 4 | 5 | /** 6 | * Generates a JSON schema for a given TypeScript type. 7 | * @param path - The path to the TypeScript file containing the type. 8 | * @param typeName - The name of the type to generate the schema for. 9 | * @returns The generated JSON schema object. 10 | */ 11 | export function schemaGenerator(path: string, typeName: string): SchemaObject { 12 | const program = TJS.getProgramFromFiles([fromFileUrl(path)], { 13 | strict: true, 14 | allowImportingTsExtensions: true, 15 | lib: ["esnext", "dom"], 16 | module: "esnext", 17 | downlevelIteration: true, 18 | }); 19 | const schema = TJS.generateSchema(program, typeName, { 20 | strictNullChecks: true, 21 | required: true, 22 | ignoreErrors: true, 23 | }); 24 | if (!schema) throw new Error(`Failed to generate schema for ${typeName}`); 25 | return schema; 26 | } 27 | -------------------------------------------------------------------------------- /tests/clients/exchange/approveAgent.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | import { generateEthereumAddress } from "../../_utils/utils.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("approveAgent", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await Promise.all([ 33 | exchClient.approveAgent({ 34 | agentAddress: generateEthereumAddress(), 35 | }), 36 | exchClient.approveAgent({ 37 | agentAddress: generateEthereumAddress(), 38 | agentName: null, 39 | }), 40 | exchClient.approveAgent({ 41 | agentAddress: generateEthereumAddress(), 42 | agentName: "", 43 | }), 44 | exchClient.approveAgent({ 45 | agentAddress: generateEthereumAddress(), 46 | agentName: "agentName", 47 | }), 48 | ]); 49 | 50 | schemaCoverage(MethodReturnType, data); 51 | }); 52 | -------------------------------------------------------------------------------- /tests/clients/exchange/approveBuilderFee.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("approveBuilderFee", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await exchClient.approveBuilderFee({ 32 | maxFeeRate: "0.001%", 33 | builder: exchClient.wallet.address, 34 | }); 35 | 36 | schemaCoverage(MethodReturnType, [data]); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/clients/exchange/cDeposit.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("cDeposit", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await exchClient.cDeposit({ wei: 1 }); 32 | 33 | schemaCoverage(MethodReturnType, [data]); 34 | }); 35 | -------------------------------------------------------------------------------- /tests/clients/exchange/cSignerAction.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertRejects } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 9 | 10 | const PRIVATE_KEY = args._[0] as Hex; 11 | 12 | // —————————— Test —————————— 13 | 14 | // NOTE: This API is difficult to test with a successful response. 15 | // So to prove that the method works, we will expect a specific error 16 | Deno.test("cSignerAction", { ignore: !PRIVATE_KEY }, async () => { 17 | await new Promise((r) => setTimeout(r, args.wait)); 18 | 19 | // —————————— Prepare —————————— 20 | 21 | const account = privateKeyToAccount(PRIVATE_KEY); 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 24 | 25 | // —————————— Test —————————— 26 | 27 | await Promise.all([ 28 | assertRejects( 29 | () => exchClient.cSignerAction({ jailSelf: null }), 30 | ApiRequestError, 31 | "Signer invalid or inactive for current epoch", 32 | ), 33 | assertRejects( 34 | () => exchClient.cSignerAction({ unjailSelf: null }), 35 | ApiRequestError, 36 | "Signer invalid or inactive for current epoch", 37 | ), 38 | ]); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/cValidatorAction.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertRejects } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 9 | 10 | const PRIVATE_KEY = args._[0] as Hex; 11 | 12 | // —————————— Test —————————— 13 | 14 | // NOTE: This API is difficult to test with a successful response. 15 | // So to prove that the method works, we will expect a specific error 16 | Deno.test("cValidatorAction", { ignore: !PRIVATE_KEY }, async () => { 17 | await new Promise((r) => setTimeout(r, args.wait)); 18 | 19 | // —————————— Prepare —————————— 20 | 21 | const account = privateKeyToAccount(PRIVATE_KEY); 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 24 | 25 | // —————————— Test —————————— 26 | 27 | await Promise.all([ 28 | assertRejects( 29 | () => exchClient.cValidatorAction({ changeProfile: { unjailed: false } }), 30 | ApiRequestError, 31 | "Unknown validator", 32 | ), 33 | assertRejects( 34 | () => 35 | exchClient.cValidatorAction({ 36 | register: { 37 | profile: { 38 | node_ip: { Ip: "1.2.3.4" }, 39 | name: "...", 40 | description: "...", 41 | delegations_disabled: true, 42 | commission_bps: 1, 43 | signer: exchClient.wallet.address, 44 | }, 45 | unjailed: false, 46 | initial_wei: 1, 47 | }, 48 | }), 49 | ApiRequestError, 50 | "Validator has delegations disabled", 51 | ), 52 | assertRejects( 53 | () => exchClient.cValidatorAction({ unregister: null }), 54 | ApiRequestError, 55 | "Action disabled on this chain", 56 | ), 57 | ]); 58 | }); 59 | -------------------------------------------------------------------------------- /tests/clients/exchange/cWithdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("cWithdraw", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await exchClient.cWithdraw({ wei: 1 }); 32 | 33 | schemaCoverage(MethodReturnType, [data]); 34 | }); 35 | -------------------------------------------------------------------------------- /tests/clients/exchange/claimRewards.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("claimRewards", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | await exchClient.claimRewards() 33 | .then((data) => { 34 | schemaCoverage(MethodReturnType, [data]); 35 | }) 36 | .catch((e) => { 37 | assertIsError(e, ApiRequestError, "No rewards to claim"); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/convertToMultiSigUser.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { generatePrivateKey, privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("convertToMultiSigUser", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // Preparing a temporary wallet 30 | const tempPrivKey = generatePrivateKey(); 31 | const tempAccount = privateKeyToAccount(tempPrivKey); 32 | const tempExchClient = new ExchangeClient({ wallet: tempAccount, transport, isTestnet: true }); 33 | await exchClient.usdSend({ destination: tempAccount.address, amount: "2" }); 34 | 35 | // —————————— Test —————————— 36 | 37 | const data = await tempExchClient.convertToMultiSigUser({ 38 | authorizedUsers: [exchClient.wallet.address], 39 | threshold: 1, 40 | }); 41 | 42 | schemaCoverage(MethodReturnType, [data]); 43 | }); 44 | -------------------------------------------------------------------------------- /tests/clients/exchange/createSubAccount.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("createSubAccount", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | await exchClient.createSubAccount({ name: String(Date.now()) }) 33 | .then((data) => { 34 | schemaCoverage(MethodReturnType, [data]); 35 | }) 36 | .catch((e) => { 37 | assertIsError(e, ApiRequestError, "Too many sub-accounts"); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/createVault.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("createVault", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | await exchClient.createVault({ name: "", description: "", initialUsd: 50 * 1e6 }) 33 | .then((data) => { 34 | schemaCoverage(MethodReturnType, [data]); 35 | }) 36 | .catch((e) => { 37 | assertIsError(e, ApiRequestError, "Initial deposit in vault is less than $100"); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/evmUserModify.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("evmUserModify", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await Promise.all([ 32 | // Check argument 'usingBigBlocks' 33 | exchClient.evmUserModify({ usingBigBlocks: true }), 34 | exchClient.evmUserModify({ usingBigBlocks: false }), 35 | ]); 36 | 37 | schemaCoverage(MethodReturnType, data); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/exchange/perpDexClassTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("perpDexClassTransfer", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await Promise.all([ 32 | exchClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: true }), 33 | exchClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: false }), 34 | ]); 35 | 36 | schemaCoverage(MethodReturnType, data); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/clients/exchange/registerReferrer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("registerReferrer", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | await exchClient.registerReferrer({ code: "TEST" }) 33 | .then((data) => { 34 | schemaCoverage(MethodReturnType, [data]); 35 | }) 36 | .catch((e) => { 37 | assertIsError(e, ApiRequestError, "Referral code already registered for this user"); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/reserveRequestWeight.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("reserveRequestWeight", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await Promise.all([ 32 | // Check response 'success' 33 | exchClient.reserveRequestWeight({ weight: 1 }), 34 | // Check argument 'expiresAfter' 35 | exchClient.reserveRequestWeight({ weight: 1, expiresAfter: Date.now() + 1000 * 60 * 60 }), 36 | ]); 37 | 38 | schemaCoverage(MethodReturnType, data); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/scheduleCancel.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("scheduleCancel", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await Promise.all([ 32 | // Check argument 'time' + argument 'expiresAfter' 33 | exchClient.scheduleCancel({ time: Date.now() + 10000 }), 34 | exchClient.scheduleCancel({ expiresAfter: Date.now() + 1000 * 60 * 60 }), 35 | ]); 36 | 37 | schemaCoverage(MethodReturnType, data); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/exchange/setDisplayName.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("setDisplayName", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await exchClient.setDisplayName({ displayName: "" }); 32 | 33 | schemaCoverage(MethodReturnType, [data]); 34 | }); 35 | -------------------------------------------------------------------------------- /tests/clients/exchange/setReferrer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { generatePrivateKey, privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("setReferrer", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // Preparing a temporary wallet 30 | const tempPrivKey = generatePrivateKey(); 31 | const tempAccount = privateKeyToAccount(tempPrivKey); 32 | const tempExchClient = new ExchangeClient({ wallet: tempAccount, transport, isTestnet: true }); 33 | await exchClient.usdSend({ destination: tempAccount.address, amount: "2" }); 34 | 35 | // —————————— Test —————————— 36 | 37 | const data = await tempExchClient.setReferrer({ code: "TEST" }); 38 | 39 | schemaCoverage(MethodReturnType, [data]); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/clients/exchange/spotSend.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const DESTINATION_ADDRESS = "0x0000000000000000000000000000000000000000"; 13 | const TOKEN_ADDRESS = "USDC:0xeb62eee3685fc4c43992febcd9e75443"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("spotSend", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY as `0x${string}`); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 30 | 31 | // —————————— Test —————————— 32 | 33 | const data = await exchClient.spotSend({ 34 | destination: DESTINATION_ADDRESS, 35 | token: TOKEN_ADDRESS, 36 | amount: "1", 37 | }); 38 | 39 | schemaCoverage(MethodReturnType, [data]); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/clients/exchange/spotUser.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("spotUser", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data1 = await exchClient.spotUser({ toggleSpotDusting: { optOut: true } }); 32 | const data2 = await exchClient.spotUser({ toggleSpotDusting: { optOut: false } }); 33 | 34 | schemaCoverage(MethodReturnType, [data1, data2]); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/clients/exchange/subAccountSpotTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const SUB_ACCOUNT_ADDRESS = "0xcb3f0bd249a89e45e86a44bcfc7113e4ffe84cd1"; 13 | const TOKEN_ADDRESS = "USDC:0xeb62eee3685fc4c43992febcd9e75443"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("subAccountSpotTransfer", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 30 | 31 | // —————————— Test —————————— 32 | 33 | const data = await Promise.all([ 34 | // Check argument 'isDeposit' 35 | exchClient.subAccountSpotTransfer({ 36 | subAccountUser: SUB_ACCOUNT_ADDRESS, 37 | isDeposit: true, 38 | token: TOKEN_ADDRESS, 39 | amount: "1", 40 | }), 41 | exchClient.subAccountSpotTransfer({ 42 | subAccountUser: SUB_ACCOUNT_ADDRESS, 43 | isDeposit: false, 44 | token: TOKEN_ADDRESS, 45 | amount: "1", 46 | }), 47 | ]); 48 | 49 | schemaCoverage(MethodReturnType, data); 50 | }); 51 | -------------------------------------------------------------------------------- /tests/clients/exchange/subAccountTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const SUB_ACCOUNT_ADDRESS = "0xcb3f0bd249a89e45e86a44bcfc7113e4ffe84cd1"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("subAccountTransfer", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await Promise.all([ 33 | // Check argument 'isDeposit' 34 | exchClient.subAccountTransfer({ subAccountUser: SUB_ACCOUNT_ADDRESS, isDeposit: true, usd: 1 }), 35 | exchClient.subAccountTransfer({ subAccountUser: SUB_ACCOUNT_ADDRESS, isDeposit: false, usd: 1 }), 36 | ]); 37 | 38 | schemaCoverage(MethodReturnType, data); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/clients/exchange/tokenDelegate.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const VALIDATOR_ADDRESS = "0xa012b9040d83c5cbad9e6ea73c525027b755f596"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("tokenDelegate", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | // Check argument 'isUndelegate' 33 | const data1 = await exchClient.tokenDelegate({ validator: VALIDATOR_ADDRESS, wei: 1, isUndelegate: true }); 34 | const data2 = await exchClient.tokenDelegate({ validator: VALIDATOR_ADDRESS, wei: 1, isUndelegate: false }); 35 | 36 | schemaCoverage(MethodReturnType, [data1, data2]); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/clients/exchange/twapCancel.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import BigNumber from "npm:bignumber.js@9"; 4 | import { ExchangeClient, type Hex, HttpTransport, InfoClient } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | import { formatSize, getAssetData } from "../../_utils/utils.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const PERPS_ASSET = "BTC"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("twapCancel", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 31 | const infoClient = new InfoClient({ transport }); 32 | 33 | const { id, universe, ctx } = await getAssetData(infoClient, PERPS_ASSET); 34 | const sz = formatSize(new BigNumber(55).div(ctx.markPx), universe.szDecimals); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await Promise.all([ 39 | // Check response 'success' 40 | exchClient.twapCancel({ 41 | a: id, 42 | t: await createTWAP(exchClient, id, sz), 43 | }), 44 | // Check argument 'expiresAfter' 45 | exchClient.twapCancel({ 46 | a: id, 47 | t: await createTWAP(exchClient, id, sz), 48 | expiresAfter: Date.now() + 1000 * 60 * 60, 49 | }), 50 | ]); 51 | 52 | schemaCoverage(MethodReturnType, data); 53 | }); 54 | 55 | async function createTWAP(client: ExchangeClient, id: number, sz: string): Promise { 56 | const twapOrderResult = await client.twapOrder({ 57 | a: id, 58 | b: true, 59 | s: sz, 60 | r: false, 61 | m: 5, 62 | t: false, 63 | }); 64 | const twapId = twapOrderResult.response.data.status.running.twapId; 65 | return twapId; 66 | } 67 | -------------------------------------------------------------------------------- /tests/clients/exchange/updateLeverage.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import BigNumber from "npm:bignumber.js@9"; 4 | import { ExchangeClient, type Hex, HttpTransport, InfoClient } from "../../../mod.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | import { formatPrice, getAssetData } from "../../_utils/utils.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const PERPS_ASSET = "BTC"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("updateLeverage", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 31 | const infoClient = new InfoClient({ transport }); 32 | 33 | const { id, universe, ctx } = await getAssetData(infoClient, PERPS_ASSET); 34 | const pxDown = formatPrice(new BigNumber(ctx.markPx).times(0.99), universe.szDecimals); 35 | 36 | await exchClient.order({ 37 | orders: [{ 38 | a: id, 39 | b: false, 40 | p: pxDown, 41 | s: "0", // Full position size 42 | r: true, 43 | t: { limit: { tif: "Gtc" } }, 44 | }], 45 | grouping: "na", 46 | }).catch(() => undefined); 47 | 48 | // —————————— Test —————————— 49 | 50 | const data = await Promise.all([ 51 | // Check argument 'isCross' + argument 'expiresAfter' 52 | exchClient.updateLeverage({ asset: id, isCross: true, leverage: 1 }), 53 | exchClient.updateLeverage({ 54 | asset: id, 55 | isCross: false, 56 | leverage: 1, 57 | expiresAfter: Date.now() + 1000 * 60 * 60, 58 | }), 59 | ]); 60 | 61 | schemaCoverage(MethodReturnType, data); 62 | }); 63 | -------------------------------------------------------------------------------- /tests/clients/exchange/usdClassTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("usdClassTransfer", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await Promise.all([ 32 | // Check argument 'toPerp' 33 | exchClient.usdClassTransfer({ amount: "1", toPerp: false }), 34 | exchClient.usdClassTransfer({ amount: "1", toPerp: true }), 35 | ]); 36 | 37 | schemaCoverage(MethodReturnType, data); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/exchange/usdSend.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const DESTINATION_ADDRESS = "0x0000000000000000000000000000000000000000"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("usdSend", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await exchClient.usdSend({ destination: DESTINATION_ADDRESS, amount: "1" }); 33 | 34 | schemaCoverage(MethodReturnType, [data]); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/clients/exchange/vaultDistribute.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const VAULT_ADDRESS = "0xd0d0eb5de91f14e53312adf92cabcbbfd2b4f24f"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("vaultDistribute", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await exchClient.vaultDistribute({ 33 | vaultAddress: VAULT_ADDRESS, 34 | usd: 10 * 1e6, 35 | }); 36 | 37 | schemaCoverage(MethodReturnType, [data]); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/exchange/vaultModify.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const VAULT_ADDRESS = "0xd0d0eb5de91f14e53312adf92cabcbbfd2b4f24f"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("vaultModify", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await Promise.all([ 33 | // Check without arguments 34 | exchClient.vaultModify({ 35 | vaultAddress: VAULT_ADDRESS, 36 | allowDeposits: null, 37 | alwaysCloseOnWithdraw: null, 38 | }), 39 | // Check argument 'allowDeposits' 40 | exchClient.vaultModify({ 41 | vaultAddress: VAULT_ADDRESS, 42 | allowDeposits: true, 43 | alwaysCloseOnWithdraw: null, 44 | }), 45 | exchClient.vaultModify({ 46 | vaultAddress: VAULT_ADDRESS, 47 | allowDeposits: false, 48 | alwaysCloseOnWithdraw: null, 49 | }), 50 | // Check argument 'alwaysCloseOnWithdraw' 51 | exchClient.vaultModify({ 52 | vaultAddress: VAULT_ADDRESS, 53 | allowDeposits: null, 54 | alwaysCloseOnWithdraw: true, 55 | }), 56 | exchClient.vaultModify({ 57 | vaultAddress: VAULT_ADDRESS, 58 | allowDeposits: null, 59 | alwaysCloseOnWithdraw: false, 60 | }), 61 | ]); 62 | 63 | schemaCoverage(MethodReturnType, data); 64 | }); 65 | -------------------------------------------------------------------------------- /tests/clients/exchange/vaultTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const VAULT_ADDRESS = "0xd0d0eb5de91f14e53312adf92cabcbbfd2b4f24f"; 13 | 14 | // —————————— Type schema —————————— 15 | 16 | export type MethodReturnType = Awaited>; 17 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 18 | 19 | // —————————— Test —————————— 20 | 21 | Deno.test("vaultTransfer", { ignore: !PRIVATE_KEY }, async () => { 22 | await new Promise((r) => setTimeout(r, args.wait)); 23 | 24 | // —————————— Prepare —————————— 25 | 26 | const account = privateKeyToAccount(PRIVATE_KEY); 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 29 | 30 | // —————————— Test —————————— 31 | 32 | // Check argument 'isDeposit' + argument 'expiresAfter' 33 | const data1 = await exchClient.vaultTransfer({ 34 | vaultAddress: VAULT_ADDRESS, 35 | isDeposit: false, 36 | usd: 5 * 1e6, 37 | }); 38 | const data2 = await exchClient.vaultTransfer({ 39 | vaultAddress: VAULT_ADDRESS, 40 | isDeposit: true, 41 | usd: 5 * 1e6, 42 | expiresAfter: Date.now() + 1000 * 60 * 60, 43 | }); 44 | 45 | schemaCoverage(MethodReturnType, [data1, data2]); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/exchange/withdraw3.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("withdraw3", { ignore: !PRIVATE_KEY }, async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const account = privateKeyToAccount(PRIVATE_KEY); 26 | const transport = new HttpTransport({ isTestnet: true }); 27 | const exchClient = new ExchangeClient({ wallet: account, transport, isTestnet: true }); 28 | 29 | // —————————— Test —————————— 30 | 31 | const data = await exchClient.withdraw3({ 32 | amount: "2", 33 | destination: exchClient.wallet.address, 34 | }); 35 | 36 | schemaCoverage(MethodReturnType, [data]); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/clients/info/allMids.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("allMids", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await Promise.all([ 28 | infoClient.allMids(), 29 | infoClient.allMids({ dex: "test" }), 30 | ]); 31 | 32 | schemaCoverage(MethodReturnType, data); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/clients/info/blockDetails.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const BLOCK_HEIGHT = 300836507; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("blockDetails", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.blockDetails({ height: BLOCK_HEIGHT }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/candleSnapshot.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("candleSnapshot", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await Promise.all([ 28 | infoClient.candleSnapshot({ 29 | coin: "BTC", 30 | interval: "15m", 31 | startTime: Date.now() - 1000 * 60 * 60 * 24, 32 | }), 33 | // Check argument 'endTime' 34 | infoClient.candleSnapshot({ 35 | coin: "BTC", 36 | interval: "15m", 37 | startTime: Date.now() - 1000 * 60 * 60 * 24, 38 | endTime: Date.now(), 39 | }), 40 | infoClient.candleSnapshot({ 41 | coin: "BTC", 42 | interval: "15m", 43 | startTime: Date.now() - 1000 * 60 * 60 * 24, 44 | endTime: null, 45 | }), 46 | infoClient.candleSnapshot({ 47 | coin: "BTC", 48 | interval: "15m", 49 | startTime: Date.now() - 1000 * 60 * 60 * 24, 50 | endTime: undefined, 51 | }), 52 | ]); 53 | 54 | schemaCoverage(MethodReturnType, data); 55 | }); 56 | -------------------------------------------------------------------------------- /tests/clients/info/clearinghouseState.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("clearinghouseState", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.clearinghouseState({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/delegations.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("delegations", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.delegations({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/delegatorHistory.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0xedc88158266c50628a9ffbaa1db2635376577eea"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("delegatorHistory", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.delegatorHistory({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/delegatorRewards.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const DELEGATION_ADDRESS = "0xedc88158266c50628a9ffbaa1db2635376577eea"; 11 | const COMMISSION_ADDRESS = "0x3c83a5cae32a05e88ca6a0350edb540194851a76"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("delegatorRewards", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new HttpTransport({ isTestnet: true }); 26 | const infoClient = new InfoClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await Promise.all([ 31 | infoClient.delegatorRewards({ user: DELEGATION_ADDRESS }), 32 | infoClient.delegatorRewards({ user: COMMISSION_ADDRESS }), 33 | ]); 34 | 35 | schemaCoverage(MethodReturnType, data); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/info/delegatorSummary.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("delegatorSummary", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.delegatorSummary({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/extraAgents.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("extraAgents", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.extraAgents({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/frontendOpenOrders.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("frontendOpenOrders", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.frontendOpenOrders({ user: USER_ADDRESS }), 31 | infoClient.frontendOpenOrders({ user: USER_ADDRESS, dex: "test" }), 32 | ]); 33 | 34 | schemaCoverage(MethodReturnType, data, { 35 | ignoreEnumValuesByPath: { 36 | "#/items/properties/orderType": ["Market"], 37 | "#/items/properties/tif/anyOf/0": ["Ioc", "FrontendMarket", "LiquidationMarket"], 38 | }, 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/clients/info/fundingHistory.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("fundingHistory", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await Promise.all([ 28 | infoClient.fundingHistory({ 29 | coin: "BTC", 30 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 31 | }), 32 | // Check argument 'endTime' 33 | infoClient.fundingHistory({ 34 | coin: "BTC", 35 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 36 | endTime: Date.now(), 37 | }), 38 | infoClient.fundingHistory({ 39 | coin: "BTC", 40 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 41 | endTime: null, 42 | }), 43 | infoClient.fundingHistory({ 44 | coin: "BTC", 45 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 46 | endTime: undefined, 47 | }), 48 | ]); 49 | 50 | schemaCoverage(MethodReturnType, data); 51 | }); 52 | -------------------------------------------------------------------------------- /tests/clients/info/historicalOrders.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("historicalOrders", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.historicalOrders({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data], { 32 | ignoreEnumValuesByPath: { 33 | "#/items/properties/status": [ 34 | "delistedCanceled", 35 | "liquidatedCanceled", 36 | "marginCanceled", 37 | "openInterestCapCanceled", 38 | "scheduledCancel", 39 | "selfTradeCanceled", 40 | "siblingFilledCanceled", 41 | "vaultWithdrawalCanceled", 42 | "reduceOnlyRejected", 43 | ], 44 | }, 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/info/isVip.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("isVip", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.isVip({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/l2Book.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("l2Book", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await Promise.all([ 28 | infoClient.l2Book({ coin: "BTC" }), 29 | // Check argument 'nSigFigs' 30 | infoClient.l2Book({ coin: "BTC", nSigFigs: 2 }), 31 | infoClient.l2Book({ coin: "BTC", nSigFigs: 3 }), 32 | infoClient.l2Book({ coin: "BTC", nSigFigs: 4 }), 33 | infoClient.l2Book({ coin: "BTC", nSigFigs: 5 }), 34 | infoClient.l2Book({ coin: "BTC", nSigFigs: null }), 35 | infoClient.l2Book({ coin: "BTC", nSigFigs: undefined }), 36 | // Check argument 'mantissa' 37 | infoClient.l2Book({ coin: "BTC", nSigFigs: 5, mantissa: 2 }), 38 | infoClient.l2Book({ coin: "BTC", nSigFigs: 5, mantissa: 5 }), 39 | infoClient.l2Book({ coin: "BTC", nSigFigs: 5, mantissa: null }), 40 | infoClient.l2Book({ coin: "BTC", nSigFigs: 5, mantissa: undefined }), 41 | ]); 42 | 43 | schemaCoverage(MethodReturnType, data); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/info/legalCheck.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("legalCheck", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.legalCheck({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/maxBuilderFee.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const BUILDER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("maxBuilderFee", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.maxBuilderFee({ user: BUILDER_ADDRESS, builder: BUILDER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/meta.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("meta", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await Promise.all([ 28 | infoClient.meta(), 29 | infoClient.meta({ dex: "test" }), 30 | ]); 31 | 32 | schemaCoverage(MethodReturnType, data); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/clients/info/metaAndAssetCtxs.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("metaAndAssetCtxs", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.metaAndAssetCtxs(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/openOrders.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("openOrders", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.openOrders({ user: USER_ADDRESS }), 31 | infoClient.openOrders({ user: USER_ADDRESS, dex: "test" }), 32 | ]); 33 | 34 | schemaCoverage(MethodReturnType, data); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/clients/info/perpDeployAuctionStatus.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("perpDeployAuctionStatus", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.perpDeployAuctionStatus(); 28 | 29 | schemaCoverage(MethodReturnType, [data], { 30 | ignoreTypesByPath: { 31 | "#/properties/currentGas": ["string", "null"], 32 | "#/properties/endGas": ["string", "null"], 33 | }, 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/clients/info/perpDex.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("perpDex", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.perpDexs(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/perpsAtOpenInterestCap.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("perpsAtOpenInterestCap", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.perpsAtOpenInterestCap(); 28 | 29 | schemaCoverage(MethodReturnType, [data], { 30 | ignoreEmptyArrayPaths: ["#"], 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/portfolio.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("portfolio", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.portfolio({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/preTransferCheck.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("preTransferCheck", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.preTransferCheck({ user: USER_ADDRESS, source: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/predictedFundings.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("predictedFundings", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.predictedFundings(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/referral.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const NON_REFERRED = "0x0000000000000000000000000000000000000000"; 11 | const REFERRED = "0x091288cd1e81e065d1541ec73dd0dfdde2f529fa"; 12 | const STATE_READY = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 13 | const STATE_NEED_TO_CREATE_CODE = "0x97c36726668f490fa17eb2957a92D39116f171fE"; 14 | const STATE_NEED_TO_TRADE = "0x0000000000000000000000000000000000000000"; 15 | const REWARD_HISTORY = "0x745d208c08be6743481cdaf5984956be87ec5a3f"; // Mainnet 16 | 17 | // —————————— Type schema —————————— 18 | 19 | export type MethodReturnType = Awaited>; 20 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 21 | 22 | // —————————— Test —————————— 23 | 24 | Deno.test("referral", async () => { 25 | await new Promise((r) => setTimeout(r, args.wait)); 26 | 27 | // —————————— Prepare —————————— 28 | 29 | const infoClient = new InfoClient({ transport: new HttpTransport({ isTestnet: true }) }); 30 | const mainnetClient = new InfoClient({ transport: new HttpTransport({ isTestnet: false }) }); 31 | 32 | // —————————— Test —————————— 33 | 34 | const data = await Promise.all([ 35 | infoClient.referral({ user: NON_REFERRED }), 36 | infoClient.referral({ user: REFERRED }), 37 | infoClient.referral({ user: STATE_READY }), 38 | infoClient.referral({ user: STATE_NEED_TO_CREATE_CODE }), 39 | infoClient.referral({ user: STATE_NEED_TO_TRADE }), 40 | mainnetClient.referral({ user: REWARD_HISTORY }), 41 | ]); 42 | 43 | schemaCoverage(MethodReturnType, data); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/info/spotClearinghouseState.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | const USER_ADDRESS_evmEscrows = "0x1defed46db35334232b9f5fd2e5c6180276fb99d"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("spotClearinghouseState", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new HttpTransport({ isTestnet: true }); 26 | const infoClient = new InfoClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await Promise.all([ 31 | infoClient.spotClearinghouseState({ user: USER_ADDRESS }), 32 | infoClient.spotClearinghouseState({ user: USER_ADDRESS, dex: "test" }), 33 | infoClient.spotClearinghouseState({ user: USER_ADDRESS_evmEscrows }), 34 | ]); 35 | 36 | schemaCoverage(MethodReturnType, data); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/clients/info/spotDeployState.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const STATES_FULL_NAME_STRING = "0x051dbfc562d44e4a01ebb986da35a47ab4f346db"; 11 | const STATES_FULL_NAME_NULL = "0xd8cb8d9747f50be8e423c698f9104ee090540961"; 12 | const STATES_MAX_SUPPLY_STRING = "0x051dbfc562d44e4a01ebb986da35a47ab4f346db"; 13 | const STATES_MAX_SUPPLY_NULL = "0xd8cb8d9747f50be8e423c698f9104ee090540961"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("spotDeployState", async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const transport = new HttpTransport({ isTestnet: true }); 28 | const infoClient = new InfoClient({ transport }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await Promise.all([ 33 | infoClient.spotDeployState({ user: STATES_FULL_NAME_STRING }), 34 | infoClient.spotDeployState({ user: STATES_FULL_NAME_NULL }), 35 | infoClient.spotDeployState({ user: STATES_MAX_SUPPLY_STRING }), 36 | infoClient.spotDeployState({ user: STATES_MAX_SUPPLY_NULL }), 37 | ]); 38 | 39 | schemaCoverage(MethodReturnType, data, { 40 | ignoreEmptyArrayPaths: [ 41 | "#/properties/states/items/properties/blacklistUsers", 42 | ], 43 | ignoreTypesByPath: { 44 | "#/properties/gasAuction/properties/currentGas": ["string", "null"], 45 | "#/properties/gasAuction/properties/endGas": ["string", "null"], 46 | }, 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /tests/clients/info/spotMeta.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("spotMeta", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.spotMeta(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/spotMetaAndAssetCtxs.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("spotMetaAndAssetCtxs", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.spotMetaAndAssetCtxs(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/subAccounts.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | const USER_ADDRESS_WITHOUT_SUBACCOUNTS = "0x0000000000000000000000000000000000000000"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("subAccounts", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new HttpTransport({ isTestnet: true }); 26 | const infoClient = new InfoClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await Promise.all([ 31 | infoClient.subAccounts({ user: USER_ADDRESS_WITHOUT_SUBACCOUNTS }), 32 | infoClient.subAccounts({ user: USER_ADDRESS }), 33 | ]); 34 | 35 | schemaCoverage(MethodReturnType, data, { 36 | ignoreBranchesByPath: { 37 | "#/anyOf/0/items/properties/clearinghouseState/properties/assetPositions/items/properties/position/properties/leverage/anyOf": 38 | [0], 39 | }, 40 | ignoreTypesByPath: { 41 | "#/anyOf/0/items/properties/clearinghouseState/properties/assetPositions/items/properties/position/properties/liquidationPx": 42 | ["string"], 43 | }, 44 | ignorePropertiesByPath: [ 45 | "#/anyOf/0/items/properties/spotState/properties/evmEscrows", 46 | ], 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /tests/clients/info/tokenDetails.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const TOKEN_ID_WITH_GENESIS = "0x3d8a82efa63e86d54a1922c2afdac61e"; 11 | const TOKEN_ID_WITHOUT_GENESIS = "0xc4bf3f870c0e9465323c0b6ed28096c2"; 12 | 13 | const TOKEN_ID_WITH_DEPLOYER = "0x3d8a82efa63e86d54a1922c2afdac61e"; 14 | const TOKEN_ID_WITHOUT_DEPLOYER = "0xc4bf3f870c0e9465323c0b6ed28096c2"; 15 | 16 | const TOKEN_ID_WITH_DEPLOY_GAS = "0x3d8a82efa63e86d54a1922c2afdac61e"; 17 | const TOKEN_ID_WITHOUT_DEPLOY_GAS = "0xeb62eee3685fc4c43992febcd9e75443"; 18 | 19 | const TOKEN_ID_WITH_DEPLOY_TIME = "0x3d8a82efa63e86d54a1922c2afdac61e"; 20 | const TOKEN_ID_WITHOUT_DEPLOY_TIME = "0xc4bf3f870c0e9465323c0b6ed28096c2"; 21 | 22 | // —————————— Type schema —————————— 23 | 24 | export type MethodReturnType = Awaited>; 25 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 26 | 27 | // —————————— Test —————————— 28 | 29 | Deno.test("tokenDetails", async () => { 30 | await new Promise((r) => setTimeout(r, args.wait)); 31 | 32 | // —————————— Prepare —————————— 33 | 34 | const transport = new HttpTransport({ isTestnet: true }); 35 | const infoClient = new InfoClient({ transport }); 36 | 37 | // —————————— Test —————————— 38 | 39 | const data = await Promise.all([ 40 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITH_GENESIS }), 41 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITHOUT_GENESIS }), 42 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITH_DEPLOYER }), 43 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITHOUT_DEPLOYER }), 44 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITH_DEPLOY_GAS }), 45 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITHOUT_DEPLOY_GAS }), 46 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITH_DEPLOY_TIME }), 47 | infoClient.tokenDetails({ tokenId: TOKEN_ID_WITHOUT_DEPLOY_TIME }), 48 | ]); 49 | 50 | schemaCoverage(MethodReturnType, data, { 51 | ignoreEmptyArrayPaths: [ 52 | "#/properties/genesis/anyOf/0/properties/blacklistUsers", 53 | ], 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /tests/clients/info/twapHistory.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("twapHistory", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.twapHistory({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/txDetails.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const TX_HASH_WITH_ERROR = "0x8f1b2b67eda04ecbc7b00411ee669b010c0041e8f52c9ff5c3609d9ef7e66c71"; 11 | const TX_HASH_WITHOUT_ERROR = "0x4de9f1f5d912c23d8fbb0411f01bfe0000eb9f3ccb3fec747cb96e75e8944b06"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("txDetails", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new HttpTransport({ isTestnet: true }); 26 | const infoClient = new InfoClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await Promise.all([ 31 | infoClient.txDetails({ hash: TX_HASH_WITH_ERROR }), 32 | infoClient.txDetails({ hash: TX_HASH_WITHOUT_ERROR }), 33 | ]); 34 | 35 | schemaCoverage(MethodReturnType, data); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/info/userDetails.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userDetails", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.userDetails({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data], { 32 | ignoreTypesByPath: { 33 | "#/properties/txs/items/properties/error": ["string"], 34 | }, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/info/userFees.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0xe973105a27e17350500926ae664dfcfe6006d924"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userFees", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.userFees({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/userFills.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userFills", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.userFills({ user: USER_ADDRESS }), 31 | // Check argument 'aggregateByTime' 32 | infoClient.userFills({ user: USER_ADDRESS, aggregateByTime: true }), 33 | infoClient.userFills({ user: USER_ADDRESS, aggregateByTime: false }), 34 | infoClient.userFills({ user: USER_ADDRESS, aggregateByTime: undefined }), 35 | ]); 36 | 37 | schemaCoverage(MethodReturnType, data); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/info/userFillsByTime.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userFillsByTime", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.userFillsByTime({ 31 | user: USER_ADDRESS, 32 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 33 | }), 34 | // Check argument 'endTime' 35 | infoClient.userFillsByTime({ 36 | user: USER_ADDRESS, 37 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 38 | endTime: Date.now(), 39 | }), 40 | infoClient.userFillsByTime({ 41 | user: USER_ADDRESS, 42 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 43 | endTime: null, 44 | }), 45 | infoClient.userFillsByTime({ 46 | user: USER_ADDRESS, 47 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 48 | endTime: undefined, 49 | }), 50 | ]); 51 | 52 | schemaCoverage(MethodReturnType, data); 53 | }); 54 | -------------------------------------------------------------------------------- /tests/clients/info/userFunding.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userFunding", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.userFunding({ 31 | user: USER_ADDRESS, 32 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 33 | }), 34 | // Check argument 'endTime' 35 | infoClient.userFunding({ 36 | user: USER_ADDRESS, 37 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 38 | endTime: Date.now(), 39 | }), 40 | infoClient.userFunding({ 41 | user: USER_ADDRESS, 42 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 43 | endTime: null, 44 | }), 45 | infoClient.userFunding({ 46 | user: USER_ADDRESS, 47 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 48 | endTime: undefined, 49 | }), 50 | ]); 51 | 52 | schemaCoverage(MethodReturnType, data); 53 | }); 54 | -------------------------------------------------------------------------------- /tests/clients/info/userNonFundingLedgerUpdates.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userNonFundingLedgerUpdates", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await Promise.all([ 30 | infoClient.userNonFundingLedgerUpdates({ 31 | user: USER_ADDRESS, 32 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 33 | }), 34 | // Check argument 'endTime' 35 | infoClient.userNonFundingLedgerUpdates({ 36 | user: USER_ADDRESS, 37 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 38 | endTime: Date.now(), 39 | }), 40 | infoClient.userNonFundingLedgerUpdates({ 41 | user: USER_ADDRESS, 42 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 43 | endTime: null, 44 | }), 45 | infoClient.userNonFundingLedgerUpdates({ 46 | user: USER_ADDRESS, 47 | startTime: Date.now() - 1000 * 60 * 60 * 24 * 365, 48 | endTime: undefined, 49 | }), 50 | ]); 51 | 52 | schemaCoverage(MethodReturnType, data, { 53 | ignoreEnumValuesByPath: { 54 | "#/items/properties/delta/anyOf/3/properties/leverageType": ["Cross"], 55 | }, 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /tests/clients/info/userRateLimit.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userRateLimit", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.userRateLimit({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/userRole.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const ROLE_MISSING = "0x941a505ACc11F5f3A12b5eF0d414A8Bff45c5e77"; 11 | const ROLE_USER = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | const ROLE_AGENT = "0xDF1bC1bA4242a47f2AeC1Cd52F9E24b243107a34"; 13 | const ROLE_VAULT = "0xd0d0eb5de91f14e53312adf92cabcbbfd2b4f24f"; 14 | const ROLE_SUB_ACCOUNT = "0x22a454d3322060475552e8f922ec0c778b8e5760"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("userRole", async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const infoClient = new InfoClient({ transport }); 30 | 31 | // —————————— Test —————————— 32 | 33 | const data = await Promise.all([ 34 | infoClient.userRole({ user: ROLE_MISSING }), 35 | infoClient.userRole({ user: ROLE_USER }), 36 | infoClient.userRole({ user: ROLE_AGENT }), 37 | infoClient.userRole({ user: ROLE_VAULT }), 38 | infoClient.userRole({ user: ROLE_SUB_ACCOUNT }), 39 | ]); 40 | 41 | schemaCoverage(MethodReturnType, data); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/info/userToMultiSigSigners.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS_WITH_MULTISIG_SIGNERS = "0x7A8b673a176a430b80cfCDfdFB6b10ED55010Ebb"; 11 | const USER_ADDRESS_WITHOUT_MULTISIG_SIGNERS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Awaited>; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userToMultiSigSigners", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new HttpTransport({ isTestnet: true }); 26 | const infoClient = new InfoClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await Promise.all([ 31 | infoClient.userToMultiSigSigners({ user: USER_ADDRESS_WITHOUT_MULTISIG_SIGNERS }), 32 | infoClient.userToMultiSigSigners({ user: USER_ADDRESS_WITH_MULTISIG_SIGNERS }), 33 | ]); 34 | 35 | schemaCoverage(MethodReturnType, data); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/info/userTwapSliceFills.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userTwapSliceFills", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.userTwapSliceFills({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/userVaultEquities.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const USER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 11 | 12 | // —————————— Type schema —————————— 13 | 14 | export type MethodReturnType = Awaited>; 15 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 16 | 17 | // —————————— Test —————————— 18 | 19 | Deno.test("userVaultEquities", async () => { 20 | await new Promise((r) => setTimeout(r, args.wait)); 21 | 22 | // —————————— Prepare —————————— 23 | 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const infoClient = new InfoClient({ transport }); 26 | 27 | // —————————— Test —————————— 28 | 29 | const data = await infoClient.userVaultEquities({ user: USER_ADDRESS }); 30 | 31 | schemaCoverage(MethodReturnType, [data]); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/clients/info/validatorSummaries.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("validatorSummaries", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.validatorSummaries(); 28 | 29 | schemaCoverage(MethodReturnType, [data]); 30 | }); 31 | -------------------------------------------------------------------------------- /tests/clients/info/vaultDetails.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | const INVALID_VAULT_ADDRESS = "0x0000000000000000000000000000000000000000"; 11 | const VAULT_ADDRESS_WITH_NORMAL_RELATIONSHIP = "0x1719884eb866cb12b2287399b15f7db5e7d775ea"; 12 | const VAULT_ADDRESS_WITH_PARENT_RELATIONSHIP = "0xa15099a30bbf2e68942d6f4c43d70d04faeab0a0"; 13 | const VAULT_ADDRESS_WITH_PARENT_RELATIONSHIP_USER = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 14 | const VAULT_ADDRESS_WITH_CHILD_RELATIONSHIP = "0x768484f7e2ebb675c57838366c02ae99ba2a9b08"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("vaultDetails", async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const infoClient = new InfoClient({ transport }); 30 | 31 | // —————————— Test —————————— 32 | 33 | const data = await Promise.all([ 34 | infoClient.vaultDetails({ vaultAddress: INVALID_VAULT_ADDRESS }), 35 | infoClient.vaultDetails({ vaultAddress: VAULT_ADDRESS_WITH_NORMAL_RELATIONSHIP }), 36 | infoClient.vaultDetails({ 37 | vaultAddress: VAULT_ADDRESS_WITH_PARENT_RELATIONSHIP, 38 | user: VAULT_ADDRESS_WITH_PARENT_RELATIONSHIP_USER, 39 | }), 40 | infoClient.vaultDetails({ vaultAddress: VAULT_ADDRESS_WITH_CHILD_RELATIONSHIP }), 41 | ]); 42 | 43 | schemaCoverage(MethodReturnType, data); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/info/vaultSummaries.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { HttpTransport, InfoClient } from "../../../mod.ts"; 3 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 4 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 5 | 6 | // —————————— Arguments —————————— 7 | 8 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 9 | 10 | // —————————— Type schema —————————— 11 | 12 | export type MethodReturnType = Awaited>; 13 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 14 | 15 | // —————————— Test —————————— 16 | 17 | Deno.test("vaultSummaries", async () => { 18 | await new Promise((r) => setTimeout(r, args.wait)); 19 | 20 | // —————————— Prepare —————————— 21 | 22 | const transport = new HttpTransport({ isTestnet: true }); 23 | const infoClient = new InfoClient({ transport }); 24 | 25 | // —————————— Test —————————— 26 | 27 | const data = await infoClient.vaultSummaries(); 28 | 29 | schemaCoverage(MethodReturnType, [data], { 30 | ignoreBranchesByPath: { 31 | "#/items/properties/relationship/anyOf": [1], 32 | }, 33 | ignoreEnumValuesByPath: { 34 | "#/items/properties/relationship/anyOf/0/properties/type": ["child"], 35 | }, 36 | ignoreEmptyArrayPaths: ["#"], 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/multiSign/approveAgent.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | import { generateEthereumAddress } from "../../_utils/utils.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("approveAgent", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | const data = await Promise.all([ 40 | multiSignClient.approveAgent({ 41 | agentAddress: generateEthereumAddress(), 42 | }), 43 | multiSignClient.approveAgent({ 44 | agentAddress: generateEthereumAddress(), 45 | agentName: null, 46 | }), 47 | multiSignClient.approveAgent({ 48 | agentAddress: generateEthereumAddress(), 49 | agentName: "", 50 | }), 51 | multiSignClient.approveAgent({ 52 | agentAddress: generateEthereumAddress(), 53 | agentName: "agentName", 54 | }), 55 | ]); 56 | 57 | schemaCoverage(MethodReturnType, data); 58 | }); 59 | -------------------------------------------------------------------------------- /tests/clients/multiSign/approveBuilderFee.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("approveBuilderFee", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await multiSignClient.approveBuilderFee({ 39 | maxFeeRate: "0.001%", 40 | builder: MULTI_SIGN_ADDRESS, 41 | }); 42 | 43 | schemaCoverage(MethodReturnType, [data]); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/multiSign/cDeposit.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("cDeposit", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await multiSignClient.cDeposit({ wei: 1 }); 39 | 40 | schemaCoverage(MethodReturnType, [data]); 41 | }); 42 | -------------------------------------------------------------------------------- /tests/clients/multiSign/cSignerAction.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertRejects } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 10 | 11 | const PRIVATE_KEY = args._[0] as Hex; 12 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 13 | 14 | // —————————— Test —————————— 15 | 16 | // NOTE: This API is difficult to test with a successful response. 17 | // So to prove that the method works, we will expect a specific error 18 | Deno.test("cSignerAction", { ignore: !PRIVATE_KEY }, async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const account = privateKeyToAccount(PRIVATE_KEY); 24 | const transport = new HttpTransport({ isTestnet: true }); 25 | const multiSignClient = new MultiSignClient({ 26 | transport, 27 | multiSignAddress: MULTI_SIGN_ADDRESS, 28 | signers: [account], 29 | isTestnet: true, 30 | }); 31 | 32 | // —————————— Test —————————— 33 | 34 | await Promise.all([ 35 | assertRejects( 36 | () => multiSignClient.cSignerAction({ jailSelf: null }), 37 | ApiRequestError, 38 | "Signer invalid or inactive for current epoch", 39 | ), 40 | assertRejects( 41 | () => multiSignClient.cSignerAction({ unjailSelf: null }), 42 | ApiRequestError, 43 | "Signer invalid or inactive for current epoch", 44 | ), 45 | ]); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/cWithdraw.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("cWithdraw", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await multiSignClient.cWithdraw({ wei: 1 }); 39 | 40 | schemaCoverage(MethodReturnType, [data]); 41 | }); 42 | -------------------------------------------------------------------------------- /tests/clients/multiSign/claimRewards.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("claimRewards", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await multiSignClient.claimRewards() 40 | .then((data) => { 41 | schemaCoverage(MethodReturnType, [data]); 42 | }) 43 | .catch((e) => { 44 | assertIsError(e, ApiRequestError, "No rewards to claim"); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/convertToMultiSigUser.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { generatePrivateKey, privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { ExchangeClient, type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("convertToMultiSigUser", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // Preparing a temporary wallet 37 | const tempPrivKey = generatePrivateKey(); 38 | const tempAccount = privateKeyToAccount(tempPrivKey); 39 | const tempExchClient = new ExchangeClient({ wallet: tempAccount, transport, isTestnet: true }); 40 | await multiSignClient.usdSend({ destination: tempAccount.address, amount: "2" }); 41 | 42 | // —————————— Test —————————— 43 | 44 | const data = await tempExchClient.convertToMultiSigUser({ 45 | authorizedUsers: [MULTI_SIGN_ADDRESS], 46 | threshold: 1, 47 | }); 48 | 49 | schemaCoverage(MethodReturnType, [data]); 50 | }); 51 | -------------------------------------------------------------------------------- /tests/clients/multiSign/createSubAccount.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("createSubAccount", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await multiSignClient.createSubAccount({ name: String(Date.now()) }) 40 | .then((data) => { 41 | schemaCoverage(MethodReturnType, [data]); 42 | }) 43 | .catch((e) => { 44 | assertIsError(e, ApiRequestError, "Cannot create sub-accounts until enough volume traded"); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/createVault.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("createVault", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await multiSignClient.createVault({ name: "", description: "", initialUsd: 50 * 1e6 }) 40 | .then((data) => { 41 | schemaCoverage(MethodReturnType, [data]); 42 | }) 43 | .catch((e) => { 44 | assertIsError(e, ApiRequestError, "Initial deposit in vault is less than $100"); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/evmUserModify.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; // Replace with your MultiSign address 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("evmUserModify", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await Promise.all([ 39 | // Check argument 'usingBigBlocks' 40 | multiSignClient.evmUserModify({ usingBigBlocks: true }), 41 | multiSignClient.evmUserModify({ usingBigBlocks: false }), 42 | ]); 43 | 44 | schemaCoverage(MethodReturnType, data); 45 | }); 46 | -------------------------------------------------------------------------------- /tests/clients/multiSign/perpDexClassTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("perpDexClassTransfer", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await Promise.all([ 39 | multiSignClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: true }), 40 | multiSignClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: false }), 41 | ]); 42 | 43 | schemaCoverage(MethodReturnType, data); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/multiSign/registerReferrer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("registerReferrer", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await multiSignClient.registerReferrer({ code: "TEST" }) 40 | .then((data) => { 41 | schemaCoverage(MethodReturnType, [data]); 42 | }) 43 | .catch((e) => { 44 | assertIsError(e, ApiRequestError, "Cannot generate referral code until enough volume traded"); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/reserveRequestWeight.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("reserveRequestWeight", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await Promise.all([ 39 | // Check response 'success' 40 | multiSignClient.reserveRequestWeight({ weight: 1 }), 41 | // Check argument 'expiresAfter' 42 | multiSignClient.reserveRequestWeight({ weight: 1, expiresAfter: Date.now() + 1000 * 60 * 60 }), 43 | ]); 44 | 45 | schemaCoverage(MethodReturnType, data); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/scheduleCancel.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("scheduleCancel", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await Promise.all([ 40 | // Check argument 'time' + argument 'expiresAfter' 41 | multiSignClient.scheduleCancel({ time: Date.now() + 10000 }) 42 | .then((data) => { 43 | schemaCoverage(MethodReturnType, [data]); 44 | }) 45 | .catch((e) => { 46 | assertIsError(e, ApiRequestError, "Cannot set scheduled cancel time until enough volume traded"); 47 | }), 48 | multiSignClient.scheduleCancel({ expiresAfter: Date.now() + 1000 * 60 * 60 }) 49 | .then((data) => { 50 | schemaCoverage(MethodReturnType, [data]); 51 | }) 52 | .catch((e) => { 53 | assertIsError(e, ApiRequestError, "Cannot set scheduled cancel time until enough volume traded"); 54 | }), 55 | ]); 56 | }); 57 | -------------------------------------------------------------------------------- /tests/clients/multiSign/setDisplayName.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("setDisplayName", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await multiSignClient.setDisplayName({ displayName: "" }); 39 | 40 | schemaCoverage(MethodReturnType, [data]); 41 | }); 42 | -------------------------------------------------------------------------------- /tests/clients/multiSign/setReferrer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("setReferrer", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | await multiSignClient.setReferrer({ code: "TEST" }) 40 | .then((data) => { 41 | schemaCoverage(MethodReturnType, [data]); 42 | }) 43 | .catch((e) => { 44 | assertIsError(e, ApiRequestError, "Referrer already set"); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/clients/multiSign/spotSend.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | const DESTINATION_ADDRESS = "0x0000000000000000000000000000000000000000"; 15 | const TOKEN_ADDRESS = "USDC:0xeb62eee3685fc4c43992febcd9e75443"; 16 | 17 | // —————————— Type schema —————————— 18 | 19 | export type MethodReturnType = Awaited>; 20 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 21 | 22 | // —————————— Test —————————— 23 | 24 | Deno.test("spotSend", { ignore: !PRIVATE_KEY }, async () => { 25 | await new Promise((r) => setTimeout(r, args.wait)); 26 | 27 | // —————————— Prepare —————————— 28 | 29 | const account = privateKeyToAccount(PRIVATE_KEY as `0x${string}`); 30 | const transport = new HttpTransport({ isTestnet: true }); 31 | const multiSignClient = new MultiSignClient({ 32 | transport, 33 | multiSignAddress: MULTI_SIGN_ADDRESS, 34 | signers: [account], 35 | isTestnet: true, 36 | }); 37 | 38 | // —————————— Test —————————— 39 | 40 | const data = await multiSignClient.spotSend({ 41 | destination: DESTINATION_ADDRESS, 42 | token: TOKEN_ADDRESS, 43 | amount: "1", 44 | }); 45 | 46 | schemaCoverage(MethodReturnType, [data]); 47 | }); 48 | -------------------------------------------------------------------------------- /tests/clients/multiSign/spotUser.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("spotUser", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data1 = await multiSignClient.spotUser({ toggleSpotDusting: { optOut: true } }); 39 | const data2 = await multiSignClient.spotUser({ toggleSpotDusting: { optOut: false } }); 40 | 41 | schemaCoverage(MethodReturnType, [data1, data2]); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/multiSign/subAccountTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 15 | const SUB_ACCOUNT_ADDRESS = "0xcb3f0bd249a89e45e86a44bcfc7113e4ffe84cd1"; 16 | 17 | // —————————— Type schema —————————— 18 | 19 | export type MethodReturnType = Awaited>; 20 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 21 | 22 | // —————————— Test —————————— 23 | 24 | Deno.test("subAccountTransfer", { ignore: !PRIVATE_KEY }, async () => { 25 | await new Promise((r) => setTimeout(r, args.wait)); 26 | 27 | // —————————— Prepare —————————— 28 | 29 | const account = privateKeyToAccount(PRIVATE_KEY); 30 | const transport = new HttpTransport({ isTestnet: true }); 31 | const multiSignClient = new MultiSignClient({ 32 | transport, 33 | multiSignAddress: MULTI_SIGN_ADDRESS, 34 | signers: [account], 35 | isTestnet: true, 36 | }); 37 | 38 | // —————————— Test —————————— 39 | 40 | await Promise.all([ 41 | // Check argument 'isDeposit' 42 | multiSignClient.subAccountTransfer({ subAccountUser: SUB_ACCOUNT_ADDRESS, isDeposit: true, usd: 1 }) 43 | .then((data) => { 44 | schemaCoverage(MethodReturnType, [data]); 45 | }) 46 | .catch((e) => { 47 | assertIsError(e, ApiRequestError, "Invalid sub-account transfer from"); 48 | }), 49 | multiSignClient.subAccountTransfer({ subAccountUser: SUB_ACCOUNT_ADDRESS, isDeposit: false, usd: 1 }) 50 | .then((data) => { 51 | schemaCoverage(MethodReturnType, [data]); 52 | }) 53 | .catch((e) => { 54 | assertIsError(e, ApiRequestError, "Invalid sub-account transfer from"); 55 | }), 56 | ]); 57 | }); 58 | -------------------------------------------------------------------------------- /tests/clients/multiSign/tokenDelegate.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | const VALIDATOR_ADDRESS = "0xa012b9040d83c5cbad9e6ea73c525027b755f596"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("tokenDelegate", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | // Check argument 'isUndelegate' 40 | const data1 = await multiSignClient.tokenDelegate({ validator: VALIDATOR_ADDRESS, wei: 1, isUndelegate: true }); 41 | const data2 = await multiSignClient.tokenDelegate({ validator: VALIDATOR_ADDRESS, wei: 1, isUndelegate: false }); 42 | 43 | schemaCoverage(MethodReturnType, [data1, data2]); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/multiSign/usdClassTransfer.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("usdClassTransfer", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await Promise.all([ 39 | // Check argument 'toPerp' 40 | multiSignClient.usdClassTransfer({ amount: "1", toPerp: false }), 41 | multiSignClient.usdClassTransfer({ amount: "1", toPerp: true }), 42 | ]); 43 | 44 | schemaCoverage(MethodReturnType, data); 45 | }); 46 | -------------------------------------------------------------------------------- /tests/clients/multiSign/usdSend.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | const DESTINATION_ADDRESS = "0x0000000000000000000000000000000000000000"; 15 | 16 | // —————————— Type schema —————————— 17 | 18 | export type MethodReturnType = Awaited>; 19 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 20 | 21 | // —————————— Test —————————— 22 | 23 | Deno.test("usdSend", { ignore: !PRIVATE_KEY }, async () => { 24 | await new Promise((r) => setTimeout(r, args.wait)); 25 | 26 | // —————————— Prepare —————————— 27 | 28 | const account = privateKeyToAccount(PRIVATE_KEY); 29 | const transport = new HttpTransport({ isTestnet: true }); 30 | const multiSignClient = new MultiSignClient({ 31 | transport, 32 | multiSignAddress: MULTI_SIGN_ADDRESS, 33 | signers: [account], 34 | isTestnet: true, 35 | }); 36 | 37 | // —————————— Test —————————— 38 | 39 | const data = await multiSignClient.usdSend({ destination: DESTINATION_ADDRESS, amount: "1" }); 40 | 41 | schemaCoverage(MethodReturnType, [data]); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/multiSign/vaultDistribute.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { assertIsError } from "jsr:@std/assert@1"; 4 | import { ApiRequestError, type Hex, HttpTransport } from "../../../mod.ts"; 5 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 6 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 7 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 8 | 9 | // —————————— Arguments —————————— 10 | 11 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 12 | 13 | const PRIVATE_KEY = args._[0] as Hex; 14 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 15 | const VAULT_ADDRESS = "0xd0d0eb5de91f14e53312adf92cabcbbfd2b4f24f"; 16 | 17 | // —————————— Type schema —————————— 18 | 19 | export type MethodReturnType = Awaited>; 20 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 21 | 22 | // —————————— Test —————————— 23 | 24 | Deno.test("vaultDistribute", { ignore: !PRIVATE_KEY }, async () => { 25 | await new Promise((r) => setTimeout(r, args.wait)); 26 | 27 | // —————————— Prepare —————————— 28 | 29 | const account = privateKeyToAccount(PRIVATE_KEY); 30 | const transport = new HttpTransport({ isTestnet: true }); 31 | const multiSignClient = new MultiSignClient({ 32 | transport, 33 | multiSignAddress: MULTI_SIGN_ADDRESS, 34 | signers: [account], 35 | isTestnet: true, 36 | }); 37 | 38 | // —————————— Test —————————— 39 | 40 | await multiSignClient.vaultDistribute({ 41 | vaultAddress: VAULT_ADDRESS, 42 | usd: 10 * 1e6, 43 | }) 44 | .then((data) => { 45 | schemaCoverage(MethodReturnType, [data]); 46 | }) 47 | .catch((e) => { 48 | assertIsError(e, ApiRequestError, "Only leader can perform this vault action"); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /tests/clients/multiSign/withdraw3.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { privateKeyToAccount } from "npm:viem@2/accounts"; 3 | import { type Hex, HttpTransport } from "../../../mod.ts"; 4 | import { MultiSignClient } from "../../../src/clients/multiSign.ts"; 5 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 6 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 7 | 8 | // —————————— Arguments —————————— 9 | 10 | const args = parseArgs(Deno.args, { default: { wait: 1500 }, string: ["_"] }) as Args<{ wait: number }>; 11 | 12 | const PRIVATE_KEY = args._[0] as Hex; 13 | const MULTI_SIGN_ADDRESS = "0x9150749C4cec13Dc7c1555D0d664F08d4d81Be83"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Awaited>; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("withdraw3", { ignore: !PRIVATE_KEY }, async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const account = privateKeyToAccount(PRIVATE_KEY); 28 | const transport = new HttpTransport({ isTestnet: true }); 29 | const multiSignClient = new MultiSignClient({ 30 | transport, 31 | multiSignAddress: MULTI_SIGN_ADDRESS, 32 | signers: [account], 33 | isTestnet: true, 34 | }); 35 | 36 | // —————————— Test —————————— 37 | 38 | const data = await multiSignClient.withdraw3({ 39 | amount: "2", 40 | destination: MULTI_SIGN_ADDRESS, 41 | }); 42 | 43 | schemaCoverage(MethodReturnType, [data]); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/clients/subscription/activeAssetCtx.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[1]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("activeAssetCtx", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await Promise.all([ 29 | // Check response 'WsActiveAssetCtx' 30 | deadline( 31 | new Promise((resolve) => { 32 | subsClient.activeAssetCtx({ coin: "BTC" }, resolve); 33 | }), 34 | 10_000, 35 | ), 36 | deadline( 37 | new Promise((resolve) => { 38 | subsClient.activeAssetCtx({ coin: "AXL" }, resolve); 39 | }), 40 | 10_000, 41 | ), 42 | // Check response 'WsActiveSpotAssetCtx' 43 | deadline( 44 | new Promise((resolve) => { 45 | subsClient.activeAssetCtx({ coin: "@107" }, resolve); 46 | }), 47 | 10_000, 48 | ), 49 | deadline( 50 | new Promise((resolve) => { 51 | subsClient.activeAssetCtx({ coin: "@27" }, resolve); 52 | }), 53 | 10_000, 54 | ), 55 | ]); 56 | 57 | schemaCoverage(MethodReturnType, data); 58 | }); 59 | -------------------------------------------------------------------------------- /tests/clients/subscription/activeAssetData.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | const COIN_1 = "GALA"; 13 | const COIN_2 = "NEAR"; 14 | 15 | // —————————— Type schema —————————— 16 | 17 | export type MethodReturnType = Parameters[1]>[0]; 18 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 19 | 20 | // —————————— Test —————————— 21 | 22 | Deno.test("activeAssetData", async () => { 23 | await new Promise((r) => setTimeout(r, args.wait)); 24 | 25 | // —————————— Prepare —————————— 26 | 27 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 28 | await using subsClient = new SubscriptionClient({ transport }); 29 | 30 | // —————————— Test —————————— 31 | 32 | const data = await Promise.all([ 33 | // Check argument 'leverage.type' 34 | deadline( 35 | new Promise((resolve) => { 36 | subsClient.activeAssetData({ coin: COIN_1, user: USER_ADDRESS }, resolve); 37 | }), 38 | 10_000, 39 | ), 40 | deadline( 41 | new Promise((resolve) => { 42 | subsClient.activeAssetData({ coin: COIN_2, user: USER_ADDRESS }, resolve); 43 | }), 44 | 10_000, 45 | ), 46 | ]); 47 | 48 | schemaCoverage(MethodReturnType, data); 49 | }); 50 | -------------------------------------------------------------------------------- /tests/clients/subscription/allMids.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[1]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("allMids", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data1 = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.allMids(resolve); 31 | }), 32 | 10_000, 33 | ); 34 | const data2 = await deadline( 35 | new Promise((resolve) => { 36 | subsClient.allMids({ dex: "test" }, resolve); 37 | }), 38 | 10_000, 39 | ); 40 | 41 | schemaCoverage(MethodReturnType, [data1, data2]); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/subscription/bbo.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[1]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("bbo", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.bbo({ coin: "BTC" }, resolve); 31 | }), 32 | 120_000, 33 | ); 34 | 35 | schemaCoverage(MethodReturnType, [data]); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/subscription/candle.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[1]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("candle", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport(); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.candle({ coin: "BTC", interval: "1m" }, resolve); 31 | }), 32 | 90_000, 33 | ); 34 | 35 | schemaCoverage(MethodReturnType, [data]); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/subscription/explorerBlock.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[0]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("explorerBlock", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://rpc.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.explorerBlock(resolve); 31 | }), 32 | 10_000, 33 | ); 34 | 35 | schemaCoverage(MethodReturnType, [data]); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/clients/subscription/explorerTxs.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[0]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("explorerTxs", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://rpc.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.explorerTxs(resolve); 31 | }), 32 | 10_000, 33 | ); 34 | 35 | schemaCoverage(MethodReturnType, [data], { 36 | ignoreTypesByPath: { 37 | "#/items/properties/error": ["string"], 38 | }, 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/clients/subscription/trades.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | // —————————— Type schema —————————— 12 | 13 | export type MethodReturnType = Parameters[1]>[0]; 14 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 15 | 16 | // —————————— Test —————————— 17 | 18 | Deno.test("trades", async () => { 19 | await new Promise((r) => setTimeout(r, args.wait)); 20 | 21 | // —————————— Prepare —————————— 22 | 23 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 24 | await using subsClient = new SubscriptionClient({ transport }); 25 | 26 | // —————————— Test —————————— 27 | 28 | const data = await deadline( 29 | new Promise((resolve) => { 30 | subsClient.trades({ coin: "BTC" }, resolve); 31 | }), 32 | 10_000, 33 | ); 34 | 35 | schemaCoverage(MethodReturnType, [data], { 36 | ignoreEnumValuesByPath: { 37 | "#/items/properties/side": ["B", "A"], // some of them may be missing 38 | }, 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/clients/subscription/userFills.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Parameters[1]>[0]; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userFills", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 26 | await using subsClient = new SubscriptionClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await deadline( 31 | new Promise((resolve) => { 32 | subsClient.userFills({ user: USER_ADDRESS }, resolve); 33 | }), 34 | 10_000, 35 | ); 36 | 37 | schemaCoverage(MethodReturnType, [data], { 38 | ignorePropertiesByPath: [ 39 | "#/properties/fills/items/properties/liquidation", 40 | ], 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/subscription/userFundings.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0xe019d6167E7e324aEd003d94098496b6d986aB05"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Parameters[1]>[0]; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userFundings", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 26 | await using subsClient = new SubscriptionClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await deadline( 31 | new Promise((resolve) => { 32 | subsClient.userFundings({ user: USER_ADDRESS }, resolve); 33 | }), 34 | 10_000, 35 | ); 36 | 37 | schemaCoverage(MethodReturnType, [data], { 38 | ignoreTypesByPath: { 39 | "#/properties/fundings/items/properties/nSamples": ["number"], 40 | }, 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /tests/clients/subscription/userNonFundingLedgerUpdates.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Parameters[1]>[0]; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userNonFundingLedgerUpdates", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 26 | await using subsClient = new SubscriptionClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await deadline( 31 | new Promise((resolve) => { 32 | subsClient.userNonFundingLedgerUpdates({ user: USER_ADDRESS }, resolve); 33 | }), 34 | 10_000, 35 | ); 36 | 37 | schemaCoverage(MethodReturnType, [data], { 38 | ignoreBranchesByPath: { 39 | "#/properties/nonFundingLedgerUpdates/items/properties/delta/anyOf": [1, 3, 4, 5, 6, 7, 8, 10, 11], 40 | }, 41 | ignoreEnumValuesByPath: { 42 | "#/properties/nonFundingLedgerUpdates/items/properties/delta/anyOf/3/properties/leverageType": ["Cross"], 43 | }, 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /tests/clients/subscription/userTwapHistory.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Parameters[1]>[0]; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userTwapHistory", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 26 | await using subsClient = new SubscriptionClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await deadline( 31 | new Promise((resolve) => { 32 | subsClient.userTwapHistory({ user: USER_ADDRESS }, resolve); 33 | }), 34 | 10_000, 35 | ); 36 | 37 | schemaCoverage(MethodReturnType, [data]); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/clients/subscription/userTwapSliceFills.test.ts: -------------------------------------------------------------------------------- 1 | import { type Args, parseArgs } from "jsr:@std/cli@1/parse-args"; 2 | import { deadline } from "jsr:@std/async@1/deadline"; 3 | import { SubscriptionClient, WebSocketTransport } from "../../../mod.ts"; 4 | import { schemaGenerator } from "../../_utils/schema/schemaGenerator.ts"; 5 | import { schemaCoverage } from "../../_utils/schema/schemaCoverage.ts"; 6 | 7 | // —————————— Arguments —————————— 8 | 9 | const args = parseArgs(Deno.args, { default: { wait: 1500 } }) as Args<{ wait?: number }>; 10 | 11 | const USER_ADDRESS = "0x563C175E6f11582f65D6d9E360A618699DEe14a9"; 12 | 13 | // —————————— Type schema —————————— 14 | 15 | export type MethodReturnType = Parameters[1]>[0]; 16 | const MethodReturnType = schemaGenerator(import.meta.url, "MethodReturnType"); 17 | 18 | // —————————— Test —————————— 19 | 20 | Deno.test("userTwapSliceFills", async () => { 21 | await new Promise((r) => setTimeout(r, args.wait)); 22 | 23 | // —————————— Prepare —————————— 24 | 25 | const transport = new WebSocketTransport({ url: "wss://api.hyperliquid-testnet.xyz/ws" }); 26 | await using subsClient = new SubscriptionClient({ transport }); 27 | 28 | // —————————— Test —————————— 29 | 30 | const data = await deadline( 31 | new Promise((resolve) => { 32 | subsClient.userTwapSliceFills({ user: USER_ADDRESS }, resolve); 33 | }), 34 | 10_000, 35 | ); 36 | 37 | schemaCoverage(MethodReturnType, [data]); 38 | }); 39 | --------------------------------------------------------------------------------