@opaquecash/stealth-balance 0.1.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/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@opaquecash/stealth-balance` — optional portfolio-style helpers (token lists and RPC stay app-owned).
|
|
3
|
+
*
|
|
4
|
+
* This package defines **types** and a small **aggregation** helper; wire your own `publicClient`
|
|
5
|
+
* calls for `getBalance` / `readContract` `balanceOf` per discovered stealth address.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { Address } from "viem";
|
|
10
|
+
import type { Hex } from "@opaquecash/stealth-core";
|
|
11
|
+
/**
|
|
12
|
+
* ERC-20 (or native) asset the app tracks for private balance UX.
|
|
13
|
+
*/
|
|
14
|
+
export interface TrackedToken {
|
|
15
|
+
/** Contract address; use a sentinel for native ETH if your UI distinguishes it. */
|
|
16
|
+
address: Address;
|
|
17
|
+
symbol: string;
|
|
18
|
+
decimals: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One discovered output + balances filled in by your fetch layer.
|
|
22
|
+
*/
|
|
23
|
+
export interface StealthOutputBalance {
|
|
24
|
+
/** One-time stealth address. */
|
|
25
|
+
stealthAddress: Address;
|
|
26
|
+
/** Per-token balances in minimal units (wei for native). */
|
|
27
|
+
balances: Record<Hex, bigint>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sum per-token balances across many outputs (simple reducer).
|
|
31
|
+
*
|
|
32
|
+
* @param outputs - Rows your indexer or scanner produced.
|
|
33
|
+
* @returns Map token address (lowercase hex) → total raw amount.
|
|
34
|
+
*/
|
|
35
|
+
export declare function aggregateBalancesByToken(outputs: StealthOutputBalance[]): Map<string, bigint>;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,cAAc,EAAE,OAAO,CAAC;IACxB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,oBAAoB,EAAE,GAC9B,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CASrB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@opaquecash/stealth-balance` — optional portfolio-style helpers (token lists and RPC stay app-owned).
|
|
3
|
+
*
|
|
4
|
+
* This package defines **types** and a small **aggregation** helper; wire your own `publicClient`
|
|
5
|
+
* calls for `getBalance` / `readContract` `balanceOf` per discovered stealth address.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Sum per-token balances across many outputs (simple reducer).
|
|
11
|
+
*
|
|
12
|
+
* @param outputs - Rows your indexer or scanner produced.
|
|
13
|
+
* @returns Map token address (lowercase hex) → total raw amount.
|
|
14
|
+
*/
|
|
15
|
+
export function aggregateBalancesByToken(outputs) {
|
|
16
|
+
const totals = new Map();
|
|
17
|
+
for (const o of outputs) {
|
|
18
|
+
for (const [token, amount] of Object.entries(o.balances)) {
|
|
19
|
+
const key = token.toLowerCase();
|
|
20
|
+
totals.set(key, (totals.get(key) ?? 0n) + amount);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return totals;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyBH;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA+B;IAE/B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzD,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opaquecash/stealth-balance",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Optional types and hooks for aggregating balances across discovered stealth outputs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"clean": "rm -rf dist"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@opaquecash/stealth-core": "0.1.0",
|
|
23
|
+
"viem": "^2.21.0"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false
|
|
26
|
+
}
|