@wormhole-foundation/wormhole-connect 0.3.14-beta.1-development → 0.3.14
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/dist/assets/{ccip-Df1X-Jsr.js → ccip-BJTvJhI5.js} +1 -1
- package/dist/assets/cosmos-mS8jzs-K.js +37 -0
- package/dist/assets/{cosmwasm-C3cFK7BC.js → cosmwasm-DGW772Mb.js} +3 -3
- package/dist/assets/{ens-validation.es6-gsmLKNwB.js → ens-validation.es6-QG6c_Puy.js} +1 -1
- package/dist/assets/{evm-BgK0PbdF.js → evm-DibVYhcH.js} +4 -4
- package/dist/assets/{index-BjIxvQFV.js → index-C1x31Jxk.js} +1 -1
- package/dist/assets/index-CP2t4FxN.js +3 -0
- package/dist/assets/{index-ByeOkyS8.js → index-CRnaWQgW.js} +1 -1
- package/dist/assets/{index-D93OVsl5.js → index-DIf-mzq7.js} +1 -1
- package/dist/assets/{index-CV4pfIw7.js → index-KMQj8MBB.js} +1 -1
- package/dist/assets/index-eblkOnb_.js +2 -0
- package/dist/assets/{index.es-B_34Y1D2.js → index.es-COHpKTWN.js} +2 -2
- package/dist/assets/{solana-Dn94-G2V.js → solana-BZCNALCU.js} +2 -2
- package/dist/assets/{solanaEmbed.esm-rqFDr9AX.js → solanaEmbed.esm-D0yWLEo-.js} +1 -1
- package/dist/assets/{unsignedTransaction-B08fN_UW.js → unsignedTransaction-D7VEWy8m.js} +1 -1
- package/dist/main.js +9 -9
- package/lib/{algorand-B_zsKIUB.js → algorand-CVFKJ49n.js} +1 -1
- package/lib/{algorand--METRir0.mjs → algorand-DlXOCG7s.mjs} +4 -4
- package/lib/{aptos-B6T-33BH.mjs → aptos-C0Pa8tPM.mjs} +1 -1
- package/lib/{aptos-DzrqvZYi.mjs → aptos-DNWaXEMs.mjs} +4 -4
- package/lib/{aptos-DUNhi8qI.js → aptos-DfMox9Nu.js} +2 -2
- package/lib/{aptos-QtEtA7ZW.js → aptos-JDPRMCdh.js} +1 -1
- package/lib/{browser-Bscopnix.js → browser-5NnkopSy.js} +1 -1
- package/lib/{browser-B85hfsEU.mjs → browser-ByPSU-Sm.mjs} +2 -2
- package/lib/{ccip-DZqWqGGu.mjs → ccip-DeNVdlP1.mjs} +1 -1
- package/lib/{ccip-B55tByf5.js → ccip-vhUwnCjN.js} +1 -1
- package/lib/{chain-DIeeymNu.mjs → chain-BqdQffpz.mjs} +1 -1
- package/lib/{chain-B6MIHCrl.js → chain-C453VbjW.js} +1 -1
- package/lib/{cosmos-COOa_hP3.mjs → cosmos-BnB7dpcl.mjs} +3 -3
- package/lib/{cosmos-xRQL5PyI.js → cosmos-Cvu7IxgR.js} +1 -1
- package/lib/{cosmwasm-BVs1dHVN.js → cosmwasm-CDJf683T.js} +2 -2
- package/lib/{cosmwasm-Bh_CxuU0.mjs → cosmwasm-CZWC0Vwt.mjs} +6 -6
- package/lib/{create-b6djXgrD.js → create-D65JDX7A.js} +1 -1
- package/lib/{create-CKAYk8Hy.mjs → create-D79R5wNC.mjs} +1 -1
- package/lib/{ens-validation.es6-BAjtkzn9.js → ens-validation.es6-CxdMEulM.js} +1 -1
- package/lib/{ens-validation.es6-D0ElLoC0.mjs → ens-validation.es6-HV5K8ymg.mjs} +2 -2
- package/lib/{evm-Dr1-QGmD.js → evm-Ab2vMhYN.js} +2 -2
- package/lib/{evm-C8LxJqN_.mjs → evm-BlTqB4gw.mjs} +6 -6
- package/lib/{evm-EvdBe0my.mjs → evm-Ct13feWV.mjs} +6 -6
- package/lib/{evm-5D2VwgNW.js → evm-Dq5MPtI4.js} +4 -4
- package/lib/{index-DbN-ha-V.mjs → index-26eawinA.mjs} +4 -4
- package/lib/{index-DG_qcbL3.mjs → index-4VRk-Zbs.mjs} +3 -3
- package/lib/{index-BXPXS8lw.mjs → index-B1lU9xI5.mjs} +4 -4
- package/lib/{index-DGMGnQ6C.js → index-B583w9fN.js} +1 -1
- package/lib/{index-CPREkxnM.js → index-BC1OqHuv.js} +1 -1
- package/lib/{index-CLNtNgN1.mjs → index-BGvHdvdt.mjs} +4 -4
- package/lib/{index-DXQ-8YfL.mjs → index-BTUOVer-.mjs} +1 -1
- package/lib/{index-glcRZoGf.js → index-BYykran7.js} +1 -1
- package/lib/{index-Cweb_Lro.js → index-Bge7ijdZ.js} +1 -1
- package/lib/{index-DBZxhVWH.mjs → index-BtSWBcda.mjs} +4 -4
- package/lib/{index-G5_KoOmK.mjs → index-BugYV_4o.mjs} +4 -4
- package/lib/{index-D64qU2ma.js → index-C2_AHiqv.js} +3 -3
- package/lib/{index-CpVPNCn9.mjs → index-CM0b-J8y.mjs} +4 -4
- package/lib/{index--POK_Qlp.js → index-CSAHzLNT.js} +1 -1
- package/lib/{index-__A2GcY6.mjs → index-CSkBcw-D.mjs} +4 -4
- package/lib/{index-Du-vQDoz.mjs → index-CTpAZ9nb.mjs} +4 -4
- package/lib/{index-BuQEehXi.mjs → index-CWl-BFJn.mjs} +5 -5
- package/lib/{index-rvGu6Fys.mjs → index-CY3avmpk.mjs} +1 -1
- package/lib/{index-BE9arVSK.mjs → index-CZytaOh1.mjs} +2 -2
- package/lib/index-Cb1Z6J_2.js +1 -0
- package/lib/{index-gYdFT0lD.mjs → index-CfUmBL7v.mjs} +4 -4
- package/lib/{index-4znO_pHu.mjs → index-CnCIIPXr.mjs} +4 -4
- package/lib/{index-DGdaLbCV.js → index-CyAgjXwe.js} +1 -1
- package/lib/{index-DYRRAKVv.js → index-D--mHvwl.js} +1 -1
- package/lib/{index-j3EW_9_6.mjs → index-D7fGdFWj.mjs} +2 -2
- package/lib/{index-C6ISUObD.js → index-DIllMluL.js} +1 -1
- package/lib/{index-DecMzlzN.js → index-DPjEn-UC.js} +1 -1
- package/lib/{index-CEtYJbRu.js → index-DUSDkJk5.js} +1 -1
- package/lib/{index-D1PGmOov.mjs → index-DXycTbzg.mjs} +22 -22
- package/lib/{index-EEtERwdP.mjs → index-DZikb8Np.mjs} +3 -3
- package/lib/{index-BGJMKya9.js → index-Dchl8cgJ.js} +1 -1
- package/lib/{index-is9YtL7L.js → index-De2z-VSE.js} +1 -1
- package/lib/{index-DAmhPblM.js → index-Dewf_228.js} +1 -1
- package/lib/{index-DC79se3K.js → index-DikhQw8s.js} +1 -1
- package/lib/{index-zpoXhgRJ.js → index-DkuY3vFZ.js} +1 -1
- package/lib/{index-Cp3rpTDm.mjs → index-Drto8TLk.mjs} +5 -5
- package/lib/{index-B5zmUJA4.js → index-DyTV2laN.js} +1 -1
- package/lib/{index-Bj7FiPmv.js → index-LNQRx_kM.js} +1 -1
- package/lib/{index-iUdRJ6rW.js → index-U-9k85Xq.js} +1 -1
- package/lib/{index-C1pDiBzJ.mjs → index-YfADnRfR.mjs} +2 -2
- package/lib/{index-SFmnxTYX.mjs → index-ZSB5WVTS.mjs} +5 -5
- package/lib/{index-bFnCEjGK.mjs → index-eYxUR3kF.mjs} +3 -3
- package/lib/{index-Bb9ALioa.js → index-l-pmNV8r.js} +1 -1
- package/lib/{index-BeJpXXCe.js → index-tlEJpVxO.js} +1 -1
- package/lib/{index-BaMCNLcV.mjs → index-xhF6pq52.mjs} +6 -6
- package/lib/{index-CoirRBt5.js → index-yqQlFROv.js} +1 -1
- package/lib/{index.es-ChbHiiWR.mjs → index.es-BhcayXFz.mjs} +4 -4
- package/lib/{index.es-B8LoJfDQ.js → index.es-lcQybjxw.js} +2 -2
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/lib/{libsodium-wrappers-Cb8uXs_p.mjs → libsodium-wrappers-BMyPhbfe.mjs} +1 -1
- package/lib/{libsodium-wrappers-CYhY_wpO.js → libsodium-wrappers-DiSaiZbZ.js} +1 -1
- package/lib/{sei-CmKJM62D.mjs → sei-De5wMBer.mjs} +2 -2
- package/lib/{sei-BJyT_MkO.js → sei-g10VEo2p.js} +1 -1
- package/lib/{solana-BqtzN83d.js → solana-6KbHNP3L.js} +1 -1
- package/lib/{solana-pegPJXF6.mjs → solana-DHrthY4V.mjs} +6 -6
- package/lib/{solana-B_4vzBx9.mjs → solana-DeE1Kc4R.mjs} +3 -3
- package/lib/{solana-CP2Ro3b6.js → solana-g2ChLShs.js} +2 -2
- package/lib/{solanaEmbed.esm-p2Maj0Kc.mjs → solanaEmbed.esm-BKfqpMHE.mjs} +2 -2
- package/lib/{solanaEmbed.esm-BZQhHixI.js → solanaEmbed.esm-CB-PWWDN.js} +1 -1
- package/lib/{sui-DEJMwoei.mjs → sui-AMfu49c6.mjs} +4 -4
- package/lib/{sui-DyMCY4Wo.js → sui-CqbULR3p.js} +1 -1
- package/lib/{sui-CnF64P2s.mjs → sui-DisgucwN.mjs} +1 -1
- package/lib/{sui-BE2FECKH.js → sui-iNn-cH44.js} +2 -2
- package/lib/{unsignedTransaction-cUSYQRUJ.mjs → unsignedTransaction-B7ANn3fF.mjs} +2 -2
- package/lib/{unsignedTransaction-ByICgBQh.js → unsignedTransaction-CXi-AC5w.js} +1 -1
- package/package.json +1 -1
- package/dist/assets/cosmos-O8tTKeuk.js +0 -37
- package/dist/assets/index-BoaPGnUb.js +0 -2
- package/dist/assets/index-Dqsfl0un.js +0 -3
- package/lib/index-C7oQpHNB.js +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var se = Object.defineProperty;
|
|
2
2
|
var oe = (s, e, t) => e in s ? se(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
3
|
var d = (s, e, t) => (oe(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { bG as T, cv as y, aC as _, bp as P, b5 as f, az as re, at as M, cw as Q, cx as ae, b4 as S, cy as ce, d as ie, cz as X, cA as C, cB as de, cC as Z, cD as pe, cE as ge, cF as J, c7 as ue, b_ as fe } from "./index-
|
|
5
|
-
import { s as l, A as N, a as le } from "./algorand
|
|
6
|
-
import { c as he } from "./create-
|
|
7
|
-
import { r as Ae } from "./chain-
|
|
4
|
+
import { bG as T, cv as y, aC as _, bp as P, b5 as f, az as re, at as M, cw as Q, cx as ae, b4 as S, cy as ce, d as ie, cz as X, cA as C, cB as de, cC as Z, cD as pe, cE as ge, cF as J, c7 as ue, b_ as fe } from "./index-DXycTbzg.mjs";
|
|
5
|
+
import { s as l, A as N, a as le } from "./algorand-DlXOCG7s.mjs";
|
|
6
|
+
import { c as he } from "./create-D79R5wNC.mjs";
|
|
7
|
+
import { r as Ae } from "./chain-BqdQffpz.mjs";
|
|
8
8
|
class ye {
|
|
9
9
|
constructor(e, t, o, n, r = !1) {
|
|
10
10
|
d(this, "transaction");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var Nt = Object.defineProperty;
|
|
2
2
|
var Dt = (s, e, t) => e in s ? Nt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
3
|
var Z = (s, e, t) => (Dt(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { n as b, aH as C, aI as p, aJ as y, aK as U, aL as T, aM as X, aN as ae, aO as H, aP as st, aQ as j, a2 as W, aF as Ae, aG as qe, aR as he, aS as Wt, aT as zt, aU as Lt, aV as Ut, aW as Ft, cb as Ve, c9 as qt, ca as Vt, ce as rt, d as se, cj as He, c1 as at, at as Ht, c2 as je, c0 as jt, c3 as Ge } from "./index-
|
|
5
|
-
import { r as Gt } from "./chain-
|
|
6
|
-
import { a as xe, S as $t, b as Jt, _ as Xt } from "./solana-
|
|
4
|
+
import { n as b, aH as C, aI as p, aJ as y, aK as U, aL as T, aM as X, aN as ae, aO as H, aP as st, aQ as j, a2 as W, aF as Ae, aG as qe, aR as he, aS as Wt, aT as zt, aU as Lt, aV as Ut, aW as Ft, cb as Ve, c9 as qt, ca as Vt, ce as rt, d as se, cj as He, c1 as at, at as Ht, c2 as je, c0 as jt, c3 as Ge } from "./index-DXycTbzg.mjs";
|
|
5
|
+
import { r as Gt } from "./chain-BqdQffpz.mjs";
|
|
6
|
+
import { a as xe, S as $t, b as Jt, _ as Xt } from "./solana-DHrthY4V.mjs";
|
|
7
7
|
import { c as it } from "./index-DpFNxVts.mjs";
|
|
8
8
|
class Yt extends TypeError {
|
|
9
9
|
constructor(e, t) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
2
|
var h = (i, e, t) => e in i ? d(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
3
|
var o = (i, e, t) => (h(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
import { bp as w, au as p, at as g } from "./index-
|
|
5
|
-
import { A as u } from "./aptos-
|
|
6
|
-
import { c as l } from "./create-
|
|
7
|
-
import { r as f } from "./chain-
|
|
4
|
+
import { bp as w, au as p, at as g } from "./index-DXycTbzg.mjs";
|
|
5
|
+
import { A as u } from "./aptos-DNWaXEMs.mjs";
|
|
6
|
+
import { c as l } from "./create-D79R5wNC.mjs";
|
|
7
|
+
import { r as f } from "./chain-BqdQffpz.mjs";
|
|
8
8
|
class c {
|
|
9
9
|
constructor(e, t, r, s) {
|
|
10
10
|
o(this, "network");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var R=(T,n,e)=>n in T?U(T,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):T[n]=e;var A=(T,n,e)=>(R(T,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index-Bb9ALioa.js"),t=require("./index-D64qU2ma.js"),c=require("./algorand-B_zsKIUB.js"),q=require("./chain-B6MIHCrl.js"),W=t.ABIMethod.fromSignature("portal_transfer(byte[])byte[]"),g=class g{constructor(n,e,r,s){A(this,"network");A(this,"chain");A(this,"connection");A(this,"contracts");A(this,"chainId");A(this,"coreBridge");A(this,"coreAppId");A(this,"coreAppAddress");A(this,"tokenBridgeAppId");A(this,"tokenBridgeAddress");if(this.network=n,this.chain=e,this.connection=r,this.contracts=s,this.chainId=t.toChainId(e),!s.coreBridge)throw new Error(`Core contract address for chain ${e} not found`);const i=BigInt(s.coreBridge);if(this.coreAppId=i,this.coreAppAddress=t.getApplicationAddress(i),this.coreBridge=new p.AlgorandWormholeCore(n,e,r,s),!s.tokenBridge)throw new Error(`TokenBridge contract address for chain ${e} not found`);const a=BigInt(s.tokenBridge);this.tokenBridgeAppId=a,this.tokenBridgeAddress=t.getApplicationAddress(a)}static async fromRpc(n,e){const[r,s]=await c.AlgorandPlatform.chainFromRpc(n),i=e[s];if(i.network!==r)throw new Error(`Network mismatch: ${i.network} != ${r}`);return new g(r,s,n,i.contracts)}async isWrappedAsset(n){const e=new c.AlgorandAddress(n).toInt();if(e===0)return!1;const r=await this.connection.getAssetByID(e).do(),i=t.Asset.from_obj_for_encoding(r).params.creator,a=await this.connection.accountInformation(i).exclude("all").do(),o=t.Account.from_obj_for_encoding(a);return(o==null?void 0:o.authAddr)===this.tokenBridgeAddress}async getOriginalAsset(n){const e=new c.AlgorandAddress(n).toInt(),r=await this.connection.getAssetByID(e).do(),s=t.Asset.from_obj_for_encoding(r),i=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,s.params.creator);if(i.length<94)throw new Error("Invalid local state data");const a=i.slice(92,94),o=t.toChain(t.bignum.decode(a)),l=new t.UniversalAddress(i.slice(60,92));return{chain:o,address:l}}async getWrappedAsset(n){const e=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,n),r=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,e.address());if(r.length<8)throw new Error("Invalid wrapped asset data");return t.toNative(this.chain,t.bignum.decode(r.slice(0,8)).toString())}async hasWrappedAsset(n){try{return await this.getWrappedAsset(n),!0}catch{}return!1}async getWrappedNative(){return t.toNative(this.chain,"0")}async isTransferCompleted(n){const e=p.StorageLogicSig.forMessageId(this.tokenBridgeAppId,{sequence:n.sequence,chain:n.emitterChain,emitter:n.emitterAddress});try{return await p.StorageLogicSig.checkBitsSet(this.connection,this.tokenBridgeAppId,e.address(),n.sequence)}catch{}return!1}async*createAttestation(n,e){if(!e)throw new Error("Payer required to create attestation");const r=new c.AlgorandAddress(e).toString(),s=new c.AlgorandAddress(n).toInt(),i=[],a=await this.connection.getTransactionParams().do(),o=p.StorageLogicSig.forEmitter(this.coreAppId,new c.AlgorandAddress(this.tokenBridgeAddress).toUint8Array()),{accounts:[l],txs:x}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,r,this.coreAppId,o,a);i.push(...x);let f="",d;if(s!==0){const I=await this.connection.getAssetByID(s).do(),S=t.Asset.from_obj_for_encoding(I),C=await this.connection.accountInformation(S.params.creator).do();if(d=t.Account.from_obj_for_encoding(C),d.authAddr===this.tokenBridgeAddress.toString())throw new Error("Cannot re-attest wormhole assets")}const w=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,BigInt(s)),k=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,r,this.tokenBridgeAppId,w);f=k.accounts[0],i.push(...k.txs);const u=t.makeApplicationCallTxnFromObject({from:r,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.noop],suggestedParams:a});i.push({tx:u});const m=await this.coreBridge.getMessageFee();if(m>BigInt(0)){const I=t.makePaymentTxnWithSuggestedParamsFromObject({from:r,suggestedParams:a,to:this.tokenBridgeAddress,amount:m});i.push({tx:I})}let b=[l,f,this.coreAppAddress];d&&b.push(d.address);let h=t.makeApplicationCallTxnFromObject({appArgs:[g.attestToken,t.bignum.toBytes(s,8)],accounts:b,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignApps:[c.safeBigIntToNumber(this.coreAppId)],foreignAssets:[s],from:r,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:a});m>BigInt(0)?h.fee*=3:h.fee*=2,i.push({tx:h});for(const I of i)yield this.createUnsignedTx(I,"TokenBridge.createAttestation",!0)}async*submitAttestation(n,e,r){if(!e)throw new Error("Sender required to submit attestation");r||(r=await this.connection.getTransactionParams().do());const s=e.toString(),a=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,n.payload.token).address(),o=[],l=[],x=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,a);x.length>8&&l.push(new c.AlgorandAddress(x.slice(0,8)).toInt()),o.push({tx:t.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:a,amount:1e5,suggestedParams:r})});let f=new Uint8Array(1);f[0]=1,o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[g.noop,f],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),f=new Uint8Array(1),f[0]=2,o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[g.noop,f],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),o.push({tx:t.makeApplicationCallTxnFromObject({accounts:[],appArgs:[g.receiveAttest,t.serialize(n)],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignAssets:l,from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),o[o.length-1].tx.fee=o[o.length-1].tx.fee*2;for(const d of o)yield this.createUnsignedTx(d,"TokenBridge.submitAttestation",!0)}async*transfer(n,e,r,s,i){const a=n.toString(),o=t.isNative(r)?0:new c.AlgorandAddress(r).toInt(),l=s,x=t.toChainId(e.chain),f=e.address.toUniversalAddress().toUint8Array(),d=await this.connection.getTransactionParams().do(),w=BigInt(0),k=p.StorageLogicSig.fromData({appId:this.coreAppId,appAddress:t.decodeAddress(this.coreAppAddress).publicKey,idx:BigInt(0),address:t.decodeAddress(this.tokenBridgeAddress).publicKey}),u=[],{accounts:[m],txs:b}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,a,this.coreAppId,k,d);u.push(...b);let h="",I,S=!1;if(o!==0){const B=await this.connection.getAssetByID(o).do();h=t.Asset.from_obj_for_encoding(B).params.creator;const O=await this.connection.accountInformation(h).do();I=t.Account.from_obj_for_encoding(O),S=I.authAddr===this.tokenBridgeAddress.toString()}const C=await this.coreBridge.getMessageFee();if(C>0&&u.push({tx:t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:this.tokenBridgeAddress,amount:C,suggestedParams:d})}),!S){const B=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,BigInt(o)),{accounts:[y],txs:O}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,a,this.tokenBridgeAppId,B,d);h=y,O.push(...O)}if(o!==0&&!await g.isOptedInToAsset(this.connection,h,o)){const B=t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:h,amount:1e5,suggestedParams:d});let y=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.optIn,t.bigIntToBytes(o,8)],foreignAssets:[o],accounts:[h],suggestedParams:d});y.fee*=2,u.unshift({tx:B},{tx:y})}const P=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.noop],suggestedParams:d});u.push({tx:P});let j=[];if(o===0){const B=t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:h,amount:l,suggestedParams:d});u.push({tx:B}),j=[m,h,h]}else{const B=t.makeAssetTransferTxnWithSuggestedParamsFromObject({from:a,to:h,amount:l,assetIndex:o,suggestedParams:d});u.push({tx:B}),j=I!=null&&I.address?[m,h,I.address]:[m,h]}const F=[g.sendTransfer,t.bignum.toBytes(o,8),t.bignum.toBytes(l,8),f,t.bignum.toBytes(x,8),t.bignum.toBytes(w,8)];i&&F.push(i);const L=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:F,foreignApps:[c.safeBigIntToNumber(this.coreAppId)],foreignAssets:[o],accounts:j,suggestedParams:d});L.fee*=2,u.push({tx:L});for(const B of u)yield this.createUnsignedTx(B,"TokenBridge.transfer",!0)}async*redeem(n,e,r=!0,s){s||(s=await this.connection.getTransactionParams().do());const i=new c.AlgorandAddress(n).toString(),{accounts:a,txs:o}=await p.AlgorandWormholeCore.submitVAAHeader(this.connection,this.coreAppId,this.tokenBridgeAppId,e,i);let l,x="",f=[],d=0;if(e.payload.token.chain!==this.chain){l=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,e.payload.token),x=l.address();const m=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,x);d=new c.AlgorandAddress(m.slice(0,8)).toInt()}else{const m=new c.AlgorandAddress(e.payload.token.address).toBigInt();l=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,m),x=l.address(),d=c.safeBigIntToNumber(m)}a.push(x);let w=0,k="";if(e.payloadName==="TransferWithPayload"?(w=new c.AlgorandAddress(e.payload.to.address).toInt(),k=t.getApplicationAddress(w)):k=new c.AlgorandAddress(e.payload.to.address.toUint8Array()).toString(),a.push(k),d!==0&&(f.push(d),!await g.isOptedInToAsset(this.connection,k,d))){if(i!=k)throw new Error("Cannot ASA optin for somebody else (asset "+d.toString()+")");o.unshift({tx:t.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:0,assetIndex:d,from:i,suggestedParams:s,to:i})})}const u={accounts:a,appArgs:[g.completeTransfer,t.serialize(e)],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignAssets:f,from:i,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:s};o.push({tx:t.makeApplicationCallTxnFromObject(u)}),o[o.length-1].tx.fee=o[o.length-1].tx.fee*(e.payloadName==="Transfer"&&e.payload.fee!==void 0&&e.payload.fee===0n?2:3),e.payloadName==="TransferWithPayload"&&(o[o.length-1].tx.appForeignApps=[w],o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[W.getSelector(),W.args[0].type.encode(t.serialize(e))],appIndex:w,foreignAssets:f,from:i,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:s})}));for(const m of o)yield this.createUnsignedTx(m,"TokenBridge.redeem",!0)}static async isOptedInToAsset(n,e,r){var s;try{const i=await n.accountAssetInformation(e,r).do();return(((s=t.AccountAssetResponse.from_obj_for_encoding(i).assetHolding)==null?void 0:s.amount)??0)>0}catch{}return!1}createUnsignedTx(n,e,r=!0){return new p.AlgorandUnsignedTransaction(n,this.network,this.chain,e,r)}};A(g,"sendTransfer",t.bytes.encode("sendTransfer")),A(g,"attestToken",t.bytes.encode("attestToken")),A(g,"noop",t.bytes.encode("nop")),A(g,"optIn",t.bytes.encode("optin")),A(g,"completeTransfer",t.bytes.encode("completeTransfer")),A(g,"receiveAttest",t.bytes.encode("receiveAttest"));let N=g;q.registerProtocol(c._platform,"TokenBridge",N);exports.AlgorandTokenBridge=N;exports.TransferMethodSelector=W;
|
|
1
|
+
"use strict";var U=Object.defineProperty;var R=(T,n,e)=>n in T?U(T,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):T[n]=e;var A=(T,n,e)=>(R(T,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./index-l-pmNV8r.js"),t=require("./index-C2_AHiqv.js"),c=require("./algorand-CVFKJ49n.js"),q=require("./chain-C453VbjW.js"),W=t.ABIMethod.fromSignature("portal_transfer(byte[])byte[]"),g=class g{constructor(n,e,r,s){A(this,"network");A(this,"chain");A(this,"connection");A(this,"contracts");A(this,"chainId");A(this,"coreBridge");A(this,"coreAppId");A(this,"coreAppAddress");A(this,"tokenBridgeAppId");A(this,"tokenBridgeAddress");if(this.network=n,this.chain=e,this.connection=r,this.contracts=s,this.chainId=t.toChainId(e),!s.coreBridge)throw new Error(`Core contract address for chain ${e} not found`);const i=BigInt(s.coreBridge);if(this.coreAppId=i,this.coreAppAddress=t.getApplicationAddress(i),this.coreBridge=new p.AlgorandWormholeCore(n,e,r,s),!s.tokenBridge)throw new Error(`TokenBridge contract address for chain ${e} not found`);const a=BigInt(s.tokenBridge);this.tokenBridgeAppId=a,this.tokenBridgeAddress=t.getApplicationAddress(a)}static async fromRpc(n,e){const[r,s]=await c.AlgorandPlatform.chainFromRpc(n),i=e[s];if(i.network!==r)throw new Error(`Network mismatch: ${i.network} != ${r}`);return new g(r,s,n,i.contracts)}async isWrappedAsset(n){const e=new c.AlgorandAddress(n).toInt();if(e===0)return!1;const r=await this.connection.getAssetByID(e).do(),i=t.Asset.from_obj_for_encoding(r).params.creator,a=await this.connection.accountInformation(i).exclude("all").do(),o=t.Account.from_obj_for_encoding(a);return(o==null?void 0:o.authAddr)===this.tokenBridgeAddress}async getOriginalAsset(n){const e=new c.AlgorandAddress(n).toInt(),r=await this.connection.getAssetByID(e).do(),s=t.Asset.from_obj_for_encoding(r),i=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,s.params.creator);if(i.length<94)throw new Error("Invalid local state data");const a=i.slice(92,94),o=t.toChain(t.bignum.decode(a)),l=new t.UniversalAddress(i.slice(60,92));return{chain:o,address:l}}async getWrappedAsset(n){const e=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,n),r=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,e.address());if(r.length<8)throw new Error("Invalid wrapped asset data");return t.toNative(this.chain,t.bignum.decode(r.slice(0,8)).toString())}async hasWrappedAsset(n){try{return await this.getWrappedAsset(n),!0}catch{}return!1}async getWrappedNative(){return t.toNative(this.chain,"0")}async isTransferCompleted(n){const e=p.StorageLogicSig.forMessageId(this.tokenBridgeAppId,{sequence:n.sequence,chain:n.emitterChain,emitter:n.emitterAddress});try{return await p.StorageLogicSig.checkBitsSet(this.connection,this.tokenBridgeAppId,e.address(),n.sequence)}catch{}return!1}async*createAttestation(n,e){if(!e)throw new Error("Payer required to create attestation");const r=new c.AlgorandAddress(e).toString(),s=new c.AlgorandAddress(n).toInt(),i=[],a=await this.connection.getTransactionParams().do(),o=p.StorageLogicSig.forEmitter(this.coreAppId,new c.AlgorandAddress(this.tokenBridgeAddress).toUint8Array()),{accounts:[l],txs:x}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,r,this.coreAppId,o,a);i.push(...x);let f="",d;if(s!==0){const I=await this.connection.getAssetByID(s).do(),S=t.Asset.from_obj_for_encoding(I),C=await this.connection.accountInformation(S.params.creator).do();if(d=t.Account.from_obj_for_encoding(C),d.authAddr===this.tokenBridgeAddress.toString())throw new Error("Cannot re-attest wormhole assets")}const w=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,BigInt(s)),k=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,r,this.tokenBridgeAppId,w);f=k.accounts[0],i.push(...k.txs);const u=t.makeApplicationCallTxnFromObject({from:r,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.noop],suggestedParams:a});i.push({tx:u});const m=await this.coreBridge.getMessageFee();if(m>BigInt(0)){const I=t.makePaymentTxnWithSuggestedParamsFromObject({from:r,suggestedParams:a,to:this.tokenBridgeAddress,amount:m});i.push({tx:I})}let b=[l,f,this.coreAppAddress];d&&b.push(d.address);let h=t.makeApplicationCallTxnFromObject({appArgs:[g.attestToken,t.bignum.toBytes(s,8)],accounts:b,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignApps:[c.safeBigIntToNumber(this.coreAppId)],foreignAssets:[s],from:r,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:a});m>BigInt(0)?h.fee*=3:h.fee*=2,i.push({tx:h});for(const I of i)yield this.createUnsignedTx(I,"TokenBridge.createAttestation",!0)}async*submitAttestation(n,e,r){if(!e)throw new Error("Sender required to submit attestation");r||(r=await this.connection.getTransactionParams().do());const s=e.toString(),a=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,n.payload.token).address(),o=[],l=[],x=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,a);x.length>8&&l.push(new c.AlgorandAddress(x.slice(0,8)).toInt()),o.push({tx:t.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:a,amount:1e5,suggestedParams:r})});let f=new Uint8Array(1);f[0]=1,o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[g.noop,f],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),f=new Uint8Array(1),f[0]=2,o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[g.noop,f],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),o.push({tx:t.makeApplicationCallTxnFromObject({accounts:[],appArgs:[g.receiveAttest,t.serialize(n)],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignAssets:l,from:s,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:r})}),o[o.length-1].tx.fee=o[o.length-1].tx.fee*2;for(const d of o)yield this.createUnsignedTx(d,"TokenBridge.submitAttestation",!0)}async*transfer(n,e,r,s,i){const a=n.toString(),o=t.isNative(r)?0:new c.AlgorandAddress(r).toInt(),l=s,x=t.toChainId(e.chain),f=e.address.toUniversalAddress().toUint8Array(),d=await this.connection.getTransactionParams().do(),w=BigInt(0),k=p.StorageLogicSig.fromData({appId:this.coreAppId,appAddress:t.decodeAddress(this.coreAppAddress).publicKey,idx:BigInt(0),address:t.decodeAddress(this.tokenBridgeAddress).publicKey}),u=[],{accounts:[m],txs:b}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,a,this.coreAppId,k,d);u.push(...b);let h="",I,S=!1;if(o!==0){const B=await this.connection.getAssetByID(o).do();h=t.Asset.from_obj_for_encoding(B).params.creator;const O=await this.connection.accountInformation(h).do();I=t.Account.from_obj_for_encoding(O),S=I.authAddr===this.tokenBridgeAddress.toString()}const C=await this.coreBridge.getMessageFee();if(C>0&&u.push({tx:t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:this.tokenBridgeAddress,amount:C,suggestedParams:d})}),!S){const B=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,BigInt(o)),{accounts:[y],txs:O}=await p.AlgorandWormholeCore.maybeCreateStorageTx(this.connection,a,this.tokenBridgeAppId,B,d);h=y,O.push(...O)}if(o!==0&&!await g.isOptedInToAsset(this.connection,h,o)){const B=t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:h,amount:1e5,suggestedParams:d});let y=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.optIn,t.bigIntToBytes(o,8)],foreignAssets:[o],accounts:[h],suggestedParams:d});y.fee*=2,u.unshift({tx:B},{tx:y})}const P=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:[g.noop],suggestedParams:d});u.push({tx:P});let j=[];if(o===0){const B=t.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:h,amount:l,suggestedParams:d});u.push({tx:B}),j=[m,h,h]}else{const B=t.makeAssetTransferTxnWithSuggestedParamsFromObject({from:a,to:h,amount:l,assetIndex:o,suggestedParams:d});u.push({tx:B}),j=I!=null&&I.address?[m,h,I.address]:[m,h]}const F=[g.sendTransfer,t.bignum.toBytes(o,8),t.bignum.toBytes(l,8),f,t.bignum.toBytes(x,8),t.bignum.toBytes(w,8)];i&&F.push(i);const L=t.makeApplicationCallTxnFromObject({from:a,appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),onComplete:t.OnApplicationComplete.NoOpOC,appArgs:F,foreignApps:[c.safeBigIntToNumber(this.coreAppId)],foreignAssets:[o],accounts:j,suggestedParams:d});L.fee*=2,u.push({tx:L});for(const B of u)yield this.createUnsignedTx(B,"TokenBridge.transfer",!0)}async*redeem(n,e,r=!0,s){s||(s=await this.connection.getTransactionParams().do());const i=new c.AlgorandAddress(n).toString(),{accounts:a,txs:o}=await p.AlgorandWormholeCore.submitVAAHeader(this.connection,this.coreAppId,this.tokenBridgeAppId,e,i);let l,x="",f=[],d=0;if(e.payload.token.chain!==this.chain){l=p.StorageLogicSig.forWrappedAsset(this.tokenBridgeAppId,e.payload.token),x=l.address();const m=await p.StorageLogicSig.decodeLocalState(this.connection,this.tokenBridgeAppId,x);d=new c.AlgorandAddress(m.slice(0,8)).toInt()}else{const m=new c.AlgorandAddress(e.payload.token.address).toBigInt();l=p.StorageLogicSig.forNativeAsset(this.tokenBridgeAppId,m),x=l.address(),d=c.safeBigIntToNumber(m)}a.push(x);let w=0,k="";if(e.payloadName==="TransferWithPayload"?(w=new c.AlgorandAddress(e.payload.to.address).toInt(),k=t.getApplicationAddress(w)):k=new c.AlgorandAddress(e.payload.to.address.toUint8Array()).toString(),a.push(k),d!==0&&(f.push(d),!await g.isOptedInToAsset(this.connection,k,d))){if(i!=k)throw new Error("Cannot ASA optin for somebody else (asset "+d.toString()+")");o.unshift({tx:t.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:0,assetIndex:d,from:i,suggestedParams:s,to:i})})}const u={accounts:a,appArgs:[g.completeTransfer,t.serialize(e)],appIndex:c.safeBigIntToNumber(this.tokenBridgeAppId),foreignAssets:f,from:i,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:s};o.push({tx:t.makeApplicationCallTxnFromObject(u)}),o[o.length-1].tx.fee=o[o.length-1].tx.fee*(e.payloadName==="Transfer"&&e.payload.fee!==void 0&&e.payload.fee===0n?2:3),e.payloadName==="TransferWithPayload"&&(o[o.length-1].tx.appForeignApps=[w],o.push({tx:t.makeApplicationCallTxnFromObject({appArgs:[W.getSelector(),W.args[0].type.encode(t.serialize(e))],appIndex:w,foreignAssets:f,from:i,onComplete:t.OnApplicationComplete.NoOpOC,suggestedParams:s})}));for(const m of o)yield this.createUnsignedTx(m,"TokenBridge.redeem",!0)}static async isOptedInToAsset(n,e,r){var s;try{const i=await n.accountAssetInformation(e,r).do();return(((s=t.AccountAssetResponse.from_obj_for_encoding(i).assetHolding)==null?void 0:s.amount)??0)>0}catch{}return!1}createUnsignedTx(n,e,r=!0){return new p.AlgorandUnsignedTransaction(n,this.network,this.chain,e,r)}};A(g,"sendTransfer",t.bytes.encode("sendTransfer")),A(g,"attestToken",t.bytes.encode("attestToken")),A(g,"noop",t.bytes.encode("nop")),A(g,"optIn",t.bytes.encode("optin")),A(g,"completeTransfer",t.bytes.encode("completeTransfer")),A(g,"receiveAttest",t.bytes.encode("receiveAttest"));let N=g;q.registerProtocol(c._platform,"TokenBridge",N);exports.AlgorandTokenBridge=N;exports.TransferMethodSelector=W;
|