edge-currency-accountbased 4.45.0 → 4.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.46.0 (2025-05-08)
6
+
7
+ - added: (Thorchain) Add TCY token
8
+ - added: Add Thorchain Stagenet
9
+ - changed: (Fantom) Update explorer links
10
+ - fixed: (EVM) Handle 'No internal transactions found' message from Blockscout servers
11
+ - removed: (Fantom) Removed ftmscan from network adaptor config
12
+
13
+ ## 4.45.1 (2025-04-29)
14
+
15
+ - fixed: (TRX) Energy estimations based on contract storage state
16
+
5
17
  ## 4.45.0 (2025-04-28)
6
18
 
7
19
  - added: Add Zano
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[7854],{62351:function(tn,te,p){"use strict";p.d(te,{Nn:function(){return R},Nt:function(){return ee},fi:function(){return re},zp:function(){return oe}});var fe=p(14171),j=p(44276),P=(x,I,S)=>new Promise((N,L)=>{var M=D=>{try{v(S.next(D))}catch(u){L(u)}},W=D=>{try{v(S.throw(D))}catch(u){L(u)}},v=D=>D.done?N(D.value):Promise.resolve(D.value).then(M,W);v((S=S.apply(x,I)).next())});const V=["https://info1.edge.app","https://info2.edge.app"];function C(x,I,S){return P(this,arguments,function*(N,L,M,W=5e3,v=fetch){const D=N.map(u=>()=>P(this,null,function*(){const A=yield v(u+"/"+L,M);if(typeof A!="object"){const se=`Invalid return value ${L} in ${u}`;throw console.log(se),new Error(se)}return A}));return yield(0,fe.NN)(D,W)})}function oe(x,I,S,N,L=5e3,M){return P(this,null,function*(){const W=yield C((0,j.R3)(I),S,N,L,M);if(!W.ok){const u=yield W.text();throw console.error(u),new Error(`Error fetching ${S}: ${u}`)}const v=yield W.json();return x(v)})}function Q(x,I,S,N=5e3,L){return P(this,null,function*(){return yield C((0,j.R3)(x),I,S,N,L)})}const R=(x,I,S,N)=>P(void 0,null,function*(){return yield Q(V,x,I,S,N)}),ee=x=>Object.keys(x).map(I=>{const S=x[I];return S==null?I:`${I}=${encodeURIComponent(S)}`}).join("&"),re=(x,I=5e3)=>x+Math.random()*I*2-I},34931:function(tn,te,p){"use strict";p.r(te),p.d(te,{CosmosTools:function(){return je},makeCurrencyEngine:function(){return rt},makeCurrencyTools:function(){return lt},updateInfoPayload:function(){return ut}});var fe=p(26469),j=p(76005),P=p(44917),V=p(5450),C=p(66001),oe=p(90749),Q=p(50949),R=p(65828),ee=p(14483),re=p(96542),x=p(44276),I=p(44941),S=p(2666),N=p(86181),L=p(59717),M=p(78824),W=p(15960),v=p(84007),D=p(67112),u=p(42704),A=p(84397),se=p(48287).Buffer,me=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const ie=(e,n)=>{const t=(0,A.tx)(n),r={},s=/{{(.*?)}}/g;for(const[o,c]of Object.entries(e.headers)){const a=s.exec(c);a!=null&&(r[o]=t[a[1]])}return{url:e.url,headers:r}},on=(e,n)=>{const{url:t,headers:r}=n;return{execute:s=>me(void 0,null,function*(){var o;const c={method:"POST",headers:r,body:JSON.stringify(s)},i=yield(yield e(t,c)).json();if((0,W.isJsonRpcErrorResponse)(i))throw new Error(String((o=i.error.data)!=null?o:i.error.message));return i}),disconnect:()=>{}}},rn=e=>me(void 0,null,function*(){const n=yield D.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield D.Tendermint37Client.create(e):yield D.Tendermint34Client.create(e)}),ke=(e,n)=>me(void 0,null,function*(){const t=yield v.StargateClient.create(yield rn(on(e,n))),r=t.forceGetCometClient();return{queryClient:v.QueryClient.withExtensions(r,v.setupAuthExtension,v.setupBankExtension,v.setupStakingExtension,v.setupTxExtension,v.setupIbcExtension),stargateClient:t,cometClient:r}}),sn=e=>{var n;const[t,...r]=e.split("."),s=e.includes("/"),o=r.join("."),c=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:c,synth:s}},G=e=>e.reduce((n,t)=>{try{return(0,M.addCoins)(n,t)}catch{}return n}),we=(0,u.E8)("amount"),an=(0,u.E8)("receiver"),cn=(0,u.E8)("spender"),ln=(0,u.E8)("amount","receiver","spender"),un=(0,u.eB)({type:(0,u.E8)("coin_received"),attributes:(0,u.VA)((0,u.eB)({key:we,value:u.oJ}),(0,u.eB)({key:an,value:u.oJ}))}),dn=(0,u.eB)({type:(0,u.E8)("coin_spent"),attributes:(0,u.VA)((0,u.eB)({key:we,value:u.oJ}),(0,u.eB)({key:cn,value:u.oJ}))}),Te=(e,n)=>{const t=new Map;for(const s of e){const o={type:s.type,attributes:s.attributes.filter(i=>(0,u.HS)(ln)(i.key)!=null).sort((i,l)=>i.key<l.key?-1:1)},c=(0,u.HS)(un)(o);if(c!=null){const[i,l]=c.attributes.map(d=>d.value);if(l!==n)continue;be(i).forEach(d=>{var y;const g=d.amount,m=(y=t.get(d.denom))!=null?y:"0";t.set(d.denom,(0,C.add)(g,m))});continue}const a=(0,u.HS)(dn)(o);if(a!=null){const[i,l]=a.attributes.map(d=>d.value);if(l!==n)continue;be(i).forEach(d=>{var y;const g=`-${d.amount}`,m=(y=t.get(d.denom))!=null?y:"0";t.set(d.denom,(0,C.add)(g,m))})}}const r=[];return t.forEach((s,o)=>{s!=="0"&&r.push({denom:o,amount:s})}),r},ae=e=>{try{return R.xn.parse(e)}catch{return R.K3.parse(e)}},be=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const r=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(r==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=r[1].replace(/^0+/,""))!=null?t:"0",denom:r[2]}}),hn=(e,n)=>{const t=Q.Bt.find(c=>c.bech32_prefix===(0,P.fromBech32)(n).prefix);if(t==null)throw new Error("Unrecognized denom");const r=t.chain_name,s=(0,L.Dn)(Q.tX,e,r);if(s==null)throw new Error(`No IBC channels between ${e} and ${r}`);const o=(0,L.hP)(s);return e<r?{channel:o.chain_1.channel_id,port:o.chain_1.port_id}:{channel:o.chain_2.channel_id,port:o.chain_2.port_id}};function fn(e){if(!(()=>(e==null?void 0:e.msgs)!=null&&Array.isArray(e.msgs)&&e.msgs.length===1?e.msgs[0].type==="sign/MsgSignData":!1)())return!1;if(e.chain_id!=="")throw new Error("Chain id should be empty string for ADR-36 signing");if(e.memo!=="")throw new Error("Memo should be empty string for ADR-36 signing");if(e.account_number!=="0")throw new Error('Account number should be "0" for ADR-36 signing');if(e.sequence!=="0")throw new Error('Sequence should be "0" for ADR-36 signing');if(e.fee.gas!=="0")throw new Error('Gas should be "0" for ADR-36 signing');if(e.fee.amount.length!==0)throw new Error("Fee amount should be empty array for ADR-36 signing");const t=e.msgs[0];if(t.type!=="sign/MsgSignData")throw new Error(`Invalid type of ADR-36 sign msg: ${t.type}`);if(t.value==null)throw new Error("Empty value in the msg");const r=t.value.signer;if(r==null)throw new Error("Empty signer in the ADR-36 msg");(0,P.fromBech32)(r);const s=t.value.data;if(s==null)throw new Error("Empty data in the ADR-36 msg");const o=se.from(s,"base64");if(o.toString("base64")!==s)throw new Error("Data is not encoded by base64");if(o.length===0)throw new Error("Empty data in the ADR-36 msg");return!0}var mn=p(28570),F=p.n(mn),gn=p(26946),f=p.n(gn);const ht="common";function Ce(){return{chain:"",symbol:"",ticker:"",synth:!1}}const Z={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ce();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.chain=t.string();continue;case 2:if(o!==18)break;s.symbol=t.string();continue;case 3:if(o!==26)break;s.ticker=t.string();continue;case 4:if(o!==32)break;s.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{chain:O(e.chain)?globalThis.String(e.chain):"",symbol:O(e.symbol)?globalThis.String(e.symbol):"",ticker:O(e.ticker)?globalThis.String(e.ticker):"",synth:O(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 Z.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s;const o=Ce();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(r=e.ticker)!=null?r:"",o.synth=(s=e.synth)!=null?s:!1,o}};function Ae(){return{asset:void 0,amount:"",decimals:F().ZERO}}const T={encode(e,n=f().Writer.create()){return e.asset!==void 0&&Z.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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ae();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.asset=Z.decode(t,t.uint32());continue;case 2:if(o!==18)break;s.amount=t.string();continue;case 3:if(o!==24)break;s.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{asset:O(e.asset)?Z.fromJSON(e.asset):void 0,amount:O(e.amount)?globalThis.String(e.amount):"",decimals:O(e.decimals)?F().fromValue(e.decimals):F().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=Z.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||F().ZERO).toString()),n},create(e){return T.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ae();return t.asset=e.asset!==void 0&&e.asset!==null?Z.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?F().fromValue(e.decimals):F().ZERO,t}};function Ie(){return{secp256k1:"",ed25519:""}}const yn={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ie();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.secp256k1=t.string();continue;case 2:if(o!==18)break;s.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{secp256k1:O(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:O(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 yn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Ie();return r.secp256k1=(n=e.secp256k1)!=null?n:"",r.ed25519=(t=e.ed25519)!=null?t:"",r}};function Se(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const pn={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Se();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=t.string();continue;case 2:if(o!==18)break;s.chain=t.string();continue;case 3:if(o!==26)break;s.fromAddress=t.string();continue;case 4:if(o!==34)break;s.toAddress=t.string();continue;case 5:if(o!==42)break;s.coins.push(T.decode(t,t.uint32()));continue;case 6:if(o!==50)break;s.gas.push(T.decode(t,t.uint32()));continue;case 7:if(o!==58)break;s.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{id:O(e.id)?globalThis.String(e.id):"",chain:O(e.chain)?globalThis.String(e.chain):"",fromAddress:O(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:O(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:O(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const r={};return e.id!==""&&(r.id=e.id),e.chain!==""&&(r.chain=e.chain),e.fromAddress!==""&&(r.fromAddress=e.fromAddress),e.toAddress!==""&&(r.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(r.coins=e.coins.map(s=>T.toJSON(s))),(t=e.gas)!=null&&t.length&&(r.gas=e.gas.map(s=>T.toJSON(s))),e.memo!==""&&(r.memo=e.memo),r},create(e){return pn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s,o,c,a;const i=Se();return i.id=(n=e.id)!=null?n:"",i.chain=(t=e.chain)!=null?t:"",i.fromAddress=(r=e.fromAddress)!=null?r:"",i.toAddress=(s=e.toAddress)!=null?s:"",i.coins=((o=e.coins)==null?void 0:o.map(l=>T.fromPartial(l)))||[],i.gas=((c=e.gas)==null?void 0:c.map(l=>T.fromPartial(l)))||[],i.memo=(a=e.memo)!=null?a:"",i}};function xe(){return{coins:[],poolDeduct:""}}const vn={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=xe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],poolDeduct:O(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>T.toJSON(r))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return vn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=xe();return r.coins=((n=e.coins)==null?void 0:n.map(s=>T.fromPartial(s)))||[],r.poolDeduct=(t=e.poolDeduct)!=null?t:"",r}};function Ee(){return{value:""}}const kn={encode(e,n=f().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ee();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{value:O(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ee();return t.value=(n=e.value)!=null?n:"",t}};f().util.Long!==F()&&(f().util.Long=F(),f().configure());function O(e){return e!=null}const ft="types";function Pe(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const ce={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Pe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.memo=t.string();continue;case 3:if(o!==26)break;s.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],memo:De(e.memo)?globalThis.String(e.memo):"",signer:De(e.signer)?wn(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>T.toJSON(r))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=Tn(e.signer)),t},create(e){return ce.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Pe();return s.coins=((n=e.coins)==null?void 0:n.map(o=>T.fromPartial(o)))||[],s.memo=(t=e.memo)!=null?t:"",s.signer=(r=e.signer)!=null?r:new Uint8Array(0),s}};function wn(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function Tn(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(""))}}f().util.Long!==F()&&(f().util.Long=F(),f().configure());function De(e){return e!=null}const mt="cosmos.base.v1beta1";function Oe(){return{denom:"",amount:""}}const X={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Oe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:Y(e.denom)?globalThis.String(e.denom):"",amount:Y(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 X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Oe();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Be(){return{denom:"",amount:""}}const bn={encode(e,n=f().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 f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Be();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:Y(e.denom)?globalThis.String(e.denom):"",amount:Y(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 bn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Be();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Re(){return{int:""}}const Cn={encode(e,n=f().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Re();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{int:Y(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return Cn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Re();return t.int=(n=e.int)!=null?n:"",t}};function Ne(){return{dec:""}}const An={encode(e,n=f().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ne();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{dec:Y(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return An.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ne();return t.dec=(n=e.dec)!=null?n:"",t}};f().util.Long!==F()&&(f().util.Long=F(),f().configure());function Y(e){return e!=null}const gt="types";function Me(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const le={encode(e,n=f().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)X.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof f().Reader?e:f().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Me();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.fromAddress=t.bytes();continue;case 2:if(o!==18)break;s.toAddress=t.bytes();continue;case 3:if(o!==26)break;s.amount.push(X.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{fromAddress:Le(e.fromAddress)?Fe(e.fromAddress):new Uint8Array(0),toAddress:Le(e.toAddress)?Fe(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>X.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=Ue(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=Ue(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(r=>X.toJSON(r))),t},create(e){return le.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Me();return s.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),s.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),s.amount=((r=e.amount)==null?void 0:r.map(o=>X.fromPartial(o)))||[],s}};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 r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function Ue(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(""))}}f().util.Long!==F()&&(f().util.Long=F(),f().configure());function Le(e){return e!=null}var In=Object.defineProperty,Sn=Object.defineProperties,xn=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,En=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable,_e=(e,n,t)=>n in e?In(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Dn=(e,n)=>{for(var t in n||(n={}))En.call(n,t)&&_e(e,t,n[t]);if(Je)for(var t of Je(n))Pn.call(n,t)&&_e(e,t,n[t]);return e},On=(e,n)=>Sn(e,xn(n));const Bn=1e3*60*60*24,Rn=e=>{const n=new V.Registry([["/ibc.applications.transfer.v1.MsgTransfer",N.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",S.zM]]);let t=s=>{const{amount:o,fromAddress:c,toAddress:a}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:I.MsgSend.encode(I.MsgSend.fromPartial({fromAddress:c,toAddress:a,amount:o})).finish()}};const r=s=>{const{memo:o,toAddress:c,fromAddress:a,channel:i,port:l,amount:h}=s;return{typeUrl:"/ibc.applications.transfer.v1.MsgTransfer",value:N.MsgTransfer.encode(N.MsgTransfer.fromPartial({memo:o,receiver:c,sender:a,sourceChannel:i,sourcePort:l,token:h,timeoutTimestamp:BigInt((Date.now()+Bn)*1e6)})).finish()}};switch(e){case"thorchainrune":{const s="/types.MsgDeposit";n.register(s,ce);const o=a=>{const{assets:i,memo:l,signer:h}=a,d=i.map(g=>On(Dn({},g),{asset:sn(g.asset)}));return{typeUrl:s,value:ce.encode(ce.fromPartial({coins:d,memo:l,signer:(0,P.fromBech32)(h).data})).finish()}},c="/types.MsgSend";return n.register(c,le),t=a=>{const{amount:i,fromAddress:l,toAddress:h}=a;return{typeUrl:c,value:le.encode(le.fromPartial({fromAddress:(0,P.fromBech32)(l).data,toAddress:(0,P.fromBech32)(h).data,amount:i})).finish()}},{methods:{deposit:o,ibcTransfer:r,transfer:t},registry:n}}}return{methods:{ibcTransfer:r,transfer:t},registry:n}};var He=p(1267),U=p(6975),Nn=p(82671),Mn=p(26277),ge=p(62351),Fn=Object.defineProperty,Un=Object.defineProperties,Ln=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,Jn=Object.getPrototypeOf,_n=Object.prototype.hasOwnProperty,Hn=Object.prototype.propertyIsEnumerable,$n=Reflect.get,We=(e,n,t)=>n in e?Fn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,ue=(e,n)=>{for(var t in n||(n={}))_n.call(n,t)&&We(e,t,n[t]);if($e)for(var t of $e(n))Hn.call(n,t)&&We(e,t,n[t]);return e},Ke=(e,n)=>Un(e,Ln(n)),Ve=(e,n,t)=>$n(Jn(e),t,n),E=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const qe=(0,ge.fi)(2e4),Wn=(0,ge.fi)(2e4),Kn=1e3*60*60*24*14,Vn=1e3*60*2,ye=50;class ne extends Mn.k{constructor(n,t,r,s){super(n,t,r,s),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.chainId=this.networkInfo.defaultChainId,this.otherMethods={getMaxTx:o=>E(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:c,memo:a}=o;if(c.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const i=this.tools.methods.deposit({assets:c,memo:a,signer:this.walletInfo.keys.bech32Address}),{networkFee:l}=yield this.calculateFee({messages:[i],memo:a}),h=this.getBalance({tokenId:null});return(0,C.sub)(h,l)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>E(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:c,memo:a,metadata:i}=o,l=this.tools.methods.deposit({assets:c,memo:a,signer:this.walletInfo.keys.bech32Address}),h=this.createUnsignedTxHex([l],a),{gasFeeCoin:d,gasLimit:y,networkFee:g}=yield this.calculateFee({messages:[l],memo:a}),m={gasFeeCoin:d,gasLimit:y,unsignedTxHex:h};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:i,nativeAmount:`-${g}`,networkFee:g,networkFees:[],otherParams:m,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>E(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 c=(0,A.S4)(o),{authInfoBytes:a,bodyBytes:i}=c.params.signDoc,l=U.TxBody.decode(ae(i)),{nativeAmount:h,tokenId:d}=this.getAmountAndTokenIdFromKnownMessageTypes(l.messages),y=U.AuthInfo.decode(ae(a));let g="0";const m=y.fee;return m!=null&&(g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:h,networkFee:g,tokenId:d}}case"cosmos_signAmino":{const c=(0,A.tV)(o),{signDoc:a}=c.params,i=(0,M.makeSignDoc)(a.msgs,a.fee,a.chain_id,a.memo,a.account_number,a.sequence),l=new v.AminoTypes(ue(ue({},v.createBankAminoConverters),v.createIbcAminoConverters)),h=i.msgs.filter(k=>k.type!=="sign/MsgSignData").map(k=>l.fromAmino(k)),{nativeAmount:d,tokenId:y}=this.getAmountAndTokenIdFromKnownMessageTypes(h);let g="0";const m=a.fee;return m!=null&&(g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),...m.amount]).amount),{nativeAmount:d,networkFee:g,tokenId:y}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(c){throw this.warn("Wallet connect call_request ",c),c}})}}tokenIdFromDenom(n){if(this.networkInfo.nativeDenom===n)return null;const t=Object.keys(this.allTokensMap).find(r=>{var s;return((s=this.allTokensMap[r].networkLocation)==null?void 0:s.contractAddress)===n});if(t===void 0)throw new Error(`Unrecognized denom: ${n}`);return t}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let r=null,s;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const c=this.tools.registry.decode(o),a=N.MsgTransfer.fromPartial(c);r===void 0&&(r=this.tokenIdFromDenom(a.token.denom));const i=(0,v.coin)(a.token.amount,a.token.denom);s==null?s=i:s=G([s,i]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const c=this.tools.registry.decode(o),a=S.zM.fromPartial(c),{funds:i}=a;if(i.length>0){const{denom:l}=i[0];r===void 0&&(r=this.tokenIdFromDenom(l));let h=(0,v.coin)("0",l);for(const d of i)h=G([h,d]);s==null?s=h:s=G([s,h])}break}default:}return{nativeAmount:(t=s==null?void 0:s.amount)!=null?t:"0",tokenId:r}}setOtherData(n){this.otherData=(0,A.qd)(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return E(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),r=yield t.getAllBalances(this.walletInfo.keys.bech32Address),s=r.find(i=>i.denom===this.networkInfo.nativeDenom);this.updateBalance(this.currencyInfo.currencyCode,(n=s==null?void 0:s.amount)!=null?n:"0");const o=[];if(Object.keys(this.allTokensMap).forEach(i=>{var l;const h=this.allTokensMap[i],d=r.find(g=>{var m;return g.denom===((m=h.networkLocation)==null?void 0:m.contractAddress)}),y=(l=d==null?void 0:d.amount)!=null?l:"0";this.updateBalance(h.currencyCode,y),(0,C.gt)(y,"0")&&!this.enabledTokenIds.includes(i)&&o.push(i)}),o.length>0&&this.currencyEngineCallbacks.onNewTokens(o),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const l={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(l),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:c,sequence:a}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=c,this.sequence=a}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return E(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 E(this,null,function*(){var n;let t=0;const r=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(o=>this.allTokensMap[o].currencyCode)],s=[];if(this.networkInfo.archiveNodes!=null&&Date.now()-Kn>this.otherData.archivedTxLastCheckTime){const o=this.networkInfo.archiveNodes.sort((c,a)=>c.blockTimeRangeSeconds.start-a.blockTimeRangeSeconds.start);for(const c of o)if(c.blockTimeRangeSeconds.end==null||c.blockTimeRangeSeconds.end>this.otherData.archivedTxLastCheckTime){const a=yield ke(this.fetchCors,ie(c.endpoint,this.tools.initOptions));s.push(a)}}s.push(this.getClients());for(const o of s){let c=0;for(const a of A.b8){const{newestTxid:i,lastTimestamp:l}=yield this.queryTransactionsInner(a,o);i!=null&&((n=this.otherData[a])==null?void 0:n.newestTxid)!==i&&(this.otherData[a]={newestTxid:i},this.walletLocalDataDirty=!0,c=Math.max(c,l)),t+=.5/s.length,r.forEach(h=>this.tokenCheckTransactionsStatus[h]=t),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=c,this.walletLocalDataDirty=!0}this.otherData.archivedTxLastCheckTime=Date.now(),this.walletLocalDataDirty=!0,this.updateTransactionEvents()})}queryTransactionsInner(n,t){return E(this,null,function*(){const r={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:ye,order_by:"asc"};let s,o=0,c=1;do{try{const{totalCount:a,txs:i}=yield t.cometClient.txSearch(Ke(ue({},r),{page:c})),l=i.findIndex(h=>{var d;return(0,P.toHex)(h.hash).toUpperCase()===((d=this.otherData[n])==null?void 0:d.newestTxid)});for(let h=l+1;h<i.length;h++){const d=i[h];if(d==null)break;const y=(0,P.toHex)(d.hash).toUpperCase(),g=d.result.events.map(v.fromTendermintEvent);let m=[];try{m=Te(g,this.walletInfo.keys.bech32Address)}catch(q){this.log.warn("reduceCoinEventsForAddress error:",String(q))}if(m.length===0)continue;const k=yield t.stargateClient.getBlock(d.height),b=(0,D.toSeconds)((0,D.fromRfc3339WithNanoseconds)(k.header.time)).seconds,{height:w,tx:B}=d,K=R.xn.stringify(B),{authInfo:{fee:_},body:{memo:H}}=(0,V.decodeTxRaw)(B);m.forEach(q=>{this.processCosmosTransaction(y,b,K,q,H,w,_)}),s=y,this.otherData[n]={newestTxid:y},o=b*1e3,this.walletLocalDataDirty=!0}if(i.length<ye||a===c*ye)break}catch(a){if(String(a).includes("page should be within"))continue;throw this.log.warn("queryTransactions error:",a),a}c++,this.otherData[n]={newestTxid:s},this.walletLocalDataDirty=!0}while(!0);return{newestTxid:s,lastTimestamp:o}})}processCosmosTransaction(n,t,r,s,o,c,a){const{amount:i,denom:l}=s,h=this.networkInfo.nativeDenom===l;let d;try{d=this.tokenIdFromDenom(l)}catch{return}const{currencyCode:y}=d==null?this.currencyInfo:this.allTokensMap[d];let g="0";if(a!=null){const{amount:_}=a;g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),..._]).amount}const m=(0,C.lt)(i,"0"),k=[];let b=i,w;m?h?b=(0,C.sub)(b,g):(w=g!=="0"?g:void 0,g="0"):(k.push(this.walletInfo.keys.bech32Address),g="0");const B=[];o!==""&&B.push({type:"text",value:o});const K={blockHeight:c,currencyCode:y,date:t,isSend:m,memos:B,nativeAmount:b,networkFee:g,networkFees:[],ourReceiveAddresses:k,parentNetworkFee:w,signedTx:r,tokenId:d,txid:n,walletId:this.walletId};this.addTransaction(y,K)}addTransaction(n,t){this.removeFromUnconfirmedCache(t.txid),super.addTransaction(n,t)}createUnsignedTxHex(n,t){const r=U.TxBody.fromPartial({messages:n,memo:t}),s=U.TxBody.encode(r).finish(),o=U.TxRaw.fromPartial({bodyBytes:s});return R.xn.stringify(U.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+Vn);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}calculateFee(n){return E(this,null,function*(){const{queryClient:t}=this.getClients(),{gasInfo:r}=yield t.tx.simulate(n.messages,n.memo,(0,M.encodeSecp256k1Pubkey)(R.xn.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((r==null?void 0:r.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");const s=(0,C.ceil)((0,C.mul)(r==null?void 0:r.gasUsed.toString(),"1.5"),0),{low:o,average:c,high:a}=(0,L.UP)(this.tools.chainData);let i=c;switch(n.networkFeeOption){case"low":{i=o;break}case"high":{i=a;break}case"custom":throw new Error("Custom fee not supported")}const l=(0,C.ceil)((0,C.mul)(s,i.toString()),0),h=(0,v.coin)(l,this.networkInfo.nativeDenom);return{gasFeeCoin:h,gasLimit:s,networkFee:h.amount}})}startEngine(){return E(this,null,function*(){yield this.tools.connectClient(),this.addToLoop("queryBalance",qe),this.addToLoop("queryBlockheight",qe),this.addToLoop("queryTransactions",Wn),yield Ve(ne.prototype,this,"startEngine").call(this)})}killEngine(){return E(this,null,function*(){yield this.tools.disconnectClient(),yield Ve(ne.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return E(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}validateTransfer(n,t,r){return E(this,null,function*(){var s;if(t==null)return;const o=this.allTokensMap[t],c=(0,ee.oQ)(o.networkLocation),a=c==null?void 0:c.contractAddress;if(a==null)throw new Error("Unknown denom");const{queryClient:i}=this.getClients();try{yield i.bank.denomMetadata(a);return}catch{const d=(s=(yield i.ibc.transfer.denomTrace(a)).denomTrace)==null?void 0:s.path.match(/transfer\/channel-\d+/);if(d==null||`${r.port}/${r.channel}`===d[0])return}throw new Error("Invalid transfer")})}makeSpend(n){return E(this,null,function*(){var t,r;const{edgeSpendInfo:s,currencyCode:o}=this.makeSpendCheck(n),{memos:c=[],networkFeeOption:a,tokenId:i}=s,l=(t=c[0])==null?void 0:t.value;if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:h,publicAddress:d}=s.spendTargets[0];if(h==null)throw new Nn.ef;if(d==null)throw new Error("makeSpend Missing publicAddress");const y=i!=null?(r=this.allTokensMap[i].networkLocation)==null?void 0:r.contractAddress:this.networkInfo.nativeDenom;if(y==null)throw new Error("Unknown denom");let g;if(this.networkInfo.bech32AddressPrefix!==(0,P.fromBech32)(d).prefix){const $=hn(this.tools.chainData.chain_name,d);yield this.validateTransfer(d,i,$);const{channel:ve,port:z}=$;g=this.tools.methods.ibcTransfer({channel:ve,port:z,memo:l,amount:(0,v.coin)(h,y),fromAddress:this.walletInfo.keys.bech32Address,toAddress:d})}else g=this.tools.methods.transfer({amount:[(0,v.coin)(h,y)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:d});let m,k,b;const w=`${d}${String(a)}`,B=this.feeCache.get(w);if(h==="0")m=(0,v.coin)("0",this.networkInfo.nativeDenom),k="0",b="0";else if(B==null){const $=yield this.calculateFee({messages:[g],memo:l,networkFeeOption:a});m=$.gasFeeCoin,k=$.gasLimit,b=$.networkFee,this.feeCache.set(w,$)}else m=B.gasFeeCoin,k=B.gasLimit,b=B.networkFee;const K=this.createUnsignedTxHex([g],l),_={gasFeeCoin:m,gasLimit:k,unsignedTxHex:K},H=this.makeEdgeTransactionAmounts(h,b,i);return this.checkBalances(H,i),{blockHeight:0,currencyCode:o,date:0,isSend:!0,memos:c,nativeAmount:H.nativeAmount,networkFee:H.networkFee,networkFees:[],otherParams:_,ourReceiveAddresses:[],parentNetworkFee:H.parentNetworkFee,signedTx:"",tokenId:i,txid:"",walletId:this.walletId}})}signMessage(n,t,r){return E(this,null,function*(){const s=(0,A.yu)(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(s.mnemonic);if((r==null?void 0:r.otherParams)!=null)switch(r.otherParams.method){case"cosmos_getAccounts":{(0,A.yt)(r.otherParams);const m=(yield o.getAccounts()).map(k=>Ke(ue({},k),{pubkey:R.K3.stringify(k.pubkey)}));return JSON.stringify(m)}case"cosmos_signDirect":{const g=(0,A.S4)(r.otherParams),{signDoc:m}=g.params,k=U.SignDoc.fromPartial({accountNumber:(0,He.longify)(m.accountNumber),authInfoBytes:ae(m.authInfoBytes),bodyBytes:ae(m.bodyBytes),chainId:m.chainId}),w={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,k)).signature,signed:g.params.signDoc};return JSON.stringify(w)}case"cosmos_signAmino":{const g=(0,A.tV)(r.otherParams),{signDoc:m}=g.params,k=(0,M.makeSignDoc)(m.msgs,m.fee,m.chain_id,m.memo,m.account_number,m.sequence);fn(k);const{bech32AddressPrefix:b,bip39Path:w}=this.networkInfo,B=(0,j.stringToPath)(w),H={signature:(yield(yield M.Secp256k1HdWallet.fromMnemonic(o.mnemonic,{prefix:b,hdPaths:[B]})).signAmino(this.walletInfo.keys.bech32Address,k)).signature,signed:m};return JSON.stringify(H)}default:throw new Error(`Invalid method: ${r.method}`)}const c=R.xn.parse(n),a=U.SignDoc.decode(c),i=yield o.signDirect(this.walletInfo.keys.bech32Address,a),l=(0,M.decodeSignature)(i.signature),h=U.TxRaw.fromPartial({authInfoBytes:a.authInfoBytes,bodyBytes:a.bodyBytes,signatures:[l.signature]}),d=U.TxRaw.encode(h).finish();return R.xn.stringify(d)})}signTx(n,t){return E(this,null,function*(){const{gasFeeCoin:r,gasLimit:s,unsignedTxHex:o}=(0,A.TG)(n.otherParams),c=(0,A.yu)(this.currencyInfo.pluginId)(t),a=R.xn.parse(o),{bodyBytes:i}=U.TxRaw.decode(a),l=R.xn.parse(this.walletInfo.keys.publicKey),h=(0,M.encodeSecp256k1Pubkey)(l),d=(0,V.makeAuthInfoBytes)([{pubkey:(0,V.encodePubkey)(h),sequence:this.getSequence()}],[r],parseInt(s),void 0,void 0,1),y=U.SignDoc.fromPartial({accountNumber:(0,He.longify)(this.accountNumber),authInfoBytes:d,bodyBytes:i,chainId:this.chainId}),m=yield(yield this.tools.createSigner(c.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,y),k=(0,M.decodeSignature)(m.signature),b=U.TxRaw.fromPartial({authInfoBytes:d,bodyBytes:i,signatures:[k.signature]}),w=U.TxRaw.encode(b).finish(),B=R.xn.stringify(w);return n.signedTx=B,n})}broadcastTx(n){return E(this,null,function*(){try{const t=R.xn.parse(n.signedTx),{stargateClient:r}=this.getClients(),s=yield r.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
- ${(0,x.T5)(n)}`),n.txid=s,n.date=Date.now()/1e3,this.addToUnconfirmedCache(s),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return E(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function ze(e){return e.currencyInfo.pluginId==="thorchainrune"}const qn=(0,u.eB)({result:(0,u.eB)({node_info:(0,u.eB)({network:u.oJ})})}),Qe=(0,u.eB)({address:u.oJ,coins:(0,u._j)((0,u.eB)({amount:u.oJ,asset:u.oJ})),txID:u.oJ}),zn=(0,u.eB)({actions:(0,u._j)((0,u.eB)({date:u.oJ,height:u.oJ,in:(0,u._j)(Qe),metadata:(0,u.eB)((0,u.eB)({memo:u.oJ,networkFees:(0,u._j)((0,u.eB)({amount:u.oJ,asset:u.oJ}))})),out:(0,u._j)(Qe)})),meta:(0,u.eB)({nextPageToken:u.oJ})}),Qn=(0,u.eB)({midgardTxQueryParams:(0,u.HS)((0,u.eB)({mostRecentHeight:u.oJ,mostRecentTxId:u.oJ}),()=>({mostRecentHeight:"0",mostRecentTxId:""}))}),Gn=(0,u.eB)({native_outbound_fee_rune:u.oJ,native_tx_fee_rune:u.oJ});var Zn=Object.defineProperty,Ge=Object.getOwnPropertySymbols,Xn=Object.getPrototypeOf,Yn=Object.prototype.hasOwnProperty,jn=Object.prototype.propertyIsEnumerable,et=Reflect.get,Ze=(e,n,t)=>n in e?Zn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Xe=(e,n)=>{for(var t in n||(n={}))Yn.call(n,t)&&Ze(e,t,n[t]);if(Ge)for(var t of Ge(n))jn.call(n,t)&&Ze(e,t,n[t]);return e},nt=(e,n,t)=>et(Xn(e),t,n),de=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const tt=(0,ge.fi)(2e4);class pe extends ne{constructor(n,t,r,s){super(n,t,r,s),this.networkInfo=n.networkInfo}setOtherData(n){const t=(0,A.qd)(n),r=Qn(n);this.otherData=Xe(Xe({},t),r)}queryChainId(){return de(this,null,function*(){try{const n=yield this.fetchCors(this.networkInfo.chainIdUpdateUrl);if(!n.ok){const s=yield n.text();throw new Error(s)}const t=yield n.json(),r=qn(t);this.chainId=r.result.node_info.network,this.removeFromLoop("queryChainId")}catch(n){this.error("queryChainId Error ",n)}})}queryTransactions(){return de(this,null,function*(){const n=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(y=>this.allTokensMap[y].currencyCode)],{url:t,headers:r}=ie(this.networkInfo.midgardConnctionInfo,this.tools.initOptions),s=`${t}/v2/actions?address=${this.walletInfo.keys.bech32Address}`,{mostRecentHeight:o,mostRecentTxId:c}=this.otherData.midgardTxQueryParams,a=o;let i,l=o,h=c,d=!1;for(;;){try{const y=`&fromHeight=${a}`,g=i!=null?`&nextPageToken=${i}`:"",m=yield this.fetchCors(`${s}${y}${g}`,r);if(!m.ok){const w=yield m.text();throw new Error(w)}const k=yield m.json(),b=zn(k);if(b.actions.length===0||b.meta.nextPageToken==="")break;i=b.meta.nextPageToken;for(const w of b.actions){l=(0,C.max)(l,w.height);const B=parseInt((0,C.div)(w.date,"1000000000")),{memo:K}=Object.values(w.metadata)[0];let _="";const H=[],q=(z,en)=>{for(const he of z){he.txID.length>_.length&&(_=he.txID);for(const nn of he.coins){if(nn.asset!=="THOR.RUNE")continue;const dt=en==="coin_received"?"receiver":"spender";H.push({type:en,attributes:[{key:"amount",value:`${(0,C.abs)(nn.amount)}rune`},{key:dt,value:he.address}]})}}};if(q(w.in,"coin_spent"),q(w.out,"coin_received"),_===c){d=!0;break}h===c&&(h=_);let $=[];try{$=Te(H,this.walletInfo.keys.bech32Address)}catch(z){this.log.warn("reduceCoinEventsForAddress error:",String(z))}if($.length===0)continue;const ve={amount:[{denom:"rune",amount:"2000000"}],gasLimit:BigInt(0),payer:"",granter:""};$.forEach(z=>{this.processCosmosTransaction(_,B,"",z,K,parseInt(w.height),ve)})}}catch(y){this.log.warn("queryTransactionsMidgard error:",y)}if(d)break}(l!==o||h!==c)&&(this.otherData.midgardTxQueryParams.mostRecentHeight=l,this.otherData.midgardTxQueryParams.mostRecentTxId=h!=null?h:"",this.walletLocalDataDirty=!0),n.forEach(y=>this.tokenCheckTransactionsStatus[y]=1),this.updateOnAddressesChecked(),this.updateTransactionEvents()})}calculateFee(n){return de(this,null,function*(){const{url:t,headers:r}=ie(this.networkInfo.transactionFeeConnectionInfo,this.tools.initOptions),o=yield(yield this.fetchCors(t,{method:"GET",headers:r})).json(),c=Gn(o);let a="0";for(const i of n.messages)switch(i.typeUrl){case"/types.MsgDeposit":a=(0,C.add)(a,c.native_outbound_fee_rune);break;case"/types.MsgSend":a=(0,C.add)(a,c.native_tx_fee_rune)}return{gasFeeCoin:(0,v.coin)("1",this.networkInfo.nativeDenom),gasLimit:"60000000",networkFee:(0,C.mul)(a,"1.01")}})}startEngine(){return de(this,null,function*(){this.addToLoop("queryChainId",tt),yield nt(pe.prototype,this,"startEngine").call(this)})}}var ot=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});function rt(e,n,t,r){return ot(this,null,function*(){const s=(0,A.r3)(t);console.debug("isThorchainEnvironment",ze(e));const o=ze(e)?new pe(e,n,s,r):new ne(e,n,s,r);return yield o.loadEngine(),o})}var st=p(48287).Buffer,Ye=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,ct=(e,n)=>{var t={};for(var r in e)it.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ye)for(var r of Ye(e))n.indexOf(r)<0&&at.call(e,r)&&(t[r]=e[r]);return t},J=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});class je{constructor(n){const{builtinTokens:t,currencyInfo:r,initOptions:s,io:o,networkInfo:c}=n;this.io=o,this.currencyInfo=r,this.builtinTokens=t,this.networkInfo=c,this.initOptions=s,this.clientCount=0;const{methods:a,registry:i}=Rn(r.pluginId);this.methods=a,this.registry=i;const{chainName:l,url:h}=this.networkInfo.chainInfo,d=Q.Bt.find(g=>g.chain_name===l&&g.network_type==="mainnet");if(d==null)throw new Error("Unknown chain");this.chainData=d;const y=new fe.wV;y.fetch(h).then(()=>{this.chainData=y.getChain(this.chainData.chain_name)}).catch(g=>{})}createSigner(n){return J(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:r}=this.networkInfo,s=(0,j.stringToPath)(r);return yield V.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[s],prefix:t})})}getDisplayPrivateKey(n){return J(this,null,function*(){const{pluginId:t}=this.currencyInfo;return(0,A.yu)(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return J(this,null,function*(){const{keys:t}=(0,A.r3)(n);return t.publicKey})}importPrivateKey(n){return J(this,null,function*(){if(!(0,oe.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return J(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=st.from(this.io.random(32)),r=(0,oe.entropyToMnemonic)(t);return yield this.importPrivateKey(r)})}derivePublicKey(n){return J(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=(0,A.yu)(this.currencyInfo.pluginId)(n.keys),s=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:c}=s[0],a=R.xn.stringify(c);return{bech32Address:o,publicKey:a}})}isValidOurAddress(n){try{if((0,P.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}isValidTargetAddress(n){try{const t=(0,P.fromBech32)(n);if(Q.Bt.find(s=>s.bech32_prefix===t.prefix)!=null)return!0}catch{}return!1}parseUri(n,t,r){return J(this,null,function*(){const{pluginId:s}=this.currencyInfo,o={[s]:!0},{parsedUri:c,edgeParsedUri:a}=yield(0,re.x)({currencyInfo:this.currencyInfo,uri:n,networks:o,builtinTokens:this.builtinTokens,currencyCode:t!=null?t:this.currencyInfo.currencyCode,customTokens:r});let i="";if(a.publicAddress!=null&&(i=a.publicAddress),!this.isValidTargetAddress(i))throw new Error("InvalidPublicAddressError");return a.uniqueIdentifier=c.query.memo,a})}encodeUri(n){return J(this,arguments,function*(t,r=[]){const{pluginId:s}=this.currencyInfo,{nativeAmount:o,currencyCode:c,publicAddress:a}=t;if(!this.isValidOurAddress(a))throw new Error("InvalidPublicAddressError");let i;if(typeof o=="string"){const h=(0,x.FQ)(c!=null?c:this.currencyInfo.currencyCode,this.currencyInfo,r,this.builtinTokens);if(h==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,C.div)(o,h.multiplier,18)}return(0,re.m)(t,s,i)})}connectClient(){return J(this,null,function*(){this.clients==null&&(this.clients=yield ke(this.io.fetchCors,ie(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return J(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 J(this,null,function*(){var t;(0,ee.k9)(n);const{contractAddress:r}=(t=(0,ee.oQ)(n.networkLocation))!=null?t:{},s=/^ibc\/[0-9A-F]{64}$/,o=/^(?!ibc)[a-z][a-z0-9/]{2,127}/;if(r==null||!s.test(r)&&!o.test(r))throw new Error("ErrorInvalidContractAddress");return r.toLowerCase().replace(/\//g,"")})}}function lt(e){return J(this,null,function*(){return new je(e)})}function ut(e,n){return J(this,null,function*(){const t=ct(n,[]);e.networkInfo=(0,x.wy)(e.networkInfo,t)})}},73776:function(){},77667:function(){},76447:function(){},15340:function(){},79838:function(){}}]);
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[7854],{62351:function(on,te,p){"use strict";p.d(te,{Nn:function(){return R},Nt:function(){return ee},fi:function(){return re},zp:function(){return oe}});var fe=p(14171),j=p(44276),P=(x,I,S)=>new Promise((N,U)=>{var M=D=>{try{v(S.next(D))}catch(u){U(u)}},W=D=>{try{v(S.throw(D))}catch(u){U(u)}},v=D=>D.done?N(D.value):Promise.resolve(D.value).then(M,W);v((S=S.apply(x,I)).next())});const V=["https://info1.edge.app","https://info2.edge.app"];function C(x,I,S){return P(this,arguments,function*(N,U,M,W=5e3,v=fetch){const D=N.map(u=>()=>P(this,null,function*(){const A=yield v(u+"/"+U,M);if(typeof A!="object"){const se=`Invalid return value ${U} in ${u}`;throw console.log(se),new Error(se)}return A}));return yield(0,fe.NN)(D,W)})}function oe(x,I,S,N,U=5e3,M){return P(this,null,function*(){const W=yield C((0,j.R3)(I),S,N,U,M);if(!W.ok){const u=yield W.text();throw console.error(u),new Error(`Error fetching ${S}: ${u}`)}const v=yield W.json();return x(v)})}function Q(x,I,S,N=5e3,U){return P(this,null,function*(){return yield C((0,j.R3)(x),I,S,N,U)})}const R=(x,I,S,N)=>P(void 0,null,function*(){return yield Q(V,x,I,S,N)}),ee=x=>Object.keys(x).map(I=>{const S=x[I];return S==null?I:`${I}=${encodeURIComponent(S)}`}).join("&"),re=(x,I=5e3)=>x+Math.random()*I*2-I},34931:function(on,te,p){"use strict";p.r(te),p.d(te,{CosmosTools:function(){return je},makeCurrencyEngine:function(){return st},makeCurrencyTools:function(){return ut},updateInfoPayload:function(){return dt}});var fe=p(26469),j=p(76005),P=p(44917),V=p(5450),C=p(66001),oe=p(90749),Q=p(50949),R=p(65828),ee=p(14483),re=p(96542),x=p(44276),I=p(44941),S=p(2666),N=p(86181),U=p(59717),M=p(78824),W=p(15960),v=p(84007),D=p(67112),u=p(42704),A=p(84397),se=p(48287).Buffer,me=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const ie=(e,n)=>{const t=(0,A.tx)(n),r={},s=/{{(.*?)}}/g;for(const[o,c]of Object.entries(e.headers)){const a=s.exec(c);a!=null&&(r[o]=t[a[1]])}return{url:e.url,headers:r}},rn=(e,n)=>{const{url:t,headers:r}=n;return{execute:s=>me(void 0,null,function*(){var o;const c={method:"POST",headers:r,body:JSON.stringify(s)},i=yield(yield e(t,c)).json();if((0,W.isJsonRpcErrorResponse)(i))throw new Error(String((o=i.error.data)!=null?o:i.error.message));return i}),disconnect:()=>{}}},sn=e=>me(void 0,null,function*(){const n=yield D.Comet38Client.create(e),t=(yield n.status()).nodeInfo.version;return t.startsWith("0.38.")?n:t.startsWith("0.37.")?yield D.Tendermint37Client.create(e):yield D.Tendermint34Client.create(e)}),ke=(e,n)=>me(void 0,null,function*(){const t=yield v.StargateClient.create(yield sn(rn(e,n))),r=t.forceGetCometClient();return{queryClient:v.QueryClient.withExtensions(r,v.setupAuthExtension,v.setupBankExtension,v.setupStakingExtension,v.setupTxExtension,v.setupIbcExtension),stargateClient:t,cometClient:r}}),an=e=>{var n;const[t,...r]=e.split("."),s=e.includes("/"),o=r.join("."),c=(n=o==null?void 0:o.split("-"))==null?void 0:n[0];return{chain:t,symbol:o,ticker:c,synth:s}},G=e=>e.reduce((n,t)=>{try{return(0,M.addCoins)(n,t)}catch{}return n}),we=(0,u.E8)("amount"),cn=(0,u.E8)("receiver"),ln=(0,u.E8)("spender"),un=(0,u.E8)("amount","receiver","spender"),dn=(0,u.eB)({type:(0,u.E8)("coin_received"),attributes:(0,u.VA)((0,u.eB)({key:we,value:u.oJ}),(0,u.eB)({key:cn,value:u.oJ}))}),hn=(0,u.eB)({type:(0,u.E8)("coin_spent"),attributes:(0,u.VA)((0,u.eB)({key:we,value:u.oJ}),(0,u.eB)({key:ln,value:u.oJ}))}),Te=(e,n)=>{const t=new Map;for(const s of e){const o={type:s.type,attributes:s.attributes.filter(i=>(0,u.HS)(un)(i.key)!=null).sort((i,l)=>i.key<l.key?-1:1)},c=(0,u.HS)(dn)(o);if(c!=null){const[i,l]=c.attributes.map(d=>d.value);if(l!==n)continue;be(i).forEach(d=>{var y;const g=d.amount,f=(y=t.get(d.denom))!=null?y:"0";t.set(d.denom,(0,C.add)(g,f))});continue}const a=(0,u.HS)(hn)(o);if(a!=null){const[i,l]=a.attributes.map(d=>d.value);if(l!==n)continue;be(i).forEach(d=>{var y;const g=`-${d.amount}`,f=(y=t.get(d.denom))!=null?y:"0";t.set(d.denom,(0,C.add)(g,f))})}}const r=[];return t.forEach((s,o)=>{s!=="0"&&r.push({denom:o,amount:s})}),r},ae=e=>{try{return R.xn.parse(e)}catch{return R.K3.parse(e)}},be=e=>e.replace(/\s/g,"").split(",").filter(Boolean).map(n=>{var t;const r=n.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/-]{2,127})$/);if(r==null)throw new Error(`Got an invalid coin string: ${e}`);return{amount:(t=r[1].replace(/^0+/,""))!=null?t:"0",denom:r[2]}}),fn=(e,n)=>{const t=Q.Bt.find(c=>c.bech32_prefix===(0,P.fromBech32)(n).prefix);if(t==null)throw new Error("Unrecognized denom");const r=t.chain_name,s=(0,U.Dn)(Q.tX,e,r);if(s==null)throw new Error(`No IBC channels between ${e} and ${r}`);const o=(0,U.hP)(s);return e<r?{channel:o.chain_1.channel_id,port:o.chain_1.port_id}:{channel:o.chain_2.channel_id,port:o.chain_2.port_id}};function mn(e){if(!(()=>(e==null?void 0:e.msgs)!=null&&Array.isArray(e.msgs)&&e.msgs.length===1?e.msgs[0].type==="sign/MsgSignData":!1)())return!1;if(e.chain_id!=="")throw new Error("Chain id should be empty string for ADR-36 signing");if(e.memo!=="")throw new Error("Memo should be empty string for ADR-36 signing");if(e.account_number!=="0")throw new Error('Account number should be "0" for ADR-36 signing');if(e.sequence!=="0")throw new Error('Sequence should be "0" for ADR-36 signing');if(e.fee.gas!=="0")throw new Error('Gas should be "0" for ADR-36 signing');if(e.fee.amount.length!==0)throw new Error("Fee amount should be empty array for ADR-36 signing");const t=e.msgs[0];if(t.type!=="sign/MsgSignData")throw new Error(`Invalid type of ADR-36 sign msg: ${t.type}`);if(t.value==null)throw new Error("Empty value in the msg");const r=t.value.signer;if(r==null)throw new Error("Empty signer in the ADR-36 msg");(0,P.fromBech32)(r);const s=t.value.data;if(s==null)throw new Error("Empty data in the ADR-36 msg");const o=se.from(s,"base64");if(o.toString("base64")!==s)throw new Error("Data is not encoded by base64");if(o.length===0)throw new Error("Empty data in the ADR-36 msg");return!0}var gn=p(28570),F=p.n(gn),yn=p(26946),m=p.n(yn);const ft="common";function Ce(){return{chain:"",symbol:"",ticker:"",synth:!1}}const Z={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ce();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.chain=t.string();continue;case 2:if(o!==18)break;s.symbol=t.string();continue;case 3:if(o!==26)break;s.ticker=t.string();continue;case 4:if(o!==32)break;s.synth=t.bool();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{chain:O(e.chain)?globalThis.String(e.chain):"",symbol:O(e.symbol)?globalThis.String(e.symbol):"",ticker:O(e.ticker)?globalThis.String(e.ticker):"",synth:O(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 Z.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s;const o=Ce();return o.chain=(n=e.chain)!=null?n:"",o.symbol=(t=e.symbol)!=null?t:"",o.ticker=(r=e.ticker)!=null?r:"",o.synth=(s=e.synth)!=null?s:!1,o}};function Ae(){return{asset:void 0,amount:"",decimals:F().ZERO}}const T={encode(e,n=m().Writer.create()){return e.asset!==void 0&&Z.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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ae();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.asset=Z.decode(t,t.uint32());continue;case 2:if(o!==18)break;s.amount=t.string();continue;case 3:if(o!==24)break;s.decimals=t.int64();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{asset:O(e.asset)?Z.fromJSON(e.asset):void 0,amount:O(e.amount)?globalThis.String(e.amount):"",decimals:O(e.decimals)?F().fromValue(e.decimals):F().ZERO}},toJSON(e){const n={};return e.asset!==void 0&&(n.asset=Z.toJSON(e.asset)),e.amount!==""&&(n.amount=e.amount),e.decimals.isZero()||(n.decimals=(e.decimals||F().ZERO).toString()),n},create(e){return T.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ae();return t.asset=e.asset!==void 0&&e.asset!==null?Z.fromPartial(e.asset):void 0,t.amount=(n=e.amount)!=null?n:"",t.decimals=e.decimals!==void 0&&e.decimals!==null?F().fromValue(e.decimals):F().ZERO,t}};function Ie(){return{secp256k1:"",ed25519:""}}const pn={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ie();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.secp256k1=t.string();continue;case 2:if(o!==18)break;s.ed25519=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{secp256k1:O(e.secp256k1)?globalThis.String(e.secp256k1):"",ed25519:O(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 pn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Ie();return r.secp256k1=(n=e.secp256k1)!=null?n:"",r.ed25519=(t=e.ed25519)!=null?t:"",r}};function Se(){return{id:"",chain:"",fromAddress:"",toAddress:"",coins:[],gas:[],memo:""}}const vn={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Se();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.id=t.string();continue;case 2:if(o!==18)break;s.chain=t.string();continue;case 3:if(o!==26)break;s.fromAddress=t.string();continue;case 4:if(o!==34)break;s.toAddress=t.string();continue;case 5:if(o!==42)break;s.coins.push(T.decode(t,t.uint32()));continue;case 6:if(o!==50)break;s.gas.push(T.decode(t,t.uint32()));continue;case 7:if(o!==58)break;s.memo=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{id:O(e.id)?globalThis.String(e.id):"",chain:O(e.chain)?globalThis.String(e.chain):"",fromAddress:O(e.fromAddress)?globalThis.String(e.fromAddress):"",toAddress:O(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:O(e.memo)?globalThis.String(e.memo):""}},toJSON(e){var n,t;const r={};return e.id!==""&&(r.id=e.id),e.chain!==""&&(r.chain=e.chain),e.fromAddress!==""&&(r.fromAddress=e.fromAddress),e.toAddress!==""&&(r.toAddress=e.toAddress),(n=e.coins)!=null&&n.length&&(r.coins=e.coins.map(s=>T.toJSON(s))),(t=e.gas)!=null&&t.length&&(r.gas=e.gas.map(s=>T.toJSON(s))),e.memo!==""&&(r.memo=e.memo),r},create(e){return vn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r,s,o,c,a;const i=Se();return i.id=(n=e.id)!=null?n:"",i.chain=(t=e.chain)!=null?t:"",i.fromAddress=(r=e.fromAddress)!=null?r:"",i.toAddress=(s=e.toAddress)!=null?s:"",i.coins=((o=e.coins)==null?void 0:o.map(l=>T.fromPartial(l)))||[],i.gas=((c=e.gas)==null?void 0:c.map(l=>T.fromPartial(l)))||[],i.memo=(a=e.memo)!=null?a:"",i}};function xe(){return{coins:[],poolDeduct:""}}const kn={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=xe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.poolDeduct=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],poolDeduct:O(e.poolDeduct)?globalThis.String(e.poolDeduct):""}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>T.toJSON(r))),e.poolDeduct!==""&&(t.poolDeduct=e.poolDeduct),t},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=xe();return r.coins=((n=e.coins)==null?void 0:n.map(s=>T.fromPartial(s)))||[],r.poolDeduct=(t=e.poolDeduct)!=null?t:"",r}};function Ee(){return{value:""}}const wn={encode(e,n=m().Writer.create()){return e.value!==""&&n.uint32(10).string(e.value),n},decode(e,n){const t=e instanceof m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ee();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.value=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{value:O(e.value)?globalThis.String(e.value):""}},toJSON(e){const n={};return e.value!==""&&(n.value=e.value),n},create(e){return wn.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ee();return t.value=(n=e.value)!=null?n:"",t}};m().util.Long!==F()&&(m().util.Long=F(),m().configure());function O(e){return e!=null}const mt="types";function Pe(){return{coins:[],memo:"",signer:new Uint8Array(0)}}const ce={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Pe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.coins.push(T.decode(t,t.uint32()));continue;case 2:if(o!==18)break;s.memo=t.string();continue;case 3:if(o!==26)break;s.signer=t.bytes();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{coins:globalThis.Array.isArray(e==null?void 0:e.coins)?e.coins.map(n=>T.fromJSON(n)):[],memo:De(e.memo)?globalThis.String(e.memo):"",signer:De(e.signer)?Tn(e.signer):new Uint8Array(0)}},toJSON(e){var n;const t={};return(n=e.coins)!=null&&n.length&&(t.coins=e.coins.map(r=>T.toJSON(r))),e.memo!==""&&(t.memo=e.memo),e.signer.length!==0&&(t.signer=bn(e.signer)),t},create(e){return ce.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Pe();return s.coins=((n=e.coins)==null?void 0:n.map(o=>T.fromPartial(o)))||[],s.memo=(t=e.memo)!=null?t:"",s.signer=(r=e.signer)!=null?r:new Uint8Array(0),s}};function Tn(e){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(e,"base64"));{const n=globalThis.atob(e),t=new Uint8Array(n.length);for(let r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function bn(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(""))}}m().util.Long!==F()&&(m().util.Long=F(),m().configure());function De(e){return e!=null}const gt="cosmos.base.v1beta1";function Oe(){return{denom:"",amount:""}}const X={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Oe();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:Y(e.denom)?globalThis.String(e.denom):"",amount:Y(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 X.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Oe();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Be(){return{denom:"",amount:""}}const Cn={encode(e,n=m().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 m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Be();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.denom=t.string();continue;case 2:if(o!==18)break;s.amount=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{denom:Y(e.denom)?globalThis.String(e.denom):"",amount:Y(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 Cn.fromPartial(e!=null?e:{})},fromPartial(e){var n,t;const r=Be();return r.denom=(n=e.denom)!=null?n:"",r.amount=(t=e.amount)!=null?t:"",r}};function Re(){return{int:""}}const An={encode(e,n=m().Writer.create()){return e.int!==""&&n.uint32(10).string(e.int),n},decode(e,n){const t=e instanceof m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Re();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.int=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{int:Y(e.int)?globalThis.String(e.int):""}},toJSON(e){const n={};return e.int!==""&&(n.int=e.int),n},create(e){return An.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Re();return t.int=(n=e.int)!=null?n:"",t}};function Ne(){return{dec:""}}const In={encode(e,n=m().Writer.create()){return e.dec!==""&&n.uint32(10).string(e.dec),n},decode(e,n){const t=e instanceof m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Ne();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.dec=t.string();continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{dec:Y(e.dec)?globalThis.String(e.dec):""}},toJSON(e){const n={};return e.dec!==""&&(n.dec=e.dec),n},create(e){return In.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=Ne();return t.dec=(n=e.dec)!=null?n:"",t}};m().util.Long!==F()&&(m().util.Long=F(),m().configure());function Y(e){return e!=null}const yt="types";function Me(){return{fromAddress:new Uint8Array(0),toAddress:new Uint8Array(0),amount:[]}}const le={encode(e,n=m().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)X.encode(t,n.uint32(26).fork()).ldelim();return n},decode(e,n){const t=e instanceof m().Reader?e:m().Reader.create(e);let r=n===void 0?t.len:t.pos+n;const s=Me();for(;t.pos<r;){const o=t.uint32();switch(o>>>3){case 1:if(o!==10)break;s.fromAddress=t.bytes();continue;case 2:if(o!==18)break;s.toAddress=t.bytes();continue;case 3:if(o!==26)break;s.amount.push(X.decode(t,t.uint32()));continue}if((o&7)===4||o===0)break;t.skipType(o&7)}return s},fromJSON(e){return{fromAddress:Ue(e.fromAddress)?Fe(e.fromAddress):new Uint8Array(0),toAddress:Ue(e.toAddress)?Fe(e.toAddress):new Uint8Array(0),amount:globalThis.Array.isArray(e==null?void 0:e.amount)?e.amount.map(n=>X.fromJSON(n)):[]}},toJSON(e){var n;const t={};return e.fromAddress.length!==0&&(t.fromAddress=Le(e.fromAddress)),e.toAddress.length!==0&&(t.toAddress=Le(e.toAddress)),(n=e.amount)!=null&&n.length&&(t.amount=e.amount.map(r=>X.toJSON(r))),t},create(e){return le.fromPartial(e!=null?e:{})},fromPartial(e){var n,t,r;const s=Me();return s.fromAddress=(n=e.fromAddress)!=null?n:new Uint8Array(0),s.toAddress=(t=e.toAddress)!=null?t:new Uint8Array(0),s.amount=((r=e.amount)==null?void 0:r.map(o=>X.fromPartial(o)))||[],s}};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 r=0;r<n.length;++r)t[r]=n.charCodeAt(r);return t}}function Le(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(""))}}m().util.Long!==F()&&(m().util.Long=F(),m().configure());function Ue(e){return e!=null}var Sn=Object.defineProperty,xn=Object.defineProperties,En=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertySymbols,Pn=Object.prototype.hasOwnProperty,Dn=Object.prototype.propertyIsEnumerable,_e=(e,n,t)=>n in e?Sn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,On=(e,n)=>{for(var t in n||(n={}))Pn.call(n,t)&&_e(e,t,n[t]);if(Je)for(var t of Je(n))Dn.call(n,t)&&_e(e,t,n[t]);return e},Bn=(e,n)=>xn(e,En(n));const Rn=1e3*60*60*24,Nn=e=>{const n=new V.Registry([["/ibc.applications.transfer.v1.MsgTransfer",N.MsgTransfer],["/cosmwasm.wasm.v1.MsgExecuteContract",S.zM]]);let t=s=>{const{amount:o,fromAddress:c,toAddress:a}=s;return{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:I.MsgSend.encode(I.MsgSend.fromPartial({fromAddress:c,toAddress:a,amount:o})).finish()}};const r=s=>{const{memo:o,toAddress:c,fromAddress:a,channel:i,port:l,amount:h}=s;return{typeUrl:"/ibc.applications.transfer.v1.MsgTransfer",value:N.MsgTransfer.encode(N.MsgTransfer.fromPartial({memo:o,receiver:c,sender:a,sourceChannel:i,sourcePort:l,token:h,timeoutTimestamp:BigInt((Date.now()+Rn)*1e6)})).finish()}};switch(e){case"thorchainrune":case"thorchainrunestagenet":{const s="/types.MsgDeposit";n.register(s,ce);const o=a=>{const{assets:i,memo:l,signer:h}=a,d=i.map(g=>Bn(On({},g),{asset:an(g.asset)}));return{typeUrl:s,value:ce.encode(ce.fromPartial({coins:d,memo:l,signer:(0,P.fromBech32)(h).data})).finish()}},c="/types.MsgSend";return n.register(c,le),t=a=>{const{amount:i,fromAddress:l,toAddress:h}=a;return{typeUrl:c,value:le.encode(le.fromPartial({fromAddress:(0,P.fromBech32)(l).data,toAddress:(0,P.fromBech32)(h).data,amount:i})).finish()}},{methods:{deposit:o,ibcTransfer:r,transfer:t},registry:n}}}return{methods:{ibcTransfer:r,transfer:t},registry:n}};var He=p(1267),L=p(6975),Mn=p(82671),Fn=p(26277),ge=p(62351),Ln=Object.defineProperty,Un=Object.defineProperties,Jn=Object.getOwnPropertyDescriptors,$e=Object.getOwnPropertySymbols,_n=Object.getPrototypeOf,Hn=Object.prototype.hasOwnProperty,$n=Object.prototype.propertyIsEnumerable,Wn=Reflect.get,We=(e,n,t)=>n in e?Ln(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,ue=(e,n)=>{for(var t in n||(n={}))Hn.call(n,t)&&We(e,t,n[t]);if($e)for(var t of $e(n))$n.call(n,t)&&We(e,t,n[t]);return e},Ke=(e,n)=>Un(e,Jn(n)),Ve=(e,n,t)=>Wn(_n(e),t,n),E=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const qe=(0,ge.fi)(2e4),Kn=(0,ge.fi)(2e4),Vn=1e3*60*60*24*14,qn=1e3*60*2,ye=50;class ne extends Fn.k{constructor(n,t,r,s){super(n,t,r,s),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.chainId=this.networkInfo.defaultChainId,this.otherMethods={getMaxTx:o=>E(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:c,memo:a}=o;if(c.length!==1)throw new Error("Cannot calculate max tx for more than one asset");const i=this.tools.methods.deposit({assets:c,memo:a,signer:this.walletInfo.keys.bech32Address}),{networkFee:l}=yield this.calculateFee({messages:[i],memo:a}),h=this.getBalance({tokenId:null});return(0,C.sub)(h,l)}default:throw new Error(`Invalid type: ${o.type}`)}}),makeTx:o=>E(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:c,memo:a,metadata:i}=o,l=this.tools.methods.deposit({assets:c,memo:a,signer:this.walletInfo.keys.bech32Address}),h=this.createUnsignedTxHex([l],a),{gasFeeCoin:d,gasLimit:y,networkFee:g}=yield this.calculateFee({messages:[l],memo:a}),f={gasFeeCoin:d,gasLimit:y,unsignedTxHex:h};return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:Date.now()/1e3,isSend:!0,memos:[],metadata:i,nativeAmount:`-${g}`,networkFee:g,networkFees:[],otherParams:f,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:"",walletId:this.walletId}}default:throw new Error(`Invalid type: ${o.type}`)}}),parseWalletConnectV2Payload:o=>E(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 c=(0,A.S4)(o),{authInfoBytes:a,bodyBytes:i}=c.params.signDoc,l=L.TxBody.decode(ae(i)),{nativeAmount:h,tokenId:d}=this.getAmountAndTokenIdFromKnownMessageTypes(l.messages),y=L.AuthInfo.decode(ae(a));let g="0";const f=y.fee;return f!=null&&(g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),...f.amount]).amount),{nativeAmount:h,networkFee:g,tokenId:d}}case"cosmos_signAmino":{const c=(0,A.tV)(o),{signDoc:a}=c.params,i=(0,M.makeSignDoc)(a.msgs,a.fee,a.chain_id,a.memo,a.account_number,a.sequence),l=new v.AminoTypes(ue(ue({},v.createBankAminoConverters),v.createIbcAminoConverters)),h=i.msgs.filter(k=>k.type!=="sign/MsgSignData").map(k=>l.fromAmino(k)),{nativeAmount:d,tokenId:y}=this.getAmountAndTokenIdFromKnownMessageTypes(h);let g="0";const f=a.fee;return f!=null&&(g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),...f.amount]).amount),{nativeAmount:d,networkFee:g,tokenId:y}}default:throw new Error(`Invalid method: ${o==null?void 0:o.method}`)}}catch(c){throw this.warn("Wallet connect call_request ",c),c}})}}tokenIdFromDenom(n){if(this.networkInfo.nativeDenom===n)return null;const t=Object.keys(this.allTokensMap).find(r=>{var s;return((s=this.allTokensMap[r].networkLocation)==null?void 0:s.contractAddress)===n});if(t===void 0)throw new Error(`Unrecognized denom: ${n}`);return t}getAmountAndTokenIdFromKnownMessageTypes(n){var t;let r=null,s;for(const o of n)switch(o.typeUrl){case"/ibc.applications.transfer.v1.MsgTransfer":{const c=this.tools.registry.decode(o),a=N.MsgTransfer.fromPartial(c);r===void 0&&(r=this.tokenIdFromDenom(a.token.denom));const i=(0,v.coin)(a.token.amount,a.token.denom);s==null?s=i:s=G([s,i]);break}case"/cosmwasm.wasm.v1.MsgExecuteContract":{const c=this.tools.registry.decode(o),a=S.zM.fromPartial(c),{funds:i}=a;if(i.length>0){const{denom:l}=i[0];r===void 0&&(r=this.tokenIdFromDenom(l));let h=(0,v.coin)("0",l);for(const d of i)h=G([h,d]);s==null?s=h:s=G([s,h])}break}default:}return{nativeAmount:(t=s==null?void 0:s.amount)!=null?t:"0",tokenId:r}}setOtherData(n){this.otherData=(0,A.qd)(n)}getClients(){if(this.tools.clients==null)throw new Error("No StargateClient");return this.tools.clients}queryBalance(){return E(this,null,function*(){var n;try{const{stargateClient:t}=this.getClients(),r=yield t.getAllBalances(this.walletInfo.keys.bech32Address),s=r.find(i=>i.denom===this.networkInfo.nativeDenom);this.updateBalance(this.currencyInfo.currencyCode,(n=s==null?void 0:s.amount)!=null?n:"0");const o=[];if(Object.keys(this.allTokensMap).forEach(i=>{var l;const h=this.allTokensMap[i],d=r.find(g=>{var f;return g.denom===((f=h.networkLocation)==null?void 0:f.contractAddress)}),y=(l=d==null?void 0:d.amount)!=null?l:"0";this.updateBalance(h.currencyCode,y),(0,C.gt)(y,"0")&&!this.enabledTokenIds.includes(i)&&o.push(i)}),o.length>0&&this.currencyEngineCallbacks.onNewTokens(o),this.stakingSupported)try{const i=yield t.getBalanceStaked(this.walletInfo.keys.bech32Address);if(i!=null&&this.stakedBalanceCache!==i.amount){const l={stakedAmounts:[{nativeAmount:i.amount}]};this.currencyEngineCallbacks.onStakingStatusChanged(l),this.stakedBalanceCache=i.amount}}catch(i){if(String(i).includes("unknown query path"))this.stakingSupported=!1;else throw i}const{accountNumber:c,sequence:a}=yield t.getSequence(this.walletInfo.keys.bech32Address);this.accountNumber=c,this.sequence=a}catch(t){String(t).includes("does not exist on chain")?this.updateBalance(this.currencyInfo.currencyCode,"0"):this.log.warn("queryBalance error:",t)}})}queryBlockheight(){return E(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 E(this,null,function*(){var n;let t=0;const r=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(o=>this.allTokensMap[o].currencyCode)],s=[];if(this.networkInfo.archiveNodes!=null&&Date.now()-Vn>this.otherData.archivedTxLastCheckTime){const o=this.networkInfo.archiveNodes.sort((c,a)=>c.blockTimeRangeSeconds.start-a.blockTimeRangeSeconds.start);for(const c of o)if(c.blockTimeRangeSeconds.end==null||c.blockTimeRangeSeconds.end>this.otherData.archivedTxLastCheckTime){const a=yield ke(this.fetchCors,ie(c.endpoint,this.tools.initOptions));s.push(a)}}s.push(this.getClients());for(const o of s){let c=0;for(const a of A.b8){const{newestTxid:i,lastTimestamp:l}=yield this.queryTransactionsInner(a,o);i!=null&&((n=this.otherData[a])==null?void 0:n.newestTxid)!==i&&(this.otherData[a]={newestTxid:i},this.walletLocalDataDirty=!0,c=Math.max(c,l)),t+=.5/s.length,r.forEach(h=>this.tokenCheckTransactionsStatus[h]=t),this.updateOnAddressesChecked()}this.otherData.archivedTxLastCheckTime=c,this.walletLocalDataDirty=!0}this.otherData.archivedTxLastCheckTime=Date.now(),this.walletLocalDataDirty=!0,this.updateTransactionEvents()})}queryTransactionsInner(n,t){return E(this,null,function*(){const r={query:`${n}='${this.walletInfo.keys.bech32Address}'`,per_page:ye,order_by:"asc"};let s,o=0,c=1;do{try{const{totalCount:a,txs:i}=yield t.cometClient.txSearch(Ke(ue({},r),{page:c})),l=i.findIndex(h=>{var d;return(0,P.toHex)(h.hash).toUpperCase()===((d=this.otherData[n])==null?void 0:d.newestTxid)});for(let h=l+1;h<i.length;h++){const d=i[h];if(d==null)break;const y=(0,P.toHex)(d.hash).toUpperCase(),g=d.result.events.map(v.fromTendermintEvent);let f=[];try{f=Te(g,this.walletInfo.keys.bech32Address)}catch(q){this.log.warn("reduceCoinEventsForAddress error:",String(q))}if(f.length===0)continue;const k=yield t.stargateClient.getBlock(d.height),b=(0,D.toSeconds)((0,D.fromRfc3339WithNanoseconds)(k.header.time)).seconds,{height:w,tx:B}=d,K=R.xn.stringify(B),{authInfo:{fee:_},body:{memo:H}}=(0,V.decodeTxRaw)(B);f.forEach(q=>{this.processCosmosTransaction(y,b,K,q,H,w,_)}),s=y,this.otherData[n]={newestTxid:y},o=b*1e3,this.walletLocalDataDirty=!0}if(i.length<ye||a===c*ye)break}catch(a){if(String(a).includes("page should be within"))continue;throw this.log.warn("queryTransactions error:",a),a}c++,this.otherData[n]={newestTxid:s},this.walletLocalDataDirty=!0}while(!0);return{newestTxid:s,lastTimestamp:o}})}processCosmosTransaction(n,t,r,s,o,c,a){const{amount:i,denom:l}=s,h=this.networkInfo.nativeDenom===l;let d;try{d=this.tokenIdFromDenom(l)}catch{return}const{currencyCode:y}=d==null?this.currencyInfo:this.allTokensMap[d];let g="0";if(a!=null){const{amount:_}=a;g=G([(0,v.coin)("0",this.networkInfo.nativeDenom),..._]).amount}const f=(0,C.lt)(i,"0"),k=[];let b=i,w;f?h?b=(0,C.sub)(b,g):(w=g!=="0"?g:void 0,g="0"):(k.push(this.walletInfo.keys.bech32Address),g="0");const B=[];o!==""&&B.push({type:"text",value:o});const K={blockHeight:c,currencyCode:y,date:t,isSend:f,memos:B,nativeAmount:b,networkFee:g,networkFees:[],ourReceiveAddresses:k,parentNetworkFee:w,signedTx:r,tokenId:d,txid:n,walletId:this.walletId};this.addTransaction(y,K)}addTransaction(n,t){this.removeFromUnconfirmedCache(t.txid),super.addTransaction(n,t)}createUnsignedTxHex(n,t){const r=L.TxBody.fromPartial({messages:n,memo:t}),s=L.TxBody.encode(r).finish(),o=L.TxRaw.fromPartial({bodyBytes:s});return R.xn.stringify(L.TxRaw.encode(o).finish())}addToUnconfirmedCache(n){const t=new Date(new Date().getTime()+qn);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}calculateFee(n){return E(this,null,function*(){const{queryClient:t}=this.getClients(),{gasInfo:r}=yield t.tx.simulate(n.messages,n.memo,(0,M.encodeSecp256k1Pubkey)(R.xn.parse(this.walletInfo.keys.publicKey)),this.getSequence());if((r==null?void 0:r.gasUsed)==null)throw new Error("simulate didn't return gasUsed ");const s=(0,C.ceil)((0,C.mul)(r==null?void 0:r.gasUsed.toString(),"1.5"),0),{low:o,average:c,high:a}=(0,U.UP)(this.tools.chainData);let i=c;switch(n.networkFeeOption){case"low":{i=o;break}case"high":{i=a;break}case"custom":throw new Error("Custom fee not supported")}const l=(0,C.ceil)((0,C.mul)(s,i.toString()),0),h=(0,v.coin)(l,this.networkInfo.nativeDenom);return{gasFeeCoin:h,gasLimit:s,networkFee:h.amount}})}startEngine(){return E(this,null,function*(){yield this.tools.connectClient(),this.addToLoop("queryBalance",qe),this.addToLoop("queryBlockheight",qe),this.addToLoop("queryTransactions",Kn),yield Ve(ne.prototype,this,"startEngine").call(this)})}killEngine(){return E(this,null,function*(){yield this.tools.disconnectClient(),yield Ve(ne.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return E(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}validateTransfer(n,t,r){return E(this,null,function*(){var s;if(t==null)return;const o=this.allTokensMap[t],c=(0,ee.oQ)(o.networkLocation),a=c==null?void 0:c.contractAddress;if(a==null)throw new Error("Unknown denom");const{queryClient:i}=this.getClients();try{yield i.bank.denomMetadata(a);return}catch{const d=(s=(yield i.ibc.transfer.denomTrace(a)).denomTrace)==null?void 0:s.path.match(/transfer\/channel-\d+/);if(d==null||`${r.port}/${r.channel}`===d[0])return}throw new Error("Invalid transfer")})}makeSpend(n){return E(this,null,function*(){var t,r;const{edgeSpendInfo:s,currencyCode:o}=this.makeSpendCheck(n),{memos:c=[],networkFeeOption:a,tokenId:i}=s,l=(t=c[0])==null?void 0:t.value;if(s.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:h,publicAddress:d}=s.spendTargets[0];if(h==null)throw new Mn.ef;if(d==null)throw new Error("makeSpend Missing publicAddress");const y=i!=null?(r=this.allTokensMap[i].networkLocation)==null?void 0:r.contractAddress:this.networkInfo.nativeDenom;if(y==null)throw new Error("Unknown denom");let g;if(this.networkInfo.bech32AddressPrefix!==(0,P.fromBech32)(d).prefix){const $=fn(this.tools.chainData.chain_name,d);yield this.validateTransfer(d,i,$);const{channel:ve,port:z}=$;g=this.tools.methods.ibcTransfer({channel:ve,port:z,memo:l,amount:(0,v.coin)(h,y),fromAddress:this.walletInfo.keys.bech32Address,toAddress:d})}else g=this.tools.methods.transfer({amount:[(0,v.coin)(h,y)],fromAddress:this.walletInfo.keys.bech32Address,toAddress:d});let f,k,b;const w=`${d}${String(a)}`,B=this.feeCache.get(w);if(h==="0")f=(0,v.coin)("0",this.networkInfo.nativeDenom),k="0",b="0";else if(B==null){const $=yield this.calculateFee({messages:[g],memo:l,networkFeeOption:a});f=$.gasFeeCoin,k=$.gasLimit,b=$.networkFee,this.feeCache.set(w,$)}else f=B.gasFeeCoin,k=B.gasLimit,b=B.networkFee;const K=this.createUnsignedTxHex([g],l),_={gasFeeCoin:f,gasLimit:k,unsignedTxHex:K},H=this.makeEdgeTransactionAmounts(h,b,i);return this.checkBalances(H,i),{blockHeight:0,currencyCode:o,date:0,isSend:!0,memos:c,nativeAmount:H.nativeAmount,networkFee:H.networkFee,networkFees:[],otherParams:_,ourReceiveAddresses:[],parentNetworkFee:H.parentNetworkFee,signedTx:"",tokenId:i,txid:"",walletId:this.walletId}})}signMessage(n,t,r){return E(this,null,function*(){const s=(0,A.yu)(this.currencyInfo.pluginId)(t),o=yield this.tools.createSigner(s.mnemonic);if((r==null?void 0:r.otherParams)!=null)switch(r.otherParams.method){case"cosmos_getAccounts":{(0,A.yt)(r.otherParams);const f=(yield o.getAccounts()).map(k=>Ke(ue({},k),{pubkey:R.K3.stringify(k.pubkey)}));return JSON.stringify(f)}case"cosmos_signDirect":{const g=(0,A.S4)(r.otherParams),{signDoc:f}=g.params,k=L.SignDoc.fromPartial({accountNumber:(0,He.longify)(f.accountNumber),authInfoBytes:ae(f.authInfoBytes),bodyBytes:ae(f.bodyBytes),chainId:f.chainId}),w={signature:(yield o.signDirect(this.walletInfo.keys.bech32Address,k)).signature,signed:g.params.signDoc};return JSON.stringify(w)}case"cosmos_signAmino":{const g=(0,A.tV)(r.otherParams),{signDoc:f}=g.params,k=(0,M.makeSignDoc)(f.msgs,f.fee,f.chain_id,f.memo,f.account_number,f.sequence);mn(k);const{bech32AddressPrefix:b,bip39Path:w}=this.networkInfo,B=(0,j.stringToPath)(w),H={signature:(yield(yield M.Secp256k1HdWallet.fromMnemonic(o.mnemonic,{prefix:b,hdPaths:[B]})).signAmino(this.walletInfo.keys.bech32Address,k)).signature,signed:f};return JSON.stringify(H)}default:throw new Error(`Invalid method: ${r.method}`)}const c=R.xn.parse(n),a=L.SignDoc.decode(c),i=yield o.signDirect(this.walletInfo.keys.bech32Address,a),l=(0,M.decodeSignature)(i.signature),h=L.TxRaw.fromPartial({authInfoBytes:a.authInfoBytes,bodyBytes:a.bodyBytes,signatures:[l.signature]}),d=L.TxRaw.encode(h).finish();return R.xn.stringify(d)})}signTx(n,t){return E(this,null,function*(){const{gasFeeCoin:r,gasLimit:s,unsignedTxHex:o}=(0,A.TG)(n.otherParams),c=(0,A.yu)(this.currencyInfo.pluginId)(t),a=R.xn.parse(o),{bodyBytes:i}=L.TxRaw.decode(a),l=R.xn.parse(this.walletInfo.keys.publicKey),h=(0,M.encodeSecp256k1Pubkey)(l),d=(0,V.makeAuthInfoBytes)([{pubkey:(0,V.encodePubkey)(h),sequence:this.getSequence()}],[r],parseInt(s),void 0,void 0,1),y=L.SignDoc.fromPartial({accountNumber:(0,He.longify)(this.accountNumber),authInfoBytes:d,bodyBytes:i,chainId:this.chainId}),f=yield(yield this.tools.createSigner(c.mnemonic)).signDirect(this.walletInfo.keys.bech32Address,y),k=(0,M.decodeSignature)(f.signature),b=L.TxRaw.fromPartial({authInfoBytes:d,bodyBytes:i,signatures:[k.signature]}),w=L.TxRaw.encode(b).finish(),B=R.xn.stringify(w);return n.signedTx=B,n})}broadcastTx(n){return E(this,null,function*(){try{const t=R.xn.parse(n.signedTx),{stargateClient:r}=this.getClients(),s=yield r.broadcastTxSync(t);return this.warn(`SUCCESS broadcastTx
2
+ ${(0,x.T5)(n)}`),n.txid=s,n.date=Date.now()/1e3,this.addToUnconfirmedCache(s),n}catch(t){throw this.warn("FAILURE broadcastTx failed: ",t),t}})}getFreshAddress(n){return E(this,null,function*(){const{bech32Address:t}=this.walletInfo.keys;return{publicAddress:t}})}}function ze(e){return e.currencyInfo.pluginId==="thorchainrune"||e.currencyInfo.pluginId==="thorchainrunestagenet"}const zn=(0,u.eB)({result:(0,u.eB)({node_info:(0,u.eB)({network:u.oJ})})}),Qe=(0,u.eB)({address:u.oJ,coins:(0,u._j)((0,u.eB)({amount:u.oJ,asset:u.oJ})),txID:u.oJ}),Qn=(0,u.eB)({actions:(0,u._j)((0,u.eB)({date:u.oJ,height:u.oJ,in:(0,u._j)(Qe),metadata:(0,u.eB)((0,u.eB)({memo:u.oJ,networkFees:(0,u.H7)((0,u._j)((0,u.eB)({amount:u.oJ,asset:u.oJ})),()=>[])})),out:(0,u._j)(Qe)})),meta:(0,u.eB)({nextPageToken:u.oJ})}),Gn=(0,u.eB)({midgardTxQueryParams:(0,u.HS)((0,u.eB)({mostRecentHeight:u.oJ,mostRecentTxId:u.oJ}),()=>({mostRecentHeight:"0",mostRecentTxId:""}))}),Zn=(0,u.eB)({native_outbound_fee_rune:u.oJ,native_tx_fee_rune:u.oJ});var Xn=Object.defineProperty,Ge=Object.getOwnPropertySymbols,Yn=Object.getPrototypeOf,jn=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,nt=Reflect.get,Ze=(e,n,t)=>n in e?Xn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Xe=(e,n)=>{for(var t in n||(n={}))jn.call(n,t)&&Ze(e,t,n[t]);if(Ge)for(var t of Ge(n))et.call(n,t)&&Ze(e,t,n[t]);return e},tt=(e,n,t)=>nt(Yn(e),t,n),de=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});const ot=(0,ge.fi)(2e4);class pe extends ne{constructor(n,t,r,s){super(n,t,r,s),this.networkInfo=n.networkInfo}setOtherData(n){const t=(0,A.qd)(n),r=Gn(n);this.otherData=Xe(Xe({},t),r)}queryChainId(){return de(this,null,function*(){try{const n=yield this.fetchCors(this.networkInfo.chainIdUpdateUrl);if(!n.ok){const s=yield n.text();throw new Error(s)}const t=yield n.json(),r=zn(t);this.chainId=r.result.node_info.network,this.removeFromLoop("queryChainId")}catch(n){this.error("queryChainId Error ",n)}})}queryTransactions(){return de(this,null,function*(){const n=[this.currencyInfo.currencyCode,...this.enabledTokenIds.map(y=>this.allTokensMap[y].currencyCode)],{url:t,headers:r}=ie(this.networkInfo.midgardConnctionInfo,this.tools.initOptions),s=`${t}/v2/actions?address=${this.walletInfo.keys.bech32Address}`,{mostRecentHeight:o,mostRecentTxId:c}=this.otherData.midgardTxQueryParams,a=o;let i,l=o,h=c,d=!1;for(;;){try{const y=`&fromHeight=${a}`,g=i!=null?`&nextPageToken=${i}`:"",f=yield this.fetchCors(`${s}${y}${g}`,r);if(!f.ok){const w=yield f.text();throw new Error(w)}const k=yield f.json(),b=Qn(k);if(b.actions.length===0||b.meta.nextPageToken==="")break;i=b.meta.nextPageToken;for(const w of b.actions){l=(0,C.max)(l,w.height);const B=parseInt((0,C.div)(w.date,"1000000000")),{memo:K}=Object.values(w.metadata)[0];let _="";const H=[],q=(z,en)=>{for(const he of z){he.txID.length>_.length&&(_=he.txID);for(const nn of he.coins){const ht=en==="coin_received"?"receiver":"spender",tn=nn.asset.split(".")[1];tn!=null&&H.push({type:en,attributes:[{key:"amount",value:`${(0,C.abs)(nn.amount)}${tn.toLowerCase()}`},{key:ht,value:he.address}]})}}};if(q(w.in,"coin_spent"),q(w.out,"coin_received"),_===c){d=!0;break}h===c&&(h=_);let $=[];try{$=Te(H,this.walletInfo.keys.bech32Address)}catch(z){this.log.warn("reduceCoinEventsForAddress error:",String(z))}if($.length===0)continue;const ve={amount:[{denom:"rune",amount:"2000000"}],gasLimit:BigInt(0),payer:"",granter:""};$.forEach(z=>{this.processCosmosTransaction(_,B,"",z,K,parseInt(w.height),ve)})}}catch(y){this.log.warn("queryTransactionsMidgard error:",y)}if(d)break}(l!==o||h!==c)&&(this.otherData.midgardTxQueryParams.mostRecentHeight=l,this.otherData.midgardTxQueryParams.mostRecentTxId=h!=null?h:"",this.walletLocalDataDirty=!0),n.forEach(y=>this.tokenCheckTransactionsStatus[y]=1),this.updateOnAddressesChecked(),this.updateTransactionEvents()})}calculateFee(n){return de(this,null,function*(){const{url:t,headers:r}=ie(this.networkInfo.transactionFeeConnectionInfo,this.tools.initOptions),o=yield(yield this.fetchCors(t,{method:"GET",headers:r})).json(),c=Zn(o);let a="0";for(const i of n.messages)switch(i.typeUrl){case"/types.MsgDeposit":a=(0,C.add)(a,c.native_outbound_fee_rune);break;case"/types.MsgSend":a=(0,C.add)(a,c.native_tx_fee_rune)}return{gasFeeCoin:(0,v.coin)("1",this.networkInfo.nativeDenom),gasLimit:"60000000",networkFee:(0,C.mul)(a,"1.01")}})}startEngine(){return de(this,null,function*(){this.addToLoop("queryChainId",ot),yield tt(pe.prototype,this,"startEngine").call(this)})}}var rt=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});function st(e,n,t,r){return rt(this,null,function*(){const s=(0,A.r3)(t);console.debug("isThorchainEnvironment",ze(e));const o=ze(e)?new pe(e,n,s,r):new ne(e,n,s,r);return yield o.loadEngine(),o})}var it=p(48287).Buffer,Ye=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,lt=(e,n)=>{var t={};for(var r in e)at.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&Ye)for(var r of Ye(e))n.indexOf(r)<0&&ct.call(e,r)&&(t[r]=e[r]);return t},J=(e,n,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(l){s(l)}},c=i=>{try{a(t.throw(i))}catch(l){s(l)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,c);a((t=t.apply(e,n)).next())});class je{constructor(n){var t;const{builtinTokens:r,currencyInfo:s,initOptions:o,io:c,networkInfo:a}=n;this.io=c,this.currencyInfo=s,this.builtinTokens=r,this.networkInfo=a,this.initOptions=o,this.clientCount=0;const{methods:i,registry:l}=Nn(s.pluginId);this.methods=i,this.registry=l;const{chainName:h,url:d}=this.networkInfo.chainInfo,y=(t=Q.Bt.find(f=>f.chain_name===h&&f.network_type==="mainnet"))!=null?t:this.networkInfo.defaultChainData;if(y==null)throw new Error("Unknown chain");this.chainData=y;const g=new fe.wV;g.fetch(d).then(()=>{this.chainData=g.getChain(this.chainData.chain_name)}).catch(f=>{})}createSigner(n){return J(this,null,function*(){const{bech32AddressPrefix:t,bip39Path:r}=this.networkInfo,s=(0,j.stringToPath)(r);return yield V.DirectSecp256k1HdWallet.fromMnemonic(n,{hdPaths:[s],prefix:t})})}getDisplayPrivateKey(n){return J(this,null,function*(){const{pluginId:t}=this.currencyInfo;return(0,A.yu)(t)(n.keys).mnemonic})}getDisplayPublicKey(n){return J(this,null,function*(){const{keys:t}=(0,A.r3)(n);return t.publicKey})}importPrivateKey(n){return J(this,null,function*(){if(!(0,oe.validateMnemonic)(n))throw new Error("Invalid mnemonic");return yield this.createSigner(n),{[this.networkInfo.pluginMnemonicKeyName]:n}})}createPrivateKey(n){return J(this,null,function*(){if(n!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const t=it.from(this.io.random(32)),r=(0,oe.entropyToMnemonic)(t);return yield this.importPrivateKey(r)})}derivePublicKey(n){return J(this,null,function*(){if(n.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const{mnemonic:t}=(0,A.yu)(this.currencyInfo.pluginId)(n.keys),s=yield(yield this.createSigner(t)).getAccounts(),{address:o,pubkey:c}=s[0],a=R.xn.stringify(c);return{bech32Address:o,publicKey:a}})}isValidOurAddress(n){try{if((0,P.fromBech32)(n).prefix===this.networkInfo.bech32AddressPrefix)return!0}catch{}return!1}isValidTargetAddress(n){try{const t=(0,P.fromBech32)(n);if(Q.Bt.find(s=>s.bech32_prefix===t.prefix)!=null)return!0}catch{}return!1}parseUri(n,t,r){return J(this,null,function*(){const{pluginId:s}=this.currencyInfo,o={[s]:!0},{parsedUri:c,edgeParsedUri:a}=yield(0,re.x)({currencyInfo:this.currencyInfo,uri:n,networks:o,builtinTokens:this.builtinTokens,currencyCode:t!=null?t:this.currencyInfo.currencyCode,customTokens:r});let i="";if(a.publicAddress!=null&&(i=a.publicAddress),!this.isValidTargetAddress(i))throw new Error("InvalidPublicAddressError");return a.uniqueIdentifier=c.query.memo,a})}encodeUri(n){return J(this,arguments,function*(t,r=[]){const{pluginId:s}=this.currencyInfo,{nativeAmount:o,currencyCode:c,publicAddress:a}=t;if(!this.isValidOurAddress(a))throw new Error("InvalidPublicAddressError");let i;if(typeof o=="string"){const h=(0,x.FQ)(c!=null?c:this.currencyInfo.currencyCode,this.currencyInfo,r,this.builtinTokens);if(h==null)throw new Error("InternalErrorInvalidCurrencyCode");i=(0,C.div)(o,h.multiplier,18)}return(0,re.m)(t,s,i)})}connectClient(){return J(this,null,function*(){this.clients==null&&(this.clients=yield ke(this.io.fetchCors,ie(this.networkInfo.rpcNode,this.initOptions))),++this.clientCount})}disconnectClient(){return J(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 J(this,null,function*(){var t;(0,ee.k9)(n);const{contractAddress:r}=(t=(0,ee.oQ)(n.networkLocation))!=null?t:{},s=/^ibc\/[0-9A-F]{64}$/,o=/^(?!ibc)[a-z][a-z0-9/]{2,127}/;if(r==null||!s.test(r)&&!o.test(r))throw new Error("ErrorInvalidContractAddress");return r.toLowerCase().replace(/\//g,"")})}}function ut(e){return J(this,null,function*(){return new je(e)})}function dt(e,n){return J(this,null,function*(){const t=lt(n,[]);e.networkInfo=(0,x.wy)(e.networkInfo,t)})}},73776:function(){},77667:function(){},76447:function(){},15340:function(){},79838:function(){}}]);