@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 +1 -1
- package/dist/index4.js +12 -13
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +17 -18
- package/package.json +1 -1
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
3
|
-
import { with0x as
|
|
4
|
-
import { waitForTransactionReceipt as
|
|
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:
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const c = await n.read.allowance([
|
|
15
|
+
t(e[0]),
|
|
16
|
+
t(a)
|
|
18
17
|
]);
|
|
19
|
-
if (BigInt(
|
|
18
|
+
if (BigInt(c) < BigInt(p)) {
|
|
20
19
|
const i = await n.write.approve(
|
|
21
|
-
[
|
|
20
|
+
[t(a), m],
|
|
22
21
|
{
|
|
23
22
|
account: r.account,
|
|
24
23
|
chain: r.chain
|
|
25
24
|
}
|
|
26
25
|
);
|
|
27
|
-
return (await
|
|
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 (
|
|
33
|
-
return o("Failed to approve: " +
|
|
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
|
|
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
|
|
3
|
-
import { mainnet as
|
|
4
|
-
import { sepolia as
|
|
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:
|
|
7
|
-
421614:
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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:
|
|
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
|
-
},
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
l as _fetchEVMBlockNumber,
|
|
34
|
+
C as fetchBitcoinBlockNumber,
|
|
35
|
+
N as fetchEVMBlockNumber
|
|
37
36
|
};
|