@andy-liquid-labs/lighter-ts-sdk 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +170 -135
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +169 -135
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client/exchange-client.ts +18 -12
- package/src/client/txClient.ts +11 -0
- package/src/index.ts +35 -38
- package/src/types/txInfoSerializer.ts +250 -226
package/dist/index.d.mts
CHANGED
|
@@ -1154,6 +1154,10 @@ declare class L2BurnSharesTxInfo implements TxInfo {
|
|
|
1154
1154
|
* The API expects PascalCase field names matching the Go struct definitions.
|
|
1155
1155
|
*/
|
|
1156
1156
|
|
|
1157
|
+
/**
|
|
1158
|
+
* Generic serializer - determines the type and calls the appropriate serializer
|
|
1159
|
+
*/
|
|
1160
|
+
declare function serializeTxInfo(txInfo: TxInfo): string;
|
|
1157
1161
|
/**
|
|
1158
1162
|
* Serialize L2CreateOrderTxInfo to JSON
|
|
1159
1163
|
*/
|
|
@@ -1215,9 +1219,9 @@ declare function serializeBurnShares(txInfo: L2BurnSharesTxInfo): string;
|
|
|
1215
1219
|
*/
|
|
1216
1220
|
declare function serializeCreateGroupedOrders(txInfo: L2CreateGroupedOrdersTxInfo): string;
|
|
1217
1221
|
/**
|
|
1218
|
-
*
|
|
1222
|
+
* Custom JSON serializer that preserves BigInt values as unquoted numbers
|
|
1219
1223
|
*/
|
|
1220
|
-
declare function
|
|
1224
|
+
declare function bigIntSafeStringify(obj: any): string;
|
|
1221
1225
|
|
|
1222
1226
|
interface WebSocketConfig {
|
|
1223
1227
|
url?: string;
|
|
@@ -1648,6 +1652,10 @@ declare class TxClient {
|
|
|
1648
1652
|
* Check that the client's API key matches the one on the server
|
|
1649
1653
|
*/
|
|
1650
1654
|
check(): Promise<void>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Get the next nonce for the current account from the server
|
|
1657
|
+
*/
|
|
1658
|
+
getNextNonce: () => Promise<bigint>;
|
|
1651
1659
|
/**
|
|
1652
1660
|
* Create an auth token
|
|
1653
1661
|
*/
|
|
@@ -3683,4 +3691,4 @@ declare function hashToQuinticExtension(elements: GoldilocksElement[]): Uint8Arr
|
|
|
3683
3691
|
|
|
3684
3692
|
declare const ORDER = 1067993516717146951041484916571792702745057740581727230159139685185762082554198619328292418486241n;
|
|
3685
3693
|
|
|
3686
|
-
export { ApiMaxOrderType, AssetMarginMode, type AssetMarginModeValue, AssetRouteType, type AssetRouteTypeValue, type BurnSharesTxReq, type CancelAllOrdersTxReq, CancelAllTimeInForce, type CancelAllTimeInForceValue, type CancelOrderTxReq, type ChangePubKeyReq, type CreateGroupedOrdersTxReq, type CreateOrderTxReq, type CreatePublicPoolTxReq, DEFAULT_ACCOUNT_INDEX, DEFAULT_API_KEY_INDEX, DEFAULT_EXPIRE_TIME_MS, ECgFp5Point, ECgFp5Scalar, ErrAccountIndexTooHigh, ErrAccountIndexTooLow, ErrApiKeyIndexTooHigh, ErrApiKeyIndexTooLow, ErrAssetIndexTooHigh, ErrAssetIndexTooLow, ErrBaseAmountTooHigh, ErrBaseAmountTooLow, ErrCancelAllTimeInForceInvalid, ErrCancelAllTimeTooHigh, ErrCancelAllTimeTooLow, ErrClientOrderIndexTooHigh, ErrClientOrderIndexTooLow, ErrExpiredAtInvalid, ErrFromAccountIndexTooHigh, ErrFromAccountIndexTooLow, ErrGroupingTypeInvalid, ErrInitialTotalSharesTooHigh, ErrInitialTotalSharesTooLow, ErrInvalidMarketIndex, ErrInvalidPublicKeyLength, ErrIsAskInvalid, ErrMarginDirectionInvalid, ErrMarginModeInvalid, ErrMinOperatorShareRateTooHigh, ErrNoOrdersInGroup, ErrNonceTooLow, ErrOperatorFeeTooHigh, ErrOperatorFeeTooLow, ErrOrderExpiryInvalid, ErrOrderIndexTooHigh, ErrOrderIndexTooLow, ErrOrderReduceOnlyInvalid, ErrOrderTimeInForceInvalid, ErrOrderTriggerPriceInvalid, ErrOrderTypeInvalid, ErrPriceTooHigh, ErrPriceTooLow, ErrPublicPoolIndexTooLow, ErrRouteTypeInvalid, ErrShareAmountTooHigh, ErrShareAmountTooLow, ErrToAccountIndexTooHigh, ErrToAccountIndexTooLow, ErrTooManyGroupedOrders, ErrTransferAmountTooHigh, ErrTransferAmountTooLow, ErrTransferFeeNegative, ErrTransferFeeTooHigh, ErrUSDCAmountTooHigh, ErrUSDCAmountTooLow, ErrWithdrawalAmountTooHigh, ErrWithdrawalAmountTooLow, index as ExchangeApi, ExchangeClient, FEE_TICK, FETCH_NONCE_FROM_SERVER, GFp5Element, GoldilocksElement, GroupingType, type GroupingTypeValue, HttpClient, INITIAL_POOL_SHARE_VALUE, index$2 as InfoApi, InfoClient, index$1 as InfoPrivateApi, InfoPrivateClient, type KeyManager, type L1BridgeConfig, type L1DepositParams, type L1DepositResult, L2BurnSharesTxInfo, L2CancelAllOrdersTxInfo, L2CancelOrderTxInfo, L2ChangePubKeyTxInfo, L2CreateGroupedOrdersTxInfo, L2CreateOrderTxInfo, L2CreatePublicPoolTxInfo, L2CreateSubAccountTxInfo, L2MintSharesTxInfo, L2ModifyOrderTxInfo, L2TransferTxInfo, L2UpdateLeverageTxInfo, L2UpdateMarginTxInfo, L2UpdatePublicPoolTxInfo, L2WithdrawTxInfo, MARGIN_FRACTION_TICK, MAX_ACCOUNT_INDEX, MAX_API_KEY_INDEX, MAX_ASSET_INDEX, MAX_BURNT_SHARE_USDC_VALUE, MAX_CLIENT_ORDER_INDEX, MAX_GROUPED_ORDER_COUNT, MAX_INITIAL_TOTAL_SHARES, MAX_INVESTED_PUBLIC_POOL_COUNT, MAX_MASTER_ACCOUNT_INDEX, MAX_ORDER_BASE_AMOUNT, MAX_ORDER_CANCEL_ALL_PERIOD, MAX_ORDER_EXPIRY, MAX_ORDER_EXPIRY_PERIOD, MAX_ORDER_INDEX, MAX_ORDER_NONCE, MAX_ORDER_PRICE, MAX_ORDER_TRIGGER_PRICE, MAX_PERPS_MARKET_INDEX, MAX_POOL_ENTRY_USDC, MAX_POOL_SHARES, MAX_POOL_SHARES_TO_MINT_OR_BURN, MAX_SPOT_MARKET_INDEX, MAX_TIMESTAMP, MAX_TRANSFER_AMOUNT, MAX_TRANSFER_FEE, MAX_USDC_AMOUNT, MAX_WITHDRAWAL_AMOUNT, MIN_ACCOUNT_INDEX, MIN_API_KEY_INDEX, MIN_ASSET_INDEX, MIN_CLIENT_ORDER_INDEX, MIN_INITIAL_TOTAL_SHARES, MIN_MARKET_INDEX, MIN_NONCE, MIN_ORDER_BASE_AMOUNT, MIN_ORDER_CANCEL_ALL_PERIOD, MIN_ORDER_EXPIRY, MIN_ORDER_EXPIRY_PERIOD, MIN_ORDER_INDEX, MIN_ORDER_NONCE, MIN_ORDER_PRICE, MIN_ORDER_TRIGGER_PRICE, MIN_PERPS_MARKET_INDEX, MIN_POOL_SHARES_TO_MINT_OR_BURN, MIN_SPOT_MARKET_INDEX, MIN_SUB_ACCOUNT_INDEX, MIN_TIMESTAMP, MIN_TRANSFER_AMOUNT, MIN_USDC_AMOUNT, MIN_WITHDRAWAL_AMOUNT, MarginDirection, type MarginDirectionValue, MarginMode, type MarginModeValue, type MinimalHTTPClient, type MintSharesTxReq, type ModifyOrderTxReq, NATIVE_ASSET_INDEX, NIL_API_KEY_INDEX, NIL_ASSET_INDEX, NIL_CLIENT_ORDER_INDEX, NIL_MARKET_INDEX, NIL_ORDER_BASE_AMOUNT, NIL_ORDER_EXPIRY, NIL_ORDER_INDEX, NIL_ORDER_PRICE, NIL_ORDER_TRIGGER_PRICE, ONE_USDC, ORDER, type OrderInfo, OrderType, type OrderTypeValue, SCALAR_ORDER, SHARE_TICK, SchnorrSignature, type Signer, TimeInForce, type TimeInForceValue, type TransactOpts, type TransferTxReq, TxClient, type TxInfo, TxType, type TxTypeValue, USDC_ASSET_INDEX, type Unsubscribe, type UpdateLeverageTxReq, type UpdateMarginTxReq, type UpdatePublicPoolTxReq, ValidationError, type WebSocketConfig, type WebSocketSubscription, type WithdrawTxReq, type WsAccountAllAssetsUpdate, type WsAccountAllOrdersUpdate, type WsAccountAllPositionsUpdate, type WsAccountAllTradesUpdate, type WsAccountAllUpdate, type WsAccountAsset, type WsAccountMarketUpdate, type WsAccountOrdersUpdate, type WsAccountPosition, type WsAnnouncementNotificationContent, WsClient, type WsDeleverageNotificationContent, type WsFundingHistoryEntry, type WsHeightUpdate, type WsLiquidationNotificationContent, type WsMarketStats, type WsMarketStatsUpdate, type WsNotification, type WsNotificationBase, type WsNotificationContent, type WsNotificationUpdate, type WsOrder, type WsOrderBookSnapshot, type WsOrderBookUpdate, type WsPoolDataUpdate, type WsPoolInfo, type WsPoolInfoDailyMetric, type WsPoolInfoUpdate, type WsPoolShare, type WsPositionFunding, type WsPriceLevel, type WsSpotMarketStats, type WsSpotMarketStatsUpdate, type WsStatsBreakdown, type WsTrade, type WsTradeUpdate, type WsTransaction, type WsTransactionUpdate, type WsUserStats, type WsUserStatsUpdate, bytesToFieldElements, bytesToHex, checkClient, clearClients, createClient, generateApiKey, getClient, getDefaultClient, hashToQuinticExtension, hexToBytes, newHttpClient, newKeyManager, permute, poseidon2Hash, sampleScalar, schnorrPkFromSk, schnorrSignHashedMessage, schnorrSignHashedMessageDeterministic, serializeBurnShares, serializeCancelAllOrders, serializeCancelOrder, serializeChangePubKey, serializeCreateGroupedOrders, serializeCreateOrder, serializeCreatePublicPool, serializeCreateSubAccount, serializeMintShares, serializeModifyOrder, serializeTransfer, serializeTxInfo, serializeUpdateLeverage, serializeUpdateMargin, serializeUpdatePublicPool, serializeWithdraw };
|
|
3694
|
+
export { ApiMaxOrderType, AssetMarginMode, type AssetMarginModeValue, AssetRouteType, type AssetRouteTypeValue, type BurnSharesTxReq, type CancelAllOrdersTxReq, CancelAllTimeInForce, type CancelAllTimeInForceValue, type CancelOrderTxReq, type ChangePubKeyReq, type CreateGroupedOrdersTxReq, type CreateOrderTxReq, type CreatePublicPoolTxReq, DEFAULT_ACCOUNT_INDEX, DEFAULT_API_KEY_INDEX, DEFAULT_EXPIRE_TIME_MS, ECgFp5Point, ECgFp5Scalar, ErrAccountIndexTooHigh, ErrAccountIndexTooLow, ErrApiKeyIndexTooHigh, ErrApiKeyIndexTooLow, ErrAssetIndexTooHigh, ErrAssetIndexTooLow, ErrBaseAmountTooHigh, ErrBaseAmountTooLow, ErrCancelAllTimeInForceInvalid, ErrCancelAllTimeTooHigh, ErrCancelAllTimeTooLow, ErrClientOrderIndexTooHigh, ErrClientOrderIndexTooLow, ErrExpiredAtInvalid, ErrFromAccountIndexTooHigh, ErrFromAccountIndexTooLow, ErrGroupingTypeInvalid, ErrInitialTotalSharesTooHigh, ErrInitialTotalSharesTooLow, ErrInvalidMarketIndex, ErrInvalidPublicKeyLength, ErrIsAskInvalid, ErrMarginDirectionInvalid, ErrMarginModeInvalid, ErrMinOperatorShareRateTooHigh, ErrNoOrdersInGroup, ErrNonceTooLow, ErrOperatorFeeTooHigh, ErrOperatorFeeTooLow, ErrOrderExpiryInvalid, ErrOrderIndexTooHigh, ErrOrderIndexTooLow, ErrOrderReduceOnlyInvalid, ErrOrderTimeInForceInvalid, ErrOrderTriggerPriceInvalid, ErrOrderTypeInvalid, ErrPriceTooHigh, ErrPriceTooLow, ErrPublicPoolIndexTooLow, ErrRouteTypeInvalid, ErrShareAmountTooHigh, ErrShareAmountTooLow, ErrToAccountIndexTooHigh, ErrToAccountIndexTooLow, ErrTooManyGroupedOrders, ErrTransferAmountTooHigh, ErrTransferAmountTooLow, ErrTransferFeeNegative, ErrTransferFeeTooHigh, ErrUSDCAmountTooHigh, ErrUSDCAmountTooLow, ErrWithdrawalAmountTooHigh, ErrWithdrawalAmountTooLow, index as ExchangeApi, ExchangeClient, FEE_TICK, FETCH_NONCE_FROM_SERVER, GFp5Element, GoldilocksElement, GroupingType, type GroupingTypeValue, HttpClient, INITIAL_POOL_SHARE_VALUE, index$2 as InfoApi, InfoClient, index$1 as InfoPrivateApi, InfoPrivateClient, type KeyManager, type L1BridgeConfig, type L1DepositParams, type L1DepositResult, L2BurnSharesTxInfo, L2CancelAllOrdersTxInfo, L2CancelOrderTxInfo, L2ChangePubKeyTxInfo, L2CreateGroupedOrdersTxInfo, L2CreateOrderTxInfo, L2CreatePublicPoolTxInfo, L2CreateSubAccountTxInfo, L2MintSharesTxInfo, L2ModifyOrderTxInfo, L2TransferTxInfo, L2UpdateLeverageTxInfo, L2UpdateMarginTxInfo, L2UpdatePublicPoolTxInfo, L2WithdrawTxInfo, MARGIN_FRACTION_TICK, MAX_ACCOUNT_INDEX, MAX_API_KEY_INDEX, MAX_ASSET_INDEX, MAX_BURNT_SHARE_USDC_VALUE, MAX_CLIENT_ORDER_INDEX, MAX_GROUPED_ORDER_COUNT, MAX_INITIAL_TOTAL_SHARES, MAX_INVESTED_PUBLIC_POOL_COUNT, MAX_MASTER_ACCOUNT_INDEX, MAX_ORDER_BASE_AMOUNT, MAX_ORDER_CANCEL_ALL_PERIOD, MAX_ORDER_EXPIRY, MAX_ORDER_EXPIRY_PERIOD, MAX_ORDER_INDEX, MAX_ORDER_NONCE, MAX_ORDER_PRICE, MAX_ORDER_TRIGGER_PRICE, MAX_PERPS_MARKET_INDEX, MAX_POOL_ENTRY_USDC, MAX_POOL_SHARES, MAX_POOL_SHARES_TO_MINT_OR_BURN, MAX_SPOT_MARKET_INDEX, MAX_TIMESTAMP, MAX_TRANSFER_AMOUNT, MAX_TRANSFER_FEE, MAX_USDC_AMOUNT, MAX_WITHDRAWAL_AMOUNT, MIN_ACCOUNT_INDEX, MIN_API_KEY_INDEX, MIN_ASSET_INDEX, MIN_CLIENT_ORDER_INDEX, MIN_INITIAL_TOTAL_SHARES, MIN_MARKET_INDEX, MIN_NONCE, MIN_ORDER_BASE_AMOUNT, MIN_ORDER_CANCEL_ALL_PERIOD, MIN_ORDER_EXPIRY, MIN_ORDER_EXPIRY_PERIOD, MIN_ORDER_INDEX, MIN_ORDER_NONCE, MIN_ORDER_PRICE, MIN_ORDER_TRIGGER_PRICE, MIN_PERPS_MARKET_INDEX, MIN_POOL_SHARES_TO_MINT_OR_BURN, MIN_SPOT_MARKET_INDEX, MIN_SUB_ACCOUNT_INDEX, MIN_TIMESTAMP, MIN_TRANSFER_AMOUNT, MIN_USDC_AMOUNT, MIN_WITHDRAWAL_AMOUNT, MarginDirection, type MarginDirectionValue, MarginMode, type MarginModeValue, type MinimalHTTPClient, type MintSharesTxReq, type ModifyOrderTxReq, NATIVE_ASSET_INDEX, NIL_API_KEY_INDEX, NIL_ASSET_INDEX, NIL_CLIENT_ORDER_INDEX, NIL_MARKET_INDEX, NIL_ORDER_BASE_AMOUNT, NIL_ORDER_EXPIRY, NIL_ORDER_INDEX, NIL_ORDER_PRICE, NIL_ORDER_TRIGGER_PRICE, ONE_USDC, ORDER, type OrderInfo, OrderType, type OrderTypeValue, SCALAR_ORDER, SHARE_TICK, SchnorrSignature, type Signer, TimeInForce, type TimeInForceValue, type TransactOpts, type TransferTxReq, TxClient, type TxInfo, TxType, type TxTypeValue, USDC_ASSET_INDEX, type Unsubscribe, type UpdateLeverageTxReq, type UpdateMarginTxReq, type UpdatePublicPoolTxReq, ValidationError, type WebSocketConfig, type WebSocketSubscription, type WithdrawTxReq, type WsAccountAllAssetsUpdate, type WsAccountAllOrdersUpdate, type WsAccountAllPositionsUpdate, type WsAccountAllTradesUpdate, type WsAccountAllUpdate, type WsAccountAsset, type WsAccountMarketUpdate, type WsAccountOrdersUpdate, type WsAccountPosition, type WsAnnouncementNotificationContent, WsClient, type WsDeleverageNotificationContent, type WsFundingHistoryEntry, type WsHeightUpdate, type WsLiquidationNotificationContent, type WsMarketStats, type WsMarketStatsUpdate, type WsNotification, type WsNotificationBase, type WsNotificationContent, type WsNotificationUpdate, type WsOrder, type WsOrderBookSnapshot, type WsOrderBookUpdate, type WsPoolDataUpdate, type WsPoolInfo, type WsPoolInfoDailyMetric, type WsPoolInfoUpdate, type WsPoolShare, type WsPositionFunding, type WsPriceLevel, type WsSpotMarketStats, type WsSpotMarketStatsUpdate, type WsStatsBreakdown, type WsTrade, type WsTradeUpdate, type WsTransaction, type WsTransactionUpdate, type WsUserStats, type WsUserStatsUpdate, bigIntSafeStringify, bytesToFieldElements, bytesToHex, checkClient, clearClients, createClient, generateApiKey, getClient, getDefaultClient, hashToQuinticExtension, hexToBytes, newHttpClient, newKeyManager, permute, poseidon2Hash, sampleScalar, schnorrPkFromSk, schnorrSignHashedMessage, schnorrSignHashedMessageDeterministic, serializeBurnShares, serializeCancelAllOrders, serializeCancelOrder, serializeChangePubKey, serializeCreateGroupedOrders, serializeCreateOrder, serializeCreatePublicPool, serializeCreateSubAccount, serializeMintShares, serializeModifyOrder, serializeTransfer, serializeTxInfo, serializeUpdateLeverage, serializeUpdateMargin, serializeUpdatePublicPool, serializeWithdraw };
|
package/dist/index.d.ts
CHANGED
|
@@ -1154,6 +1154,10 @@ declare class L2BurnSharesTxInfo implements TxInfo {
|
|
|
1154
1154
|
* The API expects PascalCase field names matching the Go struct definitions.
|
|
1155
1155
|
*/
|
|
1156
1156
|
|
|
1157
|
+
/**
|
|
1158
|
+
* Generic serializer - determines the type and calls the appropriate serializer
|
|
1159
|
+
*/
|
|
1160
|
+
declare function serializeTxInfo(txInfo: TxInfo): string;
|
|
1157
1161
|
/**
|
|
1158
1162
|
* Serialize L2CreateOrderTxInfo to JSON
|
|
1159
1163
|
*/
|
|
@@ -1215,9 +1219,9 @@ declare function serializeBurnShares(txInfo: L2BurnSharesTxInfo): string;
|
|
|
1215
1219
|
*/
|
|
1216
1220
|
declare function serializeCreateGroupedOrders(txInfo: L2CreateGroupedOrdersTxInfo): string;
|
|
1217
1221
|
/**
|
|
1218
|
-
*
|
|
1222
|
+
* Custom JSON serializer that preserves BigInt values as unquoted numbers
|
|
1219
1223
|
*/
|
|
1220
|
-
declare function
|
|
1224
|
+
declare function bigIntSafeStringify(obj: any): string;
|
|
1221
1225
|
|
|
1222
1226
|
interface WebSocketConfig {
|
|
1223
1227
|
url?: string;
|
|
@@ -1648,6 +1652,10 @@ declare class TxClient {
|
|
|
1648
1652
|
* Check that the client's API key matches the one on the server
|
|
1649
1653
|
*/
|
|
1650
1654
|
check(): Promise<void>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Get the next nonce for the current account from the server
|
|
1657
|
+
*/
|
|
1658
|
+
getNextNonce: () => Promise<bigint>;
|
|
1651
1659
|
/**
|
|
1652
1660
|
* Create an auth token
|
|
1653
1661
|
*/
|
|
@@ -3683,4 +3691,4 @@ declare function hashToQuinticExtension(elements: GoldilocksElement[]): Uint8Arr
|
|
|
3683
3691
|
|
|
3684
3692
|
declare const ORDER = 1067993516717146951041484916571792702745057740581727230159139685185762082554198619328292418486241n;
|
|
3685
3693
|
|
|
3686
|
-
export { ApiMaxOrderType, AssetMarginMode, type AssetMarginModeValue, AssetRouteType, type AssetRouteTypeValue, type BurnSharesTxReq, type CancelAllOrdersTxReq, CancelAllTimeInForce, type CancelAllTimeInForceValue, type CancelOrderTxReq, type ChangePubKeyReq, type CreateGroupedOrdersTxReq, type CreateOrderTxReq, type CreatePublicPoolTxReq, DEFAULT_ACCOUNT_INDEX, DEFAULT_API_KEY_INDEX, DEFAULT_EXPIRE_TIME_MS, ECgFp5Point, ECgFp5Scalar, ErrAccountIndexTooHigh, ErrAccountIndexTooLow, ErrApiKeyIndexTooHigh, ErrApiKeyIndexTooLow, ErrAssetIndexTooHigh, ErrAssetIndexTooLow, ErrBaseAmountTooHigh, ErrBaseAmountTooLow, ErrCancelAllTimeInForceInvalid, ErrCancelAllTimeTooHigh, ErrCancelAllTimeTooLow, ErrClientOrderIndexTooHigh, ErrClientOrderIndexTooLow, ErrExpiredAtInvalid, ErrFromAccountIndexTooHigh, ErrFromAccountIndexTooLow, ErrGroupingTypeInvalid, ErrInitialTotalSharesTooHigh, ErrInitialTotalSharesTooLow, ErrInvalidMarketIndex, ErrInvalidPublicKeyLength, ErrIsAskInvalid, ErrMarginDirectionInvalid, ErrMarginModeInvalid, ErrMinOperatorShareRateTooHigh, ErrNoOrdersInGroup, ErrNonceTooLow, ErrOperatorFeeTooHigh, ErrOperatorFeeTooLow, ErrOrderExpiryInvalid, ErrOrderIndexTooHigh, ErrOrderIndexTooLow, ErrOrderReduceOnlyInvalid, ErrOrderTimeInForceInvalid, ErrOrderTriggerPriceInvalid, ErrOrderTypeInvalid, ErrPriceTooHigh, ErrPriceTooLow, ErrPublicPoolIndexTooLow, ErrRouteTypeInvalid, ErrShareAmountTooHigh, ErrShareAmountTooLow, ErrToAccountIndexTooHigh, ErrToAccountIndexTooLow, ErrTooManyGroupedOrders, ErrTransferAmountTooHigh, ErrTransferAmountTooLow, ErrTransferFeeNegative, ErrTransferFeeTooHigh, ErrUSDCAmountTooHigh, ErrUSDCAmountTooLow, ErrWithdrawalAmountTooHigh, ErrWithdrawalAmountTooLow, index as ExchangeApi, ExchangeClient, FEE_TICK, FETCH_NONCE_FROM_SERVER, GFp5Element, GoldilocksElement, GroupingType, type GroupingTypeValue, HttpClient, INITIAL_POOL_SHARE_VALUE, index$2 as InfoApi, InfoClient, index$1 as InfoPrivateApi, InfoPrivateClient, type KeyManager, type L1BridgeConfig, type L1DepositParams, type L1DepositResult, L2BurnSharesTxInfo, L2CancelAllOrdersTxInfo, L2CancelOrderTxInfo, L2ChangePubKeyTxInfo, L2CreateGroupedOrdersTxInfo, L2CreateOrderTxInfo, L2CreatePublicPoolTxInfo, L2CreateSubAccountTxInfo, L2MintSharesTxInfo, L2ModifyOrderTxInfo, L2TransferTxInfo, L2UpdateLeverageTxInfo, L2UpdateMarginTxInfo, L2UpdatePublicPoolTxInfo, L2WithdrawTxInfo, MARGIN_FRACTION_TICK, MAX_ACCOUNT_INDEX, MAX_API_KEY_INDEX, MAX_ASSET_INDEX, MAX_BURNT_SHARE_USDC_VALUE, MAX_CLIENT_ORDER_INDEX, MAX_GROUPED_ORDER_COUNT, MAX_INITIAL_TOTAL_SHARES, MAX_INVESTED_PUBLIC_POOL_COUNT, MAX_MASTER_ACCOUNT_INDEX, MAX_ORDER_BASE_AMOUNT, MAX_ORDER_CANCEL_ALL_PERIOD, MAX_ORDER_EXPIRY, MAX_ORDER_EXPIRY_PERIOD, MAX_ORDER_INDEX, MAX_ORDER_NONCE, MAX_ORDER_PRICE, MAX_ORDER_TRIGGER_PRICE, MAX_PERPS_MARKET_INDEX, MAX_POOL_ENTRY_USDC, MAX_POOL_SHARES, MAX_POOL_SHARES_TO_MINT_OR_BURN, MAX_SPOT_MARKET_INDEX, MAX_TIMESTAMP, MAX_TRANSFER_AMOUNT, MAX_TRANSFER_FEE, MAX_USDC_AMOUNT, MAX_WITHDRAWAL_AMOUNT, MIN_ACCOUNT_INDEX, MIN_API_KEY_INDEX, MIN_ASSET_INDEX, MIN_CLIENT_ORDER_INDEX, MIN_INITIAL_TOTAL_SHARES, MIN_MARKET_INDEX, MIN_NONCE, MIN_ORDER_BASE_AMOUNT, MIN_ORDER_CANCEL_ALL_PERIOD, MIN_ORDER_EXPIRY, MIN_ORDER_EXPIRY_PERIOD, MIN_ORDER_INDEX, MIN_ORDER_NONCE, MIN_ORDER_PRICE, MIN_ORDER_TRIGGER_PRICE, MIN_PERPS_MARKET_INDEX, MIN_POOL_SHARES_TO_MINT_OR_BURN, MIN_SPOT_MARKET_INDEX, MIN_SUB_ACCOUNT_INDEX, MIN_TIMESTAMP, MIN_TRANSFER_AMOUNT, MIN_USDC_AMOUNT, MIN_WITHDRAWAL_AMOUNT, MarginDirection, type MarginDirectionValue, MarginMode, type MarginModeValue, type MinimalHTTPClient, type MintSharesTxReq, type ModifyOrderTxReq, NATIVE_ASSET_INDEX, NIL_API_KEY_INDEX, NIL_ASSET_INDEX, NIL_CLIENT_ORDER_INDEX, NIL_MARKET_INDEX, NIL_ORDER_BASE_AMOUNT, NIL_ORDER_EXPIRY, NIL_ORDER_INDEX, NIL_ORDER_PRICE, NIL_ORDER_TRIGGER_PRICE, ONE_USDC, ORDER, type OrderInfo, OrderType, type OrderTypeValue, SCALAR_ORDER, SHARE_TICK, SchnorrSignature, type Signer, TimeInForce, type TimeInForceValue, type TransactOpts, type TransferTxReq, TxClient, type TxInfo, TxType, type TxTypeValue, USDC_ASSET_INDEX, type Unsubscribe, type UpdateLeverageTxReq, type UpdateMarginTxReq, type UpdatePublicPoolTxReq, ValidationError, type WebSocketConfig, type WebSocketSubscription, type WithdrawTxReq, type WsAccountAllAssetsUpdate, type WsAccountAllOrdersUpdate, type WsAccountAllPositionsUpdate, type WsAccountAllTradesUpdate, type WsAccountAllUpdate, type WsAccountAsset, type WsAccountMarketUpdate, type WsAccountOrdersUpdate, type WsAccountPosition, type WsAnnouncementNotificationContent, WsClient, type WsDeleverageNotificationContent, type WsFundingHistoryEntry, type WsHeightUpdate, type WsLiquidationNotificationContent, type WsMarketStats, type WsMarketStatsUpdate, type WsNotification, type WsNotificationBase, type WsNotificationContent, type WsNotificationUpdate, type WsOrder, type WsOrderBookSnapshot, type WsOrderBookUpdate, type WsPoolDataUpdate, type WsPoolInfo, type WsPoolInfoDailyMetric, type WsPoolInfoUpdate, type WsPoolShare, type WsPositionFunding, type WsPriceLevel, type WsSpotMarketStats, type WsSpotMarketStatsUpdate, type WsStatsBreakdown, type WsTrade, type WsTradeUpdate, type WsTransaction, type WsTransactionUpdate, type WsUserStats, type WsUserStatsUpdate, bytesToFieldElements, bytesToHex, checkClient, clearClients, createClient, generateApiKey, getClient, getDefaultClient, hashToQuinticExtension, hexToBytes, newHttpClient, newKeyManager, permute, poseidon2Hash, sampleScalar, schnorrPkFromSk, schnorrSignHashedMessage, schnorrSignHashedMessageDeterministic, serializeBurnShares, serializeCancelAllOrders, serializeCancelOrder, serializeChangePubKey, serializeCreateGroupedOrders, serializeCreateOrder, serializeCreatePublicPool, serializeCreateSubAccount, serializeMintShares, serializeModifyOrder, serializeTransfer, serializeTxInfo, serializeUpdateLeverage, serializeUpdateMargin, serializeUpdatePublicPool, serializeWithdraw };
|
|
3694
|
+
export { ApiMaxOrderType, AssetMarginMode, type AssetMarginModeValue, AssetRouteType, type AssetRouteTypeValue, type BurnSharesTxReq, type CancelAllOrdersTxReq, CancelAllTimeInForce, type CancelAllTimeInForceValue, type CancelOrderTxReq, type ChangePubKeyReq, type CreateGroupedOrdersTxReq, type CreateOrderTxReq, type CreatePublicPoolTxReq, DEFAULT_ACCOUNT_INDEX, DEFAULT_API_KEY_INDEX, DEFAULT_EXPIRE_TIME_MS, ECgFp5Point, ECgFp5Scalar, ErrAccountIndexTooHigh, ErrAccountIndexTooLow, ErrApiKeyIndexTooHigh, ErrApiKeyIndexTooLow, ErrAssetIndexTooHigh, ErrAssetIndexTooLow, ErrBaseAmountTooHigh, ErrBaseAmountTooLow, ErrCancelAllTimeInForceInvalid, ErrCancelAllTimeTooHigh, ErrCancelAllTimeTooLow, ErrClientOrderIndexTooHigh, ErrClientOrderIndexTooLow, ErrExpiredAtInvalid, ErrFromAccountIndexTooHigh, ErrFromAccountIndexTooLow, ErrGroupingTypeInvalid, ErrInitialTotalSharesTooHigh, ErrInitialTotalSharesTooLow, ErrInvalidMarketIndex, ErrInvalidPublicKeyLength, ErrIsAskInvalid, ErrMarginDirectionInvalid, ErrMarginModeInvalid, ErrMinOperatorShareRateTooHigh, ErrNoOrdersInGroup, ErrNonceTooLow, ErrOperatorFeeTooHigh, ErrOperatorFeeTooLow, ErrOrderExpiryInvalid, ErrOrderIndexTooHigh, ErrOrderIndexTooLow, ErrOrderReduceOnlyInvalid, ErrOrderTimeInForceInvalid, ErrOrderTriggerPriceInvalid, ErrOrderTypeInvalid, ErrPriceTooHigh, ErrPriceTooLow, ErrPublicPoolIndexTooLow, ErrRouteTypeInvalid, ErrShareAmountTooHigh, ErrShareAmountTooLow, ErrToAccountIndexTooHigh, ErrToAccountIndexTooLow, ErrTooManyGroupedOrders, ErrTransferAmountTooHigh, ErrTransferAmountTooLow, ErrTransferFeeNegative, ErrTransferFeeTooHigh, ErrUSDCAmountTooHigh, ErrUSDCAmountTooLow, ErrWithdrawalAmountTooHigh, ErrWithdrawalAmountTooLow, index as ExchangeApi, ExchangeClient, FEE_TICK, FETCH_NONCE_FROM_SERVER, GFp5Element, GoldilocksElement, GroupingType, type GroupingTypeValue, HttpClient, INITIAL_POOL_SHARE_VALUE, index$2 as InfoApi, InfoClient, index$1 as InfoPrivateApi, InfoPrivateClient, type KeyManager, type L1BridgeConfig, type L1DepositParams, type L1DepositResult, L2BurnSharesTxInfo, L2CancelAllOrdersTxInfo, L2CancelOrderTxInfo, L2ChangePubKeyTxInfo, L2CreateGroupedOrdersTxInfo, L2CreateOrderTxInfo, L2CreatePublicPoolTxInfo, L2CreateSubAccountTxInfo, L2MintSharesTxInfo, L2ModifyOrderTxInfo, L2TransferTxInfo, L2UpdateLeverageTxInfo, L2UpdateMarginTxInfo, L2UpdatePublicPoolTxInfo, L2WithdrawTxInfo, MARGIN_FRACTION_TICK, MAX_ACCOUNT_INDEX, MAX_API_KEY_INDEX, MAX_ASSET_INDEX, MAX_BURNT_SHARE_USDC_VALUE, MAX_CLIENT_ORDER_INDEX, MAX_GROUPED_ORDER_COUNT, MAX_INITIAL_TOTAL_SHARES, MAX_INVESTED_PUBLIC_POOL_COUNT, MAX_MASTER_ACCOUNT_INDEX, MAX_ORDER_BASE_AMOUNT, MAX_ORDER_CANCEL_ALL_PERIOD, MAX_ORDER_EXPIRY, MAX_ORDER_EXPIRY_PERIOD, MAX_ORDER_INDEX, MAX_ORDER_NONCE, MAX_ORDER_PRICE, MAX_ORDER_TRIGGER_PRICE, MAX_PERPS_MARKET_INDEX, MAX_POOL_ENTRY_USDC, MAX_POOL_SHARES, MAX_POOL_SHARES_TO_MINT_OR_BURN, MAX_SPOT_MARKET_INDEX, MAX_TIMESTAMP, MAX_TRANSFER_AMOUNT, MAX_TRANSFER_FEE, MAX_USDC_AMOUNT, MAX_WITHDRAWAL_AMOUNT, MIN_ACCOUNT_INDEX, MIN_API_KEY_INDEX, MIN_ASSET_INDEX, MIN_CLIENT_ORDER_INDEX, MIN_INITIAL_TOTAL_SHARES, MIN_MARKET_INDEX, MIN_NONCE, MIN_ORDER_BASE_AMOUNT, MIN_ORDER_CANCEL_ALL_PERIOD, MIN_ORDER_EXPIRY, MIN_ORDER_EXPIRY_PERIOD, MIN_ORDER_INDEX, MIN_ORDER_NONCE, MIN_ORDER_PRICE, MIN_ORDER_TRIGGER_PRICE, MIN_PERPS_MARKET_INDEX, MIN_POOL_SHARES_TO_MINT_OR_BURN, MIN_SPOT_MARKET_INDEX, MIN_SUB_ACCOUNT_INDEX, MIN_TIMESTAMP, MIN_TRANSFER_AMOUNT, MIN_USDC_AMOUNT, MIN_WITHDRAWAL_AMOUNT, MarginDirection, type MarginDirectionValue, MarginMode, type MarginModeValue, type MinimalHTTPClient, type MintSharesTxReq, type ModifyOrderTxReq, NATIVE_ASSET_INDEX, NIL_API_KEY_INDEX, NIL_ASSET_INDEX, NIL_CLIENT_ORDER_INDEX, NIL_MARKET_INDEX, NIL_ORDER_BASE_AMOUNT, NIL_ORDER_EXPIRY, NIL_ORDER_INDEX, NIL_ORDER_PRICE, NIL_ORDER_TRIGGER_PRICE, ONE_USDC, ORDER, type OrderInfo, OrderType, type OrderTypeValue, SCALAR_ORDER, SHARE_TICK, SchnorrSignature, type Signer, TimeInForce, type TimeInForceValue, type TransactOpts, type TransferTxReq, TxClient, type TxInfo, TxType, type TxTypeValue, USDC_ASSET_INDEX, type Unsubscribe, type UpdateLeverageTxReq, type UpdateMarginTxReq, type UpdatePublicPoolTxReq, ValidationError, type WebSocketConfig, type WebSocketSubscription, type WithdrawTxReq, type WsAccountAllAssetsUpdate, type WsAccountAllOrdersUpdate, type WsAccountAllPositionsUpdate, type WsAccountAllTradesUpdate, type WsAccountAllUpdate, type WsAccountAsset, type WsAccountMarketUpdate, type WsAccountOrdersUpdate, type WsAccountPosition, type WsAnnouncementNotificationContent, WsClient, type WsDeleverageNotificationContent, type WsFundingHistoryEntry, type WsHeightUpdate, type WsLiquidationNotificationContent, type WsMarketStats, type WsMarketStatsUpdate, type WsNotification, type WsNotificationBase, type WsNotificationContent, type WsNotificationUpdate, type WsOrder, type WsOrderBookSnapshot, type WsOrderBookUpdate, type WsPoolDataUpdate, type WsPoolInfo, type WsPoolInfoDailyMetric, type WsPoolInfoUpdate, type WsPoolShare, type WsPositionFunding, type WsPriceLevel, type WsSpotMarketStats, type WsSpotMarketStatsUpdate, type WsStatsBreakdown, type WsTrade, type WsTradeUpdate, type WsTransaction, type WsTransactionUpdate, type WsUserStats, type WsUserStatsUpdate, bigIntSafeStringify, bytesToFieldElements, bytesToHex, checkClient, clearClients, createClient, generateApiKey, getClient, getDefaultClient, hashToQuinticExtension, hexToBytes, newHttpClient, newKeyManager, permute, poseidon2Hash, sampleScalar, schnorrPkFromSk, schnorrSignHashedMessage, schnorrSignHashedMessageDeterministic, serializeBurnShares, serializeCancelAllOrders, serializeCancelOrder, serializeChangePubKey, serializeCreateGroupedOrders, serializeCreateOrder, serializeCreatePublicPool, serializeCreateSubAccount, serializeMintShares, serializeModifyOrder, serializeTransfer, serializeTxInfo, serializeUpdateLeverage, serializeUpdateMargin, serializeUpdatePublicPool, serializeWithdraw };
|
package/dist/index.js
CHANGED
|
@@ -195,6 +195,7 @@ __export(index_exports, {
|
|
|
195
195
|
USDC_ASSET_INDEX: () => USDC_ASSET_INDEX,
|
|
196
196
|
ValidationError: () => ValidationError,
|
|
197
197
|
WsClient: () => WsClient,
|
|
198
|
+
bigIntSafeStringify: () => bigIntSafeStringify,
|
|
198
199
|
bytesToFieldElements: () => bytesToFieldElements,
|
|
199
200
|
bytesToHex: () => bytesToHex,
|
|
200
201
|
checkClient: () => checkClient,
|
|
@@ -3332,251 +3333,279 @@ var L2BurnSharesTxInfo = class {
|
|
|
3332
3333
|
};
|
|
3333
3334
|
|
|
3334
3335
|
// src/types/txInfoSerializer.ts
|
|
3335
|
-
function
|
|
3336
|
-
if (
|
|
3337
|
-
return
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3336
|
+
function serializeTxInfo(txInfo) {
|
|
3337
|
+
if (txInfo instanceof L2CreateOrderTxInfo) {
|
|
3338
|
+
return serializeCreateOrder(txInfo);
|
|
3339
|
+
} else if (txInfo instanceof L2CancelOrderTxInfo) {
|
|
3340
|
+
return serializeCancelOrder(txInfo);
|
|
3341
|
+
} else if (txInfo instanceof L2ModifyOrderTxInfo) {
|
|
3342
|
+
return serializeModifyOrder(txInfo);
|
|
3343
|
+
} else if (txInfo instanceof L2CancelAllOrdersTxInfo) {
|
|
3344
|
+
return serializeCancelAllOrders(txInfo);
|
|
3345
|
+
} else if (txInfo instanceof L2WithdrawTxInfo) {
|
|
3346
|
+
return serializeWithdraw(txInfo);
|
|
3347
|
+
} else if (txInfo instanceof L2TransferTxInfo) {
|
|
3348
|
+
return serializeTransfer(txInfo);
|
|
3349
|
+
} else if (txInfo instanceof L2ChangePubKeyTxInfo) {
|
|
3350
|
+
return serializeChangePubKey(txInfo);
|
|
3351
|
+
} else if (txInfo instanceof L2CreateSubAccountTxInfo) {
|
|
3352
|
+
return serializeCreateSubAccount(txInfo);
|
|
3353
|
+
} else if (txInfo instanceof L2UpdateLeverageTxInfo) {
|
|
3354
|
+
return serializeUpdateLeverage(txInfo);
|
|
3355
|
+
} else if (txInfo instanceof L2UpdateMarginTxInfo) {
|
|
3356
|
+
return serializeUpdateMargin(txInfo);
|
|
3357
|
+
} else if (txInfo instanceof L2CreatePublicPoolTxInfo) {
|
|
3358
|
+
return serializeCreatePublicPool(txInfo);
|
|
3359
|
+
} else if (txInfo instanceof L2UpdatePublicPoolTxInfo) {
|
|
3360
|
+
return serializeUpdatePublicPool(txInfo);
|
|
3361
|
+
} else if (txInfo instanceof L2MintSharesTxInfo) {
|
|
3362
|
+
return serializeMintShares(txInfo);
|
|
3363
|
+
} else if (txInfo instanceof L2BurnSharesTxInfo) {
|
|
3364
|
+
return serializeBurnShares(txInfo);
|
|
3365
|
+
} else if (txInfo instanceof L2CreateGroupedOrdersTxInfo) {
|
|
3366
|
+
return serializeCreateGroupedOrders(txInfo);
|
|
3342
3367
|
}
|
|
3343
|
-
|
|
3368
|
+
throw new Error(`Unknown TxInfo type: ${txInfo.constructor.name}`);
|
|
3344
3369
|
}
|
|
3345
3370
|
function serializeCreateOrder(txInfo) {
|
|
3346
|
-
return
|
|
3347
|
-
AccountIndex:
|
|
3371
|
+
return bigIntSafeStringify({
|
|
3372
|
+
AccountIndex: txInfo.accountIndex,
|
|
3348
3373
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3349
3374
|
MarketIndex: txInfo.orderInfo.marketIndex,
|
|
3350
|
-
ClientOrderIndex:
|
|
3351
|
-
BaseAmount:
|
|
3375
|
+
ClientOrderIndex: txInfo.orderInfo.clientOrderIndex,
|
|
3376
|
+
BaseAmount: txInfo.orderInfo.baseAmount,
|
|
3352
3377
|
Price: txInfo.orderInfo.price,
|
|
3353
3378
|
IsAsk: txInfo.orderInfo.isAsk,
|
|
3354
3379
|
Type: txInfo.orderInfo.type,
|
|
3355
3380
|
TimeInForce: txInfo.orderInfo.timeInForce,
|
|
3356
3381
|
ReduceOnly: txInfo.orderInfo.reduceOnly,
|
|
3357
3382
|
TriggerPrice: txInfo.orderInfo.triggerPrice,
|
|
3358
|
-
OrderExpiry:
|
|
3359
|
-
ExpiredAt:
|
|
3360
|
-
Nonce:
|
|
3383
|
+
OrderExpiry: txInfo.orderInfo.orderExpiry,
|
|
3384
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3385
|
+
Nonce: txInfo.nonce,
|
|
3361
3386
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3362
3387
|
});
|
|
3363
3388
|
}
|
|
3364
3389
|
function serializeCancelOrder(txInfo) {
|
|
3365
|
-
return
|
|
3366
|
-
AccountIndex:
|
|
3390
|
+
return bigIntSafeStringify({
|
|
3391
|
+
AccountIndex: txInfo.accountIndex,
|
|
3367
3392
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3368
3393
|
MarketIndex: txInfo.marketIndex,
|
|
3369
|
-
Index:
|
|
3370
|
-
ExpiredAt:
|
|
3371
|
-
Nonce:
|
|
3394
|
+
Index: txInfo.index,
|
|
3395
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3396
|
+
Nonce: txInfo.nonce,
|
|
3372
3397
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3373
3398
|
});
|
|
3374
3399
|
}
|
|
3375
3400
|
function serializeModifyOrder(txInfo) {
|
|
3376
|
-
return
|
|
3377
|
-
AccountIndex:
|
|
3401
|
+
return bigIntSafeStringify({
|
|
3402
|
+
AccountIndex: txInfo.accountIndex,
|
|
3378
3403
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3379
3404
|
MarketIndex: txInfo.marketIndex,
|
|
3380
|
-
Index:
|
|
3381
|
-
BaseAmount:
|
|
3405
|
+
Index: txInfo.index,
|
|
3406
|
+
BaseAmount: txInfo.baseAmount,
|
|
3382
3407
|
Price: txInfo.price,
|
|
3383
3408
|
TriggerPrice: txInfo.triggerPrice,
|
|
3384
|
-
ExpiredAt:
|
|
3385
|
-
Nonce:
|
|
3409
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3410
|
+
Nonce: txInfo.nonce,
|
|
3386
3411
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3387
3412
|
});
|
|
3388
3413
|
}
|
|
3389
3414
|
function serializeCancelAllOrders(txInfo) {
|
|
3390
|
-
return
|
|
3391
|
-
AccountIndex:
|
|
3415
|
+
return bigIntSafeStringify({
|
|
3416
|
+
AccountIndex: txInfo.accountIndex,
|
|
3392
3417
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3393
3418
|
TimeInForce: txInfo.timeInForce,
|
|
3394
|
-
Time:
|
|
3395
|
-
ExpiredAt:
|
|
3396
|
-
Nonce:
|
|
3419
|
+
Time: txInfo.time,
|
|
3420
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3421
|
+
Nonce: txInfo.nonce,
|
|
3397
3422
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3398
3423
|
});
|
|
3399
3424
|
}
|
|
3400
3425
|
function serializeWithdraw(txInfo) {
|
|
3401
|
-
return
|
|
3402
|
-
FromAccountIndex:
|
|
3426
|
+
return bigIntSafeStringify({
|
|
3427
|
+
FromAccountIndex: txInfo.fromAccountIndex,
|
|
3403
3428
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3404
3429
|
AssetIndex: txInfo.assetIndex,
|
|
3405
3430
|
RouteType: txInfo.routeType,
|
|
3406
|
-
Amount:
|
|
3407
|
-
ExpiredAt:
|
|
3408
|
-
Nonce:
|
|
3431
|
+
Amount: txInfo.amount,
|
|
3432
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3433
|
+
Nonce: txInfo.nonce,
|
|
3409
3434
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3410
3435
|
});
|
|
3411
3436
|
}
|
|
3412
3437
|
function serializeTransfer(txInfo) {
|
|
3413
|
-
return
|
|
3414
|
-
FromAccountIndex:
|
|
3438
|
+
return bigIntSafeStringify({
|
|
3439
|
+
FromAccountIndex: txInfo.fromAccountIndex,
|
|
3415
3440
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3416
|
-
ToAccountIndex:
|
|
3441
|
+
ToAccountIndex: txInfo.toAccountIndex,
|
|
3417
3442
|
AssetIndex: txInfo.assetIndex,
|
|
3418
3443
|
FromRouteType: txInfo.fromRouteType,
|
|
3419
3444
|
ToRouteType: txInfo.toRouteType,
|
|
3420
|
-
Amount:
|
|
3421
|
-
USDCFee:
|
|
3445
|
+
Amount: txInfo.amount,
|
|
3446
|
+
USDCFee: txInfo.usdcFee,
|
|
3422
3447
|
Memo: Array.from(txInfo.memo),
|
|
3423
|
-
ExpiredAt:
|
|
3424
|
-
Nonce:
|
|
3448
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3449
|
+
Nonce: txInfo.nonce,
|
|
3425
3450
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3426
3451
|
});
|
|
3427
3452
|
}
|
|
3428
3453
|
function serializeChangePubKey(txInfo) {
|
|
3429
3454
|
const pubKeyHex = Array.from(txInfo.pubKey).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3430
|
-
return
|
|
3431
|
-
AccountIndex:
|
|
3455
|
+
return bigIntSafeStringify({
|
|
3456
|
+
AccountIndex: txInfo.accountIndex,
|
|
3432
3457
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3433
3458
|
PubKey: pubKeyHex,
|
|
3434
|
-
ExpiredAt:
|
|
3435
|
-
Nonce:
|
|
3459
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3460
|
+
Nonce: txInfo.nonce,
|
|
3436
3461
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3437
3462
|
});
|
|
3438
3463
|
}
|
|
3439
3464
|
function serializeCreateSubAccount(txInfo) {
|
|
3440
|
-
return
|
|
3441
|
-
AccountIndex:
|
|
3465
|
+
return bigIntSafeStringify({
|
|
3466
|
+
AccountIndex: txInfo.accountIndex,
|
|
3442
3467
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3443
|
-
ExpiredAt:
|
|
3444
|
-
Nonce:
|
|
3468
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3469
|
+
Nonce: txInfo.nonce,
|
|
3445
3470
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3446
3471
|
});
|
|
3447
3472
|
}
|
|
3448
3473
|
function serializeUpdateLeverage(txInfo) {
|
|
3449
|
-
return
|
|
3450
|
-
AccountIndex:
|
|
3474
|
+
return bigIntSafeStringify({
|
|
3475
|
+
AccountIndex: txInfo.accountIndex,
|
|
3451
3476
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3452
3477
|
MarketIndex: txInfo.marketIndex,
|
|
3453
3478
|
InitialMarginFraction: txInfo.initialMarginFraction,
|
|
3454
3479
|
MarginMode: txInfo.marginMode,
|
|
3455
|
-
ExpiredAt:
|
|
3456
|
-
Nonce:
|
|
3480
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3481
|
+
Nonce: txInfo.nonce,
|
|
3457
3482
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3458
3483
|
});
|
|
3459
3484
|
}
|
|
3460
3485
|
function serializeUpdateMargin(txInfo) {
|
|
3461
|
-
return
|
|
3462
|
-
AccountIndex:
|
|
3486
|
+
return bigIntSafeStringify({
|
|
3487
|
+
AccountIndex: txInfo.accountIndex,
|
|
3463
3488
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3464
3489
|
MarketIndex: txInfo.marketIndex,
|
|
3465
|
-
UsdcAmount:
|
|
3490
|
+
UsdcAmount: txInfo.usdcAmount,
|
|
3466
3491
|
Direction: txInfo.direction,
|
|
3467
|
-
ExpiredAt:
|
|
3468
|
-
Nonce:
|
|
3492
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3493
|
+
Nonce: txInfo.nonce,
|
|
3469
3494
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3470
3495
|
});
|
|
3471
3496
|
}
|
|
3472
3497
|
function serializeCreatePublicPool(txInfo) {
|
|
3473
|
-
return
|
|
3474
|
-
AccountIndex:
|
|
3498
|
+
return bigIntSafeStringify({
|
|
3499
|
+
AccountIndex: txInfo.accountIndex,
|
|
3475
3500
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3476
|
-
OperatorFee:
|
|
3477
|
-
InitialTotalShares:
|
|
3501
|
+
OperatorFee: txInfo.operatorFee,
|
|
3502
|
+
InitialTotalShares: txInfo.initialTotalShares,
|
|
3478
3503
|
MinOperatorShareRate: txInfo.minOperatorShareRate,
|
|
3479
|
-
ExpiredAt:
|
|
3480
|
-
Nonce:
|
|
3504
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3505
|
+
Nonce: txInfo.nonce,
|
|
3481
3506
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3482
3507
|
});
|
|
3483
3508
|
}
|
|
3484
3509
|
function serializeUpdatePublicPool(txInfo) {
|
|
3485
|
-
return
|
|
3486
|
-
AccountIndex:
|
|
3510
|
+
return bigIntSafeStringify({
|
|
3511
|
+
AccountIndex: txInfo.accountIndex,
|
|
3487
3512
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3488
|
-
PublicPoolIndex:
|
|
3513
|
+
PublicPoolIndex: txInfo.publicPoolIndex,
|
|
3489
3514
|
Status: txInfo.status,
|
|
3490
|
-
OperatorFee:
|
|
3515
|
+
OperatorFee: txInfo.operatorFee,
|
|
3491
3516
|
MinOperatorShareRate: txInfo.minOperatorShareRate,
|
|
3492
|
-
ExpiredAt:
|
|
3493
|
-
Nonce:
|
|
3517
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3518
|
+
Nonce: txInfo.nonce,
|
|
3494
3519
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3495
3520
|
});
|
|
3496
3521
|
}
|
|
3497
3522
|
function serializeMintShares(txInfo) {
|
|
3498
|
-
return
|
|
3499
|
-
AccountIndex:
|
|
3523
|
+
return bigIntSafeStringify({
|
|
3524
|
+
AccountIndex: txInfo.accountIndex,
|
|
3500
3525
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3501
|
-
PublicPoolIndex:
|
|
3502
|
-
ShareAmount:
|
|
3503
|
-
ExpiredAt:
|
|
3504
|
-
Nonce:
|
|
3526
|
+
PublicPoolIndex: txInfo.publicPoolIndex,
|
|
3527
|
+
ShareAmount: txInfo.shareAmount,
|
|
3528
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3529
|
+
Nonce: txInfo.nonce,
|
|
3505
3530
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3506
3531
|
});
|
|
3507
3532
|
}
|
|
3508
3533
|
function serializeBurnShares(txInfo) {
|
|
3509
|
-
return
|
|
3510
|
-
AccountIndex:
|
|
3534
|
+
return bigIntSafeStringify({
|
|
3535
|
+
AccountIndex: txInfo.accountIndex,
|
|
3511
3536
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3512
|
-
PublicPoolIndex:
|
|
3513
|
-
ShareAmount:
|
|
3514
|
-
ExpiredAt:
|
|
3515
|
-
Nonce:
|
|
3537
|
+
PublicPoolIndex: txInfo.publicPoolIndex,
|
|
3538
|
+
ShareAmount: txInfo.shareAmount,
|
|
3539
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3540
|
+
Nonce: txInfo.nonce,
|
|
3516
3541
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3517
3542
|
});
|
|
3518
3543
|
}
|
|
3519
3544
|
function serializeCreateGroupedOrders(txInfo) {
|
|
3520
3545
|
const orders = txInfo.orders.map((order) => ({
|
|
3521
3546
|
MarketIndex: order.marketIndex,
|
|
3522
|
-
ClientOrderIndex:
|
|
3523
|
-
BaseAmount:
|
|
3547
|
+
ClientOrderIndex: order.clientOrderIndex,
|
|
3548
|
+
BaseAmount: order.baseAmount,
|
|
3524
3549
|
Price: order.price,
|
|
3525
3550
|
IsAsk: order.isAsk,
|
|
3526
3551
|
Type: order.type,
|
|
3527
3552
|
TimeInForce: order.timeInForce,
|
|
3528
3553
|
ReduceOnly: order.reduceOnly,
|
|
3529
3554
|
TriggerPrice: order.triggerPrice,
|
|
3530
|
-
OrderExpiry:
|
|
3555
|
+
OrderExpiry: order.orderExpiry
|
|
3531
3556
|
}));
|
|
3532
|
-
return
|
|
3533
|
-
AccountIndex:
|
|
3557
|
+
return bigIntSafeStringify({
|
|
3558
|
+
AccountIndex: txInfo.accountIndex,
|
|
3534
3559
|
ApiKeyIndex: txInfo.apiKeyIndex,
|
|
3535
3560
|
GroupingType: txInfo.groupingType,
|
|
3536
3561
|
Orders: orders,
|
|
3537
|
-
ExpiredAt:
|
|
3538
|
-
Nonce:
|
|
3562
|
+
ExpiredAt: txInfo.expiredAt,
|
|
3563
|
+
Nonce: txInfo.nonce,
|
|
3539
3564
|
Sig: txInfo.signature ? uint8ArrayToBase64(txInfo.signature) : null
|
|
3540
3565
|
});
|
|
3541
3566
|
}
|
|
3542
|
-
function
|
|
3543
|
-
if (
|
|
3544
|
-
return
|
|
3545
|
-
} else if (txInfo instanceof L2CancelOrderTxInfo) {
|
|
3546
|
-
return serializeCancelOrder(txInfo);
|
|
3547
|
-
} else if (txInfo instanceof L2ModifyOrderTxInfo) {
|
|
3548
|
-
return serializeModifyOrder(txInfo);
|
|
3549
|
-
} else if (txInfo instanceof L2CancelAllOrdersTxInfo) {
|
|
3550
|
-
return serializeCancelAllOrders(txInfo);
|
|
3551
|
-
} else if (txInfo instanceof L2WithdrawTxInfo) {
|
|
3552
|
-
return serializeWithdraw(txInfo);
|
|
3553
|
-
} else if (txInfo instanceof L2TransferTxInfo) {
|
|
3554
|
-
return serializeTransfer(txInfo);
|
|
3555
|
-
} else if (txInfo instanceof L2ChangePubKeyTxInfo) {
|
|
3556
|
-
return serializeChangePubKey(txInfo);
|
|
3557
|
-
} else if (txInfo instanceof L2CreateSubAccountTxInfo) {
|
|
3558
|
-
return serializeCreateSubAccount(txInfo);
|
|
3559
|
-
} else if (txInfo instanceof L2UpdateLeverageTxInfo) {
|
|
3560
|
-
return serializeUpdateLeverage(txInfo);
|
|
3561
|
-
} else if (txInfo instanceof L2UpdateMarginTxInfo) {
|
|
3562
|
-
return serializeUpdateMargin(txInfo);
|
|
3563
|
-
} else if (txInfo instanceof L2CreatePublicPoolTxInfo) {
|
|
3564
|
-
return serializeCreatePublicPool(txInfo);
|
|
3565
|
-
} else if (txInfo instanceof L2UpdatePublicPoolTxInfo) {
|
|
3566
|
-
return serializeUpdatePublicPool(txInfo);
|
|
3567
|
-
} else if (txInfo instanceof L2MintSharesTxInfo) {
|
|
3568
|
-
return serializeMintShares(txInfo);
|
|
3569
|
-
} else if (txInfo instanceof L2BurnSharesTxInfo) {
|
|
3570
|
-
return serializeBurnShares(txInfo);
|
|
3571
|
-
} else if (txInfo instanceof L2CreateGroupedOrdersTxInfo) {
|
|
3572
|
-
return serializeCreateGroupedOrders(txInfo);
|
|
3567
|
+
function uint8ArrayToBase64(bytes) {
|
|
3568
|
+
if (typeof Buffer !== "undefined") {
|
|
3569
|
+
return Buffer.from(bytes).toString("base64");
|
|
3573
3570
|
}
|
|
3574
|
-
|
|
3571
|
+
let binary = "";
|
|
3572
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
3573
|
+
binary += String.fromCharCode(bytes[i]);
|
|
3574
|
+
}
|
|
3575
|
+
return btoa(binary);
|
|
3576
|
+
}
|
|
3577
|
+
function bigIntSafeStringify(obj) {
|
|
3578
|
+
function serialize(value) {
|
|
3579
|
+
if (typeof value === "bigint") return value.toString();
|
|
3580
|
+
if (value === null) return "null";
|
|
3581
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
3582
|
+
return String(value);
|
|
3583
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
3584
|
+
if (Array.isArray(value)) return "[" + value.map(serialize).join(",") + "]";
|
|
3585
|
+
if (typeof value === "object") {
|
|
3586
|
+
const entries = [];
|
|
3587
|
+
for (const [k, v] of Object.entries(value)) {
|
|
3588
|
+
entries.push(JSON.stringify(k) + ":" + serialize(v));
|
|
3589
|
+
}
|
|
3590
|
+
return "{" + entries.join(",") + "}";
|
|
3591
|
+
}
|
|
3592
|
+
return JSON.stringify(value);
|
|
3593
|
+
}
|
|
3594
|
+
return serialize(obj);
|
|
3575
3595
|
}
|
|
3576
3596
|
|
|
3577
3597
|
// src/client/txClient.ts
|
|
3578
3598
|
var TxClient = class {
|
|
3579
3599
|
constructor(apiClient, privateKey, accountIndex, apiKeyIndex, chainId) {
|
|
3600
|
+
/**
|
|
3601
|
+
* Get the next nonce for the current account from the server
|
|
3602
|
+
*/
|
|
3603
|
+
this.getNextNonce = async () => {
|
|
3604
|
+
if (!this.apiClient) {
|
|
3605
|
+
throw new Error("HTTP client is not configured");
|
|
3606
|
+
}
|
|
3607
|
+
return this.apiClient.getNextNonce(this._accountIndex, this._apiKeyIndex);
|
|
3608
|
+
};
|
|
3580
3609
|
let privateKeyBytes;
|
|
3581
3610
|
try {
|
|
3582
3611
|
privateKeyBytes = hexToBytes(privateKey);
|
|
@@ -5574,19 +5603,24 @@ var ExchangeClient = class {
|
|
|
5574
5603
|
async createBatchOrders(params) {
|
|
5575
5604
|
const txTypes = [];
|
|
5576
5605
|
const txInfos = [];
|
|
5606
|
+
let nextNonce = await this.txClient.getNextNonce();
|
|
5577
5607
|
for (const order of params.orders) {
|
|
5578
|
-
const txInfo = await this.txClient.signCreateOrder(
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5608
|
+
const txInfo = await this.txClient.signCreateOrder(
|
|
5609
|
+
{
|
|
5610
|
+
marketIndex: order.marketIndex,
|
|
5611
|
+
clientOrderIndex: order.clientOrderIndex,
|
|
5612
|
+
baseAmount: order.baseAmount,
|
|
5613
|
+
price: order.price,
|
|
5614
|
+
isAsk: order.isAsk,
|
|
5615
|
+
type: order.orderType,
|
|
5616
|
+
timeInForce: order.timeInForce,
|
|
5617
|
+
reduceOnly: order.reduceOnly,
|
|
5618
|
+
triggerPrice: order.triggerPrice,
|
|
5619
|
+
orderExpiry: order.orderExpiry
|
|
5620
|
+
},
|
|
5621
|
+
{ nonce: nextNonce }
|
|
5622
|
+
);
|
|
5623
|
+
nextNonce++;
|
|
5590
5624
|
txTypes.push(TxType.L2CreateOrder);
|
|
5591
5625
|
txInfos.push(serializeCreateOrder(txInfo));
|
|
5592
5626
|
}
|
|
@@ -6130,6 +6164,7 @@ var WsClient = class {
|
|
|
6130
6164
|
USDC_ASSET_INDEX,
|
|
6131
6165
|
ValidationError,
|
|
6132
6166
|
WsClient,
|
|
6167
|
+
bigIntSafeStringify,
|
|
6133
6168
|
bytesToFieldElements,
|
|
6134
6169
|
bytesToHex,
|
|
6135
6170
|
checkClient,
|