@portal-hq/web 3.13.2 → 3.14.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.
Files changed (96) hide show
  1. package/lib/commonjs/index.js +127 -9
  2. package/lib/commonjs/index.test.js +13 -0
  3. package/lib/commonjs/integrations/delegations/index.js +109 -2
  4. package/lib/commonjs/integrations/delegations/index.test.js +171 -0
  5. package/lib/commonjs/integrations/ramps/noah/index.test.js +18 -5
  6. package/lib/commonjs/integrations/trading/index.js +16 -5
  7. package/lib/commonjs/integrations/trading/lifi/index.js +297 -25
  8. package/lib/commonjs/integrations/trading/lifi/lifi.tradeAsset.test.js +360 -0
  9. package/lib/commonjs/integrations/trading/lifi/lifiStatusPoll.js +118 -0
  10. package/lib/commonjs/integrations/trading/lifi/lifiStatusPoll.test.js +66 -0
  11. package/lib/commonjs/integrations/trading/zero-x/index.js +129 -26
  12. package/lib/commonjs/integrations/trading/zero-x/index.test.js +163 -1
  13. package/lib/commonjs/integrations/yield/index.js +18 -4
  14. package/lib/commonjs/integrations/yield/yieldxyz.getValidators.test.js +71 -0
  15. package/lib/commonjs/integrations/yield/yieldxyz.highLevel.test.js +330 -0
  16. package/lib/commonjs/integrations/yield/yieldxyz.js +517 -1
  17. package/lib/commonjs/internal/pollLoop.js +64 -0
  18. package/lib/commonjs/internal/pollLoop.test.js +100 -0
  19. package/lib/commonjs/internal/stripStalePlanningNonce.js +65 -0
  20. package/lib/commonjs/internal/stripStalePlanningNonce.test.js +35 -0
  21. package/lib/commonjs/internal/waitForEvmOrUserOpConfirmation.js +155 -0
  22. package/lib/commonjs/internal/waitForEvmOrUserOpConfirmation.test.js +33 -0
  23. package/lib/commonjs/internal/waitForEvmTxConfirmation.js +104 -0
  24. package/lib/commonjs/internal/waitForSolanaTxConfirmation.js +106 -0
  25. package/lib/commonjs/internal/yieldEvmNetwork.js +60 -0
  26. package/lib/commonjs/mpc/index.js +116 -1
  27. package/lib/commonjs/provider/index.js +17 -0
  28. package/lib/commonjs/shared/trace/index.js +0 -1
  29. package/lib/esm/index.js +127 -9
  30. package/lib/esm/index.test.js +13 -0
  31. package/lib/esm/integrations/delegations/index.js +109 -2
  32. package/lib/esm/integrations/delegations/index.test.js +171 -0
  33. package/lib/esm/integrations/ramps/noah/index.test.js +18 -5
  34. package/lib/esm/integrations/trading/index.js +16 -5
  35. package/lib/esm/integrations/trading/lifi/index.js +292 -25
  36. package/lib/esm/integrations/trading/lifi/lifi.tradeAsset.test.js +332 -0
  37. package/lib/esm/integrations/trading/lifi/lifiStatusPoll.js +113 -0
  38. package/lib/esm/integrations/trading/lifi/lifiStatusPoll.test.js +64 -0
  39. package/lib/esm/integrations/trading/zero-x/index.js +129 -26
  40. package/lib/esm/integrations/trading/zero-x/index.test.js +141 -2
  41. package/lib/esm/integrations/yield/index.js +18 -4
  42. package/lib/esm/integrations/yield/yieldxyz.getValidators.test.js +66 -0
  43. package/lib/esm/integrations/yield/yieldxyz.highLevel.test.js +325 -0
  44. package/lib/esm/integrations/yield/yieldxyz.js +517 -1
  45. package/lib/esm/internal/pollLoop.js +59 -0
  46. package/lib/esm/internal/pollLoop.test.js +98 -0
  47. package/lib/esm/internal/stripStalePlanningNonce.js +61 -0
  48. package/lib/esm/internal/stripStalePlanningNonce.test.js +33 -0
  49. package/lib/esm/internal/waitForEvmOrUserOpConfirmation.js +151 -0
  50. package/lib/esm/internal/waitForEvmOrUserOpConfirmation.test.js +31 -0
  51. package/lib/esm/internal/waitForEvmTxConfirmation.js +100 -0
  52. package/lib/esm/internal/waitForSolanaTxConfirmation.js +102 -0
  53. package/lib/esm/internal/yieldEvmNetwork.js +55 -0
  54. package/lib/esm/mpc/index.js +116 -1
  55. package/lib/esm/provider/index.js +17 -0
  56. package/lib/esm/shared/trace/index.js +0 -1
  57. package/noah-types.d.ts +16 -2
  58. package/package.json +3 -2
  59. package/src/index.test.ts +15 -0
  60. package/src/index.ts +203 -14
  61. package/src/integrations/delegations/index.test.ts +251 -0
  62. package/src/integrations/delegations/index.ts +202 -4
  63. package/src/integrations/ramps/noah/index.test.ts +18 -5
  64. package/src/integrations/trading/index.ts +10 -7
  65. package/src/integrations/trading/lifi/index.ts +388 -28
  66. package/src/integrations/trading/lifi/lifi.tradeAsset.test.ts +436 -0
  67. package/src/integrations/trading/lifi/lifiStatusPoll.test.ts +74 -0
  68. package/src/integrations/trading/lifi/lifiStatusPoll.ts +158 -0
  69. package/src/integrations/trading/zero-x/index.test.ts +297 -1
  70. package/src/integrations/trading/zero-x/index.ts +181 -27
  71. package/src/integrations/yield/index.ts +24 -4
  72. package/src/integrations/yield/yieldxyz.getValidators.test.ts +70 -0
  73. package/src/integrations/yield/yieldxyz.highLevel.test.ts +403 -0
  74. package/src/integrations/yield/yieldxyz.ts +740 -8
  75. package/src/internal/pollLoop.test.ts +109 -0
  76. package/src/internal/pollLoop.ts +87 -0
  77. package/src/internal/stripStalePlanningNonce.test.ts +38 -0
  78. package/src/internal/stripStalePlanningNonce.ts +66 -0
  79. package/src/internal/waitForEvmOrUserOpConfirmation.test.ts +31 -0
  80. package/src/internal/waitForEvmOrUserOpConfirmation.ts +194 -0
  81. package/src/internal/waitForEvmTxConfirmation.ts +155 -0
  82. package/src/internal/waitForSolanaTxConfirmation.ts +135 -0
  83. package/src/internal/yieldEvmNetwork.ts +57 -0
  84. package/src/mpc/index.ts +142 -1
  85. package/src/provider/index.ts +25 -0
  86. package/src/shared/trace/index.ts +0 -1
  87. package/src/shared/types/README.md +6 -0
  88. package/src/shared/types/api.ts +12 -1
  89. package/src/shared/types/common.ts +332 -20
  90. package/src/shared/types/delegations.ts +10 -0
  91. package/src/shared/types/index.ts +1 -0
  92. package/src/shared/types/lifi.ts +82 -0
  93. package/src/shared/types/noah.ts +124 -33
  94. package/src/shared/types/yieldxyz.ts +186 -0
  95. package/src/shared/types/zero-x.ts +66 -0
  96. package/types.d.ts +6 -0
