@gardenfi/utils 0.0.1-beta.15 → 0.0.1-beta.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.
package/dist/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@catalogfi/utils"),o=require("viem"),t=require("./index3.cjs"),d=require("./index10.cjs"),h=async(u,p,a,r)=>{if(!r.account)return c.Err("No account found");console.log("walletClient.chain",r.chain);const n=o.getContract({address:t.with0x(p),abi:o.erc20Abi,client:r}),i=await r.getAddresses();if(!i[0])return c.Err("No account found");try{const e=await n.read.allowance([t.with0x(i[0]),t.with0x(a)]);if(BigInt(e)<BigInt(u)){const s=await n.write.approve([t.with0x(a),o.maxUint256],{account:r.account,chain:r.chain});return(await d.waitForTransactionReceipt(r,{hash:s})).status!=="success"?c.Err("Failed to approve"):c.Ok(s)}return c.Ok("Already approved")}catch(e){return c.Err("Failed to approve: "+e)}};exports.checkAllowanceAndApprove=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@catalogfi/utils"),o=require("viem"),c=require("./index3.cjs"),d=require("./index10.cjs"),h=async(u,p,a,r)=>{if(!r.account)return t.Err("No account found");const n=o.getContract({address:c.with0x(p),abi:o.erc20Abi,client:r}),i=await r.getAddresses();if(!i[0])return t.Err("No account found");try{const e=await n.read.allowance([c.with0x(i[0]),c.with0x(a)]);if(BigInt(e)<BigInt(u)){const s=await n.write.approve([c.with0x(a),o.maxUint256],{account:r.account,chain:r.chain});return(await d.waitForTransactionReceipt(r,{hash:s})).status!=="success"?t.Err("Failed to approve"):t.Ok(s)}return t.Ok("Already approved")}catch(e){return t.Err("Failed to approve: "+e)}};exports.checkAllowanceAndApprove=h;
package/dist/index4.js CHANGED
@@ -1,36 +1,35 @@
1
1
  import { Err as o, Ok as s } from "@catalogfi/utils";
