@lifi/perps-sdk-provider-lighter 0.2.0-alpha.0
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/LICENSE +201 -0
- package/README.md +176 -0
- package/dist/cjs/LighterProvider.d.ts +20 -0
- package/dist/cjs/LighterProvider.d.ts.map +1 -0
- package/dist/cjs/LighterProvider.js +592 -0
- package/dist/cjs/LighterProvider.js.map +1 -0
- package/dist/cjs/accountConfig.d.ts +3 -0
- package/dist/cjs/accountConfig.d.ts.map +1 -0
- package/dist/cjs/accountConfig.js +69 -0
- package/dist/cjs/accountConfig.js.map +1 -0
- package/dist/cjs/accountSummary.d.ts +3 -0
- package/dist/cjs/accountSummary.d.ts.map +1 -0
- package/dist/cjs/accountSummary.js +8 -0
- package/dist/cjs/accountSummary.js.map +1 -0
- package/dist/cjs/constants.d.ts +14 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +18 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/signers/LighterKeyStore.d.ts +18 -0
- package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/cjs/signers/LighterKeyStore.js +54 -0
- package/dist/cjs/signers/LighterKeyStore.js.map +1 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts +56 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js +127 -0
- package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -0
- package/dist/cjs/signers/LighterSigner.d.ts +41 -0
- package/dist/cjs/signers/LighterSigner.d.ts.map +1 -0
- package/dist/cjs/signers/LighterSigner.js +175 -0
- package/dist/cjs/signers/LighterSigner.js.map +1 -0
- package/dist/cjs/signers/createAuthToken.d.ts +12 -0
- package/dist/cjs/signers/createAuthToken.d.ts.map +1 -0
- package/dist/cjs/signers/createAuthToken.js +28 -0
- package/dist/cjs/signers/createAuthToken.js.map +1 -0
- package/dist/cjs/signers/index.d.ts +11 -0
- package/dist/cjs/signers/index.d.ts.map +1 -0
- package/dist/cjs/signers/index.js +19 -0
- package/dist/cjs/signers/index.js.map +1 -0
- package/dist/cjs/signers/signActions.d.ts +15 -0
- package/dist/cjs/signers/signActions.d.ts.map +1 -0
- package/dist/cjs/signers/signActions.js +142 -0
- package/dist/cjs/signers/signActions.js.map +1 -0
- package/dist/cjs/signers/wasmLoader.d.ts +42 -0
- package/dist/cjs/signers/wasmLoader.d.ts.map +1 -0
- package/dist/cjs/signers/wasmLoader.js +166 -0
- package/dist/cjs/signers/wasmLoader.js.map +1 -0
- package/dist/cjs/types/account.d.ts +97 -0
- package/dist/cjs/types/account.d.ts.map +1 -0
- package/dist/cjs/types/account.js +3 -0
- package/dist/cjs/types/account.js.map +1 -0
- package/dist/cjs/types/action.d.ts +72 -0
- package/dist/cjs/types/action.d.ts.map +1 -0
- package/dist/cjs/types/action.js +23 -0
- package/dist/cjs/types/action.js.map +1 -0
- package/dist/cjs/types/activity.d.ts +73 -0
- package/dist/cjs/types/activity.d.ts.map +1 -0
- package/dist/cjs/types/activity.js +3 -0
- package/dist/cjs/types/activity.js.map +1 -0
- package/dist/cjs/types/asset.d.ts +122 -0
- package/dist/cjs/types/asset.d.ts.map +1 -0
- package/dist/cjs/types/asset.js +3 -0
- package/dist/cjs/types/asset.js.map +1 -0
- package/dist/cjs/types/fill.d.ts +29 -0
- package/dist/cjs/types/fill.d.ts.map +1 -0
- package/dist/cjs/types/fill.js +3 -0
- package/dist/cjs/types/fill.js.map +1 -0
- package/dist/cjs/types/index.d.ts +9 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +25 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/order.d.ts +57 -0
- package/dist/cjs/types/order.d.ts.map +1 -0
- package/dist/cjs/types/order.js +3 -0
- package/dist/cjs/types/order.js.map +1 -0
- package/dist/cjs/types/submit.d.ts +39 -0
- package/dist/cjs/types/submit.d.ts.map +1 -0
- package/dist/cjs/types/submit.js +3 -0
- package/dist/cjs/types/submit.js.map +1 -0
- package/dist/cjs/types/ws.d.ts +84 -0
- package/dist/cjs/types/ws.d.ts.map +1 -0
- package/dist/cjs/types/ws.js +3 -0
- package/dist/cjs/types/ws.js.map +1 -0
- package/dist/cjs/utils/activityCursor.d.ts +12 -0
- package/dist/cjs/utils/activityCursor.d.ts.map +1 -0
- package/dist/cjs/utils/activityCursor.js +85 -0
- package/dist/cjs/utils/activityCursor.js.map +1 -0
- package/dist/cjs/utils/apiClient.d.ts +26 -0
- package/dist/cjs/utils/apiClient.d.ts.map +1 -0
- package/dist/cjs/utils/apiClient.js +94 -0
- package/dist/cjs/utils/apiClient.js.map +1 -0
- package/dist/cjs/utils/fetchDetailedAccount.d.ts +5 -0
- package/dist/cjs/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/cjs/utils/fetchDetailedAccount.js +22 -0
- package/dist/cjs/utils/fetchDetailedAccount.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +16 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js +45 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/lighterAsset.d.ts +3 -0
- package/dist/cjs/utils/lighterAsset.d.ts.map +1 -0
- package/dist/cjs/utils/lighterAsset.js +12 -0
- package/dist/cjs/utils/lighterAsset.js.map +1 -0
- package/dist/cjs/utils/liquidation.d.ts +4 -0
- package/dist/cjs/utils/liquidation.d.ts.map +1 -0
- package/dist/cjs/utils/liquidation.js +16 -0
- package/dist/cjs/utils/liquidation.js.map +1 -0
- package/dist/cjs/utils/mapFill.d.ts +4 -0
- package/dist/cjs/utils/mapFill.d.ts.map +1 -0
- package/dist/cjs/utils/mapFill.js +61 -0
- package/dist/cjs/utils/mapFill.js.map +1 -0
- package/dist/cjs/utils/mapOpenPositions.d.ts +4 -0
- package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/cjs/utils/mapOpenPositions.js +9 -0
- package/dist/cjs/utils/mapOpenPositions.js.map +1 -0
- package/dist/cjs/utils/mapOrder.d.ts +15 -0
- package/dist/cjs/utils/mapOrder.d.ts.map +1 -0
- package/dist/cjs/utils/mapOrder.js +164 -0
- package/dist/cjs/utils/mapOrder.js.map +1 -0
- package/dist/cjs/utils/mapPosition.d.ts +4 -0
- package/dist/cjs/utils/mapPosition.d.ts.map +1 -0
- package/dist/cjs/utils/mapPosition.js +30 -0
- package/dist/cjs/utils/mapPosition.js.map +1 -0
- package/dist/cjs/utils/ohlcvInterval.d.ts +2 -0
- package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/cjs/utils/ohlcvInterval.js +26 -0
- package/dist/cjs/utils/ohlcvInterval.js.map +1 -0
- package/dist/cjs/utils/orderFormatting.d.ts +4 -0
- package/dist/cjs/utils/orderFormatting.d.ts.map +1 -0
- package/dist/cjs/utils/orderFormatting.js +23 -0
- package/dist/cjs/utils/orderFormatting.js.map +1 -0
- package/dist/cjs/utils/time.d.ts +3 -0
- package/dist/cjs/utils/time.d.ts.map +1 -0
- package/dist/cjs/utils/time.js +8 -0
- package/dist/cjs/utils/time.js.map +1 -0
- package/dist/cjs/utils/wireEncoding.d.ts +9 -0
- package/dist/cjs/utils/wireEncoding.d.ts.map +1 -0
- package/dist/cjs/utils/wireEncoding.js +87 -0
- package/dist/cjs/utils/wireEncoding.js.map +1 -0
- package/dist/cjs/websocket/LighterWsProvider.d.ts +45 -0
- package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/cjs/websocket/LighterWsProvider.js +396 -0
- package/dist/cjs/websocket/LighterWsProvider.js.map +1 -0
- package/dist/esm/LighterProvider.d.ts +105 -0
- package/dist/esm/LighterProvider.d.ts.map +1 -0
- package/dist/esm/LighterProvider.js +684 -0
- package/dist/esm/LighterProvider.js.map +1 -0
- package/dist/esm/accountConfig.d.ts +14 -0
- package/dist/esm/accountConfig.d.ts.map +1 -0
- package/dist/esm/accountConfig.js +135 -0
- package/dist/esm/accountConfig.js.map +1 -0
- package/dist/esm/accountSummary.d.ts +12 -0
- package/dist/esm/accountSummary.d.ts.map +1 -0
- package/dist/esm/accountSummary.js +14 -0
- package/dist/esm/accountSummary.js.map +1 -0
- package/dist/esm/constants.d.ts +74 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +73 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/signers/LighterKeyStore.d.ts +24 -0
- package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/esm/signers/LighterKeyStore.js +55 -0
- package/dist/esm/signers/LighterKeyStore.js.map +1 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +157 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.js +194 -0
- package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -0
- package/dist/esm/signers/LighterSigner.d.ts +94 -0
- package/dist/esm/signers/LighterSigner.d.ts.map +1 -0
- package/dist/esm/signers/LighterSigner.js +228 -0
- package/dist/esm/signers/LighterSigner.js.map +1 -0
- package/dist/esm/signers/createAuthToken.d.ts +36 -0
- package/dist/esm/signers/createAuthToken.d.ts.map +1 -0
- package/dist/esm/signers/createAuthToken.js +42 -0
- package/dist/esm/signers/createAuthToken.js.map +1 -0
- package/dist/esm/signers/index.d.ts +11 -0
- package/dist/esm/signers/index.d.ts.map +1 -0
- package/dist/esm/signers/index.js +7 -0
- package/dist/esm/signers/index.js.map +1 -0
- package/dist/esm/signers/signActions.d.ts +54 -0
- package/dist/esm/signers/signActions.d.ts.map +1 -0
- package/dist/esm/signers/signActions.js +193 -0
- package/dist/esm/signers/signActions.js.map +1 -0
- package/dist/esm/signers/wasmLoader.d.ts +79 -0
- package/dist/esm/signers/wasmLoader.d.ts.map +1 -0
- package/dist/esm/signers/wasmLoader.js +180 -0
- package/dist/esm/signers/wasmLoader.js.map +1 -0
- package/dist/esm/types/account.d.ts +113 -0
- package/dist/esm/types/account.d.ts.map +1 -0
- package/dist/esm/types/account.js +4 -0
- package/dist/esm/types/account.js.map +1 -0
- package/dist/esm/types/action.d.ts +146 -0
- package/dist/esm/types/action.d.ts.map +1 -0
- package/dist/esm/types/action.js +50 -0
- package/dist/esm/types/action.js.map +1 -0
- package/dist/esm/types/activity.d.ts +83 -0
- package/dist/esm/types/activity.d.ts.map +1 -0
- package/dist/esm/types/activity.js +4 -0
- package/dist/esm/types/activity.js.map +1 -0
- package/dist/esm/types/asset.d.ts +134 -0
- package/dist/esm/types/asset.d.ts.map +1 -0
- package/dist/esm/types/asset.js +3 -0
- package/dist/esm/types/asset.js.map +1 -0
- package/dist/esm/types/fill.d.ts +31 -0
- package/dist/esm/types/fill.d.ts.map +1 -0
- package/dist/esm/types/fill.js +3 -0
- package/dist/esm/types/fill.js.map +1 -0
- package/dist/esm/types/index.d.ts +9 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +12 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/order.d.ts +61 -0
- package/dist/esm/types/order.d.ts.map +1 -0
- package/dist/esm/types/order.js +3 -0
- package/dist/esm/types/order.js.map +1 -0
- package/dist/esm/types/submit.d.ts +76 -0
- package/dist/esm/types/submit.d.ts.map +1 -0
- package/dist/esm/types/submit.js +3 -0
- package/dist/esm/types/submit.js.map +1 -0
- package/dist/esm/types/ws.d.ts +124 -0
- package/dist/esm/types/ws.d.ts.map +1 -0
- package/dist/esm/types/ws.js +11 -0
- package/dist/esm/types/ws.js.map +1 -0
- package/dist/esm/utils/activityCursor.d.ts +51 -0
- package/dist/esm/utils/activityCursor.d.ts.map +1 -0
- package/dist/esm/utils/activityCursor.js +99 -0
- package/dist/esm/utils/activityCursor.js.map +1 -0
- package/dist/esm/utils/apiClient.d.ts +65 -0
- package/dist/esm/utils/apiClient.d.ts.map +1 -0
- package/dist/esm/utils/apiClient.js +131 -0
- package/dist/esm/utils/apiClient.js.map +1 -0
- package/dist/esm/utils/fetchDetailedAccount.d.ts +11 -0
- package/dist/esm/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/esm/utils/fetchDetailedAccount.js +24 -0
- package/dist/esm/utils/fetchDetailedAccount.js.map +1 -0
- package/dist/esm/utils/index.d.ts +16 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +17 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/lighterAsset.d.ts +4 -0
- package/dist/esm/utils/lighterAsset.d.ts.map +1 -0
- package/dist/esm/utils/lighterAsset.js +9 -0
- package/dist/esm/utils/lighterAsset.js.map +1 -0
- package/dist/esm/utils/liquidation.d.ts +22 -0
- package/dist/esm/utils/liquidation.d.ts.map +1 -0
- package/dist/esm/utils/liquidation.js +31 -0
- package/dist/esm/utils/liquidation.js.map +1 -0
- package/dist/esm/utils/mapFill.d.ts +10 -0
- package/dist/esm/utils/mapFill.d.ts.map +1 -0
- package/dist/esm/utils/mapFill.js +72 -0
- package/dist/esm/utils/mapFill.js.map +1 -0
- package/dist/esm/utils/mapOpenPositions.d.ts +11 -0
- package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/esm/utils/mapOpenPositions.js +12 -0
- package/dist/esm/utils/mapOpenPositions.js.map +1 -0
- package/dist/esm/utils/mapOrder.d.ts +72 -0
- package/dist/esm/utils/mapOrder.d.ts.map +1 -0
- package/dist/esm/utils/mapOrder.js +219 -0
- package/dist/esm/utils/mapOrder.js.map +1 -0
- package/dist/esm/utils/mapPosition.d.ts +9 -0
- package/dist/esm/utils/mapPosition.d.ts.map +1 -0
- package/dist/esm/utils/mapPosition.js +34 -0
- package/dist/esm/utils/mapPosition.js.map +1 -0
- package/dist/esm/utils/ohlcvInterval.d.ts +3 -0
- package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/esm/utils/ohlcvInterval.js +30 -0
- package/dist/esm/utils/ohlcvInterval.js.map +1 -0
- package/dist/esm/utils/orderFormatting.d.ts +29 -0
- package/dist/esm/utils/orderFormatting.d.ts.map +1 -0
- package/dist/esm/utils/orderFormatting.js +41 -0
- package/dist/esm/utils/orderFormatting.js.map +1 -0
- package/dist/esm/utils/time.d.ts +5 -0
- package/dist/esm/utils/time.d.ts.map +1 -0
- package/dist/esm/utils/time.js +5 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/esm/utils/wireEncoding.d.ts +72 -0
- package/dist/esm/utils/wireEncoding.d.ts.map +1 -0
- package/dist/esm/utils/wireEncoding.js +129 -0
- package/dist/esm/utils/wireEncoding.js.map +1 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts +97 -0
- package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/esm/websocket/LighterWsProvider.js +489 -0
- package/dist/esm/websocket/LighterWsProvider.js.map +1 -0
- package/dist/types/LighterProvider.d.ts +105 -0
- package/dist/types/LighterProvider.d.ts.map +1 -0
- package/dist/types/accountConfig.d.ts +14 -0
- package/dist/types/accountConfig.d.ts.map +1 -0
- package/dist/types/accountSummary.d.ts +12 -0
- package/dist/types/accountSummary.d.ts.map +1 -0
- package/dist/types/constants.d.ts +74 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/signers/LighterKeyStore.d.ts +24 -0
- package/dist/types/signers/LighterKeyStore.d.ts.map +1 -0
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +157 -0
- package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
- package/dist/types/signers/LighterSigner.d.ts +94 -0
- package/dist/types/signers/LighterSigner.d.ts.map +1 -0
- package/dist/types/signers/createAuthToken.d.ts +36 -0
- package/dist/types/signers/createAuthToken.d.ts.map +1 -0
- package/dist/types/signers/index.d.ts +11 -0
- package/dist/types/signers/index.d.ts.map +1 -0
- package/dist/types/signers/signActions.d.ts +54 -0
- package/dist/types/signers/signActions.d.ts.map +1 -0
- package/dist/types/signers/wasmLoader.d.ts +79 -0
- package/dist/types/signers/wasmLoader.d.ts.map +1 -0
- package/dist/types/types/account.d.ts +113 -0
- package/dist/types/types/account.d.ts.map +1 -0
- package/dist/types/types/action.d.ts +146 -0
- package/dist/types/types/action.d.ts.map +1 -0
- package/dist/types/types/activity.d.ts +83 -0
- package/dist/types/types/activity.d.ts.map +1 -0
- package/dist/types/types/asset.d.ts +134 -0
- package/dist/types/types/asset.d.ts.map +1 -0
- package/dist/types/types/fill.d.ts +31 -0
- package/dist/types/types/fill.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +9 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/order.d.ts +61 -0
- package/dist/types/types/order.d.ts.map +1 -0
- package/dist/types/types/submit.d.ts +76 -0
- package/dist/types/types/submit.d.ts.map +1 -0
- package/dist/types/types/ws.d.ts +124 -0
- package/dist/types/types/ws.d.ts.map +1 -0
- package/dist/types/utils/activityCursor.d.ts +51 -0
- package/dist/types/utils/activityCursor.d.ts.map +1 -0
- package/dist/types/utils/apiClient.d.ts +65 -0
- package/dist/types/utils/apiClient.d.ts.map +1 -0
- package/dist/types/utils/fetchDetailedAccount.d.ts +11 -0
- package/dist/types/utils/fetchDetailedAccount.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +16 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/lighterAsset.d.ts +4 -0
- package/dist/types/utils/lighterAsset.d.ts.map +1 -0
- package/dist/types/utils/liquidation.d.ts +22 -0
- package/dist/types/utils/liquidation.d.ts.map +1 -0
- package/dist/types/utils/mapFill.d.ts +10 -0
- package/dist/types/utils/mapFill.d.ts.map +1 -0
- package/dist/types/utils/mapOpenPositions.d.ts +11 -0
- package/dist/types/utils/mapOpenPositions.d.ts.map +1 -0
- package/dist/types/utils/mapOrder.d.ts +72 -0
- package/dist/types/utils/mapOrder.d.ts.map +1 -0
- package/dist/types/utils/mapPosition.d.ts +9 -0
- package/dist/types/utils/mapPosition.d.ts.map +1 -0
- package/dist/types/utils/ohlcvInterval.d.ts +3 -0
- package/dist/types/utils/ohlcvInterval.d.ts.map +1 -0
- package/dist/types/utils/orderFormatting.d.ts +29 -0
- package/dist/types/utils/orderFormatting.d.ts.map +1 -0
- package/dist/types/utils/time.d.ts +5 -0
- package/dist/types/utils/time.d.ts.map +1 -0
- package/dist/types/utils/wireEncoding.d.ts +72 -0
- package/dist/types/utils/wireEncoding.d.ts.map +1 -0
- package/dist/types/websocket/LighterWsProvider.d.ts +97 -0
- package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -0
- package/dist/wasm/lighter-signer.wasm +0 -0
- package/dist/wasm/wasm_exec.js +575 -0
- package/package.json +67 -0
- package/src/LighterProvider.ts +1167 -0
- package/src/accountConfig.ts +162 -0
- package/src/accountSummary.ts +22 -0
- package/src/constants.ts +89 -0
- package/src/index.ts +37 -0
- package/src/signers/LighterKeyStore.ts +79 -0
- package/src/signers/LighterReadOnlyTokenManager.ts +340 -0
- package/src/signers/LighterSigner.ts +400 -0
- package/src/signers/createAuthToken.ts +69 -0
- package/src/signers/index.ts +36 -0
- package/src/signers/signActions.ts +311 -0
- package/src/signers/wasmLoader.ts +293 -0
- package/src/types/account.ts +123 -0
- package/src/types/action.ts +163 -0
- package/src/types/activity.ts +94 -0
- package/src/types/asset.ts +146 -0
- package/src/types/fill.ts +42 -0
- package/src/types/index.ts +12 -0
- package/src/types/order.ts +65 -0
- package/src/types/submit.ts +83 -0
- package/src/types/ws.ts +136 -0
- package/src/utils/activityCursor.ts +150 -0
- package/src/utils/apiClient.ts +185 -0
- package/src/utils/fetchDetailedAccount.ts +46 -0
- package/src/utils/index.ts +38 -0
- package/src/utils/lighterAsset.ts +10 -0
- package/src/utils/liquidation.ts +39 -0
- package/src/utils/mapFill.ts +108 -0
- package/src/utils/mapOpenPositions.ts +18 -0
- package/src/utils/mapOrder.ts +258 -0
- package/src/utils/mapPosition.ts +42 -0
- package/src/utils/ohlcvInterval.ts +34 -0
- package/src/utils/orderFormatting.ts +46 -0
- package/src/utils/time.ts +6 -0
- package/src/utils/wireEncoding.ts +179 -0
- package/src/websocket/LighterWsProvider.ts +725 -0
- package/wasm/lighter-signer.wasm +0 -0
- package/wasm/wasm_exec.js +575 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
import { ExplorerChainId, explorerTxUrl, getAssetRegistry, getMarketRegistry, PerpsError, resolveQuote, resolveRetryPolicy, } from '@lifi/perps-sdk';
|
|
2
|
+
import { ActionType, ActivityType, PerpsErrorCode } from '@lifi/perps-types';
|
|
3
|
+
import { projectLighterConfigSettings } from './accountConfig.js';
|
|
4
|
+
import { summarizeLighterAccount } from './accountSummary.js';
|
|
5
|
+
import { DEFAULT_API_KEY_INDEX, DEFAULT_LIGHTER_REST_URL, DEFAULT_TRADES_LIMIT, LIGHTER_ALL_MARKETS_WILDCARD, LIGHTER_BASE_FEE_TIER, LIGHTER_FEE_TICK_SCALE, LIGHTER_HISTORY_PAGE_SIZE, LIGHTER_PROVIDER_KEY, } from './constants.js';
|
|
6
|
+
import { createAuthToken } from './signers/createAuthToken.js';
|
|
7
|
+
import { LighterReadOnlyTokenManager } from './signers/LighterReadOnlyTokenManager.js';
|
|
8
|
+
import { lighterSignActions } from './signers/signActions.js';
|
|
9
|
+
import { decodeActivityCursor, encodeActivityCursor, } from './utils/activityCursor.js';
|
|
10
|
+
import { LIGHTER_RETRY_DEFAULTS, LighterApiClient, LighterAuthRejectedError, } from './utils/apiClient.js';
|
|
11
|
+
import { classifyAndMapOrders, estimateLiquidationPrice, fetchDetailedAccount, formatOrderPrice, formatOrderSize, lighterAsset, mapFill, mapOpenPositions, mapOrderDetail, toIsoFromMs, toIsoFromSeconds, } from './utils/index.js';
|
|
12
|
+
const ZERO_FEE_TIER = { maker: '0', taker: '0' };
|
|
13
|
+
const tickToFeeString = (tick) => String(tick / LIGHTER_FEE_TICK_SCALE);
|
|
14
|
+
const projectFeeTier = (limits) => ({
|
|
15
|
+
maker: tickToFeeString(limits.current_maker_fee_tick),
|
|
16
|
+
taker: tickToFeeString(limits.current_taker_fee_tick),
|
|
17
|
+
});
|
|
18
|
+
const orderCountFor = (p) => (p.open_order_count ?? 0) +
|
|
19
|
+
(p.pending_order_count ?? 0) +
|
|
20
|
+
(p.position_tied_order_count ?? 0);
|
|
21
|
+
/**
|
|
22
|
+
* Lighter `sendTx` returns a bare lowercase-hex tx hash (40 bytes → 80 hex
|
|
23
|
+
* chars). `Order.order_id` is a different identifier the matching engine
|
|
24
|
+
* assigns later. The strict 80-char shape lets `getOrder` route freshly
|
|
25
|
+
* submitted IDs to the tx-hash branch without false positives.
|
|
26
|
+
*/
|
|
27
|
+
const TX_HASH_PATTERN = /^[0-9a-f]{80}$/;
|
|
28
|
+
const INACTIVE_ORDERS_LOOKUP_LIMIT = 100;
|
|
29
|
+
/**
|
|
30
|
+
* Expiry requested when the SDK lazily creates a Lighter read-only token for
|
|
31
|
+
* authenticated reads. 10 years — Lighter caps read-only tokens at the
|
|
32
|
+
* venue's maximum, so a single token covers the account's lifetime.
|
|
33
|
+
*/
|
|
34
|
+
const DEFAULT_READ_ONLY_TOKEN_LIFETIME_SECONDS = 10 * 365 * 24 * 60 * 60;
|
|
35
|
+
/** Compare Lighter public keys irrespective of `0x` prefix / casing. */
|
|
36
|
+
const normalizeLighterPublicKey = (key) => key.replace(/^0x/i, '').toLowerCase();
|
|
37
|
+
/**
|
|
38
|
+
* Lighter provider plugin factory. Returns an object implementing
|
|
39
|
+
* {@link PerpsProviderPlugin}, mirroring the `EthereumProvider()` / `hyperliquidProvider()`
|
|
40
|
+
* shape used by the rest of the LI.FI SDK family.
|
|
41
|
+
*
|
|
42
|
+
* Read functions call Lighter's REST API directly with no LI.FI backend hop.
|
|
43
|
+
* Auth-gated reads resolve their token via the order documented on
|
|
44
|
+
* {@link LighterProviderOptions}.
|
|
45
|
+
*
|
|
46
|
+
* Write actions (`WASM_BLOB` and `EVM_TX` signing) are dispatched via
|
|
47
|
+
* `signActions` — `PerpsClient.execute` delegates those arms here.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const client = createPerpsClient({
|
|
52
|
+
* integrator: 'my-app',
|
|
53
|
+
* providers: [lighterProvider()],
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export const lighterProvider = (options = {}) => {
|
|
59
|
+
// Late-bind slot: the factory runs before the client exists, so `bind`
|
|
60
|
+
// assigns this once during createPerpsClient and the read methods read it.
|
|
61
|
+
let boundClient;
|
|
62
|
+
const requireClient = () => {
|
|
63
|
+
if (boundClient === undefined) {
|
|
64
|
+
throw new PerpsError(PerpsErrorCode.SDKError, 'lighterProvider used before binding. Register it via ' +
|
|
65
|
+
'createPerpsClient({ providers: [lighterProvider()] }).');
|
|
66
|
+
}
|
|
67
|
+
return boundClient;
|
|
68
|
+
};
|
|
69
|
+
const restUrl = options.restUrl ?? DEFAULT_LIGHTER_REST_URL;
|
|
70
|
+
const authTokenSource = typeof options.authToken === 'function'
|
|
71
|
+
? options.authToken
|
|
72
|
+
: options.authToken !== undefined
|
|
73
|
+
? () => options.authToken
|
|
74
|
+
: undefined;
|
|
75
|
+
const signer = options.signer;
|
|
76
|
+
const keyStore = options.keyStore;
|
|
77
|
+
const readOnlyTokenManager = new LighterReadOnlyTokenManager({
|
|
78
|
+
lighterApiUrl: restUrl,
|
|
79
|
+
...options.readOnlyTokenOptions,
|
|
80
|
+
});
|
|
81
|
+
const tokenLifetimeSeconds = options.tokenLifetimeSeconds ?? 60 * 60;
|
|
82
|
+
const tokenRenewBufferSeconds = options.tokenRenewBufferSeconds ?? 60;
|
|
83
|
+
const standardTokenByAddress = new Map();
|
|
84
|
+
// Single-flight + failure-cache for lazy read-only token creation. Without
|
|
85
|
+
// these, concurrent reads on first load all race `tokens/create`, and any
|
|
86
|
+
// sustained failure (CORS preflight, body validation, etc.) is retried on
|
|
87
|
+
// every subsequent read — flooding the endpoint. Keyed by lowercase address.
|
|
88
|
+
const readOnlyCreationInFlight = new Map();
|
|
89
|
+
const readOnlyCreationFailed = new Set();
|
|
90
|
+
const apiClient = (opts) => {
|
|
91
|
+
const client = requireClient();
|
|
92
|
+
return new LighterApiClient(restUrl, {
|
|
93
|
+
signal: opts?.signal,
|
|
94
|
+
policy: resolveRetryPolicy(LIGHTER_RETRY_DEFAULTS, client.config.retry, LIGHTER_PROVIDER_KEY),
|
|
95
|
+
fetchImpl: client.config.fetch,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const getStandardAuthToken = async (address, apiKeyPrivateKey, indices) => {
|
|
99
|
+
if (signer === undefined) {
|
|
100
|
+
throw new PerpsError(PerpsErrorCode.SDKError, 'lighterProvider: getStandardAuthToken called without a configured signer.');
|
|
101
|
+
}
|
|
102
|
+
const cacheKey = address.toLowerCase();
|
|
103
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
104
|
+
const cached = standardTokenByAddress.get(cacheKey);
|
|
105
|
+
if (cached !== undefined &&
|
|
106
|
+
cached.expiresAt - nowSec > tokenRenewBufferSeconds) {
|
|
107
|
+
return cached.token;
|
|
108
|
+
}
|
|
109
|
+
const token = await createAuthToken({
|
|
110
|
+
signer,
|
|
111
|
+
apiKey: {
|
|
112
|
+
apiKeyPrivateKey,
|
|
113
|
+
apiKeyIndex: indices.apiKeyIndex,
|
|
114
|
+
accountIndex: indices.accountIndex,
|
|
115
|
+
},
|
|
116
|
+
lifetimeSeconds: tokenLifetimeSeconds,
|
|
117
|
+
});
|
|
118
|
+
const expiresAt = nowSec + tokenLifetimeSeconds;
|
|
119
|
+
standardTokenByAddress.set(cacheKey, { token, expiresAt });
|
|
120
|
+
return token;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the bearer token for auth-gated reads. Priority:
|
|
124
|
+
* 1. Per-call override (`options.lighterAuthToken`).
|
|
125
|
+
* 2. Constructor-supplied token source.
|
|
126
|
+
* 3. A stored read-only token — preferred for reads: it is read-only, so
|
|
127
|
+
* forwarding it (incl. to the backend) cannot authorise writes.
|
|
128
|
+
* 4. A read-only token created on first use (via signer + registered API
|
|
129
|
+
* key) and persisted for reuse.
|
|
130
|
+
* 5. A standard auth token (read+write, 8h max) as a last resort — used
|
|
131
|
+
* both as the fallback when creation is unavailable/failed and as the
|
|
132
|
+
* credential that authorises read-only token creation.
|
|
133
|
+
* Returns `undefined` when no source can produce a token — reads degrade
|
|
134
|
+
* gracefully.
|
|
135
|
+
*/
|
|
136
|
+
const resolveAuthToken = async (opts, address) => {
|
|
137
|
+
if (opts?.lighterAuthToken !== undefined) {
|
|
138
|
+
return opts.lighterAuthToken;
|
|
139
|
+
}
|
|
140
|
+
if (authTokenSource !== undefined) {
|
|
141
|
+
return authTokenSource();
|
|
142
|
+
}
|
|
143
|
+
if (address === undefined || keyStore === undefined) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const apiKey = await keyStore.get(address);
|
|
147
|
+
if (apiKey === null || signer === undefined) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const standardToken = () => getStandardAuthToken(address, apiKey.apiKeyPrivateKey, {
|
|
151
|
+
apiKeyIndex: apiKey.apiKeyIndex,
|
|
152
|
+
accountIndex: apiKey.accountIndex,
|
|
153
|
+
});
|
|
154
|
+
const stored = await readOnlyTokenManager.get(address, apiKey.accountIndex);
|
|
155
|
+
if (stored !== undefined) {
|
|
156
|
+
return stored.token;
|
|
157
|
+
}
|
|
158
|
+
const flightKey = address.toLowerCase();
|
|
159
|
+
if (readOnlyCreationFailed.has(flightKey)) {
|
|
160
|
+
return standardToken();
|
|
161
|
+
}
|
|
162
|
+
const inFlight = readOnlyCreationInFlight.get(flightKey);
|
|
163
|
+
if (inFlight !== undefined) {
|
|
164
|
+
return inFlight;
|
|
165
|
+
}
|
|
166
|
+
// No read-only token yet — create and persist one. The standard token
|
|
167
|
+
// (API-key-signed) authorises Lighter's `tokens/create`; the returned
|
|
168
|
+
// read-only bearer is what we forward on reads. On failure we mark this
|
|
169
|
+
// address as "skip ro creation for the session" so subsequent reads use
|
|
170
|
+
// the standard token directly instead of hammering `tokens/create`.
|
|
171
|
+
const attempt = (async () => {
|
|
172
|
+
try {
|
|
173
|
+
const { token } = await readOnlyTokenManager.approve(await standardToken(), {
|
|
174
|
+
address,
|
|
175
|
+
accountIndex: apiKey.accountIndex,
|
|
176
|
+
expirySeconds: Math.floor(Date.now() / 1000) +
|
|
177
|
+
DEFAULT_READ_ONLY_TOKEN_LIFETIME_SECONDS,
|
|
178
|
+
scope: 'all',
|
|
179
|
+
});
|
|
180
|
+
return token.token;
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
readOnlyCreationFailed.add(flightKey);
|
|
184
|
+
console.warn('[lighter] read-only token creation failed; ' +
|
|
185
|
+
'falling back to standard auth tokens for this session.', err);
|
|
186
|
+
return standardToken();
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
readOnlyCreationInFlight.delete(flightKey);
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
192
|
+
readOnlyCreationInFlight.set(flightKey, attempt);
|
|
193
|
+
return attempt;
|
|
194
|
+
};
|
|
195
|
+
const evictReadOnlyToken = async (address) => {
|
|
196
|
+
readOnlyCreationFailed.delete(address.toLowerCase());
|
|
197
|
+
const apiKey = keyStore ? await keyStore.get(address) : null;
|
|
198
|
+
if (apiKey !== null) {
|
|
199
|
+
await readOnlyTokenManager.remove(address, apiKey.accountIndex);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Run an auth-gated read; if Lighter rejects the token (revoked server-side —
|
|
204
|
+
* invisible to `checkSetup`, since the read-only token is a client-only
|
|
205
|
+
* concern), evict the stored read-only token and retry once with a freshly
|
|
206
|
+
* resolved one. Only self-heals tokens the SDK itself resolved — a
|
|
207
|
+
* caller-supplied `lighterAuthToken`/`authToken` source is the caller's to fix.
|
|
208
|
+
*/
|
|
209
|
+
const retryOnRevoked = async (opts, address, token, run) => {
|
|
210
|
+
try {
|
|
211
|
+
return await run(token);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
const sdkOwnsToken = opts?.lighterAuthToken === undefined && authTokenSource === undefined;
|
|
215
|
+
if (!(err instanceof LighterAuthRejectedError) || !sdkOwnsToken) {
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
await evictReadOnlyToken(address);
|
|
219
|
+
const fresh = await resolveAuthToken(opts, address);
|
|
220
|
+
if (fresh === undefined || fresh === token) {
|
|
221
|
+
throw err;
|
|
222
|
+
}
|
|
223
|
+
return await run(fresh);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const fetchRegisteredApiKey = async (client, accountIndex, apiKeyIndex) => {
|
|
227
|
+
const response = await client.get('/api/v1/apikeys', { account_index: accountIndex });
|
|
228
|
+
return response.api_keys?.find((k) => k.api_key_index === apiKeyIndex);
|
|
229
|
+
};
|
|
230
|
+
const fetchAccountLimits = (client, accountIndex, authToken) => client.getAuthed('/api/v1/accountLimits', authToken, {
|
|
231
|
+
account_index: accountIndex,
|
|
232
|
+
});
|
|
233
|
+
const fetchActiveOrdersForMarket = (client, authToken, accountIndex, marketId) => client.getAuthed('/api/v1/accountActiveOrders', authToken, { account_index: accountIndex, market_id: marketId });
|
|
234
|
+
const deriveOrderBearingMarketIds = (account) => account.positions
|
|
235
|
+
.filter((p) => orderCountFor(p) > 0)
|
|
236
|
+
.map((p) => p.market_id);
|
|
237
|
+
const fetchAllHistory = async (client, token, accountIndex, l1Address, requested, inputCursor) => {
|
|
238
|
+
const wantsType = (t) => requested === undefined || requested.includes(t);
|
|
239
|
+
const shouldFetch = (t, key) => {
|
|
240
|
+
if (!wantsType(t)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
if (inputCursor === undefined) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const v = inputCursor[key];
|
|
247
|
+
return typeof v === 'string' && v.length > 0;
|
|
248
|
+
};
|
|
249
|
+
const cursorParam = (key) => {
|
|
250
|
+
const v = inputCursor?.[key];
|
|
251
|
+
return typeof v === 'string' && v.length > 0 ? { cursor: v } : {};
|
|
252
|
+
};
|
|
253
|
+
const empty = (payload) => payload;
|
|
254
|
+
const [deposits, withdraws, fundings, liquidations, transfers] = await Promise.all([
|
|
255
|
+
shouldFetch(ActivityType.DEPOSIT, 'deposits')
|
|
256
|
+
? client.getAuthed('/api/v1/deposit/history', token, {
|
|
257
|
+
account_index: accountIndex,
|
|
258
|
+
l1_address: l1Address,
|
|
259
|
+
...cursorParam('deposits'),
|
|
260
|
+
})
|
|
261
|
+
: Promise.resolve(empty({ code: 0, deposits: [] })),
|
|
262
|
+
shouldFetch(ActivityType.WITHDRAWAL, 'withdraws')
|
|
263
|
+
? client.getAuthed('/api/v1/withdraw/history', token, { account_index: accountIndex, ...cursorParam('withdraws') })
|
|
264
|
+
: Promise.resolve(empty({ code: 0, withdraws: [] })),
|
|
265
|
+
shouldFetch(ActivityType.FUNDING, 'fundings')
|
|
266
|
+
? client.getAuthed('/api/v1/positionFunding', token, {
|
|
267
|
+
account_index: accountIndex,
|
|
268
|
+
market_id: LIGHTER_ALL_MARKETS_WILDCARD,
|
|
269
|
+
limit: LIGHTER_HISTORY_PAGE_SIZE,
|
|
270
|
+
...cursorParam('fundings'),
|
|
271
|
+
})
|
|
272
|
+
: Promise.resolve(empty({ code: 0, position_fundings: [] })),
|
|
273
|
+
shouldFetch(ActivityType.LIQUIDATION, 'liquidations')
|
|
274
|
+
? client.getAuthed('/api/v1/liquidations', token, {
|
|
275
|
+
account_index: accountIndex,
|
|
276
|
+
market_id: LIGHTER_ALL_MARKETS_WILDCARD,
|
|
277
|
+
limit: LIGHTER_HISTORY_PAGE_SIZE,
|
|
278
|
+
...cursorParam('liquidations'),
|
|
279
|
+
})
|
|
280
|
+
: Promise.resolve(empty({ code: 0, liquidations: [] })),
|
|
281
|
+
shouldFetch(ActivityType.TRANSFER, 'transfers')
|
|
282
|
+
? client.getAuthed('/api/v1/transfer/history', token, { account_index: accountIndex, ...cursorParam('transfers') })
|
|
283
|
+
: Promise.resolve(empty({ code: 0, transfers: [] })),
|
|
284
|
+
]);
|
|
285
|
+
return { deposits, withdraws, fundings, liquidations, transfers };
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
type: LIGHTER_PROVIDER_KEY,
|
|
289
|
+
bind(client) {
|
|
290
|
+
boundClient = client;
|
|
291
|
+
},
|
|
292
|
+
resolveAuthToken(address) {
|
|
293
|
+
return resolveAuthToken(undefined, address);
|
|
294
|
+
},
|
|
295
|
+
async getAccount(params, opts) {
|
|
296
|
+
const client = apiClient(opts);
|
|
297
|
+
const [account, token] = await Promise.all([
|
|
298
|
+
fetchDetailedAccount(client, params.address),
|
|
299
|
+
resolveAuthToken(opts, params.address),
|
|
300
|
+
]);
|
|
301
|
+
const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
302
|
+
const [, registeredKey, limitsResult, localKey, storedReadOnlyToken] = await Promise.all([
|
|
303
|
+
registry.sync(),
|
|
304
|
+
fetchRegisteredApiKey(client, account.index, DEFAULT_API_KEY_INDEX),
|
|
305
|
+
// No token is a legitimate unauthenticated read → undefined → zero fee
|
|
306
|
+
// tier. A fetch error is NOT: it must propagate, never be coerced to a
|
|
307
|
+
// fabricated 0%/0% fee tier.
|
|
308
|
+
token === undefined
|
|
309
|
+
? Promise.resolve(undefined)
|
|
310
|
+
: retryOnRevoked(opts, params.address, token, (t) => fetchAccountLimits(client, account.index, t)),
|
|
311
|
+
keyStore ? keyStore.get(params.address) : Promise.resolve(null),
|
|
312
|
+
readOnlyTokenManager.get(params.address, account.index),
|
|
313
|
+
]);
|
|
314
|
+
// REGISTER_API_KEY is satisfied only when the locally-held keypair
|
|
315
|
+
// matches the key registered on-chain at this slot — existence alone is
|
|
316
|
+
// insufficient (a stale/rotated local key can't sign valid auth tokens).
|
|
317
|
+
const apiKeyRegistered = registeredKey !== undefined &&
|
|
318
|
+
localKey !== null &&
|
|
319
|
+
normalizeLighterPublicKey(localKey.apiKeyPublicKey) ===
|
|
320
|
+
normalizeLighterPublicKey(registeredKey.public_key);
|
|
321
|
+
const positions = mapOpenPositions(account.positions, (id) => registry.require(String(id)));
|
|
322
|
+
const totalMarginUsed = positions.reduce((sum, p) => sum + Number.parseFloat(p.marginUsed), 0);
|
|
323
|
+
const totalUnrealizedPnl = positions.reduce((sum, p) => sum + Number.parseFloat(p.unrealizedPnl), 0);
|
|
324
|
+
// USDC collateral is the category quote asset → collateralBalances.
|
|
325
|
+
// `available_balance` is the free collateral (Lighter's `collateral` is
|
|
326
|
+
// gross, i.e. includes margin locked in positions); the locked portion is
|
|
327
|
+
// carried by the positions' `marginUsed`.
|
|
328
|
+
const collateralBalances = [
|
|
329
|
+
{
|
|
330
|
+
categoryId: LIGHTER_PROVIDER_KEY,
|
|
331
|
+
asset: lighterAsset('USDC', 'USDC'),
|
|
332
|
+
units: account.available_balance,
|
|
333
|
+
valueUsd: account.available_balance,
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
// Spot token holdings — non-collateral. USDC value is 1:1; other tokens
|
|
337
|
+
// have no price source at this boundary, so their USD value is unknown.
|
|
338
|
+
const balances = account.assets.map((a) => ({
|
|
339
|
+
categoryId: LIGHTER_PROVIDER_KEY,
|
|
340
|
+
asset: lighterAsset(String(a.asset_id), a.symbol),
|
|
341
|
+
units: a.balance,
|
|
342
|
+
valueUsd: a.symbol === 'USDC' ? a.balance : '0',
|
|
343
|
+
}));
|
|
344
|
+
const config = {
|
|
345
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
346
|
+
accountIndex: account.index,
|
|
347
|
+
apiKeyIndex: DEFAULT_API_KEY_INDEX,
|
|
348
|
+
apiKeyRegistered,
|
|
349
|
+
accountType: account.account_type,
|
|
350
|
+
// Satisfied when a non-expired read-only token is stored locally
|
|
351
|
+
// (`readOnlyTokenManager.get` filters out expired ones).
|
|
352
|
+
readOnlyTokenApproved: storedReadOnlyToken !== undefined,
|
|
353
|
+
readOnlyTokenExpiry: storedReadOnlyToken?.expiry,
|
|
354
|
+
readOnlyTokenScope: storedReadOnlyToken?.scope,
|
|
355
|
+
};
|
|
356
|
+
return {
|
|
357
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
358
|
+
address: params.address,
|
|
359
|
+
balances,
|
|
360
|
+
collateralBalances,
|
|
361
|
+
marginUsed: totalMarginUsed.toString(),
|
|
362
|
+
unrealizedPnl: totalUnrealizedPnl.toString(),
|
|
363
|
+
feeTier: limitsResult === undefined
|
|
364
|
+
? ZERO_FEE_TIER
|
|
365
|
+
: projectFeeTier(limitsResult),
|
|
366
|
+
config,
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
async getPositions(params, opts) {
|
|
370
|
+
const client = apiClient(opts);
|
|
371
|
+
const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
372
|
+
const [account] = await Promise.all([
|
|
373
|
+
fetchDetailedAccount(client, params.address),
|
|
374
|
+
registry.sync(),
|
|
375
|
+
]);
|
|
376
|
+
let positions = mapOpenPositions(account.positions, (id) => registry.require(String(id)));
|
|
377
|
+
if (params.marketId !== undefined) {
|
|
378
|
+
positions = positions.filter((p) => p.market.id === params.marketId);
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
382
|
+
positions,
|
|
383
|
+
pagination: { limit: params.limit ?? positions.length, hasMore: false },
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
async getOrders(params, opts) {
|
|
387
|
+
const token = await resolveAuthToken(opts, params.address);
|
|
388
|
+
if (token === undefined) {
|
|
389
|
+
return {
|
|
390
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
391
|
+
openOrders: [],
|
|
392
|
+
triggerOrders: [],
|
|
393
|
+
pagination: { limit: params.limit ?? 0, hasMore: false },
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
const client = apiClient(opts);
|
|
397
|
+
const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
398
|
+
const [account] = await Promise.all([
|
|
399
|
+
fetchDetailedAccount(client, params.address),
|
|
400
|
+
registry.sync(),
|
|
401
|
+
]);
|
|
402
|
+
const marketIds = params.marketId === undefined
|
|
403
|
+
? deriveOrderBearingMarketIds(account)
|
|
404
|
+
: [Number(params.marketId)];
|
|
405
|
+
const responses = await retryOnRevoked(opts, params.address, token, (t) => Promise.all(marketIds.map((id) => fetchActiveOrdersForMarket(client, t, account.index, id))));
|
|
406
|
+
const { openOrders, triggerOrders } = classifyAndMapOrders(responses.flatMap((r) => r.orders), (marketIndex) => registry.require(String(marketIndex)));
|
|
407
|
+
const total = openOrders.length + triggerOrders.length;
|
|
408
|
+
const limit = params.limit ?? total;
|
|
409
|
+
return {
|
|
410
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
411
|
+
openOrders,
|
|
412
|
+
triggerOrders,
|
|
413
|
+
pagination: { limit, hasMore: total > limit },
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
async getOrder(params, opts) {
|
|
417
|
+
const token = await resolveAuthToken(opts, params.address);
|
|
418
|
+
if (token === undefined) {
|
|
419
|
+
throw new PerpsError(PerpsErrorCode.SDKError, 'Lighter order lookup requires an auth token. Pass `authToken` to ' +
|
|
420
|
+
'lighterProvider, register an API key + signer for on-demand creation, or ' +
|
|
421
|
+
'forward `options.lighterAuthToken` on the call.');
|
|
422
|
+
}
|
|
423
|
+
const client = apiClient(opts);
|
|
424
|
+
const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
425
|
+
const [account] = await Promise.all([
|
|
426
|
+
fetchDetailedAccount(client, params.address),
|
|
427
|
+
registry.sync(),
|
|
428
|
+
]);
|
|
429
|
+
// Native `order_index` route only. The cross-provider `Order.orderId`
|
|
430
|
+
// for Lighter is `String(order_index)` — see `mapOrder`. A tx-hash route
|
|
431
|
+
// would require mapping the caller's executeAction tx hash → wasm nonce
|
|
432
|
+
// → matching order, which the LI.FI backend did via its `UserAction`
|
|
433
|
+
// table; the SDK has no equivalent persistence, so we refuse rather
|
|
434
|
+
// than mis-resolve.
|
|
435
|
+
if (TX_HASH_PATTERN.test(params.id)) {
|
|
436
|
+
throw new PerpsError(PerpsErrorCode.OrderNotFound, `Lighter order id "${params.id}" looks like a tx hash. The SDK ` +
|
|
437
|
+
`resolves orders by Lighter \`order_index\` only — surface the orderId ` +
|
|
438
|
+
`from the orderUpdates / fills WS stream and pass it here.`);
|
|
439
|
+
}
|
|
440
|
+
const predicate = (o) => String(o.order_index) === params.id;
|
|
441
|
+
const marketIds = deriveOrderBearingMarketIds(account);
|
|
442
|
+
const activeResponses = await retryOnRevoked(opts, params.address, token, (t) => Promise.all(marketIds.map((id) => fetchActiveOrdersForMarket(client, t, account.index, id))));
|
|
443
|
+
for (const response of activeResponses) {
|
|
444
|
+
const hit = response.orders.find(predicate);
|
|
445
|
+
if (hit !== undefined) {
|
|
446
|
+
return mapOrderDetail(hit, registry.require(String(hit.market_index)));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const inactive = await retryOnRevoked(opts, params.address, token, (t) => client.getAuthed('/api/v1/accountInactiveOrders', t, {
|
|
450
|
+
account_index: account.index,
|
|
451
|
+
market_id: LIGHTER_ALL_MARKETS_WILDCARD,
|
|
452
|
+
limit: INACTIVE_ORDERS_LOOKUP_LIMIT,
|
|
453
|
+
}));
|
|
454
|
+
const hit = inactive.orders.find(predicate);
|
|
455
|
+
if (hit !== undefined) {
|
|
456
|
+
return mapOrderDetail(hit, registry.require(String(hit.market_index)));
|
|
457
|
+
}
|
|
458
|
+
throw new PerpsError(PerpsErrorCode.OrderNotFound, `Lighter order ${params.id} not found for ${params.address}`);
|
|
459
|
+
},
|
|
460
|
+
async getFills(params, opts) {
|
|
461
|
+
const token = await resolveAuthToken(opts, params.address);
|
|
462
|
+
if (token === undefined) {
|
|
463
|
+
return {
|
|
464
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
465
|
+
items: [],
|
|
466
|
+
pagination: { limit: params.limit ?? 0, hasMore: false },
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
const client = apiClient(opts);
|
|
470
|
+
const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
471
|
+
const [account] = await Promise.all([
|
|
472
|
+
fetchDetailedAccount(client, params.address),
|
|
473
|
+
registry.sync(),
|
|
474
|
+
]);
|
|
475
|
+
const queryParams = {
|
|
476
|
+
account_index: account.index,
|
|
477
|
+
sort_by: 'timestamp',
|
|
478
|
+
sort_dir: 'desc',
|
|
479
|
+
limit: params.limit ?? DEFAULT_TRADES_LIMIT,
|
|
480
|
+
};
|
|
481
|
+
if (params.cursor !== undefined) {
|
|
482
|
+
queryParams.cursor = params.cursor;
|
|
483
|
+
}
|
|
484
|
+
const response = await retryOnRevoked(opts, params.address, token, (tok) => client.getAuthed('/api/v1/trades', tok, queryParams));
|
|
485
|
+
const items = response.trades.map((t) => mapFill(t, account.index, registry.require(String(t.market_id))));
|
|
486
|
+
return {
|
|
487
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
488
|
+
items,
|
|
489
|
+
pagination: {
|
|
490
|
+
limit: params.limit ?? items.length,
|
|
491
|
+
hasMore: (response.next_cursor ?? '') !== '',
|
|
492
|
+
cursor: response.next_cursor || undefined,
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
},
|
|
496
|
+
async getActivity(params, opts) {
|
|
497
|
+
const token = await resolveAuthToken(opts, params.address);
|
|
498
|
+
if (token === undefined) {
|
|
499
|
+
return {
|
|
500
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
501
|
+
items: [],
|
|
502
|
+
pagination: { limit: params.limit ?? 0, hasMore: false },
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
const inputCursor = decodeActivityCursor(params.cursor);
|
|
506
|
+
const client = apiClient(opts);
|
|
507
|
+
const account = await fetchDetailedAccount(client, params.address);
|
|
508
|
+
const marketRegistry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
509
|
+
const assetRegistry = getAssetRegistry(requireClient(), LIGHTER_PROVIDER_KEY);
|
|
510
|
+
const [history] = await Promise.all([
|
|
511
|
+
retryOnRevoked(opts, params.address, token, (t) => fetchAllHistory(client, t, account.index, params.address, params.type, inputCursor)),
|
|
512
|
+
marketRegistry.sync(),
|
|
513
|
+
assetRegistry.sync(),
|
|
514
|
+
]);
|
|
515
|
+
const items = [
|
|
516
|
+
...history.deposits.deposits.map((d) => ({
|
|
517
|
+
id: d.id,
|
|
518
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
519
|
+
timestamp: toIsoFromMs(d.timestamp),
|
|
520
|
+
type: ActivityType.DEPOSIT,
|
|
521
|
+
amount: d.amount,
|
|
522
|
+
explorerLink: d.l1_tx_hash
|
|
523
|
+
? `https://scan.li.fi/tx/${d.l1_tx_hash}`
|
|
524
|
+
: undefined,
|
|
525
|
+
})),
|
|
526
|
+
...history.withdraws.withdraws.map((w) => ({
|
|
527
|
+
id: w.id,
|
|
528
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
529
|
+
timestamp: toIsoFromMs(w.timestamp),
|
|
530
|
+
type: ActivityType.WITHDRAWAL,
|
|
531
|
+
amount: w.amount,
|
|
532
|
+
fee: '0',
|
|
533
|
+
explorerLink: w.l1_tx_hash
|
|
534
|
+
? `https://scan.li.fi/tx/${w.l1_tx_hash}`
|
|
535
|
+
: undefined,
|
|
536
|
+
})),
|
|
537
|
+
...history.fundings.position_fundings.map((f) => ({
|
|
538
|
+
id: `funding-${f.funding_id}`,
|
|
539
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
540
|
+
timestamp: toIsoFromSeconds(f.timestamp),
|
|
541
|
+
type: ActivityType.FUNDING,
|
|
542
|
+
market: marketRegistry.require(String(f.market_id)),
|
|
543
|
+
amount: f.change,
|
|
544
|
+
positionSize: f.position_size,
|
|
545
|
+
fundingRate: f.rate,
|
|
546
|
+
})),
|
|
547
|
+
...history.liquidations.liquidations.map((l) => ({
|
|
548
|
+
id: `liquidation-${l.id}`,
|
|
549
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
550
|
+
timestamp: toIsoFromMs(l.executed_at),
|
|
551
|
+
type: ActivityType.LIQUIDATION,
|
|
552
|
+
liquidatedNotionalPosition: '0',
|
|
553
|
+
accountValue: '0',
|
|
554
|
+
leverageType: l.type,
|
|
555
|
+
liquidatedPositions: [
|
|
556
|
+
{
|
|
557
|
+
market: marketRegistry.require(String(l.market_id)),
|
|
558
|
+
size: '0',
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
})),
|
|
562
|
+
...history.transfers.transfers.map((t) => {
|
|
563
|
+
const direction = t.from_account_index === account.index ? 'OUT' : 'IN';
|
|
564
|
+
const counterpartyAccountIndex = direction === 'OUT' ? t.to_account_index : t.from_account_index;
|
|
565
|
+
return {
|
|
566
|
+
id: t.id,
|
|
567
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
568
|
+
timestamp: toIsoFromMs(t.timestamp),
|
|
569
|
+
type: ActivityType.TRANSFER,
|
|
570
|
+
direction,
|
|
571
|
+
counterpartyAccountIndex,
|
|
572
|
+
asset: assetRegistry.get(String(t.asset_id))?.displaySymbol ??
|
|
573
|
+
String(t.asset_id),
|
|
574
|
+
amount: t.amount,
|
|
575
|
+
explorerLink: explorerTxUrl(ExplorerChainId.LIGHTER, t.tx_hash),
|
|
576
|
+
meta: {
|
|
577
|
+
transferType: t.type,
|
|
578
|
+
txHash: t.tx_hash,
|
|
579
|
+
fromRoute: t.from_route,
|
|
580
|
+
toRoute: t.to_route,
|
|
581
|
+
fee: t.fee,
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
}),
|
|
585
|
+
];
|
|
586
|
+
const merged = [...(inputCursor?.overflow ?? []), ...items];
|
|
587
|
+
const filtered = merged.filter((it) => {
|
|
588
|
+
const ts = new Date(it.timestamp).getTime();
|
|
589
|
+
if (params.startTime !== undefined && ts < params.startTime) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
if (params.endTime !== undefined && ts > params.endTime) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
return true;
|
|
596
|
+
});
|
|
597
|
+
filtered.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
598
|
+
const limit = params.limit ?? filtered.length;
|
|
599
|
+
const emitted = filtered.slice(0, limit);
|
|
600
|
+
const overflow = filtered.slice(limit);
|
|
601
|
+
const nextCursorEnvelope = {
|
|
602
|
+
deposits: history.deposits.cursor,
|
|
603
|
+
withdraws: history.withdraws.cursor,
|
|
604
|
+
fundings: history.fundings.next_cursor,
|
|
605
|
+
liquidations: history.liquidations.next_cursor,
|
|
606
|
+
transfers: history.transfers.cursor,
|
|
607
|
+
overflow,
|
|
608
|
+
};
|
|
609
|
+
const responseCursor = encodeActivityCursor(nextCursorEnvelope);
|
|
610
|
+
const hasMore = responseCursor !== undefined;
|
|
611
|
+
return {
|
|
612
|
+
provider: LIGHTER_PROVIDER_KEY,
|
|
613
|
+
items: emitted,
|
|
614
|
+
pagination: {
|
|
615
|
+
limit,
|
|
616
|
+
hasMore,
|
|
617
|
+
...(responseCursor === undefined ? {} : { cursor: responseCursor }),
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
},
|
|
621
|
+
getQuote(params, opts) {
|
|
622
|
+
return resolveQuote(requireClient(), LIGHTER_PROVIDER_KEY, params, LIGHTER_BASE_FEE_TIER, opts);
|
|
623
|
+
},
|
|
624
|
+
getPortfolioSummary(account, positions) {
|
|
625
|
+
return summarizeLighterAccount(account, positions);
|
|
626
|
+
},
|
|
627
|
+
formatOrderPrice,
|
|
628
|
+
formatOrderSize,
|
|
629
|
+
estimateLiquidationPrice,
|
|
630
|
+
projectConfig(config, setup, options) {
|
|
631
|
+
if (config.provider !== LIGHTER_PROVIDER_KEY) {
|
|
632
|
+
throw new PerpsError(PerpsErrorCode.SDKError, `lighterProvider.projectConfig received config for provider ` +
|
|
633
|
+
`'${config.provider}'.`);
|
|
634
|
+
}
|
|
635
|
+
return projectLighterConfigSettings(config, setup, options);
|
|
636
|
+
},
|
|
637
|
+
/**
|
|
638
|
+
* Hand the backend the local pubkey for REGISTER_API_KEY so its
|
|
639
|
+
* idempotency check can compare against the on-chain slot. No keystore
|
|
640
|
+
* configured, or no key stored for this address → omit the field;
|
|
641
|
+
* backend stages a fresh registration.
|
|
642
|
+
*/
|
|
643
|
+
async resolveSetupParams(action, address) {
|
|
644
|
+
if (action !== ActionType.REGISTER_API_KEY) {
|
|
645
|
+
return {};
|
|
646
|
+
}
|
|
647
|
+
if (keyStore === undefined) {
|
|
648
|
+
return {};
|
|
649
|
+
}
|
|
650
|
+
const local = await keyStore.get(address);
|
|
651
|
+
if (local === null) {
|
|
652
|
+
return {};
|
|
653
|
+
}
|
|
654
|
+
return { knownPublicKey: local.apiKeyPublicKey };
|
|
655
|
+
},
|
|
656
|
+
async signActions(method, steps, address, ctx) {
|
|
657
|
+
if (signer === undefined || keyStore === undefined) {
|
|
658
|
+
throw new PerpsError(PerpsErrorCode.SDKError, 'lighterProvider.signActions requires `signer` and `keyStore` to be ' +
|
|
659
|
+
'configured at construction.');
|
|
660
|
+
}
|
|
661
|
+
const signerRef = signer;
|
|
662
|
+
const keyStoreRef = keyStore;
|
|
663
|
+
return lighterSignActions({
|
|
664
|
+
signer: signerRef,
|
|
665
|
+
keyStore: keyStoreRef,
|
|
666
|
+
resolveAccountIndex: async (addr) => {
|
|
667
|
+
const apiKey = await keyStoreRef.get(addr);
|
|
668
|
+
if (apiKey !== null) {
|
|
669
|
+
return apiKey.accountIndex;
|
|
670
|
+
}
|
|
671
|
+
const account = await fetchDetailedAccount(apiClient(), addr);
|
|
672
|
+
return account.index;
|
|
673
|
+
},
|
|
674
|
+
}, method, steps, address, ctx);
|
|
675
|
+
},
|
|
676
|
+
};
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Alias matching `@lifi/sdk`'s capitalised factory naming (`EVM()`, `EthereumProvider()`).
|
|
680
|
+
*
|
|
681
|
+
* @public
|
|
682
|
+
*/
|
|
683
|
+
export const Lighter = lighterProvider;
|
|
684
|
+
//# sourceMappingURL=LighterProvider.js.map
|