@cloakely/sdk 0.2.5 → 0.2.6
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/private/client.js +5 -0
- package/package.json +1 -1
package/dist/private/client.js
CHANGED
|
@@ -10,6 +10,7 @@ const positionOf = (globalIndex) => globalIndex % 2 ** EPOCH_BITS;
|
|
|
10
10
|
const ERC20_ABI = [
|
|
11
11
|
{ type: "function", name: "allowance", stateMutability: "view", inputs: [{ type: "address" }, { type: "address" }], outputs: [{ type: "uint256" }] },
|
|
12
12
|
{ type: "function", name: "approve", stateMutability: "nonpayable", inputs: [{ type: "address" }, { type: "uint256" }], outputs: [{ type: "bool" }] },
|
|
13
|
+
{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ type: "address" }], outputs: [{ type: "uint256" }] },
|
|
13
14
|
];
|
|
14
15
|
const json = (v) => JSON.stringify(v, (_, x) => (typeof x === "bigint" ? x.toString() : x));
|
|
15
16
|
/** POST shielded calls to a Cloak relayer (`services/keeper` serves `/relay` and `/quote`). */
|
|
@@ -312,6 +313,10 @@ export class CloakPrivate {
|
|
|
312
313
|
throw new Error("amount must be positive");
|
|
313
314
|
const pool = this.market(token).pool;
|
|
314
315
|
const owner = wallet.account.address;
|
|
316
|
+
// check first, so a wallet without the tokens doesn't pay gas for an approval that leads nowhere
|
|
317
|
+
const held = await this.publicClient.readContract({ address: token, abi: ERC20_ABI, functionName: "balanceOf", args: [owner] });
|
|
318
|
+
if (held < amount)
|
|
319
|
+
throw new Error(`insufficient token balance in wallet: has ${held}, needs ${amount}`);
|
|
315
320
|
const allowance = await this.publicClient.readContract({ address: token, abi: ERC20_ABI, functionName: "allowance", args: [owner, pool] });
|
|
316
321
|
if (allowance < amount) {
|
|
317
322
|
onStatus("Approve the deposit in your wallet…");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloakely/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Cloak on Elysium: sealed-bid token launches and private trading (shielded balances, private swaps, batch auctions, private sends) with on-device zero-knowledge proofs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloak",
|