@fairblock/stabletrust 1.0.16 → 1.0.17

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.
@@ -163,9 +163,9 @@ async function main() {
163
163
  );
164
164
 
165
165
  // 3. WITHDRAW PHASE
166
- const withdrawAmount = ethers.parseUnits("0.05", tokenDecimals);
166
+ const withdrawAmount = ethers.parseUnits("0.025", tokenDecimals);
167
167
  console.log(
168
- "Withdrawing 0.05 tokens from confidential contract to recipient's public balance...",
168
+ "Withdrawing 0.025 tokens from confidential contract to recipient's public balance...",
169
169
  );
170
170
  let recipientConfidentialBalanceBeforeWithdraw =
171
171
  await client.getConfidentialBalance(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fairblock/stabletrust",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "SDK for confidential transfers using homomorphic encryption and zero-knowledge proofs",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/client.js CHANGED
@@ -778,18 +778,28 @@ export class ConfidentialTransferClient {
778
778
  }
779
779
 
780
780
  const address = await wallet.getAddress();
781
- await this._applyPendingIfNeeded(
782
- wallet,
783
- derivedKeys.privateKey,
784
- tokenAddress,
785
- "withdraw",
786
- );
787
-
788
- const balanceSummary = await this.getConfidentialBalance(
781
+ // Fetch balance first — only apply pending if available is insufficient
782
+ let balanceSummary = await this.getConfidentialBalance(
789
783
  address,
790
784
  derivedKeys.privateKey,
791
785
  tokenAddress,
792
786
  );
787
+
788
+ if (balanceSummary.available.amount < BigInt(amount)) {
789
+ await this._applyPendingIfNeeded(
790
+ wallet,
791
+ derivedKeys.privateKey,
792
+ tokenAddress,
793
+ "withdraw",
794
+ );
795
+ // Re-fetch after applying pending
796
+ balanceSummary = await this.getConfidentialBalance(
797
+ address,
798
+ derivedKeys.privateKey,
799
+ tokenAddress,
800
+ );
801
+ }
802
+
793
803
  const currentBalanceCiphertext = balanceSummary.available.ciphertext;
794
804
  const currentBalance = balanceSummary.available.amount;
795
805