From de26e8902e9de9ce145f67954de6f3fa657d6434 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 7 Sep 2022 15:26:01 +0000 Subject: [PATCH] chore(release): tulipe 1.11.0 [skip ci] --- CHANGELOG.md | 9 + ...{index.f0d1c9b1.mjs => index.7fcc06b4.mjs} | 0 dist/tulipe.es.js | 525 +++++++++--------- dist/tulipe.min.js | 2 +- dist/tulipe.umd.js | 2 +- package-lock.json | 4 +- package.json | 2 +- 7 files changed, 291 insertions(+), 253 deletions(-) rename dist/{index.f0d1c9b1.mjs => index.7fcc06b4.mjs} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6d05f9b..3a5245a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# [1.11.0](https://github.com/0Lilian/tulipe/compare/v1.10.0...v1.11.0) (2022-09-07) + + +### Features + +* a change watcher system to proxies ([879f850](https://github.com/0Lilian/tulipe/commit/879f85041d14c60c28bc215d18151544ee399c04)) +* adapt contract related classes to new ARS and proxies design ([c96a7de](https://github.com/0Lilian/tulipe/commit/c96a7de3ee4390c1179c4cd8a3dd0e4aa80e2c32)) +* re-enable in the new ARS classes auto-purging and auto-init on ethersInstance change ([2e2abb8](https://github.com/0Lilian/tulipe/commit/2e2abb8c65c03f43de9b58c4603e0eaa4e3c0214)) + # [1.10.0](https://github.com/0Lilian/tulipe/compare/v1.9.0...v1.10.0) (2022-09-07) diff --git a/dist/index.f0d1c9b1.mjs b/dist/index.7fcc06b4.mjs similarity index 100% rename from dist/index.f0d1c9b1.mjs rename to dist/index.7fcc06b4.mjs diff --git a/dist/tulipe.es.js b/dist/tulipe.es.js index 1e146b56..37799563 100644 --- a/dist/tulipe.es.js +++ b/dist/tulipe.es.js @@ -1,5 +1,5 @@ -import { isRef as $, ref as y, resolveComponent as R, openBlock as l, createBlock as I, withCtx as C, createElementVNode as c, toDisplayString as f, unref as i, createVNode as O, createTextVNode as P, createElementBlock as u, Fragment as w, renderList as g, shallowRef as nt, withDirectives as B, vModelText as V, createCommentVNode as E, computed as A, normalizeClass as at, renderSlot as v, pushScopeId as rt, popScopeId as it, vModelSelect as ot, watch as S, markRaw as ct, getCurrentInstance as x, onUnmounted as U } from "vue"; -import { ethers as _ } from "ethers"; +import { isRef as $, ref as y, resolveComponent as R, openBlock as l, createBlock as I, withCtx as C, createElementVNode as c, toDisplayString as f, unref as i, createVNode as x, createTextVNode as P, createElementBlock as u, Fragment as w, renderList as g, shallowRef as nt, withDirectives as B, vModelText as L, createCommentVNode as E, computed as A, normalizeClass as at, renderSlot as v, pushScopeId as rt, popScopeId as it, vModelSelect as ot, watch as S, markRaw as ct, getCurrentInstance as N, onUnmounted as U } from "vue"; +import { ethers as m } from "ethers"; class lt { constructor() { const t = a.config.wallets.getAvailable(); @@ -11,19 +11,25 @@ class lt { } class ut { constructor() { + } + init() { for (const t of a.config.networks.getAll()) if (t.contracts) for (const [e, s] of Object.entries(t.contracts)) - ; + this.add(e, s.address, s.abi); + } + add(t, e, s) { + const n = new m.Contract(e, s); + a._ars.contracts.add(t), this[t] = new j(t, n), a._ars.contracts[t].start(); } getAll() { const t = {}; for (const [e, s] of Object.entries(this)) - s instanceof G && (t[e] = s); + s instanceof j && (t[e] = s); return t; } } -class dt { +class ht { constructor() { this.contracts = {}, this.wallets = {}; } @@ -37,26 +43,26 @@ class dt { }); } addContractWatcher(t) { - Object.keys(this.contracts).includes(t.address) || (this.contracts[t.address] = new Me(t)); + Object.keys(this.contracts).includes(t.address) || (this.contracts[t.address] = new Ve(t)); } removeContractWatcher(t) { Object.keys(this.contracts).includes(t.address) && delete this.contracts[t.address]; } addWalletWatcher(t) { - Object.keys(this.wallets).includes(t) || (this.wallets[t] = new Ve(t)); + Object.keys(this.wallets).includes(t) || (this.wallets[t] = new Me(t)); } removeContractWatcher(t) { Object.keys(this.wallets).includes(t) && delete this.wallets[t]; } } -class ht { +class dt { constructor() { } init(t = null) { - this.config = new Oe(t), this._ars = new Ze(), this.status = this._ars.dapp.status, this.isSafe = this._ars.dapp.isSafe, this.OnSafe = this._ars.dapp.OnSafe, this.onSafe = this._ars.dapp.onSafe, this.chainWatchers = new dt(), this.wallets = new lt(), this.contracts = new ut(), this.provider = new L(), this._ars.provider.init(), this.signer = new q(), this._ars.signer.init(), this.pro = this.provider, this.sig = this.signer, this.con = this.contracts; + this.config = new xe(t), this._ars = new Ze(), this.status = this._ars.dapp.status, this.isSafe = this._ars.dapp.isSafe, this.OnSafe = this._ars.dapp.OnSafe, this.onSafe = this._ars.dapp.onSafe, this.chainWatchers = new ht(), this.wallets = new lt(), this.provider = new q(), this._ars.provider.start(), this.signer = new G(), this._ars.signer.start(), this.contracts = new ut(), this.contracts.init(), this.pro = this.provider, this.sig = this.signer, this.con = this.contracts; } } -const a = new ht(); +const a = new dt(); function M(r) { return r && typeof r == "object" && !Array.isArray(r); } @@ -109,8 +115,8 @@ const ft = { } catch { } }), (n, o) => { - const d = R("OnContractReadSafe"); - return l(), I(d, { + const h = R("OnContractReadSafe"); + return l(), I(h, { contract: t.contract }, { default: C(() => [ @@ -121,14 +127,14 @@ const ft = { c("li", null, [ _t, yt, - O(i(gt), { + x(i(gt), { contract: t.contract }, null, 8, ["contract"]) ]), c("li", null, [ vt, wt, - O(i($t), { + x(i($t), { contract: t.contract }, null, 8, ["contract"]) ]) @@ -157,10 +163,10 @@ const ft = { default: C(() => [ c("div", St, [ c("ul", null, [ - (l(!0), u(w, null, g(i(e).interface.functions, (d, h) => (l(), u("li", null, [ - O(i(At), { + (l(!0), u(w, null, g(i(e).interface.functions, (h, d) => (l(), u("li", null, [ + x(i(At), { contract: t.contract, - method: h + method: d }, null, 8, ["contract", "method"]) ]))), 256)) ]) @@ -170,7 +176,7 @@ const ft = { }, 8, ["contract"]); }; } -}, It = { class: "MethodInteractor" }, Ct = { key: 0 }, Et = /* @__PURE__ */ c("p", null, "Inputs :", -1), Rt = ["onUpdate:modelValue", "placeholder"], bt = { key: 0 }, kt = { key: 1 }, Ot = /* @__PURE__ */ c("p", null, "Outputs :", -1), Nt = ["onUpdate:modelValue", "placeholder"], xt = ["placeholder"], Pt = { key: 2 }, At = { +}, It = { class: "MethodInteractor" }, Ct = { key: 0 }, Et = /* @__PURE__ */ c("p", null, "Inputs :", -1), Rt = ["onUpdate:modelValue", "placeholder"], bt = { key: 0 }, kt = { key: 1 }, xt = /* @__PURE__ */ c("p", null, "Outputs :", -1), Ot = ["onUpdate:modelValue", "placeholder"], Nt = ["placeholder"], Pt = { key: 2 }, At = { __name: "MethodInteractor", props: { contract: { @@ -183,65 +189,65 @@ const ft = { } }, setup(r) { - const t = r, e = nt(new J(t.contract, t.method)); + const t = r, e = nt(new Y(t.contract, t.method)); function s(n) { return `${n.name && n.name !== "null" ? n.name : ""} (${n.type})`; } return (n, o) => { - const d = R("OnContractReadSafe"); - return l(), I(d, { + const h = R("OnContractReadSafe"); + return l(), I(h, { contract: t.contract }, { default: C(() => [ c("div", It, [ - O(i(qt), { + x(i(qt), { contract: t.contract, method: t.method, modelValue: i(e), - "onUpdate:modelValue": o[0] || (o[0] = (h) => $(e) ? e.value = h : null), + "onUpdate:modelValue": o[0] || (o[0] = (d) => $(e) ? e.value = d : null), configs: { content: t.method, notx: !0, noerror: !0 } }, null, 8, ["contract", "method", "modelValue", "configs"]), c("small", null, f(i(e).methodInfos.stateMutability), 1), Object.keys(i(e).methodInfos.inputs).length > 0 || i(e).methodInfos.payable ? (l(), u("div", Ct, [ Et, c("ul", null, [ - (l(!0), u(w, null, g(i(e).methodInfos.inputs, (h, p) => (l(), u("li", null, [ + (l(!0), u(w, null, g(i(e).methodInfos.inputs, (d, p) => (l(), u("li", null, [ B(c("input", { - "onUpdate:modelValue": (m) => i(e).args.value[p] = m, + "onUpdate:modelValue": (_) => i(e).args.value[p] = _, type: "text", - placeholder: s(h) + placeholder: s(d) }, null, 8, Rt), [ - [V, i(e).args.value[p]] + [L, i(e).args.value[p]] ]), P(" " + f(i(e).args.value[p]) + " " + f(typeof i(e).args.value[p]), 1) ]))), 256)), i(e).methodInfos.payable ? (l(), u("li", bt, [ - O(i(Ce), { + x(i(Ce), { modelValue: i(e).txArgs.value.value, - "onUpdate:modelValue": o[1] || (o[1] = (h) => i(e).txArgs.value.value = h) + "onUpdate:modelValue": o[1] || (o[1] = (d) => i(e).txArgs.value.value = d) }, null, 8, ["modelValue"]), P(" " + f(i(e).txArgs.value.value) + " " + f(typeof i(e).txArgs.value.value), 1) ])) : E("", !0) ]) ])) : E("", !0), Object.keys(i(e).methodInfos.outputs).length > 0 ? (l(), u("div", kt, [ - Ot, + xt, c("ul", null, [ - (l(!0), u(w, null, g(i(e).methodInfos.outputs, (h, p) => (l(), u("li", null, [ + (l(!0), u(w, null, g(i(e).methodInfos.outputs, (d, p) => (l(), u("li", null, [ i(e).data.value ? B((l(), u("input", { key: 0, - "onUpdate:modelValue": (m) => i(e).data.value[p] = m, + "onUpdate:modelValue": (_) => i(e).data.value[p] = _, type: "text", - placeholder: s(h), + placeholder: s(d), disabled: "" - }, null, 8, Nt)), [ - [V, i(e).data.value[p]] + }, null, 8, Ot)), [ + [L, i(e).data.value[p]] ]) : (l(), u("input", { key: 1, type: "text", - placeholder: s(h), + placeholder: s(d), disabled: "" - }, null, 8, xt)) + }, null, 8, Nt)) ]))), 256)) ]) ])) : E("", !0), @@ -270,10 +276,10 @@ const ft = { default: C(() => [ c("div", Wt, [ c("ul", null, [ - (l(!0), u(w, null, g(i(e).interface.events, (d, h) => (l(), u("li", null, [ - O(i(Ut), { + (l(!0), u(w, null, g(i(e).interface.events, (h, d) => (l(), u("li", null, [ + x(i(Ut), { contract: t.contract, - event: h + event: d }, null, 8, ["contract", "event"]) ]))), 256)) ]) @@ -297,18 +303,18 @@ const ft = { }, setup(r) { const t = r, e = a.contracts[t.contract]; - let s = y({}), n = y({}), o = y(0), d = y([]); + let s = y({}), n = y({}), o = y(0), h = y([]); return e.onReadSafe(() => { - s.value = e.interface.events[t.event], n.value = e.filters[s.value.name], e.on(n.value, (h) => { + s.value = e.interface.events[t.event], n.value = e.filters[s.value.name], e.on(n.value, (d) => { o.value++; - let p = `Block ${h.blockNumber} -> {`; - for (const m of s.value.inputs) - p += `${m.name}:${h.args[m.name]}, `; - p = p.substring(0, p.length - 2) + "}", d.value.push(p); + let p = `Block ${d.blockNumber} -> {`; + for (const _ of s.value.inputs) + p += `${_.name}:${d.args[_.name]}, `; + p = p.substring(0, p.length - 2) + "}", h.value.push(p); }); - }), (h, p) => { - const m = R("OnContractReadSafe"); - return l(), I(m, { + }), (d, p) => { + const _ = R("OnContractReadSafe"); + return l(), I(_, { contract: t.contract }, { default: C(() => [ @@ -319,7 +325,7 @@ const ft = { c("li", null, [ Tt, c("ul", null, [ - (l(!0), u(w, null, g(i(d), (H) => (l(), u("li", null, f(H), 1))), 256)) + (l(!0), u(w, null, g(i(h), (z) => (l(), u("li", null, f(z), 1))), 256)) ]) ]) ]) @@ -332,10 +338,10 @@ const ft = { }, Bt = { class: "TransactButton" }, jt = { key: 1, disabled: "" -}, Mt = { +}, Vt = { key: 2, disabled: "" -}, Vt = { +}, Mt = { key: 3, disabled: "" }, Lt = { key: 4 }, qt = { @@ -370,17 +376,17 @@ const ft = { get() { return e.modelValue; }, - set(d) { - t("update:modelValue", d); + set(h) { + t("update:modelValue", h); } }); function o() { - const d = e.args ? e.args : [], h = e.txArgs ? e.txArgs : {}; - n.value.send(d, h); + const h = e.args ? e.args : [], d = e.txArgs ? e.txArgs : {}; + n.value.send(h, d); } return e.config && e.configs.notx && s.onReadSafe(() => { - n = new J(e.contract, e.method); - }), (d, h) => { + n = new Y(e.contract, e.method); + }), (h, d) => { const p = R("OnContractReadSafe"); return l(), I(p, { contract: e.contract @@ -390,7 +396,7 @@ const ft = { i(n).status.is("READY") ? (l(), u("button", { key: 0, onClick: o - }, f(e.configs && e.configs.content ? e.configs.content : "Transact"), 1)) : i(n).status.is("SENT") ? (l(), u("button", jt, "Transaction sent...")) : i(n).status.is("ERROR") ? (l(), u("button", Mt, "Transaction error!")) : i(n).status.is("SUCCESS") ? (l(), u("button", Vt, "Success !")) : E("", !0), + }, f(e.configs && e.configs.content ? e.configs.content : "Transact"), 1)) : i(n).status.is("SENT") ? (l(), u("button", jt, "Transaction sent...")) : i(n).status.is("ERROR") ? (l(), u("button", Vt, "Transaction error!")) : i(n).status.is("SUCCESS") ? (l(), u("button", Mt, "Success !")) : E("", !0), !(e.configs && e.configs.noerror) && i(n).status.is("ERROR") ? (l(), u("p", Lt, f(i(n).error.value.reason), 1)) : E("", !0) ]) ]), @@ -399,7 +405,7 @@ const ft = { }; } }; -const z = (r, t) => { +const K = (r, t) => { const e = r.__vccOpts || r; for (const [s, n] of t) e[s] = n; @@ -420,7 +426,7 @@ const z = (r, t) => { _: 1 })); } -}, es = /* @__PURE__ */ z(Gt, [["__scopeId", "data-v-a10b4efb"]]), Ft = { class: "SelectWalletDropdown" }, Ht = { key: 0 }, zt = /* @__PURE__ */ c("p", null, "Connection requested...", -1), Kt = [ +}, es = /* @__PURE__ */ K(Gt, [["__scopeId", "data-v-a10b4efb"]]), Ft = { class: "SelectWalletDropdown" }, Ht = { key: 0 }, zt = /* @__PURE__ */ c("p", null, "Connection requested...", -1), Kt = [ zt ], Jt = { key: 1 }, Yt = /* @__PURE__ */ c("p", null, "Connection refused!", -1), Zt = [ Yt @@ -435,12 +441,12 @@ const z = (r, t) => { }), a.provider.onSafe(async function() { n.value = await a.config.networks.getCurrent(); }), a.signer.onSafe(async function() { - t.value = await a.config.wallets.getCurrent(), e.value = a.config.wallets.getAvailable().filter((d) => d.id !== t.value.id); + t.value = await a.config.wallets.getCurrent(), e.value = a.config.wallets.getAvailable().filter((h) => h.id !== t.value.id); }); function o() { s.value = !s.value; } - return (d, h) => { + return (h, d) => { const p = R("OnDappSafe"); return l(), I(p, null, { default: C(() => [ @@ -462,16 +468,16 @@ const z = (r, t) => { }, null, 8, ee), c("p", null, f(i(t).displayName), 1) ])) : E("", !0), - i(s) ? (l(!0), u(w, { key: 5 }, g(i(e), (m) => (l(), u("li", { - key: m.id, - onClick: (H) => i(a).signer.connectWallet(m.id) + i(s) ? (l(!0), u(w, { key: 5 }, g(i(e), (_) => (l(), u("li", { + key: _.id, + onClick: (z) => i(a).signer.connectWallet(_.id) }, [ c("img", { width: "40", - src: m.icon ? m.icon : i(a).config.defaults.wallets.icon, - alt: m.displayName + " logo" + src: _.icon ? _.icon : i(a).config.defaults.wallets.icon, + alt: _.displayName + " logo" }, null, 8, ne), - c("p", null, f(m.displayName), 1) + c("p", null, f(_.displayName), 1) ], 8, se))), 128)) : E("", !0) ]) ]) @@ -482,7 +488,7 @@ const z = (r, t) => { } }, ae = { class: "SelectNetworkDropdown" }, re = { key: 0 }, ie = ["src", "alt"], oe = { key: 1 }, ce = /* @__PURE__ */ c("p", null, "Select a network", -1), le = [ ce -], ue = ["onClick"], de = ["src", "alt"], ns = { +], ue = ["onClick"], he = ["src", "alt"], ns = { __name: "SelectNetworkDropdown", setup(r) { let t = y({}), e = y([]), s = y(!1); @@ -494,9 +500,9 @@ const z = (r, t) => { function n() { s.value = !s.value; } - return (o, d) => { - const h = R("OnDappSafe"); - return l(), I(h, null, { + return (o, h) => { + const d = R("OnDappSafe"); + return l(), I(d, null, { default: C(() => [ c("div", ae, [ c("ul", { onClick: n }, [ @@ -510,13 +516,13 @@ const z = (r, t) => { ])) : (l(), u("li", oe, le)), i(s) ? (l(!0), u(w, { key: 2 }, g(i(e), (p) => (l(), u("li", { key: p.id, - onClick: (m) => i(a).provider.changeNetwork(p.id) + onClick: (_) => i(a).provider.changeNetwork(p.id) }, [ c("img", { width: "40", src: p.icon ? p.icon : i(a).config.defaults.networks.icon, alt: p.displayName + " logo" - }, null, 8, de), + }, null, 8, he), c("p", null, f(p.displayName), 1) ], 8, ue))), 128)) : E("", !0) ]) @@ -526,7 +532,7 @@ const z = (r, t) => { }); }; } -}, he = { +}, de = { __name: "OnDappSafe", setup(r) { return (t, e) => i(a).isSafe.value ? (l(), u(w, { key: 0 }, [ @@ -581,7 +587,7 @@ const z = (r, t) => { ], 64)) : v(e.$slots, "unsafe", { key: 1 }); } }; -const K = (r) => (rt("data-v-a24ac687"), r = r(), it(), r), ye = /* @__PURE__ */ K(() => /* @__PURE__ */ c("h3", null, "Safe Runners", -1)), ve = /* @__PURE__ */ K(() => /* @__PURE__ */ c("h3", null, "Status", -1)), we = { +const J = (r) => (rt("data-v-a24ac687"), r = r(), it(), r), ye = /* @__PURE__ */ J(() => /* @__PURE__ */ c("h3", null, "Safe Runners", -1)), ve = /* @__PURE__ */ J(() => /* @__PURE__ */ c("h3", null, "Status", -1)), we = { __name: "DebugBar", setup(r) { return (t, e) => { @@ -619,7 +625,7 @@ const K = (r) => (rt("data-v-a24ac687"), r = r(), it(), r), ye = /* @__PURE__ */ }); }; } -}, as = /* @__PURE__ */ z(we, [["__scopeId", "data-v-a24ac687"]]), Se = { class: "InputUnits" }, ge = ["placeholder"], Ie = ["value"], Ce = { +}, as = /* @__PURE__ */ K(we, [["__scopeId", "data-v-a24ac687"]]), Se = { class: "InputUnits" }, ge = ["placeholder"], Ie = ["value"], Ce = { __name: "InputUnits", props: { modelValue: {}, @@ -633,26 +639,26 @@ const K = (r) => (rt("data-v-a24ac687"), r = r(), it(), r), ye = /* @__PURE__ */ let s = y(null); const n = ["wei", "gwei", "ether"]; let o = y("wei"); - function d() { + function h() { if (s.value) { - const h = _.utils.parseUnits(s.value, o.value); - t("update:modelValue", h); + const d = m.utils.parseUnits(s.value, o.value); + t("update:modelValue", d); } } - return (h, p) => (l(), u("div", Se, [ + return (d, p) => (l(), u("div", Se, [ B(c("input", { - onInput: d, - "onUpdate:modelValue": p[0] || (p[0] = (m) => $(s) ? s.value = m : s = m), + onInput: h, + "onUpdate:modelValue": p[0] || (p[0] = (_) => $(s) ? s.value = _ : s = _), type: "text", placeholder: i(e).placeholder }, null, 40, ge), [ - [V, i(s)] + [L, i(s)] ]), B(c("select", { - onChange: d, - "onUpdate:modelValue": p[1] || (p[1] = (m) => $(o) ? o.value = m : o = m) + onChange: h, + "onUpdate:modelValue": p[1] || (p[1] = (_) => $(o) ? o.value = _ : o = _) }, [ - (l(), u(w, null, g(n, (m) => c("option", { value: m }, f(m), 9, Ie)), 64)) + (l(), u(w, null, g(n, (_) => c("option", { value: _ }, f(_), 9, Ie)), 64)) ], 544), [ [ot, i(o)] ]) @@ -723,7 +729,7 @@ class T { return this.watch(this.states, t); } } -const N = { +const O = { style: { level: "minimal" }, @@ -1207,7 +1213,7 @@ const N = { class Ee { constructor(t = null) { let e = {}; - return t ? e = W({ ...N.style }, { ...t }) : e = N.style, window.addEventListener("load", () => { + return t ? e = W({ ...O.style }, { ...t }) : e = O.style, window.addEventListener("load", () => { const s = document.getElementsByClassName("ve-app"); if (s) for (const n of s) @@ -1220,11 +1226,11 @@ class Re { if (this._list = [], t) { for (const e of t) if (e.id) { - const s = N.networks.find((o) => o.id === e.id), n = W({ ...s }, { ...e }); + const s = O.networks.find((o) => o.id === e.id), n = W({ ...s }, { ...e }); n.available !== !1 && (n.available = !0), n.displayName || (n.displayName = n.name), this._list.push(n); } } - for (const e of N.networks) + for (const e of O.networks) this._list.find((n) => n.id === e.id) || (e.available = !1, this._list.push(e)); } add(t) { @@ -1260,11 +1266,11 @@ class be { if (this._list = [], t) { for (const e of t) if (e.id) { - const s = N.wallets.find((o) => o.id === e.id), n = W({ ...s }, { ...e }); + const s = O.wallets.find((o) => o.id === e.id), n = W({ ...s }, { ...e }); n.available !== !1 && (n.available = !0), n.displayName || (n.displayName = n.id), this._list.push(n); } } - for (const e of N.wallets) + for (const e of O.wallets) this._list.find((n) => n.id === e.id) || (e.available = !1, this._list.push(e)); } getCurrent() { @@ -1286,47 +1292,56 @@ class be { class ke { constructor(t = null) { let e = {}; - return t ? e = W({ ...N.defaults }, { ...t }) : e = N.defaults, e; + return t ? e = W({ ...O.defaults }, { ...t }) : e = O.defaults, e; } } -class Oe { +class xe { constructor(t = null) { this.style = new Ee(t ? t.style : null), this.networks = new Re(t ? t.networks : null), this.wallets = new be(t ? t.wallets : null), this.defaults = new ke(t ? t.defaults : null); } } -class j { +class V { constructor(t = null, e = null) { + console.log("TulipeProxy super"); const s = new Proxy(this, { - get: function(n, o, d) { + get: function(n, o, h) { if (n.proxy.ethersInstance && n.proxy.ethersInstance[o] !== void 0) return typeof n.proxy.ethersInstance[o] == "function" ? n.proxy.ethersInstance[o].bind(n.proxy.ethersInstance) : n.proxy.ethersInstance[o]; if (n.proxy.ethersInstance && n.proxy.extensionInstance && n.proxy.extensionInstance[o] !== void 0) - return typeof n.proxy.extensionInstance[o] == "function" ? n.proxy.extensionInstance[o].bind(d) : n.proxy.extensionInstance[o]; + return typeof n.proxy.extensionInstance[o] == "function" ? n.proxy.extensionInstance[o].bind(h) : n.proxy.extensionInstance[o]; if (n && n[o] !== void 0) - return typeof n[o] == "function" ? n[o].bind(d) : n[o]; + return typeof n[o] == "function" ? n[o].bind(h) : n[o]; }, - set: function(n, o, d, h) { - return n.proxy.ethersInstance && n.proxy.ethersInstance[o] !== void 0 ? (n.proxy.ethersInstance[o] = d, !0) : n.proxy.extensionInstance && n.proxy.extensionInstance[o] !== void 0 ? (n.proxy.extensionInstance[o] = d, !0) : (n[o] = d, !0); + set: function(n, o, h, d) { + return n.proxy.ethersInstance && n.proxy.ethersInstance[o] !== void 0 ? (n.proxy.ethersInstance[o] = h, !0) : n.proxy.extensionInstance && n.proxy.extensionInstance[o] !== void 0 ? (n.proxy.extensionInstance[o] = h, !0) : (n[o] = h, !0); } }); return this.proxy = { + _changeWatchers: [], + onChange: function(n) { + this._changeWatchers.push(n); + }, _initIsRunning: !1, _ethersInstance: null, get ethersInstance() { return this._ethersInstance; }, set ethersInstance(n) { - this._ethersInstance = n && ct(n), this._initIsRunning || (this._initIsRunning = !0, s._asyncInit().finally(() => { + const o = { ...this._ethersInstance }; + this._ethersInstance = n && ct(n); + for (const h of this._changeWatchers) + h(this._ethersInstance, o); + this._initIsRunning || (this._initIsRunning = !0, s._asyncInit().finally(() => { this._initIsRunning = !1; })); }, extensionInstance: e - }, s; + }, this.proxy.ethersInstance = t, s; } } -class Ne { +class Oe { } -class xe { +class Ne { constructor() { this._ars = {}; } @@ -1346,7 +1361,7 @@ class xe { this._purgeARS(), this.proxy.ethersInstance && this._initEthersInstanceARS(), this._initPlaceholderInstanceARS(); } onSafe(t) { - const e = x(); + const e = N(); if (this.isSafe.value) t(e); else { @@ -1356,12 +1371,12 @@ class xe { } } } -class L extends j { +class q extends V { constructor(t = null, e = null) { super( t, - e || new Ne() - ), this.status = a._ars.provider.status, this.isSafe = a._ars.provider.isSafe, this.OnSafe = a._ars.provider.OnSafe, this.onSafe = a._ars.provider.onSafe, this._asyncInit(); + e || new Oe() + ), this.status = a._ars.provider.status, this.isSafe = a._ars.provider.isSafe, this.OnSafe = a._ars.provider.OnSafe, this.onSafe = a._ars.provider.onSafe; } async _autoInstantiateFromWallet() { let t = null; @@ -1380,7 +1395,7 @@ class L extends j { } _autoInstantiateFromDefaultConfig() { const t = a.config.networks.getDefault(); - t && t.defaultRPC && (this.proxy.ethersInstance = new _.providers.JsonRpcProvider(t.defaultRPC)); + t && t.defaultRPC && (this.proxy.ethersInstance = new m.providers.JsonRpcProvider(t.defaultRPC)); } async _autoInstantiate() { await this._autoInstantiateFromWallet(), this.proxy.ethersInstance || this._autoInstantiateFromDefaultConfig(); @@ -1416,26 +1431,14 @@ class L extends j { } class Pe { } -class q extends j { +class G extends V { constructor(t = null, e = null) { super( t, e || new Pe() - ), this.walletId = null, this.address = y(null), this.status = a._ars.signer.status, this.isSafe = a._ars.signer.isSafe, this.OnSafe = a._ars.signer.OnSafe, this.onSafe = a._ars.signer.onSafe, this._asyncInit(); - } - _initEthersInstanceARS() { - } - _initPlaceholderInstanceARS() { - a.provider.status.watchAny((t) => { - t === "WRONG_NETWORK" ? this.status.set("WRONG_NETWORK") : ["DISCONNECTED", "ERROR"].includes(t) && this.status.set("NO_PROVIDER"); - }), this.status.watch(["REFUSED", "ERROR"], () => { - setTimeout(() => { - this.status.set("DISCONNECTED"); - }, 5e3); - }); + ), this.walletId = null, this.address = y(null), this.status = a._ars.signer.status, this.isSafe = a._ars.signer.isSafe, this.OnSafe = a._ars.signer.OnSafe, this.onSafe = a._ars.signer.onSafe; } async _autoInstantiate() { - console.log(a.wallets); for (const t of Object.keys(a.wallets)) if (a.wallets[t].lazyConnectAvailable && (await this.connectWallet(t, !0), this.proxy.ethersInstance)) break; @@ -1489,33 +1492,25 @@ class Ae { }), a.chainWatchers.contracts[this.address].getRef(t, e); } } -class G extends j { - constructor(t = null, e = null) { - super( - t, - e || new Ae() - ), this.name = null, this.status = a._ars.contracts[this.name].status, this.isReadSafe = a._ars.contracts[this.name].isReadSafe, this.isWriteSafe = a._ars.contracts[this.name].isWriteSafe, this.OnReadSafe = a._ars.contracts[this.name].OnReadSafe, this.OnWriteSafe = a._ars.contracts[this.name].OnWriteSafe, this.onReadSafe = a._ars.contracts[this.name].onReadSafe, this.onWriteSafe = a._ars.contracts[this.name].onWriteSafe, this._asyncInit(); +class j extends V { + constructor(t, e = null, s = null) { + console.log("init proxy"), console.log(t), console.log(e), super( + e, + s || new Ae() + ), console.log("proxxx"), console.log(this.proxy), this.name = t, this.status = a._ars.contracts[this.name].status, this.isReadSafe = a._ars.contracts[this.name].isReadSafe, this.isWriteSafe = a._ars.contracts[this.name].isWriteSafe, this.OnReadSafe = a._ars.contracts[this.name].OnReadSafe, this.OnWriteSafe = a._ars.contracts[this.name].OnWriteSafe, this.onReadSafe = a._ars.contracts[this.name].onReadSafe, this.onWriteSafe = a._ars.contracts[this.name].onWriteSafe, console.log("proxxx 2"), console.log(this.proxy); } onSafe(t) { throw "TulipeContract instances don't have 'onSafe()' method, use 'onReadSafe()' and 'onWriteSafe()' instead."; } - _updateContract(t, e) { - if (a.signer.isSafe.value) - this.proxy.ethersInstance = new _.Contract(t, e, a.signer.proxy.ethersInstance); - else if (a.provider.isSafe.value) - this.proxy.ethersInstance = new _.Contract(t, e, a.provider.proxy.ethersInstance); - else - throw `_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`; - } async _asyncInit() { - a.provider.onSafe(async function() { - this.proxy.ethersInstance ? (this.name = "TODO", this.status.set("INITIALIZED")) : this.status.set("UNAVAILABLE"); + console.log("proxxx 3"), console.log(this.proxy), a.provider.onSafe(async function() { + this.proxy.ethersInstance ? (this.name = "TODO", this.status.set("INITIALIZED")) : (console.log(this.proxy), console.log("marked as UNVAILABLE !"), this.status.set("UNAVAILABLE")); }.bind(this)); } } class We { } -class $e extends xe { +class $e extends Ne { constructor() { super(), this.contractName = null, this.methodName = null, this.methodInfos = {}, this.args = y(args), this.txArgs = y(txArgs), this.data = y([]), this.error = y(null), this.call = null, this.status = new T(`tx:${contractName}:${methodName}`, [ "NOT_READY", @@ -1552,69 +1547,69 @@ class $e extends xe { }); } } -class J extends j { - constructor(t, e, s = [], n = { value: 0 }, o = null, d = null, h = null) { +class Y extends V { + constructor(t, e, s = [], n = { value: 0 }, o = null, h = null, d = null) { super( o, - d || new We(), - h || new $e(t, e, s = [], n = { value: 0 }) + h || new We(), + d || new $e(t, e, s = [], n = { value: 0 }) ), this._asyncInit(); } } const De = { - JsonRpcProvider: _.providers.JsonRpcProvider, - StaticJsonRpcProvider: _.providers.StaticJsonRpcProvider, - EtherscanProvider: _.providers.EtherscanProvider, - InfuraProvider: _.providers.InfuraProvider, - AlchemyProvider: _.providers.AlchemyProvider, - CloudflareProvider: _.providers.CloudflareProvider, - PocketProvider: _.providers.PocketProvider, - AnkrProvider: _.providers.AnkrProvider, - FallbackProvider: _.providers.FallbackProvider, - IpcProvider: _.providers.IpcProvider, - JsonRpcBatchProvider: _.providers.JsonRpcBatchProvider, - UrlJsonRpcProvider: _.providers.UrlJsonRpcProvider, - Web3Provider: _.providers.Web3Provider, - WebSocketProvider: _.providers.WebSocketProvider -}, Y = {}; + JsonRpcProvider: m.providers.JsonRpcProvider, + StaticJsonRpcProvider: m.providers.StaticJsonRpcProvider, + EtherscanProvider: m.providers.EtherscanProvider, + InfuraProvider: m.providers.InfuraProvider, + AlchemyProvider: m.providers.AlchemyProvider, + CloudflareProvider: m.providers.CloudflareProvider, + PocketProvider: m.providers.PocketProvider, + AnkrProvider: m.providers.AnkrProvider, + FallbackProvider: m.providers.FallbackProvider, + IpcProvider: m.providers.IpcProvider, + JsonRpcBatchProvider: m.providers.JsonRpcBatchProvider, + UrlJsonRpcProvider: m.providers.UrlJsonRpcProvider, + Web3Provider: m.providers.Web3Provider, + WebSocketProvider: m.providers.WebSocketProvider +}, Z = {}; for (const [r, t] of Object.entries(De)) - Y[r] = class extends t { + Z[r] = class extends t { constructor(...e) { - let s = L; - return e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof L && (s = e.pop()), super(...e), new s(this); + let s = q; + return e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof q && (s = e.pop()), super(...e), new s(this); } }; const Te = { - Wallet: _.Wallet, - VoidSigner: _.VoidSigner -}, Z = {}; + Wallet: m.Wallet, + VoidSigner: m.VoidSigner +}, Q = {}; for (const [r, t] of Object.entries(Te)) - Z[r] = class extends t { + Q[r] = class extends t { constructor(...e) { - let s = q; - return e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof q && (s = e.pop()), super(...e), new s(this); + let s = G; + return e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof G && (s = e.pop()), super(...e), new s(this); } }; const Ue = { - Contract: _.Contract -}, Q = {}; + Contract: m.Contract +}, X = {}; for (const [r, t] of Object.entries(Ue)) - Q[r] = class extends t { + X[r] = class extends t { constructor(...e) { - let s = G; - e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof G && (s = e.pop()), super(...e); + let s = j; + e.length > 0 && e[e.length - 1] && e[e.length - 1].prototype instanceof j && (s = e.pop()), super(...e); const n = new s(this); return console.log(n), n; } }; const Be = { - ...Y, ...Z, - ...Q -}, je = { ..._ }; + ...Q, + ...X +}, je = { ...m }; for (const [r, t] of Object.entries(Be)) je[r] = t; -class X { +class tt { constructor() { this.lastUpdateBlock = 0, this.sources = {}; } @@ -1641,7 +1636,7 @@ class X { this._update(); } } -class Me extends X { +class Ve extends tt { constructor(t) { super(), this.contract = t; } @@ -1667,10 +1662,10 @@ class Me extends X { state: y(null), dependents: {} }, o = !0); - let d = null; - s && (d = S(this.sources[n].state, s)); - const h = this._generateDependentUUID(); - return this.sources[n].dependents[h] = d, o && this._updateState(this.sources[n]), h; + let h = null; + s && (h = S(this.sources[n].state, s)); + const d = this._generateDependentUUID(); + return this.sources[n].dependents[d] = h, o && this._updateState(this.sources[n]), d; } remove(t, e, s) { const n = this._buildSourceName(t, e); @@ -1685,7 +1680,7 @@ class Me extends X { return this.sources[s].state; } } -class Ve extends X { +class Me extends tt { constructor(t) { super(), this.address = t, this.availableSources = ["balance"]; } @@ -1711,8 +1706,8 @@ class Ve extends X { }, newSource = !0); let o = null; s && (o = watch(this.sources[n].state, s)); - const d = this._generateDependentUUID(); - return this.sources[n].dependents[d] = o, newSource && this._updateState(this.sources[n]), d; + const h = this._generateDependentUUID(); + return this.sources[n].dependents[h] = o, newSource && this._updateState(this.sources[n]), h; } remove(t, e, s) { const n = this._buildSourceName(t, e); @@ -1737,7 +1732,7 @@ class k extends Error { super(walletId, ...e), this.message = t; } } -class tt { +class et { constructor(t) { this.id = t, this.lazyConnectAvailable = !0; } @@ -1760,7 +1755,7 @@ class tt { throw new k(`switchNetwork() method is not implemented in ${this.id} wallet class.`); } } -class et extends tt { +class st extends et { constructor(t, e = null) { super(t), this.exposedObject = e; } @@ -1775,7 +1770,7 @@ class et extends tt { return !1; } getProvider() { - return this.exposedObject ? new _.providers.Web3Provider(this.exposedObject, "any") : null; + return this.exposedObject ? new m.providers.Web3Provider(this.exposedObject, "any") : null; } async getSigner() { if (this.exposedObject) { @@ -1816,7 +1811,7 @@ class et extends tt { } async changeNetwork(t, e = !1) { if (a.config.networks.getById(t)) { - t = _.utils.hexlify(parseInt(t)).toString(), t = _.utils.hexValue(t); + t = m.utils.hexlify(parseInt(t)).toString(), t = m.utils.hexValue(t); try { await this.exposedObject.request({ method: "wallet_switchEthereumChain", @@ -1833,12 +1828,12 @@ class et extends tt { } } } -class Le extends et { +class Le extends st { constructor() { super("metamask", window.ethereum); } } -class qe extends tt { +class qe extends et { constructor(t, e = {}) { super(), this.id = "coinbase"; const s = e.appName || "", n = e.appLogoUrl, o = e.darkMode || !1; @@ -1863,7 +1858,7 @@ class qe extends tt { } } } -class Ge extends et { +class Ge extends st { constructor() { super("binanceChain", window.BinanceChain), this.lazyConnectAvailable = !1; } @@ -1886,10 +1881,10 @@ class He { "UNSAFE", "ERROR", "INITIALIZED" - ]), this.isSafe = A(() => this.status.is("INITIALIZED")), this.OnSafe = he; + ]), this.isSafe = A(() => this.status.is("INITIALIZED")), this.OnSafe = de; } onSafe(t) { - const e = x(); + const e = N(); if (this.isSafe.value) t(e); else { @@ -1899,19 +1894,34 @@ class He { } } } -class ze { +class H { constructor() { - this.status = new T("provider", [ - "DISCONNECTED", - "ERROR", - "WRONG_NETWORK", - "CONNECTED" - ]), this.isSafe = A(() => a.isSafe.value && !this.status.isIn(["DISCONNECTED", "ERROR"])), this.OnSafe = pe; + this._ars = { + oldEthersInstance: null, + events: {}, + watchers: [] + }; } - init() { + _purgeARS() { + if (this._ars.unwatchers) + for (const t of this._ars.unwatchers) + t(); + if (this._ars.unwatchers = [], this._ars.oldEthersInstance && this._ars.events) + for (const [t, e] of Object.entries(this._ars.events)) + this._ars.oldEthersInstance.off(t, e); + } + _initEthersInstanceARS() { + } + _initPlaceholderInstanceARS() { + } + _initARS(t) { + this._purgeARS(), t.proxy.ethersInstance && (console.log("instance ARS"), console.log(t), this._initEthersInstanceARS()), this._initPlaceholderInstanceARS(); + } + start(t) { + this._initARS(t), t.proxy.onChange(this._initARS.bind(this, t)); } onSafe(t) { - const e = x(); + const e = N(); if (this.isSafe.value) t(e); else { @@ -1921,31 +1931,29 @@ class ze { } } } -class st { +class ze extends H { constructor() { - this._ars = { - oldEthersInstance: null, - events: {}, - watchers: {} - }; - } - _purgeARS() { - if (this._ars.unwatchers) - for (const t of this._ars.unwatchers) - t(); - if (this._ars.unwatchers = [], this._ars.oldEthersInstance && this._ars.events) - for (const [t, e] of Object.entries(this._ars.events)) - this._ars.oldEthersInstance.off(t, e); + super(), this.status = new T("provider", [ + "DISCONNECTED", + "ERROR", + "WRONG_NETWORK", + "CONNECTED" + ]), this.isSafe = A(() => a.isSafe.value && !this.status.isIn(["DISCONNECTED", "ERROR"])), this.OnSafe = pe; } _initEthersInstanceARS() { + a.provider.on("network", (t, e) => { + e && e !== t && window.location.reload(); + }), a.provider.on("error", () => { + this.status.set("ERROR"); + }); } _initPlaceholderInstanceARS() { } - _initARS() { - this._purgeARS(), this.proxy.ethersInstance && this._initEthersInstanceARS(), this._initPlaceholderInstanceARS(); + start() { + super.start(a.provider); } onSafe(t) { - const e = x(); + const e = N(); if (this.isSafe.value) t(e); else { @@ -1955,7 +1963,7 @@ class st { } } } -class Ke extends st { +class Ke extends H { constructor() { super(), this.status = new T("signer", [ "NO_PROVIDER", @@ -1967,8 +1975,10 @@ class Ke extends st { "CONNECTED" ]), this.isSafe = A(() => a.provider.isSafe.value && this.status.is("CONNECTED")), this.OnSafe = fe; } - init() { - this._ars.oldEthersInstance = { ...a.signer.proxy.ethersInstance }, a.provider.status.watchAny((t) => { + _initEthersInstanceARS() { + } + _initPlaceholderInstanceARS() { + a.provider.status.watchAny((t) => { t === "WRONG_NETWORK" ? this.status.set("WRONG_NETWORK") : ["DISCONNECTED", "ERROR"].includes(t) && this.status.set("NO_PROVIDER"); }), this.status.watch(["REFUSED", "ERROR"], () => { setTimeout(() => { @@ -1976,8 +1986,11 @@ class Ke extends st { }, 5e3); }); } + start() { + super.start(a.signer); + } onSafe(t) { - const e = x(); + const e = N(); if (this.isSafe.value) t(e); else { @@ -1987,17 +2000,17 @@ class Ke extends st { } } } -class Je extends st { +class Je extends H { constructor(t) { super(), this.name = t, this.status = new T(`contract:${t}`, [ "NO_PROVIDER", "UNAVAILABLE", "ERROR", "INITIALIZED" - ]), this.isReadSafe = A(() => a.provider.isSafe.value && this.status.is("INITIALIZED")), this.isWriteSafe = A(() => a.signer.isSafe.value && this.status.is("INITIALIZED")), this.OnReadSafe = O(me, { contract: t }), this.OnWriteSafe = O(_e, { contract: t }); + ]), this.isReadSafe = A(() => a.provider.isSafe.value && this.status.is("INITIALIZED")), this.isWriteSafe = A(() => a.signer.isSafe.value && this.status.is("INITIALIZED")), this.OnReadSafe = x(me, { contract: t }), this.OnWriteSafe = x(_e, { contract: t }); } onReadSafe(t) { - const e = x(); + const e = N(); if (this.isReadSafe.value) t(e); else { @@ -2007,7 +2020,7 @@ class Je extends st { } } onWriteSafe(t) { - const e = x(); + const e = N(); if (this.isWriteSafe.value) t(e); else { @@ -2016,16 +2029,32 @@ class Je extends st { }); } } - init() { - this._ars.oldEthersInstance = { ...a.contracts[this.name].proxy.ethersInstance }, S(a.signer.isSafe, (t, e) => { - if (t !== e) { - const s = this.proxy.ethersInstance.interface, n = this.proxy.ethersInstance.address; - this.proxy.ethersInstance = null, this._updateContract(n, s); - } - }), a.provider.status.watchAny((t) => { - t === "WRONG_NETWORK" ? this.status.set("UNAVAILABLE") : ["DISCONNECTED", "ERROR"].includes(t) && this.status.set("NO_PROVIDER"); + _updateContract(t, e) { + if (a.signer.isSafe.value) + a.contracts[this.name].proxy.ethersInstance = new m.Contract(t, e, a.signer.proxy.ethersInstance); + else if (a.provider.isSafe.value) + a.contracts[this.name].proxy.ethersInstance = new m.Contract(t, e, a.provider.proxy.ethersInstance); + else + throw `_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`; + } + _initEthersInstanceARS() { + this._ars.watchers.push( + S(a.signer.isSafe, (t, e) => { + if (t !== e) { + const s = a.contracts[this.name].proxy.ethersInstance.interface, n = a.contracts[this.name].proxy.ethersInstance.address; + this._updateContract(n, s); + } + }) + ); + } + _initPlaceholderInstanceARS() { + a.provider.status.watchAny((t) => { + t === "WRONG_NETWORK" ? (console.log("UNAVVS"), this.status.set("UNAVAILABLE")) : ["DISCONNECTED", "ERROR"].includes(t) && this.status.set("NO_PROVIDER"); }); } + start() { + super.start(a.contracts[this.name]); + } } class Ye { constructor(t) { @@ -2051,14 +2080,14 @@ async function rs(r, t) { throw a && a.status && a.status.set("ERROR"), n; } r.config.globalProperties.dapp = a, r.config.globalProperties.rGet = D, r.config.globalProperties.rSet = b, window.dapp = a; - const s = await import("./index.f0d1c9b1.mjs"); + const s = await import("./index.7fcc06b4.mjs"); r.component("OnDappSafe", s.OnDappSafe), r.component("OnProviderSafe", s.OnProviderSafe), r.component("OnSignerSafe", s.OnSignerSafe), r.component("OnContractReadSafe", s.OnContractReadSafe), r.component("OnContractWriteSafe", s.OnContractWriteSafe), a.status.set("INITIALIZED"); } export { Ze as ARS, es as ConnectWalletButton, ts as ContractInteractor, - Me as ContractWatcher, + Ve as ContractWatcher, as as DebugBar, Ut as EventInteractor, $t as EventsInteractor, @@ -2067,21 +2096,21 @@ export { gt as MethodsInteractor, me as OnContractReadSafe, _e as OnContractWriteSafe, - he as OnDappSafe, + de as OnDappSafe, pe as OnProviderSafe, fe as OnSignerSafe, ns as SelectNetworkDropdown, ss as SelectWalletDropdown, T as Status, qt as Transact, - Oe as TulipeConfig, - G as TulipeContractProxy, - L as TulipeProviderProxy, - j as TulipeProxy, - q as TulipeSignerProxy, - J as TulipeTransactionProxy, + xe as TulipeConfig, + j as TulipeContractProxy, + q as TulipeProviderProxy, + V as TulipeProxy, + G as TulipeSignerProxy, + Y as TulipeTransactionProxy, F as WalletConnectionRejected, - Ve as WalletWatcher, + Me as WalletWatcher, pt as capitalizeWords, a as dapp, W as deepMerge, diff --git a/dist/tulipe.min.js b/dist/tulipe.min.js index 7e82365f..3956eadf 100644 --- a/dist/tulipe.min.js +++ b/dist/tulipe.min.js @@ -1 +1 @@ -var Tulipe=function(c,t,p){"use strict";class it{constructor(){const e=r.config.wallets.getAvailable();for(const n of e){const s=st[n.id];s&&(this[n.id]=new s)}}}class ct{constructor(){for(const e of r.config.networks.getAll())if(e.contracts)for(const[n,s]of Object.entries(e.contracts));}getAll(){const e={};for(const[n,s]of Object.entries(this))s instanceof C&&(e[n]=s);return e}}class lt{constructor(){this.contracts={},this.wallets={}}async _asyncInit(){r.provider.onSafe(()=>{r.provider.on("block",async function(e){const n=await r.provider.getBlockWithTransactions(e);for(const s of n.transactions)Object.keys(this.contracts).includes(s.to)?this.contracts[s.to].update():Object.keys(this.wallets).includes(s.to)&&this.wallets[s.to].update(),Object.keys(this.contracts).includes(s.from)?this.contracts[s.from].update():Object.keys(this.wallets).includes(s.from)&&this.wallets[s.from].update()})})}addContractWatcher(e){Object.keys(this.contracts).includes(e.address)||(this.contracts[e.address]=new v(e))}removeContractWatcher(e){Object.keys(this.contracts).includes(e.address)&&delete this.contracts[e.address]}addWalletWatcher(e){Object.keys(this.wallets).includes(e)||(this.wallets[e]=new tt(e))}removeContractWatcher(e){Object.keys(this.wallets).includes(e)&&delete this.wallets[e]}}class dt{constructor(){}init(e=null){this.config=new K(e),this._ars=new rt,this.status=this._ars.dapp.status,this.isSafe=this._ars.dapp.isSafe,this.OnSafe=this._ars.dapp.OnSafe,this.onSafe=this._ars.dapp.onSafe,this.chainWatchers=new lt,this.wallets=new it,this.contracts=new ct,this.provider=new k,this._ars.provider.init(),this.signer=new N,this._ars.signer.init(),this.pro=this.provider,this.sig=this.signer,this.con=this.contracts}}const r=new dt;function E(o){return o&&typeof o=="object"&&!Array.isArray(o)}function _(o,...e){if(!e.length)return o;const n=e.shift();if(E(o)&&E(n))for(const s in n)E(n[s])?(o[s]||Object.assign(o,{[s]:{}}),_(o[s],n[s])):Object.assign(o,{[s]:n[s]});return _(o,...e)}function j(o){const e=o.split(" ");for(let n=0;n{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",ht,[t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Address : "+t.toDisplayString(t.unref(n).address),1),t.createElementVNode("li",null,"Owner : "+t.toDisplayString(t.unref(s)),1),t.createElementVNode("li",null,[pt,ft,t.createVNode(t.unref(b),{contract:e.contract},null,8,["contract"])]),t.createElementVNode("li",null,[ut,mt,t.createVNode(t.unref(x),{contract:e.contract},null,8,["contract"])])])])]),_:1},8,["contract"])}}},yt={class:"MethodsInteractor"},b={__name:"MethodsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",yt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.functions,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(O),{contract:e.contract,method:d},null,8,["contract","method"])]))),256))])])]),_:1},8,["contract"])}}},_t={class:"MethodInteractor"},St={key:0},wt=t.createElementVNode("p",null,"Inputs :",-1),gt=["onUpdate:modelValue","placeholder"],Et={key:0},kt={key:1},Nt=t.createElementVNode("p",null,"Outputs :",-1),Ct=["onUpdate:modelValue","placeholder"],It=["placeholder"],Rt={key:2},O={__name:"MethodInteractor",props:{contract:{type:String,required:!0},method:{type:String,required:!0}},setup(o){const e=o,n=t.shallowRef(new U(e.contract,e.method));function s(a){return`${a.name&&a.name!=="null"?a.name:""} (${a.type})`}return(a,i)=>{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",_t,[t.createVNode(t.unref(D),{contract:e.contract,method:e.method,modelValue:t.unref(n),"onUpdate:modelValue":i[0]||(i[0]=d=>t.isRef(n)?n.value=d:null),configs:{content:e.method,notx:!0,noerror:!0}},null,8,["contract","method","modelValue","configs"]),t.createElementVNode("small",null,t.toDisplayString(t.unref(n).methodInfos.stateMutability),1),Object.keys(t.unref(n).methodInfos.inputs).length>0||t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("div",St,[wt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.inputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.withDirectives(t.createElementVNode("input",{"onUpdate:modelValue":f=>t.unref(n).args.value[h]=f,type:"text",placeholder:s(d)},null,8,gt),[[t.vModelText,t.unref(n).args.value[h]]]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).args.value[h])+" "+t.toDisplayString(typeof t.unref(n).args.value[h]),1)]))),256)),t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("li",Et,[t.createVNode(t.unref($),{modelValue:t.unref(n).txArgs.value.value,"onUpdate:modelValue":i[1]||(i[1]=d=>t.unref(n).txArgs.value.value=d)},null,8,["modelValue"]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).txArgs.value.value)+" "+t.toDisplayString(typeof t.unref(n).txArgs.value.value),1)])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0),Object.keys(t.unref(n).methodInfos.outputs).length>0?(t.openBlock(),t.createElementBlock("div",kt,[Nt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.outputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.unref(n).data.value?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:0,"onUpdate:modelValue":f=>t.unref(n).data.value[h]=f,type:"text",placeholder:s(d),disabled:""},null,8,Ct)),[[t.vModelText,t.unref(n).data.value[h]]]):(t.openBlock(),t.createElementBlock("input",{key:1,type:"text",placeholder:s(d),disabled:""},null,8,It))]))),256))])])):t.createCommentVNode("",!0),t.unref(n).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Rt,t.toDisplayString(t.unref(n).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},bt={class:"EventsInteractor"},x={__name:"EventsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",bt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.events,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(B),{contract:e.contract,event:d},null,8,["contract","event"])]))),256))])])]),_:1},8,["contract"])}}},Ot={class:"EventInteractor"},xt=t.createTextVNode("Logs: "),B={__name:"EventInteractor",props:{contract:{type:String,required:!0},event:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];let s=t.ref({}),a=t.ref({}),i=t.ref(0),l=t.ref([]);return n.onReadSafe(()=>{s.value=n.interface.events[e.event],a.value=n.filters[s.value.name],n.on(a.value,d=>{i.value++;let h=`Block ${d.blockNumber} -> {`;for(const f of s.value.inputs)h+=`${f.name}:${d.args[f.name]}, `;h=h.substring(0,h.length-2)+"}",l.value.push(h)})}),(d,h)=>{const f=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(f,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Ot,[t.createElementVNode("p",null,t.toDisplayString(t.unref(s).name),1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Count : "+t.toDisplayString(t.unref(i)),1),t.createElementVNode("li",null,[xt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(l),ot=>(t.openBlock(),t.createElementBlock("li",null,t.toDisplayString(ot),1))),256))])])])])]),_:1},8,["contract"])}}},Bt={class:"TransactButton"},Dt={key:1,disabled:""},Pt={key:2,disabled:""},Vt={key:3,disabled:""},Tt={key:4},D={__name:"Transact",props:{modelValue:{},contract:{type:String,required:!0},method:{type:String,required:!0},args:{type:Array,required:!1},txArgs:{type:Object,required:!1},configs:{type:Object,required:!1}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o,s=r.contracts[n.contract];let a=t.computed({get(){return n.modelValue},set(l){e("update:modelValue",l)}});function i(){const l=n.args?n.args:[],d=n.txArgs?n.txArgs:{};a.value.send(l,d)}return n.config&&n.configs.notx&&s.onReadSafe(()=>{a=new U(n.contract,n.method)}),(l,d)=>{const h=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(h,{contract:n.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Bt,[t.unref(a).status.is("READY")?(t.openBlock(),t.createElementBlock("button",{key:0,onClick:i},t.toDisplayString(n.configs&&n.configs.content?n.configs.content:"Transact"),1)):t.unref(a).status.is("SENT")?(t.openBlock(),t.createElementBlock("button",Dt,"Transaction sent...")):t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("button",Pt,"Transaction error!")):t.unref(a).status.is("SUCCESS")?(t.openBlock(),t.createElementBlock("button",Vt,"Success !")):t.createCommentVNode("",!0),!(n.configs&&n.configs.noerror)&&t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Tt,t.toDisplayString(t.unref(a).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},Oe="",L=(o,e)=>{const n=o.__vccOpts||o;for(const[s,a]of e)n[s]=a;return n},F=L({__name:"ConnectWalletButton",props:{styleLevel:R},setup(o){const e=o;return(n,s)=>(t.openBlock(),t.createBlock(t.unref(r).provider.OnSafe,null,{default:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass(["ConnectWalletButton",`ve-${e.styleLevel}`])},null,2)]),_:1}))}},[["__scopeId","data-v-a10b4efb"]]),At={class:"SelectWalletDropdown"},Wt={key:0},$t=[t.createElementVNode("p",null,"Connection requested...",-1)],Ut={key:1},jt=[t.createElementVNode("p",null,"Connection refused!",-1)],Mt={key:2},Lt=[t.createElementVNode("p",null,"Select a wallet",-1)],Ft=["src","alt"],Gt=["onClick"],qt=["src","alt"],G={__name:"SelectWalletDropdown",setup(o){let e=t.ref(null),n=t.ref([]),s=t.ref(!1),a=t.ref({});r.onSafe(async function(){n.value=r.config.wallets.getAvailable()}),r.provider.onSafe(async function(){a.value=await r.config.networks.getCurrent()}),r.signer.onSafe(async function(){e.value=await r.config.wallets.getCurrent(),n.value=r.config.wallets.getAvailable().filter(l=>l.id!==e.value.id)});function i(){s.value=!s.value}return(l,d)=>{const h=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(h,null,{default:t.withCtx(()=>[t.createElementVNode("div",At,[t.createElementVNode("ul",null,[t.unref(r).signer.status.is("REQUESTED")?(t.openBlock(),t.createElementBlock("li",Wt,$t)):t.unref(r).signer.status.is("REFUSED")?(t.openBlock(),t.createElementBlock("li",Ut,jt)):t.unref(r).provider.status.is("WRONG_NETWORK")?(t.openBlock(),t.createElementBlock("li",Mt,[t.createElementVNode("p",null,"Wrong network! ("+t.toDisplayString(t.unref(a)?t.unref(a).displayName:"unknown")+")",1)])):t.unref(r).signer.status.is("DISCONNECTED")||!t.unref(e)?(t.openBlock(),t.createElementBlock("li",{key:3,onClick:i},Lt)):t.unref(r).signer.status.is("CONNECTED")?(t.openBlock(),t.createElementBlock("li",{key:4,onClick:i},[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.wallets.icon,alt:t.unref(e).displayName+" logo"},null,8,Ft),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):t.createCommentVNode("",!0),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:5},t.renderList(t.unref(n),f=>(t.openBlock(),t.createElementBlock("li",{key:f.id,onClick:ot=>t.unref(r).signer.connectWallet(f.id)},[t.createElementVNode("img",{width:"40",src:f.icon?f.icon:t.unref(r).config.defaults.wallets.icon,alt:f.displayName+" logo"},null,8,qt),t.createElementVNode("p",null,t.toDisplayString(f.displayName),1)],8,Gt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},Ht={class:"SelectNetworkDropdown"},zt={key:0},Kt=["src","alt"],Jt={key:1},Yt=[t.createElementVNode("p",null,"Select a network",-1)],Zt=["onClick"],Qt=["src","alt"],q={__name:"SelectNetworkDropdown",setup(o){let e=t.ref({}),n=t.ref([]),s=t.ref(!1);r.onSafe(async function(){n.value=r.config.networks.getAvailable()}),r.provider.onSafe(async function(){e.value=await r.config.networks.getCurrent(),n.value=r.config.networks.getAvailable().filter(i=>i.id!==e.value.id)});function a(){s.value=!s.value}return(i,l)=>{const d=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(d,null,{default:t.withCtx(()=>[t.createElementVNode("div",Ht,[t.createElementVNode("ul",{onClick:a},[t.unref(e)?(t.openBlock(),t.createElementBlock("li",zt,[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.networks.icon,alt:t.unref(e).displayName+" logo"},null,8,Kt),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):(t.openBlock(),t.createElementBlock("li",Jt,Yt)),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:2},t.renderList(t.unref(n),h=>(t.openBlock(),t.createElementBlock("li",{key:h.id,onClick:f=>t.unref(r).provider.changeNetwork(h.id)},[t.createElementVNode("img",{width:"40",src:h.icon?h.icon:t.unref(r).config.defaults.networks.icon,alt:h.displayName+" logo"},null,8,Qt),t.createElementVNode("p",null,t.toDisplayString(h.displayName),1)],8,Zt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},P={__name:"OnDappSafe",setup(o){return(e,n)=>t.unref(r).isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},V={__name:"OnProviderSafe",setup(o){return(e,n)=>t.unref(r).provider.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},T={__name:"OnSignerSafe",setup(o){return(e,n)=>t.unref(r).signer.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},A={__name:"OnContractReadSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isReadSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},W={__name:"OnContractWriteSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isWriteSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},Te="",H=o=>(t.pushScopeId("data-v-a24ac687"),o=o(),t.popScopeId(),o),Xt=H(()=>t.createElementVNode("h3",null,"Safe Runners",-1)),vt=H(()=>t.createElementVNode("h3",null,"Status",-1)),z=L({__name:"DebugBar",setup(o){return(e,n)=>{const s=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(s,null,{default:t.withCtx(()=>[t.createElementVNode("section",null,[t.createElementVNode("div",null,[Xt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"DApp safe : "+t.toDisplayString(t.unref(r).isSafe),1),t.createElementVNode("li",null,"Provider safe : "+t.toDisplayString(t.unref(r).provider.isSafe),1),t.createElementVNode("li",null,"Signer safe : "+t.toDisplayString(t.unref(r).signer.isSafe),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null,[t.createTextVNode(" contract "+t.toDisplayString(i)+" : ",1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"read safe : "+t.toDisplayString(a.isReadSafe),1),t.createElementVNode("li",null,"write safe : "+t.toDisplayString(a.isWriteSafe),1)])]))),256))])]),t.createElementVNode("div",null,[vt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"dapp : "+t.toDisplayString(t.unref(r).status.get()),1),t.createElementVNode("li",null,"provider : "+t.toDisplayString(t.unref(r).provider.status.get()),1),t.createElementVNode("li",null,"signer : "+t.toDisplayString(t.unref(r).signer.status.get()),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null," contract "+t.toDisplayString(i)+" : "+t.toDisplayString(a.status.get()),1))),256))])])])]),_:1})}}},[["__scopeId","data-v-a24ac687"]]),te={class:"InputUnits"},ee=["placeholder"],ne=["value"],$={__name:"InputUnits",props:{modelValue:{},placeholder:{type:String}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o;let s=t.ref(null);const a=["wei","gwei","ether"];let i=t.ref("wei");function l(){if(s.value){const d=p.ethers.utils.parseUnits(s.value,i.value);e("update:modelValue",d)}}return(d,h)=>(t.openBlock(),t.createElementBlock("div",te,[t.withDirectives(t.createElementVNode("input",{onInput:l,"onUpdate:modelValue":h[0]||(h[0]=f=>t.isRef(s)?s.value=f:s=f),type:"text",placeholder:t.unref(n).placeholder},null,40,ee),[[t.vModelText,t.unref(s)]]),t.withDirectives(t.createElementVNode("select",{onChange:l,"onUpdate:modelValue":h[1]||(h[1]=f=>t.isRef(i)?i.value=f:i=f)},[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(a,f=>t.createElementVNode("option",{value:f},t.toDisplayString(f),9,ne)),64))],544),[[t.vModelSelect,t.unref(i)]])]))}},se=Object.freeze(Object.defineProperty({__proto__:null,InputUnits:$,styleLevelProp:R,ContractInteractor:M,MethodsInteractor:b,MethodInteractor:O,EventsInteractor:x,EventInteractor:B,Transact:D,ConnectWalletButton:F,SelectWalletDropdown:G,SelectNetworkDropdown:q,OnDappSafe:P,OnProviderSafe:V,OnSignerSafe:T,OnContractReadSafe:A,OnContractWriteSafe:W,DebugBar:z},Symbol.toStringTag,{value:"Module"}));class w{constructor(e,n){if(this._name=e,this.states=[],!Array.isArray(n))throw`The 'states' parameter of a Status instance '${e}' must an array of strings. Got: ${n}`;for(const s of n)this.states.push(this._formatState(s));this._state=t.ref(this.states[0])}_formatState(e){return e.toString().toUpperCase()}_isStateValid(e){return!!this.states.includes(this._formatState(e))}_areStatesValid(e){for(const n of e)if(!this._isStateValid(n))return!1;return!0}get(){return S(this._state)}getRef(){return this._state}set(e){if(e=this._formatState(e),!this._isStateValid(e))throw`The state given to the set() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;u(this._state,e),console.log(`Status '${this._name}' set to '${S(this._state)}'`)}is(e){if(!this._isStateValid(e))throw`The state given to the is() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;return this.get()==this._formatState(e)}isIn(e){if(!this._areStatesValid(e))throw`The states given to the isIn() method of Status instance '${this._name}' must be an array with values in ${this.states}. Got: ${e}`;for(const n of e)if(this.is(n))return!0;return!1}watch(e,n){let s=`The states given to the watch() method of Status instance '${this._name}' must be a string or an array with values in ${this.states}. Got: ${e}`;if(Array.isArray(e)){if(!this._areStatesValid(e))throw s;return t.watch(this._state,()=>{this.isIn(e)&&n(this.get())})}else{if(!this._isStateValid(e))throw s;return t.watch(this._state,()=>{this.is(e)&&n(this.get())})}}watchAny(e){return this.watch(this.states,e)}}const m={style:{level:"minimal"},networks:[{name:"Ethereum Mainnet",displayName:"Ethereum",id:1,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/ethereum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.infura.io/v3/"},{name:"Ropsten",displayName:"Ropsten (Ethereum Testnet)",id:3,type:"testnet",icon:null,currency:{name:"Ropsten Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://ropsten.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://ropsten.infura.io/v3/"},{name:"Rinkeby",displayName:"Rinkeby (Ethereum Testnet)",id:4,type:"testnet",icon:null,currency:{name:"Rinkeby Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://rinkeby.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://rinkeby.infura.io/v3/"},{name:"G\xF6rli",displayName:"G\xF6rli (Ethereum Testnet)",id:5,type:"testnet",icon:null,currency:{name:"G\xF6rli Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://goerli.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://goerli.infura.io/v3/"},{name:"Optimism",id:10,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/optimism.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://optimistic.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.optimism.io/"},{name:"Cronos Mainnet Beta",displayName:"Cronos",id:25,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/cronos.svg",currency:{name:"Cronos",symbol:"CRO",decimals:18},contracts:null,explorer:{name:"Cronos Explorer",url:"https://cronos.org/explorer",standard:"EIP3091"},defaultRPC:"https://evm.cronos.org"},{name:"Telos EVM Mainnet",displayName:"Telos",id:40,type:"mainnet",icon:null,currency:{name:"Telos",symbol:"TLOS",decimals:18},contracts:null,explorer:{name:"Teloscan",url:"https://teloscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.telos.net/evm"},{name:"Binance Smart Chain Mainnet",displayName:"BSC",id:56,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/bsc.svg",currency:{name:"Binance Chain Native Token",symbol:"BNB",decimals:18},contracts:null,explorer:{name:"Bscscan",url:"https://bscscan.com/",standard:"EIP3091"},defaultRPC:"https://bsc-dataseed1.binance.org/"},{name:"Gnosis Chain",displayName:"Gnosis",id:100,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/gnosis.svg",currency:{name:"xDAI",symbol:"xDAI",decimals:18},contracts:null,explorer:{name:"Blockscout",url:"https://blockscout.com/xdai/mainnet/",standard:"EIP3091"},defaultRPC:"https://rpc.gnosischain.com"},{name:"Fuse Mainnet",displayName:"Fuse",id:122,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fuse.svg",currency:{name:"Fuse",symbol:"FUSE",decimals:18},contracts:null,explorer:{name:"Fuse Explorer",url:"https://explorer.fuse.io/",standard:"EIP3091"},defaultRPC:"https://rpc.fuse.io"},{name:"Huobi ECO Chain Mainnet",displayName:"HECO",id:128,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/heco.svg",currency:{name:"Huobi ECO Chain Native Token",symbol:"HT",decimals:18},contracts:null,explorer:{name:"Hecoinfo",url:"https://hecoinfo.com",standard:"EIP3091"},defaultRPC:"https://http-mainnet.hecochain.com"},{name:"Polygon Mainnet",displayName:"Polygon",id:137,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/polygon.svg",currency:{name:"MATIC",symbol:"MATIC",decimals:18},contracts:null,explorer:{name:"Polygonscan",url:"https://polygonscan.com/",standard:"EIP3091"},defaultRPC:"https://polygon-rpc.com/"},{name:"Fantom Opera",displayName:"Fantom",id:250,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fantom.svg",currency:{name:"Fantom",symbol:"FTM",decimals:18},contracts:null,explorer:{name:"Ftmscan",url:"https://ftmscan.com/",standard:"EIP3091"},defaultRPC:"https://rpc.ftm.tools"},{name:"Metis Andromeda Mainnet",displayName:"Metis",id:1088,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/metis.svg",currency:{name:"Metis",symbol:"METIS",decimals:18},contracts:null,explorer:{name:"Metis Explorer",url:"https://andromeda-explorer.metis.io",standard:"EIP3091"},defaultRPC:"https://andromeda.metis.io/?owner=1088"},{name:"Moonbeam",id:1284,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonbeam.svg",currency:{name:"Glimmer",symbol:"GLMR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonbeam.moonscan.io",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonbeam.network"},{name:"Moonriver",id:1285,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonriver.svg",currency:{name:"Moonriver",symbol:"MOVR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonriver.moonscan.io/",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonriver.moonbeam.network"},{name:"Klaytn Mainnet Cypress",displayName:"Klaytn",id:8217,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/klaytn.svg",currency:{name:"KLAY",symbol:"KLAY",decimals:18},contracts:null,explorer:{name:"Klaytnscope",url:"https://scope.klaytn.com",standard:"EIP3091"},defaultRPC:"https://public-node-api.klaytnapi.com/v1/cypress"},{name:"Hardhat",displayName:"Hardhat",id:31337,type:"testnet",icon:null,currency:{name:"GoChain Coin",symbol:"GO",decimals:18},contracts:null,explorer:null,defaultRPC:"http://127.0.0.1:8545/"},{name:"Arbitrum One",displayName:"Arbitrum",id:42161,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/arbitrum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Arbiscan",url:"https://arbiscan.io/",standard:"EIP3091"},defaultRPC:"https://arbitrum-mainnet.infura.io/v3/"},{name:"Celo Mainnet",displayName:"Celo",id:42220,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/celo.svg",currency:{name:"CELO",symbol:"CELO",decimals:18},contracts:null,explorer:{name:"Celo Explorer",url:"https://explorer.celo.org/",standard:"EIP3091"},defaultRPC:"https://forno.celo.org"},{name:"Emerald Paratime Mainnet",displayName:"Emerald",id:42262,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/emerald.svg",currency:{name:"Emerald Rose",symbol:"ROSE",decimals:18},contracts:null,explorer:{name:"Emerald Explorer",url:"https://explorer.emerald.oasis.dev/",standard:"EIP3091"},defaultRPC:"https://emerald.oasis.dev"},{name:"Avalanche C-Chain",displayName:"Avalanche",id:43114,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/avalanche.svg",currency:{name:"Avalanche",symbol:"AVAX",decimals:18},contracts:null,explorer:{name:"Snowtrace",url:"https://snowtrace.io/",standard:"EIP3091"},defaultRPC:"https://api.avax.network/ext/bc/C/rpc"},{name:"Aurora Mainnet",displayName:"Aurora",id:1313161554,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/aurora.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Aurorascan",url:"https://aurorascan.dev",standard:"EIP3091"},defaultRPC:"https://mainnet.aurora.dev"},{name:"Harmony Mainnet Shard 0",displayName:"Harmony",id:16666e5,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/harmony.svg",currency:{name:"ONE",symbol:"ONE",decimals:18},contracts:null,explorer:{name:"Harmony Block Explorer",url:"https://explorer.harmony.one",standard:"EIP3091"},defaultRPC:"https://api.harmony.one"}],wallets:[{id:"metamask",displayName:"Metamask",icon:null},{id:"binanceChain",displayName:"Binance Chain",icon:null},{id:"coinbase",displayName:"Coinbase",icon:null}],defaults:{networks:{icon:"https://static.tuli.pe/icons/networks/unknown.svg"},wallets:{icon:"TODO"}}};class ae{constructor(e=null){let n={};return e?n=_({...m.style},{...e}):n=m.style,window.addEventListener("load",()=>{const s=document.getElementsByClassName("ve-app");if(s)for(const a of s)a&&a.classList.add(`ve-${n.level}`)}),n}}class re{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.networks.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.name),this._list.push(a)}}for(const n of m.networks)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}add(e){this._list.push(e)}async getCurrent(){if(r.provider.proxy.ethersInstance){const e=await r.provider.getNetwork().then(n=>n.chainId);return this.getById(e)}return null}getById(e){try{e=parseInt(e)}catch{throw"'id' given to getById() method must be an integer or any data type that can be parsed to interger."}return this._list.find(n=>n.id===parseInt(e))}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class oe{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.wallets.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.id),this._list.push(a)}}for(const n of m.wallets)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}getCurrent(){return r.signer.proxy.ethersInstance?this.getById(r.signer.walletId):null}getById(e){return this._list.find(n=>n.id===e)}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class ie{constructor(e=null){let n={};return e?n=_({...m.defaults},{...e}):n=m.defaults,n}}class K{constructor(e=null){this.style=new ae(e?e.style:null),this.networks=new re(e?e.networks:null),this.wallets=new oe(e?e.wallets:null),this.defaults=new ie(e?e.defaults:null)}}class g{constructor(e=null,n=null){const s=new Proxy(this,{get:function(a,i,l){if(a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0)return typeof a.proxy.ethersInstance[i]=="function"?a.proxy.ethersInstance[i].bind(a.proxy.ethersInstance):a.proxy.ethersInstance[i];if(a.proxy.ethersInstance&&a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0)return typeof a.proxy.extensionInstance[i]=="function"?a.proxy.extensionInstance[i].bind(l):a.proxy.extensionInstance[i];if(a&&a[i]!==void 0)return typeof a[i]=="function"?a[i].bind(l):a[i]},set:function(a,i,l,d){return a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0?(a.proxy.ethersInstance[i]=l,!0):a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0?(a.proxy.extensionInstance[i]=l,!0):(a[i]=l,!0)}});return this.proxy={_initIsRunning:!1,_ethersInstance:null,get ethersInstance(){return this._ethersInstance},set ethersInstance(a){this._ethersInstance=a&&t.markRaw(a),this._initIsRunning||(this._initIsRunning=!0,s._asyncInit().finally(()=>{this._initIsRunning=!1}))},extensionInstance:n},s}}class ce{}class le{constructor(){this._ars={}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class k extends g{constructor(e=null,n=null){super(e,n||new ce),this.status=r._ars.provider.status,this.isSafe=r._ars.provider.isSafe,this.OnSafe=r._ars.provider.OnSafe,this.onSafe=r._ars.provider.onSafe,this._asyncInit()}async _autoInstantiateFromWallet(){let e=null;for(const n of Object.values(r.wallets))if(n.lazyConnectAvailable&&await n.isConnected()){e=n;break}if(e)this.proxy.ethersInstance=e.getProvider();else for(const n of Object.values(r.wallets)){const s=n.getProvider();s&&(this.proxy.ethersInstance=s)}}_autoInstantiateFromDefaultConfig(){const e=r.config.networks.getDefault();e&&e.defaultRPC&&(this.proxy.ethersInstance=new p.ethers.providers.JsonRpcProvider(e.defaultRPC))}async _autoInstantiate(){await this._autoInstantiateFromWallet(),this.proxy.ethersInstance||this._autoInstantiateFromDefaultConfig()}async _checkNetwork(){if(!this.proxy.ethersInstance)throw"._checkNetwork() method must not be called if the ethersInstance is null (if not connected to any network).";const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);if(n)this.status.set("CONNECTED");else if(this.status.set("WRONG_NETWORK"),n=r.config.networks.getAll().find(s=>s.id===e.id),!n){const s={name:e.name,displayName:j(e.name),id:e.chainId};console.log(s),r.config.networks.add(s)}}async _setNetworkSettings(){const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);n&&n&&n.pollingInterval&&(this.pollingInterval=n.pollingInterval)}async _asyncInit(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?(await this._checkNetwork(),await this._setNetworkSettings()):this.status.set("DISCONNECTED")}async changeNetwork(e){const n=await r.config.wallets.getCurrent();n&&r.wallets[n.id].changeNetwork(e)}}class de{}class N extends g{constructor(e=null,n=null){super(e,n||new de),this.walletId=null,this.address=t.ref(null),this.status=r._ars.signer.status,this.isSafe=r._ars.signer.isSafe,this.OnSafe=r._ars.signer.OnSafe,this.onSafe=r._ars.signer.onSafe,this._asyncInit()}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}async _autoInstantiate(){console.log(r.wallets);for(const e of Object.keys(r.wallets))if(r.wallets[e].lazyConnectAvailable&&(await this.connectWallet(e,!0),this.proxy.ethersInstance))break}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?this.address.value=await this.getAddress():this.status.set("DISCONNECTED")}.bind(this))}async connectWallet(e,n=!1){const s=r.wallets[e];if(s.lazyConnectAvailable){if(await s.connect(!0),await s.isConnected())r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED");else if(n){r.signer.status.set("DISCONNECTED");return}}try{this.status.set("REQUESTED"),await s.connect(!1),r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED")}catch(a){if(a instanceof I)this.status.set("REFUSED");else throw this.status.set("ERROR"),a}}disconnectWallet(){r.signer.proxy.ethersInstance=null,this.address.value=null,r.signer.status.set("DISCONNECTED")}}class he{_watch(e,n,s=null){return Object.keys(r.chainWatchers.contracts).includes(this.address)||r.chainWatchers.addContractWatcher(this),r.chainWatchers.contracts[this.address].add(e,n,s)}watch(e,n,s,a=null){const i=this._watch(e,n,s);return a?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)},a):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)}),r.chainWatchers.contracts[this.address].remove.bind(r.chainWatchers.contracts[this.address],e,n,i)}watchRef(e,n,s=null){const a=this._watch(e,n,null);return s?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)},s):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)}),r.chainWatchers.contracts[this.address].getRef(e,n)}}class C extends g{constructor(e=null,n=null){super(e,n||new he),this.name=null,this.status=r._ars.contracts[this.name].status,this.isReadSafe=r._ars.contracts[this.name].isReadSafe,this.isWriteSafe=r._ars.contracts[this.name].isWriteSafe,this.OnReadSafe=r._ars.contracts[this.name].OnReadSafe,this.OnWriteSafe=r._ars.contracts[this.name].OnWriteSafe,this.onReadSafe=r._ars.contracts[this.name].onReadSafe,this.onWriteSafe=r._ars.contracts[this.name].onWriteSafe,this._asyncInit()}onSafe(e){throw"TulipeContract instances don't have 'onSafe()' method, use 'onReadSafe()' and 'onWriteSafe()' instead."}_updateContract(e,n){if(r.signer.isSafe.value)this.proxy.ethersInstance=new p.ethers.Contract(e,n,r.signer.proxy.ethersInstance);else if(r.provider.isSafe.value)this.proxy.ethersInstance=new p.ethers.Contract(e,n,r.provider.proxy.ethersInstance);else throw`_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance?(this.name="TODO",this.status.set("INITIALIZED")):this.status.set("UNAVAILABLE")}.bind(this))}}class pe{}class fe extends le{constructor(){super(),this.contractName=null,this.methodName=null,this.methodInfos={},this.args=t.ref(args),this.txArgs=t.ref(txArgs),this.data=t.ref([]),this.error=t.ref(null),this.call=null,this.status=new w(`tx:${contractName}:${methodName}`,["NOT_READY","READY","SENT","ERROR","SUCCESS"])}initARS(){this.status.watch(["ERROR","SUCCESS"],()=>{setTimeout(()=>{this.status.set("READY")},3e3)})}_asyncInit(){this.proxy._initIsRunning=!0,r.contracts[this.contractName].isReadSafe.value&&this._initEthersInstance(),r.contracts[this.contractName].onReadSafe(()=>{this._initEthersInstance()}),this.initARS(),this.proxy._initIsRunning=!1}_initEthersInstance(){this.methodInfos=r.contracts[this.contractName].interface.functions[this.methodName],this.methodInfos.inputs.forEach(e=>this.args.value.push(null)),this.methodInfos.outputs.forEach(e=>this.data.value.push(null)),this.proxy.ethersInstance=r.contracts[this.contractName][this.methodName],this.status.set("READY")}send(e=null,n=null){e=e&&e.length>0?e:S(this.args),e?Array.isArray(e)?this.call=this.proxy.ethersInstance(...e,n):this.call=this.proxy.ethersInstance(e,n):this.call=this.proxy.ethersInstance(n),this.status.set("SENT"),this.methodInfos.constant?this.call.then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR")}):this.call.then(s=>s.wait()).then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR"),console.log(s)})}}class U extends g{constructor(e,n,s=[],a={value:0},i=null,l=null,d=null){super(i,l||new pe,d||new fe(e,n,s=[],a={value:0})),this._asyncInit()}}const ue={JsonRpcProvider:p.ethers.providers.JsonRpcProvider,StaticJsonRpcProvider:p.ethers.providers.StaticJsonRpcProvider,EtherscanProvider:p.ethers.providers.EtherscanProvider,InfuraProvider:p.ethers.providers.InfuraProvider,AlchemyProvider:p.ethers.providers.AlchemyProvider,CloudflareProvider:p.ethers.providers.CloudflareProvider,PocketProvider:p.ethers.providers.PocketProvider,AnkrProvider:p.ethers.providers.AnkrProvider,FallbackProvider:p.ethers.providers.FallbackProvider,IpcProvider:p.ethers.providers.IpcProvider,JsonRpcBatchProvider:p.ethers.providers.JsonRpcBatchProvider,UrlJsonRpcProvider:p.ethers.providers.UrlJsonRpcProvider,Web3Provider:p.ethers.providers.Web3Provider,WebSocketProvider:p.ethers.providers.WebSocketProvider},J={};for(const[o,e]of Object.entries(ue))J[o]=class extends e{constructor(...n){let s=k;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof k&&(s=n.pop()),super(...n),new s(this)}};const me={Wallet:p.ethers.Wallet,VoidSigner:p.ethers.VoidSigner},Y={};for(const[o,e]of Object.entries(me))Y[o]=class extends e{constructor(...n){let s=N;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof N&&(s=n.pop()),super(...n),new s(this)}};const ye={Contract:p.ethers.Contract},Z={};for(const[o,e]of Object.entries(ye))Z[o]=class extends e{constructor(...n){let s=C;n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof C&&(s=n.pop()),super(...n);const a=new s(this);return console.log(a),a}};const _e={...J,...Y,...Z},Q={...p.ethers};for(const[o,e]of Object.entries(_e))Q[o]=e;class X{constructor(){this.lastUpdateBlock=0,this.sources={}}_generateDependentUUID(){return"xxxxxxxx".replace(/[xy]/g,function(e){var n=Math.random()*16|0,s=e=="x"?n:n&3|8;return s.toString(16)})}async requiresUpdate(){if(!r.provider.isSafe.value)return!1;const e=await r.provider.getBlockNumber();return this.lastUpdateBlock0)return!0}catch{}return!1}getProvider(){return this.exposedObject?new p.ethers.providers.Web3Provider(this.exposedObject,"any"):null}async getSigner(){if(this.exposedObject){const e=this.getProvider();if(e)return await e.getSigner()}return null}async connect(e=!1){if(this.exposedObject){if(await this.isConnected()||e)return;try{await this.exposedObject.request({method:"eth_requestAccounts"})}catch(n){throw n.code===4001?new I(this.id):n}}throw"exposedObject not available"}async addNetwork(e){const n=r.config.networks.getById(e);await this.exposedObject.request({method:"wallet_addEthereumChain",params:[{chainId:e,rpcUrls:[n.defaultRPC],chainName:n.name,nativeCurrency:{name:n.currency.symbol,symbol:n.currency.symbol,decimals:n.currency.decimals},blockExplorerUrls:n.explorer&&n.explorer.url!==""?[n.explorer.url]:null}]})}async changeNetwork(e,n=!1){if(r.config.networks.getById(e)){e=p.ethers.utils.hexlify(parseInt(e)).toString(),e=p.ethers.utils.hexValue(e);try{await this.exposedObject.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(a){if(a.code===4902)this.addNetwork(e);else throw a}}}}class Se extends nt{constructor(){super("metamask",window.ethereum)}}class we extends et{constructor(e,n={}){super(),this.id="coinbase";const s=n.appName||"",a=n.appLogoUrl,i=n.darkMode||!1;this.coinbaseWalletSdk=new e({appName:s,appLogoUrl:a,darkMode:i}),this.provider=this.getProvider()}getProvider(){try{return this.coinbaseWalletSdk.makeWeb3Provider()}catch(e){return console.log(e),null}}async connect(){try{await this.provider.send("eth_requestAccounts")}catch{throw I(this.id)}}}class ge extends nt{constructor(){super("binanceChain",window.BinanceChain),this.lazyConnectAvailable=!1}async isConnected(){throw new y("isConnected() method is not available for BinanceChainWallet class since lazy connection is not available.")}async connect(e=!1){if(e)throw new y("connect() with 'lazy=true' is not available for BinanceChainWallet class because isConnected() is not available on this class.")}}const st={metamask:Se,coinbase:we,binanceChain:ge};class Ee{constructor(){this.status=new w("dapp",["UNSAFE","ERROR","INITIALIZED"]),this.isSafe=t.computed(()=>this.status.is("INITIALIZED")),this.OnSafe=P}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class ke{constructor(){this.status=new w("provider",["DISCONNECTED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.isSafe.value&&!this.status.isIn(["DISCONNECTED","ERROR"])),this.OnSafe=V}init(){}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class at{constructor(){this._ars={oldEthersInstance:null,events:{},watchers:{}}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ne extends at{constructor(){super(),this.status=new w("signer",["NO_PROVIDER","DISCONNECTED","REQUESTED","REFUSED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("CONNECTED")),this.OnSafe=T}init(){this._ars.oldEthersInstance={...r.signer.proxy.ethersInstance},r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ce extends at{constructor(e){super(),this.name=e,this.status=new w(`contract:${e}`,["NO_PROVIDER","UNAVAILABLE","ERROR","INITIALIZED"]),this.isReadSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("INITIALIZED")),this.isWriteSafe=t.computed(()=>r.signer.isSafe.value&&this.status.is("INITIALIZED")),this.OnReadSafe=t.createVNode(A,{contract:e}),this.OnWriteSafe=t.createVNode(W,{contract:e})}onReadSafe(e){const n=t.getCurrentInstance();if(this.isReadSafe.value)e(n);else{const s=t.watch(this.isReadSafe,()=>{this.isReadSafe.value&&(e(n),s())})}}onWriteSafe(e){const n=t.getCurrentInstance();if(this.isWriteSafe.value)e(n);else{const s=t.watch(this.isWriteSafe,()=>{this.isWriteSafe.value&&(e(n),s())})}}init(){this._ars.oldEthersInstance={...r.contracts[this.name].proxy.ethersInstance},t.watch(r.signer.isSafe,(e,n)=>{if(e!==n){const s=this.proxy.ethersInstance.interface,a=this.proxy.ethersInstance.address;this.proxy.ethersInstance=null,this._updateContract(a,s)}}),r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("UNAVAILABLE"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")})}}class Ie{constructor(e){for(const n of r.config.networks.getAll())if(n.contracts)for(const[s,a]of Object.entries(n.contracts))this.add(s)}add(e){this[e]=new Ce(e)}}class rt{constructor(){this.dapp=new Ee,this.provider=new ke,this.signer=new Ne,this.contracts=new Ie}}async function Re(o,e){const n=e;try{r.init(n)}catch(a){throw r&&r.status&&r.status.set("ERROR"),a}o.config.globalProperties.dapp=r,o.config.globalProperties.rGet=S,o.config.globalProperties.rSet=u,window.dapp=r;const s=await Promise.resolve().then(()=>se);o.component("OnDappSafe",s.OnDappSafe),o.component("OnProviderSafe",s.OnProviderSafe),o.component("OnSignerSafe",s.OnSignerSafe),o.component("OnContractReadSafe",s.OnContractReadSafe),o.component("OnContractWriteSafe",s.OnContractWriteSafe),r.status.set("INITIALIZED")}return c.ARS=rt,c.ConnectWalletButton=F,c.ContractInteractor=M,c.ContractWatcher=v,c.DebugBar=z,c.EventInteractor=B,c.EventsInteractor=x,c.InputUnits=$,c.MethodInteractor=O,c.MethodsInteractor=b,c.OnContractReadSafe=A,c.OnContractWriteSafe=W,c.OnDappSafe=P,c.OnProviderSafe=V,c.OnSignerSafe=T,c.SelectNetworkDropdown=q,c.SelectWalletDropdown=G,c.Status=w,c.Transact=D,c.TulipeConfig=K,c.TulipeContractProxy=C,c.TulipeProviderProxy=k,c.TulipeProxy=g,c.TulipeSignerProxy=N,c.TulipeTransactionProxy=U,c.WalletConnectionRejected=I,c.WalletWatcher=tt,c.capitalizeWords=j,c.dapp=r,c.deepMerge=_,c.initTulipe=Re,c.isObject=E,c.rGet=S,c.rSet=u,c.styleLevelProp=R,c.tulipeEthers=Q,c.wallets=st,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),c}({},vue,ethers); +var Tulipe=function(c,t,p){"use strict";class it{constructor(){const e=r.config.wallets.getAvailable();for(const n of e){const s=at[n.id];s&&(this[n.id]=new s)}}}class ct{constructor(){}init(){for(const e of r.config.networks.getAll())if(e.contracts)for(const[n,s]of Object.entries(e.contracts))this.add(n,s.address,s.abi)}add(e,n,s){const a=new p.ethers.Contract(n,s);r._ars.contracts.add(e),this[e]=new E(e,a),r._ars.contracts[e].start()}getAll(){const e={};for(const[n,s]of Object.entries(this))s instanceof E&&(e[n]=s);return e}}class lt{constructor(){this.contracts={},this.wallets={}}async _asyncInit(){r.provider.onSafe(()=>{r.provider.on("block",async function(e){const n=await r.provider.getBlockWithTransactions(e);for(const s of n.transactions)Object.keys(this.contracts).includes(s.to)?this.contracts[s.to].update():Object.keys(this.wallets).includes(s.to)&&this.wallets[s.to].update(),Object.keys(this.contracts).includes(s.from)?this.contracts[s.from].update():Object.keys(this.wallets).includes(s.from)&&this.wallets[s.from].update()})})}addContractWatcher(e){Object.keys(this.contracts).includes(e.address)||(this.contracts[e.address]=new tt(e))}removeContractWatcher(e){Object.keys(this.contracts).includes(e.address)&&delete this.contracts[e.address]}addWalletWatcher(e){Object.keys(this.wallets).includes(e)||(this.wallets[e]=new et(e))}removeContractWatcher(e){Object.keys(this.wallets).includes(e)&&delete this.wallets[e]}}class dt{constructor(){}init(e=null){this.config=new J(e),this._ars=new rt,this.status=this._ars.dapp.status,this.isSafe=this._ars.dapp.isSafe,this.OnSafe=this._ars.dapp.OnSafe,this.onSafe=this._ars.dapp.onSafe,this.chainWatchers=new lt,this.wallets=new it,this.provider=new C,this._ars.provider.start(),this.signer=new N,this._ars.signer.start(),this.contracts=new ct,this.contracts.init(),this.pro=this.provider,this.sig=this.signer,this.con=this.contracts}}const r=new dt;function k(o){return o&&typeof o=="object"&&!Array.isArray(o)}function _(o,...e){if(!e.length)return o;const n=e.shift();if(k(o)&&k(n))for(const s in n)k(n[s])?(o[s]||Object.assign(o,{[s]:{}}),_(o[s],n[s])):Object.assign(o,{[s]:n[s]});return _(o,...e)}function M(o){const e=o.split(" ");for(let n=0;n{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",ht,[t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Address : "+t.toDisplayString(t.unref(n).address),1),t.createElementVNode("li",null,"Owner : "+t.toDisplayString(t.unref(s)),1),t.createElementVNode("li",null,[pt,ft,t.createVNode(t.unref(b),{contract:e.contract},null,8,["contract"])]),t.createElementVNode("li",null,[ut,mt,t.createVNode(t.unref(x),{contract:e.contract},null,8,["contract"])])])])]),_:1},8,["contract"])}}},yt={class:"MethodsInteractor"},b={__name:"MethodsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",yt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.functions,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(O),{contract:e.contract,method:d},null,8,["contract","method"])]))),256))])])]),_:1},8,["contract"])}}},_t={class:"MethodInteractor"},St={key:0},wt=t.createElementVNode("p",null,"Inputs :",-1),gt=["onUpdate:modelValue","placeholder"],Et={key:0},kt={key:1},Ct=t.createElementVNode("p",null,"Outputs :",-1),Nt=["onUpdate:modelValue","placeholder"],It=["placeholder"],Rt={key:2},O={__name:"MethodInteractor",props:{contract:{type:String,required:!0},method:{type:String,required:!0}},setup(o){const e=o,n=t.shallowRef(new U(e.contract,e.method));function s(a){return`${a.name&&a.name!=="null"?a.name:""} (${a.type})`}return(a,i)=>{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",_t,[t.createVNode(t.unref(P),{contract:e.contract,method:e.method,modelValue:t.unref(n),"onUpdate:modelValue":i[0]||(i[0]=d=>t.isRef(n)?n.value=d:null),configs:{content:e.method,notx:!0,noerror:!0}},null,8,["contract","method","modelValue","configs"]),t.createElementVNode("small",null,t.toDisplayString(t.unref(n).methodInfos.stateMutability),1),Object.keys(t.unref(n).methodInfos.inputs).length>0||t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("div",St,[wt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.inputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.withDirectives(t.createElementVNode("input",{"onUpdate:modelValue":f=>t.unref(n).args.value[h]=f,type:"text",placeholder:s(d)},null,8,gt),[[t.vModelText,t.unref(n).args.value[h]]]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).args.value[h])+" "+t.toDisplayString(typeof t.unref(n).args.value[h]),1)]))),256)),t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("li",Et,[t.createVNode(t.unref($),{modelValue:t.unref(n).txArgs.value.value,"onUpdate:modelValue":i[1]||(i[1]=d=>t.unref(n).txArgs.value.value=d)},null,8,["modelValue"]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).txArgs.value.value)+" "+t.toDisplayString(typeof t.unref(n).txArgs.value.value),1)])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0),Object.keys(t.unref(n).methodInfos.outputs).length>0?(t.openBlock(),t.createElementBlock("div",kt,[Ct,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.outputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.unref(n).data.value?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:0,"onUpdate:modelValue":f=>t.unref(n).data.value[h]=f,type:"text",placeholder:s(d),disabled:""},null,8,Nt)),[[t.vModelText,t.unref(n).data.value[h]]]):(t.openBlock(),t.createElementBlock("input",{key:1,type:"text",placeholder:s(d),disabled:""},null,8,It))]))),256))])])):t.createCommentVNode("",!0),t.unref(n).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Rt,t.toDisplayString(t.unref(n).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},bt={class:"EventsInteractor"},x={__name:"EventsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",bt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.events,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(B),{contract:e.contract,event:d},null,8,["contract","event"])]))),256))])])]),_:1},8,["contract"])}}},Ot={class:"EventInteractor"},xt=t.createTextVNode("Logs: "),B={__name:"EventInteractor",props:{contract:{type:String,required:!0},event:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];let s=t.ref({}),a=t.ref({}),i=t.ref(0),l=t.ref([]);return n.onReadSafe(()=>{s.value=n.interface.events[e.event],a.value=n.filters[s.value.name],n.on(a.value,d=>{i.value++;let h=`Block ${d.blockNumber} -> {`;for(const f of s.value.inputs)h+=`${f.name}:${d.args[f.name]}, `;h=h.substring(0,h.length-2)+"}",l.value.push(h)})}),(d,h)=>{const f=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(f,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Ot,[t.createElementVNode("p",null,t.toDisplayString(t.unref(s).name),1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Count : "+t.toDisplayString(t.unref(i)),1),t.createElementVNode("li",null,[xt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(l),ot=>(t.openBlock(),t.createElementBlock("li",null,t.toDisplayString(ot),1))),256))])])])])]),_:1},8,["contract"])}}},Bt={class:"TransactButton"},Pt={key:1,disabled:""},Dt={key:2,disabled:""},Vt={key:3,disabled:""},At={key:4},P={__name:"Transact",props:{modelValue:{},contract:{type:String,required:!0},method:{type:String,required:!0},args:{type:Array,required:!1},txArgs:{type:Object,required:!1},configs:{type:Object,required:!1}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o,s=r.contracts[n.contract];let a=t.computed({get(){return n.modelValue},set(l){e("update:modelValue",l)}});function i(){const l=n.args?n.args:[],d=n.txArgs?n.txArgs:{};a.value.send(l,d)}return n.config&&n.configs.notx&&s.onReadSafe(()=>{a=new U(n.contract,n.method)}),(l,d)=>{const h=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(h,{contract:n.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Bt,[t.unref(a).status.is("READY")?(t.openBlock(),t.createElementBlock("button",{key:0,onClick:i},t.toDisplayString(n.configs&&n.configs.content?n.configs.content:"Transact"),1)):t.unref(a).status.is("SENT")?(t.openBlock(),t.createElementBlock("button",Pt,"Transaction sent...")):t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("button",Dt,"Transaction error!")):t.unref(a).status.is("SUCCESS")?(t.openBlock(),t.createElementBlock("button",Vt,"Success !")):t.createCommentVNode("",!0),!(n.configs&&n.configs.noerror)&&t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",At,t.toDisplayString(t.unref(a).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},Oe="",F=(o,e)=>{const n=o.__vccOpts||o;for(const[s,a]of e)n[s]=a;return n},q=F({__name:"ConnectWalletButton",props:{styleLevel:R},setup(o){const e=o;return(n,s)=>(t.openBlock(),t.createBlock(t.unref(r).provider.OnSafe,null,{default:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass(["ConnectWalletButton",`ve-${e.styleLevel}`])},null,2)]),_:1}))}},[["__scopeId","data-v-a10b4efb"]]),Tt={class:"SelectWalletDropdown"},Wt={key:0},$t=[t.createElementVNode("p",null,"Connection requested...",-1)],Ut={key:1},jt=[t.createElementVNode("p",null,"Connection refused!",-1)],Mt={key:2},Lt=[t.createElementVNode("p",null,"Select a wallet",-1)],Ft=["src","alt"],qt=["onClick"],Gt=["src","alt"],G={__name:"SelectWalletDropdown",setup(o){let e=t.ref(null),n=t.ref([]),s=t.ref(!1),a=t.ref({});r.onSafe(async function(){n.value=r.config.wallets.getAvailable()}),r.provider.onSafe(async function(){a.value=await r.config.networks.getCurrent()}),r.signer.onSafe(async function(){e.value=await r.config.wallets.getCurrent(),n.value=r.config.wallets.getAvailable().filter(l=>l.id!==e.value.id)});function i(){s.value=!s.value}return(l,d)=>{const h=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(h,null,{default:t.withCtx(()=>[t.createElementVNode("div",Tt,[t.createElementVNode("ul",null,[t.unref(r).signer.status.is("REQUESTED")?(t.openBlock(),t.createElementBlock("li",Wt,$t)):t.unref(r).signer.status.is("REFUSED")?(t.openBlock(),t.createElementBlock("li",Ut,jt)):t.unref(r).provider.status.is("WRONG_NETWORK")?(t.openBlock(),t.createElementBlock("li",Mt,[t.createElementVNode("p",null,"Wrong network! ("+t.toDisplayString(t.unref(a)?t.unref(a).displayName:"unknown")+")",1)])):t.unref(r).signer.status.is("DISCONNECTED")||!t.unref(e)?(t.openBlock(),t.createElementBlock("li",{key:3,onClick:i},Lt)):t.unref(r).signer.status.is("CONNECTED")?(t.openBlock(),t.createElementBlock("li",{key:4,onClick:i},[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.wallets.icon,alt:t.unref(e).displayName+" logo"},null,8,Ft),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):t.createCommentVNode("",!0),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:5},t.renderList(t.unref(n),f=>(t.openBlock(),t.createElementBlock("li",{key:f.id,onClick:ot=>t.unref(r).signer.connectWallet(f.id)},[t.createElementVNode("img",{width:"40",src:f.icon?f.icon:t.unref(r).config.defaults.wallets.icon,alt:f.displayName+" logo"},null,8,Gt),t.createElementVNode("p",null,t.toDisplayString(f.displayName),1)],8,qt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},Ht={class:"SelectNetworkDropdown"},zt={key:0},Kt=["src","alt"],Jt={key:1},Yt=[t.createElementVNode("p",null,"Select a network",-1)],Zt=["onClick"],Qt=["src","alt"],H={__name:"SelectNetworkDropdown",setup(o){let e=t.ref({}),n=t.ref([]),s=t.ref(!1);r.onSafe(async function(){n.value=r.config.networks.getAvailable()}),r.provider.onSafe(async function(){e.value=await r.config.networks.getCurrent(),n.value=r.config.networks.getAvailable().filter(i=>i.id!==e.value.id)});function a(){s.value=!s.value}return(i,l)=>{const d=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(d,null,{default:t.withCtx(()=>[t.createElementVNode("div",Ht,[t.createElementVNode("ul",{onClick:a},[t.unref(e)?(t.openBlock(),t.createElementBlock("li",zt,[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.networks.icon,alt:t.unref(e).displayName+" logo"},null,8,Kt),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):(t.openBlock(),t.createElementBlock("li",Jt,Yt)),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:2},t.renderList(t.unref(n),h=>(t.openBlock(),t.createElementBlock("li",{key:h.id,onClick:f=>t.unref(r).provider.changeNetwork(h.id)},[t.createElementVNode("img",{width:"40",src:h.icon?h.icon:t.unref(r).config.defaults.networks.icon,alt:h.displayName+" logo"},null,8,Qt),t.createElementVNode("p",null,t.toDisplayString(h.displayName),1)],8,Zt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},D={__name:"OnDappSafe",setup(o){return(e,n)=>t.unref(r).isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},V={__name:"OnProviderSafe",setup(o){return(e,n)=>t.unref(r).provider.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},A={__name:"OnSignerSafe",setup(o){return(e,n)=>t.unref(r).signer.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},T={__name:"OnContractReadSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isReadSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},W={__name:"OnContractWriteSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isWriteSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},Ae="",z=o=>(t.pushScopeId("data-v-a24ac687"),o=o(),t.popScopeId(),o),Xt=z(()=>t.createElementVNode("h3",null,"Safe Runners",-1)),vt=z(()=>t.createElementVNode("h3",null,"Status",-1)),K=F({__name:"DebugBar",setup(o){return(e,n)=>{const s=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(s,null,{default:t.withCtx(()=>[t.createElementVNode("section",null,[t.createElementVNode("div",null,[Xt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"DApp safe : "+t.toDisplayString(t.unref(r).isSafe),1),t.createElementVNode("li",null,"Provider safe : "+t.toDisplayString(t.unref(r).provider.isSafe),1),t.createElementVNode("li",null,"Signer safe : "+t.toDisplayString(t.unref(r).signer.isSafe),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null,[t.createTextVNode(" contract "+t.toDisplayString(i)+" : ",1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"read safe : "+t.toDisplayString(a.isReadSafe),1),t.createElementVNode("li",null,"write safe : "+t.toDisplayString(a.isWriteSafe),1)])]))),256))])]),t.createElementVNode("div",null,[vt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"dapp : "+t.toDisplayString(t.unref(r).status.get()),1),t.createElementVNode("li",null,"provider : "+t.toDisplayString(t.unref(r).provider.status.get()),1),t.createElementVNode("li",null,"signer : "+t.toDisplayString(t.unref(r).signer.status.get()),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null," contract "+t.toDisplayString(i)+" : "+t.toDisplayString(a.status.get()),1))),256))])])])]),_:1})}}},[["__scopeId","data-v-a24ac687"]]),te={class:"InputUnits"},ee=["placeholder"],ne=["value"],$={__name:"InputUnits",props:{modelValue:{},placeholder:{type:String}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o;let s=t.ref(null);const a=["wei","gwei","ether"];let i=t.ref("wei");function l(){if(s.value){const d=p.ethers.utils.parseUnits(s.value,i.value);e("update:modelValue",d)}}return(d,h)=>(t.openBlock(),t.createElementBlock("div",te,[t.withDirectives(t.createElementVNode("input",{onInput:l,"onUpdate:modelValue":h[0]||(h[0]=f=>t.isRef(s)?s.value=f:s=f),type:"text",placeholder:t.unref(n).placeholder},null,40,ee),[[t.vModelText,t.unref(s)]]),t.withDirectives(t.createElementVNode("select",{onChange:l,"onUpdate:modelValue":h[1]||(h[1]=f=>t.isRef(i)?i.value=f:i=f)},[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(a,f=>t.createElementVNode("option",{value:f},t.toDisplayString(f),9,ne)),64))],544),[[t.vModelSelect,t.unref(i)]])]))}},se=Object.freeze(Object.defineProperty({__proto__:null,InputUnits:$,styleLevelProp:R,ContractInteractor:L,MethodsInteractor:b,MethodInteractor:O,EventsInteractor:x,EventInteractor:B,Transact:P,ConnectWalletButton:q,SelectWalletDropdown:G,SelectNetworkDropdown:H,OnDappSafe:D,OnProviderSafe:V,OnSignerSafe:A,OnContractReadSafe:T,OnContractWriteSafe:W,DebugBar:K},Symbol.toStringTag,{value:"Module"}));class w{constructor(e,n){if(this._name=e,this.states=[],!Array.isArray(n))throw`The 'states' parameter of a Status instance '${e}' must an array of strings. Got: ${n}`;for(const s of n)this.states.push(this._formatState(s));this._state=t.ref(this.states[0])}_formatState(e){return e.toString().toUpperCase()}_isStateValid(e){return!!this.states.includes(this._formatState(e))}_areStatesValid(e){for(const n of e)if(!this._isStateValid(n))return!1;return!0}get(){return S(this._state)}getRef(){return this._state}set(e){if(e=this._formatState(e),!this._isStateValid(e))throw`The state given to the set() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;u(this._state,e),console.log(`Status '${this._name}' set to '${S(this._state)}'`)}is(e){if(!this._isStateValid(e))throw`The state given to the is() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;return this.get()==this._formatState(e)}isIn(e){if(!this._areStatesValid(e))throw`The states given to the isIn() method of Status instance '${this._name}' must be an array with values in ${this.states}. Got: ${e}`;for(const n of e)if(this.is(n))return!0;return!1}watch(e,n){let s=`The states given to the watch() method of Status instance '${this._name}' must be a string or an array with values in ${this.states}. Got: ${e}`;if(Array.isArray(e)){if(!this._areStatesValid(e))throw s;return t.watch(this._state,()=>{this.isIn(e)&&n(this.get())})}else{if(!this._isStateValid(e))throw s;return t.watch(this._state,()=>{this.is(e)&&n(this.get())})}}watchAny(e){return this.watch(this.states,e)}}const m={style:{level:"minimal"},networks:[{name:"Ethereum Mainnet",displayName:"Ethereum",id:1,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/ethereum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.infura.io/v3/"},{name:"Ropsten",displayName:"Ropsten (Ethereum Testnet)",id:3,type:"testnet",icon:null,currency:{name:"Ropsten Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://ropsten.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://ropsten.infura.io/v3/"},{name:"Rinkeby",displayName:"Rinkeby (Ethereum Testnet)",id:4,type:"testnet",icon:null,currency:{name:"Rinkeby Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://rinkeby.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://rinkeby.infura.io/v3/"},{name:"G\xF6rli",displayName:"G\xF6rli (Ethereum Testnet)",id:5,type:"testnet",icon:null,currency:{name:"G\xF6rli Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://goerli.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://goerli.infura.io/v3/"},{name:"Optimism",id:10,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/optimism.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://optimistic.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.optimism.io/"},{name:"Cronos Mainnet Beta",displayName:"Cronos",id:25,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/cronos.svg",currency:{name:"Cronos",symbol:"CRO",decimals:18},contracts:null,explorer:{name:"Cronos Explorer",url:"https://cronos.org/explorer",standard:"EIP3091"},defaultRPC:"https://evm.cronos.org"},{name:"Telos EVM Mainnet",displayName:"Telos",id:40,type:"mainnet",icon:null,currency:{name:"Telos",symbol:"TLOS",decimals:18},contracts:null,explorer:{name:"Teloscan",url:"https://teloscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.telos.net/evm"},{name:"Binance Smart Chain Mainnet",displayName:"BSC",id:56,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/bsc.svg",currency:{name:"Binance Chain Native Token",symbol:"BNB",decimals:18},contracts:null,explorer:{name:"Bscscan",url:"https://bscscan.com/",standard:"EIP3091"},defaultRPC:"https://bsc-dataseed1.binance.org/"},{name:"Gnosis Chain",displayName:"Gnosis",id:100,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/gnosis.svg",currency:{name:"xDAI",symbol:"xDAI",decimals:18},contracts:null,explorer:{name:"Blockscout",url:"https://blockscout.com/xdai/mainnet/",standard:"EIP3091"},defaultRPC:"https://rpc.gnosischain.com"},{name:"Fuse Mainnet",displayName:"Fuse",id:122,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fuse.svg",currency:{name:"Fuse",symbol:"FUSE",decimals:18},contracts:null,explorer:{name:"Fuse Explorer",url:"https://explorer.fuse.io/",standard:"EIP3091"},defaultRPC:"https://rpc.fuse.io"},{name:"Huobi ECO Chain Mainnet",displayName:"HECO",id:128,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/heco.svg",currency:{name:"Huobi ECO Chain Native Token",symbol:"HT",decimals:18},contracts:null,explorer:{name:"Hecoinfo",url:"https://hecoinfo.com",standard:"EIP3091"},defaultRPC:"https://http-mainnet.hecochain.com"},{name:"Polygon Mainnet",displayName:"Polygon",id:137,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/polygon.svg",currency:{name:"MATIC",symbol:"MATIC",decimals:18},contracts:null,explorer:{name:"Polygonscan",url:"https://polygonscan.com/",standard:"EIP3091"},defaultRPC:"https://polygon-rpc.com/"},{name:"Fantom Opera",displayName:"Fantom",id:250,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fantom.svg",currency:{name:"Fantom",symbol:"FTM",decimals:18},contracts:null,explorer:{name:"Ftmscan",url:"https://ftmscan.com/",standard:"EIP3091"},defaultRPC:"https://rpc.ftm.tools"},{name:"Metis Andromeda Mainnet",displayName:"Metis",id:1088,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/metis.svg",currency:{name:"Metis",symbol:"METIS",decimals:18},contracts:null,explorer:{name:"Metis Explorer",url:"https://andromeda-explorer.metis.io",standard:"EIP3091"},defaultRPC:"https://andromeda.metis.io/?owner=1088"},{name:"Moonbeam",id:1284,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonbeam.svg",currency:{name:"Glimmer",symbol:"GLMR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonbeam.moonscan.io",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonbeam.network"},{name:"Moonriver",id:1285,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonriver.svg",currency:{name:"Moonriver",symbol:"MOVR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonriver.moonscan.io/",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonriver.moonbeam.network"},{name:"Klaytn Mainnet Cypress",displayName:"Klaytn",id:8217,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/klaytn.svg",currency:{name:"KLAY",symbol:"KLAY",decimals:18},contracts:null,explorer:{name:"Klaytnscope",url:"https://scope.klaytn.com",standard:"EIP3091"},defaultRPC:"https://public-node-api.klaytnapi.com/v1/cypress"},{name:"Hardhat",displayName:"Hardhat",id:31337,type:"testnet",icon:null,currency:{name:"GoChain Coin",symbol:"GO",decimals:18},contracts:null,explorer:null,defaultRPC:"http://127.0.0.1:8545/"},{name:"Arbitrum One",displayName:"Arbitrum",id:42161,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/arbitrum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Arbiscan",url:"https://arbiscan.io/",standard:"EIP3091"},defaultRPC:"https://arbitrum-mainnet.infura.io/v3/"},{name:"Celo Mainnet",displayName:"Celo",id:42220,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/celo.svg",currency:{name:"CELO",symbol:"CELO",decimals:18},contracts:null,explorer:{name:"Celo Explorer",url:"https://explorer.celo.org/",standard:"EIP3091"},defaultRPC:"https://forno.celo.org"},{name:"Emerald Paratime Mainnet",displayName:"Emerald",id:42262,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/emerald.svg",currency:{name:"Emerald Rose",symbol:"ROSE",decimals:18},contracts:null,explorer:{name:"Emerald Explorer",url:"https://explorer.emerald.oasis.dev/",standard:"EIP3091"},defaultRPC:"https://emerald.oasis.dev"},{name:"Avalanche C-Chain",displayName:"Avalanche",id:43114,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/avalanche.svg",currency:{name:"Avalanche",symbol:"AVAX",decimals:18},contracts:null,explorer:{name:"Snowtrace",url:"https://snowtrace.io/",standard:"EIP3091"},defaultRPC:"https://api.avax.network/ext/bc/C/rpc"},{name:"Aurora Mainnet",displayName:"Aurora",id:1313161554,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/aurora.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Aurorascan",url:"https://aurorascan.dev",standard:"EIP3091"},defaultRPC:"https://mainnet.aurora.dev"},{name:"Harmony Mainnet Shard 0",displayName:"Harmony",id:16666e5,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/harmony.svg",currency:{name:"ONE",symbol:"ONE",decimals:18},contracts:null,explorer:{name:"Harmony Block Explorer",url:"https://explorer.harmony.one",standard:"EIP3091"},defaultRPC:"https://api.harmony.one"}],wallets:[{id:"metamask",displayName:"Metamask",icon:null},{id:"binanceChain",displayName:"Binance Chain",icon:null},{id:"coinbase",displayName:"Coinbase",icon:null}],defaults:{networks:{icon:"https://static.tuli.pe/icons/networks/unknown.svg"},wallets:{icon:"TODO"}}};class ae{constructor(e=null){let n={};return e?n=_({...m.style},{...e}):n=m.style,window.addEventListener("load",()=>{const s=document.getElementsByClassName("ve-app");if(s)for(const a of s)a&&a.classList.add(`ve-${n.level}`)}),n}}class re{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.networks.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.name),this._list.push(a)}}for(const n of m.networks)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}add(e){this._list.push(e)}async getCurrent(){if(r.provider.proxy.ethersInstance){const e=await r.provider.getNetwork().then(n=>n.chainId);return this.getById(e)}return null}getById(e){try{e=parseInt(e)}catch{throw"'id' given to getById() method must be an integer or any data type that can be parsed to interger."}return this._list.find(n=>n.id===parseInt(e))}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class oe{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.wallets.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.id),this._list.push(a)}}for(const n of m.wallets)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}getCurrent(){return r.signer.proxy.ethersInstance?this.getById(r.signer.walletId):null}getById(e){return this._list.find(n=>n.id===e)}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class ie{constructor(e=null){let n={};return e?n=_({...m.defaults},{...e}):n=m.defaults,n}}class J{constructor(e=null){this.style=new ae(e?e.style:null),this.networks=new re(e?e.networks:null),this.wallets=new oe(e?e.wallets:null),this.defaults=new ie(e?e.defaults:null)}}class g{constructor(e=null,n=null){console.log("TulipeProxy super");const s=new Proxy(this,{get:function(a,i,l){if(a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0)return typeof a.proxy.ethersInstance[i]=="function"?a.proxy.ethersInstance[i].bind(a.proxy.ethersInstance):a.proxy.ethersInstance[i];if(a.proxy.ethersInstance&&a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0)return typeof a.proxy.extensionInstance[i]=="function"?a.proxy.extensionInstance[i].bind(l):a.proxy.extensionInstance[i];if(a&&a[i]!==void 0)return typeof a[i]=="function"?a[i].bind(l):a[i]},set:function(a,i,l,d){return a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0?(a.proxy.ethersInstance[i]=l,!0):a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0?(a.proxy.extensionInstance[i]=l,!0):(a[i]=l,!0)}});return this.proxy={_changeWatchers:[],onChange:function(a){this._changeWatchers.push(a)},_initIsRunning:!1,_ethersInstance:null,get ethersInstance(){return this._ethersInstance},set ethersInstance(a){const i={...this._ethersInstance};this._ethersInstance=a&&t.markRaw(a);for(const l of this._changeWatchers)l(this._ethersInstance,i);this._initIsRunning||(this._initIsRunning=!0,s._asyncInit().finally(()=>{this._initIsRunning=!1}))},extensionInstance:n},this.proxy.ethersInstance=e,s}}class ce{}class le{constructor(){this._ars={}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class C extends g{constructor(e=null,n=null){super(e,n||new ce),this.status=r._ars.provider.status,this.isSafe=r._ars.provider.isSafe,this.OnSafe=r._ars.provider.OnSafe,this.onSafe=r._ars.provider.onSafe}async _autoInstantiateFromWallet(){let e=null;for(const n of Object.values(r.wallets))if(n.lazyConnectAvailable&&await n.isConnected()){e=n;break}if(e)this.proxy.ethersInstance=e.getProvider();else for(const n of Object.values(r.wallets)){const s=n.getProvider();s&&(this.proxy.ethersInstance=s)}}_autoInstantiateFromDefaultConfig(){const e=r.config.networks.getDefault();e&&e.defaultRPC&&(this.proxy.ethersInstance=new p.ethers.providers.JsonRpcProvider(e.defaultRPC))}async _autoInstantiate(){await this._autoInstantiateFromWallet(),this.proxy.ethersInstance||this._autoInstantiateFromDefaultConfig()}async _checkNetwork(){if(!this.proxy.ethersInstance)throw"._checkNetwork() method must not be called if the ethersInstance is null (if not connected to any network).";const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);if(n)this.status.set("CONNECTED");else if(this.status.set("WRONG_NETWORK"),n=r.config.networks.getAll().find(s=>s.id===e.id),!n){const s={name:e.name,displayName:M(e.name),id:e.chainId};console.log(s),r.config.networks.add(s)}}async _setNetworkSettings(){const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);n&&n&&n.pollingInterval&&(this.pollingInterval=n.pollingInterval)}async _asyncInit(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?(await this._checkNetwork(),await this._setNetworkSettings()):this.status.set("DISCONNECTED")}async changeNetwork(e){const n=await r.config.wallets.getCurrent();n&&r.wallets[n.id].changeNetwork(e)}}class de{}class N extends g{constructor(e=null,n=null){super(e,n||new de),this.walletId=null,this.address=t.ref(null),this.status=r._ars.signer.status,this.isSafe=r._ars.signer.isSafe,this.OnSafe=r._ars.signer.OnSafe,this.onSafe=r._ars.signer.onSafe}async _autoInstantiate(){for(const e of Object.keys(r.wallets))if(r.wallets[e].lazyConnectAvailable&&(await this.connectWallet(e,!0),this.proxy.ethersInstance))break}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?this.address.value=await this.getAddress():this.status.set("DISCONNECTED")}.bind(this))}async connectWallet(e,n=!1){const s=r.wallets[e];if(s.lazyConnectAvailable){if(await s.connect(!0),await s.isConnected())r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED");else if(n){r.signer.status.set("DISCONNECTED");return}}try{this.status.set("REQUESTED"),await s.connect(!1),r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED")}catch(a){if(a instanceof I)this.status.set("REFUSED");else throw this.status.set("ERROR"),a}}disconnectWallet(){r.signer.proxy.ethersInstance=null,this.address.value=null,r.signer.status.set("DISCONNECTED")}}class he{_watch(e,n,s=null){return Object.keys(r.chainWatchers.contracts).includes(this.address)||r.chainWatchers.addContractWatcher(this),r.chainWatchers.contracts[this.address].add(e,n,s)}watch(e,n,s,a=null){const i=this._watch(e,n,s);return a?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)},a):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)}),r.chainWatchers.contracts[this.address].remove.bind(r.chainWatchers.contracts[this.address],e,n,i)}watchRef(e,n,s=null){const a=this._watch(e,n,null);return s?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)},s):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)}),r.chainWatchers.contracts[this.address].getRef(e,n)}}class E extends g{constructor(e,n=null,s=null){console.log("init proxy"),console.log(e),console.log(n),super(n,s||new he),console.log("proxxx"),console.log(this.proxy),this.name=e,this.status=r._ars.contracts[this.name].status,this.isReadSafe=r._ars.contracts[this.name].isReadSafe,this.isWriteSafe=r._ars.contracts[this.name].isWriteSafe,this.OnReadSafe=r._ars.contracts[this.name].OnReadSafe,this.OnWriteSafe=r._ars.contracts[this.name].OnWriteSafe,this.onReadSafe=r._ars.contracts[this.name].onReadSafe,this.onWriteSafe=r._ars.contracts[this.name].onWriteSafe,console.log("proxxx 2"),console.log(this.proxy)}onSafe(e){throw"TulipeContract instances don't have 'onSafe()' method, use 'onReadSafe()' and 'onWriteSafe()' instead."}async _asyncInit(){console.log("proxxx 3"),console.log(this.proxy),r.provider.onSafe(async function(){this.proxy.ethersInstance?(this.name="TODO",this.status.set("INITIALIZED")):(console.log(this.proxy),console.log("marked as UNVAILABLE !"),this.status.set("UNAVAILABLE"))}.bind(this))}}class pe{}class fe extends le{constructor(){super(),this.contractName=null,this.methodName=null,this.methodInfos={},this.args=t.ref(args),this.txArgs=t.ref(txArgs),this.data=t.ref([]),this.error=t.ref(null),this.call=null,this.status=new w(`tx:${contractName}:${methodName}`,["NOT_READY","READY","SENT","ERROR","SUCCESS"])}initARS(){this.status.watch(["ERROR","SUCCESS"],()=>{setTimeout(()=>{this.status.set("READY")},3e3)})}_asyncInit(){this.proxy._initIsRunning=!0,r.contracts[this.contractName].isReadSafe.value&&this._initEthersInstance(),r.contracts[this.contractName].onReadSafe(()=>{this._initEthersInstance()}),this.initARS(),this.proxy._initIsRunning=!1}_initEthersInstance(){this.methodInfos=r.contracts[this.contractName].interface.functions[this.methodName],this.methodInfos.inputs.forEach(e=>this.args.value.push(null)),this.methodInfos.outputs.forEach(e=>this.data.value.push(null)),this.proxy.ethersInstance=r.contracts[this.contractName][this.methodName],this.status.set("READY")}send(e=null,n=null){e=e&&e.length>0?e:S(this.args),e?Array.isArray(e)?this.call=this.proxy.ethersInstance(...e,n):this.call=this.proxy.ethersInstance(e,n):this.call=this.proxy.ethersInstance(n),this.status.set("SENT"),this.methodInfos.constant?this.call.then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR")}):this.call.then(s=>s.wait()).then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR"),console.log(s)})}}class U extends g{constructor(e,n,s=[],a={value:0},i=null,l=null,d=null){super(i,l||new pe,d||new fe(e,n,s=[],a={value:0})),this._asyncInit()}}const ue={JsonRpcProvider:p.ethers.providers.JsonRpcProvider,StaticJsonRpcProvider:p.ethers.providers.StaticJsonRpcProvider,EtherscanProvider:p.ethers.providers.EtherscanProvider,InfuraProvider:p.ethers.providers.InfuraProvider,AlchemyProvider:p.ethers.providers.AlchemyProvider,CloudflareProvider:p.ethers.providers.CloudflareProvider,PocketProvider:p.ethers.providers.PocketProvider,AnkrProvider:p.ethers.providers.AnkrProvider,FallbackProvider:p.ethers.providers.FallbackProvider,IpcProvider:p.ethers.providers.IpcProvider,JsonRpcBatchProvider:p.ethers.providers.JsonRpcBatchProvider,UrlJsonRpcProvider:p.ethers.providers.UrlJsonRpcProvider,Web3Provider:p.ethers.providers.Web3Provider,WebSocketProvider:p.ethers.providers.WebSocketProvider},Y={};for(const[o,e]of Object.entries(ue))Y[o]=class extends e{constructor(...n){let s=C;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof C&&(s=n.pop()),super(...n),new s(this)}};const me={Wallet:p.ethers.Wallet,VoidSigner:p.ethers.VoidSigner},Z={};for(const[o,e]of Object.entries(me))Z[o]=class extends e{constructor(...n){let s=N;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof N&&(s=n.pop()),super(...n),new s(this)}};const ye={Contract:p.ethers.Contract},Q={};for(const[o,e]of Object.entries(ye))Q[o]=class extends e{constructor(...n){let s=E;n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof E&&(s=n.pop()),super(...n);const a=new s(this);return console.log(a),a}};const _e={...Y,...Z,...Q},X={...p.ethers};for(const[o,e]of Object.entries(_e))X[o]=e;class v{constructor(){this.lastUpdateBlock=0,this.sources={}}_generateDependentUUID(){return"xxxxxxxx".replace(/[xy]/g,function(e){var n=Math.random()*16|0,s=e=="x"?n:n&3|8;return s.toString(16)})}async requiresUpdate(){if(!r.provider.isSafe.value)return!1;const e=await r.provider.getBlockNumber();return this.lastUpdateBlock0)return!0}catch{}return!1}getProvider(){return this.exposedObject?new p.ethers.providers.Web3Provider(this.exposedObject,"any"):null}async getSigner(){if(this.exposedObject){const e=this.getProvider();if(e)return await e.getSigner()}return null}async connect(e=!1){if(this.exposedObject){if(await this.isConnected()||e)return;try{await this.exposedObject.request({method:"eth_requestAccounts"})}catch(n){throw n.code===4001?new I(this.id):n}}throw"exposedObject not available"}async addNetwork(e){const n=r.config.networks.getById(e);await this.exposedObject.request({method:"wallet_addEthereumChain",params:[{chainId:e,rpcUrls:[n.defaultRPC],chainName:n.name,nativeCurrency:{name:n.currency.symbol,symbol:n.currency.symbol,decimals:n.currency.decimals},blockExplorerUrls:n.explorer&&n.explorer.url!==""?[n.explorer.url]:null}]})}async changeNetwork(e,n=!1){if(r.config.networks.getById(e)){e=p.ethers.utils.hexlify(parseInt(e)).toString(),e=p.ethers.utils.hexValue(e);try{await this.exposedObject.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(a){if(a.code===4902)this.addNetwork(e);else throw a}}}}class Se extends st{constructor(){super("metamask",window.ethereum)}}class we extends nt{constructor(e,n={}){super(),this.id="coinbase";const s=n.appName||"",a=n.appLogoUrl,i=n.darkMode||!1;this.coinbaseWalletSdk=new e({appName:s,appLogoUrl:a,darkMode:i}),this.provider=this.getProvider()}getProvider(){try{return this.coinbaseWalletSdk.makeWeb3Provider()}catch(e){return console.log(e),null}}async connect(){try{await this.provider.send("eth_requestAccounts")}catch{throw I(this.id)}}}class ge extends st{constructor(){super("binanceChain",window.BinanceChain),this.lazyConnectAvailable=!1}async isConnected(){throw new y("isConnected() method is not available for BinanceChainWallet class since lazy connection is not available.")}async connect(e=!1){if(e)throw new y("connect() with 'lazy=true' is not available for BinanceChainWallet class because isConnected() is not available on this class.")}}const at={metamask:Se,coinbase:we,binanceChain:ge};class Ee{constructor(){this.status=new w("dapp",["UNSAFE","ERROR","INITIALIZED"]),this.isSafe=t.computed(()=>this.status.is("INITIALIZED")),this.OnSafe=D}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class j{constructor(){this._ars={oldEthersInstance:null,events:{},watchers:[]}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(e){this._purgeARS(),e.proxy.ethersInstance&&(console.log("instance ARS"),console.log(e),this._initEthersInstanceARS()),this._initPlaceholderInstanceARS()}start(e){this._initARS(e),e.proxy.onChange(this._initARS.bind(this,e))}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class ke extends j{constructor(){super(),this.status=new w("provider",["DISCONNECTED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.isSafe.value&&!this.status.isIn(["DISCONNECTED","ERROR"])),this.OnSafe=V}_initEthersInstanceARS(){r.provider.on("network",(e,n)=>{n&&n!==e&&window.location.reload()}),r.provider.on("error",()=>{this.status.set("ERROR")})}_initPlaceholderInstanceARS(){}start(){super.start(r.provider)}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ce extends j{constructor(){super(),this.status=new w("signer",["NO_PROVIDER","DISCONNECTED","REQUESTED","REFUSED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("CONNECTED")),this.OnSafe=A}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}start(){super.start(r.signer)}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ne extends j{constructor(e){super(),this.name=e,this.status=new w(`contract:${e}`,["NO_PROVIDER","UNAVAILABLE","ERROR","INITIALIZED"]),this.isReadSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("INITIALIZED")),this.isWriteSafe=t.computed(()=>r.signer.isSafe.value&&this.status.is("INITIALIZED")),this.OnReadSafe=t.createVNode(T,{contract:e}),this.OnWriteSafe=t.createVNode(W,{contract:e})}onReadSafe(e){const n=t.getCurrentInstance();if(this.isReadSafe.value)e(n);else{const s=t.watch(this.isReadSafe,()=>{this.isReadSafe.value&&(e(n),s())})}}onWriteSafe(e){const n=t.getCurrentInstance();if(this.isWriteSafe.value)e(n);else{const s=t.watch(this.isWriteSafe,()=>{this.isWriteSafe.value&&(e(n),s())})}}_updateContract(e,n){if(r.signer.isSafe.value)r.contracts[this.name].proxy.ethersInstance=new p.ethers.Contract(e,n,r.signer.proxy.ethersInstance);else if(r.provider.isSafe.value)r.contracts[this.name].proxy.ethersInstance=new p.ethers.Contract(e,n,r.provider.proxy.ethersInstance);else throw`_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`}_initEthersInstanceARS(){this._ars.watchers.push(t.watch(r.signer.isSafe,(e,n)=>{if(e!==n){const s=r.contracts[this.name].proxy.ethersInstance.interface,a=r.contracts[this.name].proxy.ethersInstance.address;this._updateContract(a,s)}}))}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?(console.log("UNAVVS"),this.status.set("UNAVAILABLE")):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")})}start(){super.start(r.contracts[this.name])}}class Ie{constructor(e){for(const n of r.config.networks.getAll())if(n.contracts)for(const[s,a]of Object.entries(n.contracts))this.add(s)}add(e){this[e]=new Ne(e)}}class rt{constructor(){this.dapp=new Ee,this.provider=new ke,this.signer=new Ce,this.contracts=new Ie}}async function Re(o,e){const n=e;try{r.init(n)}catch(a){throw r&&r.status&&r.status.set("ERROR"),a}o.config.globalProperties.dapp=r,o.config.globalProperties.rGet=S,o.config.globalProperties.rSet=u,window.dapp=r;const s=await Promise.resolve().then(()=>se);o.component("OnDappSafe",s.OnDappSafe),o.component("OnProviderSafe",s.OnProviderSafe),o.component("OnSignerSafe",s.OnSignerSafe),o.component("OnContractReadSafe",s.OnContractReadSafe),o.component("OnContractWriteSafe",s.OnContractWriteSafe),r.status.set("INITIALIZED")}return c.ARS=rt,c.ConnectWalletButton=q,c.ContractInteractor=L,c.ContractWatcher=tt,c.DebugBar=K,c.EventInteractor=B,c.EventsInteractor=x,c.InputUnits=$,c.MethodInteractor=O,c.MethodsInteractor=b,c.OnContractReadSafe=T,c.OnContractWriteSafe=W,c.OnDappSafe=D,c.OnProviderSafe=V,c.OnSignerSafe=A,c.SelectNetworkDropdown=H,c.SelectWalletDropdown=G,c.Status=w,c.Transact=P,c.TulipeConfig=J,c.TulipeContractProxy=E,c.TulipeProviderProxy=C,c.TulipeProxy=g,c.TulipeSignerProxy=N,c.TulipeTransactionProxy=U,c.WalletConnectionRejected=I,c.WalletWatcher=et,c.capitalizeWords=M,c.dapp=r,c.deepMerge=_,c.initTulipe=Re,c.isObject=k,c.rGet=S,c.rSet=u,c.styleLevelProp=R,c.tulipeEthers=X,c.wallets=at,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),c}({},vue,ethers); diff --git a/dist/tulipe.umd.js b/dist/tulipe.umd.js index a05d7c05..53f00389 100644 --- a/dist/tulipe.umd.js +++ b/dist/tulipe.umd.js @@ -1 +1 @@ -(function(c,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("ethers")):typeof define=="function"&&define.amd?define(["exports","vue","ethers"],t):(c=typeof globalThis<"u"?globalThis:c||self,t(c.Tulipe={},c.vue,c.ethers))})(this,function(c,t,p){"use strict";class it{constructor(){const e=r.config.wallets.getAvailable();for(const n of e){const s=st[n.id];s&&(this[n.id]=new s)}}}class ct{constructor(){for(const e of r.config.networks.getAll())if(e.contracts)for(const[n,s]of Object.entries(e.contracts));}getAll(){const e={};for(const[n,s]of Object.entries(this))s instanceof C&&(e[n]=s);return e}}class lt{constructor(){this.contracts={},this.wallets={}}async _asyncInit(){r.provider.onSafe(()=>{r.provider.on("block",async function(e){const n=await r.provider.getBlockWithTransactions(e);for(const s of n.transactions)Object.keys(this.contracts).includes(s.to)?this.contracts[s.to].update():Object.keys(this.wallets).includes(s.to)&&this.wallets[s.to].update(),Object.keys(this.contracts).includes(s.from)?this.contracts[s.from].update():Object.keys(this.wallets).includes(s.from)&&this.wallets[s.from].update()})})}addContractWatcher(e){Object.keys(this.contracts).includes(e.address)||(this.contracts[e.address]=new v(e))}removeContractWatcher(e){Object.keys(this.contracts).includes(e.address)&&delete this.contracts[e.address]}addWalletWatcher(e){Object.keys(this.wallets).includes(e)||(this.wallets[e]=new tt(e))}removeContractWatcher(e){Object.keys(this.wallets).includes(e)&&delete this.wallets[e]}}class dt{constructor(){}init(e=null){this.config=new K(e),this._ars=new rt,this.status=this._ars.dapp.status,this.isSafe=this._ars.dapp.isSafe,this.OnSafe=this._ars.dapp.OnSafe,this.onSafe=this._ars.dapp.onSafe,this.chainWatchers=new lt,this.wallets=new it,this.contracts=new ct,this.provider=new k,this._ars.provider.init(),this.signer=new N,this._ars.signer.init(),this.pro=this.provider,this.sig=this.signer,this.con=this.contracts}}const r=new dt;function E(o){return o&&typeof o=="object"&&!Array.isArray(o)}function _(o,...e){if(!e.length)return o;const n=e.shift();if(E(o)&&E(n))for(const s in n)E(n[s])?(o[s]||Object.assign(o,{[s]:{}}),_(o[s],n[s])):Object.assign(o,{[s]:n[s]});return _(o,...e)}function U(o){const e=o.split(" ");for(let n=0;n{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",ht,[t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Address : "+t.toDisplayString(t.unref(n).address),1),t.createElementVNode("li",null,"Owner : "+t.toDisplayString(t.unref(s)),1),t.createElementVNode("li",null,[pt,ft,t.createVNode(t.unref(b),{contract:e.contract},null,8,["contract"])]),t.createElementVNode("li",null,[ut,mt,t.createVNode(t.unref(x),{contract:e.contract},null,8,["contract"])])])])]),_:1},8,["contract"])}}},yt={class:"MethodsInteractor"},b={__name:"MethodsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",yt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.functions,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(O),{contract:e.contract,method:d},null,8,["contract","method"])]))),256))])])]),_:1},8,["contract"])}}},_t={class:"MethodInteractor"},St={key:0},wt=t.createElementVNode("p",null,"Inputs :",-1),gt=["onUpdate:modelValue","placeholder"],Et={key:0},kt={key:1},Nt=t.createElementVNode("p",null,"Outputs :",-1),Ct=["onUpdate:modelValue","placeholder"],It=["placeholder"],Rt={key:2},O={__name:"MethodInteractor",props:{contract:{type:String,required:!0},method:{type:String,required:!0}},setup(o){const e=o,n=t.shallowRef(new j(e.contract,e.method));function s(a){return`${a.name&&a.name!=="null"?a.name:""} (${a.type})`}return(a,i)=>{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",_t,[t.createVNode(t.unref(D),{contract:e.contract,method:e.method,modelValue:t.unref(n),"onUpdate:modelValue":i[0]||(i[0]=d=>t.isRef(n)?n.value=d:null),configs:{content:e.method,notx:!0,noerror:!0}},null,8,["contract","method","modelValue","configs"]),t.createElementVNode("small",null,t.toDisplayString(t.unref(n).methodInfos.stateMutability),1),Object.keys(t.unref(n).methodInfos.inputs).length>0||t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("div",St,[wt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.inputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.withDirectives(t.createElementVNode("input",{"onUpdate:modelValue":f=>t.unref(n).args.value[h]=f,type:"text",placeholder:s(d)},null,8,gt),[[t.vModelText,t.unref(n).args.value[h]]]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).args.value[h])+" "+t.toDisplayString(typeof t.unref(n).args.value[h]),1)]))),256)),t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("li",Et,[t.createVNode(t.unref($),{modelValue:t.unref(n).txArgs.value.value,"onUpdate:modelValue":i[1]||(i[1]=d=>t.unref(n).txArgs.value.value=d)},null,8,["modelValue"]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).txArgs.value.value)+" "+t.toDisplayString(typeof t.unref(n).txArgs.value.value),1)])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0),Object.keys(t.unref(n).methodInfos.outputs).length>0?(t.openBlock(),t.createElementBlock("div",kt,[Nt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.outputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.unref(n).data.value?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:0,"onUpdate:modelValue":f=>t.unref(n).data.value[h]=f,type:"text",placeholder:s(d),disabled:""},null,8,Ct)),[[t.vModelText,t.unref(n).data.value[h]]]):(t.openBlock(),t.createElementBlock("input",{key:1,type:"text",placeholder:s(d),disabled:""},null,8,It))]))),256))])])):t.createCommentVNode("",!0),t.unref(n).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Rt,t.toDisplayString(t.unref(n).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},bt={class:"EventsInteractor"},x={__name:"EventsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",bt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.events,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(B),{contract:e.contract,event:d},null,8,["contract","event"])]))),256))])])]),_:1},8,["contract"])}}},Ot={class:"EventInteractor"},xt=t.createTextVNode("Logs: "),B={__name:"EventInteractor",props:{contract:{type:String,required:!0},event:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];let s=t.ref({}),a=t.ref({}),i=t.ref(0),l=t.ref([]);return n.onReadSafe(()=>{s.value=n.interface.events[e.event],a.value=n.filters[s.value.name],n.on(a.value,d=>{i.value++;let h=`Block ${d.blockNumber} -> {`;for(const f of s.value.inputs)h+=`${f.name}:${d.args[f.name]}, `;h=h.substring(0,h.length-2)+"}",l.value.push(h)})}),(d,h)=>{const f=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(f,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Ot,[t.createElementVNode("p",null,t.toDisplayString(t.unref(s).name),1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Count : "+t.toDisplayString(t.unref(i)),1),t.createElementVNode("li",null,[xt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(l),ot=>(t.openBlock(),t.createElementBlock("li",null,t.toDisplayString(ot),1))),256))])])])])]),_:1},8,["contract"])}}},Bt={class:"TransactButton"},Dt={key:1,disabled:""},Pt={key:2,disabled:""},Vt={key:3,disabled:""},Tt={key:4},D={__name:"Transact",props:{modelValue:{},contract:{type:String,required:!0},method:{type:String,required:!0},args:{type:Array,required:!1},txArgs:{type:Object,required:!1},configs:{type:Object,required:!1}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o,s=r.contracts[n.contract];let a=t.computed({get(){return n.modelValue},set(l){e("update:modelValue",l)}});function i(){const l=n.args?n.args:[],d=n.txArgs?n.txArgs:{};a.value.send(l,d)}return n.config&&n.configs.notx&&s.onReadSafe(()=>{a=new j(n.contract,n.method)}),(l,d)=>{const h=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(h,{contract:n.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Bt,[t.unref(a).status.is("READY")?(t.openBlock(),t.createElementBlock("button",{key:0,onClick:i},t.toDisplayString(n.configs&&n.configs.content?n.configs.content:"Transact"),1)):t.unref(a).status.is("SENT")?(t.openBlock(),t.createElementBlock("button",Dt,"Transaction sent...")):t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("button",Pt,"Transaction error!")):t.unref(a).status.is("SUCCESS")?(t.openBlock(),t.createElementBlock("button",Vt,"Success !")):t.createCommentVNode("",!0),!(n.configs&&n.configs.noerror)&&t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Tt,t.toDisplayString(t.unref(a).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},Oe="",L=(o,e)=>{const n=o.__vccOpts||o;for(const[s,a]of e)n[s]=a;return n},F=L({__name:"ConnectWalletButton",props:{styleLevel:R},setup(o){const e=o;return(n,s)=>(t.openBlock(),t.createBlock(t.unref(r).provider.OnSafe,null,{default:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass(["ConnectWalletButton",`ve-${e.styleLevel}`])},null,2)]),_:1}))}},[["__scopeId","data-v-a10b4efb"]]),At={class:"SelectWalletDropdown"},Wt={key:0},$t=[t.createElementVNode("p",null,"Connection requested...",-1)],jt={key:1},Ut=[t.createElementVNode("p",null,"Connection refused!",-1)],Mt={key:2},Lt=[t.createElementVNode("p",null,"Select a wallet",-1)],Ft=["src","alt"],qt=["onClick"],Gt=["src","alt"],q={__name:"SelectWalletDropdown",setup(o){let e=t.ref(null),n=t.ref([]),s=t.ref(!1),a=t.ref({});r.onSafe(async function(){n.value=r.config.wallets.getAvailable()}),r.provider.onSafe(async function(){a.value=await r.config.networks.getCurrent()}),r.signer.onSafe(async function(){e.value=await r.config.wallets.getCurrent(),n.value=r.config.wallets.getAvailable().filter(l=>l.id!==e.value.id)});function i(){s.value=!s.value}return(l,d)=>{const h=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(h,null,{default:t.withCtx(()=>[t.createElementVNode("div",At,[t.createElementVNode("ul",null,[t.unref(r).signer.status.is("REQUESTED")?(t.openBlock(),t.createElementBlock("li",Wt,$t)):t.unref(r).signer.status.is("REFUSED")?(t.openBlock(),t.createElementBlock("li",jt,Ut)):t.unref(r).provider.status.is("WRONG_NETWORK")?(t.openBlock(),t.createElementBlock("li",Mt,[t.createElementVNode("p",null,"Wrong network! ("+t.toDisplayString(t.unref(a)?t.unref(a).displayName:"unknown")+")",1)])):t.unref(r).signer.status.is("DISCONNECTED")||!t.unref(e)?(t.openBlock(),t.createElementBlock("li",{key:3,onClick:i},Lt)):t.unref(r).signer.status.is("CONNECTED")?(t.openBlock(),t.createElementBlock("li",{key:4,onClick:i},[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.wallets.icon,alt:t.unref(e).displayName+" logo"},null,8,Ft),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):t.createCommentVNode("",!0),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:5},t.renderList(t.unref(n),f=>(t.openBlock(),t.createElementBlock("li",{key:f.id,onClick:ot=>t.unref(r).signer.connectWallet(f.id)},[t.createElementVNode("img",{width:"40",src:f.icon?f.icon:t.unref(r).config.defaults.wallets.icon,alt:f.displayName+" logo"},null,8,Gt),t.createElementVNode("p",null,t.toDisplayString(f.displayName),1)],8,qt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},Ht={class:"SelectNetworkDropdown"},zt={key:0},Kt=["src","alt"],Jt={key:1},Yt=[t.createElementVNode("p",null,"Select a network",-1)],Zt=["onClick"],Qt=["src","alt"],G={__name:"SelectNetworkDropdown",setup(o){let e=t.ref({}),n=t.ref([]),s=t.ref(!1);r.onSafe(async function(){n.value=r.config.networks.getAvailable()}),r.provider.onSafe(async function(){e.value=await r.config.networks.getCurrent(),n.value=r.config.networks.getAvailable().filter(i=>i.id!==e.value.id)});function a(){s.value=!s.value}return(i,l)=>{const d=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(d,null,{default:t.withCtx(()=>[t.createElementVNode("div",Ht,[t.createElementVNode("ul",{onClick:a},[t.unref(e)?(t.openBlock(),t.createElementBlock("li",zt,[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.networks.icon,alt:t.unref(e).displayName+" logo"},null,8,Kt),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):(t.openBlock(),t.createElementBlock("li",Jt,Yt)),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:2},t.renderList(t.unref(n),h=>(t.openBlock(),t.createElementBlock("li",{key:h.id,onClick:f=>t.unref(r).provider.changeNetwork(h.id)},[t.createElementVNode("img",{width:"40",src:h.icon?h.icon:t.unref(r).config.defaults.networks.icon,alt:h.displayName+" logo"},null,8,Qt),t.createElementVNode("p",null,t.toDisplayString(h.displayName),1)],8,Zt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},P={__name:"OnDappSafe",setup(o){return(e,n)=>t.unref(r).isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},V={__name:"OnProviderSafe",setup(o){return(e,n)=>t.unref(r).provider.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},T={__name:"OnSignerSafe",setup(o){return(e,n)=>t.unref(r).signer.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},A={__name:"OnContractReadSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isReadSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},W={__name:"OnContractWriteSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isWriteSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},Te="",H=o=>(t.pushScopeId("data-v-a24ac687"),o=o(),t.popScopeId(),o),Xt=H(()=>t.createElementVNode("h3",null,"Safe Runners",-1)),vt=H(()=>t.createElementVNode("h3",null,"Status",-1)),z=L({__name:"DebugBar",setup(o){return(e,n)=>{const s=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(s,null,{default:t.withCtx(()=>[t.createElementVNode("section",null,[t.createElementVNode("div",null,[Xt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"DApp safe : "+t.toDisplayString(t.unref(r).isSafe),1),t.createElementVNode("li",null,"Provider safe : "+t.toDisplayString(t.unref(r).provider.isSafe),1),t.createElementVNode("li",null,"Signer safe : "+t.toDisplayString(t.unref(r).signer.isSafe),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null,[t.createTextVNode(" contract "+t.toDisplayString(i)+" : ",1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"read safe : "+t.toDisplayString(a.isReadSafe),1),t.createElementVNode("li",null,"write safe : "+t.toDisplayString(a.isWriteSafe),1)])]))),256))])]),t.createElementVNode("div",null,[vt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"dapp : "+t.toDisplayString(t.unref(r).status.get()),1),t.createElementVNode("li",null,"provider : "+t.toDisplayString(t.unref(r).provider.status.get()),1),t.createElementVNode("li",null,"signer : "+t.toDisplayString(t.unref(r).signer.status.get()),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null," contract "+t.toDisplayString(i)+" : "+t.toDisplayString(a.status.get()),1))),256))])])])]),_:1})}}},[["__scopeId","data-v-a24ac687"]]),te={class:"InputUnits"},ee=["placeholder"],ne=["value"],$={__name:"InputUnits",props:{modelValue:{},placeholder:{type:String}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o;let s=t.ref(null);const a=["wei","gwei","ether"];let i=t.ref("wei");function l(){if(s.value){const d=p.ethers.utils.parseUnits(s.value,i.value);e("update:modelValue",d)}}return(d,h)=>(t.openBlock(),t.createElementBlock("div",te,[t.withDirectives(t.createElementVNode("input",{onInput:l,"onUpdate:modelValue":h[0]||(h[0]=f=>t.isRef(s)?s.value=f:s=f),type:"text",placeholder:t.unref(n).placeholder},null,40,ee),[[t.vModelText,t.unref(s)]]),t.withDirectives(t.createElementVNode("select",{onChange:l,"onUpdate:modelValue":h[1]||(h[1]=f=>t.isRef(i)?i.value=f:i=f)},[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(a,f=>t.createElementVNode("option",{value:f},t.toDisplayString(f),9,ne)),64))],544),[[t.vModelSelect,t.unref(i)]])]))}},se=Object.freeze(Object.defineProperty({__proto__:null,InputUnits:$,styleLevelProp:R,ContractInteractor:M,MethodsInteractor:b,MethodInteractor:O,EventsInteractor:x,EventInteractor:B,Transact:D,ConnectWalletButton:F,SelectWalletDropdown:q,SelectNetworkDropdown:G,OnDappSafe:P,OnProviderSafe:V,OnSignerSafe:T,OnContractReadSafe:A,OnContractWriteSafe:W,DebugBar:z},Symbol.toStringTag,{value:"Module"}));class w{constructor(e,n){if(this._name=e,this.states=[],!Array.isArray(n))throw`The 'states' parameter of a Status instance '${e}' must an array of strings. Got: ${n}`;for(const s of n)this.states.push(this._formatState(s));this._state=t.ref(this.states[0])}_formatState(e){return e.toString().toUpperCase()}_isStateValid(e){return!!this.states.includes(this._formatState(e))}_areStatesValid(e){for(const n of e)if(!this._isStateValid(n))return!1;return!0}get(){return S(this._state)}getRef(){return this._state}set(e){if(e=this._formatState(e),!this._isStateValid(e))throw`The state given to the set() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;u(this._state,e),console.log(`Status '${this._name}' set to '${S(this._state)}'`)}is(e){if(!this._isStateValid(e))throw`The state given to the is() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;return this.get()==this._formatState(e)}isIn(e){if(!this._areStatesValid(e))throw`The states given to the isIn() method of Status instance '${this._name}' must be an array with values in ${this.states}. Got: ${e}`;for(const n of e)if(this.is(n))return!0;return!1}watch(e,n){let s=`The states given to the watch() method of Status instance '${this._name}' must be a string or an array with values in ${this.states}. Got: ${e}`;if(Array.isArray(e)){if(!this._areStatesValid(e))throw s;return t.watch(this._state,()=>{this.isIn(e)&&n(this.get())})}else{if(!this._isStateValid(e))throw s;return t.watch(this._state,()=>{this.is(e)&&n(this.get())})}}watchAny(e){return this.watch(this.states,e)}}const m={style:{level:"minimal"},networks:[{name:"Ethereum Mainnet",displayName:"Ethereum",id:1,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/ethereum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.infura.io/v3/"},{name:"Ropsten",displayName:"Ropsten (Ethereum Testnet)",id:3,type:"testnet",icon:null,currency:{name:"Ropsten Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://ropsten.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://ropsten.infura.io/v3/"},{name:"Rinkeby",displayName:"Rinkeby (Ethereum Testnet)",id:4,type:"testnet",icon:null,currency:{name:"Rinkeby Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://rinkeby.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://rinkeby.infura.io/v3/"},{name:"G\xF6rli",displayName:"G\xF6rli (Ethereum Testnet)",id:5,type:"testnet",icon:null,currency:{name:"G\xF6rli Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://goerli.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://goerli.infura.io/v3/"},{name:"Optimism",id:10,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/optimism.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://optimistic.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.optimism.io/"},{name:"Cronos Mainnet Beta",displayName:"Cronos",id:25,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/cronos.svg",currency:{name:"Cronos",symbol:"CRO",decimals:18},contracts:null,explorer:{name:"Cronos Explorer",url:"https://cronos.org/explorer",standard:"EIP3091"},defaultRPC:"https://evm.cronos.org"},{name:"Telos EVM Mainnet",displayName:"Telos",id:40,type:"mainnet",icon:null,currency:{name:"Telos",symbol:"TLOS",decimals:18},contracts:null,explorer:{name:"Teloscan",url:"https://teloscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.telos.net/evm"},{name:"Binance Smart Chain Mainnet",displayName:"BSC",id:56,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/bsc.svg",currency:{name:"Binance Chain Native Token",symbol:"BNB",decimals:18},contracts:null,explorer:{name:"Bscscan",url:"https://bscscan.com/",standard:"EIP3091"},defaultRPC:"https://bsc-dataseed1.binance.org/"},{name:"Gnosis Chain",displayName:"Gnosis",id:100,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/gnosis.svg",currency:{name:"xDAI",symbol:"xDAI",decimals:18},contracts:null,explorer:{name:"Blockscout",url:"https://blockscout.com/xdai/mainnet/",standard:"EIP3091"},defaultRPC:"https://rpc.gnosischain.com"},{name:"Fuse Mainnet",displayName:"Fuse",id:122,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fuse.svg",currency:{name:"Fuse",symbol:"FUSE",decimals:18},contracts:null,explorer:{name:"Fuse Explorer",url:"https://explorer.fuse.io/",standard:"EIP3091"},defaultRPC:"https://rpc.fuse.io"},{name:"Huobi ECO Chain Mainnet",displayName:"HECO",id:128,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/heco.svg",currency:{name:"Huobi ECO Chain Native Token",symbol:"HT",decimals:18},contracts:null,explorer:{name:"Hecoinfo",url:"https://hecoinfo.com",standard:"EIP3091"},defaultRPC:"https://http-mainnet.hecochain.com"},{name:"Polygon Mainnet",displayName:"Polygon",id:137,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/polygon.svg",currency:{name:"MATIC",symbol:"MATIC",decimals:18},contracts:null,explorer:{name:"Polygonscan",url:"https://polygonscan.com/",standard:"EIP3091"},defaultRPC:"https://polygon-rpc.com/"},{name:"Fantom Opera",displayName:"Fantom",id:250,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fantom.svg",currency:{name:"Fantom",symbol:"FTM",decimals:18},contracts:null,explorer:{name:"Ftmscan",url:"https://ftmscan.com/",standard:"EIP3091"},defaultRPC:"https://rpc.ftm.tools"},{name:"Metis Andromeda Mainnet",displayName:"Metis",id:1088,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/metis.svg",currency:{name:"Metis",symbol:"METIS",decimals:18},contracts:null,explorer:{name:"Metis Explorer",url:"https://andromeda-explorer.metis.io",standard:"EIP3091"},defaultRPC:"https://andromeda.metis.io/?owner=1088"},{name:"Moonbeam",id:1284,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonbeam.svg",currency:{name:"Glimmer",symbol:"GLMR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonbeam.moonscan.io",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonbeam.network"},{name:"Moonriver",id:1285,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonriver.svg",currency:{name:"Moonriver",symbol:"MOVR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonriver.moonscan.io/",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonriver.moonbeam.network"},{name:"Klaytn Mainnet Cypress",displayName:"Klaytn",id:8217,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/klaytn.svg",currency:{name:"KLAY",symbol:"KLAY",decimals:18},contracts:null,explorer:{name:"Klaytnscope",url:"https://scope.klaytn.com",standard:"EIP3091"},defaultRPC:"https://public-node-api.klaytnapi.com/v1/cypress"},{name:"Hardhat",displayName:"Hardhat",id:31337,type:"testnet",icon:null,currency:{name:"GoChain Coin",symbol:"GO",decimals:18},contracts:null,explorer:null,defaultRPC:"http://127.0.0.1:8545/"},{name:"Arbitrum One",displayName:"Arbitrum",id:42161,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/arbitrum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Arbiscan",url:"https://arbiscan.io/",standard:"EIP3091"},defaultRPC:"https://arbitrum-mainnet.infura.io/v3/"},{name:"Celo Mainnet",displayName:"Celo",id:42220,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/celo.svg",currency:{name:"CELO",symbol:"CELO",decimals:18},contracts:null,explorer:{name:"Celo Explorer",url:"https://explorer.celo.org/",standard:"EIP3091"},defaultRPC:"https://forno.celo.org"},{name:"Emerald Paratime Mainnet",displayName:"Emerald",id:42262,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/emerald.svg",currency:{name:"Emerald Rose",symbol:"ROSE",decimals:18},contracts:null,explorer:{name:"Emerald Explorer",url:"https://explorer.emerald.oasis.dev/",standard:"EIP3091"},defaultRPC:"https://emerald.oasis.dev"},{name:"Avalanche C-Chain",displayName:"Avalanche",id:43114,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/avalanche.svg",currency:{name:"Avalanche",symbol:"AVAX",decimals:18},contracts:null,explorer:{name:"Snowtrace",url:"https://snowtrace.io/",standard:"EIP3091"},defaultRPC:"https://api.avax.network/ext/bc/C/rpc"},{name:"Aurora Mainnet",displayName:"Aurora",id:1313161554,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/aurora.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Aurorascan",url:"https://aurorascan.dev",standard:"EIP3091"},defaultRPC:"https://mainnet.aurora.dev"},{name:"Harmony Mainnet Shard 0",displayName:"Harmony",id:16666e5,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/harmony.svg",currency:{name:"ONE",symbol:"ONE",decimals:18},contracts:null,explorer:{name:"Harmony Block Explorer",url:"https://explorer.harmony.one",standard:"EIP3091"},defaultRPC:"https://api.harmony.one"}],wallets:[{id:"metamask",displayName:"Metamask",icon:null},{id:"binanceChain",displayName:"Binance Chain",icon:null},{id:"coinbase",displayName:"Coinbase",icon:null}],defaults:{networks:{icon:"https://static.tuli.pe/icons/networks/unknown.svg"},wallets:{icon:"TODO"}}};class ae{constructor(e=null){let n={};return e?n=_({...m.style},{...e}):n=m.style,window.addEventListener("load",()=>{const s=document.getElementsByClassName("ve-app");if(s)for(const a of s)a&&a.classList.add(`ve-${n.level}`)}),n}}class re{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.networks.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.name),this._list.push(a)}}for(const n of m.networks)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}add(e){this._list.push(e)}async getCurrent(){if(r.provider.proxy.ethersInstance){const e=await r.provider.getNetwork().then(n=>n.chainId);return this.getById(e)}return null}getById(e){try{e=parseInt(e)}catch{throw"'id' given to getById() method must be an integer or any data type that can be parsed to interger."}return this._list.find(n=>n.id===parseInt(e))}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class oe{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.wallets.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.id),this._list.push(a)}}for(const n of m.wallets)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}getCurrent(){return r.signer.proxy.ethersInstance?this.getById(r.signer.walletId):null}getById(e){return this._list.find(n=>n.id===e)}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class ie{constructor(e=null){let n={};return e?n=_({...m.defaults},{...e}):n=m.defaults,n}}class K{constructor(e=null){this.style=new ae(e?e.style:null),this.networks=new re(e?e.networks:null),this.wallets=new oe(e?e.wallets:null),this.defaults=new ie(e?e.defaults:null)}}class g{constructor(e=null,n=null){const s=new Proxy(this,{get:function(a,i,l){if(a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0)return typeof a.proxy.ethersInstance[i]=="function"?a.proxy.ethersInstance[i].bind(a.proxy.ethersInstance):a.proxy.ethersInstance[i];if(a.proxy.ethersInstance&&a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0)return typeof a.proxy.extensionInstance[i]=="function"?a.proxy.extensionInstance[i].bind(l):a.proxy.extensionInstance[i];if(a&&a[i]!==void 0)return typeof a[i]=="function"?a[i].bind(l):a[i]},set:function(a,i,l,d){return a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0?(a.proxy.ethersInstance[i]=l,!0):a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0?(a.proxy.extensionInstance[i]=l,!0):(a[i]=l,!0)}});return this.proxy={_initIsRunning:!1,_ethersInstance:null,get ethersInstance(){return this._ethersInstance},set ethersInstance(a){this._ethersInstance=a&&t.markRaw(a),this._initIsRunning||(this._initIsRunning=!0,s._asyncInit().finally(()=>{this._initIsRunning=!1}))},extensionInstance:n},s}}class ce{}class le{constructor(){this._ars={}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class k extends g{constructor(e=null,n=null){super(e,n||new ce),this.status=r._ars.provider.status,this.isSafe=r._ars.provider.isSafe,this.OnSafe=r._ars.provider.OnSafe,this.onSafe=r._ars.provider.onSafe,this._asyncInit()}async _autoInstantiateFromWallet(){let e=null;for(const n of Object.values(r.wallets))if(n.lazyConnectAvailable&&await n.isConnected()){e=n;break}if(e)this.proxy.ethersInstance=e.getProvider();else for(const n of Object.values(r.wallets)){const s=n.getProvider();s&&(this.proxy.ethersInstance=s)}}_autoInstantiateFromDefaultConfig(){const e=r.config.networks.getDefault();e&&e.defaultRPC&&(this.proxy.ethersInstance=new p.ethers.providers.JsonRpcProvider(e.defaultRPC))}async _autoInstantiate(){await this._autoInstantiateFromWallet(),this.proxy.ethersInstance||this._autoInstantiateFromDefaultConfig()}async _checkNetwork(){if(!this.proxy.ethersInstance)throw"._checkNetwork() method must not be called if the ethersInstance is null (if not connected to any network).";const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);if(n)this.status.set("CONNECTED");else if(this.status.set("WRONG_NETWORK"),n=r.config.networks.getAll().find(s=>s.id===e.id),!n){const s={name:e.name,displayName:U(e.name),id:e.chainId};console.log(s),r.config.networks.add(s)}}async _setNetworkSettings(){const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);n&&n&&n.pollingInterval&&(this.pollingInterval=n.pollingInterval)}async _asyncInit(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?(await this._checkNetwork(),await this._setNetworkSettings()):this.status.set("DISCONNECTED")}async changeNetwork(e){const n=await r.config.wallets.getCurrent();n&&r.wallets[n.id].changeNetwork(e)}}class de{}class N extends g{constructor(e=null,n=null){super(e,n||new de),this.walletId=null,this.address=t.ref(null),this.status=r._ars.signer.status,this.isSafe=r._ars.signer.isSafe,this.OnSafe=r._ars.signer.OnSafe,this.onSafe=r._ars.signer.onSafe,this._asyncInit()}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}async _autoInstantiate(){console.log(r.wallets);for(const e of Object.keys(r.wallets))if(r.wallets[e].lazyConnectAvailable&&(await this.connectWallet(e,!0),this.proxy.ethersInstance))break}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?this.address.value=await this.getAddress():this.status.set("DISCONNECTED")}.bind(this))}async connectWallet(e,n=!1){const s=r.wallets[e];if(s.lazyConnectAvailable){if(await s.connect(!0),await s.isConnected())r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED");else if(n){r.signer.status.set("DISCONNECTED");return}}try{this.status.set("REQUESTED"),await s.connect(!1),r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED")}catch(a){if(a instanceof I)this.status.set("REFUSED");else throw this.status.set("ERROR"),a}}disconnectWallet(){r.signer.proxy.ethersInstance=null,this.address.value=null,r.signer.status.set("DISCONNECTED")}}class he{_watch(e,n,s=null){return Object.keys(r.chainWatchers.contracts).includes(this.address)||r.chainWatchers.addContractWatcher(this),r.chainWatchers.contracts[this.address].add(e,n,s)}watch(e,n,s,a=null){const i=this._watch(e,n,s);return a?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)},a):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)}),r.chainWatchers.contracts[this.address].remove.bind(r.chainWatchers.contracts[this.address],e,n,i)}watchRef(e,n,s=null){const a=this._watch(e,n,null);return s?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)},s):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)}),r.chainWatchers.contracts[this.address].getRef(e,n)}}class C extends g{constructor(e=null,n=null){super(e,n||new he),this.name=null,this.status=r._ars.contracts[this.name].status,this.isReadSafe=r._ars.contracts[this.name].isReadSafe,this.isWriteSafe=r._ars.contracts[this.name].isWriteSafe,this.OnReadSafe=r._ars.contracts[this.name].OnReadSafe,this.OnWriteSafe=r._ars.contracts[this.name].OnWriteSafe,this.onReadSafe=r._ars.contracts[this.name].onReadSafe,this.onWriteSafe=r._ars.contracts[this.name].onWriteSafe,this._asyncInit()}onSafe(e){throw"TulipeContract instances don't have 'onSafe()' method, use 'onReadSafe()' and 'onWriteSafe()' instead."}_updateContract(e,n){if(r.signer.isSafe.value)this.proxy.ethersInstance=new p.ethers.Contract(e,n,r.signer.proxy.ethersInstance);else if(r.provider.isSafe.value)this.proxy.ethersInstance=new p.ethers.Contract(e,n,r.provider.proxy.ethersInstance);else throw`_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance?(this.name="TODO",this.status.set("INITIALIZED")):this.status.set("UNAVAILABLE")}.bind(this))}}class pe{}class fe extends le{constructor(){super(),this.contractName=null,this.methodName=null,this.methodInfos={},this.args=t.ref(args),this.txArgs=t.ref(txArgs),this.data=t.ref([]),this.error=t.ref(null),this.call=null,this.status=new w(`tx:${contractName}:${methodName}`,["NOT_READY","READY","SENT","ERROR","SUCCESS"])}initARS(){this.status.watch(["ERROR","SUCCESS"],()=>{setTimeout(()=>{this.status.set("READY")},3e3)})}_asyncInit(){this.proxy._initIsRunning=!0,r.contracts[this.contractName].isReadSafe.value&&this._initEthersInstance(),r.contracts[this.contractName].onReadSafe(()=>{this._initEthersInstance()}),this.initARS(),this.proxy._initIsRunning=!1}_initEthersInstance(){this.methodInfos=r.contracts[this.contractName].interface.functions[this.methodName],this.methodInfos.inputs.forEach(e=>this.args.value.push(null)),this.methodInfos.outputs.forEach(e=>this.data.value.push(null)),this.proxy.ethersInstance=r.contracts[this.contractName][this.methodName],this.status.set("READY")}send(e=null,n=null){e=e&&e.length>0?e:S(this.args),e?Array.isArray(e)?this.call=this.proxy.ethersInstance(...e,n):this.call=this.proxy.ethersInstance(e,n):this.call=this.proxy.ethersInstance(n),this.status.set("SENT"),this.methodInfos.constant?this.call.then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR")}):this.call.then(s=>s.wait()).then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR"),console.log(s)})}}class j extends g{constructor(e,n,s=[],a={value:0},i=null,l=null,d=null){super(i,l||new pe,d||new fe(e,n,s=[],a={value:0})),this._asyncInit()}}const ue={JsonRpcProvider:p.ethers.providers.JsonRpcProvider,StaticJsonRpcProvider:p.ethers.providers.StaticJsonRpcProvider,EtherscanProvider:p.ethers.providers.EtherscanProvider,InfuraProvider:p.ethers.providers.InfuraProvider,AlchemyProvider:p.ethers.providers.AlchemyProvider,CloudflareProvider:p.ethers.providers.CloudflareProvider,PocketProvider:p.ethers.providers.PocketProvider,AnkrProvider:p.ethers.providers.AnkrProvider,FallbackProvider:p.ethers.providers.FallbackProvider,IpcProvider:p.ethers.providers.IpcProvider,JsonRpcBatchProvider:p.ethers.providers.JsonRpcBatchProvider,UrlJsonRpcProvider:p.ethers.providers.UrlJsonRpcProvider,Web3Provider:p.ethers.providers.Web3Provider,WebSocketProvider:p.ethers.providers.WebSocketProvider},J={};for(const[o,e]of Object.entries(ue))J[o]=class extends e{constructor(...n){let s=k;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof k&&(s=n.pop()),super(...n),new s(this)}};const me={Wallet:p.ethers.Wallet,VoidSigner:p.ethers.VoidSigner},Y={};for(const[o,e]of Object.entries(me))Y[o]=class extends e{constructor(...n){let s=N;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof N&&(s=n.pop()),super(...n),new s(this)}};const ye={Contract:p.ethers.Contract},Z={};for(const[o,e]of Object.entries(ye))Z[o]=class extends e{constructor(...n){let s=C;n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof C&&(s=n.pop()),super(...n);const a=new s(this);return console.log(a),a}};const _e={...J,...Y,...Z},Q={...p.ethers};for(const[o,e]of Object.entries(_e))Q[o]=e;class X{constructor(){this.lastUpdateBlock=0,this.sources={}}_generateDependentUUID(){return"xxxxxxxx".replace(/[xy]/g,function(e){var n=Math.random()*16|0,s=e=="x"?n:n&3|8;return s.toString(16)})}async requiresUpdate(){if(!r.provider.isSafe.value)return!1;const e=await r.provider.getBlockNumber();return this.lastUpdateBlock0)return!0}catch{}return!1}getProvider(){return this.exposedObject?new p.ethers.providers.Web3Provider(this.exposedObject,"any"):null}async getSigner(){if(this.exposedObject){const e=this.getProvider();if(e)return await e.getSigner()}return null}async connect(e=!1){if(this.exposedObject){if(await this.isConnected()||e)return;try{await this.exposedObject.request({method:"eth_requestAccounts"})}catch(n){throw n.code===4001?new I(this.id):n}}throw"exposedObject not available"}async addNetwork(e){const n=r.config.networks.getById(e);await this.exposedObject.request({method:"wallet_addEthereumChain",params:[{chainId:e,rpcUrls:[n.defaultRPC],chainName:n.name,nativeCurrency:{name:n.currency.symbol,symbol:n.currency.symbol,decimals:n.currency.decimals},blockExplorerUrls:n.explorer&&n.explorer.url!==""?[n.explorer.url]:null}]})}async changeNetwork(e,n=!1){if(r.config.networks.getById(e)){e=p.ethers.utils.hexlify(parseInt(e)).toString(),e=p.ethers.utils.hexValue(e);try{await this.exposedObject.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(a){if(a.code===4902)this.addNetwork(e);else throw a}}}}class Se extends nt{constructor(){super("metamask",window.ethereum)}}class we extends et{constructor(e,n={}){super(),this.id="coinbase";const s=n.appName||"",a=n.appLogoUrl,i=n.darkMode||!1;this.coinbaseWalletSdk=new e({appName:s,appLogoUrl:a,darkMode:i}),this.provider=this.getProvider()}getProvider(){try{return this.coinbaseWalletSdk.makeWeb3Provider()}catch(e){return console.log(e),null}}async connect(){try{await this.provider.send("eth_requestAccounts")}catch{throw I(this.id)}}}class ge extends nt{constructor(){super("binanceChain",window.BinanceChain),this.lazyConnectAvailable=!1}async isConnected(){throw new y("isConnected() method is not available for BinanceChainWallet class since lazy connection is not available.")}async connect(e=!1){if(e)throw new y("connect() with 'lazy=true' is not available for BinanceChainWallet class because isConnected() is not available on this class.")}}const st={metamask:Se,coinbase:we,binanceChain:ge};class Ee{constructor(){this.status=new w("dapp",["UNSAFE","ERROR","INITIALIZED"]),this.isSafe=t.computed(()=>this.status.is("INITIALIZED")),this.OnSafe=P}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class ke{constructor(){this.status=new w("provider",["DISCONNECTED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.isSafe.value&&!this.status.isIn(["DISCONNECTED","ERROR"])),this.OnSafe=V}init(){}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class at{constructor(){this._ars={oldEthersInstance:null,events:{},watchers:{}}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ne extends at{constructor(){super(),this.status=new w("signer",["NO_PROVIDER","DISCONNECTED","REQUESTED","REFUSED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("CONNECTED")),this.OnSafe=T}init(){this._ars.oldEthersInstance={...r.signer.proxy.ethersInstance},r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ce extends at{constructor(e){super(),this.name=e,this.status=new w(`contract:${e}`,["NO_PROVIDER","UNAVAILABLE","ERROR","INITIALIZED"]),this.isReadSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("INITIALIZED")),this.isWriteSafe=t.computed(()=>r.signer.isSafe.value&&this.status.is("INITIALIZED")),this.OnReadSafe=t.createVNode(A,{contract:e}),this.OnWriteSafe=t.createVNode(W,{contract:e})}onReadSafe(e){const n=t.getCurrentInstance();if(this.isReadSafe.value)e(n);else{const s=t.watch(this.isReadSafe,()=>{this.isReadSafe.value&&(e(n),s())})}}onWriteSafe(e){const n=t.getCurrentInstance();if(this.isWriteSafe.value)e(n);else{const s=t.watch(this.isWriteSafe,()=>{this.isWriteSafe.value&&(e(n),s())})}}init(){this._ars.oldEthersInstance={...r.contracts[this.name].proxy.ethersInstance},t.watch(r.signer.isSafe,(e,n)=>{if(e!==n){const s=this.proxy.ethersInstance.interface,a=this.proxy.ethersInstance.address;this.proxy.ethersInstance=null,this._updateContract(a,s)}}),r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("UNAVAILABLE"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")})}}class Ie{constructor(e){for(const n of r.config.networks.getAll())if(n.contracts)for(const[s,a]of Object.entries(n.contracts))this.add(s)}add(e){this[e]=new Ce(e)}}class rt{constructor(){this.dapp=new Ee,this.provider=new ke,this.signer=new Ne,this.contracts=new Ie}}async function Re(o,e){const n=e;try{r.init(n)}catch(a){throw r&&r.status&&r.status.set("ERROR"),a}o.config.globalProperties.dapp=r,o.config.globalProperties.rGet=S,o.config.globalProperties.rSet=u,window.dapp=r;const s=await Promise.resolve().then(()=>se);o.component("OnDappSafe",s.OnDappSafe),o.component("OnProviderSafe",s.OnProviderSafe),o.component("OnSignerSafe",s.OnSignerSafe),o.component("OnContractReadSafe",s.OnContractReadSafe),o.component("OnContractWriteSafe",s.OnContractWriteSafe),r.status.set("INITIALIZED")}c.ARS=rt,c.ConnectWalletButton=F,c.ContractInteractor=M,c.ContractWatcher=v,c.DebugBar=z,c.EventInteractor=B,c.EventsInteractor=x,c.InputUnits=$,c.MethodInteractor=O,c.MethodsInteractor=b,c.OnContractReadSafe=A,c.OnContractWriteSafe=W,c.OnDappSafe=P,c.OnProviderSafe=V,c.OnSignerSafe=T,c.SelectNetworkDropdown=G,c.SelectWalletDropdown=q,c.Status=w,c.Transact=D,c.TulipeConfig=K,c.TulipeContractProxy=C,c.TulipeProviderProxy=k,c.TulipeProxy=g,c.TulipeSignerProxy=N,c.TulipeTransactionProxy=j,c.WalletConnectionRejected=I,c.WalletWatcher=tt,c.capitalizeWords=U,c.dapp=r,c.deepMerge=_,c.initTulipe=Re,c.isObject=E,c.rGet=S,c.rSet=u,c.styleLevelProp=R,c.tulipeEthers=Q,c.wallets=st,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(c,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("ethers")):typeof define=="function"&&define.amd?define(["exports","vue","ethers"],t):(c=typeof globalThis<"u"?globalThis:c||self,t(c.Tulipe={},c.vue,c.ethers))})(this,function(c,t,p){"use strict";class it{constructor(){const e=r.config.wallets.getAvailable();for(const n of e){const s=at[n.id];s&&(this[n.id]=new s)}}}class ct{constructor(){}init(){for(const e of r.config.networks.getAll())if(e.contracts)for(const[n,s]of Object.entries(e.contracts))this.add(n,s.address,s.abi)}add(e,n,s){const a=new p.ethers.Contract(n,s);r._ars.contracts.add(e),this[e]=new E(e,a),r._ars.contracts[e].start()}getAll(){const e={};for(const[n,s]of Object.entries(this))s instanceof E&&(e[n]=s);return e}}class lt{constructor(){this.contracts={},this.wallets={}}async _asyncInit(){r.provider.onSafe(()=>{r.provider.on("block",async function(e){const n=await r.provider.getBlockWithTransactions(e);for(const s of n.transactions)Object.keys(this.contracts).includes(s.to)?this.contracts[s.to].update():Object.keys(this.wallets).includes(s.to)&&this.wallets[s.to].update(),Object.keys(this.contracts).includes(s.from)?this.contracts[s.from].update():Object.keys(this.wallets).includes(s.from)&&this.wallets[s.from].update()})})}addContractWatcher(e){Object.keys(this.contracts).includes(e.address)||(this.contracts[e.address]=new tt(e))}removeContractWatcher(e){Object.keys(this.contracts).includes(e.address)&&delete this.contracts[e.address]}addWalletWatcher(e){Object.keys(this.wallets).includes(e)||(this.wallets[e]=new et(e))}removeContractWatcher(e){Object.keys(this.wallets).includes(e)&&delete this.wallets[e]}}class dt{constructor(){}init(e=null){this.config=new J(e),this._ars=new rt,this.status=this._ars.dapp.status,this.isSafe=this._ars.dapp.isSafe,this.OnSafe=this._ars.dapp.OnSafe,this.onSafe=this._ars.dapp.onSafe,this.chainWatchers=new lt,this.wallets=new it,this.provider=new C,this._ars.provider.start(),this.signer=new N,this._ars.signer.start(),this.contracts=new ct,this.contracts.init(),this.pro=this.provider,this.sig=this.signer,this.con=this.contracts}}const r=new dt;function k(o){return o&&typeof o=="object"&&!Array.isArray(o)}function _(o,...e){if(!e.length)return o;const n=e.shift();if(k(o)&&k(n))for(const s in n)k(n[s])?(o[s]||Object.assign(o,{[s]:{}}),_(o[s],n[s])):Object.assign(o,{[s]:n[s]});return _(o,...e)}function M(o){const e=o.split(" ");for(let n=0;n{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",ht,[t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Address : "+t.toDisplayString(t.unref(n).address),1),t.createElementVNode("li",null,"Owner : "+t.toDisplayString(t.unref(s)),1),t.createElementVNode("li",null,[pt,ft,t.createVNode(t.unref(b),{contract:e.contract},null,8,["contract"])]),t.createElementVNode("li",null,[ut,mt,t.createVNode(t.unref(x),{contract:e.contract},null,8,["contract"])])])])]),_:1},8,["contract"])}}},yt={class:"MethodsInteractor"},b={__name:"MethodsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",yt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.functions,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(O),{contract:e.contract,method:d},null,8,["contract","method"])]))),256))])])]),_:1},8,["contract"])}}},_t={class:"MethodInteractor"},St={key:0},wt=t.createElementVNode("p",null,"Inputs :",-1),gt=["onUpdate:modelValue","placeholder"],Et={key:0},kt={key:1},Ct=t.createElementVNode("p",null,"Outputs :",-1),Nt=["onUpdate:modelValue","placeholder"],It=["placeholder"],Rt={key:2},O={__name:"MethodInteractor",props:{contract:{type:String,required:!0},method:{type:String,required:!0}},setup(o){const e=o,n=t.shallowRef(new U(e.contract,e.method));function s(a){return`${a.name&&a.name!=="null"?a.name:""} (${a.type})`}return(a,i)=>{const l=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(l,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",_t,[t.createVNode(t.unref(P),{contract:e.contract,method:e.method,modelValue:t.unref(n),"onUpdate:modelValue":i[0]||(i[0]=d=>t.isRef(n)?n.value=d:null),configs:{content:e.method,notx:!0,noerror:!0}},null,8,["contract","method","modelValue","configs"]),t.createElementVNode("small",null,t.toDisplayString(t.unref(n).methodInfos.stateMutability),1),Object.keys(t.unref(n).methodInfos.inputs).length>0||t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("div",St,[wt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.inputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.withDirectives(t.createElementVNode("input",{"onUpdate:modelValue":f=>t.unref(n).args.value[h]=f,type:"text",placeholder:s(d)},null,8,gt),[[t.vModelText,t.unref(n).args.value[h]]]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).args.value[h])+" "+t.toDisplayString(typeof t.unref(n).args.value[h]),1)]))),256)),t.unref(n).methodInfos.payable?(t.openBlock(),t.createElementBlock("li",Et,[t.createVNode(t.unref($),{modelValue:t.unref(n).txArgs.value.value,"onUpdate:modelValue":i[1]||(i[1]=d=>t.unref(n).txArgs.value.value=d)},null,8,["modelValue"]),t.createTextVNode(" "+t.toDisplayString(t.unref(n).txArgs.value.value)+" "+t.toDisplayString(typeof t.unref(n).txArgs.value.value),1)])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0),Object.keys(t.unref(n).methodInfos.outputs).length>0?(t.openBlock(),t.createElementBlock("div",kt,[Ct,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).methodInfos.outputs,(d,h)=>(t.openBlock(),t.createElementBlock("li",null,[t.unref(n).data.value?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:0,"onUpdate:modelValue":f=>t.unref(n).data.value[h]=f,type:"text",placeholder:s(d),disabled:""},null,8,Nt)),[[t.vModelText,t.unref(n).data.value[h]]]):(t.openBlock(),t.createElementBlock("input",{key:1,type:"text",placeholder:s(d),disabled:""},null,8,It))]))),256))])])):t.createCommentVNode("",!0),t.unref(n).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",Rt,t.toDisplayString(t.unref(n).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},bt={class:"EventsInteractor"},x={__name:"EventsInteractor",props:{contract:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];return(s,a)=>{const i=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(i,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",bt,[t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n).interface.events,(l,d)=>(t.openBlock(),t.createElementBlock("li",null,[t.createVNode(t.unref(B),{contract:e.contract,event:d},null,8,["contract","event"])]))),256))])])]),_:1},8,["contract"])}}},Ot={class:"EventInteractor"},xt=t.createTextVNode("Logs: "),B={__name:"EventInteractor",props:{contract:{type:String,required:!0},event:{type:String,required:!0}},setup(o){const e=o,n=r.contracts[e.contract];let s=t.ref({}),a=t.ref({}),i=t.ref(0),l=t.ref([]);return n.onReadSafe(()=>{s.value=n.interface.events[e.event],a.value=n.filters[s.value.name],n.on(a.value,d=>{i.value++;let h=`Block ${d.blockNumber} -> {`;for(const f of s.value.inputs)h+=`${f.name}:${d.args[f.name]}, `;h=h.substring(0,h.length-2)+"}",l.value.push(h)})}),(d,h)=>{const f=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(f,{contract:e.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Ot,[t.createElementVNode("p",null,t.toDisplayString(t.unref(s).name),1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"Count : "+t.toDisplayString(t.unref(i)),1),t.createElementVNode("li",null,[xt,t.createElementVNode("ul",null,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(l),ot=>(t.openBlock(),t.createElementBlock("li",null,t.toDisplayString(ot),1))),256))])])])])]),_:1},8,["contract"])}}},Bt={class:"TransactButton"},Pt={key:1,disabled:""},Dt={key:2,disabled:""},Vt={key:3,disabled:""},At={key:4},P={__name:"Transact",props:{modelValue:{},contract:{type:String,required:!0},method:{type:String,required:!0},args:{type:Array,required:!1},txArgs:{type:Object,required:!1},configs:{type:Object,required:!1}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o,s=r.contracts[n.contract];let a=t.computed({get(){return n.modelValue},set(l){e("update:modelValue",l)}});function i(){const l=n.args?n.args:[],d=n.txArgs?n.txArgs:{};a.value.send(l,d)}return n.config&&n.configs.notx&&s.onReadSafe(()=>{a=new U(n.contract,n.method)}),(l,d)=>{const h=t.resolveComponent("OnContractReadSafe");return t.openBlock(),t.createBlock(h,{contract:n.contract},{default:t.withCtx(()=>[t.createElementVNode("div",Bt,[t.unref(a).status.is("READY")?(t.openBlock(),t.createElementBlock("button",{key:0,onClick:i},t.toDisplayString(n.configs&&n.configs.content?n.configs.content:"Transact"),1)):t.unref(a).status.is("SENT")?(t.openBlock(),t.createElementBlock("button",Pt,"Transaction sent...")):t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("button",Dt,"Transaction error!")):t.unref(a).status.is("SUCCESS")?(t.openBlock(),t.createElementBlock("button",Vt,"Success !")):t.createCommentVNode("",!0),!(n.configs&&n.configs.noerror)&&t.unref(a).status.is("ERROR")?(t.openBlock(),t.createElementBlock("p",At,t.toDisplayString(t.unref(a).error.value.reason),1)):t.createCommentVNode("",!0)])]),_:1},8,["contract"])}}},Oe="",F=(o,e)=>{const n=o.__vccOpts||o;for(const[s,a]of e)n[s]=a;return n},q=F({__name:"ConnectWalletButton",props:{styleLevel:R},setup(o){const e=o;return(n,s)=>(t.openBlock(),t.createBlock(t.unref(r).provider.OnSafe,null,{default:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass(["ConnectWalletButton",`ve-${e.styleLevel}`])},null,2)]),_:1}))}},[["__scopeId","data-v-a10b4efb"]]),Tt={class:"SelectWalletDropdown"},Wt={key:0},$t=[t.createElementVNode("p",null,"Connection requested...",-1)],Ut={key:1},jt=[t.createElementVNode("p",null,"Connection refused!",-1)],Mt={key:2},Lt=[t.createElementVNode("p",null,"Select a wallet",-1)],Ft=["src","alt"],qt=["onClick"],Gt=["src","alt"],G={__name:"SelectWalletDropdown",setup(o){let e=t.ref(null),n=t.ref([]),s=t.ref(!1),a=t.ref({});r.onSafe(async function(){n.value=r.config.wallets.getAvailable()}),r.provider.onSafe(async function(){a.value=await r.config.networks.getCurrent()}),r.signer.onSafe(async function(){e.value=await r.config.wallets.getCurrent(),n.value=r.config.wallets.getAvailable().filter(l=>l.id!==e.value.id)});function i(){s.value=!s.value}return(l,d)=>{const h=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(h,null,{default:t.withCtx(()=>[t.createElementVNode("div",Tt,[t.createElementVNode("ul",null,[t.unref(r).signer.status.is("REQUESTED")?(t.openBlock(),t.createElementBlock("li",Wt,$t)):t.unref(r).signer.status.is("REFUSED")?(t.openBlock(),t.createElementBlock("li",Ut,jt)):t.unref(r).provider.status.is("WRONG_NETWORK")?(t.openBlock(),t.createElementBlock("li",Mt,[t.createElementVNode("p",null,"Wrong network! ("+t.toDisplayString(t.unref(a)?t.unref(a).displayName:"unknown")+")",1)])):t.unref(r).signer.status.is("DISCONNECTED")||!t.unref(e)?(t.openBlock(),t.createElementBlock("li",{key:3,onClick:i},Lt)):t.unref(r).signer.status.is("CONNECTED")?(t.openBlock(),t.createElementBlock("li",{key:4,onClick:i},[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.wallets.icon,alt:t.unref(e).displayName+" logo"},null,8,Ft),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):t.createCommentVNode("",!0),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:5},t.renderList(t.unref(n),f=>(t.openBlock(),t.createElementBlock("li",{key:f.id,onClick:ot=>t.unref(r).signer.connectWallet(f.id)},[t.createElementVNode("img",{width:"40",src:f.icon?f.icon:t.unref(r).config.defaults.wallets.icon,alt:f.displayName+" logo"},null,8,Gt),t.createElementVNode("p",null,t.toDisplayString(f.displayName),1)],8,qt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},Ht={class:"SelectNetworkDropdown"},zt={key:0},Kt=["src","alt"],Jt={key:1},Yt=[t.createElementVNode("p",null,"Select a network",-1)],Zt=["onClick"],Qt=["src","alt"],H={__name:"SelectNetworkDropdown",setup(o){let e=t.ref({}),n=t.ref([]),s=t.ref(!1);r.onSafe(async function(){n.value=r.config.networks.getAvailable()}),r.provider.onSafe(async function(){e.value=await r.config.networks.getCurrent(),n.value=r.config.networks.getAvailable().filter(i=>i.id!==e.value.id)});function a(){s.value=!s.value}return(i,l)=>{const d=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(d,null,{default:t.withCtx(()=>[t.createElementVNode("div",Ht,[t.createElementVNode("ul",{onClick:a},[t.unref(e)?(t.openBlock(),t.createElementBlock("li",zt,[t.createElementVNode("img",{width:"40",src:t.unref(e).icon?t.unref(e).icon:t.unref(r).config.defaults.networks.icon,alt:t.unref(e).displayName+" logo"},null,8,Kt),t.createElementVNode("p",null,t.toDisplayString(t.unref(e).displayName),1)])):(t.openBlock(),t.createElementBlock("li",Jt,Yt)),t.unref(s)?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:2},t.renderList(t.unref(n),h=>(t.openBlock(),t.createElementBlock("li",{key:h.id,onClick:f=>t.unref(r).provider.changeNetwork(h.id)},[t.createElementVNode("img",{width:"40",src:h.icon?h.icon:t.unref(r).config.defaults.networks.icon,alt:h.displayName+" logo"},null,8,Qt),t.createElementVNode("p",null,t.toDisplayString(h.displayName),1)],8,Zt))),128)):t.createCommentVNode("",!0)])])]),_:1})}}},D={__name:"OnDappSafe",setup(o){return(e,n)=>t.unref(r).isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},V={__name:"OnProviderSafe",setup(o){return(e,n)=>t.unref(r).provider.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},A={__name:"OnSignerSafe",setup(o){return(e,n)=>t.unref(r).signer.isSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(e.$slots,"default"),t.renderSlot(e.$slots,"safe")],64)):t.renderSlot(e.$slots,"unsafe",{key:1})}},T={__name:"OnContractReadSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isReadSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},W={__name:"OnContractWriteSafe",props:{contract:{type:String,required:!0}},setup(o){const e=o;return(n,s)=>t.unref(r).contracts[e.contract].isWriteSafe.value?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.renderSlot(n.$slots,"default"),t.renderSlot(n.$slots,"safe")],64)):t.renderSlot(n.$slots,"unsafe",{key:1})}},Ae="",z=o=>(t.pushScopeId("data-v-a24ac687"),o=o(),t.popScopeId(),o),Xt=z(()=>t.createElementVNode("h3",null,"Safe Runners",-1)),vt=z(()=>t.createElementVNode("h3",null,"Status",-1)),K=F({__name:"DebugBar",setup(o){return(e,n)=>{const s=t.resolveComponent("OnDappSafe");return t.openBlock(),t.createBlock(s,null,{default:t.withCtx(()=>[t.createElementVNode("section",null,[t.createElementVNode("div",null,[Xt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"DApp safe : "+t.toDisplayString(t.unref(r).isSafe),1),t.createElementVNode("li",null,"Provider safe : "+t.toDisplayString(t.unref(r).provider.isSafe),1),t.createElementVNode("li",null,"Signer safe : "+t.toDisplayString(t.unref(r).signer.isSafe),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null,[t.createTextVNode(" contract "+t.toDisplayString(i)+" : ",1),t.createElementVNode("ul",null,[t.createElementVNode("li",null,"read safe : "+t.toDisplayString(a.isReadSafe),1),t.createElementVNode("li",null,"write safe : "+t.toDisplayString(a.isWriteSafe),1)])]))),256))])]),t.createElementVNode("div",null,[vt,t.createElementVNode("ul",null,[t.createElementVNode("li",null,"dapp : "+t.toDisplayString(t.unref(r).status.get()),1),t.createElementVNode("li",null,"provider : "+t.toDisplayString(t.unref(r).provider.status.get()),1),t.createElementVNode("li",null,"signer : "+t.toDisplayString(t.unref(r).signer.status.get()),1),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(r).contracts.getAll(),(a,i)=>(t.openBlock(),t.createElementBlock("li",null," contract "+t.toDisplayString(i)+" : "+t.toDisplayString(a.status.get()),1))),256))])])])]),_:1})}}},[["__scopeId","data-v-a24ac687"]]),te={class:"InputUnits"},ee=["placeholder"],ne=["value"],$={__name:"InputUnits",props:{modelValue:{},placeholder:{type:String}},emits:["update:modelValue"],setup(o,{emit:e}){const n=o;let s=t.ref(null);const a=["wei","gwei","ether"];let i=t.ref("wei");function l(){if(s.value){const d=p.ethers.utils.parseUnits(s.value,i.value);e("update:modelValue",d)}}return(d,h)=>(t.openBlock(),t.createElementBlock("div",te,[t.withDirectives(t.createElementVNode("input",{onInput:l,"onUpdate:modelValue":h[0]||(h[0]=f=>t.isRef(s)?s.value=f:s=f),type:"text",placeholder:t.unref(n).placeholder},null,40,ee),[[t.vModelText,t.unref(s)]]),t.withDirectives(t.createElementVNode("select",{onChange:l,"onUpdate:modelValue":h[1]||(h[1]=f=>t.isRef(i)?i.value=f:i=f)},[(t.openBlock(),t.createElementBlock(t.Fragment,null,t.renderList(a,f=>t.createElementVNode("option",{value:f},t.toDisplayString(f),9,ne)),64))],544),[[t.vModelSelect,t.unref(i)]])]))}},se=Object.freeze(Object.defineProperty({__proto__:null,InputUnits:$,styleLevelProp:R,ContractInteractor:L,MethodsInteractor:b,MethodInteractor:O,EventsInteractor:x,EventInteractor:B,Transact:P,ConnectWalletButton:q,SelectWalletDropdown:G,SelectNetworkDropdown:H,OnDappSafe:D,OnProviderSafe:V,OnSignerSafe:A,OnContractReadSafe:T,OnContractWriteSafe:W,DebugBar:K},Symbol.toStringTag,{value:"Module"}));class w{constructor(e,n){if(this._name=e,this.states=[],!Array.isArray(n))throw`The 'states' parameter of a Status instance '${e}' must an array of strings. Got: ${n}`;for(const s of n)this.states.push(this._formatState(s));this._state=t.ref(this.states[0])}_formatState(e){return e.toString().toUpperCase()}_isStateValid(e){return!!this.states.includes(this._formatState(e))}_areStatesValid(e){for(const n of e)if(!this._isStateValid(n))return!1;return!0}get(){return S(this._state)}getRef(){return this._state}set(e){if(e=this._formatState(e),!this._isStateValid(e))throw`The state given to the set() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;u(this._state,e),console.log(`Status '${this._name}' set to '${S(this._state)}'`)}is(e){if(!this._isStateValid(e))throw`The state given to the is() method of Status instance '${this._name}' must a value in ${this.states}. Got: ${e}`;return this.get()==this._formatState(e)}isIn(e){if(!this._areStatesValid(e))throw`The states given to the isIn() method of Status instance '${this._name}' must be an array with values in ${this.states}. Got: ${e}`;for(const n of e)if(this.is(n))return!0;return!1}watch(e,n){let s=`The states given to the watch() method of Status instance '${this._name}' must be a string or an array with values in ${this.states}. Got: ${e}`;if(Array.isArray(e)){if(!this._areStatesValid(e))throw s;return t.watch(this._state,()=>{this.isIn(e)&&n(this.get())})}else{if(!this._isStateValid(e))throw s;return t.watch(this._state,()=>{this.is(e)&&n(this.get())})}}watchAny(e){return this.watch(this.states,e)}}const m={style:{level:"minimal"},networks:[{name:"Ethereum Mainnet",displayName:"Ethereum",id:1,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/ethereum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.infura.io/v3/"},{name:"Ropsten",displayName:"Ropsten (Ethereum Testnet)",id:3,type:"testnet",icon:null,currency:{name:"Ropsten Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://ropsten.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://ropsten.infura.io/v3/"},{name:"Rinkeby",displayName:"Rinkeby (Ethereum Testnet)",id:4,type:"testnet",icon:null,currency:{name:"Rinkeby Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://rinkeby.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://rinkeby.infura.io/v3/"},{name:"G\xF6rli",displayName:"G\xF6rli (Ethereum Testnet)",id:5,type:"testnet",icon:null,currency:{name:"G\xF6rli Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://goerli.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://goerli.infura.io/v3/"},{name:"Optimism",id:10,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/optimism.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Etherscan",url:"https://optimistic.etherscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.optimism.io/"},{name:"Cronos Mainnet Beta",displayName:"Cronos",id:25,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/cronos.svg",currency:{name:"Cronos",symbol:"CRO",decimals:18},contracts:null,explorer:{name:"Cronos Explorer",url:"https://cronos.org/explorer",standard:"EIP3091"},defaultRPC:"https://evm.cronos.org"},{name:"Telos EVM Mainnet",displayName:"Telos",id:40,type:"mainnet",icon:null,currency:{name:"Telos",symbol:"TLOS",decimals:18},contracts:null,explorer:{name:"Teloscan",url:"https://teloscan.io/",standard:"EIP3091"},defaultRPC:"https://mainnet.telos.net/evm"},{name:"Binance Smart Chain Mainnet",displayName:"BSC",id:56,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/bsc.svg",currency:{name:"Binance Chain Native Token",symbol:"BNB",decimals:18},contracts:null,explorer:{name:"Bscscan",url:"https://bscscan.com/",standard:"EIP3091"},defaultRPC:"https://bsc-dataseed1.binance.org/"},{name:"Gnosis Chain",displayName:"Gnosis",id:100,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/gnosis.svg",currency:{name:"xDAI",symbol:"xDAI",decimals:18},contracts:null,explorer:{name:"Blockscout",url:"https://blockscout.com/xdai/mainnet/",standard:"EIP3091"},defaultRPC:"https://rpc.gnosischain.com"},{name:"Fuse Mainnet",displayName:"Fuse",id:122,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fuse.svg",currency:{name:"Fuse",symbol:"FUSE",decimals:18},contracts:null,explorer:{name:"Fuse Explorer",url:"https://explorer.fuse.io/",standard:"EIP3091"},defaultRPC:"https://rpc.fuse.io"},{name:"Huobi ECO Chain Mainnet",displayName:"HECO",id:128,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/heco.svg",currency:{name:"Huobi ECO Chain Native Token",symbol:"HT",decimals:18},contracts:null,explorer:{name:"Hecoinfo",url:"https://hecoinfo.com",standard:"EIP3091"},defaultRPC:"https://http-mainnet.hecochain.com"},{name:"Polygon Mainnet",displayName:"Polygon",id:137,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/polygon.svg",currency:{name:"MATIC",symbol:"MATIC",decimals:18},contracts:null,explorer:{name:"Polygonscan",url:"https://polygonscan.com/",standard:"EIP3091"},defaultRPC:"https://polygon-rpc.com/"},{name:"Fantom Opera",displayName:"Fantom",id:250,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/fantom.svg",currency:{name:"Fantom",symbol:"FTM",decimals:18},contracts:null,explorer:{name:"Ftmscan",url:"https://ftmscan.com/",standard:"EIP3091"},defaultRPC:"https://rpc.ftm.tools"},{name:"Metis Andromeda Mainnet",displayName:"Metis",id:1088,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/metis.svg",currency:{name:"Metis",symbol:"METIS",decimals:18},contracts:null,explorer:{name:"Metis Explorer",url:"https://andromeda-explorer.metis.io",standard:"EIP3091"},defaultRPC:"https://andromeda.metis.io/?owner=1088"},{name:"Moonbeam",id:1284,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonbeam.svg",currency:{name:"Glimmer",symbol:"GLMR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonbeam.moonscan.io",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonbeam.network"},{name:"Moonriver",id:1285,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/moonriver.svg",currency:{name:"Moonriver",symbol:"MOVR",decimals:18},contracts:null,explorer:{name:"Moonscan",url:"https://moonriver.moonscan.io/",standard:"EIP3091"},defaultRPC:"https://rpc.api.moonriver.moonbeam.network"},{name:"Klaytn Mainnet Cypress",displayName:"Klaytn",id:8217,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/klaytn.svg",currency:{name:"KLAY",symbol:"KLAY",decimals:18},contracts:null,explorer:{name:"Klaytnscope",url:"https://scope.klaytn.com",standard:"EIP3091"},defaultRPC:"https://public-node-api.klaytnapi.com/v1/cypress"},{name:"Hardhat",displayName:"Hardhat",id:31337,type:"testnet",icon:null,currency:{name:"GoChain Coin",symbol:"GO",decimals:18},contracts:null,explorer:null,defaultRPC:"http://127.0.0.1:8545/"},{name:"Arbitrum One",displayName:"Arbitrum",id:42161,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/arbitrum.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Arbiscan",url:"https://arbiscan.io/",standard:"EIP3091"},defaultRPC:"https://arbitrum-mainnet.infura.io/v3/"},{name:"Celo Mainnet",displayName:"Celo",id:42220,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/celo.svg",currency:{name:"CELO",symbol:"CELO",decimals:18},contracts:null,explorer:{name:"Celo Explorer",url:"https://explorer.celo.org/",standard:"EIP3091"},defaultRPC:"https://forno.celo.org"},{name:"Emerald Paratime Mainnet",displayName:"Emerald",id:42262,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/emerald.svg",currency:{name:"Emerald Rose",symbol:"ROSE",decimals:18},contracts:null,explorer:{name:"Emerald Explorer",url:"https://explorer.emerald.oasis.dev/",standard:"EIP3091"},defaultRPC:"https://emerald.oasis.dev"},{name:"Avalanche C-Chain",displayName:"Avalanche",id:43114,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/avalanche.svg",currency:{name:"Avalanche",symbol:"AVAX",decimals:18},contracts:null,explorer:{name:"Snowtrace",url:"https://snowtrace.io/",standard:"EIP3091"},defaultRPC:"https://api.avax.network/ext/bc/C/rpc"},{name:"Aurora Mainnet",displayName:"Aurora",id:1313161554,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/aurora.svg",currency:{name:"Ether",symbol:"ETH",decimals:18},contracts:null,explorer:{name:"Aurorascan",url:"https://aurorascan.dev",standard:"EIP3091"},defaultRPC:"https://mainnet.aurora.dev"},{name:"Harmony Mainnet Shard 0",displayName:"Harmony",id:16666e5,type:"mainnet",icon:"https://static.tuli.pe/icons/networks/harmony.svg",currency:{name:"ONE",symbol:"ONE",decimals:18},contracts:null,explorer:{name:"Harmony Block Explorer",url:"https://explorer.harmony.one",standard:"EIP3091"},defaultRPC:"https://api.harmony.one"}],wallets:[{id:"metamask",displayName:"Metamask",icon:null},{id:"binanceChain",displayName:"Binance Chain",icon:null},{id:"coinbase",displayName:"Coinbase",icon:null}],defaults:{networks:{icon:"https://static.tuli.pe/icons/networks/unknown.svg"},wallets:{icon:"TODO"}}};class ae{constructor(e=null){let n={};return e?n=_({...m.style},{...e}):n=m.style,window.addEventListener("load",()=>{const s=document.getElementsByClassName("ve-app");if(s)for(const a of s)a&&a.classList.add(`ve-${n.level}`)}),n}}class re{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.networks.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.name),this._list.push(a)}}for(const n of m.networks)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}add(e){this._list.push(e)}async getCurrent(){if(r.provider.proxy.ethersInstance){const e=await r.provider.getNetwork().then(n=>n.chainId);return this.getById(e)}return null}getById(e){try{e=parseInt(e)}catch{throw"'id' given to getById() method must be an integer or any data type that can be parsed to interger."}return this._list.find(n=>n.id===parseInt(e))}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class oe{constructor(e=null){if(this._list=[],e){for(const n of e)if(n.id){const s=m.wallets.find(i=>i.id===n.id),a=_({...s},{...n});a.available!==!1&&(a.available=!0),a.displayName||(a.displayName=a.id),this._list.push(a)}}for(const n of m.wallets)this._list.find(a=>a.id===n.id)||(n.available=!1,this._list.push(n))}getCurrent(){return r.signer.proxy.ethersInstance?this.getById(r.signer.walletId):null}getById(e){return this._list.find(n=>n.id===e)}getDefault(){return this._list.find(e=>e.default===!0)}getAvailable(){return this._list.filter(e=>e.available)}getAll(){return this._list}}class ie{constructor(e=null){let n={};return e?n=_({...m.defaults},{...e}):n=m.defaults,n}}class J{constructor(e=null){this.style=new ae(e?e.style:null),this.networks=new re(e?e.networks:null),this.wallets=new oe(e?e.wallets:null),this.defaults=new ie(e?e.defaults:null)}}class g{constructor(e=null,n=null){console.log("TulipeProxy super");const s=new Proxy(this,{get:function(a,i,l){if(a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0)return typeof a.proxy.ethersInstance[i]=="function"?a.proxy.ethersInstance[i].bind(a.proxy.ethersInstance):a.proxy.ethersInstance[i];if(a.proxy.ethersInstance&&a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0)return typeof a.proxy.extensionInstance[i]=="function"?a.proxy.extensionInstance[i].bind(l):a.proxy.extensionInstance[i];if(a&&a[i]!==void 0)return typeof a[i]=="function"?a[i].bind(l):a[i]},set:function(a,i,l,d){return a.proxy.ethersInstance&&a.proxy.ethersInstance[i]!==void 0?(a.proxy.ethersInstance[i]=l,!0):a.proxy.extensionInstance&&a.proxy.extensionInstance[i]!==void 0?(a.proxy.extensionInstance[i]=l,!0):(a[i]=l,!0)}});return this.proxy={_changeWatchers:[],onChange:function(a){this._changeWatchers.push(a)},_initIsRunning:!1,_ethersInstance:null,get ethersInstance(){return this._ethersInstance},set ethersInstance(a){const i={...this._ethersInstance};this._ethersInstance=a&&t.markRaw(a);for(const l of this._changeWatchers)l(this._ethersInstance,i);this._initIsRunning||(this._initIsRunning=!0,s._asyncInit().finally(()=>{this._initIsRunning=!1}))},extensionInstance:n},this.proxy.ethersInstance=e,s}}class ce{}class le{constructor(){this._ars={}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(){this._purgeARS(),this.proxy.ethersInstance&&this._initEthersInstanceARS(),this._initPlaceholderInstanceARS()}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class C extends g{constructor(e=null,n=null){super(e,n||new ce),this.status=r._ars.provider.status,this.isSafe=r._ars.provider.isSafe,this.OnSafe=r._ars.provider.OnSafe,this.onSafe=r._ars.provider.onSafe}async _autoInstantiateFromWallet(){let e=null;for(const n of Object.values(r.wallets))if(n.lazyConnectAvailable&&await n.isConnected()){e=n;break}if(e)this.proxy.ethersInstance=e.getProvider();else for(const n of Object.values(r.wallets)){const s=n.getProvider();s&&(this.proxy.ethersInstance=s)}}_autoInstantiateFromDefaultConfig(){const e=r.config.networks.getDefault();e&&e.defaultRPC&&(this.proxy.ethersInstance=new p.ethers.providers.JsonRpcProvider(e.defaultRPC))}async _autoInstantiate(){await this._autoInstantiateFromWallet(),this.proxy.ethersInstance||this._autoInstantiateFromDefaultConfig()}async _checkNetwork(){if(!this.proxy.ethersInstance)throw"._checkNetwork() method must not be called if the ethersInstance is null (if not connected to any network).";const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);if(n)this.status.set("CONNECTED");else if(this.status.set("WRONG_NETWORK"),n=r.config.networks.getAll().find(s=>s.id===e.id),!n){const s={name:e.name,displayName:M(e.name),id:e.chainId};console.log(s),r.config.networks.add(s)}}async _setNetworkSettings(){const e=await this.getNetwork();let n=await r.config.networks.getById(e.chainId);n&&n&&n.pollingInterval&&(this.pollingInterval=n.pollingInterval)}async _asyncInit(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?(await this._checkNetwork(),await this._setNetworkSettings()):this.status.set("DISCONNECTED")}async changeNetwork(e){const n=await r.config.wallets.getCurrent();n&&r.wallets[n.id].changeNetwork(e)}}class de{}class N extends g{constructor(e=null,n=null){super(e,n||new de),this.walletId=null,this.address=t.ref(null),this.status=r._ars.signer.status,this.isSafe=r._ars.signer.isSafe,this.OnSafe=r._ars.signer.OnSafe,this.onSafe=r._ars.signer.onSafe}async _autoInstantiate(){for(const e of Object.keys(r.wallets))if(r.wallets[e].lazyConnectAvailable&&(await this.connectWallet(e,!0),this.proxy.ethersInstance))break}async _asyncInit(){r.provider.onSafe(async function(){this.proxy.ethersInstance||await this._autoInstantiate(),this.proxy.ethersInstance?this.address.value=await this.getAddress():this.status.set("DISCONNECTED")}.bind(this))}async connectWallet(e,n=!1){const s=r.wallets[e];if(s.lazyConnectAvailable){if(await s.connect(!0),await s.isConnected())r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED");else if(n){r.signer.status.set("DISCONNECTED");return}}try{this.status.set("REQUESTED"),await s.connect(!1),r.signer.proxy.ethersInstance=await s.getSigner(),this.walletId=s.id,r.signer.status.set("CONNECTED")}catch(a){if(a instanceof I)this.status.set("REFUSED");else throw this.status.set("ERROR"),a}}disconnectWallet(){r.signer.proxy.ethersInstance=null,this.address.value=null,r.signer.status.set("DISCONNECTED")}}class he{_watch(e,n,s=null){return Object.keys(r.chainWatchers.contracts).includes(this.address)||r.chainWatchers.addContractWatcher(this),r.chainWatchers.contracts[this.address].add(e,n,s)}watch(e,n,s,a=null){const i=this._watch(e,n,s);return a?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)},a):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,i)}),r.chainWatchers.contracts[this.address].remove.bind(r.chainWatchers.contracts[this.address],e,n,i)}watchRef(e,n,s=null){const a=this._watch(e,n,null);return s?t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)},s):t.onUnmounted(()=>{r.chainWatchers.contracts[this.address].remove(e,n,a)}),r.chainWatchers.contracts[this.address].getRef(e,n)}}class E extends g{constructor(e,n=null,s=null){console.log("init proxy"),console.log(e),console.log(n),super(n,s||new he),console.log("proxxx"),console.log(this.proxy),this.name=e,this.status=r._ars.contracts[this.name].status,this.isReadSafe=r._ars.contracts[this.name].isReadSafe,this.isWriteSafe=r._ars.contracts[this.name].isWriteSafe,this.OnReadSafe=r._ars.contracts[this.name].OnReadSafe,this.OnWriteSafe=r._ars.contracts[this.name].OnWriteSafe,this.onReadSafe=r._ars.contracts[this.name].onReadSafe,this.onWriteSafe=r._ars.contracts[this.name].onWriteSafe,console.log("proxxx 2"),console.log(this.proxy)}onSafe(e){throw"TulipeContract instances don't have 'onSafe()' method, use 'onReadSafe()' and 'onWriteSafe()' instead."}async _asyncInit(){console.log("proxxx 3"),console.log(this.proxy),r.provider.onSafe(async function(){this.proxy.ethersInstance?(this.name="TODO",this.status.set("INITIALIZED")):(console.log(this.proxy),console.log("marked as UNVAILABLE !"),this.status.set("UNAVAILABLE"))}.bind(this))}}class pe{}class fe extends le{constructor(){super(),this.contractName=null,this.methodName=null,this.methodInfos={},this.args=t.ref(args),this.txArgs=t.ref(txArgs),this.data=t.ref([]),this.error=t.ref(null),this.call=null,this.status=new w(`tx:${contractName}:${methodName}`,["NOT_READY","READY","SENT","ERROR","SUCCESS"])}initARS(){this.status.watch(["ERROR","SUCCESS"],()=>{setTimeout(()=>{this.status.set("READY")},3e3)})}_asyncInit(){this.proxy._initIsRunning=!0,r.contracts[this.contractName].isReadSafe.value&&this._initEthersInstance(),r.contracts[this.contractName].onReadSafe(()=>{this._initEthersInstance()}),this.initARS(),this.proxy._initIsRunning=!1}_initEthersInstance(){this.methodInfos=r.contracts[this.contractName].interface.functions[this.methodName],this.methodInfos.inputs.forEach(e=>this.args.value.push(null)),this.methodInfos.outputs.forEach(e=>this.data.value.push(null)),this.proxy.ethersInstance=r.contracts[this.contractName][this.methodName],this.status.set("READY")}send(e=null,n=null){e=e&&e.length>0?e:S(this.args),e?Array.isArray(e)?this.call=this.proxy.ethersInstance(...e,n):this.call=this.proxy.ethersInstance(e,n):this.call=this.proxy.ethersInstance(n),this.status.set("SENT"),this.methodInfos.constant?this.call.then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR")}):this.call.then(s=>s.wait()).then(s=>{Array.isArray(s)||(s=[s]),u(this.data,s),u(this.error,null),this.status.set("SUCCESS")}).catch(s=>{u(this.error,s),this.status.set("ERROR"),console.log(s)})}}class U extends g{constructor(e,n,s=[],a={value:0},i=null,l=null,d=null){super(i,l||new pe,d||new fe(e,n,s=[],a={value:0})),this._asyncInit()}}const ue={JsonRpcProvider:p.ethers.providers.JsonRpcProvider,StaticJsonRpcProvider:p.ethers.providers.StaticJsonRpcProvider,EtherscanProvider:p.ethers.providers.EtherscanProvider,InfuraProvider:p.ethers.providers.InfuraProvider,AlchemyProvider:p.ethers.providers.AlchemyProvider,CloudflareProvider:p.ethers.providers.CloudflareProvider,PocketProvider:p.ethers.providers.PocketProvider,AnkrProvider:p.ethers.providers.AnkrProvider,FallbackProvider:p.ethers.providers.FallbackProvider,IpcProvider:p.ethers.providers.IpcProvider,JsonRpcBatchProvider:p.ethers.providers.JsonRpcBatchProvider,UrlJsonRpcProvider:p.ethers.providers.UrlJsonRpcProvider,Web3Provider:p.ethers.providers.Web3Provider,WebSocketProvider:p.ethers.providers.WebSocketProvider},Y={};for(const[o,e]of Object.entries(ue))Y[o]=class extends e{constructor(...n){let s=C;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof C&&(s=n.pop()),super(...n),new s(this)}};const me={Wallet:p.ethers.Wallet,VoidSigner:p.ethers.VoidSigner},Z={};for(const[o,e]of Object.entries(me))Z[o]=class extends e{constructor(...n){let s=N;return n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof N&&(s=n.pop()),super(...n),new s(this)}};const ye={Contract:p.ethers.Contract},Q={};for(const[o,e]of Object.entries(ye))Q[o]=class extends e{constructor(...n){let s=E;n.length>0&&n[n.length-1]&&n[n.length-1].prototype instanceof E&&(s=n.pop()),super(...n);const a=new s(this);return console.log(a),a}};const _e={...Y,...Z,...Q},X={...p.ethers};for(const[o,e]of Object.entries(_e))X[o]=e;class v{constructor(){this.lastUpdateBlock=0,this.sources={}}_generateDependentUUID(){return"xxxxxxxx".replace(/[xy]/g,function(e){var n=Math.random()*16|0,s=e=="x"?n:n&3|8;return s.toString(16)})}async requiresUpdate(){if(!r.provider.isSafe.value)return!1;const e=await r.provider.getBlockNumber();return this.lastUpdateBlock0)return!0}catch{}return!1}getProvider(){return this.exposedObject?new p.ethers.providers.Web3Provider(this.exposedObject,"any"):null}async getSigner(){if(this.exposedObject){const e=this.getProvider();if(e)return await e.getSigner()}return null}async connect(e=!1){if(this.exposedObject){if(await this.isConnected()||e)return;try{await this.exposedObject.request({method:"eth_requestAccounts"})}catch(n){throw n.code===4001?new I(this.id):n}}throw"exposedObject not available"}async addNetwork(e){const n=r.config.networks.getById(e);await this.exposedObject.request({method:"wallet_addEthereumChain",params:[{chainId:e,rpcUrls:[n.defaultRPC],chainName:n.name,nativeCurrency:{name:n.currency.symbol,symbol:n.currency.symbol,decimals:n.currency.decimals},blockExplorerUrls:n.explorer&&n.explorer.url!==""?[n.explorer.url]:null}]})}async changeNetwork(e,n=!1){if(r.config.networks.getById(e)){e=p.ethers.utils.hexlify(parseInt(e)).toString(),e=p.ethers.utils.hexValue(e);try{await this.exposedObject.request({method:"wallet_switchEthereumChain",params:[{chainId:e}]})}catch(a){if(a.code===4902)this.addNetwork(e);else throw a}}}}class Se extends st{constructor(){super("metamask",window.ethereum)}}class we extends nt{constructor(e,n={}){super(),this.id="coinbase";const s=n.appName||"",a=n.appLogoUrl,i=n.darkMode||!1;this.coinbaseWalletSdk=new e({appName:s,appLogoUrl:a,darkMode:i}),this.provider=this.getProvider()}getProvider(){try{return this.coinbaseWalletSdk.makeWeb3Provider()}catch(e){return console.log(e),null}}async connect(){try{await this.provider.send("eth_requestAccounts")}catch{throw I(this.id)}}}class ge extends st{constructor(){super("binanceChain",window.BinanceChain),this.lazyConnectAvailable=!1}async isConnected(){throw new y("isConnected() method is not available for BinanceChainWallet class since lazy connection is not available.")}async connect(e=!1){if(e)throw new y("connect() with 'lazy=true' is not available for BinanceChainWallet class because isConnected() is not available on this class.")}}const at={metamask:Se,coinbase:we,binanceChain:ge};class Ee{constructor(){this.status=new w("dapp",["UNSAFE","ERROR","INITIALIZED"]),this.isSafe=t.computed(()=>this.status.is("INITIALIZED")),this.OnSafe=D}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class j{constructor(){this._ars={oldEthersInstance:null,events:{},watchers:[]}}_purgeARS(){if(this._ars.unwatchers)for(const e of this._ars.unwatchers)e();if(this._ars.unwatchers=[],this._ars.oldEthersInstance&&this._ars.events)for(const[e,n]of Object.entries(this._ars.events))this._ars.oldEthersInstance.off(e,n)}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){}_initARS(e){this._purgeARS(),e.proxy.ethersInstance&&(console.log("instance ARS"),console.log(e),this._initEthersInstanceARS()),this._initPlaceholderInstanceARS()}start(e){this._initARS(e),e.proxy.onChange(this._initARS.bind(this,e))}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class ke extends j{constructor(){super(),this.status=new w("provider",["DISCONNECTED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.isSafe.value&&!this.status.isIn(["DISCONNECTED","ERROR"])),this.OnSafe=V}_initEthersInstanceARS(){r.provider.on("network",(e,n)=>{n&&n!==e&&window.location.reload()}),r.provider.on("error",()=>{this.status.set("ERROR")})}_initPlaceholderInstanceARS(){}start(){super.start(r.provider)}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ce extends j{constructor(){super(),this.status=new w("signer",["NO_PROVIDER","DISCONNECTED","REQUESTED","REFUSED","ERROR","WRONG_NETWORK","CONNECTED"]),this.isSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("CONNECTED")),this.OnSafe=A}_initEthersInstanceARS(){}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?this.status.set("WRONG_NETWORK"):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")}),this.status.watch(["REFUSED","ERROR"],()=>{setTimeout(()=>{this.status.set("DISCONNECTED")},5e3)})}start(){super.start(r.signer)}onSafe(e){const n=t.getCurrentInstance();if(this.isSafe.value)e(n);else{const s=t.watch(this.isSafe,()=>{this.isSafe.value&&(e(n),s())})}}}class Ne extends j{constructor(e){super(),this.name=e,this.status=new w(`contract:${e}`,["NO_PROVIDER","UNAVAILABLE","ERROR","INITIALIZED"]),this.isReadSafe=t.computed(()=>r.provider.isSafe.value&&this.status.is("INITIALIZED")),this.isWriteSafe=t.computed(()=>r.signer.isSafe.value&&this.status.is("INITIALIZED")),this.OnReadSafe=t.createVNode(T,{contract:e}),this.OnWriteSafe=t.createVNode(W,{contract:e})}onReadSafe(e){const n=t.getCurrentInstance();if(this.isReadSafe.value)e(n);else{const s=t.watch(this.isReadSafe,()=>{this.isReadSafe.value&&(e(n),s())})}}onWriteSafe(e){const n=t.getCurrentInstance();if(this.isWriteSafe.value)e(n);else{const s=t.watch(this.isWriteSafe,()=>{this.isWriteSafe.value&&(e(n),s())})}}_updateContract(e,n){if(r.signer.isSafe.value)r.contracts[this.name].proxy.ethersInstance=new p.ethers.Contract(e,n,r.signer.proxy.ethersInstance);else if(r.provider.isSafe.value)r.contracts[this.name].proxy.ethersInstance=new p.ethers.Contract(e,n,r.provider.proxy.ethersInstance);else throw`_updateContract() is called for contract ${this.name} but neither provider nor signer are available.`}_initEthersInstanceARS(){this._ars.watchers.push(t.watch(r.signer.isSafe,(e,n)=>{if(e!==n){const s=r.contracts[this.name].proxy.ethersInstance.interface,a=r.contracts[this.name].proxy.ethersInstance.address;this._updateContract(a,s)}}))}_initPlaceholderInstanceARS(){r.provider.status.watchAny(e=>{e==="WRONG_NETWORK"?(console.log("UNAVVS"),this.status.set("UNAVAILABLE")):["DISCONNECTED","ERROR"].includes(e)&&this.status.set("NO_PROVIDER")})}start(){super.start(r.contracts[this.name])}}class Ie{constructor(e){for(const n of r.config.networks.getAll())if(n.contracts)for(const[s,a]of Object.entries(n.contracts))this.add(s)}add(e){this[e]=new Ne(e)}}class rt{constructor(){this.dapp=new Ee,this.provider=new ke,this.signer=new Ce,this.contracts=new Ie}}async function Re(o,e){const n=e;try{r.init(n)}catch(a){throw r&&r.status&&r.status.set("ERROR"),a}o.config.globalProperties.dapp=r,o.config.globalProperties.rGet=S,o.config.globalProperties.rSet=u,window.dapp=r;const s=await Promise.resolve().then(()=>se);o.component("OnDappSafe",s.OnDappSafe),o.component("OnProviderSafe",s.OnProviderSafe),o.component("OnSignerSafe",s.OnSignerSafe),o.component("OnContractReadSafe",s.OnContractReadSafe),o.component("OnContractWriteSafe",s.OnContractWriteSafe),r.status.set("INITIALIZED")}c.ARS=rt,c.ConnectWalletButton=q,c.ContractInteractor=L,c.ContractWatcher=tt,c.DebugBar=K,c.EventInteractor=B,c.EventsInteractor=x,c.InputUnits=$,c.MethodInteractor=O,c.MethodsInteractor=b,c.OnContractReadSafe=T,c.OnContractWriteSafe=W,c.OnDappSafe=D,c.OnProviderSafe=V,c.OnSignerSafe=A,c.SelectNetworkDropdown=H,c.SelectWalletDropdown=G,c.Status=w,c.Transact=P,c.TulipeConfig=J,c.TulipeContractProxy=E,c.TulipeProviderProxy=C,c.TulipeProxy=g,c.TulipeSignerProxy=N,c.TulipeTransactionProxy=U,c.WalletConnectionRejected=I,c.WalletWatcher=et,c.capitalizeWords=M,c.dapp=r,c.deepMerge=_,c.initTulipe=Re,c.isObject=k,c.rGet=S,c.rSet=u,c.styleLevelProp=R,c.tulipeEthers=X,c.wallets=at,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/package-lock.json b/package-lock.json index 79037450..bcd09374 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tulipe", - "version": "1.10.0", + "version": "1.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tulipe", - "version": "1.10.0", + "version": "1.11.0", "license": "MIT", "dependencies": { "ethers": "^5.7.0", diff --git a/package.json b/package.json index ce9d8c67..c41b12ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tulipe", - "version": "1.10.0", + "version": "1.11.0", "private": false, "description": "A DApp frontend framework for Vue3 built with Ethers.js 🌷", "license": "MIT",