@@ -75,6 +75,7 @@ export interface LegacyTransaction {
75
75
 
76
76
  export type EthereumTransaction = EIP1559Transaction | LegacyTransaction
77
77
 
78
+ // Legacy transaction type (deprecated - use TransactionHistoryItem instead)
78
79
  export interface Transaction {
79
80
  asset: string
80
81
  blockNum: string
@@ -98,6 +99,240 @@ export interface Transaction {
98
99
  value: number
99
100
  }
100
101
 
102
+ /**
103
+ * Solana error type (can be string, structured object, or null)
104
+ * Observed from backend: errors can be strings or objects with code/message
105
+ */
106
+ export type SolanaError =
107
+ | string
108
+ | {
109
+ code?: string | number
110
+ message?: string
111
+ data?: unknown
112
+ }
113
+ | null
114
+
115
+ /**
116
+ * Solana transaction instruction data structure
117
+ * Backend returns variable shapes depending on program
118
+ * Extended version with optional parsed fields
119
+ */
120
+ export interface SolanaTransactionInstruction {
121
+ accounts: number[]
122
+ data: string
123
+ programIdIndex: number
124
+ stackHeight?: number
125
+ parsed?: unknown
126
+ program?: string
127
+ programId?: string
128
+ }
129
+
130
+ /**
131
+ * Token balance type for Solana pre/post balances
132
+ * Structure varies by token standard (SPL, Token-2022, etc.)
133
+ */
134
+ export interface SolanaTokenBalance {
135
+ accountIndex: number
136
+ mint: string
137
+ owner?: string
138
+ programId?: string
139
+ uiTokenAmount?: {
140
+ amount: string
141
+ decimals: number
142
+ uiAmount: number | null
143
+ uiAmountString: string
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Inner instruction structure for Solana transactions
149
+ * Nested program invocations
150
+ */
151
+ export interface SolanaInnerInstruction {
152
+ index: number
153
+ instructions: Array<{
154
+ accounts: number[]
155
+ data: string
156
+ programIdIndex: number
157
+ parsed?: unknown
158
+ }>
159
+ }
160
+
161
+ /**
162
+ * Solana transaction reward entry
163
+ */
164
+ export interface SolanaReward {
165
+ pubkey: string
166
+ lamports: number
167
+ postBalance: number
168
+ rewardType: string | null
169
+ commission: number | null
170
+ }
171
+
172
+ /**
173
+ * Base transaction type shared by both regular and UserOp transactions
174
+ */
175
+ interface BaseTransactionHistoryItem {
176
+ hash: string
177
+ from: string
178
+ to: string | null
179
+ value: string
180
+ blockNumber: string | null
181
+ blockTimestamp: number | null
182
+ status: string | null
183
+ chainId: string
184
+ }
185
+
186
+ /**
187
+ * Regular blockchain transaction (EVM, Bitcoin, Tron, Stellar, etc.)
188
+ * Includes optional token transfer metadata
189
+ */
190
+ export interface RegularTransaction extends BaseTransactionHistoryItem {
191
+ type: 'transaction'
192
+ asset?: string
193
+ tokenAddress?: string
194
+ tokenDecimals?: number
195
+ // UserOp fields must NOT be present
196
+ userOpHash?: never
197
+ entryPoint?: never
198
+ actualGasCost?: never
199
+ actualGasUsed?: never
200
+ }
201
+
202
+ /**
203
+ * ERC-4337 User Operation transaction (EVM only)
204
+ * Always has to=null and value='0', includes UserOp-specific fields
205
+ */
206
+ export interface UserOperationTransaction extends BaseTransactionHistoryItem {
207
+ type: 'userOperation'
208
+ to: null
209
+ value: '0'
210
+ userOpHash: string
211
+ entryPoint: string
212
+ actualGasCost?: string
213
+ actualGasUsed?: string
214
+ // Token fields must NOT be present
215
+ asset?: never
216
+ tokenAddress?: never
217
+ tokenDecimals?: never
218
+ }
219
+
220
+ /**
221
+ * Discriminated union for unified transaction format
222
+ * Used by EVM, Bitcoin, Tron, Stellar chains
223
+ */
224
+ export type TransactionHistoryItem = RegularTransaction | UserOperationTransaction
225
+
226
+ /**
227
+ * Solana transaction details (legacy format)
228
+ * Returned only for chains with namespace 'solana:*'
229
+ * Uses signature-based identification instead of hash
230
+ */
231
+ export interface SolanaTransactionDetails {
232
+ blockTime: number
233
+ error: SolanaError
234
+ signature: string
235
+ status: string
236
+ tokenMint: string | null
237
+ transactionDetails: {
238
+ transaction: {
239
+ message: {
240
+ accountKeys: string[]
241
+ header: {
242
+ numRequiredSignatures: number
243
+ numReadonlySignedAccounts: number
244
+ numReadonlyUnsignedAccounts: number
245
+ }
246
+ instructions: SolanaTransactionInstruction[]
247
+ recentBlockhash: string
248
+ }
249
+ signatures: string[]
250
+ } | null
251
+ signatureDetails: {
252
+ blockTime: number
253
+ confirmationStatus: string
254
+ error: SolanaError
255
+ memo: string | null
256
+ signature: string
257
+ slot: number
258
+ } | null
259
+ metadata: {
260
+ blockTime: number | null
261
+ slot: number | null
262
+ error: SolanaError
263
+ fee: number | null
264
+ innerInstructions?: SolanaInnerInstruction[] | null
265
+ loadedAddresses?: {
266
+ readonly: string[]
267
+ writable: string[]
268
+ } | null
269
+ logMessages: string[] | null
270
+ postBalances: number[] | null
271
+ postTokenBalances?: SolanaTokenBalance[] | null
272
+ preBalances: number[] | null
273
+ preTokenBalances?: SolanaTokenBalance[] | null
274
+ rewards?: SolanaReward[] | null
275
+ status: {
276
+ Ok?: null | unknown
277
+ Err?: unknown
278
+ } | null
279
+ version: 'legacy' | number | null
280
+ } | null
281
+ } | null
282
+ }
283
+
284
+ /**
285
+ * Request parameters for fetching transaction history
286
+ */
287
+ export interface GetTransactionHistoryParams {
288
+ chainId: string
289
+ limit?: number
290
+ offset?: number
291
+ order?: 'asc' | 'desc'
292
+ address?: string
293
+ userOperations?: 'include' | 'only' | 'exclude'
294
+ }
295
+
296
+ /**
297
+ * Response metadata (same structure for both Solana and unified formats)
298
+ */
299
+ export interface GetTransactionHistoryMetadata {
300
+ address: string
301
+ chainId: string
302
+ clientId: string
303
+ limit: number
304
+ offset: number
305
+ count: number
306
+ }
307
+
308
+ /**
309
+ * Response for Solana chains (solana:*)
310
+ */
311
+ export interface SolanaTransactionsResponse {
312
+ data: {
313
+ transactions: SolanaTransactionDetails[]
314
+ }
315
+ metadata: GetTransactionHistoryMetadata
316
+ }
317
+
318
+ /**
319
+ * Response for unified format (EVM, Bitcoin, Tron, Stellar, etc.)
320
+ */
321
+ export interface UnifiedTransactionsResponse {
322
+ data: {
323
+ transactions: TransactionHistoryItem[]
324
+ }
325
+ metadata: GetTransactionHistoryMetadata
326
+ }
327
+
328
+ /**
329
+ * Polymorphic response type based on chain namespace
330
+ * Runtime discrimination: check metadata.chainId namespace
331
+ */
332
+ export type GetTransactionHistoryResponse =
333
+ | SolanaTransactionsResponse
334
+ | UnifiedTransactionsResponse
335
+
101
336
  // Built transaction types
102
337
  export type BuiltTransaction = BuiltEip155Transaction | BuiltSolanaTransaction
103
338
 
@@ -117,6 +352,15 @@ export interface BuiltEip155Transaction {
117
352
  }
118
353
  }
119
354
 
355
+ /**
356
+ * Solana token extension data
357
+ * Structure varies by extension type (e.g., transfer fee, metadata pointer)
358
+ */
359
+ export interface SolanaTokenExtension {
360
+ extension?: string
361
+ state?: unknown
362
+ }
363
+
120
364
  export interface BuiltSolanaTransaction {
121
365
  transaction:
122
366
  | string
@@ -133,7 +377,7 @@ export interface BuiltSolanaTransaction {
133
377
  tokenMintAddress: string
134
378
  tokenDecimals: number
135
379
  tokenProgramId: string
136
- tokenExtensions: any[]
380
+ tokenExtensions: SolanaTokenExtension[]
137
381
  rawAmount: string
138
382
  lastValidBlockHeight: string
139
383
  serializedTransactionBase64Encoded: string
@@ -226,26 +470,79 @@ interface AssetMovement {
226
470
  rawValue: string
227
471
  }
228
472
 
473
+ /**
474
+ * Asset metadata from Blockaid simulation
475
+ */
476
+ export interface AssetMetadata {
477
+ type: string
478
+ decimals: number
479
+ chainName?: string
480
+ chainId?: number
481
+ logoUrl?: string
482
+ name?: string
483
+ symbol?: string
484
+ }
485
+
486
+ /**
487
+ * Asset differential (inflows/outflows)
488
+ */
229
489
  interface AssetDiff {
230
- asset: Record<
231
- string,
232
- {
233
- type: string
234
- decimals: number
235
- chainName?: string
236
- chainId?: number
237
- logoUrl?: string
238
- name?: string
239
- symbol?: string
240
- }
241
- >
490
+ asset: Record<string, AssetMetadata>
242
491
  in: Record<string, AssetMovement>[]
243
492
  out: Record<string, AssetMovement>[]
244
493
  }
245
494
 
495
+ /**
496
+ * Extended asset properties from Blockaid
497
+ * Structure varies by chain and asset type
498
+ */
499
+ export interface ExtendedAssetProperties {
500
+ address?: string
501
+ contractAddress?: string
502
+ tokenId?: string
503
+ standard?: string
504
+ [key: string]: unknown
505
+ }
506
+
507
+ /**
508
+ * Account-level summary from simulation
509
+ */
246
510
  interface AccountSummary {
247
511
  assetsDiffs: Record<string, AssetDiff>[]
248
- [k: string]: any
512
+ exposures?: Record<string, ExtendedAssetProperties>[]
513
+ totalUsdDiff?: Record<string, ExtendedAssetProperties>
514
+ totalUsdExposure?: Record<string, ExtendedAssetProperties>
515
+ }
516
+
517
+ /**
518
+ * Address details from simulation (contract info, labels, etc.)
519
+ */
520
+ export interface AddressDetails {
521
+ contractName?: string
522
+ type?: string
523
+ isVerified?: boolean
524
+ [key: string]: unknown
525
+ }
526
+
527
+ /**
528
+ * Solana-specific delegation info
529
+ */
530
+ export interface SolanaDelegation {
531
+ account: string
532
+ authority?: string
533
+ amount?: string
534
+ state?: string
535
+ [key: string]: unknown
536
+ }
537
+
538
+ /**
539
+ * Solana-specific ownership diff
540
+ */
541
+ export interface SolanaOwnershipDiff {
542
+ account: string
543
+ before?: string
544
+ after?: string
545
+ [key: string]: unknown
249
546
  }
250
547
 
251
548
  export type Simulation = SuccessfulSimulation | UnsuccessfulSimulation
@@ -253,15 +550,15 @@ export type Simulation = SuccessfulSimulation | UnsuccessfulSimulation
253
550
  interface SuccessfulSimulation {
254
551
  accountAddress: string
255
552
  accountSummary: AccountSummary
256
- addressDetails: Record<string, any>
553
+ addressDetails: Record<string, AddressDetails>
257
554
  assetsDiffs: Record<string, AssetDiff[]>
258
555
  status: string
259
- exposures?: Record<string, any>
260
- totalUsdDiff?: Record<string, any>
261
- totalUsdExposure?: Record<string, any>
556
+ exposures?: Record<string, ExtendedAssetProperties[]>
557
+ totalUsdDiff?: Record<string, ExtendedAssetProperties>
558
+ totalUsdExposure?: Record<string, ExtendedAssetProperties>
262
559
  solana?: {
263
- delegations: Record<string, Record<string, any>[]>
264
- assetsOwnershipDiff: Record<string, Record<string, any>[]>
560
+ delegations: Record<string, SolanaDelegation[]>
561
+ assetsOwnershipDiff: Record<string, SolanaOwnershipDiff[]>
265
562
  }
266
563
  }
267
564
 
@@ -384,6 +681,21 @@ export interface RpcConfig {
384
681
  [key: string]: string
385
682
  }
386
683
 
684
+ export interface RpcProxyRequest {
685
+ requestId: string
686
+ method: string
687
+ params: unknown[]
688
+ chainId: string
689
+ }
690
+
691
+ export interface RpcProxyResponse {
692
+ requestId: string
693
+ jsonrpc: '2.0'
694
+ id: string
695
+ result?: unknown
696
+ error?: { code: number; message: string }
697
+ }
698
+
387
699
  export interface CustomBackupConfig {
388
700
  encryptionKey: string
389
701
  }
@@ -112,3 +112,13 @@ export interface TransferFromResponse {
112
112
  encodedTransactions?: ConstructedSolanaTransaction[]
113
113
  metadata: TransferAsDelegateMetadata
114
114
  }
115
+
116
+ /**
117
+ * Progress event for delegation submit flows (`approveAndSubmit`, `revokeAndSubmit`, `transferAndSubmit`).
118
+ */
119
+ export interface DelegationSubmitProgress {
120
+ step: 'signing' | 'submitted'
121
+ index: number
122
+ total: number
123
+ hash?: string
124
+ }
@@ -37,4 +37,5 @@ export type {
37
37
  TransferFromRequest,
38
38
  TransferAsDelegateMetadata,
39
39
  TransferFromResponse,
40
+ DelegationSubmitProgress,
40
41
  } from './delegations'
@@ -510,6 +510,8 @@ export interface LifiTransactionRequest {
510
510
  from?: string
511
511
  gasLimit?: string
512
512
  gasPrice?: string
513
+ maxFeePerGas?: string
514
+ maxPriorityFeePerGas?: string
513
515
  to?: string
514
516
  value?: string
515
517
  }
@@ -1234,3 +1236,83 @@ export interface LifiStepTransactionResponse {
1234
1236
  export interface LifiStepTransactionData {
1235
1237
  rawResponse: LifiStep
1236
1238
  }
1239
+
1240
+ // --- High-level LiFi trade and route/step polling types ---
1241
+
1242
+ export type LifiTradeAssetProgressStatus =
1243
+ | 'fetching_routes'
1244
+ | 'route_selected'
1245
+ | 'preparing_step'
1246
+ | 'signing'
1247
+ | 'submitted'
1248
+ | 'confirming'
1249
+ | 'lifi_pending'
1250
+ | 'step_done'
1251
+ | 'complete'
1252
+ | 'failed'
1253
+
1254
+ export interface LifiTradeAssetProgressData {
1255
+ errorMessage?: string
1256
+ routeIndex?: number
1257
+ route?: LifiRoute
1258
+ stepIndex?: number
1259
+ totalSteps?: number
1260
+ step?: LifiStep
1261
+ txHash?: string
1262
+ lifiStatus?: LifiStatusRawResponse
1263
+ transaction?: unknown
1264
+ }
1265
+
1266
+ export interface LifiTradeAssetParams {
1267
+ fromChain: string
1268
+ toChain: string
1269
+ fromToken: string
1270
+ toToken: string
1271
+ amount: string
1272
+ fromAddress: string
1273
+ toAddress?: string
1274
+ routeOptions?: LifiRoutesRequestOptions
1275
+ routeIndex?: number
1276
+ onProgress?: (
1277
+ status: LifiTradeAssetProgressStatus,
1278
+ data?: LifiTradeAssetProgressData,
1279
+ ) => void
1280
+ statusPoll?: LifiPollStatusOptions
1281
+ }
1282
+
1283
+ export interface LifiTradeAssetOptions {
1284
+ signAndSendTransaction?: (
1285
+ transaction: unknown,
1286
+ network: string,
1287
+ ) => Promise<string>
1288
+ waitForConfirmation?: (
1289
+ txHash: string,
1290
+ network: string,
1291
+ ) => Promise<void | boolean>
1292
+ evmRequestFn?: (
1293
+ method: string,
1294
+ params: unknown[],
1295
+ network: string,
1296
+ ) => Promise<unknown>
1297
+ evmPollerOptions?: {
1298
+ pollIntervalMs?: number
1299
+ timeoutMs?: number
1300
+ }
1301
+ }
1302
+
1303
+ export interface LifiTradeAssetResult {
1304
+ hashes: string[]
1305
+ steps: LifiStep[]
1306
+ route: LifiRoute
1307
+ }
1308
+
1309
+ export interface LifiPollStatusOptions {
1310
+ everyMs?: number
1311
+ initialDelayMs?: number
1312
+ timeoutMs?: number
1313
+ maxConsecutiveErrors?: number
1314
+ backoff?: {
1315
+ factor: number
1316
+ maxIntervalMs: number
1317
+ }
1318
+ }