@gardenfi/utils 0.0.1-beta.0
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/README.md +0 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +21 -0
- package/dist/index10.cjs +1 -0
- package/dist/index10.js +97 -0
- package/dist/index11.cjs +1 -0
- package/dist/index11.js +33 -0
- package/dist/index12.cjs +1 -0
- package/dist/index12.js +34 -0
- package/dist/index13.cjs +1 -0
- package/dist/index13.js +27 -0
- package/dist/index14.cjs +1 -0
- package/dist/index14.js +33 -0
- package/dist/index15.cjs +1 -0
- package/dist/index15.js +11 -0
- package/dist/index16.cjs +1 -0
- package/dist/index16.js +20 -0
- package/dist/index17.cjs +1 -0
- package/dist/index17.js +10 -0
- package/dist/index18.cjs +1 -0
- package/dist/index18.js +23 -0
- package/dist/index19.cjs +1 -0
- package/dist/index19.js +25 -0
- package/dist/index2.cjs +1 -0
- package/dist/index2.js +4 -0
- package/dist/index20.cjs +1 -0
- package/dist/index20.js +11 -0
- package/dist/index21.cjs +1 -0
- package/dist/index21.js +34 -0
- package/dist/index22.cjs +1 -0
- package/dist/index22.js +29 -0
- package/dist/index23.cjs +1 -0
- package/dist/index23.js +26 -0
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +55 -0
- package/dist/index25.cjs +1 -0
- package/dist/index25.js +15 -0
- package/dist/index26.cjs +1 -0
- package/dist/index26.js +27 -0
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +78 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +26 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +10 -0
- package/dist/index3.cjs +1 -0
- package/dist/index3.js +6 -0
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +32 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +18 -0
- package/dist/index32.cjs +1 -0
- package/dist/index32.js +4 -0
- package/dist/index33.cjs +1 -0
- package/dist/index33.js +23 -0
- package/dist/index34.cjs +1 -0
- package/dist/index34.js +15 -0
- package/dist/index35.cjs +1 -0
- package/dist/index35.js +37 -0
- package/dist/index36.cjs +2 -0
- package/dist/index36.js +62 -0
- package/dist/index37.cjs +1 -0
- package/dist/index37.js +4 -0
- package/dist/index38.cjs +1 -0
- package/dist/index38.js +7 -0
- package/dist/index39.cjs +1 -0
- package/dist/index39.js +14 -0
- package/dist/index4.cjs +1 -0
- package/dist/index4.js +37 -0
- package/dist/index40.cjs +1 -0
- package/dist/index40.js +6 -0
- package/dist/index41.cjs +1 -0
- package/dist/index41.js +6 -0
- package/dist/index42.cjs +1 -0
- package/dist/index42.js +9 -0
- package/dist/index5.cjs +1 -0
- package/dist/index5.js +33 -0
- package/dist/index6.cjs +1 -0
- package/dist/index6.js +20 -0
- package/dist/index7.cjs +1 -0
- package/dist/index7.js +95 -0
- package/dist/index8.cjs +1 -0
- package/dist/index8.js +17 -0
- package/dist/index9.cjs +1 -0
- package/dist/index9.js +4 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/lib/apiResponse.types.d.ts +9 -0
- package/dist/src/lib/approve.d.ts +7 -0
- package/dist/src/lib/auth/auth.types.d.ts +21 -0
- package/dist/src/lib/auth/index.d.ts +2 -0
- package/dist/src/lib/auth/siwe.d.ts +17 -0
- package/dist/src/lib/store/index.d.ts +2 -0
- package/dist/src/lib/store/memoryStorage.d.ts +14 -0
- package/dist/src/lib/store/store.interface.d.ts +33 -0
- package/dist/src/lib/switchOrAddNetwork.d.ts +5 -0
- package/dist/src/lib/url/Url.d.ts +5 -0
- package/dist/src/lib/url/index.d.ts +1 -0
- package/dist/src/lib/utils.d.ts +8 -0
- package/package.json +43 -0
package/dist/index27.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index28.cjs"),d=require("./index29.cjs"),y=require("./index30.cjs"),h=require("./index31.cjs"),B=require("./index32.cjs"),m=require("./index20.cjs");function q(t,{emitOnBegin:b=!1,emitMissed:l=!1,onBlockNumber:p,onError:a,poll:k,pollingInterval:i=t.pollingInterval}){const g=typeof k<"u"?k:!(t.transport.type==="webSocket"||t.transport.type==="fallback"&&t.transport.transports[0].config.type==="webSocket");let r;return g?(()=>{const f=B.stringify(["watchBlockNumber",t.uid,b,l,i]);return y.observe(f,{onBlockNumber:p,onError:a},o=>h.poll(async()=>{var c;try{const e=await d.getAction(t,m.getBlockNumber,"getBlockNumber")({cacheTime:0});if(r){if(e===r)return;if(e-r>1&&l)for(let s=r+1n;s<e;s++)o.onBlockNumber(s,r),r=s}(!r||e>r)&&(o.onBlockNumber(e,r),r=e)}catch(e){(c=o.onError)==null||c.call(o,e)}},{emitOnBegin:b,interval:i}))})():(()=>{const f=B.stringify(["watchBlockNumber",t.uid,b,l]);return y.observe(f,{onBlockNumber:p,onError:a},o=>{let c=!0,e=()=>c=!1;return(async()=>{try{const s=(()=>{if(t.transport.type==="fallback"){const n=t.transport.transports.find(u=>u.config.type==="webSocket");return n?n.value:t.transport}return t.transport})(),{unsubscribe:v}=await s.subscribe({params:["newHeads"],onData(n){var N;if(!c)return;const u=w.hexToBigInt((N=n.result)==null?void 0:N.number);o.onBlockNumber(u,r),r=u},onError(n){var u;(u=o.onError)==null||u.call(o,n)}});e=v,c||e()}catch(s){a==null||a(s)}})(),()=>e()})})()}exports.watchBlockNumber=q;
|
package/dist/index27.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { hexToBigInt as h } from "./index28.js";
|
|
2
|
+
import { getAction as v } from "./index29.js";
|
|
3
|
+
import { observe as i } from "./index30.js";
|
|
4
|
+
import { poll as d } from "./index31.js";
|
|
5
|
+
import { stringify as y } from "./index32.js";
|
|
6
|
+
import { getBlockNumber as g } from "./index20.js";
|
|
7
|
+
function j(t, { emitOnBegin: b = !1, emitMissed: f = !1, onBlockNumber: p, onError: n, poll: k, pollingInterval: m = t.pollingInterval }) {
|
|
8
|
+
const B = typeof k < "u" ? k : !(t.transport.type === "webSocket" || t.transport.type === "fallback" && t.transport.transports[0].config.type === "webSocket");
|
|
9
|
+
let r;
|
|
10
|
+
return B ? (() => {
|
|
11
|
+
const l = y([
|
|
12
|
+
"watchBlockNumber",
|
|
13
|
+
t.uid,
|
|
14
|
+
b,
|
|
15
|
+
f,
|
|
16
|
+
m
|
|
17
|
+
]);
|
|
18
|
+
return i(l, { onBlockNumber: p, onError: n }, (e) => d(async () => {
|
|
19
|
+
var a;
|
|
20
|
+
try {
|
|
21
|
+
const o = await v(t, g, "getBlockNumber")({ cacheTime: 0 });
|
|
22
|
+
if (r) {
|
|
23
|
+
if (o === r)
|
|
24
|
+
return;
|
|
25
|
+
if (o - r > 1 && f)
|
|
26
|
+
for (let s = r + 1n; s < o; s++)
|
|
27
|
+
e.onBlockNumber(s, r), r = s;
|
|
28
|
+
}
|
|
29
|
+
(!r || o > r) && (e.onBlockNumber(o, r), r = o);
|
|
30
|
+
} catch (o) {
|
|
31
|
+
(a = e.onError) == null || a.call(e, o);
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
emitOnBegin: b,
|
|
35
|
+
interval: m
|
|
36
|
+
}));
|
|
37
|
+
})() : (() => {
|
|
38
|
+
const l = y([
|
|
39
|
+
"watchBlockNumber",
|
|
40
|
+
t.uid,
|
|
41
|
+
b,
|
|
42
|
+
f
|
|
43
|
+
]);
|
|
44
|
+
return i(l, { onBlockNumber: p, onError: n }, (e) => {
|
|
45
|
+
let a = !0, o = () => a = !1;
|
|
46
|
+
return (async () => {
|
|
47
|
+
try {
|
|
48
|
+
const s = (() => {
|
|
49
|
+
if (t.transport.type === "fallback") {
|
|
50
|
+
const c = t.transport.transports.find((u) => u.config.type === "webSocket");
|
|
51
|
+
return c ? c.value : t.transport;
|
|
52
|
+
}
|
|
53
|
+
return t.transport;
|
|
54
|
+
})(), { unsubscribe: w } = await s.subscribe({
|
|
55
|
+
params: ["newHeads"],
|
|
56
|
+
onData(c) {
|
|
57
|
+
var N;
|
|
58
|
+
if (!a)
|
|
59
|
+
return;
|
|
60
|
+
const u = h((N = c.result) == null ? void 0 : N.number);
|
|
61
|
+
e.onBlockNumber(u, r), r = u;
|
|
62
|
+
},
|
|
63
|
+
onError(c) {
|
|
64
|
+
var u;
|
|
65
|
+
(u = e.onError) == null || u.call(e, c);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
o = w, a || o();
|
|
69
|
+
} catch (s) {
|
|
70
|
+
n == null || n(s);
|
|
71
|
+
}
|
|
72
|
+
})(), () => o();
|
|
73
|
+
});
|
|
74
|
+
})();
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
j as watchBlockNumber
|
|
78
|
+
};
|
package/dist/index28.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("./index34.cjs"),r=require("./index38.cjs");function o(e,{size:n}){if(r.size(e)>n)throw new z.SizeOverflowError({givenSize:r.size(e),maxSize:n})}function s(e,n={}){const{signed:u}=n;n.size&&o(e,{size:n.size});const i=BigInt(e);if(!u)return i;const t=(e.length-2)/2,c=(1n<<BigInt(t)*8n-1n)-1n;return i<=c?i:i-BigInt(`0x${"f".padStart(t*2,"f")}`)-1n}function f(e,n={}){return Number(s(e,n))}exports.assertSize=o;exports.hexToBigInt=s;exports.hexToNumber=f;
|
package/dist/index28.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SizeOverflowError as u } from "./index34.js";
|
|
2
|
+
import { size as t } from "./index38.js";
|
|
3
|
+
function s(n, { size: i }) {
|
|
4
|
+
if (t(n) > i)
|
|
5
|
+
throw new u({
|
|
6
|
+
givenSize: t(n),
|
|
7
|
+
maxSize: i
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function z(n, i = {}) {
|
|
11
|
+
const { signed: o } = i;
|
|
12
|
+
i.size && s(n, { size: i.size });
|
|
13
|
+
const e = BigInt(n);
|
|
14
|
+
if (!o)
|
|
15
|
+
return e;
|
|
16
|
+
const r = (n.length - 2) / 2, f = (1n << BigInt(r) * 8n - 1n) - 1n;
|
|
17
|
+
return e <= f ? e : e - BigInt(`0x${"f".padStart(r * 2, "f")}`) - 1n;
|
|
18
|
+
}
|
|
19
|
+
function g(n, i = {}) {
|
|
20
|
+
return Number(z(n, i));
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
s as assertSize,
|
|
24
|
+
z as hexToBigInt,
|
|
25
|
+
g as hexToNumber
|
|
26
|
+
};
|
package/dist/index29.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(t,e,o){const i=t[e.name];if(typeof i=="function")return i;const n=t[o];return typeof n=="function"?n:c=>e(t,c)}exports.getAction=r;
|
package/dist/index29.js
ADDED
package/dist/index3.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=t=>t.startsWith("0x")?t:`0x${t}`,o=t=>`Bearer ${t}`,r=t=>new Promise(e=>setTimeout(e,t));exports.Authorization=o;exports.sleep=r;exports.with0x=i;
|
package/dist/index3.js
ADDED
package/dist/index30.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=new Map,i=new Map;let w=0;function M(e,l,C){const u=++w,n=()=>s.get(e)||[],y=()=>{const t=n();s.set(e,t.filter(o=>o.id!==u))},a=()=>{const t=i.get(e);n().length===1&&t&&t(),y()},c=n();if(s.set(e,[...c,{id:u,fns:l}]),c&&c.length>0)return a;const r={};for(const t in l)r[t]=(...o)=>{var h,p;const g=n();if(g.length!==0)for(const b of g)(p=(h=b.fns)[t])==null||p.call(h,...o)};const f=C(r);return typeof f=="function"&&i.set(e,f),a}exports.cleanupCache=i;exports.listenersCache=s;exports.observe=M;
|
package/dist/index30.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const o = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
2
|
+
let y = 0;
|
|
3
|
+
function M(t, i, w) {
|
|
4
|
+
const l = ++y, e = () => o.get(t) || [], C = () => {
|
|
5
|
+
const n = e();
|
|
6
|
+
o.set(t, n.filter((c) => c.id !== l));
|
|
7
|
+
}, f = () => {
|
|
8
|
+
const n = h.get(t);
|
|
9
|
+
e().length === 1 && n && n(), C();
|
|
10
|
+
}, s = e();
|
|
11
|
+
if (o.set(t, [
|
|
12
|
+
...s,
|
|
13
|
+
{ id: l, fns: i }
|
|
14
|
+
]), s && s.length > 0)
|
|
15
|
+
return f;
|
|
16
|
+
const u = {};
|
|
17
|
+
for (const n in i)
|
|
18
|
+
u[n] = (...c) => {
|
|
19
|
+
var p, g;
|
|
20
|
+
const r = e();
|
|
21
|
+
if (r.length !== 0)
|
|
22
|
+
for (const k of r)
|
|
23
|
+
(g = (p = k.fns)[n]) == null || g.call(p, ...c);
|
|
24
|
+
};
|
|
25
|
+
const a = w(u);
|
|
26
|
+
return typeof a == "function" && h.set(t, a), f;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
h as cleanupCache,
|
|
30
|
+
o as listenersCache,
|
|
31
|
+
M as observe
|
|
32
|
+
};
|
package/dist/index31.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index40.cjs");function s(o,{emitOnBegin:w,initialWaitTime:t,interval:c}){let e=!0;const a=()=>e=!1;return(async()=>{let n;w&&(n=await o({unpoll:a}));const r=await(t==null?void 0:t(n))??c;await u.wait(r);const l=async()=>{e&&(await o({unpoll:a}),await u.wait(c),l())};l()})(),a}exports.poll=s;
|
package/dist/index31.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { wait as l } from "./index40.js";
|
|
2
|
+
function f(o, { emitOnBegin: r, initialWaitTime: t, interval: c }) {
|
|
3
|
+
let n = !0;
|
|
4
|
+
const a = () => n = !1;
|
|
5
|
+
return (async () => {
|
|
6
|
+
let w;
|
|
7
|
+
r && (w = await o({ unpoll: a }));
|
|
8
|
+
const s = await (t == null ? void 0 : t(w)) ?? c;
|
|
9
|
+
await l(s);
|
|
10
|
+
const u = async () => {
|
|
11
|
+
n && (await o({ unpoll: a }), await l(c), u());
|
|
12
|
+
};
|
|
13
|
+
u();
|
|
14
|
+
})(), a;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
f as poll
|
|
18
|
+
};
|
package/dist/index32.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(e,n,i)=>JSON.stringify(e,(o,t)=>typeof t=="bigint"?t.toString():t,i);exports.stringify=r;
|
package/dist/index32.js
ADDED
package/dist/index33.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index40.cjs");function f(n,{delay:e=100,retryCount:o=2,shouldRetry:c=()=>!0}={}){return new Promise((s,y)=>{const a=async({count:r=0}={})=>{const w=async({error:t})=>{const i=typeof e=="function"?e({count:r,error:t}):e;i&&await u.wait(i),a({count:r+1})};try{const t=await n();s(t)}catch(t){if(r<o&&await c({count:r,error:t}))return w({error:t});y(t)}};a()})}exports.withRetry=f;
|
package/dist/index33.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { wait as w } from "./index40.js";
|
|
2
|
+
function p(n, { delay: e = 100, retryCount: o = 2, shouldRetry: c = () => !0 } = {}) {
|
|
3
|
+
return new Promise((s, y) => {
|
|
4
|
+
const a = async ({ count: r = 0 } = {}) => {
|
|
5
|
+
const f = async ({ error: t }) => {
|
|
6
|
+
const i = typeof e == "function" ? e({ count: r, error: t }) : e;
|
|
7
|
+
i && await w(i), a({ count: r + 1 });
|
|
8
|
+
};
|
|
9
|
+
try {
|
|
10
|
+
const t = await n();
|
|
11
|
+
s(t);
|
|
12
|
+
} catch (t) {
|
|
13
|
+
if (r < o && await c({ count: r, error: t }))
|
|
14
|
+
return f({ error: t });
|
|
15
|
+
y(t);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
a();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
p as withRetry
|
|
23
|
+
};
|
package/dist/index34.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index36.cjs");class i extends n.BaseError{constructor({max:e,min:r,signed:s,size:t,value:a}){super(`Number "${a}" is not in safe ${t?`${t*8}-bit ${s?"signed":"unsigned"} `:""}integer range ${e?`(${r} to ${e})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class u extends n.BaseError{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}exports.IntegerOutOfRangeError=i;exports.SizeOverflowError=u;
|
package/dist/index34.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError as t } from "./index36.js";
|
|
2
|
+
class $ extends t {
|
|
3
|
+
constructor({ max: e, min: r, signed: s, size: n, value: a }) {
|
|
4
|
+
super(`Number "${a}" is not in safe ${n ? `${n * 8}-bit ${s ? "signed" : "unsigned"} ` : ""}integer range ${e ? `(${r} to ${e})` : `(above ${r})`}`, { name: "IntegerOutOfRangeError" });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class c extends t {
|
|
8
|
+
constructor({ givenSize: e, maxSize: r }) {
|
|
9
|
+
super(`Size cannot exceed ${r} bytes. Given size: ${e} bytes.`, { name: "SizeOverflowError" });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
$ as IntegerOutOfRangeError,
|
|
14
|
+
c as SizeOverflowError
|
|
15
|
+
};
|
package/dist/index35.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index42.cjs");function p(e,{dir:n,size:t=32}={}){return typeof e=="string"?o(e,{dir:n,size:t}):l(e,{dir:n,size:t})}function o(e,{dir:n,size:t=32}={}){if(t===null)return e;const r=e.replace("0x","");if(r.length>t*2)throw new i.SizeExceedsPaddingSizeError({size:Math.ceil(r.length/2),targetSize:t,type:"hex"});return`0x${r[n==="right"?"padEnd":"padStart"](t*2,"0")}`}function l(e,{dir:n,size:t=32}={}){if(t===null)return e;if(e.length>t)throw new i.SizeExceedsPaddingSizeError({size:e.length,targetSize:t,type:"bytes"});const r=new Uint8Array(t);for(let a=0;a<t;a++){const d=n==="right";r[d?a:t-a-1]=e[d?a:e.length-a-1]}return r}exports.pad=p;exports.padBytes=l;exports.padHex=o;
|
package/dist/index35.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SizeExceedsPaddingSizeError as d } from "./index42.js";
|
|
2
|
+
function f(n, { dir: r, size: t = 32 } = {}) {
|
|
3
|
+
return typeof n == "string" ? p(n, { dir: r, size: t }) : i(n, { dir: r, size: t });
|
|
4
|
+
}
|
|
5
|
+
function p(n, { dir: r, size: t = 32 } = {}) {
|
|
6
|
+
if (t === null)
|
|
7
|
+
return n;
|
|
8
|
+
const e = n.replace("0x", "");
|
|
9
|
+
if (e.length > t * 2)
|
|
10
|
+
throw new d({
|
|
11
|
+
size: Math.ceil(e.length / 2),
|
|
12
|
+
targetSize: t,
|
|
13
|
+
type: "hex"
|
|
14
|
+
});
|
|
15
|
+
return `0x${e[r === "right" ? "padEnd" : "padStart"](t * 2, "0")}`;
|
|
16
|
+
}
|
|
17
|
+
function i(n, { dir: r, size: t = 32 } = {}) {
|
|
18
|
+
if (t === null)
|
|
19
|
+
return n;
|
|
20
|
+
if (n.length > t)
|
|
21
|
+
throw new d({
|
|
22
|
+
size: n.length,
|
|
23
|
+
targetSize: t,
|
|
24
|
+
type: "bytes"
|
|
25
|
+
});
|
|
26
|
+
const e = new Uint8Array(t);
|
|
27
|
+
for (let a = 0; a < t; a++) {
|
|
28
|
+
const o = r === "right";
|
|
29
|
+
e[o ? a : t - a - 1] = n[o ? a : n.length - a - 1];
|
|
30
|
+
}
|
|
31
|
+
return e;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
f as pad,
|
|
35
|
+
i as padBytes,
|
|
36
|
+
p as padHex
|
|
37
|
+
};
|
package/dist/index36.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./index37.cjs");let r={getDocsUrl:({docsBaseUrl:s,docsPath:t="",docsSlug:e})=>t?`${s??"https://viem.sh"}${t}${e?`#${e}`:""}`:void 0,version:l.version};class i extends Error{constructor(t,e={}){var o;const u=(()=>{var c;return e.cause instanceof i?e.cause.details:(c=e.cause)!=null&&c.message?e.cause.message:e.details})(),a=e.cause instanceof i&&e.cause.docsPath||e.docsPath,n=(o=r.getDocsUrl)==null?void 0:o.call(r,{...e,docsPath:a}),b=[t||"An error occurred.","",...e.metaMessages?[...e.metaMessages,""]:[],...n?[`Docs: ${n}`]:[],...u?[`Details: ${u}`]:[],`Version: ${r.version}`].join(`
|
|
2
|
+
`);super(b,e.cause?{cause:e.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=u,this.docsPath=a,this.metaMessages=e.metaMessages,this.name=e.name??this.name,this.shortMessage=t,this.version=l.version}walk(t){return d(this,t)}}function d(s,t){return t!=null&&t(s)?s:s&&typeof s=="object"&&"cause"in s?d(s.cause,t):t?null:s}exports.BaseError=i;
|
package/dist/index36.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { version as l } from "./index37.js";
|
|
2
|
+
let u = {
|
|
3
|
+
getDocsUrl: ({ docsBaseUrl: s, docsPath: t = "", docsSlug: e }) => t ? `${s ?? "https://viem.sh"}${t}${e ? `#${e}` : ""}` : void 0,
|
|
4
|
+
version: l
|
|
5
|
+
};
|
|
6
|
+
class r extends Error {
|
|
7
|
+
constructor(t, e = {}) {
|
|
8
|
+
var o;
|
|
9
|
+
const i = (() => {
|
|
10
|
+
var c;
|
|
11
|
+
return e.cause instanceof r ? e.cause.details : (c = e.cause) != null && c.message ? e.cause.message : e.details;
|
|
12
|
+
})(), a = e.cause instanceof r && e.cause.docsPath || e.docsPath, n = (o = u.getDocsUrl) == null ? void 0 : o.call(u, { ...e, docsPath: a }), b = [
|
|
13
|
+
t || "An error occurred.",
|
|
14
|
+
"",
|
|
15
|
+
...e.metaMessages ? [...e.metaMessages, ""] : [],
|
|
16
|
+
...n ? [`Docs: ${n}`] : [],
|
|
17
|
+
...i ? [`Details: ${i}`] : [],
|
|
18
|
+
`Version: ${u.version}`
|
|
19
|
+
].join(`
|
|
20
|
+
`);
|
|
21
|
+
super(b, e.cause ? { cause: e.cause } : void 0), Object.defineProperty(this, "details", {
|
|
22
|
+
enumerable: !0,
|
|
23
|
+
configurable: !0,
|
|
24
|
+
writable: !0,
|
|
25
|
+
value: void 0
|
|
26
|
+
}), Object.defineProperty(this, "docsPath", {
|
|
27
|
+
enumerable: !0,
|
|
28
|
+
configurable: !0,
|
|
29
|
+
writable: !0,
|
|
30
|
+
value: void 0
|
|
31
|
+
}), Object.defineProperty(this, "metaMessages", {
|
|
32
|
+
enumerable: !0,
|
|
33
|
+
configurable: !0,
|
|
34
|
+
writable: !0,
|
|
35
|
+
value: void 0
|
|
36
|
+
}), Object.defineProperty(this, "shortMessage", {
|
|
37
|
+
enumerable: !0,
|
|
38
|
+
configurable: !0,
|
|
39
|
+
writable: !0,
|
|
40
|
+
value: void 0
|
|
41
|
+
}), Object.defineProperty(this, "version", {
|
|
42
|
+
enumerable: !0,
|
|
43
|
+
configurable: !0,
|
|
44
|
+
writable: !0,
|
|
45
|
+
value: void 0
|
|
46
|
+
}), Object.defineProperty(this, "name", {
|
|
47
|
+
enumerable: !0,
|
|
48
|
+
configurable: !0,
|
|
49
|
+
writable: !0,
|
|
50
|
+
value: "BaseError"
|
|
51
|
+
}), this.details = i, this.docsPath = a, this.metaMessages = e.metaMessages, this.name = e.name ?? this.name, this.shortMessage = t, this.version = l;
|
|
52
|
+
}
|
|
53
|
+
walk(t) {
|
|
54
|
+
return d(this, t);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function d(s, t) {
|
|
58
|
+
return t != null && t(s) ? s : s && typeof s == "object" && "cause" in s ? d(s.cause, t) : t ? null : s;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
r as BaseError
|
|
62
|
+
};
|
package/dist/index37.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="2.21.18";exports.version=e;
|
package/dist/index37.js
ADDED
package/dist/index38.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index41.cjs");function i(e){return t.isHex(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}exports.size=i;
|
package/dist/index38.js
ADDED
package/dist/index39.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(n,{args:a,eventName:t}={}){return{...n,blockHash:n.blockHash?n.blockHash:null,blockNumber:n.blockNumber?BigInt(n.blockNumber):null,logIndex:n.logIndex?Number(n.logIndex):null,transactionHash:n.transactionHash?n.transactionHash:null,transactionIndex:n.transactionIndex?Number(n.transactionIndex):null,...t?{args:a,eventName:t}:{}}}exports.formatLog=r;
|
package/dist/index39.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function r(n, { args: t, eventName: a } = {}) {
|
|
2
|
+
return {
|
|
3
|
+
...n,
|
|
4
|
+
blockHash: n.blockHash ? n.blockHash : null,
|
|
5
|
+
blockNumber: n.blockNumber ? BigInt(n.blockNumber) : null,
|
|
6
|
+
logIndex: n.logIndex ? Number(n.logIndex) : null,
|
|
7
|
+
transactionHash: n.transactionHash ? n.transactionHash : null,
|
|
8
|
+
transactionIndex: n.transactionIndex ? Number(n.transactionIndex) : null,
|
|
9
|
+
...a ? { args: t, eventName: a } : {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
r as formatLog
|
|
14
|
+
};
|
package/dist/index4.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Err as o, Ok as s } from "@catalogfi/utils";
|
|
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
|
+
const y = async (p, u, a, r) => {
|
|
6
|
+
if (!r.account) return o("No account found");
|
|
7
|
+
const n = d({
|
|
8
|
+
address: t(u),
|
|
9
|
+
abi: f,
|
|
10
|
+
client: r
|
|
11
|
+
}), e = await r.getAddresses();
|
|
12
|
+
if (!e[0]) return o("No account found");
|
|
13
|
+
try {
|
|
14
|
+
const c = await n.read.allowance([
|
|
15
|
+
t(e[0]),
|
|
16
|
+
t(a)
|
|
17
|
+
]);
|
|
18
|
+
if (BigInt(c) < BigInt(p)) {
|
|
19
|
+
const i = await n.write.approve(
|
|
20
|
+
[t(a), m],
|
|
21
|
+
{
|
|
22
|
+
account: r.account,
|
|
23
|
+
chain: r.chain
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
return (await h(r, {
|
|
27
|
+
hash: i
|
|
28
|
+
})).status !== "success" ? o("Failed to approve") : s(i);
|
|
29
|
+
}
|
|
30
|
+
return s("Already approved");
|
|
31
|
+
} catch (c) {
|
|
32
|
+
return o("Failed to approve: " + c);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
y as checkAllowanceAndApprove
|
|
37
|
+
};
|
package/dist/index40.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function i(e){return new Promise(t=>setTimeout(t,e))}exports.wait=i;
|
package/dist/index40.js
ADDED
package/dist/index41.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}exports.isHex=r;
|
package/dist/index41.js
ADDED
package/dist/index42.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index36.cjs");class d extends i.BaseError{constructor({size:r,targetSize:s,type:e}){super(`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()} size (${r}) exceeds padding size (${s}).`,{name:"SizeExceedsPaddingSizeError"})}}exports.SizeExceedsPaddingSizeError=d;
|
package/dist/index42.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseError as i } from "./index36.js";
|
|
2
|
+
class a extends i {
|
|
3
|
+
constructor({ size: r, targetSize: s, type: e }) {
|
|
4
|
+
super(`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()} size (${r}) exceeds padding size (${s}).`, { name: "SizeExceedsPaddingSizeError" });
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
a as SizeExceedsPaddingSizeError
|
|
9
|
+
};
|
package/dist/index5.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index11.cjs"),t=require("@catalogfi/utils"),c=require("./index12.cjs"),u=require("./index13.cjs"),d=require("./index14.cjs"),a={ethereum:c.mainnet,ethereum_arbitrum:u.arbitrum,ethereum_sepolia:d.sepolia,ethereum_localnet:n.EthereumLocalnet,arbitrum_localnet:n.ArbitrumLocalnet},s=async(e,i)=>{const r=a[e];if(r)try{return await i.switchChain({id:r.id}),t.Ok("Switched chain")}catch(o){if(h(o))try{return await i.addChain({chain:r}),t.Ok("Added and switched chain")}catch{return t.Err("Failed to add network")}else return t.Err("Failed to switch network")}else return t.Err("Chain not supported")},h=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.ChainToID=a;exports.switchOrAddNetwork=s;
|
package/dist/index5.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EthereumLocalnet as n, ArbitrumLocalnet as c } from "./index11.js";
|
|
2
|
+
import { Ok as o, Err as e } from "@catalogfi/utils";
|
|
3
|
+
import { mainnet as d } from "./index12.js";
|
|
4
|
+
import { arbitrum as h } from "./index13.js";
|
|
5
|
+
import { sepolia as m } from "./index14.js";
|
|
6
|
+
const s = {
|
|
7
|
+
ethereum: d,
|
|
8
|
+
ethereum_arbitrum: h,
|
|
9
|
+
ethereum_sepolia: m,
|
|
10
|
+
ethereum_localnet: n,
|
|
11
|
+
arbitrum_localnet: c
|
|
12
|
+
}, y = async (t, i) => {
|
|
13
|
+
const r = s[t];
|
|
14
|
+
if (r)
|
|
15
|
+
try {
|
|
16
|
+
return await i.switchChain({ id: r.id }), o("Switched chain");
|
|
17
|
+
} catch (a) {
|
|
18
|
+
if (u(a))
|
|
19
|
+
try {
|
|
20
|
+
return await i.addChain({ chain: r }), o("Added and switched chain");
|
|
21
|
+
} catch {
|
|
22
|
+
return e("Failed to add network");
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
return e("Failed to switch network");
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
return e("Chain not supported");
|
|
29
|
+
}, u = (t) => typeof t == "object" && t !== null && "code" in t && t.code === 4902;
|
|
30
|
+
export {
|
|
31
|
+
s as ChainToID,
|
|
32
|
+
y as switchOrAddNetwork
|
|
33
|
+
};
|
package/dist/index6.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r extends URL{constructor(t,e){super(t,e)}endpoint(t){t.startsWith("/")||(t=`/${t}`);const e=`${this.pathname!=="/"?this.pathname:""}${t}`;return new r(e,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}}exports.Url=r;
|
package/dist/index6.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class r extends URL {
|
|
2
|
+
constructor(t, s) {
|
|
3
|
+
super(t, s);
|
|
4
|
+
}
|
|
5
|
+
endpoint(t) {
|
|
6
|
+
t.startsWith("/") || (t = `/${t}`);
|
|
7
|
+
const s = `${this.pathname !== "/" ? this.pathname : ""}${t}`;
|
|
8
|
+
return new r(s, this);
|
|
9
|
+
}
|
|
10
|
+
socket() {
|
|
11
|
+
if (this.protocol === "https:")
|
|
12
|
+
return this.origin.replace("https", "wss");
|
|
13
|
+
if (this.protocol === "http:")
|
|
14
|
+
return this.origin.replace("http", "ws");
|
|
15
|
+
throw new Error("Invalid protocol");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
r as Url
|
|
20
|
+
};
|
package/dist/index7.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("siwe"),t=require("@catalogfi/utils"),w=require("./index8.cjs"),d=require("./index9.cjs"),m=require("./index6.cjs");class y{constructor(r,i,e){this.API="https://api.garden.finance",this.url=new m.Url("/",r??this.API),this.walletClient=i,this.domain=(e==null?void 0:e.domain)||"app.garden.finance",this.domain.startsWith("https://")&&(this.domain=this.domain.split("https://")[1]),this.signingStatement=(e==null?void 0:e.signingStatement)??"Garden.fi",this.store=(e==null?void 0:e.store)??new w.MemoryStorage}verifyToken(r,i){const e=S(r);if(!e)return t.Ok(!1);try{const n=Math.floor(Date.now()/1e3)+120;return t.Ok(e.exp>n&&e.address.toLowerCase()===i.toLowerCase())}catch{return t.Ok(!1)}}async getToken(){var o;if(!((o=this.walletClient.account)!=null&&o.address))return t.Err("Wallet client does not have an account");const r=this.store.getItem(d.StoreKeys.AUTH_TOKEN);if(r){const s=this.verifyToken(r,this.walletClient.account.address);if(s.ok&&s.val)return t.Ok(r)}const i=await this.signStatement();if(i.error)return t.Err(i.error);const e=await t.Fetcher.post(this.url.endpoint("verify"),{body:JSON.stringify({...i.val}),headers:{"Content-Type":"application/json"}});if(e.error)return t.Err(e.error);const n=e.result;if(!n)return t.Err("Failed to get token");if(!this.verifyToken(n,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(d.StoreKeys.AUTH_TOKEN,n),t.Ok(n)}async signStatement(){var l,h,u;if(!((l=this.walletClient.chain)!=null&&l.id)||!((h=this.walletClient.account)!=null&&h.address))return t.Err("Wallet client does not have a chain");const r=new Date,i=new Date(r.getTime()+300*1e3),n=(await t.Fetcher.get(this.url.endpoint("nonce"))).result;if(!n)return t.Err("Failed to get nonce");const c=(u=this.walletClient.chain)==null?void 0:u.id,s=new g.SiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:n,uri:"https://"+this.domain,version:"1",chainId:c,expirationTime:i.toISOString()}).prepareMessage(),f=await this.walletClient.signMessage({account:this.walletClient.account,message:s});return t.Ok({message:s,signature:f,nonce:n})}}const S=a=>{try{if(a.split(".").length<3)return;const r=a.split(".")[1];return r?JSON.parse(Buffer.from(r,"base64").toString("latin1")):void 0}catch{return}};exports.Siwe=y;
|