@permissionless-technologies/upp-sdk 0.4.17 → 0.4.20
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/{chunk-KOT5MTDL.js → chunk-2F4NTQRA.js} +2 -2
- package/dist/{chunk-KOT5MTDL.js.map → chunk-2F4NTQRA.js.map} +1 -1
- package/dist/{chunk-GJXJBDE5.cjs → chunk-5H27F6W6.cjs} +14 -5
- package/dist/chunk-5H27F6W6.cjs.map +1 -0
- package/dist/{chunk-HRHGZKTJ.js → chunk-7VPW5T5R.js} +3 -3
- package/dist/{chunk-HRHGZKTJ.js.map → chunk-7VPW5T5R.js.map} +1 -1
- package/dist/{chunk-7BOX7YFZ.js → chunk-C7DUABSG.js} +14 -5
- package/dist/chunk-C7DUABSG.js.map +1 -0
- package/dist/{chunk-7Y6O4P2P.cjs → chunk-FULINHKW.cjs} +14 -14
- package/dist/{chunk-7Y6O4P2P.cjs.map → chunk-FULINHKW.cjs.map} +1 -1
- package/dist/{chunk-QOMHO6FP.cjs → chunk-HONU4ZCL.cjs} +2 -2
- package/dist/{chunk-QOMHO6FP.cjs.map → chunk-HONU4ZCL.cjs.map} +1 -1
- package/dist/{chunk-GQ6JMNJI.js → chunk-NUVI47NL.js} +14 -14
- package/dist/{chunk-GQ6JMNJI.js.map → chunk-NUVI47NL.js.map} +1 -1
- package/dist/{chunk-D3XBKPQ2.cjs → chunk-V6MW5VOF.cjs} +4 -4
- package/dist/{chunk-D3XBKPQ2.cjs.map → chunk-V6MW5VOF.cjs.map} +1 -1
- package/dist/core/index.cjs +57 -57
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +3 -3
- package/dist/{index-DKFupAA8.d.cts → index-DcfqeWvk.d.cts} +7 -2
- package/dist/{index-M91G-og3.d.ts → index-DmowSsZb.d.ts} +7 -2
- package/dist/{index-S2fzWmLW.d.ts → index-DsXMd8zh.d.ts} +1 -1
- package/dist/{index-qTwnREeK.d.cts → index-PgqOAfcc.d.cts} +1 -1
- package/dist/index.cjs +71 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/indexer/index.cjs +6 -6
- package/dist/indexer/index.d.cts +5 -5
- package/dist/indexer/index.d.ts +5 -5
- package/dist/indexer/index.js +1 -1
- package/dist/react/index.cjs +178 -25
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +60 -3
- package/dist/react/index.d.ts +60 -3
- package/dist/react/index.js +161 -9
- package/dist/react/index.js.map +1 -1
- package/dist/{transfer-BDYID3Hn.d.cts → transfer-B4q3ZTJK.d.cts} +73 -0
- package/dist/{transfer-DLukr6ed.d.ts → transfer-Cqg235q6.d.ts} +73 -0
- package/dist/{transfer-OPGKWWX2.cjs → transfer-IAG5G5U5.cjs} +9 -9
- package/dist/{transfer-OPGKWWX2.cjs.map → transfer-IAG5G5U5.cjs.map} +1 -1
- package/dist/{transfer-LT2VGGPZ.js → transfer-U5NRG5ZX.js} +3 -3
- package/dist/{transfer-LT2VGGPZ.js.map → transfer-U5NRG5ZX.js.map} +1 -1
- package/package.json +1 -1
- package/src/contracts/interfaces/IUniversalPrivatePool.sol +1 -0
- package/src/deployments/11155111.json +12 -12
- package/dist/chunk-7BOX7YFZ.js.map +0 -1
- package/dist/chunk-GJXJBDE5.cjs.map +0 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { aC as NoteCreationResult, m as ProofWorkerManager, aD as PlonkProofStruct, aE as ShieldedNote, W as TransferStage, P as PlonkProvingStage, O as SwapOrderEvent } from '../transfer-
|
|
2
|
-
export { A as ASPProof, aL as ASP_TREE_DEPTH, aJ as IndexerConfig, aI as ProofSystemType, aK as SignTypedDataFn, aH as UPPAccountContextType, aG as UPPAccountProvider, a0 as buildASPTree, a6 as computeMultiOriginASPRoot, a9 as computeSingleOriginASPRoot, ai as generateASPProof, ak as generateMultiOriginASPProof, am as generateSingleOriginASPProof, ap as generateUPPProofAsync, aF as useUPPAccount } from '../transfer-
|
|
1
|
+
import { aC as NoteCreationResult, m as ProofWorkerManager, aD as PlonkProofStruct, aE as ShieldedNote, W as TransferStage, P as PlonkProvingStage, O as SwapOrderEvent } from '../transfer-B4q3ZTJK.cjs';
|
|
2
|
+
export { A as ASPProof, aL as ASP_TREE_DEPTH, aJ as IndexerConfig, aI as ProofSystemType, aK as SignTypedDataFn, aH as UPPAccountContextType, aG as UPPAccountProvider, a0 as buildASPTree, a6 as computeMultiOriginASPRoot, a9 as computeSingleOriginASPRoot, ai as generateASPProof, ak as generateMultiOriginASPProof, am as generateSingleOriginASPProof, ap as generateUPPProofAsync, aF as useUPPAccount } from '../transfer-B4q3ZTJK.cjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { CSSProperties } from 'react';
|
|
@@ -804,4 +804,61 @@ declare function useSwap(config: SwapConfig): UseSwapReturn;
|
|
|
804
804
|
|
|
805
805
|
declare function useProofWorker(worker: Worker | null | undefined): ProofWorkerManager | null;
|
|
806
806
|
|
|
807
|
-
|
|
807
|
+
interface TokenBalanceEntry {
|
|
808
|
+
/** Token contract address */
|
|
809
|
+
token: Address;
|
|
810
|
+
/** Symbol from token list (if provided) */
|
|
811
|
+
symbol?: string;
|
|
812
|
+
/** Decimals from token list (if provided) */
|
|
813
|
+
decimals?: number;
|
|
814
|
+
/** Logo emoji from token list (if provided) */
|
|
815
|
+
logoEmoji?: string;
|
|
816
|
+
/** Confirmed private notes (spendable) — SNARK proof system */
|
|
817
|
+
snark: {
|
|
818
|
+
balance: bigint;
|
|
819
|
+
noteCount: number;
|
|
820
|
+
};
|
|
821
|
+
/** Confirmed private notes (spendable) — STARK proof system */
|
|
822
|
+
stark: {
|
|
823
|
+
balance: bigint;
|
|
824
|
+
noteCount: number;
|
|
825
|
+
};
|
|
826
|
+
/** Sell tokens locked in open swap orders (claimable by maker) */
|
|
827
|
+
unclaimedSnark: {
|
|
828
|
+
balance: bigint;
|
|
829
|
+
orderCount: number;
|
|
830
|
+
};
|
|
831
|
+
/** Total across all categories */
|
|
832
|
+
total: bigint;
|
|
833
|
+
}
|
|
834
|
+
interface TokenListItem {
|
|
835
|
+
address: Address;
|
|
836
|
+
symbol: string;
|
|
837
|
+
decimals: number;
|
|
838
|
+
logoEmoji?: string;
|
|
839
|
+
}
|
|
840
|
+
interface PrivateBalanceConfig {
|
|
841
|
+
/** UniversalPrivatePool contract address */
|
|
842
|
+
poolAddress: Address;
|
|
843
|
+
/** viem PublicClient for event scanning */
|
|
844
|
+
publicClient: PublicClient;
|
|
845
|
+
/** Connected wallet address (for identifying own orders) */
|
|
846
|
+
walletAddress?: Address;
|
|
847
|
+
/** Optional token list for symbol/decimals enrichment */
|
|
848
|
+
tokenList?: TokenListItem[];
|
|
849
|
+
/** Auto-sync on mount (default: true) */
|
|
850
|
+
autoSync?: boolean;
|
|
851
|
+
/** Deploy block to scan from (default: 0) */
|
|
852
|
+
fromBlock?: bigint;
|
|
853
|
+
}
|
|
854
|
+
interface UsePrivateBalanceReturn {
|
|
855
|
+
/** Per-token balances sorted by total descending */
|
|
856
|
+
balances: TokenBalanceEntry[];
|
|
857
|
+
/** Whether a sync is in progress */
|
|
858
|
+
isSyncing: boolean;
|
|
859
|
+
/** Trigger a manual sync */
|
|
860
|
+
sync: () => Promise<void>;
|
|
861
|
+
}
|
|
862
|
+
declare function usePrivateBalance(config: PrivateBalanceConfig): UsePrivateBalanceReturn;
|
|
863
|
+
|
|
864
|
+
export { type AvatarData, type AvatarShape, type CancelOrderBuildData, type CancelOrderParams, type ClaimOrderBuildData, type ClaimOrderParams, type FillOrderBuildData, type FillOrderParams, NoteCreationResult, type PersonalASPConfig, type PersonalASPInfo, type PlaceOrderBuildData, type PlaceOrderParams, PlonkProvingStage, type PoolTransferBuildData, type PoolTransferConfig, type PoolTransferParams, type PrivateBalanceConfig, ProofWorkerManager, type ShieldBuildData, type ShieldConfig, type ShieldParams, ShieldedNote, type SplitNoteBuildData, type SplitNoteParams, type SwapConfig, type SwapOrderBookConfig, type SwapStage, type TokenBalanceEntry, type TokenListItem, TransferStage, UPPAvatar, type UPPAvatarProps, UPPModal, type UPPModalProps, UPPPrivateButton, type UPPPrivateButtonProps, type UsePersonalASPReturn, type UsePoolTransferReturn, type UsePrivateBalanceReturn, type UseShieldReturn, type UseSwapOrderBookReturn, type UseSwapReturn, type UseWithdrawReturn, type WithdrawBuildData, type WithdrawConfig, type WithdrawParams, generateAvatarData, renderAvatarSVG, storePersonalASPId, usePersonalASP, usePoolTransfer, usePrivateBalance, useProofWorker, useShield, useSwap, useSwapOrderBook, useUPPCrypto, useWithdraw };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { aC as NoteCreationResult, m as ProofWorkerManager, aD as PlonkProofStruct, aE as ShieldedNote, W as TransferStage, P as PlonkProvingStage, O as SwapOrderEvent } from '../transfer-
|
|
2
|
-
export { A as ASPProof, aL as ASP_TREE_DEPTH, aJ as IndexerConfig, aI as ProofSystemType, aK as SignTypedDataFn, aH as UPPAccountContextType, aG as UPPAccountProvider, a0 as buildASPTree, a6 as computeMultiOriginASPRoot, a9 as computeSingleOriginASPRoot, ai as generateASPProof, ak as generateMultiOriginASPProof, am as generateSingleOriginASPProof, ap as generateUPPProofAsync, aF as useUPPAccount } from '../transfer-
|
|
1
|
+
import { aC as NoteCreationResult, m as ProofWorkerManager, aD as PlonkProofStruct, aE as ShieldedNote, W as TransferStage, P as PlonkProvingStage, O as SwapOrderEvent } from '../transfer-Cqg235q6.js';
|
|
2
|
+
export { A as ASPProof, aL as ASP_TREE_DEPTH, aJ as IndexerConfig, aI as ProofSystemType, aK as SignTypedDataFn, aH as UPPAccountContextType, aG as UPPAccountProvider, a0 as buildASPTree, a6 as computeMultiOriginASPRoot, a9 as computeSingleOriginASPRoot, ai as generateASPProof, ak as generateMultiOriginASPProof, am as generateSingleOriginASPProof, ap as generateUPPProofAsync, aF as useUPPAccount } from '../transfer-Cqg235q6.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { CSSProperties } from 'react';
|
|
@@ -804,4 +804,61 @@ declare function useSwap(config: SwapConfig): UseSwapReturn;
|
|
|
804
804
|
|
|
805
805
|
declare function useProofWorker(worker: Worker | null | undefined): ProofWorkerManager | null;
|
|
806
806
|
|
|
807
|
-
|
|
807
|
+
interface TokenBalanceEntry {
|
|
808
|
+
/** Token contract address */
|
|
809
|
+
token: Address;
|
|
810
|
+
/** Symbol from token list (if provided) */
|
|
811
|
+
symbol?: string;
|
|
812
|
+
/** Decimals from token list (if provided) */
|
|
813
|
+
decimals?: number;
|
|
814
|
+
/** Logo emoji from token list (if provided) */
|
|
815
|
+
logoEmoji?: string;
|
|
816
|
+
/** Confirmed private notes (spendable) — SNARK proof system */
|
|
817
|
+
snark: {
|
|
818
|
+
balance: bigint;
|
|
819
|
+
noteCount: number;
|
|
820
|
+
};
|
|
821
|
+
/** Confirmed private notes (spendable) — STARK proof system */
|
|
822
|
+
stark: {
|
|
823
|
+
balance: bigint;
|
|
824
|
+
noteCount: number;
|
|
825
|
+
};
|
|
826
|
+
/** Sell tokens locked in open swap orders (claimable by maker) */
|
|
827
|
+
unclaimedSnark: {
|
|
828
|
+
balance: bigint;
|
|
829
|
+
orderCount: number;
|
|
830
|
+
};
|
|
831
|
+
/** Total across all categories */
|
|
832
|
+
total: bigint;
|
|
833
|
+
}
|
|
834
|
+
interface TokenListItem {
|
|
835
|
+
address: Address;
|
|
836
|
+
symbol: string;
|
|
837
|
+
decimals: number;
|
|
838
|
+
logoEmoji?: string;
|
|
839
|
+
}
|
|
840
|
+
interface PrivateBalanceConfig {
|
|
841
|
+
/** UniversalPrivatePool contract address */
|
|
842
|
+
poolAddress: Address;
|
|
843
|
+
/** viem PublicClient for event scanning */
|
|
844
|
+
publicClient: PublicClient;
|
|
845
|
+
/** Connected wallet address (for identifying own orders) */
|
|
846
|
+
walletAddress?: Address;
|
|
847
|
+
/** Optional token list for symbol/decimals enrichment */
|
|
848
|
+
tokenList?: TokenListItem[];
|
|
849
|
+
/** Auto-sync on mount (default: true) */
|
|
850
|
+
autoSync?: boolean;
|
|
851
|
+
/** Deploy block to scan from (default: 0) */
|
|
852
|
+
fromBlock?: bigint;
|
|
853
|
+
}
|
|
854
|
+
interface UsePrivateBalanceReturn {
|
|
855
|
+
/** Per-token balances sorted by total descending */
|
|
856
|
+
balances: TokenBalanceEntry[];
|
|
857
|
+
/** Whether a sync is in progress */
|
|
858
|
+
isSyncing: boolean;
|
|
859
|
+
/** Trigger a manual sync */
|
|
860
|
+
sync: () => Promise<void>;
|
|
861
|
+
}
|
|
862
|
+
declare function usePrivateBalance(config: PrivateBalanceConfig): UsePrivateBalanceReturn;
|
|
863
|
+
|
|
864
|
+
export { type AvatarData, type AvatarShape, type CancelOrderBuildData, type CancelOrderParams, type ClaimOrderBuildData, type ClaimOrderParams, type FillOrderBuildData, type FillOrderParams, NoteCreationResult, type PersonalASPConfig, type PersonalASPInfo, type PlaceOrderBuildData, type PlaceOrderParams, PlonkProvingStage, type PoolTransferBuildData, type PoolTransferConfig, type PoolTransferParams, type PrivateBalanceConfig, ProofWorkerManager, type ShieldBuildData, type ShieldConfig, type ShieldParams, ShieldedNote, type SplitNoteBuildData, type SplitNoteParams, type SwapConfig, type SwapOrderBookConfig, type SwapStage, type TokenBalanceEntry, type TokenListItem, TransferStage, UPPAvatar, type UPPAvatarProps, UPPModal, type UPPModalProps, UPPPrivateButton, type UPPPrivateButtonProps, type UsePersonalASPReturn, type UsePoolTransferReturn, type UsePrivateBalanceReturn, type UseShieldReturn, type UseSwapOrderBookReturn, type UseSwapReturn, type UseWithdrawReturn, type WithdrawBuildData, type WithdrawConfig, type WithdrawParams, generateAvatarData, renderAvatarSVG, storePersonalASPId, usePersonalASP, usePoolTransfer, usePrivateBalance, useProofWorker, useShield, useSwap, useSwapOrderBook, useUPPCrypto, useWithdraw };
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StorableAccountAdapter, init_stealth, stealth_exports, generateUPPProofAsync, SWAP_ORDER_PLACED_EVENT, filterOrdersByTokenPair, filterOrdersByASP, generateCancelSecret, computeCancelKeyHash, computeGiveAmount, ProofWorkerManager, NoteStore } from '../chunk-
|
|
2
|
-
export { ProofWorkerManager, generateUPPProofAsync } from '../chunk-
|
|
1
|
+
import { StorableAccountAdapter, init_stealth, stealth_exports, generateUPPProofAsync, SWAP_ORDER_PLACED_EVENT, filterOrdersByTokenPair, filterOrdersByASP, generateCancelSecret, computeCancelKeyHash, computeGiveAmount, ProofWorkerManager, getCancelSecret, SWAP_ORDER_FILLED_EVENT, SWAP_ORDER_CLAIMED_EVENT, SWAP_ORDER_CANCELLED_EVENT, NoteStore } from '../chunk-C7DUABSG.js';
|
|
2
|
+
export { ProofWorkerManager, generateUPPProofAsync } from '../chunk-C7DUABSG.js';
|
|
3
3
|
import { computeSingleOriginASPRoot } from '../chunk-6IEYWJVS.js';
|
|
4
4
|
export { ASP_TREE_DEPTH, buildASPTree, computeMultiOriginASPRoot, computeSingleOriginASPRoot, generateASPProof, generateMultiOriginASPProof, generateSingleOriginASPProof } from '../chunk-6IEYWJVS.js';
|
|
5
5
|
import { createAutoAdapter } from '../chunk-XV72HNHN.js';
|
|
@@ -488,6 +488,7 @@ function UPPAccountProvider({
|
|
|
488
488
|
{ name: "takeAmount", type: "uint256", indexed: false },
|
|
489
489
|
{ name: "giveAmount", type: "uint256", indexed: false },
|
|
490
490
|
{ name: "fillerAspId", type: "uint256", indexed: false },
|
|
491
|
+
{ name: "remainingSellAmount", type: "uint256", indexed: false },
|
|
491
492
|
{ name: "encryptedFillerNote", type: "bytes", indexed: false }
|
|
492
493
|
]
|
|
493
494
|
},
|
|
@@ -790,7 +791,10 @@ function UPPAccountProvider({
|
|
|
790
791
|
syncPromiseRef.current = syncPromise;
|
|
791
792
|
return syncPromise;
|
|
792
793
|
},
|
|
793
|
-
|
|
794
|
+
// Note: `notes` is intentionally NOT in the dependency array to prevent
|
|
795
|
+
// sync loops. The callback reads notes from noteStoreRef.current directly.
|
|
796
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
797
|
+
[masterKeys, cryptoReady, persistNotes]
|
|
794
798
|
);
|
|
795
799
|
const startLiveSync = useCallback(
|
|
796
800
|
(contractAddress, client) => {
|
|
@@ -1706,7 +1710,7 @@ function usePoolTransfer(config) {
|
|
|
1706
1710
|
const recipientNote = await createNoteForSelf(amount, origin, token);
|
|
1707
1711
|
const changeNote = await createNoteForSelf(changeAmount, origin, token);
|
|
1708
1712
|
const [transferModule, proofModule, aspModule] = await Promise.all([
|
|
1709
|
-
import('../transfer-
|
|
1713
|
+
import('../transfer-U5NRG5ZX.js'),
|
|
1710
1714
|
import('../proof-XQG5DN5N.js'),
|
|
1711
1715
|
import('../asp-72WUGTQE.js')
|
|
1712
1716
|
]);
|
|
@@ -1863,7 +1867,7 @@ function useWithdraw(config) {
|
|
|
1863
1867
|
const token = BigInt(selectedNote.token);
|
|
1864
1868
|
setStage("creating_outputs");
|
|
1865
1869
|
const [transferModule, proofModule, sdk] = await Promise.all([
|
|
1866
|
-
import('../transfer-
|
|
1870
|
+
import('../transfer-U5NRG5ZX.js'),
|
|
1867
1871
|
import('../proof-XQG5DN5N.js'),
|
|
1868
1872
|
import('../index.js')
|
|
1869
1873
|
]);
|
|
@@ -2240,7 +2244,7 @@ function useSwap(config) {
|
|
|
2240
2244
|
}
|
|
2241
2245
|
setStage("creating_outputs");
|
|
2242
2246
|
const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
|
|
2243
|
-
import('../transfer-
|
|
2247
|
+
import('../transfer-U5NRG5ZX.js'),
|
|
2244
2248
|
import('../proof-XQG5DN5N.js'),
|
|
2245
2249
|
import('../index.js'),
|
|
2246
2250
|
import('../asp-72WUGTQE.js')
|
|
@@ -2387,7 +2391,7 @@ function useSwap(config) {
|
|
|
2387
2391
|
}
|
|
2388
2392
|
setStage("creating_outputs");
|
|
2389
2393
|
const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
|
|
2390
|
-
import('../transfer-
|
|
2394
|
+
import('../transfer-U5NRG5ZX.js'),
|
|
2391
2395
|
import('../proof-XQG5DN5N.js'),
|
|
2392
2396
|
import('../index.js'),
|
|
2393
2397
|
import('../asp-72WUGTQE.js')
|
|
@@ -2624,7 +2628,7 @@ function useSwap(config) {
|
|
|
2624
2628
|
createNoteForSelf(changeAmount, origin, token)
|
|
2625
2629
|
]);
|
|
2626
2630
|
const [transferModule, proofModule, aspModule] = await Promise.all([
|
|
2627
|
-
import('../transfer-
|
|
2631
|
+
import('../transfer-U5NRG5ZX.js'),
|
|
2628
2632
|
import('../proof-XQG5DN5N.js'),
|
|
2629
2633
|
import('../asp-72WUGTQE.js')
|
|
2630
2634
|
]);
|
|
@@ -2754,7 +2758,155 @@ function useProofWorker(worker) {
|
|
|
2754
2758
|
}, [worker]);
|
|
2755
2759
|
return managerRef.current;
|
|
2756
2760
|
}
|
|
2761
|
+
function usePrivateBalance(config) {
|
|
2762
|
+
const { unspentNotes, syncNotes, isSyncing: isNoteSyncing } = useUPPAccount();
|
|
2763
|
+
const { poolAddress, publicClient, walletAddress, tokenList, autoSync = true, fromBlock = 0n } = config;
|
|
2764
|
+
const [unclaimedOrders, setUnclaimedOrders] = useState(/* @__PURE__ */ new Map());
|
|
2765
|
+
const [isOrderSyncing, setIsOrderSyncing] = useState(false);
|
|
2766
|
+
const hasAutoSynced = useRef(false);
|
|
2767
|
+
const configRef = useRef(config);
|
|
2768
|
+
configRef.current = config;
|
|
2769
|
+
const syncUnclaimedOrders = useCallback(async () => {
|
|
2770
|
+
if (!publicClient || !poolAddress) return;
|
|
2771
|
+
setIsOrderSyncing(true);
|
|
2772
|
+
try {
|
|
2773
|
+
const placedLogs = await publicClient.getLogs({
|
|
2774
|
+
address: poolAddress,
|
|
2775
|
+
event: SWAP_ORDER_PLACED_EVENT,
|
|
2776
|
+
fromBlock,
|
|
2777
|
+
toBlock: "latest"
|
|
2778
|
+
});
|
|
2779
|
+
const orders = /* @__PURE__ */ new Map();
|
|
2780
|
+
for (const log of placedLogs) {
|
|
2781
|
+
const args = log.args;
|
|
2782
|
+
const orderId = args.orderId;
|
|
2783
|
+
if (walletAddress && !getCancelSecret(orderId, walletAddress)) continue;
|
|
2784
|
+
orders.set(orderId.toLowerCase(), {
|
|
2785
|
+
sellToken: args.sellToken,
|
|
2786
|
+
sellAmount: BigInt(args.sellAmount),
|
|
2787
|
+
remaining: BigInt(args.sellAmount)
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
const filledLogs = await publicClient.getLogs({
|
|
2791
|
+
address: poolAddress,
|
|
2792
|
+
event: SWAP_ORDER_FILLED_EVENT,
|
|
2793
|
+
fromBlock,
|
|
2794
|
+
toBlock: "latest"
|
|
2795
|
+
});
|
|
2796
|
+
for (const log of filledLogs) {
|
|
2797
|
+
const args = log.args;
|
|
2798
|
+
const orderId = args.orderId.toLowerCase();
|
|
2799
|
+
const order = orders.get(orderId);
|
|
2800
|
+
if (order) {
|
|
2801
|
+
const remaining = args.remainingSellAmount;
|
|
2802
|
+
if (remaining !== void 0) {
|
|
2803
|
+
order.remaining = BigInt(remaining);
|
|
2804
|
+
} else {
|
|
2805
|
+
order.remaining -= BigInt(args.takeAmount);
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
const claimedLogs = await publicClient.getLogs({
|
|
2810
|
+
address: poolAddress,
|
|
2811
|
+
event: SWAP_ORDER_CLAIMED_EVENT,
|
|
2812
|
+
fromBlock,
|
|
2813
|
+
toBlock: "latest"
|
|
2814
|
+
});
|
|
2815
|
+
for (const log of claimedLogs) {
|
|
2816
|
+
orders.delete(log.args.orderId.toLowerCase());
|
|
2817
|
+
}
|
|
2818
|
+
const cancelledLogs = await publicClient.getLogs({
|
|
2819
|
+
address: poolAddress,
|
|
2820
|
+
event: SWAP_ORDER_CANCELLED_EVENT,
|
|
2821
|
+
fromBlock,
|
|
2822
|
+
toBlock: "latest"
|
|
2823
|
+
});
|
|
2824
|
+
for (const log of cancelledLogs) {
|
|
2825
|
+
orders.delete(log.args.orderId.toLowerCase());
|
|
2826
|
+
}
|
|
2827
|
+
const result = /* @__PURE__ */ new Map();
|
|
2828
|
+
for (const [id, order] of orders) {
|
|
2829
|
+
if (order.remaining > 0n) {
|
|
2830
|
+
result.set(id, { sellToken: order.sellToken, remaining: order.remaining });
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
setUnclaimedOrders(result);
|
|
2834
|
+
} catch (e) {
|
|
2835
|
+
console.warn("[usePrivateBalance] Failed to sync unclaimed orders:", e);
|
|
2836
|
+
} finally {
|
|
2837
|
+
setIsOrderSyncing(false);
|
|
2838
|
+
}
|
|
2839
|
+
}, [publicClient, poolAddress, walletAddress, fromBlock]);
|
|
2840
|
+
const sync = useCallback(async () => {
|
|
2841
|
+
if (!publicClient || !poolAddress) return;
|
|
2842
|
+
await Promise.all([
|
|
2843
|
+
syncNotes(poolAddress, publicClient),
|
|
2844
|
+
syncUnclaimedOrders()
|
|
2845
|
+
]);
|
|
2846
|
+
}, [publicClient, poolAddress, syncNotes, syncUnclaimedOrders]);
|
|
2847
|
+
useEffect(() => {
|
|
2848
|
+
if (!autoSync || hasAutoSynced.current || !publicClient || !poolAddress) return;
|
|
2849
|
+
hasAutoSynced.current = true;
|
|
2850
|
+
sync().catch((e) => console.error("[usePrivateBalance] Auto-sync failed:", e));
|
|
2851
|
+
}, [autoSync, publicClient, poolAddress]);
|
|
2852
|
+
useEffect(() => {
|
|
2853
|
+
hasAutoSynced.current = false;
|
|
2854
|
+
}, [walletAddress]);
|
|
2855
|
+
const balances = useMemo(() => {
|
|
2856
|
+
const byToken = /* @__PURE__ */ new Map();
|
|
2857
|
+
const getOrCreate = (addr) => {
|
|
2858
|
+
const key = addr.toLowerCase();
|
|
2859
|
+
let entry = byToken.get(key);
|
|
2860
|
+
if (!entry) {
|
|
2861
|
+
const info = tokenList?.find((t) => t.address.toLowerCase() === key);
|
|
2862
|
+
entry = {
|
|
2863
|
+
token: key,
|
|
2864
|
+
symbol: info?.symbol,
|
|
2865
|
+
decimals: info?.decimals,
|
|
2866
|
+
logoEmoji: info?.logoEmoji,
|
|
2867
|
+
snark: { balance: 0n, noteCount: 0 },
|
|
2868
|
+
stark: { balance: 0n, noteCount: 0 },
|
|
2869
|
+
unclaimedSnark: { balance: 0n, orderCount: 0 },
|
|
2870
|
+
total: 0n
|
|
2871
|
+
};
|
|
2872
|
+
byToken.set(key, entry);
|
|
2873
|
+
}
|
|
2874
|
+
return entry;
|
|
2875
|
+
};
|
|
2876
|
+
for (const note of unspentNotes) {
|
|
2877
|
+
if (!note.token) continue;
|
|
2878
|
+
const entry = getOrCreate(note.token);
|
|
2879
|
+
const ps = note.proofSystem ?? "snark";
|
|
2880
|
+
entry[ps].balance += note.amount;
|
|
2881
|
+
entry[ps].noteCount++;
|
|
2882
|
+
}
|
|
2883
|
+
for (const [, order] of unclaimedOrders) {
|
|
2884
|
+
const entry = getOrCreate(order.sellToken);
|
|
2885
|
+
entry.unclaimedSnark.balance += order.remaining;
|
|
2886
|
+
entry.unclaimedSnark.orderCount++;
|
|
2887
|
+
}
|
|
2888
|
+
if (tokenList) {
|
|
2889
|
+
for (const t of tokenList) {
|
|
2890
|
+
getOrCreate(t.address);
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
for (const entry of byToken.values()) {
|
|
2894
|
+
entry.total = entry.snark.balance + entry.stark.balance + entry.unclaimedSnark.balance;
|
|
2895
|
+
}
|
|
2896
|
+
return Array.from(byToken.values()).sort((a, b) => {
|
|
2897
|
+
if (a.total > 0n && b.total === 0n) return -1;
|
|
2898
|
+
if (a.total === 0n && b.total > 0n) return 1;
|
|
2899
|
+
if (a.total !== b.total) return Number(b.total - a.total);
|
|
2900
|
+
return (a.symbol ?? "").localeCompare(b.symbol ?? "");
|
|
2901
|
+
});
|
|
2902
|
+
}, [unspentNotes, unclaimedOrders, tokenList]);
|
|
2903
|
+
return {
|
|
2904
|
+
balances,
|
|
2905
|
+
isSyncing: isNoteSyncing || isOrderSyncing,
|
|
2906
|
+
sync
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2757
2909
|
|
|
2758
|
-
export { UPPAccountProvider, UPPAvatar, UPPModal, UPPPrivateButton, generateAvatarData, renderAvatarSVG, storePersonalASPId, usePersonalASP, usePoolTransfer, useProofWorker, useShield, useSwap, useSwapOrderBook, useUPPAccount, useUPPCrypto, useWithdraw };
|
|
2910
|
+
export { UPPAccountProvider, UPPAvatar, UPPModal, UPPPrivateButton, generateAvatarData, renderAvatarSVG, storePersonalASPId, usePersonalASP, usePoolTransfer, usePrivateBalance, useProofWorker, useShield, useSwap, useSwapOrderBook, useUPPAccount, useUPPCrypto, useWithdraw };
|
|
2759
2911
|
//# sourceMappingURL=index.js.map
|
|
2760
2912
|
//# sourceMappingURL=index.js.map
|