@deserialize/multi-vm-wallet 1.6.1 → 1.6.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.
@@ -17,6 +17,8 @@ export interface PocketBalance {
17
17
  balances: {
18
18
  token: string;
19
19
  balance: Balance;
20
+ priceUsd: number;
21
+ priceChange24h: number;
20
22
  balanceInUsd: number;
21
23
  }[];
22
24
  }
@@ -21,7 +21,12 @@ class MultiChainSavingsManager {
21
21
  for (const item of prices) {
22
22
  if (!item?.tokenAddress || typeof item.price !== 'number')
23
23
  continue;
24
- priceMap.set(this.getTokenKey(item.tokenAddress, chainType), item.price);
24
+ priceMap.set(this.getTokenKey(item.tokenAddress, chainType), {
25
+ priceUsd: item.price,
26
+ priceChange24h: typeof item.priceChange24h === 'number'
27
+ ? item.priceChange24h
28
+ : 0
29
+ });
25
30
  }
26
31
  return priceMap;
27
32
  }
@@ -138,8 +143,10 @@ class MultiChainSavingsManager {
138
143
  balances: balanceRows.map(row => ({
139
144
  token: row.token,
140
145
  balance: row.balance,
146
+ priceUsd: priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceUsd ?? 0,
147
+ priceChange24h: priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceChange24h ?? 0,
141
148
  balanceInUsd: row.balance.formatted *
142
- (priceMap.get(this.getTokenKey(row.token, 'EVM')) ?? 0)
149
+ (priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceUsd ?? 0)
143
150
  }))
144
151
  };
145
152
  }
@@ -160,8 +167,10 @@ class MultiChainSavingsManager {
160
167
  balances: balanceRows.map(row => ({
161
168
  token: row.token,
162
169
  balance: row.balance,
170
+ priceUsd: priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceUsd ?? 0,
171
+ priceChange24h: priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceChange24h ?? 0,
163
172
  balanceInUsd: row.balance.formatted *
164
- (priceMap.get(this.getTokenKey(row.token, 'SVM')) ?? 0)
173
+ (priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceUsd ?? 0)
165
174
  }))
166
175
  };
167
176
  }
package/dist/utils.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface AddressPortfolioItem {
7
7
  balanceRaw: string;
8
8
  balanceFormatted: number;
9
9
  priceUsd: number | null;
10
+ priceChange24h: number | null;
10
11
  valueUsd: number | null;
11
12
  }
