@ambitlabs/hyperliquid-sdk
Advanced tools
Comparing version 0.0.2-beta4 to 0.0.2-beta5
@@ -15,8 +15,9 @@ import { HyperliquidEnvironment } from './constants'; | ||
}; | ||
export type SpotUserAction = Action<'spotUser'> & { | ||
classTransfer: { | ||
usdc: bigint; | ||
toPerp: boolean; | ||
}; | ||
export type EvmUserModifyAction = Action<'evmUserModify'> & { | ||
usingBigBlocks: boolean; | ||
}; | ||
export type UsdClassTransferAction = Action<'usdClassTransfer'> & { | ||
amount: string; | ||
toPerp: boolean; | ||
}; | ||
export type VaultTransferAction = Action<'vaultTransfer'> & { | ||
@@ -120,3 +121,3 @@ vaultAddress: string; | ||
export type SpotDeployAction = RegisterToken2Action | UserGenesisAction | RegisterSpotAction | RegisterHyperliquidityAction | GenesisAction | SetEvmContractAction; | ||
export type HyperliquidL1Action = SpotUserAction | VaultTransferAction | OrderAction | SpotDeployAction; | ||
export type HyperliquidL1Action = EvmUserModifyAction | UsdClassTransferAction | VaultTransferAction | OrderAction | SpotDeployAction; | ||
export type HyperliquidUserAction = SpotSendAction; | ||
@@ -123,0 +124,0 @@ export type HyperliquidAction = HyperliquidL1Action | HyperliquidUserAction; |
@@ -24,3 +24,3 @@ "use strict"; | ||
}; | ||
// console.log(action); | ||
//console.log(action); | ||
const url = [this.endpoint, 'exchange'].join('/'); | ||
@@ -36,6 +36,24 @@ const response = await fetch(url, options); | ||
case 'order': | ||
case 'spotUser': | ||
case 'vaultTransfer': | ||
case 'spotDeploy': | ||
case 'evmUserModify': | ||
return [action, await this.signer.signL1Action(action, null, nonce)]; | ||
case 'usdClassTransfer': | ||
action = { | ||
...action, | ||
nonce, | ||
signatureChainId: `0x${this.signatureChainId.toString(16)}`, | ||
hyperliquidChain: this.environment === 'mainnet' ? 'Mainnet' : 'Testnet', | ||
}; | ||
return [ | ||
action, | ||
await this.signer.signUserAction(action, { | ||
'HyperliquidTransaction:UsdClassTransfer': [ | ||
{ name: 'hyperliquidChain', type: 'string' }, | ||
{ name: 'amount', type: 'string' }, | ||
{ name: 'toPerp', type: 'bool' }, | ||
{ name: 'nonce', type: 'uint64' }, | ||
], | ||
}), | ||
]; | ||
case 'spotSend': | ||
@@ -42,0 +60,0 @@ action = { |
import { ExchangeEndpoint, HyperliquidAction, SpotDeployAction } from './ExchangeEndpoint'; | ||
import { AllMidsResponse, ClearingHouseStateResponse, InfoEndpoint, SpotMetaResponse, VaultDetailsResponse } from './InfoEndpoint'; | ||
import { AllMidsResponse, ClearingHouseStateResponse, InfoEndpoint, SpotMetaResponse, UserVaultEquitiesResponse, VaultDetailsResponse } from './InfoEndpoint'; | ||
import { Price } from './Price'; | ||
@@ -12,2 +12,11 @@ import { TypedDataSigner } from './Signer'; | ||
}; | ||
type UsdClassTransferOptions = { | ||
amount: string; | ||
toPerp: boolean; | ||
}; | ||
type VaultTransferOptions = { | ||
vaultAddress: string; | ||
isDeposit: boolean; | ||
usd: number; | ||
}; | ||
type MarketOrderOptions = { | ||
@@ -24,2 +33,5 @@ buyOrSell: 'buy' | 'sell'; | ||
}; | ||
type UserVaultEquitiesOptions = { | ||
user: string; | ||
}; | ||
type RegisterToken2Options = Extract<SpotDeployAction, { | ||
@@ -79,2 +91,3 @@ registerToken2: any; | ||
fetchVaultDetails(options: VaultDetailsOptions): Promise<VaultDetailsResponse>; | ||
fetchUserVaultEquities(options: UserVaultEquitiesOptions): Promise<UserVaultEquitiesResponse>; | ||
executeOrThrow<TResponse>(action: HyperliquidAction): Promise<TResponse>; | ||
@@ -89,3 +102,6 @@ spotDeployer(): { | ||
}; | ||
evmUserModifiy(usingBigBlocks: boolean): Promise<unknown>; | ||
spotSend(options: SpotSendOptions): Promise<unknown>; | ||
usdClassTransfer(options: UsdClassTransferOptions): Promise<unknown>; | ||
vaultTransfer(options: VaultTransferOptions): Promise<unknown>; | ||
marketOrder(options: MarketOrderOptions): Promise<{ | ||
@@ -92,0 +108,0 @@ error: string; |
@@ -35,2 +35,5 @@ "use strict"; | ||
} | ||
// async fetchPortfolio() { | ||
// return this.info.fetch<any>({ type: 'portfolio' }); | ||
// } | ||
async fetchClearinghouseState(user) { | ||
@@ -62,2 +65,8 @@ const response = await this.info.fetch({ | ||
} | ||
fetchUserVaultEquities(options) { | ||
return this.info.fetch({ | ||
type: 'userVaultEquities', | ||
user: options.user, | ||
}); | ||
} | ||
async executeOrThrow(action) { | ||
@@ -128,2 +137,8 @@ if (this.exchange === undefined) { | ||
} | ||
evmUserModifiy(usingBigBlocks) { | ||
return this.executeOrThrow({ | ||
type: 'evmUserModify', | ||
usingBigBlocks, | ||
}); | ||
} | ||
spotSend(options) { | ||
@@ -135,2 +150,14 @@ return this.executeOrThrow({ | ||
} | ||
usdClassTransfer(options) { | ||
return this.executeOrThrow({ | ||
type: 'usdClassTransfer', | ||
...options, | ||
}); | ||
} | ||
vaultTransfer(options) { | ||
return this.executeOrThrow({ | ||
type: 'vaultTransfer', | ||
...options, | ||
}); | ||
} | ||
async marketOrder(options) { | ||
@@ -137,0 +164,0 @@ // Market Order is an aggressive Limit Order IoC |
@@ -7,2 +7,3 @@ type Request<T extends string> = { | ||
}; | ||
export type PortfolioRequest = UserApiRequest<'portfolio'>; | ||
export type ClearingHouseStateRequest = UserApiRequest<'clearinghouseState'>; | ||
@@ -94,3 +95,3 @@ export type ClearingHouseStateResponse = { | ||
export type AllMidsResponse = Record<string, string>; | ||
type HyperliquidRequest = UserVaultEquitiesRequest | VaultDetailsRequest | SpotMetaRequest | ClearingHouseStateRequest | SpotClearingHouseStateRequest | AllMidsRequest; | ||
type HyperliquidRequest = UserVaultEquitiesRequest | VaultDetailsRequest | SpotMetaRequest | ClearingHouseStateRequest | SpotClearingHouseStateRequest | AllMidsRequest | PortfolioRequest; | ||
export declare class InfoEndpoint { | ||
@@ -97,0 +98,0 @@ readonly endpoint: string; |
@@ -15,8 +15,9 @@ import { HyperliquidEnvironment } from './constants'; | ||
}; | ||
export type SpotUserAction = Action<'spotUser'> & { | ||
classTransfer: { | ||
usdc: bigint; | ||
toPerp: boolean; | ||
}; | ||
export type EvmUserModifyAction = Action<'evmUserModify'> & { | ||
usingBigBlocks: boolean; | ||
}; | ||
export type UsdClassTransferAction = Action<'usdClassTransfer'> & { | ||
amount: string; | ||
toPerp: boolean; | ||
}; | ||
export type VaultTransferAction = Action<'vaultTransfer'> & { | ||
@@ -120,3 +121,3 @@ vaultAddress: string; | ||
export type SpotDeployAction = RegisterToken2Action | UserGenesisAction | RegisterSpotAction | RegisterHyperliquidityAction | GenesisAction | SetEvmContractAction; | ||
export type HyperliquidL1Action = SpotUserAction | VaultTransferAction | OrderAction | SpotDeployAction; | ||
export type HyperliquidL1Action = EvmUserModifyAction | UsdClassTransferAction | VaultTransferAction | OrderAction | SpotDeployAction; | ||
export type HyperliquidUserAction = SpotSendAction; | ||
@@ -123,0 +124,0 @@ export type HyperliquidAction = HyperliquidL1Action | HyperliquidUserAction; |
@@ -21,3 +21,3 @@ export class ExchangeEndpoint { | ||
}; | ||
// console.log(action); | ||
//console.log(action); | ||
const url = [this.endpoint, 'exchange'].join('/'); | ||
@@ -33,6 +33,24 @@ const response = await fetch(url, options); | ||
case 'order': | ||
case 'spotUser': | ||
case 'vaultTransfer': | ||
case 'spotDeploy': | ||
case 'evmUserModify': | ||
return [action, await this.signer.signL1Action(action, null, nonce)]; | ||
case 'usdClassTransfer': | ||
action = { | ||
...action, | ||
nonce, | ||
signatureChainId: `0x${this.signatureChainId.toString(16)}`, | ||
hyperliquidChain: this.environment === 'mainnet' ? 'Mainnet' : 'Testnet', | ||
}; | ||
return [ | ||
action, | ||
await this.signer.signUserAction(action, { | ||
'HyperliquidTransaction:UsdClassTransfer': [ | ||
{ name: 'hyperliquidChain', type: 'string' }, | ||
{ name: 'amount', type: 'string' }, | ||
{ name: 'toPerp', type: 'bool' }, | ||
{ name: 'nonce', type: 'uint64' }, | ||
], | ||
}), | ||
]; | ||
case 'spotSend': | ||
@@ -39,0 +57,0 @@ action = { |
import { ExchangeEndpoint, HyperliquidAction, SpotDeployAction } from './ExchangeEndpoint'; | ||
import { AllMidsResponse, ClearingHouseStateResponse, InfoEndpoint, SpotMetaResponse, VaultDetailsResponse } from './InfoEndpoint'; | ||
import { AllMidsResponse, ClearingHouseStateResponse, InfoEndpoint, SpotMetaResponse, UserVaultEquitiesResponse, VaultDetailsResponse } from './InfoEndpoint'; | ||
import { Price } from './Price'; | ||
@@ -12,2 +12,11 @@ import { TypedDataSigner } from './Signer'; | ||
}; | ||
type UsdClassTransferOptions = { | ||
amount: string; | ||
toPerp: boolean; | ||
}; | ||
type VaultTransferOptions = { | ||
vaultAddress: string; | ||
isDeposit: boolean; | ||
usd: number; | ||
}; | ||
type MarketOrderOptions = { | ||
@@ -24,2 +33,5 @@ buyOrSell: 'buy' | 'sell'; | ||
}; | ||
type UserVaultEquitiesOptions = { | ||
user: string; | ||
}; | ||
type RegisterToken2Options = Extract<SpotDeployAction, { | ||
@@ -79,2 +91,3 @@ registerToken2: any; | ||
fetchVaultDetails(options: VaultDetailsOptions): Promise<VaultDetailsResponse>; | ||
fetchUserVaultEquities(options: UserVaultEquitiesOptions): Promise<UserVaultEquitiesResponse>; | ||
executeOrThrow<TResponse>(action: HyperliquidAction): Promise<TResponse>; | ||
@@ -89,3 +102,6 @@ spotDeployer(): { | ||
}; | ||
evmUserModifiy(usingBigBlocks: boolean): Promise<unknown>; | ||
spotSend(options: SpotSendOptions): Promise<unknown>; | ||
usdClassTransfer(options: UsdClassTransferOptions): Promise<unknown>; | ||
vaultTransfer(options: VaultTransferOptions): Promise<unknown>; | ||
marketOrder(options: MarketOrderOptions): Promise<{ | ||
@@ -92,0 +108,0 @@ error: string; |
@@ -32,2 +32,5 @@ import { ExchangeEndpoint, } from './ExchangeEndpoint'; | ||
} | ||
// async fetchPortfolio() { | ||
// return this.info.fetch<any>({ type: 'portfolio' }); | ||
// } | ||
async fetchClearinghouseState(user) { | ||
@@ -59,2 +62,8 @@ const response = await this.info.fetch({ | ||
} | ||
fetchUserVaultEquities(options) { | ||
return this.info.fetch({ | ||
type: 'userVaultEquities', | ||
user: options.user, | ||
}); | ||
} | ||
async executeOrThrow(action) { | ||
@@ -125,2 +134,8 @@ if (this.exchange === undefined) { | ||
} | ||
evmUserModifiy(usingBigBlocks) { | ||
return this.executeOrThrow({ | ||
type: 'evmUserModify', | ||
usingBigBlocks, | ||
}); | ||
} | ||
spotSend(options) { | ||
@@ -132,2 +147,14 @@ return this.executeOrThrow({ | ||
} | ||
usdClassTransfer(options) { | ||
return this.executeOrThrow({ | ||
type: 'usdClassTransfer', | ||
...options, | ||
}); | ||
} | ||
vaultTransfer(options) { | ||
return this.executeOrThrow({ | ||
type: 'vaultTransfer', | ||
...options, | ||
}); | ||
} | ||
async marketOrder(options) { | ||
@@ -134,0 +161,0 @@ // Market Order is an aggressive Limit Order IoC |
@@ -7,2 +7,3 @@ type Request<T extends string> = { | ||
}; | ||
export type PortfolioRequest = UserApiRequest<'portfolio'>; | ||
export type ClearingHouseStateRequest = UserApiRequest<'clearinghouseState'>; | ||
@@ -94,3 +95,3 @@ export type ClearingHouseStateResponse = { | ||
export type AllMidsResponse = Record<string, string>; | ||
type HyperliquidRequest = UserVaultEquitiesRequest | VaultDetailsRequest | SpotMetaRequest | ClearingHouseStateRequest | SpotClearingHouseStateRequest | AllMidsRequest; | ||
type HyperliquidRequest = UserVaultEquitiesRequest | VaultDetailsRequest | SpotMetaRequest | ClearingHouseStateRequest | SpotClearingHouseStateRequest | AllMidsRequest | PortfolioRequest; | ||
export declare class InfoEndpoint { | ||
@@ -97,0 +98,0 @@ readonly endpoint: string; |
{ | ||
"name": "@ambitlabs/hyperliquid-sdk", | ||
"version": "0.0.2-beta4", | ||
"version": "0.0.2-beta5", | ||
"types": "./dist/esm/index.d.ts", | ||
@@ -5,0 +5,0 @@ "module": "./dist/esm/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
100921
1868