@exodus/asset-types 0.1.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.1](https://github.com/ExodusMovement/assets/compare/@exodus/asset-types@0.2.0...@exodus/asset-types@0.2.1) (2025-02-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix: add missing types (#5001)
13
+
14
+
15
+
16
+ ## [0.2.0](https://github.com/ExodusMovement/assets/compare/@exodus/asset-types@0.0.0...@exodus/asset-types@0.2.0) (2025-01-22)
17
+
18
+
19
+ ### Features
20
+
21
+
22
+ * feat: improve assets type definitions (#4897)
23
+
24
+
25
+
6
26
  ## 0.1.0 (2024-12-23)
7
27
 
8
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/asset-types",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Typings for Assets",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "repository": {
@@ -28,5 +28,8 @@
28
28
  "bugs": {
29
29
  "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Aasset-types"
30
30
  },
31
- "gitHead": "e1ca2b674078f1c19b08a4b99a50e55a851ec453"
31
+ "devDependencies": {
32
+ "@types/bn.js": "^5"
33
+ },
34
+ "gitHead": "4bf0b4efd938c60fc9ef8af756030442bda18f70"
32
35
  }
@@ -15,13 +15,15 @@ export type Info = {
15
15
  telegram?: string
16
16
  }
17
17
 
18
+ export type BlockExplorer = {
19
+ txUrl: (txId: string) => Promise<string>
20
+ addressUrl: (address: string) => Promise<string>
21
+ }
22
+
18
23
  export type AssetMeta = {
19
24
  assetType: string
20
25
  baseAssetName: string
21
- blockExplorer: {
22
- txUrl: (txId: string) => Promise<string>
23
- addressUrl: (address: string) => Promise<string>
24
- }
26
+ blockExplorer: BlockExplorer
25
27
  chainBadgeColors: string[]
26
28
  currency: UnitType
27
29
  displayNetworkName: string
@@ -37,4 +39,6 @@ export type AssetMeta = {
37
39
  ticker: string
38
40
  decimals?: number
39
41
  mintAddress?: string
42
+ units: Record<string, number>
43
+ [prop: string]: any // allow additional chain specific properties
40
44
  }
package/src/asset.d.ts CHANGED
@@ -3,14 +3,28 @@
3
3
  import type NumberUnit from '@exodus/currency'
4
4
  import type KeyIdentifier from '@exodus/key-identifier'
5
5
  import type { AccountState, Tx, TxSet, WalletAccount } from '@exodus/models'
6
+ import type BN from 'bn.js'
6
7
 
7
8
  import type { AssetMeta } from './asset-meta.js'
8
9
  import type { CreateFeeMonitorApi } from './fee-monitor.js'
10
+ import type { Extendable, FreeForm, RequireOnly, WithRequired } from './helpers.js'
9
11
  import type { HistoryMonitor } from './history-monitor.js'
10
12
  import type { Logger } from './logger.js'
11
13
  import type { MoveFunds } from './move-funds.js'
12
14
  import type { Signer } from './signer.js'
13
15
 
16
+ type WalletAccountLike = WalletAccount | string
17
+
18
+ type WalletCompatibilityMode =
19
+ | 'phantom'
20
+ | 'metamask'
21
+ | 'trust'
22
+ | 'mathwallet'
23
+ | 'ordinals86'
24
+ | 'ordinals84'
25
+ // Hack to allow any string without breaking intelisense
26
+ | (string & NonNullable<unknown>)
27
+
14
28
  export type CreateHistoryMonitorApi = (args: {
15
29
  asset: BaseAsset
16
30
  runner: () => void
@@ -18,6 +32,8 @@ export type CreateHistoryMonitorApi = (args: {
18
32
  logger: Logger
19
33
  }) => HistoryMonitor
20
34
 
35
+ export type IdentifiableTx = RequireOnly<Tx, 'txId'>
36
+
21
37
  export type ApiFeatures = {
22
38
  accountState?: boolean
23
39
  customTokens?: boolean
@@ -51,37 +67,132 @@ export type BalanceFieldName =
51
67
 
52
68
  export type Balances = Record<BalanceFieldName, NumberUnit>
53
69
 
70
+ export type UnsignedTxPayload<NumberValue = BN | string> = Extendable<{
71
+ txData: Extendable<{
72
+ to: string
73
+ amount: NumberValue
74
+ fee: NumberValue
75
+ gasPrice: NumberValue
76
+ gasLimit: NumberValue
77
+ nonce: NumberValue
78
+ }>
79
+ txMeta: Extendable<{
80
+ assetName: string
81
+ }>
82
+ }>
83
+
84
+ export type SignTransactionParams = Extendable<{
85
+ assetName: string
86
+ unsignedTx: UnsignedTxPayload
87
+ walletAccount: WalletAccountLike
88
+ }>
89
+
90
+ export type HardwareDeviceSignTransactionParams = Extendable<{
91
+ assetName: string
92
+ signableTransaction: Buffer
93
+ derivationPaths: string[]
94
+ }>
95
+
96
+ export type HardwareDevice = Extendable<{
97
+ signTransaction: (tx: HardwareDeviceSignTransactionParams) => Promise<void>
98
+ }>
99
+
100
+ export type WalletAccountParams = Extendable<{
101
+ asset: AbstractAsset
102
+ accountState: AccountState
103
+ txLog: TxSet
104
+ }>
105
+
106
+ export type GetActivityTxsParams = Extendable<{ txs: Tx[] }>
107
+
108
+ export type GetDefaultAddressPathParams = Extendable<{
109
+ walletAccount: WalletAccountLike
110
+ compatibilityMode?: WalletCompatibilityMode
111
+ }>
112
+
113
+ export type GetKeyIdentifierParams = Extendable<{
114
+ purpose: number
115
+ accountIndex: number
116
+ chainIndex?: number
117
+ addressIndex?: number
118
+ compatibilityMode?: WalletCompatibilityMode
119
+ }>
120
+
121
+ export type GetSupportedPurposesParams = Extendable<{
122
+ compatibilityMode?: WalletCompatibilityMode
123
+ isMultisig?: boolean
124
+ }>
125
+
126
+ export type SignHardwareTxParams = Extendable<{
127
+ unsignedTx: UnsignedTxPayload
128
+ accountIndex: number
129
+ hardwareDevice: HardwareDevice
130
+ }>
131
+
132
+ /** Purpose -> BIP32 instance */
133
+ export type HDKeysMap = Record<number, unknown>
134
+
135
+ export type SignTxParams = Extendable<{
136
+ unsignedTx?: UnsignedTxPayload
137
+ accountIndex?: number
138
+ txHex?: string
139
+ partialSign?: boolean
140
+ hdkeys?: HDKeysMap
141
+ privateKey: string
142
+ signer?: Signer
143
+ }>
144
+
54
145
  export type CommonAssetApi = {
55
146
  features: ApiFeatures
56
- getActivityTxs?: (params: { txs: Tx[] }) => Tx[]
57
- getBalances: (args: {
58
- asset: AbstractAsset
59
- accountState: AccountState
60
- txLog: TxSet
61
- }) => Balances
147
+ getActivityTxs?: (params: GetActivityTxsParams) => Tx[]
148
+ getBalances: (params: WalletAccountParams) => Balances
62
149
  getTxLogFilter?: (tx: Tx) => boolean
63
150
  hasFeature: (feature: keyof ApiFeatures) => boolean // @deprecated use api.features instead
64
151
  }
65
152
 
66
- /// Not all assets txsend can handle all params. This needs to be improved!
67
- type TxSendParams = any
68
- // for future reference
69
- // type TxSendParams = {
70
- // address: string
71
- // amount?: NumberUnit
72
- // asset: TokenAsset | BaseAsset
73
- // bumpTxId?: string
74
- // customFee?: NumberUnit
75
- // feeAmount?: NumberUnit
76
- // feeOpts?: { [key: string]: any } // eth, move out!
77
- // isExchange?: boolean
78
- // isSendAll?: boolean
79
- // nft?: { nftId: string; [key: string]: any }
80
- // options: { [key: string]: any }
81
- // shouldLog?: boolean
82
- // walletAccount: string
83
- // [key: string]: any
84
- // }
153
+ export type EncondePublicOptions = Extendable<{ purpose?: number }>
154
+
155
+ export type KeyEncoder = {
156
+ encodePrivate: (key: Buffer) => string
157
+ encodePublic: (key: Buffer, options?: EncondePublicOptions) => string
158
+ }
159
+
160
+ export type AssetAddress = {
161
+ validate: (address: string) => boolean
162
+ resolvePurpose?: (address: string) => Promise<number>
163
+ }
164
+
165
+ export type Nft = Extendable<{ nftId: string }>
166
+
167
+ export type BaseTxSendParams<Options = FreeForm> = {
168
+ address: string
169
+ asset: TokenAsset | BaseAsset
170
+ walletAccount: WalletAccountLike
171
+ amount?: NumberUnit
172
+ options?: Options
173
+ }
174
+
175
+ export type FundibleTokenTxSendParams = BaseTxSendParams & WithRequired<BaseTxSendParams, 'amount'>
176
+ export type NonFungibleTokenTxSendParams = BaseTxSendParams & { nft: Nft }
177
+
178
+ export type StrictTxSendParams = FundibleTokenTxSendParams | NonFungibleTokenTxSendParams
179
+
180
+ export type ExtendedTxSendParams = Extendable<
181
+ StrictTxSendParams,
182
+ {
183
+ bumpTxId?: string
184
+ customFee?: NumberUnit
185
+ feeAmount?: NumberUnit
186
+ feeOpts?: { [key: string]: any }
187
+ isExchange?: boolean
188
+ isSendAll?: boolean
189
+ shouldLog?: boolean
190
+ }
191
+ >
192
+
193
+ export type TxSendParams = StrictTxSendParams | ExtendedTxSendParams
194
+
195
+ export type SignMessageParams = { message: string; signer: Signer }
85
196
 
86
197
  export type AssetApi = CommonAssetApi & {
87
198
  addressHasHistory?: (address: string) => Promise<boolean>
@@ -92,37 +203,26 @@ export type AssetApi = CommonAssetApi & {
92
203
  defaultAddressPath: string
93
204
  getBalanceForAddress: (address: string) => NumberUnit
94
205
  getConfirmationsNumber: () => number
95
- getDefaultAddressPath?: (args: {
96
- walletAccount: WalletAccount
97
- compatibilityMode?: string
98
- }) => string
206
+ getDefaultAddressPath?: (params: GetDefaultAddressPathParams) => string
99
207
  getFeeData: () => any
100
- getKeyIdentifier(params: {
101
- purpose: number
102
- accountIndex: number
103
- chainIndex?: number
104
- addressIndex?: number
105
- compatibilityMode?: string
106
- }): KeyIdentifier
107
- getSupportedPurposes?: (params?: { compatibilityMode?: string; isMultisig?: boolean }) => number[]
208
+ getKeyIdentifier(params: GetKeyIdentifierParams): KeyIdentifier
209
+ getSupportedPurposes?: (params?: GetSupportedPurposesParams) => number[]
108
210
  moveFunds?: MoveFunds
109
- signHardware?: (params: {
110
- unsignedTx: any
111
- hardwareDevice: any
112
- accountIndex: number
113
- }) => Promise<any>
114
- signMessage?(params: { message: any; signer: Signer }): Promise<any>
115
- signTx(params: { unsignedTx: any; signer: Signer }): Promise<any>
116
- sendTx(params: TxSendParams): Promise<{ txId: string }>
211
+ signHardware?: (params: SignHardwareTxParams) => Promise<any>
212
+ signMessage?(params: SignMessageParams): Promise<any>
213
+ signTx(params: SignTxParams): Promise<any>
214
+ sendTx(params: TxSendParams): Promise<IdentifiableTx>
117
215
  validateAssetId?: (assetId: string) => boolean
118
216
  }
119
217
 
218
+ export type GetBalancesParams = {
219
+ asset: AbstractAsset
220
+ accountState: AccountState
221
+ txLog: TxSet
222
+ }
223
+
120
224
  export type TokenAssetApi = {
121
- getBalances: (params: {
122
- asset: AbstractAsset
123
- accountState: AccountState
124
- txLog: TxSet
125
- }) => Balances
225
+ getBalances: (params: GetBalancesParams) => Balances
126
226
  }
127
227
 
128
228
  export type AbstractAsset = AssetMeta & {
@@ -132,14 +232,9 @@ export type AbstractAsset = AssetMeta & {
132
232
  isCustomToken?: boolean
133
233
  isCombined?: boolean
134
234
  lifecycleStatus?: string
135
- keys: {
136
- encodePrivate: (key: Buffer) => string
137
- encodePublic: (key: Buffer, options?: { purpose?: number }) => string
138
- }
139
- address: {
140
- validate: (address: string) => boolean
141
- resolvePurpose?: (address: string) => Promise<number>
142
- }
235
+ keys: KeyEncoder
236
+ address: AssetAddress
237
+ toString(): string
143
238
  }
144
239
 
145
240
  export type CombinedAsset<A extends BaseAsset | TokenAsset = BaseAsset | TokenAsset> = AssetMeta & {
@@ -157,11 +252,14 @@ export type TokenAsset = AbstractAsset & {
157
252
  api: CommonAssetApi
158
253
  }
159
254
 
160
- export type AssetPlugin<A = BaseAsset, C = unknown> = {
161
- createAsset: (params: {
162
- assetClientInterface: any
163
- // extract interface
164
- config: C
165
- overrideCallback?: ({ asset: A }) => A
166
- }) => A
255
+ export type AddressOverrideCallbackParams<A extends BaseAsset = BaseAsset> = { asset: A }
256
+
257
+ export type CreateAddressParams<A extends BaseAsset = BaseAsset, C = unknown> = {
258
+ assetClientInterface: any
259
+ config: C
260
+ overrideCallback?: (params: AddressOverrideCallbackParams) => A
261
+ }
262
+
263
+ export type AssetPlugin<A extends BaseAsset = BaseAsset, C = unknown> = {
264
+ createAsset: (params: CreateAddressParams<A, C>) => A
167
265
  }
@@ -6,9 +6,10 @@ export type FeeMonitor = {
6
6
  tick: () => Promise<void>
7
7
  }
8
8
 
9
+ export type FeeDataValue = number | string | NumberUnit
10
+
11
+ export type FeeData = Record<string, FeeDataValue>
12
+
9
13
  export type CreateFeeMonitorApi = (params: {
10
- updateFee: (
11
- assetName: string,
12
- feeDataToUpdate: Record<string, number | string | NumberUnit>
13
- ) => Promise<void>
14
+ updateFee: (assetName: string, feeDataToUpdate: FeeData) => Promise<void>
14
15
  }) => FeeMonitor
@@ -0,0 +1,17 @@
1
+ export type FreeForm = Record<string | number | symbol, unknown>
2
+
3
+ /**
4
+ * Helper that allows extending a type as a union type
5
+ * while also providing syntactic sugar for extending a type with FreeForm
6
+ */
7
+ export type Extendable<T, Ext = FreeForm> = Ext & T
8
+
9
+ /**
10
+ * Mark the given keys of target type as required
11
+ */
12
+ export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
13
+
14
+ /*
15
+ * Make a set of keys of a given target type required, while making all other optional
16
+ */
17
+ export type RequireOnly<T, Keys extends keyof T> = Partial<T> & Pick<WithRequired<T, Keys>, Keys>
package/src/index.d.ts CHANGED
@@ -1,8 +1,32 @@
1
1
  export type {
2
- //
3
2
  AbstractAsset,
4
3
  AssetPlugin,
5
4
  BaseAsset,
6
5
  CombinedAsset,
7
6
  TokenAsset,
7
+ WalletAccountParams,
8
+ UnsignedTxPayload,
9
+ SignMessageParams,
10
+ TxSendParams,
11
+ TokenAssetApi,
12
+ StrictTxSendParams,
13
+ SignTxParams,
14
+ SignTransactionParams,
15
+ SignHardwareTxParams,
16
+ NonFungibleTokenTxSendParams,
17
+ HardwareDeviceSignTransactionParams,
18
+ HardwareDevice,
19
+ GetSupportedPurposesParams,
20
+ GetKeyIdentifierParams,
21
+ GetDefaultAddressPathParams,
22
+ GetBalancesParams,
23
+ GetActivityTxsParams,
24
+ FundibleTokenTxSendParams,
25
+ ExtendedTxSendParams,
26
+ EncondePublicOptions,
27
+ CreateHistoryMonitorApi,
28
+ CreateAddressParams,
29
+ AssetApi,
30
+ AssetAddress,
31
+ ApiFeatures,
8
32
  } from './asset.js'