12
13
  export interface AddressPortfolioResult {
package/dist/utils.js CHANGED
@@ -47,18 +47,24 @@ const normalizePriceMap = (prices) => {
47
47
  for (const item of prices) {
48
48
  if (!item?.tokenAddress || typeof item.price !== "number")
49
49
  continue;
50
- priceMap.set(item.tokenAddress.toLowerCase(), item.price);
50
+ priceMap.set(item.tokenAddress.toLowerCase(), {
51
+ priceUsd: item.price,
52
+ priceChange24h: typeof item.priceChange24h === "number" ? item.priceChange24h : null,
53
+ });
51
54
  }
52
55
  return priceMap;
53
56
  };
54
57
  const enrichWithUsdValues = (items, priceMap) => {
55
58
  return items.map((item) => {
56
59
  const key = String(item.tokenAddress).toLowerCase();
57
- const priceUsd = priceMap.get(key) ?? null;
60
+ const priceEntry = priceMap.get(key);
61
+ const priceUsd = priceEntry?.priceUsd ?? null;
62
+ const priceChange24h = priceEntry?.priceChange24h ?? null;
58
63
  const valueUsd = priceUsd === null ? null : item.balanceFormatted * priceUsd;
59
64
  return {
60
65
  ...item,
61
66
  priceUsd,
67
+ priceChange24h,
62
68
  valueUsd,
63
69
  };
64
70
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deserialize/multi-vm-wallet",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "devDependencies": {
5
5
  "@types/bn.js": "^5.2.0",
6
6
  "@types/crypto-js": "^4.2.2",
@@ -47,6 +47,10 @@ export interface PocketBalance {
47
47
  token: string;
48
48
  /** Balance information */
49
49
  balance: Balance;
50
+ /** Token unit price in USD (if unavailable, defaults to 0) */
51
+ priceUsd: number;
52
+ /** Token 24h price change percentage (if unavailable, defaults to 0) */
53
+ priceChange24h: number;
50
54
  /** Balance in USD (if unavailable, defaults to 0) */
51
55
  balanceInUsd: number;
52
56
  }[];
@@ -101,13 +105,18 @@ export class MultiChainSavingsManager {
101
105
  }
102
106
 
103
107
  private normalizePriceMap(
104
- prices: Array<{ tokenAddress: string; price: number }>,
108
+ prices: Array<{ tokenAddress: string; price: number; priceChange24h?: number }>,
105
109
  chainType: ChainType
106
- ): Map<string, number> {
107
- const priceMap = new Map<string, number>();
110
+ ): Map<string, { priceUsd: number; priceChange24h: number }> {
111
+ const priceMap = new Map<string, { priceUsd: number; priceChange24h: number }>();
108
112
  for (const item of prices) {
109
113
  if (!item?.tokenAddress || typeof item.price !== 'number') continue;
110
- priceMap.set(this.getTokenKey(item.tokenAddress, chainType), item.price);
114
+ priceMap.set(this.getTokenKey(item.tokenAddress, chainType), {
115
+ priceUsd: item.price,
116
+ priceChange24h: typeof item.priceChange24h === 'number'
117
+ ? item.priceChange24h
118
+ : 0
119
+ });
111
120
  }
112
121
  return priceMap;
113
122
  }
@@ -115,7 +124,7 @@ export class MultiChainSavingsManager {
115
124
  private async getPriceMap(
116
125
  chain: ChainConfig,
117
126
  tokenAddresses: string[]
118
- ): Promise<Map<string, number>> {
127
+ ): Promise<Map<string, { priceUsd: number; priceChange24h: number }>> {
119
128
  const chainWithId = chain.config as Partial<ChainWalletConfig>;
120
129
  if (typeof chainWithId.chainId !== 'number') {
121
130
  return new Map();
@@ -311,9 +320,11 @@ export class MultiChainSavingsManager {
311
320
  balances: balanceRows.map(row => ({
312
321
  token: row.token,
313
322
  balance: row.balance,
323
+ priceUsd: priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceUsd ?? 0,
324
+ priceChange24h: priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceChange24h ?? 0,
314
325
  balanceInUsd:
315
326
  row.balance.formatted *
316
- (priceMap.get(this.getTokenKey(row.token, 'EVM')) ?? 0)
327
+ (priceMap.get(this.getTokenKey(row.token, 'EVM'))?.priceUsd ?? 0)
317
328
  }))
318
329
  };
319
330
  } else {
@@ -337,9 +348,11 @@ export class MultiChainSavingsManager {
337
348
  balances: balanceRows.map(row => ({
338
349
  token: row.token,
339
350
  balance: row.balance,
351
+ priceUsd: priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceUsd ?? 0,
352
+ priceChange24h: priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceChange24h ?? 0,
340
353
  balanceInUsd:
341
354
  row.balance.formatted *
342
- (priceMap.get(this.getTokenKey(row.token, 'SVM')) ?? 0)
355
+ (priceMap.get(this.getTokenKey(row.token, 'SVM'))?.priceUsd ?? 0)
343
356
  }))
344
357
  };
345
358
  }
package/utils/utils.ts CHANGED
@@ -33,6 +33,7 @@ export interface AddressPortfolioItem {
33
33
  balanceRaw: string;
34
34
  balanceFormatted: number;
35
35
  priceUsd: number | null;
36
+ priceChange24h: number | null;
36
37
  valueUsd: number | null;
37
38
  }
38
39
 
@@ -71,27 +72,35 @@ export const detectVmTypeFromAddress = (address: string): vmTypes => {
71
72
  }
72
73
  };
73
74
 
74
- const normalizePriceMap = (prices: Array<{ tokenAddress: string; price: number }>) => {
75
- const priceMap = new Map<string, number>();
75
+ const normalizePriceMap = (
76
+ prices: Array<{ tokenAddress: string; price: number; priceChange24h?: number }>
77
+ ) => {
78
+ const priceMap = new Map<string, { priceUsd: number; priceChange24h: number | null }>();
76
79
  for (const item of prices) {
77
80
  if (!item?.tokenAddress || typeof item.price !== "number") continue;
78
- priceMap.set(item.tokenAddress.toLowerCase(), item.price);
81
+ priceMap.set(item.tokenAddress.toLowerCase(), {
82
+ priceUsd: item.price,
83
+ priceChange24h: typeof item.priceChange24h === "number" ? item.priceChange24h : null,
84
+ });
79
85
  }
80
86
  return priceMap;
81
87
  };
82
88
 
83
89
  const enrichWithUsdValues = (
84
- items: Omit<AddressPortfolioItem, "priceUsd" | "valueUsd">[],
85
- priceMap: Map<string, number>
90
+ items: Omit<AddressPortfolioItem, "priceUsd" | "priceChange24h" | "valueUsd">[],
91
+ priceMap: Map<string, { priceUsd: number; priceChange24h: number | null }>
86
92
  ): AddressPortfolioResult["items"] => {
87
93
  return items.map((item) => {
88
94
  const key = String(item.tokenAddress).toLowerCase();
89
- const priceUsd = priceMap.get(key) ?? null;
95
+ const priceEntry = priceMap.get(key);
96
+ const priceUsd = priceEntry?.priceUsd ?? null;
97
+ const priceChange24h = priceEntry?.priceChange24h ?? null;
90
98
  const valueUsd = priceUsd === null ? null : item.balanceFormatted * priceUsd;
91
99
 
92
100
  return {
93
101
  ...item,
94
102
  priceUsd,
103
+ priceChange24h,
95
104
  valueUsd,
96
105
  };
97
106
  });
@@ -129,7 +138,7 @@ export const getAddressPortfolioValue = async (params: AddressPortfolioParams):
129
138
  if (vmType === "EVM") {
130
139
  const client = createPublicClientFromChainConfig(chain);
131
140
 
132
- const items: Omit<AddressPortfolioItem, "priceUsd" | "valueUsd">[] = [];
141
+ const items: Omit<AddressPortfolioItem, "priceUsd" | "priceChange24h" | "valueUsd">[] = [];
133
142
  const priceTargets = new Set<string>();
134
143
 
135
144
  if (includeNative) {
@@ -202,7 +211,7 @@ export const getAddressPortfolioValue = async (params: AddressPortfolioParams):
202
211
 
203
212
  const svmAddress = new PublicKey(address);
204
213
  const connection = new Connection(chain.rpcUrl);
205
- const items: Omit<AddressPortfolioItem, "priceUsd" | "valueUsd">[] = [];
214
+ const items: Omit<AddressPortfolioItem, "priceUsd" | "priceChange24h" | "valueUsd">[] = [];
206
215
  const priceTargets = new Set<string>();
207
216
 
208
217
  if (includeNative) {