"use strict";var _=Object.defineProperty;var v=(a,n,o)=>n in a?_(a,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[n]=o;var m=(a,n,o)=>v(a,typeof n!="symbol"?n+"":n,o);const t=require("./index-CDGktAjP.js");class h extends t.ChainContext{}const l=class l extends t.PlatformContext{constructor(n,o){super(n,o??t.networkPlatformConfigs(n,l._platform))}getRpc(n){if(n in this.config)return new t.algosdk.Algodv2("",this.config[n].rpc);throw new Error("No configuration available for chain: "+n)}getChain(n){if(n in this.config)return new h(n,this);throw new Error("No configuration available for chain: "+n)}static nativeTokenId(n,o){if(!l.isSupportedChain(o))throw new Error(`invalid chain for Algorand: ${o}`);return t.Wormhole.chainAddress(o,t.AlgorandZeroAddress)}static isNativeTokenId(n,o,s){return!l.isSupportedChain(o)||s.chain!==o?!1:this.nativeTokenId(n,o)==s}static isSupportedChain(n){return t.chainToPlatform(n)===l._platform}static async getDecimals(n,o,s){const r=t.isNative(s)?0:new t.AlgorandAddress(s).toInt();if(r===0)return t.nativeDecimals(l._platform);const d=await o.getAssetByID(r).do(),i=t.algosdk.modelsv2.Asset.from_obj_for_encoding(d);if(!i.params||!i.params.decimals)throw new Error("Could not fetch token details");return Number(i.params.decimals)}static async getBalance(n,o,s,r){const d=t.isNative(r)?0:new t.AlgorandAddress(r).toInt();if(d===0){const c=await o.accountInformation(s).do(),u=t.algosdk.modelsv2.Account.from_obj_for_encoding(c);return BigInt(u.amount)}const i=await o.accountAssetInformation(s,d).do(),e=t.algosdk.modelsv2.AssetHolding.from_obj_for_encoding(i);return BigInt(e.amount)}static async getBalances(n,o,s,r){let d;if(r.includes("native")){const e=await o.accountInformation(s).do(),c=t.algosdk.modelsv2.Account.from_obj_for_encoding(e);d=BigInt(c.amount)}return r.map(async e=>{if(t.isNative(e))return{native:d};const c=new t.AlgorandAddress(e).toInt(),u=await o.accountAssetInformation(s,c).do(),g=t.algosdk.modelsv2.AssetHolding.from_obj_for_encoding(u);return BigInt(g.amount)}).reduce((e,c)=>Object.assign(e,c),{})}static async sendWait(n,o,s){const i=s.map((g,p)=>t.algosdk.decodeSignedTransaction(g)).map((g,p)=>g.txn.txID()),{txId:e}=await o.sendRawTransaction(s).do();if(!e)throw new Error("Transaction(s) failed to send");const c=await t.algosdk.waitForConfirmation(o,e,4);if(!t.algosdk.modelsv2.PendingTransactionResponse.from_obj_for_encoding(c).confirmedRound)throw new Error("Transaction(s) could not be confirmed in 4 rounds");return i}static async getLatestBlock(n){const o=await n.status().do(),s=t.algosdk.modelsv2.NodeStatusResponse.from_obj_for_encoding(o);if(!s.lastRound)throw new Error("Error getting status from node");return Number(s.lastRound)}static async getLatestFinalizedBlock(n){const o=await n.status().do(),s=t.algosdk.modelsv2.NodeStatusResponse.from_obj_for_encoding(o);if(!s.lastRound)throw new Error("Error getting status from node");return Number(s.lastRound)}static chainFromChainId(n){const o=t.platformNativeChainIdToNetworkChain(l._platform,n);if(o===void 0)throw new Error(`Unknown native chain id ${n}`);const[s,r]=o;return[s,r]}static async chainFromRpc(n){const o=await n.versionsCheck().do(),s=t.algosdk.modelsv2.Version.from_obj_for_encoding(o);return this.chainFromChainId(s.genesisId)}};m(l,"_platform",t._platform$4);let f=l;async function I(a,n){const[o,s]=await f.chainFromRpc(a);return new A(s,a,n)}class A{constructor(n,o,s,r=!1){m(this,"_chain");m(this,"_debug");m(this,"_account");this._chain=n,this._debug=r,this._account=t.mnemonicToSecretKey(s)}chain(){return this._chain}address(){return this._account.addr}async sign(n){const o=[],s=n.map((i,e)=>i.transaction.tx),r=t.assignGroupID(s),d=n.map((i,e)=>(i.transaction.tx=r[e],i));for(const i of d){const{description:e,transaction:c}=i,{tx:u,signer:g}=c;this._debug&&(console.log(u._getDictForDisplay()),console.log(u.txID())),g?(this._debug&&console.log(`Signing: ${e} with signer ${g.address} for address ${this.address()}`),o.push(await g.signTxn(u))):(this._debug&&console.log(`Signing: ${e} without signer for address ${this.address()}`),o.push(u.signTxn(this._account.sk)))}return o}}const b={Address:t.AlgorandAddress,Platform:f,getSigner:I,protocols:{WormholeCore:()=>Promise.resolve().then(()=>require("./index-CaFGZvKm.js")).then(a=>a.index),TokenBridge:()=>Promise.resolve().then(()=>require("./index-BwCIDEBK.js"))},getChain:(a,n,o)=>new h(n,new f(a,t.applyChainsConfigConfigOverrides(a,t._platform$4,{[n]:o})))},x=Object.freeze(Object.defineProperty({__proto__:null,default:b},Symbol.toStringTag,{value:"Module"}));exports.AlgorandPlatform=f;exports.algorand=x;