2
- import { getContract as d, erc20Abi as f, maxUint256 as h } from "viem";
3
- import { with0x as c } from "./index3.js";
4
- import { waitForTransactionReceipt as m } from "./index10.js";
2
+ import { getContract as d, erc20Abi as f, maxUint256 as m } from "viem";
3
+ import { with0x as t } from "./index3.js";
4
+ import { waitForTransactionReceipt as h } from "./index10.js";
5
5
  const y = async (p, u, a, r) => {
6
6
  if (!r.account) return o("No account found");
7
- console.log("walletClient.chain", r.chain);
8
7
  const n = d({
9
- address: c(u),
8
+ address: t(u),
10
9
  abi: f,
11
10
  client: r
12
11
  }), e = await r.getAddresses();
13
12
  if (!e[0]) return o("No account found");
14
13
  try {
15
- const t = await n.read.allowance([
16
- c(e[0]),
17
- c(a)
14
+ const c = await n.read.allowance([
15
+ t(e[0]),
16
+ t(a)
18
17
  ]);
19
- if (BigInt(t) < BigInt(p)) {
18
+ if (BigInt(c) < BigInt(p)) {
20
19
  const i = await n.write.approve(
21
- [c(a), h],
20
+ [t(a), m],
22
21
  {
23
22
  account: r.account,
24
23
  chain: r.chain
25
24
  }
26
25
  );
27
- return (await m(r, {
26
+ return (await h(r, {
28
27
  hash: i
29
28
  })).status !== "success" ? o("Failed to approve") : s(i);
30
29
  }
31
30
  return s("Already approved");
32
- } catch (t) {
33
- return o("Failed to approve: " + t);
31
+ } catch (c) {
32
+ return o("Failed to approve: " + c);
34
33
  }
35
34
  };
36
35
  export {
package/dist/index9.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@catalogfi/utils"),n=require("viem"),u=require("./index12.cjs"),a=require("./index13.cjs"),o={42161:u.mainnet,421614:a.sepolia},s=async e=>{if(!e.chain)return c.Err("No chain found");const t=Object.keys(o).includes(e.chain.id.toString())?o[e.chain.id]:e.chain;return await i(t)},i=async e=>{const t=n.createPublicClient({chain:e,transport:n.http()});try{const r=await t.getBlockNumber();return c.Ok(Number(r))}catch(r){return c.Err("Failed to fetch evm block number",r)}},b=async e=>{try{const t=await e.getLatestTip();return c.Ok(t)}catch(t){return c.Err("Failed to fetch bitcoin block number",t)}};exports._fetchEVMBlockNumber=i;exports.fetchBitcoinBlockNumber=b;exports.fetchEVMBlockNumber=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@catalogfi/utils"),n=require("viem"),s=require("./index12.cjs"),l=require("./index13.cjs"),o={42161:s.mainnet,421614:l.sepolia},b=async e=>{const{chain:t}=e;if(!t)return r.Err("No chain found");const u=(a=>a in o)(t.id)?o[t.id]:t;return await i(u)},i=async e=>{const t=n.createPublicClient({chain:e,transport:n.http()});try{const c=await t.getBlockNumber();return r.Ok(Number(c))}catch(c){return r.Err("Failed to fetch evm block number",c)}},m=async e=>{try{const t=await e.getLatestTip();return r.Ok(t)}catch(t){return r.Err("Failed to fetch bitcoin block number",t)}};exports._fetchEVMBlockNumber=i;exports.fetchBitcoinBlockNumber=m;exports.fetchEVMBlockNumber=b;
package/dist/index9.js CHANGED
@@ -1,20 +1,19 @@
1
1
  import { Err as o, Ok as n } from "@catalogfi/utils";
2
- import { createPublicClient as i, http as a } from "viem";
3
- import { mainnet as m } from "./index12.js";
4
- import { sepolia as u } from "./index13.js";
2
+ import { createPublicClient as m, http as s } from "viem";
3
+ import { mainnet as u } from "./index12.js";
4
+ import { sepolia as b } from "./index13.js";
5
5
  const e = {
6
- 42161: m,
7
- 421614: u
8
- }, p = async (r) => {
9
- if (!r.chain) return o("No chain found");
10
- const t = Object.keys(e).includes(
11
- r.chain.id.toString()
12
- ) ? e[r.chain.id] : r.chain;
13
- return await b(t);
14
- }, b = async (r) => {
15
- const t = i({
6
+ 42161: u,
7
+ 421614: b
8
+ }, N = async (r) => {
9
+ const { chain: t } = r;
10
+ if (!t) return o("No chain found");
11
+ const i = ((a) => a in e)(t.id) ? e[t.id] : t;
12
+ return await l(i);
13
+ }, l = async (r) => {
14
+ const t = m({
16
15
  chain: r,
17
- transport: a()
16
+ transport: s()
18
17
  });
19
18
  try {
20
19
  const c = await t.getBlockNumber();
@@ -22,7 +21,7 @@ const e = {
22
21
  } catch (c) {
23
22
  return o("Failed to fetch evm block number", c);
24
23
  }
25
- }, N = async (r) => {
24
+ }, C = async (r) => {
26
25
  try {
27
26
  const t = await r.getLatestTip();
28
27
  return n(t);
@@ -31,7 +30,7 @@ const e = {
31
30
  }
32
31
  };
33
32
  export {
34
- b as _fetchEVMBlockNumber,
35
- N as fetchBitcoinBlockNumber,
36
- p as fetchEVMBlockNumber
33
+ l as _fetchEVMBlockNumber,
34
+ C as fetchBitcoinBlockNumber,
35
+ N as fetchEVMBlockNumber
37
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/utils",
3
- "version": "0.0.1-beta.15",
3
+ "version": "0.0.1-beta.17",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",