edge-currency-accountbased 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.1.2 (2024-02-20)
6
+
7
+ - fixed: Cosmos token balance query
8
+
9
+ ## 3.1.1 (2024-02-14)
10
+
11
+ - changed: (FIO) Use a backup balance method for accounts affected by unstake chain data issue
12
+
5
13
  ## 3.1.0 (2024-02-12)
6
14
 
7
15
  - added: Arbitrum One network support
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8222],{79014:function(qe,Q,g){"use strict";g.d(Q,{Q:function(){return N},k:function(){return oe}});var V=g(77591),pe=g.n(V),W=g(24350),_=g(84564),b=g.n(_),j=g(76714),P=Object.defineProperty,q=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,Y=(y,C,a)=>C in y?P(y,C,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[C]=a,te=(y,C)=>{for(var a in C||(C={}))ee.call(C,a)&&Y(y,a,C[a]);if(q)for(var a of q(C))ne.call(C,a)&&Y(y,a,C[a]);return y};function oe(y,C,a,I,G=[]){const A=te({},b()(C,{},!0)),L=C.startsWith(`${y.pluginId}://`);if(A.protocol!=null&&(A.protocol=A.protocol.replace(":","")),A.protocol!=null&&A.protocol!==""&&!a[A.protocol])throw new Error(`Uri protocol '${A.protocol}' is not supported for ${y.pluginId}.`);if(A.host===""&&A.pathname==="")throw new Error("Path and host not found in uri.");const R={publicAddress:A.host!==""?A.host:A.pathname.split("/")[0]},se=A.query.label,re=A.query.message,ie=A.query.category;(se!=null||re!=null||ie!=null||L)&&(R.metadata={},R.metadata.name=se,R.metadata.notes=re,R.metadata.category=ie,R.metadata.gateway=L!=null?L:!1);const z=A.query.amount;if(z!=null&&typeof z=="string"){I==null&&(I=y.currencyCode);const ae=(0,j.Qs)(I!=null?I:"",y,G);if(ae==null)throw new Error("InternalErrorInvalidCurrencyCode");let J=(0,V.mul)(z,ae.multiplier);J=(0,V.toFixed)(J,0,0),R.nativeAmount=J,R.currencyCode=I}return{edgeParsedUri:R,parsedUri:A}}function N(y,C,a){if(y.publicAddress==null)throw new Error("InvalidPublicAddressError");if(a==null&&y.label==null&&y.message==null)return y.publicAddress;{let I="";a!=null&&(I+="amount="+a+"&"),(y.label!=null||y.message!=null)&&(typeof y.label=="string"&&(I+="label="+y.label+"&"),typeof y.message=="string"&&(I+="message="+y.message+"&")),I=I.substr(0,I.length-1);const G={scheme:C,path:y.publicAddress,query:I};return(0,W.qC)(G)}}},94831:function(qe,Q,g){"use strict";g.r(Q),g.d(Q,{CosmosTools:function(){return Ve},makeCurrencyEngine:function(){return Fn},makeCurrencyTools:function(){return _n}});var V=g(87137),pe=g(79562),W=g(28972),_=g(74087),b=g(77591),j=g(2153),P=g(79325),q=g(20918),ee=g(79014),ne=g(76714),Y=g(98994),te=g(2387),oe=g(39385),N=g(33359),y=g(24658),C=g(73034),a=g(82448),I=g(62177);const G=["coin_spent.spender","coin_received.receiver"],A=(0,a.su)({archivedTxLastCheckTime:(0,a.Vk)(a.mH,0),"coin_spent.spender":(0,a.Vk)(a.XC),"coin_received.receiver":(0,a.Vk)(a.XC)}),L=(0,I.jd)((0,a.su)({bech32Address:a.XC,publicKey:a.XC})),Z=e=>{const n=(0,a.su)({[`${e}Mnemonic`]:a.XC});return(0,a.W1)(t=>({mnemonic:n(t)[`${e}Mnemonic`]}),t=>({[`${e}Mnemonic`]:t.mnemonic}))},R=(0,a.su)({ninerealmsClientId:(0,a.Zz)(a.XC)}),se=(0,a.su)({denom:a.XC,amount:a.XC}),re=(0,a.su)({gasFeeCoin:se,gasLimit:a.XC,unsignedTxHex:a.XC}),ie=(0,a.su)({native_outbound_fee_rune:a.XC,native_tx_fee_rune:a.XC}),z=(0,a.su)({method:(0,a.Wf)("cosmos_getAccounts"),params:(0,a.su)({})}),ae=(0,a.Wf)("cosmos_signDirect"),J=(0,a.su)({method:ae,params:(0,a.su)({signerAddress:a.XC,signDoc:(0,a.su)({chainId:a.XC,accountNumber:a.XC,authInfoBytes:a.XC,bodyBytes:a.XC})})}),ve=(0,a.su)({method:(0,a.Wf)("cosmos_signAmino"),params:(0,a.su)({signerAddress:a.XC,signDoc:(0,a.su)({chain_id:a.XC,account_number:a.XC,sequence:a.XC,memo:a.XC,msgs:(0,a._2)((0,a.su)({type:a.XC,value:a.JC})),fee:(0,a.su)({amount:(0,a._2)((0,a.su)({denom:a.XC,amount:a.XC})),gas:a.XC})})})});var me=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});const ge=(e,n)=>{const t=R(n),s={},r=/{{(.*?)}}/g;for(const[o,l]of Object.entries(e.headers)){const i=r.exec(l);i!=null&&(s[o]=t[i[1]])}return{url:e.url,headers:s}},Ye=(e,n)=>{const{url:t,headers:s}=n;return{execute:r=>me(void 0,null,function*(){const o={method:"POST",headers:s,body:JSON.stringify(r)};return yield(yield e(t,o)).json()}),disconnect:()=>{}}},Ge=e=>me(void 0,null,function*(){const n=yield C.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield C.Tendermint37Client.create(e):yield C.Tendermint34Client.create(e)}),ke=(e,n)=>me(void 0,null,function*(){const t=yield y.StargateClient.create(yield Ge(Ye(e,n))),s=t.forceGetQueryClient(),r=t.forceGetCometClient();return{queryClient:s,stargateClient:t,cometClient:r}}),Ze=e=>{var n;const[t,...s]=e.split("."),r=e.includes("/"),o=s.join("."),l=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:l,synth:r}},K=e=>e.reduce((n,t)=>{try{return(0,N.addCoins)(n,t)}catch{}return n}),Ce=(0,a.Wf)("amount"),ze=(0,a.Wf)("receiver"),Qe=(0,a.Wf)("spender"),je=(0,a.Wf)("amount","receiver","spender"),en=(0,a.su)({type:(0,a.Wf)("coin_received"),attributes:(0,a.vq)((0,a.su)({key:Ce,value:a.XC}),(0,a.su)({key:ze,value:a.XC}))}),nn=(0,a.su)({type:(0,a.Wf)("coin_spent"),attributes:(0,a.vq)((0,a.su)({key:Ce,value:a.XC}),(0,a.su)({key:Qe,value:a.XC}))}),tn=(e,n)=>{const t=new Map;for(const r of e){const o={type:r.type,attributes:r.attributes.filter(c=>(0,a.Vk)(je)(c.key)!=null).sort((c,u)=>c.key<u.key?-1:1)},l=(0,a.Vk)(en)(o);if(l!=null){const[c,u]=l.attributes.map(p=>p.value);if(u!==n)continue;Te(c).forEach(p=>{var v;const h=p.amount,m=(v=t.get(p.denom))!=null?v:"0";t.set(p.denom,(0,b.add)(h,m))});continue}const i=(0,a.Vk)(nn)(o);if(i!=null){const[c,u]=i.attributes.map(p=>p.value);if(u!==n)continue;Te(c).forEach(p=>{var v;const h=`-${p.amount}`,m=(v=t.get(p.denom))!=null?v:"0";t.set(p.denom,(0,b.add)(h,m))})}}const s=[];return t.forEach((r,o)=>{r!=="0"&&s.push({denom:o,amount:r})}),s},ce=e=>{try{return P.YU.parse(e)}catch{return P.US.parse(e)}},Te=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const s=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(s==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=s[1].replace(/^0+/,""))!=null?t:"0",denom:s[2]}});var on=g(43720),x=g.n(on),sn=g(62100),d=g.n(sn);const Xn="common";function Ae(){return{chain:"",symbol:"",ticker:"",synth:!1}}const X={encode(e,n=d().Writer.create()){return e.chain!==""&&n.uint32(10).string(e.chain),e.symbol!==""&&n.uint32(18).string(e.symbol),e.ticker!==""&&n.uint32(26).string(e.ticker),e.synth===!0&&n.uint32(32).bool(e.synth),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ae();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.chain=t.string();continue;case 2:if(o!==18)break;r.symbol=t.string();continue;case 3:if(o!==26)break;r.ticker=t.string();continue;case 4:if(o!==32)break;r.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{chain:S(e.chain)?globalThis.String(e.chain):"",symbol:S(e.symbol)?globalThis.String(e.symbol):"",ticker:S(e.ticker)?globalThis.String(e.ticker):"",synth:S(e.synth)?globalThis.Boolean(e.synth):!1}},toJSON(e){const n={};return e.chain!==""&&(n.chain=e.chain),e.symbol!==""&&(n.symbol=e.symbol),e.ticker!==""&&(n.ticker=e.ticker),e.synth===!0&&(n.synth=e.synth),n},create(e){return X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s,r;const o=Ae();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(s=e.ticker)!=null?s:"",o.synth=(r=e.synth)!=null?r:!1,o}};function we(){return{asset:void 0,amount:"",decimals:x().ZERO}}const T={encode(e,n=d().Writer.create()){return e.asset!==void 0&&X.encode(e.asset,n.uint32(10).fork()).ldelim(),e.amount!==""&&n.uint32(18).string(e.amount),e.decimals.isZero()||n.uint32(24).int64(e.decimals),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=we();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.asset=X.decode(t,t.uint32());continue;case 2:if(o!==18)break;r.amount=t.string();continue;case 3:if(o!==24)break;r.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{asset:S(e.asset)?X.fromJSON(e.asset):void 0,amount:S(e.amount)?globalThis.String(e.amount):"",decimals:S(e.decimals)?x().fromValue(e.decimals):x().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=X.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||x().ZERO).toString()),n},create(e){return T.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=we();return t.asset=e.asset!==void 0&&e.asset!==null?X.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?x().fromValue(e.decimals):x().ZERO,t}};function be(){return{secp256k1:"",ed25519:""}}const rn={encode(e,n=d().Writer.create()){return e.secp256k1!==""&&n.uint32(10).string(e.secp256k1),e.ed25519!==""&&n.uint32(18).string(e.ed25519),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=be();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.secp256k1=t.string();continue;case 2:if(o!==18)break;r.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{secp256k1:S(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:S(e.ed25519)?globalThis.String(e.ed25519):""}},toJSON(e){const n={};return e.secp256k1!==""&&(n.secp256k1=e.secp256k1),e.ed25519!==""&&(n.ed25519=e.ed25519),n},create(e){return rn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=be();return s.secp256k1=(n=e.secp256k1)!=null?n:"",s.ed25519=(t=e.ed25519)!=null?t:"",s}};function Se(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const an={encode(e,n=d().Writer.create()){e.id!==""&&n.uint32(10).string(e.id),e.chain!==""&&n.uint32(18).string(e.chain),e.fromAddress!==""&&n.uint32(26).string(e.fromAddress),e.toAddress!==""&&n.uint32(34).string(e.toAddress);for(const t of e.coins)T.encode(t,n.uint32(42).fork()).ldelim();for(const t of e.gas)T.encode(t,n.uint32(50).fork()).ldelim();return e.memo!==""&&n.uint32(58).string(e.memo),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Se();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.id=t.string();continue;case 2:if(o!==18)break;r.chain=t.string();continue;case 3:if(o!==26)break;r.fromAddress=t.string();continue;case 4:if(o!==34)break;r.toAddress=t.string();continue;case 5:if(o!==42)break;r.coins.push(T.decode(t,t.uint32()));continue;case 6:if(o!==50)break;r.gas.push(T.decode(t,t.uint32()));continue;case 7:if(o!==58)break;r.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{id:S(e.id)?globalThis.String(e.id):"",chain:S(e.chain)?globalThis.String(e.chain):"",fromAddress:S(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:S(e.toAddress)?globalThis.String(e.toAddress):"",coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],gas:globalThis.Array.isArray(e==null?void 0:e.gas)?e.gas.map(n=>T.fromJSON(n)):[],memo:S(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const s={};return e.id!==""&&(s.id=e.id),e.chain!==""&&(s.chain=e.chain),e.fromAddress!==""&&(s.fromAddress=e.fromAddress),e.toAddress!==""&&(s.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(s.coins=e.coins.map(r=>T.toJSON(r))),(t=e.gas)!=null&&t.length&&(s.gas=e.gas.map(r=>T.toJSON(r))),e.memo!==""&&(s.memo=e.memo),s},create(e){return an.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s,r,o,l,i;const c=Se();return c.id=(n=e.id)!=null?n:"",c.chain=(t=e.chain)!=null?t:"",c.fromAddress=(s=e.fromAddress)!=null?s:"",c.toAddress=(r=e.toAddress)!=null?r:"",c.coins=((o=e.coins)==null?void 0:o.map(u=>T.fromPartial(u)))||[],c.gas=((l=e.gas)==null?void 0:l.map(u=>T.fromPartial(u)))||[],c.memo=(i=e.memo)!=null?i:"",c}};function Pe(){return{coins:[],poolDeduct:""}}const cn={encode(e,n=d().Writer.create()){for(const t of e.coins)T.encode(t,n.uint32(10).fork()).ldelim();return e.poolDeduct!==""&&n.uint32(18).string(e.poolDeduct),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Pe();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;r.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],poolDeduct:S(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(s=>T.toJSON(s))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return cn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Pe();return s.coins=((n=e.coins)==null?void 0:n.map(r=>T.fromPartial(r)))||[],s.poolDeduct=(t=e.poolDeduct)!=null?t:"",s}};function Ie(){return{value:""}}const ln={encode(e,n=d().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ie();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{value:S(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return ln.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ie();return t.value=(n=e.value)!=null?n:"",t}};d().util.Long!==x()&&(d().util.Long=x(),d().configure());function S(e){return e!=null}const $n="types";function Oe(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const le={encode(e,n=d().Writer.create()){for(const t of e.coins)T.encode(t,n.uint32(10).fork()).ldelim();return e.memo!==""&&n.uint32(18).string(e.memo),e.signer.length!==0&&n.uint32(26).bytes(e.signer),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Oe();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;r.memo=t.string();continue;case 3:if(o!==26)break;r.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],memo:xe(e.memo)?globalThis.String(e.memo):"",signer:xe(e.signer)?un(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(s=>T.toJSON(s))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=dn(e.signer)),t},create(e){return le.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s;const r=Oe();return r.coins=((n=e.coins)==null?void 0:n.map(o=>T.fromPartial(o)))||[],r.memo=(t=e.memo)!=null?t:"",r.signer=(s=e.signer)!=null?s:new Uint8Array(0),r}};function un(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let s=0;s<n.length;++s)t[s]=n.charCodeAt(s);return t}}function dn(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}d().util.Long!==x()&&(d().util.Long=x(),d().configure());function xe(e){return e!=null}const Hn="cosmos.base.v1beta1";function De(){return{denom:"",amount:""}}const $={encode(e,n=d().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=De();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.denom=t.string();continue;case 2:if(o!==18)break;r.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{denom:H(e.denom)?globalThis.String(e.denom):"",amount:H(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return $.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=De();return s.denom=(n=e.denom)!=null?n:"",s.amount=(t=e.amount)!=null?t:"",s}};function Ee(){return{denom:"",amount:""}}const fn={encode(e,n=d().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ee();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.denom=t.string();continue;case 2:if(o!==18)break;r.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{denom:H(e.denom)?globalThis.String(e.denom):"",amount:H(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return fn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Ee();return s.denom=(n=e.denom)!=null?n:"",s.amount=(t=e.amount)!=null?t:"",s}};function Be(){return{int:""}}const hn={encode(e,n=d().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Be();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{int:H(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return hn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Be();return t.int=(n=e.int)!=null?n:"",t}};function Ne(){return{dec:""}}const mn={encode(e,n=d().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ne();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{dec:H(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return mn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ne();return t.dec=(n=e.dec)!=null?n:"",t}};d().util.Long!==x()&&(d().util.Long=x(),d().configure());function H(e){return e!=null}const Vn="types";function Re(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const ue={encode(e,n=d().Writer.create()){e.fromAddress.length!==0&&n.uint32(10).bytes(e.fromAddress),e.toAddress.length!==0&&n.uint32(18).bytes(e.toAddress);for(const t of e.amount)$.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Re();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.fromAddress=t.bytes();continue;case 2:if(o!==18)break;r.toAddress=t.bytes();continue;case 3:if(o!==26)break;r.amount.push($.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{fromAddress:Fe(e.fromAddress)?Ue(e.fromAddress):new Uint8Array(0),toAddress:Fe(e.toAddress)?Ue(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>$.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=Me(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=Me(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(s=>$.toJSON(s))),t},create(e){return ue.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s;const r=Re();return r.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),r.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),r.amount=((s=e.amount)==null?void 0:s.map(o=>$.fromPartial(o)))||[],r}};function Ue(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let s=0;s<n.length;++s)t[s]=n.charCodeAt(s);return t}}function Me(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}d().util.Long!==x()&&(d().util.Long=x(),d().configure());function Fe(e){return e!=null}var gn=Object.defineProperty,yn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,kn=Object.prototype.propertyIsEnumerable,_e=(e,n,t)=>n in e?gn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Cn=(e,n)=>{for(var t in n||(n={}))vn.call(n,t)&&_e(e,t,n[t]);if(We)for(var t of We(n))kn.call(n,t)&&_e(e,t,n[t]);return e},Tn=(e,n)=>yn(e,pn(n));const An=e=>{const n=new _.Registry([["/ibc.applications.transfer.v1.MsgTransfer",oe.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",te.$n]]);let t=s=>{const{amount:r,fromAddress:o,toAddress:l}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:Y.MsgSend.encode(Y.MsgSend.fromPartial({fromAddress:o,toAddress:l,amount:r})).finish()}};switch(e){case"thorchainrune":{const s="/types.MsgDeposit";n.register(s,le);const r=l=>{const{assets:i,memo:c,signer:u}=l,f=i.map(v=>Tn(Cn({},v),{asset:Ze(v.asset)}));return{typeUrl:s,value:le.encode(le.fromPartial({coins:f,memo:c,signer:(0,W.fromBech32)(u).data})).finish()}},o="/types.MsgSend";return n.register(o,ue),t=l=>{const{amount:i,fromAddress:c,toAddress:u}=l;return{typeUrl:o,value:ue.encode(ue.fromPartial({fromAddress:(0,W.fromBech32)(c).data,toAddress:(0,W.fromBech32)(u).data,amount:i})).finish()}},{methods:{deposit:r,transfer:t},registry:n}}}return{methods:{transfer:t},registry:n}};var wn=g(7416),Le=g(45504),D=g(29639),bn=g(94935),Sn=g(84650),Pn=g(72681),In=Object.defineProperty,On=Object.defineProperties,xn=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,Dn=Object.getPrototypeOf,En=Object.prototype.hasOwnProperty,Bn=Object.prototype.propertyIsEnumerable,Nn=Reflect.get,Ke=(e,n,t)=>n in e?In(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,de=(e,n)=>{for(var t in n||(n={}))En.call(n,t)&&Ke(e,t,n[t]);if(Je)for(var t of Je(n))Bn.call(n,t)&&Ke(e,t,n[t]);return e},Xe=(e,n)=>On(e,xn(n)),$e=(e,n,t)=>Nn(Dn(e),t,n),w=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});const He=5e3,Rn=3e3,Un=1e3*60*60*24*14,Mn=1e3*60*2;class fe extends Sn.P{constructor(n,t,s,r){super(n,t,s,r),this.networkInfo=n.networkInfo,this.fetchCors=n.io.fetchCors,this.accountNumber=0,this.sequence=0,this.unconfirmedTransactionCache={cacheSequence:0,txids:new Map},this.feeCache=new Map,this.stakedBalanceCache="0",this.stakingSupported=!0,this.otherMethods={getMaxTx:o=>w(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i}=o;if(l.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const c=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),{networkFee:u}=yield this.calculateFee({messages:[c],memo:i}),f=this.getBalance({currencyCode:this.currencyInfo.currencyCode});return(0,b.sub)(f,u)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>w(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i,metadata:c}=o,u=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),f=this.createUnsignedTxHex([u],i),{gasFeeCoin:p,gasLimit:v,networkFee:h}=yield this.calculateFee({messages:[u],memo:i}),m={gasFeeCoin:p,gasLimit:v,unsignedTxHex:f};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:c,nativeAmount:`-${h}`,networkFee:h,otherParams:m,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>w(this,null,function*(){try{switch(o==null?void 0:o.method){case"cosmos_getAccounts":return{nativeAmount:"0",networkFee:"0",tokenId:null};case"cosmos_signDirect":{const l=J(o),{authInfoBytes:i,bodyBytes:c}=l.params.signDoc,u=D.TxBody.decode(ce(c)),{nativeAmount:f,tokenId:p}=this.getAmountAndTokenIdFromKnownMessageTypes(u.messages),v=D.AuthInfo.decode(ce(i));let h="0";const m=v.fee;return m!=null&&(h=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:f,networkFee:h,tokenId:p}}case"cosmos_signAmino":{const l=ve(o),{signDoc:i}=l.params,c=(0,N.makeSignDoc)(i.msgs,i.fee,i.chain_id,i.memo,i.account_number,i.sequence),u=new y.AminoTypes(de(de({},y.createBankAminoConverters),y.createIbcAminoConverters)),f=c.msgs.map(k=>u.fromAmino(k)),{nativeAmount:p,tokenId:v}=this.getAmountAndTokenIdFromKnownMessageTypes(f);let h="0";const m=i.fee;return m!=null&&(h=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:p,networkFee:h,tokenId:v}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(l){throw this.warn("Wallet connect call_request ",l),l}})}}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let s=null,r;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const l=this.tools.registry.decode(o),i=oe.MsgTransfer.fromPartial(l);s===void 0&&(s=this.allTokensMap[i.token.denom]!=null?i.token.denom:null);const c=(0,y.coin)(i.token.amount,i.token.denom);r==null?r=c:r=K([r,c]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const l=this.tools.registry.decode(o),i=te.$n.fromPartial(l),{funds:c}=i;if(c.length>0){const{denom:u}=c[0];s===void 0&&(s=this.allTokensMap[u]!=null?u:null);let f=(0,y.coin)("0",u);for(const p of c)f=K([f,p]);r==null?r=f:r=K([r,f])}break}default:}return{nativeAmount:(t=r==null?void 0:r.amount)!=null?t:"0",tokenId:s}}setOtherData(n){this.otherData=A(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return w(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),s=yield t.getAllBalances(this.walletInfo.keys.bech32Address),r=s.find(i=>i.denom===this.networkInfo.nativeDenom);if(this.updateBalance(this.currencyInfo.currencyCode,(n=r==null?void 0:r.amount)!=null?n:"0"),this.enabledTokenIds.forEach(i=>{var c;const u=this.allTokensMap[i],f=s.find(p=>p.denom===i);this.updateBalance(u.currencyCode,(c=f==null?void 0:f.amount)!=null?c:"0")}),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const c={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(c),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:o,sequence:l}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=o,this.sequence=l}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return w(this,null,function*(){try{const{stargateClient:n}=this.getClients(),t=yield n.getHeight();t>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(n){this.error("queryBlockheight Error ",n)}})}queryTransactions(){return w(this,null,function*(){let n=0;const t=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(r=>this.allTokensMap[r].currencyCode)],s=Date.now()-Un>this.otherData.archivedTxLastCheckTime?yield ke(this.fetchCors,ge(this.networkInfo.archiveNode,this.tools.initOptions)):this.getClients();for(const r of G){const o=yield this.queryTransactionsInner(r,s);o!=null&&this.otherData[r]!==o&&(this.otherData[r]=o,this.walletLocalDataDirty=!0),n+=.5,t.forEach(l=>this.tokenCheckTransactionsStatus[l]=n),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=Date.now(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}queryTransactionsInner(n,t){return w(this,null,function*(){const s={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:50,order_by:"desc"};let r,o=0,l,i=0,c=!1;try{do{const u=yield t.cometClient.txSearch(Xe(de({},s),{page:++o})),{totalCount:f,txs:p}=u;l==null&&(l=f),i=i+p.length;for(const v of p){const h=(0,W.toHex)(v.hash).toUpperCase();if(this.removeFromUnconfirmedCache(h),r==null&&(r=h),h===this.otherData[n]){c=!0;break}const m=v.result.events.map(y.fromTendermintEvent);let k=[];try{k=tn(m,this.walletInfo.keys.bech32Address)}catch(ye){this.log.warn("reduceCoinEventsForAddress error:",String(ye))}if(k.length===0)continue;const O=yield t.stargateClient.getBlock(v.height),B=(0,C.toSeconds)((0,C.fromRfc3339WithNanoseconds)(O.header.time)).seconds,{height:U,tx:M}=v,he=P.YU.stringify(M),{authInfo:{fee:F},body:{memo:Ln,messages:Jn}}=(0,_.decodeTxRaw)(M),Kn=yield this.totalDynamicNetworkFee(Jn,O.header.height);k.forEach(ye=>{this.processCosmosTransaction(h,B,he,ye,Ln,U,Kn,F)})}}while(l>i&&!c)}catch(u){throw this.log.warn("queryTransactions error:",u),u}return r})}processCosmosTransaction(n,t,s,r,o,l,i,c){const{amount:u,denom:f}=r,p=this.networkInfo.nativeDenom===f,v=this.networkInfo.nativeDenom===f?this.currencyInfo.currencyCode:this.allTokensMap[f]!=null?this.allTokensMap[f].currencyCode:void 0;if(v==null)return;let h="0";if(c!=null){const{amount:he}=c,F=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...he]);h=(0,b.add)(h,F.amount)}const m=(0,b.lt)(u,"0"),k=[];let O=u,B;m?p?(h=(0,b.add)(h,i),O=(0,b.sub)(O,h)):(h="0",B=i!=="0"?i:void 0):(k.push(this.walletInfo.keys.bech32Address),h="0");const U=[];o!==""&&U.push({type:"text",value:o});const M={blockHeight:l,currencyCode:v,date:t,isSend:m,memos:U,nativeAmount:O,networkFee:h,ourReceiveAddresses:k,parentNetworkFee:B,signedTx:s,txid:n,walletId:this.walletId};this.addTransaction(v,M)}createUnsignedTxHex(n,t){const s=D.TxBody.fromPartial({messages:n,memo:t}),r=D.TxBody.encode(s).finish(),o=D.TxRaw.fromPartial({bodyBytes:r});return P.YU.stringify(D.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+Mn);this.unconfirmedTransactionCache.txids.size===0&&(this.unconfirmedTransactionCache.cacheSequence=this.sequence),this.unconfirmedTransactionCache.txids.set(n,t)}removeFromUnconfirmedCache(n){this.unconfirmedTransactionCache.txids.has(n)&&(this.unconfirmedTransactionCache.cacheSequence=this.unconfirmedTransactionCache.cacheSequence+1,this.sequence=this.unconfirmedTransactionCache.cacheSequence,this.unconfirmedTransactionCache.txids.delete(n))}getSequence(){return this.unconfirmedTransactionCache.txids.size===0?this.sequence:[...this.unconfirmedTransactionCache.txids.values()].some(n=>n<new Date)?(this.unconfirmedTransactionCache.txids=new Map,this.sequence):this.unconfirmedTransactionCache.cacheSequence+this.unconfirmedTransactionCache.txids.size}totalDynamicNetworkFee(n,t){return w(this,null,function*(){let s="0";if(this.networkInfo.defaultTransactionFeeUrl==null)return s;const{url:r,headers:o}=ge(this.networkInfo.defaultTransactionFeeUrl,this.tools.initOptions),l=t==null?"":`?height=${t}`,c=yield(yield this.fetchCors(`${r}${l}`,{method:"GET",headers:o})).json(),u=ie(c);for(const f of n)switch(f.typeUrl){case"/types.MsgDeposit":s=(0,b.add)(s,u.native_outbound_fee_rune);break;case"/types.MsgSend":s=(0,b.add)(s,u.native_tx_fee_rune)}return s})}calculateFee(n){return w(this,null,function*(){const{messages:t,memo:s,networkFeeOption:r}=n;let o=(0,y.coin)("0",this.networkInfo.nativeDenom),l="0",i="0";if(this.networkInfo.defaultTransactionFeeUrl==null){const{queryClient:c}=this.getClients(),{gasInfo:u}=yield c.tx.simulate(t,s,(0,N.encodeSecp256k1Pubkey)(P.YU.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((u==null?void 0:u.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");l=(0,b.ceil)((0,b.mul)(u==null?void 0:u.gasUsed.toString(),"1.5"),0);const{low:f,average:p,high:v}=(0,wn.getGasPriceStep)(this.tools.chainData);let h=p;switch(r){case"low":{h=f;break}case"high":{h=v;break}case"custom":throw new Error("Custom fee not supported")}const m=(0,b.ceil)((0,b.mul)(l,h.toString()),0);o=(0,y.coin)(m,this.networkInfo.nativeDenom),i=o.amount}else i=yield this.totalDynamicNetworkFee(t),i=(0,b.mul)(i,"1.01");return{gasFeeCoin:o,gasLimit:l,networkFee:i}})}startEngine(){return w(this,null,function*(){this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",He).catch(()=>{}),this.addToLoop("queryBlockheight",He).catch(()=>{}),this.addToLoop("queryTransactions",Rn).catch(()=>{}),yield $e(fe.prototype,this,"startEngine").call(this)})}killEngine(){return w(this,null,function*(){yield this.tools.disconnectClient(),yield $e(fe.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return w(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(n){return w(this,null,function*(){var t;n=(0,Pn.s)(n,this.currencyInfo);const{edgeSpendInfo:s,currencyCode:r}=this.makeSpendCheck(n),{memos:o=[],networkFeeOption:l,tokenId:i}=s,c=(t=o[0])==null?void 0:t.value;if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:u,publicAddress:f}=s.spendTargets[0];if(u==null)throw new bn.$D;if(f==null)throw new Error("makeSpend Missing publicAddress");const p=this.tools.methods.transfer({amount:[(0,y.coin)(u,i!=null?i:this.networkInfo.nativeDenom)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:f});let v,h,m;const k=`${f}${String(l)}`,O=this.feeCache.get(k);if(u==="0")v=(0,y.coin)("0",this.networkInfo.nativeDenom),h="0",m="0";else if(O==null){const F=yield this.calculateFee({messages:[p],memo:c,networkFeeOption:l});v=F.gasFeeCoin,h=F.gasLimit,m=F.networkFee,this.feeCache.set(k,F)}else v=O.gasFeeCoin,h=O.gasLimit,m=O.networkFee;const B=this.createUnsignedTxHex([p],c),U={gasFeeCoin:v,gasLimit:h,unsignedTxHex:B},M=this.makeEdgeTransactionAmounts(u,m,i);return this.checkBalances(M,i),{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:o,nativeAmount:M.nativeAmount,networkFee:M.networkFee,otherParams:U,ourReceiveAddresses:[],parentNetworkFee:M.parentNetworkFee,signedTx:"",txid:"",walletId:this.walletId}})}signMessage(n,t,s){return w(this,null,function*(){const r=Z(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(r.mnemonic);if((s==null?void 0:s.otherParams)!=null)switch(s.otherParams.method){case"cosmos_getAccounts":{z(s.otherParams);const m=(yield o.getAccounts()).map(k=>Xe(de({},k),{pubkey:P.US.stringify(k.pubkey)}));return JSON.stringify(m)}case"cosmos_signDirect":{const h=J(s.otherParams),{signDoc:m}=h.params,k=D.SignDoc.fromPartial({accountNumber:(0,Le.longify)(m.accountNumber),authInfoBytes:ce(m.authInfoBytes),bodyBytes:ce(m.bodyBytes),chainId:m.chainId}),B={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,k)).signature,signed:h.params.signDoc};return JSON.stringify(B)}case"cosmos_signAmino":{const h=ve(s.otherParams),{signDoc:m}=h.params,k=(0,N.makeSignDoc)(m.msgs,m.fee,m.chain_id,m.memo,m.account_number,m.sequence),U={signature:(yield(yield N.Secp256k1HdWallet.fromMnemonic(o.mnemonic)).signAmino(this.walletInfo.keys.bech32Address,k)).signature,signed:m};return JSON.stringify(U)}default:throw new Error(`Invalid method: ${s.method}`)}const l=P.YU.parse(n),i=D.SignDoc.decode(l),c=yield o.signDirect(this.walletInfo.keys.bech32Address,i),u=(0,N.decodeSignature)(c.signature),f=D.TxRaw.fromPartial({authInfoBytes:i.authInfoBytes,bodyBytes:i.bodyBytes,signatures:[u.signature]}),p=D.TxRaw.encode(f).finish();return P.YU.stringify(p)})}signTx(n,t){return w(this,null,function*(){const{gasFeeCoin:s,gasLimit:r,unsignedTxHex:o}=re(n.otherParams),l=Z(this.currencyInfo.pluginId)(t),i=P.YU.parse(o),{bodyBytes:c}=D.TxRaw.decode(i),u=P.YU.parse(this.walletInfo.keys.publicKey),f=(0,N.encodeSecp256k1Pubkey)(u),p=(0,_.makeAuthInfoBytes)([{pubkey:(0,_.encodePubkey)(f),sequence:this.getSequence()}],[s],parseInt(r),void 0,void 0,1),v=D.SignDoc.fromPartial({accountNumber:(0,Le.longify)(this.accountNumber),authInfoBytes:p,bodyBytes:c,chainId:this.tools.chainData.chain_id}),m=yield(yield this.tools.createSigner(l.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,v),k=(0,N.decodeSignature)(m.signature),O=D.TxRaw.fromPartial({authInfoBytes:p,bodyBytes:c,signatures:[k.signature]}),B=D.TxRaw.encode(O).finish(),U=P.YU.stringify(B);return n.signedTx=U,n})}broadcastTx(n){return w(this,null,function*(){try{const t=P.YU.parse(n.signedTx),{stargateClient:s}=this.getClients(),r=yield s.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
- ${(0,ne.oX)(n)}`),n.txid=r,n.date=Date.now()/1e3,this.addToUnconfirmedCache(r),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return w(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function Fn(e,n,t,s){return w(this,null,function*(){const r=L(t),o=new fe(e,n,r,s);return yield o.loadEngine(),o})}var Wn=g(48764).Buffer,E=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});class Ve{constructor(n){const{builtinTokens:t,currencyInfo:s,initOptions:r,io:o,networkInfo:l}=n;this.io=o,this.currencyInfo=s,this.builtinTokens=t,this.networkInfo=l,this.initOptions=r,this.clientCount=0;const{methods:i,registry:c}=An(s.pluginId);this.methods=i,this.registry=c;const{data:u,name:f,url:p}=this.networkInfo.chainInfo;this.chainData=u;const v=new V.ChainRegistryFetcher;v.fetch(p).then(()=>{this.chainData=v.getChain(f)}).catch(h=>{})}createSigner(n){return E(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:s}=this.networkInfo,r=(0,pe.stringToPath)(s);return yield _.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[r],prefix:t})})}getDisplayPrivateKey(n){return E(this,null,function*(){const{pluginId:t}=this.currencyInfo;return Z(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return E(this,null,function*(){const{keys:t}=L(n);return t.publicKey})}importPrivateKey(n){return E(this,null,function*(){if(!(0,j.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return E(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=Wn.from(this.io.random(32)),s=(0,j.entropyToMnemonic)(t);return yield this.importPrivateKey(s)})}derivePublicKey(n){return E(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=Z(this.currencyInfo.pluginId)(n.keys),r=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:l}=r[0],i=P.YU.stringify(l);return{bech32Address:o,publicKey:i}})}isValidAddress(n){try{if((0,W.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}parseUri(n,t,s){return E(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{parsedUri:l,edgeParsedUri:i}=(0,ee.k)(this.currencyInfo,n,o,t!=null?t:this.currencyInfo.currencyCode,s);let c="";if(i.publicAddress!=null&&(c=i.publicAddress),!this.isValidAddress(c))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=l.query.memo,i})}encodeUri(n){return E(this,arguments,function*(t,s=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:o,currencyCode:l,publicAddress:i}=t;if(!this.isValidAddress(i))throw new Error("InvalidPublicAddressError");let c;if(typeof o=="string"){const f=(0,ne.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,s);if(f==null)throw new Error("InternalErrorInvalidCurrencyCode");c=(0,b.div)(o,f.multiplier,18)}return(0,ee.Q)(t,r,c)})}connectClient(){return E(this,null,function*(){this.clients==null&&(this.clients=yield ke(this.io.fetchCors,ge(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return E(this,null,function*(){var n,t;--this.clientCount,this.clientCount===0&&(yield(t=(n=this.clients)==null?void 0:n.stargateClient)==null?void 0:t.disconnect(),this.clients=void 0)})}getTokenId(n){return E(this,null,function*(){(0,q.Rp)(n);const t=(0,q.Oj)(n.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase()})}}function _n(e){return E(this,null,function*(){return new Ve(e)})}},89214:function(){},20131:function(){},16026:function(){},52361:function(){},94616:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8222],{79014:function(Ge,ee,g){"use strict";g.d(ee,{Q:function(){return N},k:function(){return re}});var q=g(77591),ke=g.n(q),F=g(24350),_=g(84564),b=g.n(_),ne=g(76714),I=Object.defineProperty,Y=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable,G=(y,C,a)=>C in y?I(y,C,{enumerable:!0,configurable:!0,writable:!0,value:a}):y[C]=a,se=(y,C)=>{for(var a in C||(C={}))te.call(C,a)&&G(y,a,C[a]);if(Y)for(var a of Y(C))oe.call(C,a)&&G(y,a,C[a]);return y};function re(y,C,a,P,Z=[]){const A=se({},b()(C,{},!0)),L=C.startsWith(`${y.pluginId}://`);if(A.protocol!=null&&(A.protocol=A.protocol.replace(":","")),A.protocol!=null&&A.protocol!==""&&!a[A.protocol])throw new Error(`Uri protocol '${A.protocol}' is not supported for ${y.pluginId}.`);if(A.host===""&&A.pathname==="")throw new Error("Path and host not found in uri.");const R={publicAddress:A.host!==""?A.host:A.pathname.split("/")[0]},ie=A.query.label,ae=A.query.message,ce=A.query.category;(ie!=null||ae!=null||ce!=null||L)&&(R.metadata={},R.metadata.name=ie,R.metadata.notes=ae,R.metadata.category=ce,R.metadata.gateway=L!=null?L:!1);const Q=A.query.amount;if(Q!=null&&typeof Q=="string"){P==null&&(P=y.currencyCode);const le=(0,ne.Qs)(P!=null?P:"",y,Z);if(le==null)throw new Error("InternalErrorInvalidCurrencyCode");let J=(0,q.mul)(Q,le.multiplier);J=(0,q.toFixed)(J,0,0),R.nativeAmount=J,R.currencyCode=P}return{edgeParsedUri:R,parsedUri:A}}function N(y,C,a){if(y.publicAddress==null)throw new Error("InvalidPublicAddressError");if(a==null&&y.label==null&&y.message==null)return y.publicAddress;{let P="";a!=null&&(P+="amount="+a+"&"),(y.label!=null||y.message!=null)&&(typeof y.label=="string"&&(P+="label="+y.label+"&"),typeof y.message=="string"&&(P+="message="+y.message+"&")),P=P.substr(0,P.length-1);const Z={scheme:C,path:y.publicAddress,query:P};return(0,F.qC)(Z)}}},94831:function(Ge,ee,g){"use strict";g.r(ee),g.d(ee,{CosmosTools:function(){return Ye},makeCurrencyEngine:function(){return Wn},makeCurrencyTools:function(){return Jn}});var q=g(87137),ke=g(79562),F=g(28972),_=g(74087),b=g(77591),ne=g(2153),I=g(79325),Y=g(20918),te=g(79014),oe=g(76714),G=g(98994),se=g(2387),re=g(39385),N=g(33359),y=g(24658),C=g(73034),a=g(82448),P=g(62177);const Z=["coin_spent.spender","coin_received.receiver"],A=(0,a.su)({archivedTxLastCheckTime:(0,a.Vk)(a.mH,0),"coin_spent.spender":(0,a.Vk)(a.XC),"coin_received.receiver":(0,a.Vk)(a.XC)}),L=(0,P.jd)((0,a.su)({bech32Address:a.XC,publicKey:a.XC})),z=e=>{const n=(0,a.su)({[`${e}Mnemonic`]:a.XC});return(0,a.W1)(t=>({mnemonic:n(t)[`${e}Mnemonic`]}),t=>({[`${e}Mnemonic`]:t.mnemonic}))},R=(0,a.su)({ninerealmsClientId:(0,a.Zz)(a.XC)}),ie=(0,a.su)({denom:a.XC,amount:a.XC}),ae=(0,a.su)({gasFeeCoin:ie,gasLimit:a.XC,unsignedTxHex:a.XC}),ce=(0,a.su)({native_outbound_fee_rune:a.XC,native_tx_fee_rune:a.XC}),Q=(0,a.su)({method:(0,a.Wf)("cosmos_getAccounts"),params:(0,a.su)({})}),le=(0,a.Wf)("cosmos_signDirect"),J=(0,a.su)({method:le,params:(0,a.su)({signerAddress:a.XC,signDoc:(0,a.su)({chainId:a.XC,accountNumber:a.XC,authInfoBytes:a.XC,bodyBytes:a.XC})})}),Ce=(0,a.su)({method:(0,a.Wf)("cosmos_signAmino"),params:(0,a.su)({signerAddress:a.XC,signDoc:(0,a.su)({chain_id:a.XC,account_number:a.XC,sequence:a.XC,memo:a.XC,msgs:(0,a._2)((0,a.su)({type:a.XC,value:a.JC})),fee:(0,a.su)({amount:(0,a._2)((0,a.su)({denom:a.XC,amount:a.XC})),gas:a.XC})})})});var ye=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});const pe=(e,n)=>{const t=R(n),s={},r=/{{(.*?)}}/g;for(const[o,l]of Object.entries(e.headers)){const i=r.exec(l);i!=null&&(s[o]=t[i[1]])}return{url:e.url,headers:s}},Ze=(e,n)=>{const{url:t,headers:s}=n;return{execute:r=>ye(void 0,null,function*(){const o={method:"POST",headers:s,body:JSON.stringify(r)};return yield(yield e(t,o)).json()}),disconnect:()=>{}}},ze=e=>ye(void 0,null,function*(){const n=yield C.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield C.Tendermint37Client.create(e):yield C.Tendermint34Client.create(e)}),Te=(e,n)=>ye(void 0,null,function*(){const t=yield y.StargateClient.create(yield ze(Ze(e,n))),s=t.forceGetQueryClient(),r=t.forceGetCometClient();return{queryClient:s,stargateClient:t,cometClient:r}}),Qe=e=>{var n;const[t,...s]=e.split("."),r=e.includes("/"),o=s.join("."),l=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:l,synth:r}},K=e=>e.reduce((n,t)=>{try{return(0,N.addCoins)(n,t)}catch{}return n}),Ae=(0,a.Wf)("amount"),je=(0,a.Wf)("receiver"),en=(0,a.Wf)("spender"),nn=(0,a.Wf)("amount","receiver","spender"),tn=(0,a.su)({type:(0,a.Wf)("coin_received"),attributes:(0,a.vq)((0,a.su)({key:Ae,value:a.XC}),(0,a.su)({key:je,value:a.XC}))}),on=(0,a.su)({type:(0,a.Wf)("coin_spent"),attributes:(0,a.vq)((0,a.su)({key:Ae,value:a.XC}),(0,a.su)({key:en,value:a.XC}))}),sn=(e,n)=>{const t=new Map;for(const r of e){const o={type:r.type,attributes:r.attributes.filter(c=>(0,a.Vk)(nn)(c.key)!=null).sort((c,u)=>c.key<u.key?-1:1)},l=(0,a.Vk)(tn)(o);if(l!=null){const[c,u]=l.attributes.map(m=>m.value);if(u!==n)continue;we(c).forEach(m=>{var p;const v=m.amount,f=(p=t.get(m.denom))!=null?p:"0";t.set(m.denom,(0,b.add)(v,f))});continue}const i=(0,a.Vk)(on)(o);if(i!=null){const[c,u]=i.attributes.map(m=>m.value);if(u!==n)continue;we(c).forEach(m=>{var p;const v=`-${m.amount}`,f=(p=t.get(m.denom))!=null?p:"0";t.set(m.denom,(0,b.add)(v,f))})}}const s=[];return t.forEach((r,o)=>{r!=="0"&&s.push({denom:o,amount:r})}),s},ue=e=>{try{return I.YU.parse(e)}catch{return I.US.parse(e)}},we=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const s=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(s==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=s[1].replace(/^0+/,""))!=null?t:"0",denom:s[2]}});var rn=g(43720),O=g.n(rn),an=g(62100),d=g.n(an);const Xn="common";function be(){return{chain:"",symbol:"",ticker:"",synth:!1}}const X={encode(e,n=d().Writer.create()){return e.chain!==""&&n.uint32(10).string(e.chain),e.symbol!==""&&n.uint32(18).string(e.symbol),e.ticker!==""&&n.uint32(26).string(e.ticker),e.synth===!0&&n.uint32(32).bool(e.synth),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=be();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.chain=t.string();continue;case 2:if(o!==18)break;r.symbol=t.string();continue;case 3:if(o!==26)break;r.ticker=t.string();continue;case 4:if(o!==32)break;r.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{chain:S(e.chain)?globalThis.String(e.chain):"",symbol:S(e.symbol)?globalThis.String(e.symbol):"",ticker:S(e.ticker)?globalThis.String(e.ticker):"",synth:S(e.synth)?globalThis.Boolean(e.synth):!1}},toJSON(e){const n={};return e.chain!==""&&(n.chain=e.chain),e.symbol!==""&&(n.symbol=e.symbol),e.ticker!==""&&(n.ticker=e.ticker),e.synth===!0&&(n.synth=e.synth),n},create(e){return X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s,r;const o=be();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(s=e.ticker)!=null?s:"",o.synth=(r=e.synth)!=null?r:!1,o}};function Se(){return{asset:void 0,amount:"",decimals:O().ZERO}}const T={encode(e,n=d().Writer.create()){return e.asset!==void 0&&X.encode(e.asset,n.uint32(10).fork()).ldelim(),e.amount!==""&&n.uint32(18).string(e.amount),e.decimals.isZero()||n.uint32(24).int64(e.decimals),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Se();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.asset=X.decode(t,t.uint32());continue;case 2:if(o!==18)break;r.amount=t.string();continue;case 3:if(o!==24)break;r.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{asset:S(e.asset)?X.fromJSON(e.asset):void 0,amount:S(e.amount)?globalThis.String(e.amount):"",decimals:S(e.decimals)?O().fromValue(e.decimals):O().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=X.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||O().ZERO).toString()),n},create(e){return T.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Se();return t.asset=e.asset!==void 0&&e.asset!==null?X.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?O().fromValue(e.decimals):O().ZERO,t}};function Ie(){return{secp256k1:"",ed25519:""}}const cn={encode(e,n=d().Writer.create()){return e.secp256k1!==""&&n.uint32(10).string(e.secp256k1),e.ed25519!==""&&n.uint32(18).string(e.ed25519),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ie();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.secp256k1=t.string();continue;case 2:if(o!==18)break;r.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{secp256k1:S(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:S(e.ed25519)?globalThis.String(e.ed25519):""}},toJSON(e){const n={};return e.secp256k1!==""&&(n.secp256k1=e.secp256k1),e.ed25519!==""&&(n.ed25519=e.ed25519),n},create(e){return cn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Ie();return s.secp256k1=(n=e.secp256k1)!=null?n:"",s.ed25519=(t=e.ed25519)!=null?t:"",s}};function Pe(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const ln={encode(e,n=d().Writer.create()){e.id!==""&&n.uint32(10).string(e.id),e.chain!==""&&n.uint32(18).string(e.chain),e.fromAddress!==""&&n.uint32(26).string(e.fromAddress),e.toAddress!==""&&n.uint32(34).string(e.toAddress);for(const t of e.coins)T.encode(t,n.uint32(42).fork()).ldelim();for(const t of e.gas)T.encode(t,n.uint32(50).fork()).ldelim();return e.memo!==""&&n.uint32(58).string(e.memo),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Pe();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.id=t.string();continue;case 2:if(o!==18)break;r.chain=t.string();continue;case 3:if(o!==26)break;r.fromAddress=t.string();continue;case 4:if(o!==34)break;r.toAddress=t.string();continue;case 5:if(o!==42)break;r.coins.push(T.decode(t,t.uint32()));continue;case 6:if(o!==50)break;r.gas.push(T.decode(t,t.uint32()));continue;case 7:if(o!==58)break;r.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{id:S(e.id)?globalThis.String(e.id):"",chain:S(e.chain)?globalThis.String(e.chain):"",fromAddress:S(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:S(e.toAddress)?globalThis.String(e.toAddress):"",coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],gas:globalThis.Array.isArray(e==null?void 0:e.gas)?e.gas.map(n=>T.fromJSON(n)):[],memo:S(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const s={};return e.id!==""&&(s.id=e.id),e.chain!==""&&(s.chain=e.chain),e.fromAddress!==""&&(s.fromAddress=e.fromAddress),e.toAddress!==""&&(s.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(s.coins=e.coins.map(r=>T.toJSON(r))),(t=e.gas)!=null&&t.length&&(s.gas=e.gas.map(r=>T.toJSON(r))),e.memo!==""&&(s.memo=e.memo),s},create(e){return ln.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s,r,o,l,i;const c=Pe();return c.id=(n=e.id)!=null?n:"",c.chain=(t=e.chain)!=null?t:"",c.fromAddress=(s=e.fromAddress)!=null?s:"",c.toAddress=(r=e.toAddress)!=null?r:"",c.coins=((o=e.coins)==null?void 0:o.map(u=>T.fromPartial(u)))||[],c.gas=((l=e.gas)==null?void 0:l.map(u=>T.fromPartial(u)))||[],c.memo=(i=e.memo)!=null?i:"",c}};function Oe(){return{coins:[],poolDeduct:""}}const un={encode(e,n=d().Writer.create()){for(const t of e.coins)T.encode(t,n.uint32(10).fork()).ldelim();return e.poolDeduct!==""&&n.uint32(18).string(e.poolDeduct),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Oe();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;r.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],poolDeduct:S(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(s=>T.toJSON(s))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return un.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Oe();return s.coins=((n=e.coins)==null?void 0:n.map(r=>T.fromPartial(r)))||[],s.poolDeduct=(t=e.poolDeduct)!=null?t:"",s}};function De(){return{value:""}}const dn={encode(e,n=d().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=De();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{value:S(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return dn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=De();return t.value=(n=e.value)!=null?n:"",t}};d().util.Long!==O()&&(d().util.Long=O(),d().configure());function S(e){return e!=null}const $n="types";function Ee(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const de={encode(e,n=d().Writer.create()){for(const t of e.coins)T.encode(t,n.uint32(10).fork()).ldelim();return e.memo!==""&&n.uint32(18).string(e.memo),e.signer.length!==0&&n.uint32(26).bytes(e.signer),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ee();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;r.memo=t.string();continue;case 3:if(o!==26)break;r.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],memo:xe(e.memo)?globalThis.String(e.memo):"",signer:xe(e.signer)?fn(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(s=>T.toJSON(s))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=hn(e.signer)),t},create(e){return de.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s;const r=Ee();return r.coins=((n=e.coins)==null?void 0:n.map(o=>T.fromPartial(o)))||[],r.memo=(t=e.memo)!=null?t:"",r.signer=(s=e.signer)!=null?s:new Uint8Array(0),r}};function fn(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let s=0;s<n.length;++s)t[s]=n.charCodeAt(s);return t}}function hn(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}d().util.Long!==O()&&(d().util.Long=O(),d().configure());function xe(e){return e!=null}const Hn="cosmos.base.v1beta1";function Be(){return{denom:"",amount:""}}const $={encode(e,n=d().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Be();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.denom=t.string();continue;case 2:if(o!==18)break;r.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{denom:H(e.denom)?globalThis.String(e.denom):"",amount:H(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return $.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Be();return s.denom=(n=e.denom)!=null?n:"",s.amount=(t=e.amount)!=null?t:"",s}};function Ue(){return{denom:"",amount:""}}const mn={encode(e,n=d().Writer.create()){return e.denom!==""&&n.uint32(10).string(e.denom),e.amount!==""&&n.uint32(18).string(e.amount),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ue();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.denom=t.string();continue;case 2:if(o!==18)break;r.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{denom:H(e.denom)?globalThis.String(e.denom):"",amount:H(e.amount)?globalThis.String(e.amount):""}},toJSON(e){const n={};return e.denom!==""&&(n.denom=e.denom),e.amount!==""&&(n.amount=e.amount),n},create(e){return mn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const s=Ue();return s.denom=(n=e.denom)!=null?n:"",s.amount=(t=e.amount)!=null?t:"",s}};function Ne(){return{int:""}}const gn={encode(e,n=d().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Ne();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{int:H(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return gn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ne();return t.int=(n=e.int)!=null?n:"",t}};function Re(){return{dec:""}}const yn={encode(e,n=d().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Re();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{dec:H(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return yn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Re();return t.dec=(n=e.dec)!=null?n:"",t}};d().util.Long!==O()&&(d().util.Long=O(),d().configure());function H(e){return e!=null}const Vn="types";function Me(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const fe={encode(e,n=d().Writer.create()){e.fromAddress.length!==0&&n.uint32(10).bytes(e.fromAddress),e.toAddress.length!==0&&n.uint32(18).bytes(e.toAddress);for(const t of e.amount)$.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof d().Reader?e:d().Reader.create(e);let s=n===void 0?t.len:t.pos+n;const r=Me();for(;t.pos<s;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;r.fromAddress=t.bytes();continue;case 2:if(o!==18)break;r.toAddress=t.bytes();continue;case 3:if(o!==26)break;r.amount.push($.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return r},fromJSON(e){return{fromAddress:We(e.fromAddress)?Fe(e.fromAddress):new Uint8Array(0),toAddress:We(e.toAddress)?Fe(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>$.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=_e(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=_e(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(s=>$.toJSON(s))),t},create(e){return fe.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,s;const r=Me();return r.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),r.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),r.amount=((s=e.amount)==null?void 0:s.map(o=>$.fromPartial(o)))||[],r}};function Fe(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let s=0;s<n.length;++s)t[s]=n.charCodeAt(s);return t}}function _e(e){if(globalThis.Buffer)return globalThis.Buffer.from(e).toString("base64");{const n=[];return e.forEach(t=>{n.push(globalThis.String.fromCharCode(t))}),globalThis.btoa(n.join(""))}}d().util.Long!==O()&&(d().util.Long=O(),d().configure());function We(e){return e!=null}var pn=Object.defineProperty,vn=Object.defineProperties,kn=Object.getOwnPropertyDescriptors,Le=Object.getOwnPropertySymbols,Cn=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable,Je=(e,n,t)=>n in e?pn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,An=(e,n)=>{for(var t in n||(n={}))Cn.call(n,t)&&Je(e,t,n[t]);if(Le)for(var t of Le(n))Tn.call(n,t)&&Je(e,t,n[t]);return e},wn=(e,n)=>vn(e,kn(n));const bn=e=>{const n=new _.Registry([["/ibc.applications.transfer.v1.MsgTransfer",re.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",se.$n]]);let t=s=>{const{amount:r,fromAddress:o,toAddress:l}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:G.MsgSend.encode(G.MsgSend.fromPartial({fromAddress:o,toAddress:l,amount:r})).finish()}};switch(e){case"thorchainrune":{const s="/types.MsgDeposit";n.register(s,de);const r=l=>{const{assets:i,memo:c,signer:u}=l,h=i.map(p=>wn(An({},p),{asset:Qe(p.asset)}));return{typeUrl:s,value:de.encode(de.fromPartial({coins:h,memo:c,signer:(0,F.fromBech32)(u).data})).finish()}},o="/types.MsgSend";return n.register(o,fe),t=l=>{const{amount:i,fromAddress:c,toAddress:u}=l;return{typeUrl:o,value:fe.encode(fe.fromPartial({fromAddress:(0,F.fromBech32)(c).data,toAddress:(0,F.fromBech32)(u).data,amount:i})).finish()}},{methods:{deposit:r,transfer:t},registry:n}}}return{methods:{transfer:t},registry:n}};var Sn=g(7416),Ke=g(45504),D=g(29639),In=g(94935),Pn=g(84650),On=g(72681),Dn=Object.defineProperty,En=Object.defineProperties,xn=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertySymbols,Bn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty,Nn=Object.prototype.propertyIsEnumerable,Rn=Reflect.get,$e=(e,n,t)=>n in e?Dn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,he=(e,n)=>{for(var t in n||(n={}))Un.call(n,t)&&$e(e,t,n[t]);if(Xe)for(var t of Xe(n))Nn.call(n,t)&&$e(e,t,n[t]);return e},He=(e,n)=>En(e,xn(n)),Ve=(e,n,t)=>Rn(Bn(e),t,n),w=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});const qe=5e3,Mn=3e3,Fn=1e3*60*60*24*14,_n=1e3*60*2;class me extends Pn.P{constructor(n,t,s,r){super(n,t,s,r),this.networkInfo=n.networkInfo,this.fetchCors=n.io.fetchCors,this.accountNumber=0,this.sequence=0,this.unconfirmedTransactionCache={cacheSequence:0,txids:new Map},this.feeCache=new Map,this.stakedBalanceCache="0",this.stakingSupported=!0,this.otherMethods={getMaxTx:o=>w(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i}=o;if(l.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const c=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),{networkFee:u}=yield this.calculateFee({messages:[c],memo:i}),h=this.getBalance({currencyCode:this.currencyInfo.currencyCode});return(0,b.sub)(h,u)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>w(this,null,function*(){switch(o.type){case"MakeTxDeposit":{if(this.tools.methods.deposit==null)throw new Error(`${this.currencyInfo.displayName} does not support the deposit method`);const{assets:l,memo:i,metadata:c}=o,u=this.tools.methods.deposit({assets:l,memo:i,signer:this.walletInfo.keys.bech32Address}),h=this.createUnsignedTxHex([u],i),{gasFeeCoin:m,gasLimit:p,networkFee:v}=yield this.calculateFee({messages:[u],memo:i}),f={gasFeeCoin:m,gasLimit:p,unsignedTxHex:h};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:c,nativeAmount:`-${v}`,networkFee:v,otherParams:f,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>w(this,null,function*(){try{switch(o==null?void 0:o.method){case"cosmos_getAccounts":return{nativeAmount:"0",networkFee:"0",tokenId:null};case"cosmos_signDirect":{const l=J(o),{authInfoBytes:i,bodyBytes:c}=l.params.signDoc,u=D.TxBody.decode(ue(c)),{nativeAmount:h,tokenId:m}=this.getAmountAndTokenIdFromKnownMessageTypes(u.messages),p=D.AuthInfo.decode(ue(i));let v="0";const f=p.fee;return f!=null&&(v=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...f.amount]).amount),{nativeAmount:h,networkFee:v,tokenId:m}}case"cosmos_signAmino":{const l=Ce(o),{signDoc:i}=l.params,c=(0,N.makeSignDoc)(i.msgs,i.fee,i.chain_id,i.memo,i.account_number,i.sequence),u=new y.AminoTypes(he(he({},y.createBankAminoConverters),y.createIbcAminoConverters)),h=c.msgs.map(k=>u.fromAmino(k)),{nativeAmount:m,tokenId:p}=this.getAmountAndTokenIdFromKnownMessageTypes(h);let v="0";const f=i.fee;return f!=null&&(v=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...f.amount]).amount),{nativeAmount:m,networkFee:v,tokenId:p}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(l){throw this.warn("Wallet connect call_request ",l),l}})}}tokenIdFromDenom(n){if(this.networkInfo.nativeDenom===n)return null;const t=Object.keys(this.allTokensMap).find(s=>{var r;return((r=this.allTokensMap[s].networkLocation)==null?void 0:r.contractAddress)===n});if(t===void 0)throw new Error(`Unrecognized denom: ${n}`);return t}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let s=null,r;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const l=this.tools.registry.decode(o),i=re.MsgTransfer.fromPartial(l);s===void 0&&(s=this.tokenIdFromDenom(i.token.denom));const c=(0,y.coin)(i.token.amount,i.token.denom);r==null?r=c:r=K([r,c]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const l=this.tools.registry.decode(o),i=se.$n.fromPartial(l),{funds:c}=i;if(c.length>0){const{denom:u}=c[0];s===void 0&&(s=this.tokenIdFromDenom(u));let h=(0,y.coin)("0",u);for(const m of c)h=K([h,m]);r==null?r=h:r=K([r,h])}break}default:}return{nativeAmount:(t=r==null?void 0:r.amount)!=null?t:"0",tokenId:s}}setOtherData(n){this.otherData=A(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return w(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),s=yield t.getAllBalances(this.walletInfo.keys.bech32Address),r=s.find(i=>i.denom===this.networkInfo.nativeDenom);if(this.updateBalance(this.currencyInfo.currencyCode,(n=r==null?void 0:r.amount)!=null?n:"0"),this.enabledTokenIds.forEach(i=>{var c;const u=this.allTokensMap[i],h=s.find(m=>{var p;return m.denom===((p=u.networkLocation)==null?void 0:p.contractAddress)});this.updateBalance(u.currencyCode,(c=h==null?void 0:h.amount)!=null?c:"0")}),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const c={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(c),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:o,sequence:l}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=o,this.sequence=l}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return w(this,null,function*(){try{const{stargateClient:n}=this.getClients(),t=yield n.getHeight();t>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(n){this.error("queryBlockheight Error ",n)}})}queryTransactions(){return w(this,null,function*(){let n=0;const t=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(r=>this.allTokensMap[r].currencyCode)],s=Date.now()-Fn>this.otherData.archivedTxLastCheckTime?yield Te(this.fetchCors,pe(this.networkInfo.archiveNode,this.tools.initOptions)):this.getClients();for(const r of Z){const o=yield this.queryTransactionsInner(r,s);o!=null&&this.otherData[r]!==o&&(this.otherData[r]=o,this.walletLocalDataDirty=!0),n+=.5,t.forEach(l=>this.tokenCheckTransactionsStatus[l]=n),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=Date.now(),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}queryTransactionsInner(n,t){return w(this,null,function*(){const s={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:50,order_by:"desc"};let r,o=0,l,i=0,c=!1;try{do{const u=yield t.cometClient.txSearch(He(he({},s),{page:++o})),{totalCount:h,txs:m}=u;l==null&&(l=h),i=i+m.length;for(const p of m){const v=(0,F.toHex)(p.hash).toUpperCase();if(this.removeFromUnconfirmedCache(v),r==null&&(r=v),v===this.otherData[n]){c=!0;break}const f=p.result.events.map(y.fromTendermintEvent);let k=[];try{k=sn(f,this.walletInfo.keys.bech32Address)}catch(ve){this.log.warn("reduceCoinEventsForAddress error:",String(ve))}if(k.length===0)continue;const E=yield t.stargateClient.getBlock(p.height),x=(0,C.toSeconds)((0,C.fromRfc3339WithNanoseconds)(E.header.time)).seconds,{height:B,tx:W}=p,j=I.YU.stringify(W),{authInfo:{fee:M},body:{memo:ge,messages:V}}=(0,_.decodeTxRaw)(W),Kn=yield this.totalDynamicNetworkFee(V,E.header.height);k.forEach(ve=>{this.processCosmosTransaction(v,x,j,ve,ge,B,Kn,M)})}}while(l>i&&!c)}catch(u){throw this.log.warn("queryTransactions error:",u),u}return r})}processCosmosTransaction(n,t,s,r,o,l,i,c){const{amount:u,denom:h}=r,m=this.networkInfo.nativeDenom===h;let p;try{p=this.tokenIdFromDenom(h)}catch{return}const v=p===null?this.currencyInfo.currencyCode:this.allTokensMap[p].currencyCode;let f="0";if(c!=null){const{amount:M}=c,ge=K([(0,y.coin)("0",this.networkInfo.nativeDenom),...M]);f=(0,b.add)(f,ge.amount)}const k=(0,b.lt)(u,"0"),E=[];let x=u,B;k?m?(f=(0,b.add)(f,i),x=(0,b.sub)(x,f)):(f="0",B=i!=="0"?i:void 0):(E.push(this.walletInfo.keys.bech32Address),f="0");const W=[];o!==""&&W.push({type:"text",value:o});const j={blockHeight:l,currencyCode:v,date:t,isSend:k,memos:W,nativeAmount:x,networkFee:f,ourReceiveAddresses:E,parentNetworkFee:B,signedTx:s,txid:n,walletId:this.walletId};this.addTransaction(v,j)}createUnsignedTxHex(n,t){const s=D.TxBody.fromPartial({messages:n,memo:t}),r=D.TxBody.encode(s).finish(),o=D.TxRaw.fromPartial({bodyBytes:r});return I.YU.stringify(D.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+_n);this.unconfirmedTransactionCache.txids.size===0&&(this.unconfirmedTransactionCache.cacheSequence=this.sequence),this.unconfirmedTransactionCache.txids.set(n,t)}removeFromUnconfirmedCache(n){this.unconfirmedTransactionCache.txids.has(n)&&(this.unconfirmedTransactionCache.cacheSequence=this.unconfirmedTransactionCache.cacheSequence+1,this.sequence=this.unconfirmedTransactionCache.cacheSequence,this.unconfirmedTransactionCache.txids.delete(n))}getSequence(){return this.unconfirmedTransactionCache.txids.size===0?this.sequence:[...this.unconfirmedTransactionCache.txids.values()].some(n=>n<new Date)?(this.unconfirmedTransactionCache.txids=new Map,this.sequence):this.unconfirmedTransactionCache.cacheSequence+this.unconfirmedTransactionCache.txids.size}totalDynamicNetworkFee(n,t){return w(this,null,function*(){let s="0";if(this.networkInfo.defaultTransactionFeeUrl==null)return s;const{url:r,headers:o}=pe(this.networkInfo.defaultTransactionFeeUrl,this.tools.initOptions),l=t==null?"":`?height=${t}`,c=yield(yield this.fetchCors(`${r}${l}`,{method:"GET",headers:o})).json(),u=ce(c);for(const h of n)switch(h.typeUrl){case"/types.MsgDeposit":s=(0,b.add)(s,u.native_outbound_fee_rune);break;case"/types.MsgSend":s=(0,b.add)(s,u.native_tx_fee_rune)}return s})}calculateFee(n){return w(this,null,function*(){const{messages:t,memo:s,networkFeeOption:r}=n;let o=(0,y.coin)("0",this.networkInfo.nativeDenom),l="0",i="0";if(this.networkInfo.defaultTransactionFeeUrl==null){const{queryClient:c}=this.getClients(),{gasInfo:u}=yield c.tx.simulate(t,s,(0,N.encodeSecp256k1Pubkey)(I.YU.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((u==null?void 0:u.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");l=(0,b.ceil)((0,b.mul)(u==null?void 0:u.gasUsed.toString(),"1.5"),0);const{low:h,average:m,high:p}=(0,Sn.getGasPriceStep)(this.tools.chainData);let v=m;switch(r){case"low":{v=h;break}case"high":{v=p;break}case"custom":throw new Error("Custom fee not supported")}const f=(0,b.ceil)((0,b.mul)(l,v.toString()),0);o=(0,y.coin)(f,this.networkInfo.nativeDenom),i=o.amount}else i=yield this.totalDynamicNetworkFee(t),i=(0,b.mul)(i,"1.01");return{gasFeeCoin:o,gasLimit:l,networkFee:i}})}startEngine(){return w(this,null,function*(){this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",qe).catch(()=>{}),this.addToLoop("queryBlockheight",qe).catch(()=>{}),this.addToLoop("queryTransactions",Mn).catch(()=>{}),yield Ve(me.prototype,this,"startEngine").call(this)})}killEngine(){return w(this,null,function*(){yield this.tools.disconnectClient(),yield Ve(me.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return w(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}makeSpend(n){return w(this,null,function*(){var t,s;n=(0,On.s)(n,this.currencyInfo);const{edgeSpendInfo:r,currencyCode:o}=this.makeSpendCheck(n),{memos:l=[],networkFeeOption:i,tokenId:c}=r,u=(t=l[0])==null?void 0:t.value;if(r.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:h,publicAddress:m}=r.spendTargets[0];if(h==null)throw new In.$D;if(m==null)throw new Error("makeSpend Missing publicAddress");const p=c!=null?(s=this.allTokensMap[c].networkLocation)==null?void 0:s.contractAddress:this.networkInfo.nativeDenom;if(p==null)throw new Error("Unknown denom");const v=this.tools.methods.transfer({amount:[(0,y.coin)(h,p)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:m});let f,k,E;const x=`${m}${String(i)}`,B=this.feeCache.get(x);if(h==="0")f=(0,y.coin)("0",this.networkInfo.nativeDenom),k="0",E="0";else if(B==null){const V=yield this.calculateFee({messages:[v],memo:u,networkFeeOption:i});f=V.gasFeeCoin,k=V.gasLimit,E=V.networkFee,this.feeCache.set(x,V)}else f=B.gasFeeCoin,k=B.gasLimit,E=B.networkFee;const W=this.createUnsignedTxHex([v],u),j={gasFeeCoin:f,gasLimit:k,unsignedTxHex:W},M=this.makeEdgeTransactionAmounts(h,E,c);return this.checkBalances(M,c),{blockHeight:0,currencyCode:o,date:0,isSend:!0,memos:l,nativeAmount:M.nativeAmount,networkFee:M.networkFee,otherParams:j,ourReceiveAddresses:[],parentNetworkFee:M.parentNetworkFee,signedTx:"",txid:"",walletId:this.walletId}})}signMessage(n,t,s){return w(this,null,function*(){const r=z(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(r.mnemonic);if((s==null?void 0:s.otherParams)!=null)switch(s.otherParams.method){case"cosmos_getAccounts":{Q(s.otherParams);const f=(yield o.getAccounts()).map(k=>He(he({},k),{pubkey:I.US.stringify(k.pubkey)}));return JSON.stringify(f)}case"cosmos_signDirect":{const v=J(s.otherParams),{signDoc:f}=v.params,k=D.SignDoc.fromPartial({accountNumber:(0,Ke.longify)(f.accountNumber),authInfoBytes:ue(f.authInfoBytes),bodyBytes:ue(f.bodyBytes),chainId:f.chainId}),x={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,k)).signature,signed:v.params.signDoc};return JSON.stringify(x)}case"cosmos_signAmino":{const v=Ce(s.otherParams),{signDoc:f}=v.params,k=(0,N.makeSignDoc)(f.msgs,f.fee,f.chain_id,f.memo,f.account_number,f.sequence),B={signature:(yield(yield N.Secp256k1HdWallet.fromMnemonic(o.mnemonic)).signAmino(this.walletInfo.keys.bech32Address,k)).signature,signed:f};return JSON.stringify(B)}default:throw new Error(`Invalid method: ${s.method}`)}const l=I.YU.parse(n),i=D.SignDoc.decode(l),c=yield o.signDirect(this.walletInfo.keys.bech32Address,i),u=(0,N.decodeSignature)(c.signature),h=D.TxRaw.fromPartial({authInfoBytes:i.authInfoBytes,bodyBytes:i.bodyBytes,signatures:[u.signature]}),m=D.TxRaw.encode(h).finish();return I.YU.stringify(m)})}signTx(n,t){return w(this,null,function*(){const{gasFeeCoin:s,gasLimit:r,unsignedTxHex:o}=ae(n.otherParams),l=z(this.currencyInfo.pluginId)(t),i=I.YU.parse(o),{bodyBytes:c}=D.TxRaw.decode(i),u=I.YU.parse(this.walletInfo.keys.publicKey),h=(0,N.encodeSecp256k1Pubkey)(u),m=(0,_.makeAuthInfoBytes)([{pubkey:(0,_.encodePubkey)(h),sequence:this.getSequence()}],[s],parseInt(r),void 0,void 0,1),p=D.SignDoc.fromPartial({accountNumber:(0,Ke.longify)(this.accountNumber),authInfoBytes:m,bodyBytes:c,chainId:this.tools.chainData.chain_id}),f=yield(yield this.tools.createSigner(l.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,p),k=(0,N.decodeSignature)(f.signature),E=D.TxRaw.fromPartial({authInfoBytes:m,bodyBytes:c,signatures:[k.signature]}),x=D.TxRaw.encode(E).finish(),B=I.YU.stringify(x);return n.signedTx=B,n})}broadcastTx(n){return w(this,null,function*(){try{const t=I.YU.parse(n.signedTx),{stargateClient:s}=this.getClients(),r=yield s.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
+ ${(0,oe.oX)(n)}`),n.txid=r,n.date=Date.now()/1e3,this.addToUnconfirmedCache(r),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return w(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function Wn(e,n,t,s){return w(this,null,function*(){const r=L(t),o=new me(e,n,r,s);return yield o.loadEngine(),o})}var Ln=g(48764).Buffer,U=(e,n,t)=>new Promise((s,r)=>{var o=c=>{try{i(t.next(c))}catch(u){r(u)}},l=c=>{try{i(t.throw(c))}catch(u){r(u)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(o,l);i((t=t.apply(e,n)).next())});class Ye{constructor(n){const{builtinTokens:t,currencyInfo:s,initOptions:r,io:o,networkInfo:l}=n;this.io=o,this.currencyInfo=s,this.builtinTokens=t,this.networkInfo=l,this.initOptions=r,this.clientCount=0;const{methods:i,registry:c}=bn(s.pluginId);this.methods=i,this.registry=c;const{data:u,name:h,url:m}=this.networkInfo.chainInfo;this.chainData=u;const p=new q.ChainRegistryFetcher;p.fetch(m).then(()=>{this.chainData=p.getChain(h)}).catch(v=>{})}createSigner(n){return U(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:s}=this.networkInfo,r=(0,ke.stringToPath)(s);return yield _.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[r],prefix:t})})}getDisplayPrivateKey(n){return U(this,null,function*(){const{pluginId:t}=this.currencyInfo;return z(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return U(this,null,function*(){const{keys:t}=L(n);return t.publicKey})}importPrivateKey(n){return U(this,null,function*(){if(!(0,ne.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return U(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=Ln.from(this.io.random(32)),s=(0,ne.entropyToMnemonic)(t);return yield this.importPrivateKey(s)})}derivePublicKey(n){return U(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=z(this.currencyInfo.pluginId)(n.keys),r=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:l}=r[0],i=I.YU.stringify(l);return{bech32Address:o,publicKey:i}})}isValidAddress(n){try{if((0,F.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}parseUri(n,t,s){return U(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{parsedUri:l,edgeParsedUri:i}=(0,te.k)(this.currencyInfo,n,o,t!=null?t:this.currencyInfo.currencyCode,s);let c="";if(i.publicAddress!=null&&(c=i.publicAddress),!this.isValidAddress(c))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=l.query.memo,i})}encodeUri(n){return U(this,arguments,function*(t,s=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:o,currencyCode:l,publicAddress:i}=t;if(!this.isValidAddress(i))throw new Error("InvalidPublicAddressError");let c;if(typeof o=="string"){const h=(0,oe.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,s);if(h==null)throw new Error("InternalErrorInvalidCurrencyCode");c=(0,b.div)(o,h.multiplier,18)}return(0,te.Q)(t,r,c)})}connectClient(){return U(this,null,function*(){this.clients==null&&(this.clients=yield Te(this.io.fetchCors,pe(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return U(this,null,function*(){var n,t;--this.clientCount,this.clientCount===0&&(yield(t=(n=this.clients)==null?void 0:n.stargateClient)==null?void 0:t.disconnect(),this.clients=void 0)})}getTokenId(n){return U(this,null,function*(){(0,Y.Rp)(n);const t=(0,Y.Oj)(n.networkLocation);if(t==null)throw new Error("ErrorInvalidContractAddress");return t.contractAddress.toLowerCase().replace(/^ibc[/]/,"ibc")})}}function Jn(e){return U(this,null,function*(){return new Ye(e)})}},89214:function(){},20131:function(){},16026:function(){},52361:function(){},94616:function(){}}]);