@gardenfi/utils 2.5.0 → 2.5.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.
package/dist/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index3.cjs"),t=require("./index5.cjs"),d=require("./index19.cjs"),w=require("./index20.cjs"),f=require("./index21.cjs"),g=require("./index22.cjs"),m=async(u,a,o,e)=>{if(!e.account)return t.Err("No account found");const n=d.getContract({address:s.with0x(a),abi:g.erc20Abi,client:e});try{const c=await n.read.allowance([s.with0x(e.account.address),s.with0x(o)]);if(BigInt(c)<BigInt(u)){const r=await n.write.approve([s.with0x(o),w.maxUint256],{account:e.account,chain:e.chain}),i=await p(e,r);return i.ok?!i.val||i.val.status!=="success"?t.Err("Failed to approve"):t.Ok(r):t.Err(i.error)}return t.Ok("Already approved")}catch(c){return t.Err("Failed to approve: "+c)}},p=async(u,a,o=2e3,e=12e4)=>{const n=Math.ceil(e/o);for(let c=0;c<n;c++){try{const r=await f.getTransactionReceipt(u,{hash:a});if(r)return t.Ok(r)}catch(r){if(!r.message.includes(`Transaction receipt with hash "${a}" could not be found.`))return t.Err(r.message)}c<n-1&&await new Promise(r=>setTimeout(r,o))}return t.Err(`Timed out waiting for receipt of ${a}`)};exports.checkAllowanceAndApprove=m;exports.waitForTransactionReceipt=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index3.cjs"),e=require("./index5.cjs"),g=require("./index19.cjs"),l=require("./index20.cjs"),A=require("./index21.cjs"),h=require("./index22.cjs"),m=async(a,o,i,t)=>{if(!t.account)return e.Err("No account found");const n=g.getContract({address:u.with0x(o),abi:h.erc20Abi,client:t});try{const c=u.with0x(t.account.address),r=u.with0x(i),f=await n.read.allowance([c,r]);if(BigInt(f)<BigInt(a)){const p=await n.write.approve([r,l.maxUint256],{account:t.account,chain:t.chain}),s=await w(t,p);if(!s.ok)return e.Err(s.error);if(!s.val||s.val.status!=="success")return e.Err("Failed to approve");const d=await n.read.allowance([c,r]);return d<a?e.Err(`Insufficient allowance after approval. Needed ${a.toString()}, got ${d.toString()}.`):e.Ok(p)}return e.Ok("Already approved")}catch(c){return e.Err("Failed to approve: "+c)}},w=async(a,o,i=2e3,t=12e4)=>{const n=Math.ceil(t/i);for(let c=0;c<n;c++){try{const r=await A.getTransactionReceipt(a,{hash:o});if(r)return e.Ok(r)}catch(r){if(!r.message.includes(`Transaction receipt with hash "${o}" could not be found.`))return e.Err(r.message)}c<n-1&&await new Promise(r=>setTimeout(r,i))}return e.Err(`Timed out waiting for receipt of ${o}`)};exports.checkAllowanceAndApprove=m;exports.waitForTransactionReceipt=w;
package/dist/index4.js CHANGED
@@ -1,53 +1,53 @@
1
- import { with0x as s } from "./index3.js";
2
- import { Err as e, Ok as u } from "./index5.js";
3
- import { getContract as m } from "./index19.js";
4
- import { maxUint256 as f } from "./index20.js";
5
- import { getTransactionReceipt as d } from "./index21.js";
6
- import { erc20Abi as w } from "./index22.js";
7
- const b = async (p, a, c, t) => {
8
- if (!t.account) return e("No account found");
9
- const i = m({
10
- address: s(a),
11
- abi: w,
1
+ import { with0x as p } from "./index3.js";
2
+ import { Err as o, Ok as f } from "./index5.js";
3
+ import { getContract as w } from "./index19.js";
4
+ import { maxUint256 as g } from "./index20.js";
5
+ import { getTransactionReceipt as l } from "./index21.js";
6
+ import { erc20Abi as v } from "./index22.js";
7
+ const k = async (c, n, i, t) => {
8
+ if (!t.account) return o("No account found");
9
+ const a = w({
10
+ address: p(n),
11
+ abi: v,
12
12
  client: t
13
13
  });
14
14
  try {
15
- const o = await i.read.allowance([
16
- s(t.account.address),
17
- s(c)
18
- ]);
19
- if (BigInt(o) < BigInt(p)) {
20
- const r = await i.write.approve(
21
- [s(c), f],
22
- {
23
- account: t.account,
24
- chain: t.chain
25
- }
26
- ), n = await g(t, r);
27
- return n.ok ? !n.val || n.val.status !== "success" ? e("Failed to approve") : u(r) : e(n.error);
15
+ const e = p(t.account.address), r = p(i), m = await a.read.allowance([e, r]);
16
+ if (BigInt(m) < BigInt(c)) {
17
+ const u = await a.write.approve([r, g], {
18
+ account: t.account,
19
+ chain: t.chain
20
+ }), s = await A(t, u);
21
+ if (!s.ok) return o(s.error);
22
+ if (!s.val || s.val.status !== "success")
23
+ return o("Failed to approve");
24
+ const d = await a.read.allowance([e, r]);
25
+ return d < c ? o(
26
+ `Insufficient allowance after approval. Needed ${c.toString()}, got ${d.toString()}.`
27
+ ) : f(u);
28
28
  }
29
- return u("Already approved");
30
- } catch (o) {
31
- return e("Failed to approve: " + o);
29
+ return f("Already approved");
30
+ } catch (e) {
31
+ return o("Failed to approve: " + e);
32
32
  }
33
- }, g = async (p, a, c = 2e3, t = 12e4) => {
34
- const i = Math.ceil(t / c);
35
- for (let o = 0; o < i; o++) {
33
+ }, A = async (c, n, i = 2e3, t = 12e4) => {
34
+ const a = Math.ceil(t / i);
35
+ for (let e = 0; e < a; e++) {
36
36
  try {
37
- const r = await d(p, { hash: a });
37
+ const r = await l(c, { hash: n });
38
38
  if (r)
39
- return u(r);
39
+ return f(r);
40
40
  } catch (r) {
41
41
  if (!r.message.includes(
42
- `Transaction receipt with hash "${a}" could not be found.`
42
+ `Transaction receipt with hash "${n}" could not be found.`
43
43
  ))
44
- return e(r.message);
44
+ return o(r.message);
45
45
  }
46
- o < i - 1 && await new Promise((r) => setTimeout(r, c));
46
+ e < a - 1 && await new Promise((r) => setTimeout(r, i));
47
47
  }
48
- return e(`Timed out waiting for receipt of ${a}`);
48
+ return o(`Timed out waiting for receipt of ${n}`);
49
49
  };
50
50
  export {
51
- b as checkAllowanceAndApprove,
52
- g as waitForTransactionReceipt
51
+ k as checkAllowanceAndApprove,
52
+ A as waitForTransactionReceipt
53
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/utils",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",