diff --git a/docs/main.js b/docs/main.js index c683c47..e6ea876 100644 --- a/docs/main.js +++ b/docs/main.js @@ -1015,4 +1015,4 @@ color: ${e=>e.theme.colors.text.secondary}; `,Tc=Cr(Yn)` margin-top: 32px; -`,Oc=e=>{const t=Gn(e),r=nt(Bs),[n,i]=Ze(!0);let o;(null==r?void 0:r.wallet)&&"universalLink"in r.wallet&&("universal-link"===r.wallet.openMethod||L(r.wallet.universalLink)&&On())&&(o=r.wallet.universalLink);const s=()=>{const e=Jr(),t="returnStrategy"in e?e.returnStrategy:Ga.returnStrategy;if(L(o)){const r=!n();i(!1),El(o,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Ga.twaReturnUrl,forceRedirect:r})}else Tr(Bl(o,t))};return kt(Ic,Bt(t,{get children(){return[Qe((()=>e.icon)),kt(Uc,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),kt(Mc,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),kt(It,{get when(){return"open-wallet"!==e.showButton},get children(){return kt(Tc,{onClick:()=>e.onClose(),get children(){return kt(Sl,{translationKey:"common.close",children:"Close"})}})}}),kt(It,{get when(){return"open-wallet"===e.showButton&&o},get children(){return kt(Tc,{onClick:s,get children(){return kt(Sl,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}}))},Rc=e=>{const t=nt(Bs),[r]=Gi();return kt(Oc,{headerTranslationKey:"actionModal.confirmTransaction.header",get headerTranslationValues(){return{name:t.wallet&&"name"in t.wallet?t.wallet.name:r("common.yourWallet",{},"Your wallet")}},textTranslationKey:"actionModal.confirmTransaction.text",get icon(){return kt(Uo,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},jc=e=>kt(Oc,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return kt(Bo,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Lc=e=>kt(Oc,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return kt(ko,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),zc=()=>kt(Ai,{get opened(){var e;return Qe((()=>null!==Jr()))()&&!0===(null==(e=Jr())?void 0:e.openModal)},get enableAndroidBackHandler(){return Ga.enableAndroidBackHandler},onClose:()=>Xr(null),"data-tc-actions-modal-container":"true",get children(){return kt(Ut,{get children(){return[kt(Mt,{get when(){return"transaction-sent"===Jr().name},get children(){return kt(Lc,{onClose:()=>Xr(null)})}}),kt(Mt,{get when(){return"transaction-canceled"===Jr().name},get children(){return kt(jc,{onClose:()=>Xr(null)})}}),kt(Mt,{get when(){return"confirm-transaction"===Jr().name},get children(){return kt(Rc,{onClose:()=>Xr(null)})}})]}})}}),Nc=e=>{const t=((e={},t=(navigator.language in e?navigator.language:Object.keys(e)[0]))=>{const[r,n]=Ze(t),[i,o]=bn(e);return[(e,t,n)=>{const o=Zi(i[r()],e,n||"");return"function"==typeof o?o(t):"string"==typeof o?((e,t,r=/{{(.*?)}}/g)=>e.replace(r,((e,r)=>Zi(t,r,""))))(o,t||{}):o},{add(e,t){o(e,(e=>Object.assign(e||{},t)))},locale:e=>e?n(e):r(),dict:e=>Zi(i,e)}]})(en,Ga.language);return customElements.define(kr,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),kt(Wi.Provider,{value:t,get children(){return kt(Bs.Provider,{get value(){return e.tonConnectUI},get children(){return kt(rn.Provider,{get value(){return Ga.connector},get children(){return[kt(Sr,{}),kt(br,{theme:kn,get children(){return[kt(It,{get when(){return Ga.buttonRootId},get children(){return kt(rr,{get mount(){return document.getElementById(Ga.buttonRootId)},get children(){return kt(Ha,{})}})}}),kt(nr,{component:kr,get children(){return[kt(Pc,{}),kt(zc,{})]}})]}})]}})}})}})},Dc=()=>{setTimeout((()=>qr({status:"opened",closeReason:null})))},$c=e=>{setTimeout((()=>Xr(e)))};class Fc{constructor(e){Pe(this,"connector"),Pe(this,"setConnectRequestParametersCallback"),Pe(this,"consumers",[]),Pe(this,"state",Hr()),this.connector=e.connector,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,Ye((()=>{const e=Hr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(){return Ie(this,null,(function*(){const e=(yield this.connector.getWallets()).find(ee);return e?this.connectEmbeddedWallet(e):this.connectExternalWallet()}))}close(){var e;e="action-cancelled",setTimeout((()=>qr({status:"closed",closeReason:e})))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Qr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},r=Ga.connectRequestParameters;"loading"===(null==r?void 0:r.state)?this.setConnectRequestParametersCallback(t):t(null==r?void 0:r.value)}connectExternalWallet(){return Ie(this,null,(function*(){return On()&&Rn(),Dc(),new Promise((e=>{const t=this.onStateChange((r=>{const{status:n}=r;"opened"===n&&(t(),e())}))}))}))}}class Kc{constructor(e){Pe(this,"connector"),Pe(this,"consumers",[]),this.connector=e.connector,Ye((()=>{const e=Jr();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}var Vc=r(3515);const Hc="d843619b379084d133f061606beecbf72ae2bf60e0622e808f2a3f631673599b",qc=async(e,t,r)=>{const n=r?"https://testnet.toncenter.com/api/v3/":"https://toncenter.com/api/v3/",i={"Content-Type":"application/json","X-API-Key":Hc},o=await fetch(n+e+"?"+new URLSearchParams(t),{method:"GET",headers:i}),s=await o.json();if(s.error)throw new Error(s.error);return s};class Zc{constructor(e,t){this.contractAddress=e,this.isTestnet=t,this.tonClient=new Vc.TonClient({endpoint:t?"https://testnet.toncenter.com/api/v2/jsonRPC":"https://toncenter.com/api/v2/jsonRPC",apiKey:Hc})}getState(){throw new Error("Method not implemented.")}get(e,t){return this.tonClient.runMethod(this.contractAddress,e,t)}external(e){throw new Error("Method not implemented.")}internal(e,t){throw new Error("Method not implemented.")}open(e){throw new Error("Method not implemented.")}getTransactions(e,t,r,n){throw new Error("Method not implemented.")}}const Wc=(e,t)=>a.Address.isFriendly(e)?a.Address.parseFriendly(e).isTestOnly&&!t?"Please enter mainnet address":null:"Invalid address",Gc=async(e,t)=>{const r=await(async(e,t)=>{const r=e.toRawString(),n=await qc("addressBook",{address:r},t);return a.Address.parseFriendly(n[r].user_friendly)})(e,t);return Yc(r)},Yc=e=>{const t=Qc(e),r=((e,t)=>(a.Address.parseFriendly(e),(t?"https://testnet.tonscan.org/address/":"https://tonscan.org/address/")+e))(t,e.isTestOnly);return`${t}`},Qc=e=>e.address.toString({bounceable:e.isBounceable,testOnly:e.isTestOnly}),Jc=(e,t)=>{if(e.length!==t.length)return!1;for(let r=0;r{if(!e)throw console.error(t),new Error(t)};class ed{}ed.multisig={new_order:4145565967,execute:1963556701,execute_internal:2737592767},ed.order={approve:2808226575,expired:6,approve_rejected:2947491902,approved:2187369462,init:2624846754},ed.actions={send_message:4046986843,update_multisig_params:487390163};class td{}td.multisig={unauthorized_new_order:1007,invalid_new_order:1008,not_enough_ton:100,unauthorized_execute:101,singers_outdated:102,invalid_dictionary_sequence:103,expired:111},td.order={unauthorized_init:104,already_approved:107,already_inited:105,unauthorized_sign:106,expired:111,unknown_op:65535,already_executed:112};class rd{}function nd(e){let t=a.Dictionary.empty(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address());for(let r=0;r0||e.remainingRefs>0)throw new Error("remaining bits in data")}rd.bitsize={op:32,queryId:64,orderSeqno:256,signerIndex:8,actionIndex:8,time:48};class sd{constructor(e,t,r){this.address=e,this.init=t,this.configuration=r,this.orderSeqno=0n}static createFromAddress(e){let t=new sd(e);return t.orderSeqno=0n,t}static createFromConfig(e,t,r=0){const n=function(e){return(0,a.beginCell)().storeUint(0,rd.bitsize.orderSeqno).storeUint(e.threshold,rd.bitsize.signerIndex).storeRef((0,a.beginCell)().storeDictDirect(nd(e.signers))).storeUint(e.signers.length,rd.bitsize.signerIndex).storeDict(nd(e.proposers)).storeBit(e.allowArbitrarySeqno).endCell()}(e),i={code:t,data:n};return new sd((0,a.contractAddress)(r,i),i,e)}async sendDeploy(e,t,r){await e.internal(t,{value:r,sendMode:a.SendMode.PAY_GAS_SEPARATELY,body:(0,a.beginCell)().storeUint(0,rd.bitsize.op).storeUint(0,rd.bitsize.queryId).endCell()})}static packTransferRequest(e){let t=(0,a.beginCell)().store((0,a.storeMessageRelaxed)(e.message)).endCell();return(0,a.beginCell)().storeUint(ed.actions.send_message,rd.bitsize.op).storeUint(e.sendMode,8).storeRef(t).endCell()}static packUpdateRequest(e){return(0,a.beginCell)().storeUint(ed.actions.update_multisig_params,rd.bitsize.op).storeUint(e.threshold,rd.bitsize.signerIndex).storeRef((0,a.beginCell)().storeDictDirect(nd(e.signers))).storeDict(nd(e.proposers)).endCell()}static packOrder(e){let t=a.Dictionary.empty(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell());if(e.length>255)throw new Error("For action chains above 255, use packLarge method");for(let r=0;r{const t=e.beginParse(),r=t.loadAddress(),n=t.loadUintBig(256);return od(t),{multisigAddress:r,orderId:n}},ld=e=>{const t=a.Address.parse(e.destination),r=(e=>{const t=e.beginParse();if(0!==t.loadUint(2))throw new Error("invalid init state prefix");const r=t.loadMaybeRef(),n=t.loadMaybeRef();if(t.loadBoolean())throw new Error("invalid init state empty libraries");return od(t),{code:r,body:ad(n)}})(a.Cell.fromBase64(e.init_state.body)),n=a.Cell.fromBase64(e.message_content.body).beginParse();Xc(n.loadUint(32)===ed.order.init,"invalid op");const i=n.loadUint(64),o=n.loadUint(8),s=n.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address()),l=n.loadUint(48),c=n.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell()),d=n.loadUint(1);let u;return d&&(u=n.loadUint(8)),console.log("OUT",{queryId:i,threshold:o,signers:s,expiredAt:l,order:c,isSigner:d,signerIndex:u}),od(n),{orderAddress:t,orderId:r.body.orderId}};function cd(e){let t=[];if(null!==e){const r=a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address(),e);for(let e=0;e{switch(e){case"unlock":return 0;case"out":return 1;case"in":return 2;case"full":return 3;default:throw new Error("Invalid argument!")}},md=e=>{switch(e){case"unlock":return"Unlock";case"out":return"Outgoing transfers locked";case"in":return"Inbound transfers locked";case"full":return"Outgoing and Inbound transfers locked"}};function yd(e){if(e.remainingBits>0||e.remainingRefs>0)throw new Error("remaining bits in data")}class bd{constructor(e,t){this.address=e,this.init=t}static createFromAddress(e){return new bd(e)}static createFromConfig(e,t,r=0){const n=function(e){const t=e.jetton_content instanceof a.Cell?e.jetton_content:function(e){return(0,a.beginCell)().storeStringTail(e.uri).endCell()}(e.jetton_content);return(0,a.beginCell)().storeCoins(0).storeAddress(e.admin).storeAddress(null).storeRef(e.wallet_code).storeRef(t).endCell()}(e),i={code:t,data:n};return new bd((0,a.contractAddress)(r,i),i)}async sendDeploy(e,t,r){await e.internal(t,{value:r,sendMode:a.SendMode.PAY_GAS_SEPARATELY,body:(0,a.beginCell)().storeUint(ud.top_up,32).storeUint(0,64).endCell()})}static mintMessage(e,t,r,n,i,o,s){const l=(0,a.beginCell)().storeUint(ud.internal_transfer,32).storeUint(0,64).storeCoins(t).storeAddress(r).storeAddress(n).storeCoins(o).storeMaybeRef(i).endCell();return(0,a.beginCell)().storeUint(ud.mint,32).storeUint(0,64).storeAddress(e).storeCoins(s).storeRef(l).endCell()}static parseMintInternalMessage(e){if(e.loadUint(32)!==ud.internal_transfer)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadCoins(),n=e.loadAddress(),i=e.loadAddress(),o=e.loadCoins(),s=e.loadBit()?e.loadRef().beginParse():e;return yd(e),{queryId:t,jettonAmount:r,fromAddress:n,responseAddress:i,forwardTonAmount:o,forwardPayload:s}}static parseMintMessage(e){if(e.loadUint(32)!==ud.mint)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadAddress(),n=e.loadCoins(),i=e.loadRef();return yd(e),{queryId:t,toAddress:r,tonAmount:n,internalMessage:this.parseMintInternalMessage(i.beginParse())}}static topUpMessage(){return(0,a.beginCell)().storeUint(ud.top_up,32).storeUint(0,64).endCell()}static parseTopUp(e){if(e.loadUint(32)!==ud.top_up)throw new Error("Invalid op");const t=e.loadUint(64);return yd(e),{queryId:t}}static changeAdminMessage(e){return(0,a.beginCell)().storeUint(ud.change_admin,32).storeUint(0,64).storeAddress(e).endCell()}static parseChangeAdmin(e){if(e.loadUint(32)!==ud.change_admin)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadAddress();return yd(e),{queryId:t,newAdminAddress:r}}static claimAdminMessage(e=0n){return(0,a.beginCell)().storeUint(ud.claim_admin,32).storeUint(e,64).endCell()}static parseClaimAdmin(e){if(e.loadUint(32)!==ud.claim_admin)throw new Error("Invalid op");const t=e.loadUint(64);return yd(e),{queryId:t}}static changeContentMessage(e){const t=e.uri;return(0,a.beginCell)().storeUint(ud.change_metadata_url,32).storeUint(0,64).storeStringTail(t).endCell()}static parseChangeContent(e){if(e.loadUint(32)!==ud.change_metadata_url)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadStringTail();return yd(e),{queryId:t,newMetadataUrl:r}}static lockWalletMessage(e,t,r,n=0){return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(n,64).storeAddress(e).storeCoins(r).storeRef((0,a.beginCell)().storeUint(ud.set_status,32).storeUint(n,64).storeUint(t,4).endCell()).endCell()}static parseSetStatus(e){if(e.loadUint(32)!==ud.set_status)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadUint(4);return yd(e),{queryId:t,newStatus:r}}static parseCallTo(e,t){if(e.loadUint(32)!==ud.call_to)throw new Error("Invalid op");const r=e.loadUint(64),n=e.loadAddress(),i=e.loadCoins(),o=e.loadRef();return yd(e),{queryId:r,toAddress:n,tonAmount:i,action:t(o.beginParse())}}static forceTransferMessage(e,t,r,n,i,o,s,l,c=0n){const d=fd.transferMessage(e,t,n,i,o,s);return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(c,64).storeAddress(r).storeCoins(l).storeRef(d).endCell()}static parseTransfer(e){if(e.loadUint(32)!==ud.transfer)throw new Error("Invalid op");return{queryId:e.loadUint(64),jettonAmount:e.loadCoins(),toAddress:e.loadAddress(),responseAddress:e.loadAddress(),customPayload:e.loadMaybeRef(),forwardTonAmount:e.loadCoins(),forwardPayload:e.loadBit()?e.loadRef().beginParse():e}}static forceBurnMessage(e,t,r,n,i=0){return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(i,64).storeAddress(t).storeCoins(n).storeRef(fd.burnMessage(e,r,null)).endCell()}static parseBurn(e){if(e.loadUint(32)!==ud.burn)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadCoins(),n=e.loadAddress(),i=e.loadMaybeRef();return yd(e),{queryId:t,jettonAmount:r,responseAddress:n,customPayload:i}}static upgradeMessage(e,t,r=0){return(0,a.beginCell)().storeUint(ud.upgrade,32).storeUint(r,64).storeRef(t).storeRef(e).endCell()}static parseUpgrade(e){if(e.loadUint(32)!==ud.upgrade)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadRef(),n=e.loadRef();return yd(e),{queryId:t,newData:r,newCode:n}}async getWalletAddress(e,t){const r=await e.get("get_wallet_address",[{type:"slice",cell:(0,a.beginCell)().storeAddress(t).endCell()}]);return Xc(1===r.stack.remaining,"invalid get_wallet_address result"),r.stack.readAddress()}async getJettonData(e){let t=await e.get("get_jetton_data",[]);return Xc(5===t.stack.remaining,"invalid get_jetton_data result"),{totalSupply:t.stack.readBigNumber(),mintable:t.stack.readBoolean(),adminAddress:t.stack.readAddress(),content:t.stack.readCell(),walletCode:t.stack.readCell()}}async getNextAdminAddress(e){const t=await e.get("get_next_admin_address",[]);return Xc(1===t.stack.remaining,"invalid get_next_admin_address result"),t.stack.readAddressOpt()}}const wd=e=>{if(null===e)throw new Error("invalid number");if(void 0===e)throw new Error("invalid number");if(isNaN(e))throw new Error("invalid number");if(e<0)throw new Error("invalid number")};var vd=r(5269);const Cd=["uri","name","description","image","image_data","symbol","decimals","amount_style"],_d={serialize:(e,t)=>{t.storeRef((0,a.beginCell)().storeUint(0,8).storeStringTail(e).endCell())},parse:e=>{const t=e.loadRef().beginParse(),r=t.loadUint(8);if(0==r)return t.loadStringTail();if(1==r)return a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(32),a.Dictionary.Values.Cell(),t).values().map((e=>e.beginParse().loadStringTail())).join("");throw Error(`Prefix ${r} is not supported yet`)}},kd=async(e,t,r)=>{const n=await qc("account",{address:Qc(e)},t);Xc("active"===n.status,"Contract not active");const i=n.balance,o=new Zc(e.address,t),s=bd.createFromAddress(e.address),l=await s.getJettonData(o);let c,d;const u=await(async e=>{const t=e.beginParse(),r=t.loadUint(8);if(1==r){const e=0==t.remainingBits;if(e&&0==t.remainingRefs)throw new Error("No data in content cell!");return e?t.loadStringRefTail():t.loadStringTail()}if(0==r){const e=a.Dictionary.load(a.Dictionary.Keys.BigUint(256),_d,t),r={};for(const t of Cd){const n=BigInt("0x"+(await(0,vd.sha256)(t)).toString("hex")),i=e.get(n);void 0!==i&&(r[t]=i)}return r}throw new Error(`Unknown content format indicator:${r}`)})(l.content);if(u instanceof String)d=u;else{const e=u;d=e.uri;const t=e.decimals;if(void 0!==t&&(c=parseInt(t),isNaN(c)))throw new Error("invalid decimals")}let h;return r&&(h=await s.getNextAdminAddress(o)),{tonBalance:i,jettonMinterContract:s,adminAddress:l.adminAddress,nextAdminAddress:h,decimals:c,metadataUrl:d}};var xd=r(9107),Ad=r.n(xd),Sd=r(8287).hp;function Bd(e){let t=0;const r=Sd.alloc(e.length+2);r.set(e);for(let e of r){let r=128;for(;r>0;)t<<=1,e&r&&(t+=1),r>>=1,t>65535&&(t&=65535,t^=4129)}return Sd.from([Math.floor(t/256),t%256])}var Ed,Pd,Id=r(8287).hp;function Ud(e){if("string"==typeof e&&!Md.isFriendly(e))throw new Error("Unknown address type");const t=Id.isBuffer(e)?e:Id.from(e,"base64");if(36!==t.length)throw new Error("Unknown address type: byte length is not equal to 36");const r=t.subarray(0,34),n=t.subarray(34,36),i=Bd(r);if(i[0]!==n[0]||i[1]!==n[1])throw new Error("Invalid checksum: "+e);let o=r[0],s=!1,a=!1;if(128&o&&(s=!0,o^=128),17!==o&&81!==o)throw"Unknown address tag";a=17===o;let l=null;return l=255===r[1]?-1:r[1],{isTestOnly:s,isBounceable:a,workchain:l,hashPart:r.subarray(2,34)}}class Md{static isAddress(e){return e instanceof Md}static isFriendly(e){return 48===e.length&&!!/[A-Za-z0-9+/_-]+/.test(e)}static isRaw(e){if(-1===e.indexOf(":"))return!1;let[t,r]=e.split(":");return!!Number.isInteger(parseFloat(t))&&!!/[a-f0-9]+/.test(r.toLowerCase())&&64===r.length}static normalize(e){return"string"==typeof e?Md.parse(e).toString():e.toString()}static parse(e){if(Md.isFriendly(e))return this.parseFriendly(e).address;if(Md.isRaw(e))return this.parseRaw(e);throw new Error("Unknown address type: "+e)}static parseRaw(e){let t=parseInt(e.split(":")[0]),r=Id.from(e.split(":")[1],"hex");return new Md(t,r)}static parseFriendly(e){if(Id.isBuffer(e)){let t=Ud(e);return{isBounceable:t.isBounceable,isTestOnly:t.isTestOnly,address:new Md(t.workchain,t.hashPart)}}{let t=Ud(e.replace(/\-/g,"+").replace(/_/g,"/"));return{isBounceable:t.isBounceable,isTestOnly:t.isTestOnly,address:new Md(t.workchain,t.hashPart)}}}constructor(e,t){if(this.toRawString=()=>this.workChain+":"+this.hash.toString("hex"),this.toRaw=()=>{const e=Id.alloc(36);return e.set(this.hash),e.set([this.workChain,this.workChain,this.workChain,this.workChain],32),e},this.toStringBuffer=e=>{let t=!(!e||void 0===e.testOnly)&&e.testOnly,r=!e||void 0===e.bounceable||e.bounceable?17:81;t&&(r|=128);const n=Id.alloc(34);n[0]=r,n[1]=this.workChain,n.set(this.hash,2);const i=Id.alloc(36);return i.set(n),i.set(Bd(n),34),i},this.toString=e=>{let t=!e||void 0===e.urlSafe||e.urlSafe,r=this.toStringBuffer(e);return t?r.toString("base64").replace(/\+/g,"-").replace(/\//g,"_"):r.toString("base64")},this[Ed]=()=>this.toString(),32!==t.length)throw new Error("Invalid address hash length: "+t.length);this.workChain=e,this.hash=t,Object.freeze(this)}equals(e){return e.workChain===this.workChain&&e.hash.equals(this.hash)}}Ed=Ad();class Td{static isAddress(e){return e instanceof Td}constructor(e,t){this[Pd]=()=>this.toString(),this.value=e,this.bits=t}toString(){return`External<${this.bits}:${this.value}>`}}function Od(e){let t=new Dd(8*Math.ceil(e.length/8));t.writeBits(e);let r=8*Math.ceil(e.length/8)-e.length;for(let e=0;ethis.toString(),r<0)throw new Error(`Length ${r} is out of bounds`);this._length=r,this._data=e,this._offset=t}get length(){return this._length}at(e){if(e>=this._length)throw new Error(`Index ${e} > ${this._length} is out of bounds`);if(e<0)throw new Error(`Index ${e} < 0 is out of bounds`);let t=this._offset+e>>3,r=7-(this._offset+e)%8;return!!(this._data[t]&1<this._length)throw new Error(`Offset(${e}) > ${this._length} is out of bounds`);if(e<0)throw new Error(`Offset(${e}) < 0 is out of bounds`);if(0===t)return Ld.EMPTY;if(e+t>this._length)throw new Error(`Offset ${e} + Length ${t} > ${this._length} is out of bounds`);return new Ld(this._data,this._offset+e,t)}subbuffer(e,t){if(e>this._length)throw new Error(`Offset ${e} is out of bounds`);if(e<0)throw new Error(`Offset ${e} is out of bounds`);if(e+t>this._length)throw new Error(`Offset + Lenght = ${e+t} is out of bounds`);if(t%8!=0)return null;if((this._offset+e)%8!=0)return null;let r=this._offset+e>>3,n=r+(t>>3);return this._data.subarray(r,n)}equals(e){if(this._length!==e._length)return!1;for(let t=0;t8*this._buffer.length)throw new Error("BitBuilder overflow");("boolean"==typeof e&&!0===e||"number"==typeof e&&e>0)&&(this._buffer[t/8|0]|=1<<7-t%8),this._length++}writeBits(e){for(let t=0;t8*this._buffer.length)throw new Error("BitBuilder overflow");e.copy(this._buffer,this._length/8),this._length+=8*e.length}else for(let t=0;t=n)throw Error(`bitLength is too small for a value ${e}. Got ${t}`);if(this._length+t>8*this._buffer.length)throw new Error("BitBuilder overflow");const i=8-this._length%8;if(i>0){const e=Math.floor(this._length/8);if(t>BigInt(t-i));this._buffer[e]|=n,this._length+=i}}for(t-=i;t>0;)t>=8?(this._buffer[this._length/8]=Number(r>>BigInt(t-8)&0xffn),this._length+=8,t-=8):(this._buffer[this._length/8]=Number(r<=n)throw Error(`value is out of range for ${t} bits. Got ${e}`);r<0?(this.writeBit(!0),r=n+r):this.writeBit(!1),this.writeUint(r,t-1)}writeVarUint(e,t){let r=BigInt(e);if(t<0||!Number.isSafeInteger(t))throw Error(`invalid bit length. Got ${t}`);if(r<0)throw Error(`value is negative. Got ${e}`);if(0n===r)return void this.writeUint(0,t);const n=Math.ceil(r.toString(2).length/8),i=8*n;this.writeUint(n,t),this.writeUint(r,i)}writeVarInt(e,t){let r=BigInt(e);if(t<0||!Number.isSafeInteger(t))throw Error(`invalid bit length. Got ${t}`);if(0n===r)return void this.writeUint(0,t);let n=r>0?r:-r;const i=1+Math.ceil(n.toString(2).length/8),o=8*i;this.writeUint(i,t),this.writeInt(r,o)}writeCoins(e){this.writeVarUint(e,4)}writeAddress(e){if(null!=e){if(Md.isAddress(e))return this.writeUint(2,2),this.writeUint(0,1),this.writeInt(e.workChain,8),void this.writeBuffer(e.hash);if(Td.isAddress(e))return this.writeUint(1,2),this.writeUint(e.bits,9),void this.writeUint(e.value,e.bits);throw Error(`Invalid address. Got ${e}`)}this.writeUint(0,2)}build(){return new Ld(this._buffer,0,this._length)}buffer(){if(this._length%8!=0)throw new Error("BitBuilder buffer is not byte aligned");return this._buffer.subarray(0,this._length/8)}}!function(e){e[e.Ordinary=-1]="Ordinary",e[e.PrunedBranch=1]="PrunedBranch",e[e.Library=2]="Library",e[e.MerkleProof=3]="MerkleProof",e[e.MerkleUpdate=4]="MerkleUpdate"}(zd||(zd={}));var $d,Fd=r(8287).hp;function Kd(e){if(e.remainingBits%8!=0)throw new Error(`Invalid string length: ${e.remainingBits}`);if(0!==e.remainingRefs&&1!==e.remainingRefs)throw new Error(`invalid number of refs: ${e.remainingRefs}`);let t;return t=0===e.remainingBits?Fd.alloc(0):e.loadBuffer(e.remainingBits/8),1===e.remainingRefs&&(t=Fd.concat([t,Kd(e.loadRef().beginParse())])),t}function Vd(e){return Kd(e).toString()}function Hd(e,t){if(e.length>0){let r=Math.floor(t.availableBits/8);if(e.length>r){let n=e.subarray(0,r),i=e.subarray(r);t=t.storeBuffer(n);let o=yu();Hd(i,o),t=t.storeRef(o.endCell())}else t=t.storeBuffer(e)}}function qd(e,t){Hd(Fd.from(e),t)}class Zd{constructor(e,t){this[$d]=()=>this.toString(),this._reader=e.clone(),this._refs=[...t],this._refsOffset=0}get remainingBits(){return this._reader.remaining}get offsetBits(){return this._reader.offset}get remainingRefs(){return this._refs.length-this._refsOffset}get offsetRefs(){return this._refsOffset}skip(e){return this._reader.skip(e),this}loadBit(){return this._reader.loadBit()}preloadBit(){return this._reader.preloadBit()}loadBoolean(){return this.loadBit()}loadMaybeBoolean(){return this.loadBit()?this.loadBoolean():null}loadBits(e){return this._reader.loadBits(e)}preloadBits(e){return this._reader.preloadBits(e)}loadUint(e){return this._reader.loadUint(e)}loadUintBig(e){return this._reader.loadUintBig(e)}preloadUint(e){return this._reader.preloadUint(e)}preloadUintBig(e){return this._reader.preloadUintBig(e)}loadMaybeUint(e){return this.loadBit()?this.loadUint(e):null}loadMaybeUintBig(e){return this.loadBit()?this.loadUintBig(e):null}loadInt(e){return this._reader.loadInt(e)}loadIntBig(e){return this._reader.loadIntBig(e)}preloadInt(e){return this._reader.preloadInt(e)}preloadIntBig(e){return this._reader.preloadIntBig(e)}loadMaybeInt(e){return this.loadBit()?this.loadInt(e):null}loadMaybeIntBig(e){return this.loadBit()?this.loadIntBig(e):null}loadVarUint(e){return this._reader.loadVarUint(e)}loadVarUintBig(e){return this._reader.loadVarUintBig(e)}preloadVarUint(e){return this._reader.preloadVarUint(e)}preloadVarUintBig(e){return this._reader.preloadVarUintBig(e)}loadVarInt(e){return this._reader.loadVarInt(e)}loadVarIntBig(e){return this._reader.loadVarIntBig(e)}preloadVarInt(e){return this._reader.preloadVarInt(e)}preloadVarIntBig(e){return this._reader.preloadVarIntBig(e)}loadCoins(){return this._reader.loadCoins()}preloadCoins(){return this._reader.preloadCoins()}loadMaybeCoins(){return this._reader.loadBit()?this._reader.loadCoins():null}loadAddress(){return this._reader.loadAddress()}loadMaybeAddress(){return this._reader.loadMaybeAddress()}loadExternalAddress(){return this._reader.loadExternalAddress()}loadMaybeExternalAddress(){return this._reader.loadMaybeExternalAddress()}loadAddressAny(){return this._reader.loadAddressAny()}loadRef(){if(this._refsOffset>=this._refs.length)throw new Error("No more references");return this._refs[this._refsOffset++]}preloadRef(){if(this._refsOffset>=this._refs.length)throw new Error("No more references");return this._refs[this._refsOffset]}loadMaybeRef(){return this.loadBit()?this.loadRef():null}preloadMaybeRef(){return this.preloadBit()?this.preloadRef():null}loadBuffer(e){return this._reader.loadBuffer(e)}preloadBuffer(e){return this._reader.preloadBuffer(e)}loadStringTail(){return Vd(this)}loadMaybeStringTail(){return this.loadBit()?Vd(this):null}loadStringRefTail(){return Vd(this.loadRef().beginParse())}loadMaybeStringRefTail(){const e=this.loadMaybeRef();return e?Vd(e.beginParse()):null}loadDict(e,t){return Ou.load(e,t,this)}loadDictDirect(e,t){return Ou.loadDirect(e,t,this)}endParse(){if(this.remainingBits>0||this.remainingRefs>0)throw new Error("Slice is not empty")}asCell(){return yu().storeSlice(this).endCell()}asBuilder(){return yu().storeSlice(this)}clone(e=!1){if(e){let e=this._reader.clone();return e.reset(),new Zd(e,this._refs)}{let e=new Zd(this._reader,this._refs);return e._refsOffset=this._refsOffset,e}}toString(){return this.asCell().toString()}}$d=Ad();var Wd=r(8287).hp;class Gd{constructor(e,t=0){this._checkpoints=[],this._bits=e,this._offset=t}get offset(){return this._offset}get remaining(){return this._bits.length-this._offset}skip(e){if(e<0||this._offset+e>this._bits.length)throw new Error(`Index ${this._offset+e} is out of bounds`);this._offset+=e}reset(){this._checkpoints.length>0?this._offset=this._checkpoints.pop():this._offset=0}save(){this._checkpoints.push(this._offset)}loadBit(){let e=this._bits.at(this._offset);return this._offset++,e}preloadBit(){return this._bits.at(this._offset)}loadBits(e){let t=this._bits.substring(this._offset,e);return this._offset+=e,t}preloadBits(e){return this._bits.substring(this._offset,e)}loadBuffer(e){let t=this._preloadBuffer(e,this._offset);return this._offset+=8*e,t}preloadBuffer(e){return this._preloadBuffer(e,this._offset)}loadUint(e){return Number(this.loadUintBig(e))}loadUintBig(e){let t=this.preloadUintBig(e);return this._offset+=e,t}preloadUint(e){return Number(this._preloadUint(e,this._offset))}preloadUintBig(e){return this._preloadUint(e,this._offset)}loadInt(e){let t=this._preloadInt(e,this._offset);return this._offset+=e,Number(t)}loadIntBig(e){let t=this._preloadInt(e,this._offset);return this._offset+=e,t}preloadInt(e){return Number(this._preloadInt(e,this._offset))}preloadIntBig(e){return this._preloadInt(e,this._offset)}loadVarUint(e){let t=Number(this.loadUint(e));return Number(this.loadUintBig(8*t))}loadVarUintBig(e){let t=Number(this.loadUint(e));return this.loadUintBig(8*t)}preloadVarUint(e){let t=Number(this._preloadUint(e,this._offset));return Number(this._preloadUint(8*t,this._offset+e))}preloadVarUintBig(e){let t=Number(this._preloadUint(e,this._offset));return this._preloadUint(8*t,this._offset+e)}loadVarInt(e){let t=Number(this.loadUint(e));return Number(this.loadIntBig(8*t))}loadVarIntBig(e){let t=Number(this.loadUint(e));return this.loadIntBig(8*t)}preloadVarInt(e){let t=Number(this._preloadUint(e,this._offset));return Number(this._preloadInt(8*t,this._offset+e))}preloadVarIntBig(e){let t=Number(this._preloadUint(e,this._offset));return this._preloadInt(8*t,this._offset+e)}loadCoins(){return this.loadVarUintBig(4)}preloadCoins(){return this.preloadVarUintBig(4)}loadAddress(){let e=Number(this._preloadUint(2,this._offset));if(2===e)return this._loadInternalAddress();throw new Error("Invalid address: "+e)}loadMaybeAddress(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(2===e)return this._loadInternalAddress();throw new Error("Invalid address")}loadExternalAddress(){if(1===Number(this._preloadUint(2,this._offset)))return this._loadExternalAddress();throw new Error("Invalid address")}loadMaybeExternalAddress(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(1===e)return this._loadExternalAddress();throw new Error("Invalid address")}loadAddressAny(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(2===e)return this._loadInternalAddress();if(1===e)return this._loadExternalAddress();throw 3===e?Error("Unsupported"):Error("Unreachable")}loadPaddedBits(e){if(e%8!=0)throw new Error("Invalid number of bits");let t=e;for(;;){if(this._bits.at(this._offset+t-1)){t--;break}t--}let r=this._bits.substring(this._offset,t);return this._offset+=e,r}clone(){return new Gd(this._bits,this._offset)}_preloadInt(e,t){if(0==e)return 0n;let r=this._bits.at(t),n=0n;for(let r=0;r>1&1431655765))+(e>>2&858993459))+(e>>4)&252645135)>>24}(this._mask),this._hashCount=this._hashIndex+1}get value(){return this._mask}get level(){return 32-Math.clz32(this._mask)}get hashIndex(){return this._hashIndex}get hashCount(){return this._hashCount}apply(e){return new Xd(this._mask&(1<>e-1)%2!=0}}function eu(e,t){let r,n=new Gd(e),i=n.loadUint(8);if(1!==i)throw new Error(`Pruned branch cell must have type 1, got "${i}"`);if(0!==t.length)throw new Error(`Pruned Branch cell can't has refs, got "${t.length}"`);if(280===e.length)r=new Xd(1);else{if(r=new Xd(n.loadUint(8)),r.level<1||r.level>3)throw new Error(`Pruned Branch cell level must be >= 1 and <= 3, got "${r.level}/${r.value}"`);const t=16+272*r.apply(r.level-1).hashCount;if(e.length!==t)throw new Error(`Pruned branch cell must have exactly ${t} bits, got "${e.length}"`)}let o=[],s=[],a=[];for(let e=0;e>1);else if(e===zd.MerkleUpdate)Jd(t,r),n=new Xd((r[0].mask.value|r[1].mask.value)>>1);else{if(e!==zd.Library)throw new Error("Unsupported exotic type");Yd(t),n=new Xd}let o=[],s=[],a=e===zd.PrunedBranch?1:n.hashCount,l=n.hashCount-a;for(let i=0,a=0;i<=n.level;i++){if(!n.isSignificant(i))continue;if(a0&&d++;let u=iu(t,c,r,i,n.apply(i).value,e),h=(0,vd.sha256_sync)(u),f=a-l;o[f]=d,s[f]=h,a++}let c=[],d=[];if(i)for(let e=0;e<4;e++){const{hashIndex:t}=n.apply(e),{hashIndex:r}=n;t!==r?(c.push(i.pruned[t].hash),d.push(i.pruned[t].depth)):(c.push(s[0]),d.push(o[0]))}else for(let e=0;e<4;e++)c.push(s[n.apply(e).hashIndex]),d.push(o[n.apply(e).hashIndex]);return{mask:n,hashes:c,depths:d}}function su(e,t){let r=BigInt(e);if("int"===t)return 0n===r||-1n===r?1:(r>0?r:-r).toString(2).length+1;if("uint"===t){if(r<0)throw Error(`value is negative. Got ${e}`);return r.toString(2).length}throw Error(`invalid mode. Got ${t}`)}var au=r(8287).hp;const lu=2197175160;function cu(e){let t=-1;for(let r=0;r>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1;t^=4294967295;let r=au.alloc(4);return r.writeInt32LE(t),r}function du(e){return function(e){let t=0;for(let r=0;r<3;r++)t+=1&e,e>>=1;return t+1}(7&e)}function uu(e,t){const r=e.loadUint(8),n=r%8,i=!!(8&r),o=e.loadUint(8),s=Math.ceil(o/2),a=!!(o%2),l=r>>5,c=!!(16&r),d=c?32*du(l):0,u=c?2*du(l):0;e.skip(8*d),e.skip(8*u);let h=Ld.EMPTY;s>0&&(h=a?e.loadPaddedBits(8*s):e.loadBits(8*s));let f=[];for(let r=0;r=0;e--){if(n[e].result)throw Error("Impossible");let t=[];for(let r of n[e].refs){if(!n[r].result)throw Error("Invalid BOC file");t.push(n[r].result)}n[e].result=new mu({bits:n[e].bits,refs:t,exotic:n[e].exotic})}let i=[];for(let e=0;e{if(this.isExotic&&!e)throw new Error("Exotic cells cannot be parsed");return new Zd(new Gd(this.bits),this.refs)},this.hash=(e=3)=>this._hashes[Math.min(this._hashes.length-1,e)],this.depth=(e=3)=>this._depths[Math.min(this._depths.length-1,e)],this.level=()=>this.mask.level,this.equals=e=>this.hash().equals(e.hash()),this[pu]=()=>this.toString();let t=Ld.EMPTY;e&&e.bits&&(t=e.bits);let r,n,i,o=[];e&&e.refs&&(o=[...e.refs]);let s=zd.Ordinary;if(e&&e.exotic){let e=function(e,t){let r=new Gd(e).preloadUint(8);if(1===r)return function(e,t){let r=eu(e,t),n=[],i=[],o=new Xd(r.mask);for(let e=0;e>1);return{type:zd.MerkleProof,depths:[],hashes:[],mask:r}}(e,t);if(4===r)return function(e,t){Jd(e,t);let r=new Xd((t[0].level()|t[1].level())>>1);return{type:zd.MerkleUpdate,depths:[],hashes:[],mask:r}}(e,t);throw Error("Invalid exotic cell type: "+r)}(t,o),a=ou(e.type,t,o);i=a.mask,n=a.depths,r=a.hashes,s=e.type}else{if(o.length>4)throw new Error("Invalid number of references");if(t.length>1023)throw new Error(`Bits overflow: ${t.length} > 1023`);let e=ou(zd.Ordinary,t,o);i=e.mask,n=e.depths,r=e.hashes,s=zd.Ordinary}this.type=s,this.bits=t,this.refs=o,this.mask=i,this._depths=n,this._hashes=r,Object.freeze(this),Object.freeze(this.refs),Object.freeze(this.bits),Object.freeze(this.mask),Object.freeze(this._depths),Object.freeze(this._hashes)}get isExotic(){return this.type!==zd.Ordinary}toBoc(e){return function(e,t){let r=function(e){let t=[e],r=new Map,n=new Set,i=[];for(;t.length>0;){const e=[...t];t=[];for(let i of e){const e=i.hash().toString("hex");if(!r.has(e)){n.add(e),r.set(e,{cell:i,refs:i.refs.map((e=>e.hash().toString("hex")))});for(let e of i.refs)t.push(e)}}}let o=new Set;function s(e){if(!n.has(e))return;if(o.has(e))throw Error("Not a DAG");o.add(e);let t=r.get(e).refs;for(let e=t.length-1;e>=0;e--)s(t[e]);i.push(e),o.delete(e),n.delete(e)}for(;n.size>0;)s(Array.from(n)[0]);let a=new Map;for(let e=0;e=0;e--){let t=i[e];const n=r.get(t);l.push({cell:n.cell,refs:n.refs.map((e=>a.get(e)))})}return l}(e),n=r.length,i=t.idx,o=t.crc32,s=Math.max(Math.ceil(su(n,"uint")/8),1),a=0,l=[];for(let e of r)a+=hu(e.cell,s),l.push(a);let c=Math.max(Math.ceil(su(a,"uint")/8),1),d=8*(6+3*s+c+1*s+(i?n*c:0)+a+(o?4:0)),u=new Dd(d);if(u.writeUint(3052313714,32),u.writeBit(i),u.writeBit(o),u.writeBit(!1),u.writeUint(0,2),u.writeUint(s,3),u.writeUint(c,8),u.writeUint(n,8*s),u.writeUint(1,8*s),u.writeUint(0,8*s),u.writeUint(a,8*c),u.writeUint(0,8*s),i)for(let e=0;e=4)throw new Error("Too many references");if(e instanceof mu)this._refs.push(e);else{if(!(e instanceof bu))throw new Error("Invalid argument");this._refs.push(e.endCell())}return this}storeMaybeRef(e){return e?(this.storeBit(1),this.storeRef(e)):this.storeBit(0),this}storeSlice(e){let t=e.clone();for(t.remainingBits>0&&this.storeBits(t.loadBits(t.remainingBits));t.remainingRefs>0;)this.storeRef(t.loadRef());return this}storeMaybeSlice(e){return e?(this.storeBit(1),this.storeSlice(e)):this.storeBit(0),this}storeBuilder(e){return this.storeSlice(e.endCell().beginParse())}storeMaybeBuilder(e){return e?(this.storeBit(1),this.storeBuilder(e)):this.storeBit(0),this}storeWritable(e){return"object"==typeof e?e.writeTo(this):e(this),this}storeMaybeWritable(e){return e?(this.storeBit(1),this.storeWritable(e)):this.storeBit(0),this}store(e){return this.storeWritable(e),this}storeStringTail(e){return qd(e,this),this}storeMaybeStringTail(e){return null!=e?(this.storeBit(1),qd(e,this)):this.storeBit(0),this}storeStringRefTail(e){return this.storeRef(yu().storeStringTail(e)),this}storeMaybeStringRefTail(e){return null!=e?(this.storeBit(1),this.storeStringRefTail(e)):this.storeBit(0),this}storeDict(e,t,r){return e?e.store(this,t,r):this.storeBit(0),this}storeDictDirect(e,t,r){return e.storeDirect(this,t,r),this}endCell(e){return new mu({bits:this._bits.build(),refs:this._refs,exotic:e?.exotic})}asCell(){return this.endCell()}asSlice(){return this.endCell().beginParse()}}function wu(e){return yu().storeUint(1,8).storeUint(1,8).storeBuffer(e.hash(0)).storeUint(e.depth(0),16).endCell({exotic:!0})}function vu(e,t,r,n){const i=t.asCell();let o=0,s=e;if(0==(t.loadBit()?1:0)){o=function(e){let t=0;for(;e.loadBit();)t++;return t}(t);for(let e=0;e0&&t.storeUint(BigInt("0b"+e),e.length)}(e,r):"long"===n?function(e,t,r){r.storeBit(1),r.storeBit(0);let n=Math.ceil(Math.log2(t+1));r.storeUint(e.length,n),e.length>0&&r.storeUint(BigInt("0b"+e),e.length)}(e,t,r):"same"===n&&function(e,t,r,n){n.storeBit(1),n.storeBit(1),n.storeBit(e);let i=Math.ceil(Math.log2(r+1));n.storeUint(t,i)}("1"===e[0],e.length,t,r)}function Eu(e,t,r,n){Bu(e.label,t,n),function(e,t,r,n){if("leaf"===e.type&&r(e.value,n),"fork"===e.type){const i=yu(),o=yu();Eu(e.left,t-1,r,i),Eu(e.right,t-1,r,o),n.storeRef(i),n.storeRef(o)}}(e.node,t-e.label.length,r,n)}function Pu(e,t,r,n){const i=function(e,t){let r=new Map;for(let n of Array.from(e.keys())){const i=xu(n.toString(2),t);r.set(i,e.get(n))}return Su(r)}(e,t);Eu(i,t,r,n)}var Iu=r(8287).hp;function Uu(e){if("number"==typeof e){if(!Number.isSafeInteger(e))throw Error("Invalid key type: not a safe integer: "+e);return"n:"+e.toString(10)}if("bigint"==typeof e)return"b:"+e.toString(10);if(Md.isAddress(e))return"a:"+e.toString();if(Iu.isBuffer(e))return"f:"+e.toString("hex");if(Ld.isBitString(e))return"B:"+e.toString();throw Error("Invalid key type")}function Mu(e){let t=e.slice(0,2),r=e.slice(2);if("n:"===t)return parseInt(r,10);if("b:"===t)return BigInt(r);if("a:"===t)return Md.parse(r);if("f:"===t)return Iu.from(r,"hex");if("B:"===t){const e="_"==r.slice(-1);if(e||r.length%2!=0){let t=e?r.length-1:r.length;const n=r.substr(0,t)+"0";return!e&&1&t?new Ld(Iu.from(n,"hex"),0,t<<2):function(e){let t=0;for(let r=e.length-1;r>=0;r--)if(0!==e[r]){const n=e[r];let i=n&-n;1&i||(i=Math.log2(i)+1),r>0&&(t=r<<3),t+=8-i;break}return new Ld(e,0,t)}(Iu.from(n,"hex"))}return new Ld(Iu.from(r,"hex"),0,r.length<<2)}throw Error("Invalid key type: "+t)}var Tu=r(8287).hp;class Ou{static empty(e,t){return e&&t?new Ou(new Map,e,t):new Ou(new Map,null,null)}static load(e,t,r){let n;if(r instanceof mu){if(r.isExotic)return Ou.empty(e,t);n=r.beginParse()}else n=r;let i=n.loadMaybeRef();return i&&!i.isExotic?Ou.loadDirect(e,t,i.beginParse()):Ou.empty(e,t)}static loadDirect(e,t,r){if(!r)return Ou.empty(e,t);let n;n=r instanceof mu?r.beginParse():r;let i=ku(n,e.bits,t.parse),o=new Map;for(let[t,r]of i)o.set(Uu(e.parse(t)),r);return new Ou(o,e,t)}constructor(e,t,r){this._key=t,this._value=r,this._map=e}get size(){return this._map.size}get(e){return this._map.get(Uu(e))}has(e){return this._map.has(Uu(e))}set(e,t){return this._map.set(Uu(e),t),this}delete(e){const t=Uu(e);return this._map.delete(t)}clear(){this._map.clear()}*[Symbol.iterator](){for(const[e,t]of this._map){const r=Mu(e);yield[r,t]}}keys(){return Array.from(this._map.keys()).map((e=>Mu(e)))}values(){return Array.from(this._map.values())}store(e,t,r){if(0===this._map.size)e.storeBit(0);else{let n=this._key;null!=t&&(n=t);let i=this._value;if(null!=r&&(i=r),!n)throw Error("Key serializer is not defined");if(!i)throw Error("Value serializer is not defined");let o=new Map;for(const[e,t]of this._map)o.set(n.serialize(Mu(e)),t);e.storeBit(1);let s=yu();Pu(o,n.bits,i.serialize,s),e.storeRef(s.endCell())}}storeDirect(e,t,r){if(0===this._map.size)throw Error("Cannot store empty dictionary directly");let n=this._key;null!=t&&(n=t);let i=this._value;if(null!=r&&(i=r),!n)throw Error("Key serializer is not defined");if(!i)throw Error("Value serializer is not defined");let o=new Map;for(const[e,t]of this._map)o.set(n.serialize(Mu(e)),t);Pu(o,n.bits,i.serialize,e)}generateMerkleProof(e){return Cu(this,e,this._key)}generateMerkleUpdate(e,t){return function(e,t,r,n){const i=Cu(e,t,r).refs[0];return e.set(t,n),o=i,s=Cu(e,t,r).refs[0],yu().storeUint(4,8).storeBuffer(o.hash(0)).storeBuffer(s.hash(0)).storeUint(o.depth(0),16).storeUint(s.depth(0),16).storeRef(o).storeRef(s).endCell({exotic:!0});var o,s}(this,e,this._key,t)}}Ou.Keys={Address:()=>({bits:267,serialize:e=>{if(!Md.isAddress(e))throw Error("Key is not an address");return yu().storeAddress(e).endCell().beginParse().preloadUintBig(267)},parse:e=>yu().storeUint(e,267).endCell().beginParse().loadAddress()}),BigInt:e=>function(e){return{bits:e,serialize:t=>{if("bigint"!=typeof t)throw Error("Key is not a bigint");return yu().storeInt(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadIntBig(e)}}(e),Int:e=>function(e){return{bits:e,serialize:t=>{if("number"!=typeof t)throw Error("Key is not a number");if(!Number.isSafeInteger(t))throw Error("Key is not a safe integer: "+t);return yu().storeInt(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadInt(e)}}(e),BigUint:e=>function(e){return{bits:e,serialize:t=>{if("bigint"!=typeof t)throw Error("Key is not a bigint");if(t<0)throw Error("Key is negative: "+t);return yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)}}(e),Uint:e=>function(e){return{bits:e,serialize:t=>{if("number"!=typeof t)throw Error("Key is not a number");if(!Number.isSafeInteger(t))throw Error("Key is not a safe integer: "+t);if(t<0)throw Error("Key is negative: "+t);return yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>Number(yu().storeUint(t,e).endCell().beginParse().loadUint(e))}}(e),Buffer:e=>function(e){return{bits:8*e,serialize:t=>{if(!Tu.isBuffer(t))throw Error("Key is not a buffer");return yu().storeBuffer(t).endCell().beginParse().loadUintBig(8*e)},parse:t=>yu().storeUint(t,8*e).endCell().beginParse().loadBuffer(e)}}(e),BitString:e=>function(e){return{bits:e,serialize:t=>{if(!Ld.isBitString(t))throw Error("Key is not a BitString");return yu().storeBits(t).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadBits(e)}}(e)},Ou.Values={BigInt:e=>function(e){return{serialize:(t,r)=>{r.storeInt(t,e)},parse:t=>t.loadIntBig(e)}}(e),Int:e=>function(e){return{serialize:(t,r)=>{r.storeInt(t,e)},parse:t=>t.loadInt(e)}}(e),BigVarInt:e=>function(e){return{serialize:(t,r)=>{r.storeVarInt(t,e)},parse:t=>t.loadVarIntBig(e)}}(e),BigUint:e=>function(e){return{serialize:(t,r)=>{r.storeUint(t,e)},parse:t=>t.loadUintBig(e)}}(e),Uint:e=>function(e){return{serialize:(t,r)=>{r.storeUint(t,e)},parse:t=>t.loadUint(e)}}(e),BigVarUint:e=>function(e){return{serialize:(t,r)=>{r.storeVarUint(t,e)},parse:t=>t.loadVarUintBig(e)}}(e),Bool:()=>({serialize:(e,t)=>{t.storeBit(e)},parse:e=>e.loadBit()}),Address:()=>({serialize:(e,t)=>{t.storeAddress(e)},parse:e=>e.loadAddress()}),Cell:()=>({serialize:(e,t)=>{t.storeRef(e)},parse:e=>e.loadRef()}),Buffer:e=>{return t=e,{serialize:(e,r)=>{if(e.length!==t)throw Error("Invalid buffer size");r.storeBuffer(e)},parse:e=>e.loadBuffer(t)};var t},BitString:e=>function(e){return{serialize:(t,r)=>{if(t.length!==e)throw Error("Invalid BitString size");r.storeBits(t)},parse:t=>t.loadBits(e)}}(e),Dictionary:(e,t)=>function(e,t){return{serialize:(e,t)=>{e.store(t)},parse:r=>Ou.load(e,t,r)}}(e,t)};const Ru=e=>document.querySelector(e),ju=(e,t)=>{e.style.display=t?"flex":"none"};let Lu="startScreen";const zu=e=>{const t=["startScreen","importScreen","multisigScreen","newOrderScreen","orderScreen","loadingScreen","newMultisigScreen1","newMultisigScreen2"];Lu=e;for(const r of t)ju(Ru("#"+r),r===e);"importScreen"===Lu&&(Ru("#import_input").value=""),"newOrderScreen"===Lu&&th&&lh()},Nu=(navigator.language,window.location.href.indexOf("testnet=true")>-1);Nu&&(Ru(".testnet-badge").style.display="block",document.body.classList.add("testnet-padding"));const Du=new class{constructor(e){if(Pe(this,"walletInfoStorage",new Fr),Pe(this,"preferredWalletStorage",new Kr),Pe(this,"walletInfo",null),Pe(this,"systemThemeChangeUnsubscribe",null),Pe(this,"actionsConfiguration"),Pe(this,"walletsList"),Pe(this,"connectRequestParametersCallback"),Pe(this,"connector"),Pe(this,"modal"),Pe(this,"transactionModal"),Pe(this,"connectionRestored",Promise.resolve(!1)),e&&"connector"in e&&e.connector)this.connector=e.connector;else{if(!(e&&"manifestUrl"in e&&e.manifestUrl))throw new Ur("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new oe({manifestUrl:e.manifestUrl})}this.modal=new Fc({connector:this.connector,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new Kc({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return jr((t=e.map((e=>e.imageUrl)),[...new Set(t)]));var t}));const t=this.normalizeWidgetRoot(null==e?void 0:e.widgetRootId);this.subscribeToWalletChange(),!1!==(null==e?void 0:e.restoreConnection)&&(this.connectionRestored=new Promise((e=>Ie(this,null,(function*(){yield this.connector.restoreConnection(),this.connector.connected||this.walletInfoStorage.removeWalletInfo(),e(this.connector.connected)}))))),this.uiOptions=_n(e,{uiPreferences:{theme:"SYSTEM"}});const r=this.preferredWalletStorage.getPreferredWalletAppName();Ya({connector:this.connector,preferredWalletAppName:r}),((e,t)=>{(function(e,t,r,n={}){let i;qe((n=>{i=n,t===document?e():qt(t,e(),t.firstChild?null:void 0,r)}),n.owner)})((()=>kt(Nc,{tonConnectUI:t})),document.getElementById(e))})(t,this)}static getWallets(){return oe.getWallets()}get connected(){return this.connector.connected}get account(){return this.connector.account}get wallet(){return this.connector.wallet?Be(Be({},this.connector.wallet),this.walletInfo):null}set uiOptions(e){var t,r,n,i,o,s,a;this.checkButtonRootExist(e.buttonRootId),this.actionsConfiguration=e.actionsConfiguration,(null==(t=e.uiPreferences)?void 0:t.theme)?"SYSTEM"!==(null==(r=e.uiPreferences)?void 0:r.theme)?(null==(n=this.systemThemeChangeUnsubscribe)||n.call(this),Bn(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(Bn(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?ir.LIGHT:ir.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?ir.DARK:ir.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(Bn))):(null==(i=e.uiPreferences)?void 0:i.colorsSet)&&(s=e.uiPreferences.colorsSet,Sn[ir.DARK]=_n(s[ir.DARK],Sn[ir.DARK]),Sn[ir.LIGHT]=_n(s[ir.LIGHT],Sn[ir.LIGHT]),xn((e=>({colors:_n(Sn[e.theme],An[e.theme])})))),(null==(o=e.uiPreferences)?void 0:o.borderRadius)&&(a=e.uiPreferences.borderRadius,xn({borderRadius:a})),Ya((t=>{var r,n;const i=_n(Be(Be(Be(Be({},e.language&&{language:e.language}),!!(null==(r=e.actionsConfiguration)?void 0:r.returnStrategy)&&{returnStrategy:e.actionsConfiguration.returnStrategy}),!!(null==(n=e.actionsConfiguration)?void 0:n.twaReturnUrl)&&{twaReturnUrl:e.actionsConfiguration.twaReturnUrl}),!!e.walletsListConfiguration&&{walletsListConfiguration:e.walletsListConfiguration}),cn(t));return void 0!==e.buttonRootId&&(i.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(i.enableAndroidBackHandler=e.enableAndroidBackHandler),i}))}setConnectRequestParameters(e){var t;Ya({connectRequestParameters:e}),"ready"!==(null==e?void 0:e.state)&&e||null==(t=this.connectRequestParametersCallback)||t.call(this,null==e?void 0:e.value)}getWallets(){return Ie(this,null,(function*(){return this.connector.getWallets()}))}onStatusChange(e,t){return this.connector.onStatusChange((t=>Ie(this,null,(function*(){if(t){const r=yield this.getSelectedWalletInfo(t);e(Be(Be({},t),r||this.walletInfoStorage.getWalletInfo()))}else e(t)}))),t)}openModal(){return Ie(this,null,(function*(){return this.modal.open()}))}closeModal(){this.modal.close()}onModalStateChange(e){return this.modal.onStateChange(e)}get modalState(){return this.modal.state}connectWallet(){return Ie(this,null,(function*(){const e=(yield this.getWallets()).find(ee);return e?yield this.connectEmbeddedWallet(e):yield this.connectExternalWallet()}))}disconnect(){return setTimeout((()=>Xr(null))),Qr(null),this.walletInfoStorage.removeWalletInfo(),this.connector.disconnect()}sendTransaction(e,t){return Ie(this,null,(function*(){if(!this.connected)throw new Ur("Connect wallet to send a transaction.");On()&&Rn();const{notifications:r,modals:n,returnStrategy:i,twaReturnUrl:o,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);$c({name:"confirm-transaction",showNotification:r.includes("before"),openModal:n.includes("before")});const a=()=>{const e="ios"===Nr().os,t="ios"===s&&e||"always"===s;this.walletInfo&&"universalLink"in this.walletInfo&&"universal-link"===this.walletInfo.openMethod&&!t&&(L(this.walletInfo.universalLink)?El(this.walletInfo.universalLink,{returnStrategy:i,twaReturnUrl:o||Ga.twaReturnUrl,forceRedirect:!1}):Tr(Bl(this.walletInfo.universalLink,i)))},l=new AbortController,c=this.onTransactionModalStateChange((e=>{(null==e?void 0:e.openModal)||(c(),e||l.abort())}));try{const t=yield this.waitForSendTransaction({transaction:e,abortSignal:l.signal},a);return $c({name:"transaction-sent",showNotification:r.includes("success"),openModal:n.includes("success")}),t}catch(e){throw $c({name:"transaction-canceled",showNotification:r.includes("error"),openModal:n.includes("error")}),e instanceof m?e:(console.error(e),new Ur("Unhandled error:"+e))}finally{c()}}))}connectEmbeddedWallet(e){return Ie(this,null,(function*(){const t=t=>{Qr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},r=Ga.connectRequestParameters;return"loading"===(null==r?void 0:r.state)?this.connectRequestParametersCallback=t:t(null==r?void 0:r.value),yield this.waitForWalletConnection({ignoreErrors:!1})}))}connectExternalWallet(){return Ie(this,null,(function*(){const e=new AbortController;Dc();const t=this.onModalStateChange((r=>{const{status:n,closeReason:i}=r;"opened"!==n&&(t(),"action-cancelled"===i&&e.abort())}));return yield this.waitForWalletConnection({ignoreErrors:!0,abortSignal:e.signal})}))}waitForWalletConnection(e){return Ie(this,null,(function*(){return new Promise(((t,r)=>{const{ignoreErrors:n=!1,abortSignal:i=null}=e;if(i&&i.aborted)return r(new Ur("Wallet was not connected"));const o=e=>Ie(this,null,(function*(){if(e)s(),t(e);else{if(n)return;s(),r(new Ur("Wallet was not connected"))}})),s=this.onStatusChange((e=>o(e)),(e=>(e=>{n||(s(),r(e))})(e)));i&&i.addEventListener("abort",(()=>{s(),r(new Ur("Wallet was not connected"))}))}))}))}waitForSendTransaction(e,t){return Ie(this,null,(function*(){return new Promise(((r,n)=>{const{transaction:i,abortSignal:o}=e;if(o.aborted)return n(new Ur("Transaction was not sent"));const s=e=>Ie(this,null,(function*(){r(e)}));this.connector.sendTransaction(i,t).then((e=>s(e))).catch((e=>(e=>{n(e)})(e))),o.addEventListener("abort",(()=>{n(new Ur("Transaction was not sent"))}))}))}))}onTransactionModalStateChange(e){return this.transactionModal.onStateChange(e)}subscribeToWalletChange(){this.connector.onStatusChange((e=>Ie(this,null,(function*(){var t;e?(yield this.updateWalletInfo(e),this.setPreferredWalletAppName((null==(t=this.walletInfo)?void 0:t.appName)||e.device.appName)):this.walletInfoStorage.removeWalletInfo()}))))}setPreferredWalletAppName(e){this.preferredWalletStorage.setPreferredWalletAppName(e),Ya({preferredWalletAppName:e})}getSelectedWalletInfo(e){return Ie(this,null,(function*(){let t,r=Gr();if(!r)return null;if("name"in r)t=r;else{const n=Ja(yield this.walletsList,Ga.walletsListConfiguration).find((t=>rl(t,e.device.appName)));if(!n)throw new Ur(`Cannot find WalletInfo for the '${e.device.appName}' wallet`);t=Be(Be({},n),r)}return t}))}updateWalletInfo(e){return Ie(this,null,(function*(){const t=yield this.getSelectedWalletInfo(e);if(t)return this.walletInfo=t,void this.walletInfoStorage.setWalletInfo(t);const r=this.walletInfoStorage.getWalletInfo();this.walletInfo=r||(yield this.walletsList).find((t=>rl(t,e.device.appName)))||null}))}normalizeWidgetRoot(e){if(!e||!document.getElementById(e)){e="tc-widget-root";const t=document.createElement("div");t.id=e,document.body.appendChild(t)}return e}checkButtonRootExist(e){if(null!=e&&!document.getElementById(e))throw new Ur(`${e} element not found in the document.`)}getModalsAndNotificationsConfiguration(e){var t,r,n,i,o,s;const a=["before","success","error"];let l=a;(null==(t=this.actionsConfiguration)?void 0:t.notifications)&&"all"!==(null==(r=this.actionsConfiguration)?void 0:r.notifications)&&(l=this.actionsConfiguration.notifications),(null==e?void 0:e.notifications)&&(l="all"===e.notifications?a:e.notifications);let c=["before"];(null==(n=this.actionsConfiguration)?void 0:n.modals)&&(c="all"===this.actionsConfiguration.modals?a:this.actionsConfiguration.modals),(null==e?void 0:e.modals)&&(c="all"===e.modals?a:e.modals);const d=(null==e?void 0:e.returnStrategy)||(null==(i=this.actionsConfiguration)?void 0:i.returnStrategy)||"back",u=(null==e?void 0:e.twaReturnUrl)||(null==(o=this.actionsConfiguration)?void 0:o.twaReturnUrl);let h=(null==e?void 0:e.skipRedirectToWallet)||(null==(s=this.actionsConfiguration)?void 0:s.skipRedirectToWallet)||"ios";return On()&&(h="never"),{notifications:l,modals:c,returnStrategy:d,twaReturnUrl:u,skipRedirectToWallet:h}}}({manifestUrl:"https://multisig.ton.org/tonconnect-manifest.json",buttonRootId:"tonConnectButton"});let $u;Du.uiOptions={uiPreferences:{theme:ir.LIGHT}},Du.onStatusChange((e=>{null===e?$u=null:e.account&&($u=a.Address.parseRaw(e.account.address))})),Ru("#createMultisigButton").addEventListener("click",(()=>{fh(),mh="create",zu("newMultisigScreen1")})),Ru("#importMultisigButton").addEventListener("click",(()=>{zu("importScreen")})),Ru("#import_okButton").addEventListener("click",(()=>{const e=Ru("#import_input").value,t=Wc(e,Nu);t?alert(t):Hu(e)})),Ru("#import_backButton").addEventListener("click",(()=>{zu("startScreen")}));const Fu=a.Cell.fromBase64("te6cckECEgEABJUAART/APSkE/S88sgLAQIBYgIDAsrQM9DTAwFxsJJfA+D6QDAi10nAAJJfA+AC0x8BIMAAkl8E4AHTPwHtRNDT/wEB0wcBAdTTBwEB9ATSAAEB0SiCEPcYUQ+64w8FREPIUAYBy/9QBAHLBxLMAQHLB/QAAQHKAMntVAQFAgEgDA0BnjgG0/8BKLOOEiCE/7qSMCSWUwW68uPw4gWkBd4B0gABAdMHAQHTLwEB1NEjkSaRKuJSMHj0Dm+h8uPvHscF8uPvIPgjvvLgbyD4I6FUbXAGApo2OCaCEHUJf126jroGghCjLFm/uo6p+CgYxwXy4GUD1NEQNBA2RlD4AH+OjSF49HxvpSCRMuMNAbPmWxA1UDSSNDbiUFQT4w1AFVAzBAoJAdT4BwODDPlBMAODCPlBMPgHUAahgSf4AaBw+DaBEgZw+DaggSvscPg2oIEdmHD4NqAipgYioIEFOSagJ6Bw+DgjpIECmCegcPg4oAOmBliggQbgUAWgUAWgQwNw+DdZoAGgHL7y4GT4KFADBwK4AXACyFjPFgEBy//JiCLIywH0APQAywDJcCH5AHTIywISygfL/8nQyIIQnHP7olgKAssfyz8mAcsHUlDMUAsByy8bzCoBygAKlRkBywcIkTDiECRwQImAGIBQ2zwRCACSjkXIWAHLBVAFzxZQA/oCVHEjI+1E7UXtR59byFADzxfJE3dQA8trzMztZ+1l7WR0f+0RmHYBy2vMAc8X7UHt8QHy/8kB+wDbBgLiNgTT/wEB0y8BAdMHAQHT/wEB1NH4KFAFAXACyFjPFgEBy//JiCLIywH0APQAywDJcAH5AHTIywISygfL/8nQG8cF8uBlJvkAGrpRk74ZsPLgZgf4I77y4G9EFFBW+AB/jo0hePR8b6UgkTLjDQGz5lsRCgH6AtdM0NMfASCCEPE4Hlu6jmqCEB0M+9O6jl5sRNMHAQHUIX9wjhdREnj0fG+lMiGZUwK68uBnAqQC3gGzEuZsISDCAPLgbiPCAPLgbVMwu/LgbQH0BCF/cI4XURJ49HxvpTIhmVMCuvLgZwKkAt4BsxLmbCEw0VUjkTDi4w0LABAw0wfUAvsA0QFDv3T/aiaGn/gIDpg4CA6mmDgID6AmkAAIDoiBqvgoD8EdDA4CAWYPEADC+AcDgwz5QTADgwj5QTD4B1AGoYEn+AGgcPg2gRIGcPg2oIEr7HD4NqCBHZhw+DagIqYGIqCBBTkmoCegcPg4I6SBApgnoHD4OKADpgZYoIEG4FAFoFAFoEMDcPg3WaABoADxsMr7UTQ0/8BAdMHAQHU0wcBAfQE0gABAdEjf3COF1ESePR8b6UyIZlTArry4GcCpALeAbMS5mwhUjC68uBsIX9wjhdREnj0fG+lMiGZUwK68uBnAqQC3gGzEuZsITAiwgDy4G4kwgDy4G1SQ7vy4G0BkjN/kQPiA4AFZsMn+CgBAXACyFjPFgEBy//JiCLIywH0APQAywDJcAH5AHTIywISygfL/8nQgEQhCAmMFqAYchWwszwXcsN9YFccUdYcFZ8q18EnjQLz1klHzYNH/nQ=="),Ku=a.Cell.fromBase64("te6cckEBAQEAIwAIQgJjBagGHIVsLM8F3LDfWBXHFHWHBWfKtfBJ40C89ZJR80AoJo0=");let Vu=null;const Hu=async e=>{zu("loadingScreen");const t=a.Address.parseFriendly(e);t.isBounceable=!0,t.isTestOnly=Nu,Ru("#mulisig_address").innerHTML=Yc(t),localStorage.setItem("multisigAddress",e),ju(Ru("#multisig_content"),!1),ju(Ru("#multisig_error"),!1);try{Vu=await(async(e,t,r,n)=>{const i=await qc("account",{address:Qc(e)},r);Xc("active"===i.status,"Contract not active"),Xc(a.Cell.fromBase64(i.code).equals(t),"The contract code DOES NOT match the multisig code from this repository");const o=i.balance,s=function(e){const t=e.beginParse(),r=t.loadUintBig(256),n=t.loadUint(8),i=id(t.loadRef()),o=t.loadUint(8),s=id(t.loadMaybeRef()),a=t.loadBit();return od(t),{nextOderSeqno:r,threshold:n,signers:i,signersCount:o,proposers:s,allowArbitraryOrderSeqno:a}}(a.Cell.fromBase64(i.data));s.allowArbitraryOrderSeqno&&Xc(s.nextOderSeqno===BigInt(0),"invalid nextOrderSeqno for allowArbitraryOrderSeqno");const l=s.signers,c=s.proposers;Xc(l.length===s.signersCount,"invalid signersCount"),Xc(s.threshold>0,"threshold <= 0"),Xc(s.threshold<=s.signersCount,"invalid threshold");const d=sd.createFromAddress(e.address),u=new Zc(e.address,r),h=await d.getMultisigData(u);s.allowArbitraryOrderSeqno?Xc(h.nextOrderSeqno===BigInt(-1),"nextOderSeqno doesn't match"):Xc(h.nextOrderSeqno===s.nextOderSeqno,"nextOderSeqno doesn't match"),Xc(h.threshold===BigInt(s.threshold),"threshold doesn't match"),Xc(Jc(h.signers,s.signers),"invalid signers"),Xc(Jc(h.proposers,s.proposers),"invalid proposers");const f=sd.createFromConfig({threshold:s.threshold,signers:s.signers,proposers:s.proposers,allowArbitrarySeqno:s.allowArbitraryOrderSeqno},t).address.equals(e.address),p=[];if(n){const t=await qc("transactions",{account:Qc(e)},r);for(const e of t.transactions){if(!e.in_msg.message_content)continue;if(!e.in_msg.message_content.body)continue;const t=a.Cell.fromBase64(e.in_msg.message_content.body).beginParse();if(t.remainingBits<32)continue;const n=t.loadUint(32);if(1963556701===n)try{t.loadUintBig(64);const n=t.loadUintBig(256),i=a.Address.parse(e.in_msg.source),o=await d.getOrderAddress(u,n);if(!i.equals(o))throw new Error("fake order");p.push({type:"execute",order:{address:{address:i,isBounceable:!0,isTestOnly:r},id:n}})}catch(e){p.push({type:"execute",errorMessage:e.message})}else if(4145565967===n)try{if(1!==e.out_msgs.length)throw new Error("invalid out messages");const n=e.out_msgs[0],{orderAddress:i,orderId:o}=ld(n),s=await d.getOrderAddress(u,o);if(!i.equals(s))throw new Error("fake order");const l=t.loadUint(64),c=(t.loadUint(256),t.loadUint(1)),h=t.loadUint(8),f=t.loadUint(48),g=t.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell());od(t),console.log("IN",{queryId:l,orderId:o,orderAddress:i.toString(),isSigner:c,index:h,expiredAt:f,order:g}),p.push({type:"new",order:{address:{address:i,isBounceable:!0,isTestOnly:r},id:o}})}catch(e){console.log(e),p.push({type:"new",errorMessage:"Invalid new order: "+e.message})}}}return{address:e,multisigContract:d,provider:u,signers:l,proposers:c,threshold:s.threshold,allowArbitraryOrderSeqno:s.allowArbitraryOrderSeqno,nextOderSeqno:s.nextOderSeqno,tonBalance:o,lastOrders:p,stateInitMatches:f}})(a.Address.parseFriendly(e),Fu,Nu,!0);const{tonBalance:t,threshold:r,signers:n,proposers:i,allowArbitraryOrderSeqno:o,nextOderSeqno:s,lastOrders:l}=Vu;Ru("#multisig_tonBalance").innerText=(0,a.fromNano)(t)+" TON",Ru("#multisig_threshold").innerText=r+"/"+n.length;let c="";for(let e=0;e#${e} - ${await Gc(t,Nu)}`}if(Ru("#multisig_signersList").innerHTML=c,i.length>0){let e="";for(let t=0;t#${t} - ${await Gc(r,Nu)}`}Ru("#multisig_proposersList").innerHTML=e}else Ru("#multisig_proposersList").innerHTML="No proposers";Ru("#multisig_orderId").innerText=o?"Arbitrary":s.toString();let d="";for(const e of l)e.errorMessage||(d+=`
${"new"===e.type?"New order":"Executed order"} #${e.order.id}
`);Ru("#mainScreen_ordersList").innerHTML=d,(".multisig_lastOrder",document.querySelectorAll(".multisig_lastOrder")).forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.attributes.getNamedItem("order-address").value;Zu(t)}))})),zu("multisigScreen"),ju(Ru("#multisig_content"),!0)}catch(e){console.error(e),zu("multisigScreen"),ju(Ru("#multisig_error"),!0),Ru("#multisig_error").innerText=e.message}};Ru("#multisig_logoutButton").addEventListener("click",(()=>{localStorage.removeItem("multisigAddress"),zu("startScreen")})),Ru("#multisig_createNewOrderButton").addEventListener("click",(()=>{zu("newOrderScreen")}));let qu=null;const Zu=async e=>{zu("loadingScreen");const t=a.Address.parseFriendly(e);t.isBounceable=!0,t.isTestOnly=Nu,Ru("#order_address").innerHTML=Yc(t),ju(Ru("#order_content"),!1),ju(Ru("#order_error"),!1);try{qu=await(async(e,t,r,n)=>{const i=await qc("account",{address:Qc(e)},n);Xc("active"===i.status,"Contract not active"),Xc(a.Cell.fromBase64(i.code).equals(t),"The contract code DOES NOT match the multisig-order code from this repository");const o=i.balance,s=function(e){const t=e.beginParse(),r=t.loadAddress(),n=t.loadUintBig(256);if(0===t.remainingBits)throw new Error("Order not initialized");const i=t.loadUint(8),o=t.loadBoolean(),s=cd(t.loadRef()),a=t.loadUint(256),l=t.loadUint(8),c=t.loadUint(48),d=t.loadRef();return od(t),{multisigAddress:r,orderSeqno:n,threshold:i,isExecuted:o,signers:s,approvalsMask:a,approvalsNum:l,expirationDate:c,order:d}}(a.Cell.fromBase64(i.data));wd(s.threshold),Xc(s.threshold>0,"threshold <= 0"),Xc(s.threshold<=s.signers.length,"threshold invalid"),wd(s.approvalsMask),wd(s.approvalsNum),Xc(s.approvalsNum<=s.signers.length,"approvalsNum invalid"),wd(s.expirationDate),Xc(s.multisigAddress.equals(r.address.address),"multisig address does not match");const l=await r.multisigContract.getOrderAddress(r.provider,s.orderSeqno);Xc(l.equals(e.address),"fake multisig-order"),s.isExecuted||(Xc(r.threshold===s.threshold,"multisig threshold != order threshold"),Xc(Jc(r.signers,s.signers),"multisig signers != order signers"));const c=new Zc(e.address,n),d=dd.createFromAddress(e.address),u=await d.getOrderDataStrict(c);Xc(u.multisig.equals(s.multisigAddress),"invalid multisigAddress"),Xc(u.order_seqno===s.orderSeqno,"invalid orderSeqno"),Xc(u.threshold===s.threshold,"invalid threshold"),Xc(u.executed===s.isExecuted,"invalid isExecuted"),Xc(Jc(u.signers,s.signers),"invalid signers"),Xc(u._approvals===BigInt(s.approvalsMask),"invalid approvalsMask"),Xc(u.approvals_num===s.approvalsNum,"invalid approvalsNum"),Xc(u.expiration_date===BigInt(s.expirationDate),"invalid expirationDate"),Xc(u.order.hash().equals(s.order.hash()),"invalid order");const h=dd.createFromConfig({multisig:s.multisigAddress,orderSeqno:s.orderSeqno},t).address.equals(e.address),f=a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell(),s.order),p=async e=>{try{const t=e.beginParse();if(0===t.remainingBits&&0==t.remainingRefs)return"Send Toncoins without comment"}catch(e){}try{const t=e.beginParse();if(0==t.loadUint(32)){const e=t.loadStringTail();return`Send Toncoins with comment "${encodeURI(e)}"`}}catch(e){}try{const t=e.beginParse(),r=bd.parseMintMessage(t);Xc(0===r.internalMessage.forwardPayload.remainingBits&&0===r.internalMessage.forwardPayload.remainingRefs,"forward payload not supported");const i=await Gc(r.toAddress,n);return`Mint ${r.internalMessage.jettonAmount} jettons (in units) to ${i}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse();return bd.parseTopUp(t),"Top Up"}catch(e){}try{const t=e.beginParse(),r=bd.parseChangeAdmin(t);return`Change Admin to ${await Gc(r.newAdminAddress,n)}`}catch(e){}try{const t=e.beginParse();return bd.parseClaimAdmin(t),"Claim Admin"}catch(e){}try{const t=e.beginParse();return`Change metadata URL to "${bd.parseChangeContent(t).newMetadataUrl}"`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseSetStatus),i=await Gc(r.toAddress,n),o=(e=>{switch(e){case 0:return"unlock";case 1:return"out";case 2:return"in";case 3:return"full";default:throw new Error("Invalid argument!")}})(r.action.newStatus);return`Lock jetton wallet of user ${i}. Set status "${o}" - "${md(o)}"; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseTransfer);if(r.action.customPayload)throw new Error("custom payload not supported");Xc(0===r.action.forwardPayload.remainingBits&&0===r.action.forwardPayload.remainingRefs,"forward payload not supported");const i=await Gc(r.toAddress,n),o=await Gc(r.action.toAddress,n);return`Force transfer ${r.action.jettonAmount} jettons (in units) from user ${i} to ${o}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseBurn);if(r.action.customPayload)throw new Error("custom payload not supported");const i=await Gc(r.toAddress,n);return`Force burn ${r.action.jettonAmount} jettons (in units) from user ${i}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}throw new Error("Unknown action")};let g=[];const m=f.keys();for(let e of m){let t=`
Action #${e}:
`;const r=f.get(e).beginParse(),i=r.loadUint(32);if(4046986843===i){const e=r.loadUint(8);let i=[],o=!1;1&e&&i.push("Pays fees separately"),2&e&&i.push("Ignore sending errors"),128&e&&(o=!0,i.push("CARRY ALL BALANCE")),64&e&&i.push("Carry all the remaining value of the inbound message"),32&e&&i.push("DESTROY ACCOUNT");const s=r.loadRef();od(r);const l=(0,a.loadMessageRelaxed)(s.beginParse());console.log(l);const c=l.info,d=await Gc(c.dest,n);t+=`
Send ${o?"ALL BALANCE":(0,a.fromNano)(c.value.coins)} TON to ${d}
`,t+=`
${await p(l.body)}
`,e&&(t+=`
Send mode: ${i.join(", ")}.
`)}else{if(487390163!==i)throw new Error("unknown action op");{const e=r.loadUint(8),i=id(r.loadRef()),o=r.loadUint(1)?id(r.loadRef()):[];od(r),Xc(i.length>0,"invalid new signers"),Xc(e>0,"invalid new threshold"),Xc(e<=i.length,"invalid new threshold"),t+="
Update Multisig Params
",t+=`
New threshold : ${e.toString()}
`,t+="
New signers:
";for(let e=0;e#${e} - ${await Gc(r,n)}`}if(t+="
New proposers:
",o.length>0)for(let e=0;e#${e} - ${await Gc(r,n)}`}else t+="
No poroposers
"}}g.push(t)}return{address:e,tonBalance:o,orderId:s.orderSeqno,isExecuted:s.isExecuted,approvalsNum:s.approvalsNum,approvalsMask:s.approvalsMask,threshold:s.threshold,signers:s.signers,expiresAt:new Date(1e3*s.expirationDate),actions:g,stateInitMatches:h}})(t,Ku,Vu,Nu);const{tonBalance:e,actions:r,orderId:n,isExecuted:i,approvalsNum:o,approvalsMask:s,threshold:l,signers:c,expiresAt:d}=qu,u=(new Date).getTime()>d.getTime();Ru("#order_id").innerText="#"+n,Ru("#order_tonBalance").innerText=(0,a.fromNano)(e)+" TON",Ru("#order_executed").innerText=i?"Yes":"Not yet",Ru("#order_approvals").innerText=o+"/"+l,Ru("#order_expiresAt").innerText=(u?"❌ EXPIRED - ":"")+d.toString();let h="";for(let e=0;e#${e} - ${await Gc(t,Nu)} - ${s&1<`}Ru("#order_signersList").innerHTML=h;let f="";for(const e of r)f+=e;0===r.length?Ru("#order_actionsTitle").innerText="No actions":1===r.length?Ru("#order_actionsTitle").innerText="One action:":Ru("#order_actionsTitle").innerText=r.length+" actions:",Ru("#order_actions").innerHTML=f,ju(Ru("#order_approveButton"),!i&&!u),ju(Ru("#order_approveNote"),!i&&!u),zu("orderScreen"),ju(Ru("#order_content"),!0)}catch(e){console.error(e),zu("orderScreen"),ju(Ru("#order_error"),!0),Ru("#order_error").innerText=e.message}};Ru("#order_backButton").addEventListener("click",(()=>{zu("multisigScreen")})),Ru("#order_approveButton").addEventListener("click",(async()=>{if(!$u)return void alert("Please connect wallet");if(-1==qu.signers.findIndex((e=>e.equals($u))))return void alert("You are not signer");const e=Qc(qu.address),t=Yu.toString(),r=(0,a.beginCell)().storeUint(0,32).storeStringTail("approve").endCell().toBoc().toString("base64");console.log({orderAddressString:e,amount:t});const n={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:e,amount:t,payload:r}]};try{await Du.sendTransaction(n),await Zu(e)}catch(e){console.error(e)}}));const Wu=(e,t,r)=>{const n=t=>({error:e+": "+t}),i=e=>({value:e});if(null==t||""===t)return n("Empty");switch(r){case"TON":return((e,t)=>{try{const r=function(e,t){const r=function(e){let t=1n;for(let r=0;r2)throw Error("Invalid number");let o=i[0],s=i[1];if(o||(o="0"),s||(s="0"),s.length>t)throw Error("Invalid number");for(;s.length{try{const t=BigInt(e);return t<=0?n("Enter positive amount"):i(t)}catch(e){return n("Invalid amount")}})(t);case"Address":if(!a.Address.isFriendly(t))return n("Invalid Address");const e=a.Address.parseFriendly(t);return e.isTestOnly&&!Nu?n("Please enter mainnet address"):i(e);case"URL":return t.startsWith("https://")?i(t):n("Invalid URL");case"Status":return pd.indexOf(t)>-1?i(t):n("Invalid status. Please use: "+pd.join(", "))}},Gu=(0,a.toNano)("0.2"),Yu=(0,a.toNano)("0.1"),Qu=(0,a.toNano)("0.05"),Ju=async e=>{try{const t=await kd(e.jettonMinterAddress,Nu,!1);return Vu.address.address.equals(t.adminAddress)?{value:t}:{error:"Multisig is not admin of this jetton"}}catch(e){return console.error(e),{error:"Jetton-minter check error"}}},Xu=async e=>{try{const t=await Vu.multisigContract.getOrderAddress(Vu.provider,e);return"uninit"===(await qc("account",{address:t.toRawString()},Nu)).status?{value:!0}:{error:`Order ${e} already exists`}}catch(e){return console.error(e),{error:"Possibly connectivity error"}}},eh=[{name:"Transfer TON",fields:{amount:{name:"TON Amount",type:"TON"},toAddress:{name:"Destination Address",type:"Address"}},makeMessage:e=>({toAddress:e.toAddress,tonAmount:e.amount,body:(0,a.beginCell)().endCell()})},{name:"Change Jetton Admin",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},newAdminAddress:{name:"New Admin Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.changeAdminMessage(e.newAdminAddress.address)})},{name:"Claim Jetton Admin",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"}},check:async e=>{try{const t=await kd(e.jettonMinterAddress,Nu,!0);return t.nextAdminAddress&&Vu.address.address.equals(t.nextAdminAddress)?{value:t}:{error:"Multisig is not next-admin of this jetton"}}catch(e){return console.error(e),{error:"Jetton-minter check error"}}},makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.claimAdminMessage()})},{name:"Top-up Jetton Minter",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"TON Amount",type:"TON"}},makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:e.amount,body:bd.topUpMessage()})},{name:"Change Jetton Metadata URL",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},newMetadataUrl:{name:"New Metadata URL",type:"URL"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.changeContentMessage({uri:e.newMetadataUrl})})},{name:"Mint Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},toAddress:{name:"To Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.mintMessage(e.toAddress.address,e.amount,e.jettonMinterAddress.address,Vu.address.address,null,0n,Qu)})},{name:"Force Burn Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},fromAddress:{name:"User Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.forceBurnMessage(e.amount,e.fromAddress.address,Vu.address.address,Qu)})},{name:"Force Transfer Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},fromAddress:{name:"From Address",type:"Address"},toAddress:{name:"To Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.forceTransferMessage(e.amount,e.toAddress.address,e.fromAddress.address,e.jettonMinterAddress.address,null,0n,null,Qu)})},{name:"Set status for Jetton Wallet",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},userAddress:{name:"User Address",type:"Address"},newStatus:{name:`New Status (${pd.join(", ")})`,type:"Status"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.lockWalletMessage(e.userAddress.address,gd(e.newStatus),Qu)})}],th=Ru("#newOrder_typeInput");th.innerHTML=(()=>{let e="";for(let t=0;t${eh[t].name}`;return e})();const rh=e=>{const t=eh[e];let r="";for(let n in t.fields)if(t.fields.hasOwnProperty(n)){const i=t.fields[n];if(r+=`
${i.name}:
`,"Status"===i.type){r+=`"}else r+=``}Ru("#newOrder_fieldsContainer").innerHTML=r};th.addEventListener("change",(e=>{rh(th.selectedIndex)})),rh(0);const nh=e=>{Ru("#newOrder_createButton").disabled=e,Ru("#newOrder_backButton").disabled=e},ih=e=>{const t=th.selectedIndex,r=eh[t];th.disabled=e,Ru("#newOrder_orderId").disabled=e;for(let n in r.fields)r.fields.hasOwnProperty(n)&&(Ru(`#newOrder_${t}_${n}`).disabled=e);nh(e)};let oh="fill",sh=null;const ah=e=>{"fill"==e?(ih(!1),Ru("#newOrder_createButton").innerHTML="Create",Ru("#newOrder_backButton").innerHTML="Back"):(Ru("#newOrder_createButton").innerHTML="Send Transaction",Ru("#newOrder_backButton").innerHTML="Cancel"),oh=e};Ru("#newOrder_createButton").addEventListener("click",(async()=>{if("confirm"===oh){if(!sh)throw new Error("");try{await Du.sendTransaction({validUntil:Math.floor(Date.now()/1e3)+60,messages:[sh]}),zu("multisigScreen")}catch(e){console.error(e)}return}const e=gh(Ru("#newOrder_orderId"));if(null===e||e<0)return void alert("Invalid Order ID");const t=th.selectedIndex,r=eh[t],n={};for(let e in r.fields)if(r.fields.hasOwnProperty(e)){const i=r.fields[e],o=Ru(`#newOrder_${t}_${e}`).value,s=Wu(i.name,o,i.type);if(s.error)return void alert(s.error);n[e]=s.value}ih(!0);const i=await Xu(e);if(i.error)return alert(i.error),void ah("fill");if(r.check){const e=await r.check(n);if(e.error)return alert(e.error),void ah("fill")}const o=r.makeMessage(n),s=Vu.proposers.findIndex((e=>e.equals($u))),l=Vu.signers.findIndex((e=>e.equals($u)));if(-1===s&&-1===l)return void alert("Error: you are not proposer and not signer");const c=l>-1,d=o.toAddress,u=o.tonAmount,h=o.body,f=Math.floor(Date.now()/1e3)+2592e3,p=sd.packOrder([{type:"transfer",sendMode:a.SendMode.PAY_GAS_SEPARATELY,message:{info:{type:"internal",ihrDisabled:!1,bounce:!0,bounced:!1,dest:d.address,value:{coins:u},ihrFee:0n,forwardFee:0n,createdLt:0n,createdAt:0},body:h}}]),g=sd.newOrderMessage(p,f,c,c?l:s,e,0n),m=g.toBoc().toString("base64");console.log({toAddress:d,tonAmount:u,payloadCell:h,message:g,orderId:e});const y=Qc(Vu.address),b=Gu.toString();sh={address:y,amount:b,payload:m},ah("confirm"),nh(!1)})),Ru("#newOrder_backButton").addEventListener("click",(()=>{"fill"==oh?zu("multisigScreen"):ah("fill")}));const lh=()=>{ah("fill"),sh=null,th.selectedIndex=0,rh(0),Ru("#newOrder_orderId").value=""},ch=Ru("#newMultisig_signersCount"),dh=Ru("#newMultisig_proposersCount"),uh=Ru("#newMultisig_threshold"),hh=Ru("#newMultisig_orderId"),fh=()=>{ch.value="",dh.value="",uh.value="",ju(Ru("#newMultisig_orderIdLabel"),"update"===mh),ju(Ru("#newMultisig_orderId"),"update"===mh)},ph=e=>{if(""==e.value)return null;try{const t=parseInt(e.value);return isNaN(t)?null:t}catch(e){return null}},gh=e=>{if(""==e.value)return null;try{return BigInt(e.value)}catch(e){return null}};let mh="create",yh=null;Ru("#newMultisig1_nextButton").addEventListener("click",(async()=>{const e=ph(ch);if(null===e||e<=0)return void alert("Signers count: not valid number");const t=ph(dh);if(null===t||t<0)return void alert("Proposers count: not valid number");const r=ph(uh);if(null===r||r<=0||r>e)return void alert("Threshold count: not valid number");let n;if("update"===mh){if(n=gh(hh),null===n||n<0)return void alert("Invalid order Id");Ru("#newMultisig1_nextButton").disabled=!0,Ru("#newMultisigScreen1").style.pointerEvents="none";const e=await Xu(n);if(Ru("#newMultisig1_nextButton").disabled=!1,Ru("#newMultisigScreen1").style.pointerEvents="auto",e.error)return void alert(e.error)}yh={signersCount:e,proposersCount:t,threshold:r,orderId:n};let i="";for(let t=0;t
#${t}.
`;Ru("#newMultisig_signers").innerHTML=i;let o="";for(let e=0;e
#${e}.
`;Ru("#newMultisig_proposers").innerHTML=o,Ru("#newMultisig2_createButton").innerText="create"===mh?"Create":"Update",zu("newMultisigScreen2")})),Ru("#newMultisig1_backButton").addEventListener("click",(()=>{zu("create"===mh?"startScreen":"multisigScreen")})),Ru("#newMultisig2_createButton").addEventListener("click",(async()=>{const e={},t=[];for(let r=0;r{null!=n.splitDepth?(e.storeBit(!0),e.storeUint(n.splitDepth,5)):e.storeBit(!1),null!=n.special?(e.storeBit(!0),e.store(function(e){return t=>{t.storeBit(e.tick),t.storeBit(e.tock)}}(n.special))):e.storeBit(!1),e.storeMaybeRef(n.code),e.storeMaybeRef(n.data),e.storeDict(n.libraries)})(s),console.log({stateInitCell:s.endCell()});const l={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:i.toString({urlSafe:!0,bounceable:!0,testOnly:Nu}),amount:o,stateInit:s.endCell().toBoc().toString("base64")}]};try{await Du.sendTransaction(l),Hu(Qc({address:i,isBounceable:!0,isTestOnly:Nu}))}catch(e){console.error(e)}}else{const e=Vu.proposers.findIndex((e=>e.equals($u))),n=Vu.signers.findIndex((e=>e.equals($u)));if(-1===e&&-1===n)return void alert("Error: you are not proposer and not signer");const i=n>-1,o=Math.floor(Date.now()/1e3)+2592e3,s=sd.packOrder([{type:"update",threshold:yh.threshold,signers:t,proposers:r}]),a=sd.newOrderMessage(s,o,i,i?n:e,yh.orderId,0n).toBoc().toString("base64"),l=Qc(Vu.address),c=Yu.toString(),d={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:l,amount:c,payload:a}]};try{await Du.sendTransaction(d),Hu(l)}catch(e){console.error(e)}}var n})),Ru("#newMultisig2_backButton").addEventListener("click",(()=>{zu("newMultisigScreen1")})),Ru("#multisig_updateButton").addEventListener("click",(()=>{mh="update",fh(),zu("newMultisigScreen1")}));let bh=localStorage.getItem("multisigAddress");bh?Hu(bh):zu("startScreen")})()})(); \ No newline at end of file +`,Oc=e=>{const t=Gn(e),r=nt(Bs),[n,i]=Ze(!0);let o;(null==r?void 0:r.wallet)&&"universalLink"in r.wallet&&("universal-link"===r.wallet.openMethod||L(r.wallet.universalLink)&&On())&&(o=r.wallet.universalLink);const s=()=>{const e=Jr(),t="returnStrategy"in e?e.returnStrategy:Ga.returnStrategy;if(L(o)){const r=!n();i(!1),El(o,{returnStrategy:t,twaReturnUrl:"twaReturnUrl"in e?e.twaReturnUrl:Ga.twaReturnUrl,forceRedirect:r})}else Tr(Bl(o,t))};return kt(Ic,Bt(t,{get children(){return[Qe((()=>e.icon)),kt(Uc,{get translationKey(){return e.headerTranslationKey},get translationValues(){return e.headerTranslationValues}}),kt(Mc,{get translationKey(){return e.textTranslationKey},get translationValues(){return e.textTranslationValues}}),kt(It,{get when(){return"open-wallet"!==e.showButton},get children(){return kt(Tc,{onClick:()=>e.onClose(),get children(){return kt(Sl,{translationKey:"common.close",children:"Close"})}})}}),kt(It,{get when(){return"open-wallet"===e.showButton&&o},get children(){return kt(Tc,{onClick:s,get children(){return kt(Sl,{translationKey:"common.openWallet",children:"Open wallet"})}})}})]}}))},Rc=e=>{const t=nt(Bs),[r]=Gi();return kt(Oc,{headerTranslationKey:"actionModal.confirmTransaction.header",get headerTranslationValues(){return{name:t.wallet&&"name"in t.wallet?t.wallet.name:r("common.yourWallet",{},"Your wallet")}},textTranslationKey:"actionModal.confirmTransaction.text",get icon(){return kt(Uo,{size:"m"})},onClose:()=>e.onClose(),showButton:"open-wallet","data-tc-confirm-modal":"true"})},jc=e=>kt(Oc,{headerTranslationKey:"actionModal.transactionCanceled.header",textTranslationKey:"actionModal.transactionCanceled.text",get icon(){return kt(Bo,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-canceled-modal":"true"}),Lc=e=>kt(Oc,{headerTranslationKey:"actionModal.transactionSent.header",textTranslationKey:"actionModal.transactionSent.text",get icon(){return kt(ko,{size:"m"})},onClose:()=>e.onClose(),"data-tc-transaction-sent-modal":"true"}),zc=()=>kt(Ai,{get opened(){var e;return Qe((()=>null!==Jr()))()&&!0===(null==(e=Jr())?void 0:e.openModal)},get enableAndroidBackHandler(){return Ga.enableAndroidBackHandler},onClose:()=>Xr(null),"data-tc-actions-modal-container":"true",get children(){return kt(Ut,{get children(){return[kt(Mt,{get when(){return"transaction-sent"===Jr().name},get children(){return kt(Lc,{onClose:()=>Xr(null)})}}),kt(Mt,{get when(){return"transaction-canceled"===Jr().name},get children(){return kt(jc,{onClose:()=>Xr(null)})}}),kt(Mt,{get when(){return"confirm-transaction"===Jr().name},get children(){return kt(Rc,{onClose:()=>Xr(null)})}})]}})}}),Nc=e=>{const t=((e={},t=(navigator.language in e?navigator.language:Object.keys(e)[0]))=>{const[r,n]=Ze(t),[i,o]=bn(e);return[(e,t,n)=>{const o=Zi(i[r()],e,n||"");return"function"==typeof o?o(t):"string"==typeof o?((e,t,r=/{{(.*?)}}/g)=>e.replace(r,((e,r)=>Zi(t,r,""))))(o,t||{}):o},{add(e,t){o(e,(e=>Object.assign(e||{},t)))},locale:e=>e?n(e):r(),dict:e=>Zi(i,e)}]})(en,Ga.language);return customElements.define(kr,class extends HTMLElement{}),document.body.hasAttribute("ontouchstart")||document.body.setAttribute("ontouchstart",""),kt(Wi.Provider,{value:t,get children(){return kt(Bs.Provider,{get value(){return e.tonConnectUI},get children(){return kt(rn.Provider,{get value(){return Ga.connector},get children(){return[kt(Sr,{}),kt(br,{theme:kn,get children(){return[kt(It,{get when(){return Ga.buttonRootId},get children(){return kt(rr,{get mount(){return document.getElementById(Ga.buttonRootId)},get children(){return kt(Ha,{})}})}}),kt(nr,{component:kr,get children(){return[kt(Pc,{}),kt(zc,{})]}})]}})]}})}})}})},Dc=()=>{setTimeout((()=>qr({status:"opened",closeReason:null})))},$c=e=>{setTimeout((()=>Xr(e)))};class Fc{constructor(e){Pe(this,"connector"),Pe(this,"setConnectRequestParametersCallback"),Pe(this,"consumers",[]),Pe(this,"state",Hr()),this.connector=e.connector,this.setConnectRequestParametersCallback=e.setConnectRequestParametersCallback,Ye((()=>{const e=Hr();this.state=e,this.consumers.forEach((t=>t(e)))}))}open(){return Ie(this,null,(function*(){const e=(yield this.connector.getWallets()).find(ee);return e?this.connectEmbeddedWallet(e):this.connectExternalWallet()}))}close(){var e;e="action-cancelled",setTimeout((()=>qr({status:"closed",closeReason:e})))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}connectEmbeddedWallet(e){const t=t=>{Qr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},r=Ga.connectRequestParameters;"loading"===(null==r?void 0:r.state)?this.setConnectRequestParametersCallback(t):t(null==r?void 0:r.value)}connectExternalWallet(){return Ie(this,null,(function*(){return On()&&Rn(),Dc(),new Promise((e=>{const t=this.onStateChange((r=>{const{status:n}=r;"opened"===n&&(t(),e())}))}))}))}}class Kc{constructor(e){Pe(this,"connector"),Pe(this,"consumers",[]),this.connector=e.connector,Ye((()=>{const e=Jr();this.consumers.forEach((t=>t(e)))}))}onStateChange(e){return this.consumers.push(e),()=>{this.consumers=this.consumers.filter((t=>t!==e))}}}var Vc=r(3515);const Hc="d843619b379084d133f061606beecbf72ae2bf60e0622e808f2a3f631673599b",qc=async(e,t,r)=>{const n=r?"https://testnet.toncenter.com/api/v3/":"https://toncenter.com/api/v3/",i={"Content-Type":"application/json","X-API-Key":Hc},o=await fetch(n+e+"?"+new URLSearchParams(t),{method:"GET",headers:i}),s=await o.json();if(s.error)throw new Error(s.error);return s};class Zc{constructor(e,t){this.contractAddress=e,this.isTestnet=t,this.tonClient=new Vc.TonClient({endpoint:t?"https://testnet.toncenter.com/api/v2/jsonRPC":"https://toncenter.com/api/v2/jsonRPC",apiKey:Hc})}getState(){throw new Error("Method not implemented.")}get(e,t){return this.tonClient.runMethod(this.contractAddress,e,t)}external(e){throw new Error("Method not implemented.")}internal(e,t){throw new Error("Method not implemented.")}open(e){throw new Error("Method not implemented.")}getTransactions(e,t,r,n){throw new Error("Method not implemented.")}}const Wc=(e,t)=>a.Address.isFriendly(e)?a.Address.parseFriendly(e).isTestOnly&&!t?"Please enter mainnet address":null:"Invalid address",Gc=async(e,t)=>{const r=await(async(e,t)=>{const r=e.toRawString(),n=await qc("addressBook",{address:r},t);return a.Address.parseFriendly(n[r].user_friendly)})(e,t);return Yc(r)},Yc=e=>{const t=Qc(e),r=((e,t)=>(a.Address.parseFriendly(e),(t?"https://testnet.tonscan.org/address/":"https://tonscan.org/address/")+e))(t,e.isTestOnly);return`${t}`},Qc=e=>e.address.toString({bounceable:e.isBounceable,testOnly:e.isTestOnly}),Jc=(e,t)=>{if(e.length!==t.length)return!1;for(let r=0;r{if(!e)throw console.error(t),new Error(t)};class ed{}ed.multisig={new_order:4145565967,execute:1963556701,execute_internal:2737592767},ed.order={approve:2808226575,expired:6,approve_rejected:2947491902,approved:2187369462,init:2624846754},ed.actions={send_message:4046986843,update_multisig_params:487390163};class td{}td.multisig={unauthorized_new_order:1007,invalid_new_order:1008,not_enough_ton:100,unauthorized_execute:101,singers_outdated:102,invalid_dictionary_sequence:103,expired:111},td.order={unauthorized_init:104,already_approved:107,already_inited:105,unauthorized_sign:106,expired:111,unknown_op:65535,already_executed:112};class rd{}function nd(e){let t=a.Dictionary.empty(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address());for(let r=0;r0||e.remainingRefs>0)throw new Error("remaining bits in data")}rd.bitsize={op:32,queryId:64,orderSeqno:256,signerIndex:8,actionIndex:8,time:48};class sd{constructor(e,t,r){this.address=e,this.init=t,this.configuration=r,this.orderSeqno=0n}static createFromAddress(e){let t=new sd(e);return t.orderSeqno=0n,t}static createFromConfig(e,t,r=0){const n=function(e){return(0,a.beginCell)().storeUint(0,rd.bitsize.orderSeqno).storeUint(e.threshold,rd.bitsize.signerIndex).storeRef((0,a.beginCell)().storeDictDirect(nd(e.signers))).storeUint(e.signers.length,rd.bitsize.signerIndex).storeDict(nd(e.proposers)).storeBit(e.allowArbitrarySeqno).endCell()}(e),i={code:t,data:n};return new sd((0,a.contractAddress)(r,i),i,e)}async sendDeploy(e,t,r){await e.internal(t,{value:r,sendMode:a.SendMode.PAY_GAS_SEPARATELY,body:(0,a.beginCell)().storeUint(0,rd.bitsize.op).storeUint(0,rd.bitsize.queryId).endCell()})}static packTransferRequest(e){let t=(0,a.beginCell)().store((0,a.storeMessageRelaxed)(e.message)).endCell();return(0,a.beginCell)().storeUint(ed.actions.send_message,rd.bitsize.op).storeUint(e.sendMode,8).storeRef(t).endCell()}static packUpdateRequest(e){return(0,a.beginCell)().storeUint(ed.actions.update_multisig_params,rd.bitsize.op).storeUint(e.threshold,rd.bitsize.signerIndex).storeRef((0,a.beginCell)().storeDictDirect(nd(e.signers))).storeDict(nd(e.proposers)).endCell()}static packOrder(e){let t=a.Dictionary.empty(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell());if(e.length>255)throw new Error("For action chains above 255, use packLarge method");for(let r=0;r{const t=e.beginParse(),r=t.loadAddress(),n=t.loadUintBig(256);return od(t),{multisigAddress:r,orderId:n}},ld=e=>{const t=a.Address.parse(e.destination),r=(e=>{const t=e.beginParse();if(0!==t.loadUint(2))throw new Error("invalid init state prefix");const r=t.loadMaybeRef(),n=t.loadMaybeRef();if(t.loadBoolean())throw new Error("invalid init state empty libraries");return od(t),{code:r,body:ad(n)}})(a.Cell.fromBase64(e.init_state.body)),n=a.Cell.fromBase64(e.message_content.body).beginParse();Xc(n.loadUint(32)===ed.order.init,"invalid op");const i=n.loadUint(64),o=n.loadUint(8),s=n.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address()),l=n.loadUint(48),c=n.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell()),d=n.loadUint(1);let u;return d&&(u=n.loadUint(8)),console.log("OUT",{queryId:i,threshold:o,signers:s,expiredAt:l,order:c,isSigner:d,signerIndex:u}),od(n),{orderAddress:t,orderId:r.body.orderId}};function cd(e){let t=[];if(null!==e){const r=a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Address(),e);for(let e=0;e{switch(e){case"unlock":return 0;case"out":return 1;case"in":return 2;case"full":return 3;default:throw new Error("Invalid argument!")}},md=e=>{switch(e){case"unlock":return"Unlock";case"out":return"Outgoing transfers locked";case"in":return"Inbound transfers locked";case"full":return"Outgoing and Inbound transfers locked"}};function yd(e){if(e.remainingBits>0||e.remainingRefs>0)throw new Error("remaining bits in data")}class bd{constructor(e,t){this.address=e,this.init=t}static createFromAddress(e){return new bd(e)}static createFromConfig(e,t,r=0){const n=function(e){const t=e.jetton_content instanceof a.Cell?e.jetton_content:function(e){return(0,a.beginCell)().storeStringTail(e.uri).endCell()}(e.jetton_content);return(0,a.beginCell)().storeCoins(0).storeAddress(e.admin).storeAddress(null).storeRef(e.wallet_code).storeRef(t).endCell()}(e),i={code:t,data:n};return new bd((0,a.contractAddress)(r,i),i)}async sendDeploy(e,t,r){await e.internal(t,{value:r,sendMode:a.SendMode.PAY_GAS_SEPARATELY,body:(0,a.beginCell)().storeUint(ud.top_up,32).storeUint(0,64).endCell()})}static mintMessage(e,t,r,n,i,o,s){const l=(0,a.beginCell)().storeUint(ud.internal_transfer,32).storeUint(0,64).storeCoins(t).storeAddress(r).storeAddress(n).storeCoins(o).storeMaybeRef(i).endCell();return(0,a.beginCell)().storeUint(ud.mint,32).storeUint(0,64).storeAddress(e).storeCoins(s).storeRef(l).endCell()}static parseMintInternalMessage(e){if(e.loadUint(32)!==ud.internal_transfer)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadCoins(),n=e.loadAddress(),i=e.loadAddress(),o=e.loadCoins(),s=e.loadBit()?e.loadRef().beginParse():e;return yd(e),{queryId:t,jettonAmount:r,fromAddress:n,responseAddress:i,forwardTonAmount:o,forwardPayload:s}}static parseMintMessage(e){if(e.loadUint(32)!==ud.mint)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadAddress(),n=e.loadCoins(),i=e.loadRef();return yd(e),{queryId:t,toAddress:r,tonAmount:n,internalMessage:this.parseMintInternalMessage(i.beginParse())}}static topUpMessage(){return(0,a.beginCell)().storeUint(ud.top_up,32).storeUint(0,64).endCell()}static parseTopUp(e){if(e.loadUint(32)!==ud.top_up)throw new Error("Invalid op");const t=e.loadUint(64);return yd(e),{queryId:t}}static changeAdminMessage(e){return(0,a.beginCell)().storeUint(ud.change_admin,32).storeUint(0,64).storeAddress(e).endCell()}static parseChangeAdmin(e){if(e.loadUint(32)!==ud.change_admin)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadAddress();return yd(e),{queryId:t,newAdminAddress:r}}static claimAdminMessage(e=0n){return(0,a.beginCell)().storeUint(ud.claim_admin,32).storeUint(e,64).endCell()}static parseClaimAdmin(e){if(e.loadUint(32)!==ud.claim_admin)throw new Error("Invalid op");const t=e.loadUint(64);return yd(e),{queryId:t}}static changeContentMessage(e){const t=e.uri;return(0,a.beginCell)().storeUint(ud.change_metadata_url,32).storeUint(0,64).storeStringTail(t).endCell()}static parseChangeContent(e){if(e.loadUint(32)!==ud.change_metadata_url)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadStringTail();return yd(e),{queryId:t,newMetadataUrl:r}}static lockWalletMessage(e,t,r,n=0){return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(n,64).storeAddress(e).storeCoins(r).storeRef((0,a.beginCell)().storeUint(ud.set_status,32).storeUint(n,64).storeUint(t,4).endCell()).endCell()}static parseSetStatus(e){if(e.loadUint(32)!==ud.set_status)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadUint(4);return yd(e),{queryId:t,newStatus:r}}static parseCallTo(e,t){if(e.loadUint(32)!==ud.call_to)throw new Error("Invalid op");const r=e.loadUint(64),n=e.loadAddress(),i=e.loadCoins(),o=e.loadRef();return yd(e),{queryId:r,toAddress:n,tonAmount:i,action:t(o.beginParse())}}static forceTransferMessage(e,t,r,n,i,o,s,l,c=0n){const d=fd.transferMessage(e,t,n,i,o,s);return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(c,64).storeAddress(r).storeCoins(l).storeRef(d).endCell()}static parseTransfer(e){if(e.loadUint(32)!==ud.transfer)throw new Error("Invalid op");return{queryId:e.loadUint(64),jettonAmount:e.loadCoins(),toAddress:e.loadAddress(),responseAddress:e.loadAddress(),customPayload:e.loadMaybeRef(),forwardTonAmount:e.loadCoins(),forwardPayload:e.loadBit()?e.loadRef().beginParse():e}}static forceBurnMessage(e,t,r,n,i=0){return(0,a.beginCell)().storeUint(ud.call_to,32).storeUint(i,64).storeAddress(t).storeCoins(n).storeRef(fd.burnMessage(e,r,null)).endCell()}static parseBurn(e){if(e.loadUint(32)!==ud.burn)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadCoins(),n=e.loadAddress(),i=e.loadMaybeRef();return yd(e),{queryId:t,jettonAmount:r,responseAddress:n,customPayload:i}}static upgradeMessage(e,t,r=0){return(0,a.beginCell)().storeUint(ud.upgrade,32).storeUint(r,64).storeRef(t).storeRef(e).endCell()}static parseUpgrade(e){if(e.loadUint(32)!==ud.upgrade)throw new Error("Invalid op");const t=e.loadUint(64),r=e.loadRef(),n=e.loadRef();return yd(e),{queryId:t,newData:r,newCode:n}}async getWalletAddress(e,t){const r=await e.get("get_wallet_address",[{type:"slice",cell:(0,a.beginCell)().storeAddress(t).endCell()}]);return Xc(1===r.stack.remaining,"invalid get_wallet_address result"),r.stack.readAddress()}async getJettonData(e){let t=await e.get("get_jetton_data",[]);return Xc(5===t.stack.remaining,"invalid get_jetton_data result"),{totalSupply:t.stack.readBigNumber(),mintable:t.stack.readBoolean(),adminAddress:t.stack.readAddress(),content:t.stack.readCell(),walletCode:t.stack.readCell()}}async getNextAdminAddress(e){const t=await e.get("get_next_admin_address",[]);return Xc(1===t.stack.remaining,"invalid get_next_admin_address result"),t.stack.readAddressOpt()}}const wd=e=>{if(null===e)throw new Error("invalid number");if(void 0===e)throw new Error("invalid number");if(isNaN(e))throw new Error("invalid number");if(e<0)throw new Error("invalid number")};var vd=r(5269);const Cd=["uri","name","description","image","image_data","symbol","decimals","amount_style"],_d={serialize:(e,t)=>{t.storeRef((0,a.beginCell)().storeUint(0,8).storeStringTail(e).endCell())},parse:e=>{const t=e.loadRef().beginParse(),r=t.loadUint(8);if(0==r)return t.loadStringTail();if(1==r)return a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(32),a.Dictionary.Values.Cell(),t).values().map((e=>e.beginParse().loadStringTail())).join("");throw Error(`Prefix ${r} is not supported yet`)}},kd=async(e,t,r)=>{const n=await qc("account",{address:Qc(e)},t);Xc("active"===n.status,"Contract not active");const i=n.balance,o=new Zc(e.address,t),s=bd.createFromAddress(e.address),l=await s.getJettonData(o);let c,d;const u=await(async e=>{const t=e.beginParse(),r=t.loadUint(8);if(1==r){const e=0==t.remainingBits;if(e&&0==t.remainingRefs)throw new Error("No data in content cell!");return e?t.loadStringRefTail():t.loadStringTail()}if(0==r){const e=a.Dictionary.load(a.Dictionary.Keys.BigUint(256),_d,t),r={};for(const t of Cd){const n=BigInt("0x"+(await(0,vd.sha256)(t)).toString("hex")),i=e.get(n);void 0!==i&&(r[t]=i)}return r}throw new Error(`Unknown content format indicator:${r}`)})(l.content);if(u instanceof String)d=u;else{const e=u;d=e.uri;const t=e.decimals;if(void 0!==t&&(c=parseInt(t),isNaN(c)))throw new Error("invalid decimals")}let h;return r&&(h=await s.getNextAdminAddress(o)),{tonBalance:i,jettonMinterContract:s,adminAddress:l.adminAddress,nextAdminAddress:h,decimals:c,metadataUrl:d}};var xd=r(9107),Ad=r.n(xd),Sd=r(8287).hp;function Bd(e){let t=0;const r=Sd.alloc(e.length+2);r.set(e);for(let e of r){let r=128;for(;r>0;)t<<=1,e&r&&(t+=1),r>>=1,t>65535&&(t&=65535,t^=4129)}return Sd.from([Math.floor(t/256),t%256])}var Ed,Pd,Id=r(8287).hp;function Ud(e){if("string"==typeof e&&!Md.isFriendly(e))throw new Error("Unknown address type");const t=Id.isBuffer(e)?e:Id.from(e,"base64");if(36!==t.length)throw new Error("Unknown address type: byte length is not equal to 36");const r=t.subarray(0,34),n=t.subarray(34,36),i=Bd(r);if(i[0]!==n[0]||i[1]!==n[1])throw new Error("Invalid checksum: "+e);let o=r[0],s=!1,a=!1;if(128&o&&(s=!0,o^=128),17!==o&&81!==o)throw"Unknown address tag";a=17===o;let l=null;return l=255===r[1]?-1:r[1],{isTestOnly:s,isBounceable:a,workchain:l,hashPart:r.subarray(2,34)}}class Md{static isAddress(e){return e instanceof Md}static isFriendly(e){return 48===e.length&&!!/[A-Za-z0-9+/_-]+/.test(e)}static isRaw(e){if(-1===e.indexOf(":"))return!1;let[t,r]=e.split(":");return!!Number.isInteger(parseFloat(t))&&!!/[a-f0-9]+/.test(r.toLowerCase())&&64===r.length}static normalize(e){return"string"==typeof e?Md.parse(e).toString():e.toString()}static parse(e){if(Md.isFriendly(e))return this.parseFriendly(e).address;if(Md.isRaw(e))return this.parseRaw(e);throw new Error("Unknown address type: "+e)}static parseRaw(e){let t=parseInt(e.split(":")[0]),r=Id.from(e.split(":")[1],"hex");return new Md(t,r)}static parseFriendly(e){if(Id.isBuffer(e)){let t=Ud(e);return{isBounceable:t.isBounceable,isTestOnly:t.isTestOnly,address:new Md(t.workchain,t.hashPart)}}{let t=Ud(e.replace(/\-/g,"+").replace(/_/g,"/"));return{isBounceable:t.isBounceable,isTestOnly:t.isTestOnly,address:new Md(t.workchain,t.hashPart)}}}constructor(e,t){if(this.toRawString=()=>this.workChain+":"+this.hash.toString("hex"),this.toRaw=()=>{const e=Id.alloc(36);return e.set(this.hash),e.set([this.workChain,this.workChain,this.workChain,this.workChain],32),e},this.toStringBuffer=e=>{let t=!(!e||void 0===e.testOnly)&&e.testOnly,r=!e||void 0===e.bounceable||e.bounceable?17:81;t&&(r|=128);const n=Id.alloc(34);n[0]=r,n[1]=this.workChain,n.set(this.hash,2);const i=Id.alloc(36);return i.set(n),i.set(Bd(n),34),i},this.toString=e=>{let t=!e||void 0===e.urlSafe||e.urlSafe,r=this.toStringBuffer(e);return t?r.toString("base64").replace(/\+/g,"-").replace(/\//g,"_"):r.toString("base64")},this[Ed]=()=>this.toString(),32!==t.length)throw new Error("Invalid address hash length: "+t.length);this.workChain=e,this.hash=t,Object.freeze(this)}equals(e){return e.workChain===this.workChain&&e.hash.equals(this.hash)}}Ed=Ad();class Td{static isAddress(e){return e instanceof Td}constructor(e,t){this[Pd]=()=>this.toString(),this.value=e,this.bits=t}toString(){return`External<${this.bits}:${this.value}>`}}function Od(e){let t=new Dd(8*Math.ceil(e.length/8));t.writeBits(e);let r=8*Math.ceil(e.length/8)-e.length;for(let e=0;ethis.toString(),r<0)throw new Error(`Length ${r} is out of bounds`);this._length=r,this._data=e,this._offset=t}get length(){return this._length}at(e){if(e>=this._length)throw new Error(`Index ${e} > ${this._length} is out of bounds`);if(e<0)throw new Error(`Index ${e} < 0 is out of bounds`);let t=this._offset+e>>3,r=7-(this._offset+e)%8;return!!(this._data[t]&1<this._length)throw new Error(`Offset(${e}) > ${this._length} is out of bounds`);if(e<0)throw new Error(`Offset(${e}) < 0 is out of bounds`);if(0===t)return Ld.EMPTY;if(e+t>this._length)throw new Error(`Offset ${e} + Length ${t} > ${this._length} is out of bounds`);return new Ld(this._data,this._offset+e,t)}subbuffer(e,t){if(e>this._length)throw new Error(`Offset ${e} is out of bounds`);if(e<0)throw new Error(`Offset ${e} is out of bounds`);if(e+t>this._length)throw new Error(`Offset + Lenght = ${e+t} is out of bounds`);if(t%8!=0)return null;if((this._offset+e)%8!=0)return null;let r=this._offset+e>>3,n=r+(t>>3);return this._data.subarray(r,n)}equals(e){if(this._length!==e._length)return!1;for(let t=0;t8*this._buffer.length)throw new Error("BitBuilder overflow");("boolean"==typeof e&&!0===e||"number"==typeof e&&e>0)&&(this._buffer[t/8|0]|=1<<7-t%8),this._length++}writeBits(e){for(let t=0;t8*this._buffer.length)throw new Error("BitBuilder overflow");e.copy(this._buffer,this._length/8),this._length+=8*e.length}else for(let t=0;t=n)throw Error(`bitLength is too small for a value ${e}. Got ${t}`);if(this._length+t>8*this._buffer.length)throw new Error("BitBuilder overflow");const i=8-this._length%8;if(i>0){const e=Math.floor(this._length/8);if(t>BigInt(t-i));this._buffer[e]|=n,this._length+=i}}for(t-=i;t>0;)t>=8?(this._buffer[this._length/8]=Number(r>>BigInt(t-8)&0xffn),this._length+=8,t-=8):(this._buffer[this._length/8]=Number(r<=n)throw Error(`value is out of range for ${t} bits. Got ${e}`);r<0?(this.writeBit(!0),r=n+r):this.writeBit(!1),this.writeUint(r,t-1)}writeVarUint(e,t){let r=BigInt(e);if(t<0||!Number.isSafeInteger(t))throw Error(`invalid bit length. Got ${t}`);if(r<0)throw Error(`value is negative. Got ${e}`);if(0n===r)return void this.writeUint(0,t);const n=Math.ceil(r.toString(2).length/8),i=8*n;this.writeUint(n,t),this.writeUint(r,i)}writeVarInt(e,t){let r=BigInt(e);if(t<0||!Number.isSafeInteger(t))throw Error(`invalid bit length. Got ${t}`);if(0n===r)return void this.writeUint(0,t);let n=r>0?r:-r;const i=1+Math.ceil(n.toString(2).length/8),o=8*i;this.writeUint(i,t),this.writeInt(r,o)}writeCoins(e){this.writeVarUint(e,4)}writeAddress(e){if(null!=e){if(Md.isAddress(e))return this.writeUint(2,2),this.writeUint(0,1),this.writeInt(e.workChain,8),void this.writeBuffer(e.hash);if(Td.isAddress(e))return this.writeUint(1,2),this.writeUint(e.bits,9),void this.writeUint(e.value,e.bits);throw Error(`Invalid address. Got ${e}`)}this.writeUint(0,2)}build(){return new Ld(this._buffer,0,this._length)}buffer(){if(this._length%8!=0)throw new Error("BitBuilder buffer is not byte aligned");return this._buffer.subarray(0,this._length/8)}}!function(e){e[e.Ordinary=-1]="Ordinary",e[e.PrunedBranch=1]="PrunedBranch",e[e.Library=2]="Library",e[e.MerkleProof=3]="MerkleProof",e[e.MerkleUpdate=4]="MerkleUpdate"}(zd||(zd={}));var $d,Fd=r(8287).hp;function Kd(e){if(e.remainingBits%8!=0)throw new Error(`Invalid string length: ${e.remainingBits}`);if(0!==e.remainingRefs&&1!==e.remainingRefs)throw new Error(`invalid number of refs: ${e.remainingRefs}`);let t;return t=0===e.remainingBits?Fd.alloc(0):e.loadBuffer(e.remainingBits/8),1===e.remainingRefs&&(t=Fd.concat([t,Kd(e.loadRef().beginParse())])),t}function Vd(e){return Kd(e).toString()}function Hd(e,t){if(e.length>0){let r=Math.floor(t.availableBits/8);if(e.length>r){let n=e.subarray(0,r),i=e.subarray(r);t=t.storeBuffer(n);let o=yu();Hd(i,o),t=t.storeRef(o.endCell())}else t=t.storeBuffer(e)}}function qd(e,t){Hd(Fd.from(e),t)}class Zd{constructor(e,t){this[$d]=()=>this.toString(),this._reader=e.clone(),this._refs=[...t],this._refsOffset=0}get remainingBits(){return this._reader.remaining}get offsetBits(){return this._reader.offset}get remainingRefs(){return this._refs.length-this._refsOffset}get offsetRefs(){return this._refsOffset}skip(e){return this._reader.skip(e),this}loadBit(){return this._reader.loadBit()}preloadBit(){return this._reader.preloadBit()}loadBoolean(){return this.loadBit()}loadMaybeBoolean(){return this.loadBit()?this.loadBoolean():null}loadBits(e){return this._reader.loadBits(e)}preloadBits(e){return this._reader.preloadBits(e)}loadUint(e){return this._reader.loadUint(e)}loadUintBig(e){return this._reader.loadUintBig(e)}preloadUint(e){return this._reader.preloadUint(e)}preloadUintBig(e){return this._reader.preloadUintBig(e)}loadMaybeUint(e){return this.loadBit()?this.loadUint(e):null}loadMaybeUintBig(e){return this.loadBit()?this.loadUintBig(e):null}loadInt(e){return this._reader.loadInt(e)}loadIntBig(e){return this._reader.loadIntBig(e)}preloadInt(e){return this._reader.preloadInt(e)}preloadIntBig(e){return this._reader.preloadIntBig(e)}loadMaybeInt(e){return this.loadBit()?this.loadInt(e):null}loadMaybeIntBig(e){return this.loadBit()?this.loadIntBig(e):null}loadVarUint(e){return this._reader.loadVarUint(e)}loadVarUintBig(e){return this._reader.loadVarUintBig(e)}preloadVarUint(e){return this._reader.preloadVarUint(e)}preloadVarUintBig(e){return this._reader.preloadVarUintBig(e)}loadVarInt(e){return this._reader.loadVarInt(e)}loadVarIntBig(e){return this._reader.loadVarIntBig(e)}preloadVarInt(e){return this._reader.preloadVarInt(e)}preloadVarIntBig(e){return this._reader.preloadVarIntBig(e)}loadCoins(){return this._reader.loadCoins()}preloadCoins(){return this._reader.preloadCoins()}loadMaybeCoins(){return this._reader.loadBit()?this._reader.loadCoins():null}loadAddress(){return this._reader.loadAddress()}loadMaybeAddress(){return this._reader.loadMaybeAddress()}loadExternalAddress(){return this._reader.loadExternalAddress()}loadMaybeExternalAddress(){return this._reader.loadMaybeExternalAddress()}loadAddressAny(){return this._reader.loadAddressAny()}loadRef(){if(this._refsOffset>=this._refs.length)throw new Error("No more references");return this._refs[this._refsOffset++]}preloadRef(){if(this._refsOffset>=this._refs.length)throw new Error("No more references");return this._refs[this._refsOffset]}loadMaybeRef(){return this.loadBit()?this.loadRef():null}preloadMaybeRef(){return this.preloadBit()?this.preloadRef():null}loadBuffer(e){return this._reader.loadBuffer(e)}preloadBuffer(e){return this._reader.preloadBuffer(e)}loadStringTail(){return Vd(this)}loadMaybeStringTail(){return this.loadBit()?Vd(this):null}loadStringRefTail(){return Vd(this.loadRef().beginParse())}loadMaybeStringRefTail(){const e=this.loadMaybeRef();return e?Vd(e.beginParse()):null}loadDict(e,t){return Ou.load(e,t,this)}loadDictDirect(e,t){return Ou.loadDirect(e,t,this)}endParse(){if(this.remainingBits>0||this.remainingRefs>0)throw new Error("Slice is not empty")}asCell(){return yu().storeSlice(this).endCell()}asBuilder(){return yu().storeSlice(this)}clone(e=!1){if(e){let e=this._reader.clone();return e.reset(),new Zd(e,this._refs)}{let e=new Zd(this._reader,this._refs);return e._refsOffset=this._refsOffset,e}}toString(){return this.asCell().toString()}}$d=Ad();var Wd=r(8287).hp;class Gd{constructor(e,t=0){this._checkpoints=[],this._bits=e,this._offset=t}get offset(){return this._offset}get remaining(){return this._bits.length-this._offset}skip(e){if(e<0||this._offset+e>this._bits.length)throw new Error(`Index ${this._offset+e} is out of bounds`);this._offset+=e}reset(){this._checkpoints.length>0?this._offset=this._checkpoints.pop():this._offset=0}save(){this._checkpoints.push(this._offset)}loadBit(){let e=this._bits.at(this._offset);return this._offset++,e}preloadBit(){return this._bits.at(this._offset)}loadBits(e){let t=this._bits.substring(this._offset,e);return this._offset+=e,t}preloadBits(e){return this._bits.substring(this._offset,e)}loadBuffer(e){let t=this._preloadBuffer(e,this._offset);return this._offset+=8*e,t}preloadBuffer(e){return this._preloadBuffer(e,this._offset)}loadUint(e){return Number(this.loadUintBig(e))}loadUintBig(e){let t=this.preloadUintBig(e);return this._offset+=e,t}preloadUint(e){return Number(this._preloadUint(e,this._offset))}preloadUintBig(e){return this._preloadUint(e,this._offset)}loadInt(e){let t=this._preloadInt(e,this._offset);return this._offset+=e,Number(t)}loadIntBig(e){let t=this._preloadInt(e,this._offset);return this._offset+=e,t}preloadInt(e){return Number(this._preloadInt(e,this._offset))}preloadIntBig(e){return this._preloadInt(e,this._offset)}loadVarUint(e){let t=Number(this.loadUint(e));return Number(this.loadUintBig(8*t))}loadVarUintBig(e){let t=Number(this.loadUint(e));return this.loadUintBig(8*t)}preloadVarUint(e){let t=Number(this._preloadUint(e,this._offset));return Number(this._preloadUint(8*t,this._offset+e))}preloadVarUintBig(e){let t=Number(this._preloadUint(e,this._offset));return this._preloadUint(8*t,this._offset+e)}loadVarInt(e){let t=Number(this.loadUint(e));return Number(this.loadIntBig(8*t))}loadVarIntBig(e){let t=Number(this.loadUint(e));return this.loadIntBig(8*t)}preloadVarInt(e){let t=Number(this._preloadUint(e,this._offset));return Number(this._preloadInt(8*t,this._offset+e))}preloadVarIntBig(e){let t=Number(this._preloadUint(e,this._offset));return this._preloadInt(8*t,this._offset+e)}loadCoins(){return this.loadVarUintBig(4)}preloadCoins(){return this.preloadVarUintBig(4)}loadAddress(){let e=Number(this._preloadUint(2,this._offset));if(2===e)return this._loadInternalAddress();throw new Error("Invalid address: "+e)}loadMaybeAddress(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(2===e)return this._loadInternalAddress();throw new Error("Invalid address")}loadExternalAddress(){if(1===Number(this._preloadUint(2,this._offset)))return this._loadExternalAddress();throw new Error("Invalid address")}loadMaybeExternalAddress(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(1===e)return this._loadExternalAddress();throw new Error("Invalid address")}loadAddressAny(){let e=Number(this._preloadUint(2,this._offset));if(0===e)return this._offset+=2,null;if(2===e)return this._loadInternalAddress();if(1===e)return this._loadExternalAddress();throw 3===e?Error("Unsupported"):Error("Unreachable")}loadPaddedBits(e){if(e%8!=0)throw new Error("Invalid number of bits");let t=e;for(;;){if(this._bits.at(this._offset+t-1)){t--;break}t--}let r=this._bits.substring(this._offset,t);return this._offset+=e,r}clone(){return new Gd(this._bits,this._offset)}_preloadInt(e,t){if(0==e)return 0n;let r=this._bits.at(t),n=0n;for(let r=0;r>1&1431655765))+(e>>2&858993459))+(e>>4)&252645135)>>24}(this._mask),this._hashCount=this._hashIndex+1}get value(){return this._mask}get level(){return 32-Math.clz32(this._mask)}get hashIndex(){return this._hashIndex}get hashCount(){return this._hashCount}apply(e){return new Xd(this._mask&(1<>e-1)%2!=0}}function eu(e,t){let r,n=new Gd(e),i=n.loadUint(8);if(1!==i)throw new Error(`Pruned branch cell must have type 1, got "${i}"`);if(0!==t.length)throw new Error(`Pruned Branch cell can't has refs, got "${t.length}"`);if(280===e.length)r=new Xd(1);else{if(r=new Xd(n.loadUint(8)),r.level<1||r.level>3)throw new Error(`Pruned Branch cell level must be >= 1 and <= 3, got "${r.level}/${r.value}"`);const t=16+272*r.apply(r.level-1).hashCount;if(e.length!==t)throw new Error(`Pruned branch cell must have exactly ${t} bits, got "${e.length}"`)}let o=[],s=[],a=[];for(let e=0;e>1);else if(e===zd.MerkleUpdate)Jd(t,r),n=new Xd((r[0].mask.value|r[1].mask.value)>>1);else{if(e!==zd.Library)throw new Error("Unsupported exotic type");Yd(t),n=new Xd}let o=[],s=[],a=e===zd.PrunedBranch?1:n.hashCount,l=n.hashCount-a;for(let i=0,a=0;i<=n.level;i++){if(!n.isSignificant(i))continue;if(a0&&d++;let u=iu(t,c,r,i,n.apply(i).value,e),h=(0,vd.sha256_sync)(u),f=a-l;o[f]=d,s[f]=h,a++}let c=[],d=[];if(i)for(let e=0;e<4;e++){const{hashIndex:t}=n.apply(e),{hashIndex:r}=n;t!==r?(c.push(i.pruned[t].hash),d.push(i.pruned[t].depth)):(c.push(s[0]),d.push(o[0]))}else for(let e=0;e<4;e++)c.push(s[n.apply(e).hashIndex]),d.push(o[n.apply(e).hashIndex]);return{mask:n,hashes:c,depths:d}}function su(e,t){let r=BigInt(e);if("int"===t)return 0n===r||-1n===r?1:(r>0?r:-r).toString(2).length+1;if("uint"===t){if(r<0)throw Error(`value is negative. Got ${e}`);return r.toString(2).length}throw Error(`invalid mode. Got ${t}`)}var au=r(8287).hp;const lu=2197175160;function cu(e){let t=-1;for(let r=0;r>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1,t=1&t?t>>>1^lu:t>>>1;t^=4294967295;let r=au.alloc(4);return r.writeInt32LE(t),r}function du(e){return function(e){let t=0;for(let r=0;r<3;r++)t+=1&e,e>>=1;return t+1}(7&e)}function uu(e,t){const r=e.loadUint(8),n=r%8,i=!!(8&r),o=e.loadUint(8),s=Math.ceil(o/2),a=!!(o%2),l=r>>5,c=!!(16&r),d=c?32*du(l):0,u=c?2*du(l):0;e.skip(8*d),e.skip(8*u);let h=Ld.EMPTY;s>0&&(h=a?e.loadPaddedBits(8*s):e.loadBits(8*s));let f=[];for(let r=0;r=0;e--){if(n[e].result)throw Error("Impossible");let t=[];for(let r of n[e].refs){if(!n[r].result)throw Error("Invalid BOC file");t.push(n[r].result)}n[e].result=new mu({bits:n[e].bits,refs:t,exotic:n[e].exotic})}let i=[];for(let e=0;e{if(this.isExotic&&!e)throw new Error("Exotic cells cannot be parsed");return new Zd(new Gd(this.bits),this.refs)},this.hash=(e=3)=>this._hashes[Math.min(this._hashes.length-1,e)],this.depth=(e=3)=>this._depths[Math.min(this._depths.length-1,e)],this.level=()=>this.mask.level,this.equals=e=>this.hash().equals(e.hash()),this[pu]=()=>this.toString();let t=Ld.EMPTY;e&&e.bits&&(t=e.bits);let r,n,i,o=[];e&&e.refs&&(o=[...e.refs]);let s=zd.Ordinary;if(e&&e.exotic){let e=function(e,t){let r=new Gd(e).preloadUint(8);if(1===r)return function(e,t){let r=eu(e,t),n=[],i=[],o=new Xd(r.mask);for(let e=0;e>1);return{type:zd.MerkleProof,depths:[],hashes:[],mask:r}}(e,t);if(4===r)return function(e,t){Jd(e,t);let r=new Xd((t[0].level()|t[1].level())>>1);return{type:zd.MerkleUpdate,depths:[],hashes:[],mask:r}}(e,t);throw Error("Invalid exotic cell type: "+r)}(t,o),a=ou(e.type,t,o);i=a.mask,n=a.depths,r=a.hashes,s=e.type}else{if(o.length>4)throw new Error("Invalid number of references");if(t.length>1023)throw new Error(`Bits overflow: ${t.length} > 1023`);let e=ou(zd.Ordinary,t,o);i=e.mask,n=e.depths,r=e.hashes,s=zd.Ordinary}this.type=s,this.bits=t,this.refs=o,this.mask=i,this._depths=n,this._hashes=r,Object.freeze(this),Object.freeze(this.refs),Object.freeze(this.bits),Object.freeze(this.mask),Object.freeze(this._depths),Object.freeze(this._hashes)}get isExotic(){return this.type!==zd.Ordinary}toBoc(e){return function(e,t){let r=function(e){let t=[e],r=new Map,n=new Set,i=[];for(;t.length>0;){const e=[...t];t=[];for(let i of e){const e=i.hash().toString("hex");if(!r.has(e)){n.add(e),r.set(e,{cell:i,refs:i.refs.map((e=>e.hash().toString("hex")))});for(let e of i.refs)t.push(e)}}}let o=new Set;function s(e){if(!n.has(e))return;if(o.has(e))throw Error("Not a DAG");o.add(e);let t=r.get(e).refs;for(let e=t.length-1;e>=0;e--)s(t[e]);i.push(e),o.delete(e),n.delete(e)}for(;n.size>0;)s(Array.from(n)[0]);let a=new Map;for(let e=0;e=0;e--){let t=i[e];const n=r.get(t);l.push({cell:n.cell,refs:n.refs.map((e=>a.get(e)))})}return l}(e),n=r.length,i=t.idx,o=t.crc32,s=Math.max(Math.ceil(su(n,"uint")/8),1),a=0,l=[];for(let e of r)a+=hu(e.cell,s),l.push(a);let c=Math.max(Math.ceil(su(a,"uint")/8),1),d=8*(6+3*s+c+1*s+(i?n*c:0)+a+(o?4:0)),u=new Dd(d);if(u.writeUint(3052313714,32),u.writeBit(i),u.writeBit(o),u.writeBit(!1),u.writeUint(0,2),u.writeUint(s,3),u.writeUint(c,8),u.writeUint(n,8*s),u.writeUint(1,8*s),u.writeUint(0,8*s),u.writeUint(a,8*c),u.writeUint(0,8*s),i)for(let e=0;e=4)throw new Error("Too many references");if(e instanceof mu)this._refs.push(e);else{if(!(e instanceof bu))throw new Error("Invalid argument");this._refs.push(e.endCell())}return this}storeMaybeRef(e){return e?(this.storeBit(1),this.storeRef(e)):this.storeBit(0),this}storeSlice(e){let t=e.clone();for(t.remainingBits>0&&this.storeBits(t.loadBits(t.remainingBits));t.remainingRefs>0;)this.storeRef(t.loadRef());return this}storeMaybeSlice(e){return e?(this.storeBit(1),this.storeSlice(e)):this.storeBit(0),this}storeBuilder(e){return this.storeSlice(e.endCell().beginParse())}storeMaybeBuilder(e){return e?(this.storeBit(1),this.storeBuilder(e)):this.storeBit(0),this}storeWritable(e){return"object"==typeof e?e.writeTo(this):e(this),this}storeMaybeWritable(e){return e?(this.storeBit(1),this.storeWritable(e)):this.storeBit(0),this}store(e){return this.storeWritable(e),this}storeStringTail(e){return qd(e,this),this}storeMaybeStringTail(e){return null!=e?(this.storeBit(1),qd(e,this)):this.storeBit(0),this}storeStringRefTail(e){return this.storeRef(yu().storeStringTail(e)),this}storeMaybeStringRefTail(e){return null!=e?(this.storeBit(1),this.storeStringRefTail(e)):this.storeBit(0),this}storeDict(e,t,r){return e?e.store(this,t,r):this.storeBit(0),this}storeDictDirect(e,t,r){return e.storeDirect(this,t,r),this}endCell(e){return new mu({bits:this._bits.build(),refs:this._refs,exotic:e?.exotic})}asCell(){return this.endCell()}asSlice(){return this.endCell().beginParse()}}function wu(e){return yu().storeUint(1,8).storeUint(1,8).storeBuffer(e.hash(0)).storeUint(e.depth(0),16).endCell({exotic:!0})}function vu(e,t,r,n){const i=t.asCell();let o=0,s=e;if(0==(t.loadBit()?1:0)){o=function(e){let t=0;for(;e.loadBit();)t++;return t}(t);for(let e=0;e0&&t.storeUint(BigInt("0b"+e),e.length)}(e,r):"long"===n?function(e,t,r){r.storeBit(1),r.storeBit(0);let n=Math.ceil(Math.log2(t+1));r.storeUint(e.length,n),e.length>0&&r.storeUint(BigInt("0b"+e),e.length)}(e,t,r):"same"===n&&function(e,t,r,n){n.storeBit(1),n.storeBit(1),n.storeBit(e);let i=Math.ceil(Math.log2(r+1));n.storeUint(t,i)}("1"===e[0],e.length,t,r)}function Eu(e,t,r,n){Bu(e.label,t,n),function(e,t,r,n){if("leaf"===e.type&&r(e.value,n),"fork"===e.type){const i=yu(),o=yu();Eu(e.left,t-1,r,i),Eu(e.right,t-1,r,o),n.storeRef(i),n.storeRef(o)}}(e.node,t-e.label.length,r,n)}function Pu(e,t,r,n){const i=function(e,t){let r=new Map;for(let n of Array.from(e.keys())){const i=xu(n.toString(2),t);r.set(i,e.get(n))}return Su(r)}(e,t);Eu(i,t,r,n)}var Iu=r(8287).hp;function Uu(e){if("number"==typeof e){if(!Number.isSafeInteger(e))throw Error("Invalid key type: not a safe integer: "+e);return"n:"+e.toString(10)}if("bigint"==typeof e)return"b:"+e.toString(10);if(Md.isAddress(e))return"a:"+e.toString();if(Iu.isBuffer(e))return"f:"+e.toString("hex");if(Ld.isBitString(e))return"B:"+e.toString();throw Error("Invalid key type")}function Mu(e){let t=e.slice(0,2),r=e.slice(2);if("n:"===t)return parseInt(r,10);if("b:"===t)return BigInt(r);if("a:"===t)return Md.parse(r);if("f:"===t)return Iu.from(r,"hex");if("B:"===t){const e="_"==r.slice(-1);if(e||r.length%2!=0){let t=e?r.length-1:r.length;const n=r.substr(0,t)+"0";return!e&&1&t?new Ld(Iu.from(n,"hex"),0,t<<2):function(e){let t=0;for(let r=e.length-1;r>=0;r--)if(0!==e[r]){const n=e[r];let i=n&-n;1&i||(i=Math.log2(i)+1),r>0&&(t=r<<3),t+=8-i;break}return new Ld(e,0,t)}(Iu.from(n,"hex"))}return new Ld(Iu.from(r,"hex"),0,r.length<<2)}throw Error("Invalid key type: "+t)}var Tu=r(8287).hp;class Ou{static empty(e,t){return e&&t?new Ou(new Map,e,t):new Ou(new Map,null,null)}static load(e,t,r){let n;if(r instanceof mu){if(r.isExotic)return Ou.empty(e,t);n=r.beginParse()}else n=r;let i=n.loadMaybeRef();return i&&!i.isExotic?Ou.loadDirect(e,t,i.beginParse()):Ou.empty(e,t)}static loadDirect(e,t,r){if(!r)return Ou.empty(e,t);let n;n=r instanceof mu?r.beginParse():r;let i=ku(n,e.bits,t.parse),o=new Map;for(let[t,r]of i)o.set(Uu(e.parse(t)),r);return new Ou(o,e,t)}constructor(e,t,r){this._key=t,this._value=r,this._map=e}get size(){return this._map.size}get(e){return this._map.get(Uu(e))}has(e){return this._map.has(Uu(e))}set(e,t){return this._map.set(Uu(e),t),this}delete(e){const t=Uu(e);return this._map.delete(t)}clear(){this._map.clear()}*[Symbol.iterator](){for(const[e,t]of this._map){const r=Mu(e);yield[r,t]}}keys(){return Array.from(this._map.keys()).map((e=>Mu(e)))}values(){return Array.from(this._map.values())}store(e,t,r){if(0===this._map.size)e.storeBit(0);else{let n=this._key;null!=t&&(n=t);let i=this._value;if(null!=r&&(i=r),!n)throw Error("Key serializer is not defined");if(!i)throw Error("Value serializer is not defined");let o=new Map;for(const[e,t]of this._map)o.set(n.serialize(Mu(e)),t);e.storeBit(1);let s=yu();Pu(o,n.bits,i.serialize,s),e.storeRef(s.endCell())}}storeDirect(e,t,r){if(0===this._map.size)throw Error("Cannot store empty dictionary directly");let n=this._key;null!=t&&(n=t);let i=this._value;if(null!=r&&(i=r),!n)throw Error("Key serializer is not defined");if(!i)throw Error("Value serializer is not defined");let o=new Map;for(const[e,t]of this._map)o.set(n.serialize(Mu(e)),t);Pu(o,n.bits,i.serialize,e)}generateMerkleProof(e){return Cu(this,e,this._key)}generateMerkleUpdate(e,t){return function(e,t,r,n){const i=Cu(e,t,r).refs[0];return e.set(t,n),o=i,s=Cu(e,t,r).refs[0],yu().storeUint(4,8).storeBuffer(o.hash(0)).storeBuffer(s.hash(0)).storeUint(o.depth(0),16).storeUint(s.depth(0),16).storeRef(o).storeRef(s).endCell({exotic:!0});var o,s}(this,e,this._key,t)}}Ou.Keys={Address:()=>({bits:267,serialize:e=>{if(!Md.isAddress(e))throw Error("Key is not an address");return yu().storeAddress(e).endCell().beginParse().preloadUintBig(267)},parse:e=>yu().storeUint(e,267).endCell().beginParse().loadAddress()}),BigInt:e=>function(e){return{bits:e,serialize:t=>{if("bigint"!=typeof t)throw Error("Key is not a bigint");return yu().storeInt(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadIntBig(e)}}(e),Int:e=>function(e){return{bits:e,serialize:t=>{if("number"!=typeof t)throw Error("Key is not a number");if(!Number.isSafeInteger(t))throw Error("Key is not a safe integer: "+t);return yu().storeInt(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadInt(e)}}(e),BigUint:e=>function(e){return{bits:e,serialize:t=>{if("bigint"!=typeof t)throw Error("Key is not a bigint");if(t<0)throw Error("Key is negative: "+t);return yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)}}(e),Uint:e=>function(e){return{bits:e,serialize:t=>{if("number"!=typeof t)throw Error("Key is not a number");if(!Number.isSafeInteger(t))throw Error("Key is not a safe integer: "+t);if(t<0)throw Error("Key is negative: "+t);return yu().storeUint(t,e).endCell().beginParse().loadUintBig(e)},parse:t=>Number(yu().storeUint(t,e).endCell().beginParse().loadUint(e))}}(e),Buffer:e=>function(e){return{bits:8*e,serialize:t=>{if(!Tu.isBuffer(t))throw Error("Key is not a buffer");return yu().storeBuffer(t).endCell().beginParse().loadUintBig(8*e)},parse:t=>yu().storeUint(t,8*e).endCell().beginParse().loadBuffer(e)}}(e),BitString:e=>function(e){return{bits:e,serialize:t=>{if(!Ld.isBitString(t))throw Error("Key is not a BitString");return yu().storeBits(t).endCell().beginParse().loadUintBig(e)},parse:t=>yu().storeUint(t,e).endCell().beginParse().loadBits(e)}}(e)},Ou.Values={BigInt:e=>function(e){return{serialize:(t,r)=>{r.storeInt(t,e)},parse:t=>t.loadIntBig(e)}}(e),Int:e=>function(e){return{serialize:(t,r)=>{r.storeInt(t,e)},parse:t=>t.loadInt(e)}}(e),BigVarInt:e=>function(e){return{serialize:(t,r)=>{r.storeVarInt(t,e)},parse:t=>t.loadVarIntBig(e)}}(e),BigUint:e=>function(e){return{serialize:(t,r)=>{r.storeUint(t,e)},parse:t=>t.loadUintBig(e)}}(e),Uint:e=>function(e){return{serialize:(t,r)=>{r.storeUint(t,e)},parse:t=>t.loadUint(e)}}(e),BigVarUint:e=>function(e){return{serialize:(t,r)=>{r.storeVarUint(t,e)},parse:t=>t.loadVarUintBig(e)}}(e),Bool:()=>({serialize:(e,t)=>{t.storeBit(e)},parse:e=>e.loadBit()}),Address:()=>({serialize:(e,t)=>{t.storeAddress(e)},parse:e=>e.loadAddress()}),Cell:()=>({serialize:(e,t)=>{t.storeRef(e)},parse:e=>e.loadRef()}),Buffer:e=>{return t=e,{serialize:(e,r)=>{if(e.length!==t)throw Error("Invalid buffer size");r.storeBuffer(e)},parse:e=>e.loadBuffer(t)};var t},BitString:e=>function(e){return{serialize:(t,r)=>{if(t.length!==e)throw Error("Invalid BitString size");r.storeBits(t)},parse:t=>t.loadBits(e)}}(e),Dictionary:(e,t)=>function(e,t){return{serialize:(e,t)=>{e.store(t)},parse:r=>Ou.load(e,t,r)}}(e,t)};const Ru=e=>document.querySelector(e),ju=(e,t)=>{e.style.display=t?"flex":"none"};let Lu="startScreen";const zu=e=>{const t=["startScreen","importScreen","multisigScreen","newOrderScreen","orderScreen","loadingScreen","newMultisigScreen1","newMultisigScreen2"];Lu=e;for(const r of t)ju(Ru("#"+r),r===e);"importScreen"===Lu&&(Ru("#import_input").value=""),"newOrderScreen"===Lu&&th&&lh()},Nu=(navigator.language,window.location.href.indexOf("testnet=true")>-1);Nu&&(Ru(".testnet-badge").style.display="block",document.body.classList.add("testnet-padding"));const Du=new class{constructor(e){if(Pe(this,"walletInfoStorage",new Fr),Pe(this,"preferredWalletStorage",new Kr),Pe(this,"walletInfo",null),Pe(this,"systemThemeChangeUnsubscribe",null),Pe(this,"actionsConfiguration"),Pe(this,"walletsList"),Pe(this,"connectRequestParametersCallback"),Pe(this,"connector"),Pe(this,"modal"),Pe(this,"transactionModal"),Pe(this,"connectionRestored",Promise.resolve(!1)),e&&"connector"in e&&e.connector)this.connector=e.connector;else{if(!(e&&"manifestUrl"in e&&e.manifestUrl))throw new Ur("You have to specify a `manifestUrl` or a `connector` in the options.");this.connector=new oe({manifestUrl:e.manifestUrl})}this.modal=new Fc({connector:this.connector,setConnectRequestParametersCallback:e=>{this.connectRequestParametersCallback=e}}),this.transactionModal=new Kc({connector:this.connector}),this.walletsList=this.getWallets(),this.walletsList.then((e=>{return jr((t=e.map((e=>e.imageUrl)),[...new Set(t)]));var t}));const t=this.normalizeWidgetRoot(null==e?void 0:e.widgetRootId);this.subscribeToWalletChange(),!1!==(null==e?void 0:e.restoreConnection)&&(this.connectionRestored=new Promise((e=>Ie(this,null,(function*(){yield this.connector.restoreConnection(),this.connector.connected||this.walletInfoStorage.removeWalletInfo(),e(this.connector.connected)}))))),this.uiOptions=_n(e,{uiPreferences:{theme:"SYSTEM"}});const r=this.preferredWalletStorage.getPreferredWalletAppName();Ya({connector:this.connector,preferredWalletAppName:r}),((e,t)=>{(function(e,t,r,n={}){let i;qe((n=>{i=n,t===document?e():qt(t,e(),t.firstChild?null:void 0,r)}),n.owner)})((()=>kt(Nc,{tonConnectUI:t})),document.getElementById(e))})(t,this)}static getWallets(){return oe.getWallets()}get connected(){return this.connector.connected}get account(){return this.connector.account}get wallet(){return this.connector.wallet?Be(Be({},this.connector.wallet),this.walletInfo):null}set uiOptions(e){var t,r,n,i,o,s,a;this.checkButtonRootExist(e.buttonRootId),this.actionsConfiguration=e.actionsConfiguration,(null==(t=e.uiPreferences)?void 0:t.theme)?"SYSTEM"!==(null==(r=e.uiPreferences)?void 0:r.theme)?(null==(n=this.systemThemeChangeUnsubscribe)||n.call(this),Bn(e.uiPreferences.theme,e.uiPreferences.colorsSet)):(Bn(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?ir.LIGHT:ir.DARK,e.uiPreferences.colorsSet),this.systemThemeChangeUnsubscribe||(this.systemThemeChangeUnsubscribe=function(e){const t=t=>e(t.matches?ir.DARK:ir.LIGHT);return window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t),()=>window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change",t)}(Bn))):(null==(i=e.uiPreferences)?void 0:i.colorsSet)&&(s=e.uiPreferences.colorsSet,Sn[ir.DARK]=_n(s[ir.DARK],Sn[ir.DARK]),Sn[ir.LIGHT]=_n(s[ir.LIGHT],Sn[ir.LIGHT]),xn((e=>({colors:_n(Sn[e.theme],An[e.theme])})))),(null==(o=e.uiPreferences)?void 0:o.borderRadius)&&(a=e.uiPreferences.borderRadius,xn({borderRadius:a})),Ya((t=>{var r,n;const i=_n(Be(Be(Be(Be({},e.language&&{language:e.language}),!!(null==(r=e.actionsConfiguration)?void 0:r.returnStrategy)&&{returnStrategy:e.actionsConfiguration.returnStrategy}),!!(null==(n=e.actionsConfiguration)?void 0:n.twaReturnUrl)&&{twaReturnUrl:e.actionsConfiguration.twaReturnUrl}),!!e.walletsListConfiguration&&{walletsListConfiguration:e.walletsListConfiguration}),cn(t));return void 0!==e.buttonRootId&&(i.buttonRootId=e.buttonRootId),void 0!==e.enableAndroidBackHandler&&(i.enableAndroidBackHandler=e.enableAndroidBackHandler),i}))}setConnectRequestParameters(e){var t;Ya({connectRequestParameters:e}),"ready"!==(null==e?void 0:e.state)&&e||null==(t=this.connectRequestParametersCallback)||t.call(this,null==e?void 0:e.value)}getWallets(){return Ie(this,null,(function*(){return this.connector.getWallets()}))}onStatusChange(e,t){return this.connector.onStatusChange((t=>Ie(this,null,(function*(){if(t){const r=yield this.getSelectedWalletInfo(t);e(Be(Be({},t),r||this.walletInfoStorage.getWalletInfo()))}else e(t)}))),t)}openModal(){return Ie(this,null,(function*(){return this.modal.open()}))}closeModal(){this.modal.close()}onModalStateChange(e){return this.modal.onStateChange(e)}get modalState(){return this.modal.state}connectWallet(){return Ie(this,null,(function*(){const e=(yield this.getWallets()).find(ee);return e?yield this.connectEmbeddedWallet(e):yield this.connectExternalWallet()}))}disconnect(){return setTimeout((()=>Xr(null))),Qr(null),this.walletInfoStorage.removeWalletInfo(),this.connector.disconnect()}sendTransaction(e,t){return Ie(this,null,(function*(){if(!this.connected)throw new Ur("Connect wallet to send a transaction.");On()&&Rn();const{notifications:r,modals:n,returnStrategy:i,twaReturnUrl:o,skipRedirectToWallet:s}=this.getModalsAndNotificationsConfiguration(t);$c({name:"confirm-transaction",showNotification:r.includes("before"),openModal:n.includes("before")});const a=()=>{const e="ios"===Nr().os,t="ios"===s&&e||"always"===s;this.walletInfo&&"universalLink"in this.walletInfo&&"universal-link"===this.walletInfo.openMethod&&!t&&(L(this.walletInfo.universalLink)?El(this.walletInfo.universalLink,{returnStrategy:i,twaReturnUrl:o||Ga.twaReturnUrl,forceRedirect:!1}):Tr(Bl(this.walletInfo.universalLink,i)))},l=new AbortController,c=this.onTransactionModalStateChange((e=>{(null==e?void 0:e.openModal)||(c(),e||l.abort())}));try{const t=yield this.waitForSendTransaction({transaction:e,abortSignal:l.signal},a);return $c({name:"transaction-sent",showNotification:r.includes("success"),openModal:n.includes("success")}),t}catch(e){throw $c({name:"transaction-canceled",showNotification:r.includes("error"),openModal:n.includes("error")}),e instanceof m?e:(console.error(e),new Ur("Unhandled error:"+e))}finally{c()}}))}connectEmbeddedWallet(e){return Ie(this,null,(function*(){const t=t=>{Qr(e),this.connector.connect({jsBridgeKey:e.jsBridgeKey},t)},r=Ga.connectRequestParameters;return"loading"===(null==r?void 0:r.state)?this.connectRequestParametersCallback=t:t(null==r?void 0:r.value),yield this.waitForWalletConnection({ignoreErrors:!1})}))}connectExternalWallet(){return Ie(this,null,(function*(){const e=new AbortController;Dc();const t=this.onModalStateChange((r=>{const{status:n,closeReason:i}=r;"opened"!==n&&(t(),"action-cancelled"===i&&e.abort())}));return yield this.waitForWalletConnection({ignoreErrors:!0,abortSignal:e.signal})}))}waitForWalletConnection(e){return Ie(this,null,(function*(){return new Promise(((t,r)=>{const{ignoreErrors:n=!1,abortSignal:i=null}=e;if(i&&i.aborted)return r(new Ur("Wallet was not connected"));const o=e=>Ie(this,null,(function*(){if(e)s(),t(e);else{if(n)return;s(),r(new Ur("Wallet was not connected"))}})),s=this.onStatusChange((e=>o(e)),(e=>(e=>{n||(s(),r(e))})(e)));i&&i.addEventListener("abort",(()=>{s(),r(new Ur("Wallet was not connected"))}))}))}))}waitForSendTransaction(e,t){return Ie(this,null,(function*(){return new Promise(((r,n)=>{const{transaction:i,abortSignal:o}=e;if(o.aborted)return n(new Ur("Transaction was not sent"));const s=e=>Ie(this,null,(function*(){r(e)}));this.connector.sendTransaction(i,t).then((e=>s(e))).catch((e=>(e=>{n(e)})(e))),o.addEventListener("abort",(()=>{n(new Ur("Transaction was not sent"))}))}))}))}onTransactionModalStateChange(e){return this.transactionModal.onStateChange(e)}subscribeToWalletChange(){this.connector.onStatusChange((e=>Ie(this,null,(function*(){var t;e?(yield this.updateWalletInfo(e),this.setPreferredWalletAppName((null==(t=this.walletInfo)?void 0:t.appName)||e.device.appName)):this.walletInfoStorage.removeWalletInfo()}))))}setPreferredWalletAppName(e){this.preferredWalletStorage.setPreferredWalletAppName(e),Ya({preferredWalletAppName:e})}getSelectedWalletInfo(e){return Ie(this,null,(function*(){let t,r=Gr();if(!r)return null;if("name"in r)t=r;else{const n=Ja(yield this.walletsList,Ga.walletsListConfiguration).find((t=>rl(t,e.device.appName)));if(!n)throw new Ur(`Cannot find WalletInfo for the '${e.device.appName}' wallet`);t=Be(Be({},n),r)}return t}))}updateWalletInfo(e){return Ie(this,null,(function*(){const t=yield this.getSelectedWalletInfo(e);if(t)return this.walletInfo=t,void this.walletInfoStorage.setWalletInfo(t);const r=this.walletInfoStorage.getWalletInfo();this.walletInfo=r||(yield this.walletsList).find((t=>rl(t,e.device.appName)))||null}))}normalizeWidgetRoot(e){if(!e||!document.getElementById(e)){e="tc-widget-root";const t=document.createElement("div");t.id=e,document.body.appendChild(t)}return e}checkButtonRootExist(e){if(null!=e&&!document.getElementById(e))throw new Ur(`${e} element not found in the document.`)}getModalsAndNotificationsConfiguration(e){var t,r,n,i,o,s;const a=["before","success","error"];let l=a;(null==(t=this.actionsConfiguration)?void 0:t.notifications)&&"all"!==(null==(r=this.actionsConfiguration)?void 0:r.notifications)&&(l=this.actionsConfiguration.notifications),(null==e?void 0:e.notifications)&&(l="all"===e.notifications?a:e.notifications);let c=["before"];(null==(n=this.actionsConfiguration)?void 0:n.modals)&&(c="all"===this.actionsConfiguration.modals?a:this.actionsConfiguration.modals),(null==e?void 0:e.modals)&&(c="all"===e.modals?a:e.modals);const d=(null==e?void 0:e.returnStrategy)||(null==(i=this.actionsConfiguration)?void 0:i.returnStrategy)||"back",u=(null==e?void 0:e.twaReturnUrl)||(null==(o=this.actionsConfiguration)?void 0:o.twaReturnUrl);let h=(null==e?void 0:e.skipRedirectToWallet)||(null==(s=this.actionsConfiguration)?void 0:s.skipRedirectToWallet)||"ios";return On()&&(h="never"),{notifications:l,modals:c,returnStrategy:d,twaReturnUrl:u,skipRedirectToWallet:h}}}({manifestUrl:"https://multisig.ton.org/tonconnect-manifest.json",buttonRootId:"tonConnectButton"});let $u;Du.uiOptions={uiPreferences:{theme:ir.LIGHT}},Du.onStatusChange((e=>{null===e?$u=null:e.account&&($u=a.Address.parseRaw(e.account.address))})),Ru("#createMultisigButton").addEventListener("click",(()=>{fh(),mh="create",zu("newMultisigScreen1")})),Ru("#importMultisigButton").addEventListener("click",(()=>{zu("importScreen")})),Ru("#import_okButton").addEventListener("click",(()=>{const e=Ru("#import_input").value,t=Wc(e,Nu);t?alert(t):Hu(e)})),Ru("#import_backButton").addEventListener("click",(()=>{zu("startScreen")}));const Fu=a.Cell.fromBase64("te6cckECEgEABJUAART/APSkE/S88sgLAQIBYgIDAsrQM9DTAwFxsJJfA+D6QDAi10nAAJJfA+AC0x8BIMAAkl8E4AHTPwHtRNDT/wEB0wcBAdTTBwEB9ATSAAEB0SiCEPcYUQ+64w8FREPIUAYBy/9QBAHLBxLMAQHLB/QAAQHKAMntVAQFAgEgDA0BnjgG0/8BKLOOEiCE/7qSMCSWUwW68uPw4gWkBd4B0gABAdMHAQHTLwEB1NEjkSaRKuJSMHj0Dm+h8uPvHscF8uPvIPgjvvLgbyD4I6FUbXAGApo2OCaCEHUJf126jroGghCjLFm/uo6p+CgYxwXy4GUD1NEQNBA2RlD4AH+OjSF49HxvpSCRMuMNAbPmWxA1UDSSNDbiUFQT4w1AFVAzBAoJAdT4BwODDPlBMAODCPlBMPgHUAahgSf4AaBw+DaBEgZw+DaggSvscPg2oIEdmHD4NqAipgYioIEFOSagJ6Bw+DgjpIECmCegcPg4oAOmBliggQbgUAWgUAWgQwNw+DdZoAGgHL7y4GT4KFADBwK4AXACyFjPFgEBy//JiCLIywH0APQAywDJcCH5AHTIywISygfL/8nQyIIQnHP7olgKAssfyz8mAcsHUlDMUAsByy8bzCoBygAKlRkBywcIkTDiECRwQImAGIBQ2zwRCACSjkXIWAHLBVAFzxZQA/oCVHEjI+1E7UXtR59byFADzxfJE3dQA8trzMztZ+1l7WR0f+0RmHYBy2vMAc8X7UHt8QHy/8kB+wDbBgLiNgTT/wEB0y8BAdMHAQHT/wEB1NH4KFAFAXACyFjPFgEBy//JiCLIywH0APQAywDJcAH5AHTIywISygfL/8nQG8cF8uBlJvkAGrpRk74ZsPLgZgf4I77y4G9EFFBW+AB/jo0hePR8b6UgkTLjDQGz5lsRCgH6AtdM0NMfASCCEPE4Hlu6jmqCEB0M+9O6jl5sRNMHAQHUIX9wjhdREnj0fG+lMiGZUwK68uBnAqQC3gGzEuZsISDCAPLgbiPCAPLgbVMwu/LgbQH0BCF/cI4XURJ49HxvpTIhmVMCuvLgZwKkAt4BsxLmbCEw0VUjkTDi4w0LABAw0wfUAvsA0QFDv3T/aiaGn/gIDpg4CA6mmDgID6AmkAAIDoiBqvgoD8EdDA4CAWYPEADC+AcDgwz5QTADgwj5QTD4B1AGoYEn+AGgcPg2gRIGcPg2oIEr7HD4NqCBHZhw+DagIqYGIqCBBTkmoCegcPg4I6SBApgnoHD4OKADpgZYoIEG4FAFoFAFoEMDcPg3WaABoADxsMr7UTQ0/8BAdMHAQHU0wcBAfQE0gABAdEjf3COF1ESePR8b6UyIZlTArry4GcCpALeAbMS5mwhUjC68uBsIX9wjhdREnj0fG+lMiGZUwK68uBnAqQC3gGzEuZsITAiwgDy4G4kwgDy4G1SQ7vy4G0BkjN/kQPiA4AFZsMn+CgBAXACyFjPFgEBy//JiCLIywH0APQAywDJcAH5AHTIywISygfL/8nQgEQhCAmMFqAYchWwszwXcsN9YFccUdYcFZ8q18EnjQLz1klHzYNH/nQ=="),Ku=a.Cell.fromBase64("te6cckEBAQEAIwAIQgJjBagGHIVsLM8F3LDfWBXHFHWHBWfKtfBJ40C89ZJR80AoJo0=");let Vu=null;const Hu=async e=>{zu("loadingScreen");const t=a.Address.parseFriendly(e);t.isBounceable=!0,t.isTestOnly=Nu,Ru("#mulisig_address").innerHTML=Yc(t),localStorage.setItem("multisigAddress",e),ju(Ru("#multisig_content"),!1),ju(Ru("#multisig_error"),!1);try{Vu=await(async(e,t,r,n)=>{const i=await qc("account",{address:Qc(e)},r);Xc("active"===i.status,"Contract not active"),Xc(a.Cell.fromBase64(i.code).equals(t),"The contract code DOES NOT match the multisig code from this repository");const o=i.balance,s=function(e){const t=e.beginParse(),r=t.loadUintBig(256),n=t.loadUint(8),i=id(t.loadRef()),o=t.loadUint(8),s=id(t.loadMaybeRef()),a=t.loadBit();return od(t),{nextOderSeqno:r,threshold:n,signers:i,signersCount:o,proposers:s,allowArbitraryOrderSeqno:a}}(a.Cell.fromBase64(i.data));s.allowArbitraryOrderSeqno&&Xc(s.nextOderSeqno===BigInt(0),"invalid nextOrderSeqno for allowArbitraryOrderSeqno");const l=s.signers,c=s.proposers;Xc(l.length===s.signersCount,"invalid signersCount"),Xc(s.threshold>0,"threshold <= 0"),Xc(s.threshold<=s.signersCount,"invalid threshold");const d=sd.createFromAddress(e.address),u=new Zc(e.address,r),h=await d.getMultisigData(u);s.allowArbitraryOrderSeqno?Xc(h.nextOrderSeqno===BigInt(-1),"nextOderSeqno doesn't match"):Xc(h.nextOrderSeqno===s.nextOderSeqno,"nextOderSeqno doesn't match"),Xc(h.threshold===BigInt(s.threshold),"threshold doesn't match"),Xc(Jc(h.signers,s.signers),"invalid signers"),Xc(Jc(h.proposers,s.proposers),"invalid proposers");const f=sd.createFromConfig({threshold:s.threshold,signers:s.signers,proposers:s.proposers,allowArbitrarySeqno:s.allowArbitraryOrderSeqno},t).address.equals(e.address),p=[];if(n){const t=await qc("transactions",{account:Qc(e)},r);for(const e of t.transactions){if(!e.in_msg.message_content)continue;if(!e.in_msg.message_content.body)continue;const t=a.Cell.fromBase64(e.in_msg.message_content.body).beginParse();if(t.remainingBits<32)continue;const n=t.loadUint(32);if(1963556701===n)try{t.loadUintBig(64);const n=t.loadUintBig(256),i=a.Address.parse(e.in_msg.source),o=await d.getOrderAddress(u,n);if(!i.equals(o))throw new Error("fake order");p.push({type:"execute",order:{address:{address:i,isBounceable:!0,isTestOnly:r},id:n}})}catch(e){p.push({type:"execute",errorMessage:e.message})}else if(4145565967===n)try{if(1!==e.out_msgs.length)throw new Error("invalid out messages");const n=e.out_msgs[0],{orderAddress:i,orderId:o}=ld(n),s=await d.getOrderAddress(u,o);if(!i.equals(s))throw new Error("fake order");const l=t.loadUint(64),c=(t.loadUint(256),t.loadUint(1)),h=t.loadUint(8),f=t.loadUint(48),g=t.loadRef().beginParse().loadDictDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell());od(t),console.log("IN",{queryId:l,orderId:o,orderAddress:i.toString(),isSigner:c,index:h,expiredAt:f,order:g}),p.push({type:"new",order:{address:{address:i,isBounceable:!0,isTestOnly:r},id:o}})}catch(e){console.log(e),p.push({type:"new",errorMessage:"Invalid new order: "+e.message})}}}return{address:e,multisigContract:d,provider:u,signers:l,proposers:c,threshold:s.threshold,allowArbitraryOrderSeqno:s.allowArbitraryOrderSeqno,nextOderSeqno:s.nextOderSeqno,tonBalance:o,lastOrders:p,stateInitMatches:f}})(a.Address.parseFriendly(e),Fu,Nu,!0);const{tonBalance:t,threshold:r,signers:n,proposers:i,allowArbitraryOrderSeqno:o,nextOderSeqno:s,lastOrders:l}=Vu;Ru("#multisig_tonBalance").innerText=(0,a.fromNano)(t)+" TON",Ru("#multisig_threshold").innerText=r+"/"+n.length;let c="";for(let e=0;e#${e} - ${await Gc(t,Nu)}`}if(Ru("#multisig_signersList").innerHTML=c,i.length>0){let e="";for(let t=0;t#${t} - ${await Gc(r,Nu)}`}Ru("#multisig_proposersList").innerHTML=e}else Ru("#multisig_proposersList").innerHTML="No proposers";Ru("#multisig_orderId").innerText=o?"Arbitrary":s.toString();let d="";for(const e of l)e.errorMessage||(d+=`
${"new"===e.type?"New order":"Executed order"} #${e.order.id}
`);Ru("#mainScreen_ordersList").innerHTML=d,(".multisig_lastOrder",document.querySelectorAll(".multisig_lastOrder")).forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.attributes.getNamedItem("order-address").value;Zu(t)}))})),zu("multisigScreen"),ju(Ru("#multisig_content"),!0)}catch(e){console.error(e),zu("multisigScreen"),ju(Ru("#multisig_error"),!0),Ru("#multisig_error").innerText=e.message}};Ru("#multisig_logoutButton").addEventListener("click",(()=>{localStorage.removeItem("multisigAddress"),zu("startScreen")})),Ru("#multisig_createNewOrderButton").addEventListener("click",(()=>{zu("newOrderScreen")}));let qu=null;const Zu=async e=>{zu("loadingScreen");const t=a.Address.parseFriendly(e);t.isBounceable=!0,t.isTestOnly=Nu,Ru("#order_address").innerHTML=Yc(t),ju(Ru("#order_content"),!1),ju(Ru("#order_error"),!1);try{qu=await(async(e,t,r,n)=>{const i=await qc("account",{address:Qc(e)},n);Xc("active"===i.status,"Contract not active"),Xc(a.Cell.fromBase64(i.code).equals(t),"The contract code DOES NOT match the multisig-order code from this repository");const o=i.balance,s=function(e){const t=e.beginParse(),r=t.loadAddress(),n=t.loadUintBig(256);if(0===t.remainingBits)throw new Error("Order not initialized");const i=t.loadUint(8),o=t.loadBoolean(),s=cd(t.loadRef()),a=t.loadUint(256),l=t.loadUint(8),c=t.loadUint(48),d=t.loadRef();return od(t),{multisigAddress:r,orderSeqno:n,threshold:i,isExecuted:o,signers:s,approvalsMask:a,approvalsNum:l,expirationDate:c,order:d}}(a.Cell.fromBase64(i.data));wd(s.threshold),Xc(s.threshold>0,"threshold <= 0"),Xc(s.threshold<=s.signers.length,"threshold invalid"),wd(s.approvalsMask),wd(s.approvalsNum),Xc(s.approvalsNum<=s.signers.length,"approvalsNum invalid"),wd(s.expirationDate),Xc(s.multisigAddress.equals(r.address.address),"multisig address does not match");const l=await r.multisigContract.getOrderAddress(r.provider,s.orderSeqno);Xc(l.equals(e.address),"fake multisig-order"),s.isExecuted||(Xc(r.threshold===s.threshold,"multisig threshold != order threshold"),Xc(Jc(r.signers,s.signers),"multisig signers != order signers"));const c=new Zc(e.address,n),d=dd.createFromAddress(e.address),u=await d.getOrderDataStrict(c);Xc(u.multisig.equals(s.multisigAddress),"invalid multisigAddress"),Xc(u.order_seqno===s.orderSeqno,"invalid orderSeqno"),Xc(u.threshold===s.threshold,"invalid threshold"),Xc(u.executed===s.isExecuted,"invalid isExecuted"),Xc(Jc(u.signers,s.signers),"invalid signers"),Xc(u._approvals===BigInt(s.approvalsMask),"invalid approvalsMask"),Xc(u.approvals_num===s.approvalsNum,"invalid approvalsNum"),Xc(u.expiration_date===BigInt(s.expirationDate),"invalid expirationDate"),Xc(u.order.hash().equals(s.order.hash()),"invalid order");const h=dd.createFromConfig({multisig:s.multisigAddress,orderSeqno:s.orderSeqno},t).address.equals(e.address),f=a.Dictionary.loadDirect(a.Dictionary.Keys.Uint(8),a.Dictionary.Values.Cell(),s.order),p=async e=>{try{const t=e.beginParse();if(0===t.remainingBits&&0==t.remainingRefs)return"Send Toncoins without comment"}catch(e){}try{const t=e.beginParse();if(0==t.loadUint(32)){const e=t.loadStringTail();return`Send Toncoins with comment "${encodeURI(e)}"`}}catch(e){}try{const t=e.beginParse(),r=bd.parseMintMessage(t);Xc(0===r.internalMessage.forwardPayload.remainingBits&&0===r.internalMessage.forwardPayload.remainingRefs,"forward payload not supported");const i=await Gc(r.toAddress,n);return`Mint ${r.internalMessage.jettonAmount} jettons (in units) to ${i}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse();return bd.parseTopUp(t),"Top Up"}catch(e){}try{const t=e.beginParse(),r=bd.parseChangeAdmin(t);return`Change Admin to ${await Gc(r.newAdminAddress,n)}`}catch(e){}try{const t=e.beginParse();return bd.parseClaimAdmin(t),"Claim Admin"}catch(e){}try{const t=e.beginParse();return`Change metadata URL to "${bd.parseChangeContent(t).newMetadataUrl}"`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseSetStatus),i=await Gc(r.toAddress,n),o=(e=>{switch(e){case 0:return"unlock";case 1:return"out";case 2:return"in";case 3:return"full";default:throw new Error("Invalid argument!")}})(r.action.newStatus);return`Lock jetton wallet of user ${i}. Set status "${o}" - "${md(o)}"; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseTransfer);if(r.action.customPayload)throw new Error("custom payload not supported");Xc(0===r.action.forwardPayload.remainingBits&&0===r.action.forwardPayload.remainingRefs,"forward payload not supported");const i=await Gc(r.toAddress,n),o=await Gc(r.action.toAddress,n);return`Force transfer ${r.action.jettonAmount} jettons (in units) from user ${i} to ${o}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}try{const t=e.beginParse(),r=bd.parseCallTo(t,bd.parseBurn);if(r.action.customPayload)throw new Error("custom payload not supported");const i=await Gc(r.toAddress,n);return`Force burn ${r.action.jettonAmount} jettons (in units) from user ${i}; ${(0,a.fromNano)(r.tonAmount)} TON for gas`}catch(e){}throw new Error("Unknown action")};let g=[];const m=f.keys();for(let e of m){let t=`
Action #${e}:
`;const r=f.get(e).beginParse(),i=r.loadUint(32);if(4046986843===i){const e=r.loadUint(8);let i=[],o=!1;1&e&&i.push("Pays fees separately"),2&e&&i.push("Ignore sending errors"),128&e&&(o=!0,i.push("CARRY ALL BALANCE")),64&e&&i.push("Carry all the remaining value of the inbound message"),32&e&&i.push("DESTROY ACCOUNT");const s=r.loadRef();od(r);const l=(0,a.loadMessageRelaxed)(s.beginParse());console.log(l);const c=l.info,d=await Gc(c.dest,n);t+=`
Send ${o?"ALL BALANCE":(0,a.fromNano)(c.value.coins)} TON to ${d}
`,t+=`
${await p(l.body)}
`,e&&(t+=`
Send mode: ${i.join(", ")}.
`)}else{if(487390163!==i)throw new Error("unknown action op");{const e=r.loadUint(8),i=id(r.loadRef()),o=r.loadUint(1)?id(r.loadRef()):[];od(r),Xc(i.length>0,"invalid new signers"),Xc(e>0,"invalid new threshold"),Xc(e<=i.length,"invalid new threshold"),t+="
Update Multisig Params
",t+=`
New threshold : ${e.toString()}
`,t+="
New signers:
";for(let e=0;e#${e} - ${await Gc(r,n)}`}if(t+="
New proposers:
",o.length>0)for(let e=0;e#${e} - ${await Gc(r,n)}`}else t+="
No poroposers
"}}g.push(t)}return{address:e,tonBalance:o,orderId:s.orderSeqno,isExecuted:s.isExecuted,approvalsNum:s.approvalsNum,approvalsMask:s.approvalsMask,threshold:s.threshold,signers:s.signers,expiresAt:new Date(1e3*s.expirationDate),actions:g,stateInitMatches:h}})(t,Ku,Vu,Nu);const{tonBalance:e,actions:r,orderId:n,isExecuted:i,approvalsNum:o,approvalsMask:s,threshold:l,signers:c,expiresAt:d}=qu,u=(new Date).getTime()>d.getTime();Ru("#order_id").innerText="#"+n,Ru("#order_tonBalance").innerText=(0,a.fromNano)(e)+" TON",Ru("#order_executed").innerText=i?"Yes":"Not yet",Ru("#order_approvals").innerText=o+"/"+l,Ru("#order_expiresAt").innerText=(u?"❌ EXPIRED - ":"")+d.toString();let h="";for(let e=0;e#${e} - ${await Gc(t,Nu)} - ${s&1<`}Ru("#order_signersList").innerHTML=h;let f="";for(const e of r)f+=e;0===r.length?Ru("#order_actionsTitle").innerText="No actions":1===r.length?Ru("#order_actionsTitle").innerText="One action:":Ru("#order_actionsTitle").innerText=r.length+" actions:",Ru("#order_actions").innerHTML=f,ju(Ru("#order_approveButton"),!i&&!u),ju(Ru("#order_approveNote"),!i&&!u),zu("orderScreen"),ju(Ru("#order_content"),!0)}catch(e){console.error(e),zu("orderScreen"),ju(Ru("#order_error"),!0),Ru("#order_error").innerText=e.message}};Ru("#order_backButton").addEventListener("click",(()=>{zu("multisigScreen")})),Ru("#order_approveButton").addEventListener("click",(async()=>{if(!$u)return void alert("Please connect wallet");if(-1==qu.signers.findIndex((e=>e.equals($u))))return void alert("You are not signer");const e=Qc(qu.address),t=Yu.toString(),r=(0,a.beginCell)().storeUint(0,32).storeStringTail("approve").endCell().toBoc().toString("base64");console.log({orderAddressString:e,amount:t});const n={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:e,amount:t,payload:r}]};try{await Du.sendTransaction(n),await Zu(e)}catch(e){console.error(e)}}));const Wu=(e,t,r)=>{const n=t=>({error:e+": "+t}),i=e=>({value:e});if(null==t||""===t)return n("Empty");switch(r){case"TON":return((e,t)=>{try{const r=function(e,t){const r=function(e){let t=1n;for(let r=0;r2)throw Error("Invalid number");let o=i[0],s=i[1];if(o||(o="0"),s||(s="0"),s.length>t)throw Error("Invalid number");for(;s.length{try{const t=BigInt(e);return t<=0?n("Enter positive amount"):i(t)}catch(e){return n("Invalid amount")}})(t);case"Address":if(!a.Address.isFriendly(t))return n("Invalid Address");const e=a.Address.parseFriendly(t);return e.isTestOnly&&!Nu?n("Please enter mainnet address"):i(e);case"URL":return t.startsWith("https://")?i(t):n("Invalid URL");case"Status":return pd.indexOf(t)>-1?i(t):n("Invalid status. Please use: "+pd.join(", "))}},Gu=(0,a.toNano)("0.2"),Yu=(0,a.toNano)("0.1"),Qu=(0,a.toNano)("0.05"),Ju=async e=>{try{const t=await kd(e.jettonMinterAddress,Nu,!1);return Vu.address.address.equals(t.adminAddress)?{value:t}:{error:"Multisig is not admin of this jetton"}}catch(e){return console.error(e),{error:"Jetton-minter check error"}}},Xu=async e=>{try{const t=await Vu.multisigContract.getOrderAddress(Vu.provider,e);return"uninit"===(await qc("account",{address:t.toRawString()},Nu)).status?{value:!0}:{error:`Order ${e} already exists`}}catch(e){return console.error(e),{error:"Possibly connectivity error"}}},eh=[{name:"Transfer TON",fields:{amount:{name:"TON Amount",type:"TON"},toAddress:{name:"Destination Address",type:"Address"}},makeMessage:e=>({toAddress:e.toAddress,tonAmount:e.amount,body:(0,a.beginCell)().endCell()})},{name:"Change Jetton Admin",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},newAdminAddress:{name:"New Admin Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.changeAdminMessage(e.newAdminAddress.address)})},{name:"Claim Jetton Admin",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"}},check:async e=>{try{const t=await kd(e.jettonMinterAddress,Nu,!0);return t.nextAdminAddress&&Vu.address.address.equals(t.nextAdminAddress)?{value:t}:{error:"Multisig is not next-admin of this jetton"}}catch(e){return console.error(e),{error:"Jetton-minter check error"}}},makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.claimAdminMessage()})},{name:"Top-up Jetton Minter",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"TON Amount",type:"TON"}},makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:e.amount,body:bd.topUpMessage()})},{name:"Change Jetton Metadata URL",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},newMetadataUrl:{name:"New Metadata URL",type:"URL"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.changeContentMessage({uri:e.newMetadataUrl})})},{name:"Mint Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},toAddress:{name:"To Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.mintMessage(e.toAddress.address,e.amount,e.jettonMinterAddress.address,Vu.address.address,null,0n,Qu)})},{name:"Force Burn Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},fromAddress:{name:"User Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.forceBurnMessage(e.amount,e.fromAddress.address,Vu.address.address,Qu)})},{name:"Force Transfer Jetton",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},amount:{name:"Jetton Amount (in units)",type:"Jetton"},fromAddress:{name:"From Address",type:"Address"},toAddress:{name:"To Address",type:"Address"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.forceTransferMessage(e.amount,e.toAddress.address,e.fromAddress.address,e.jettonMinterAddress.address,null,0n,null,Qu)})},{name:"Set status for Jetton Wallet",fields:{jettonMinterAddress:{name:"Jetton Minter Address",type:"Address"},userAddress:{name:"User Address",type:"Address"},newStatus:{name:`New Status (${pd.join(", ")})`,type:"Status"}},check:Ju,makeMessage:e=>({toAddress:e.jettonMinterAddress,tonAmount:Yu,body:bd.lockWalletMessage(e.userAddress.address,gd(e.newStatus),Qu)})}],th=Ru("#newOrder_typeInput");th.innerHTML=(()=>{let e="";for(let t=0;t${eh[t].name}`;return e})();const rh=e=>{const t=eh[e];let r="";for(let n in t.fields)if(t.fields.hasOwnProperty(n)){const i=t.fields[n];if(r+=`
${i.name}:
`,"Status"===i.type){r+=`"}else r+=``}Ru("#newOrder_fieldsContainer").innerHTML=r};th.addEventListener("change",(e=>{rh(th.selectedIndex)})),rh(0);const nh=e=>{Ru("#newOrder_createButton").disabled=e,Ru("#newOrder_backButton").disabled=e},ih=e=>{const t=th.selectedIndex,r=eh[t];th.disabled=e,Ru("#newOrder_orderId").disabled=e;for(let n in r.fields)r.fields.hasOwnProperty(n)&&(Ru(`#newOrder_${t}_${n}`).disabled=e);nh(e)};let oh="fill",sh=null;const ah=e=>{"fill"==e?(ih(!1),Ru("#newOrder_createButton").innerHTML="Create",Ru("#newOrder_backButton").innerHTML="Back"):(Ru("#newOrder_createButton").innerHTML="Send Transaction",Ru("#newOrder_backButton").innerHTML="Cancel"),oh=e};Ru("#newOrder_createButton").addEventListener("click",(async()=>{if(!$u)return void alert("Please connect wallet");if("confirm"===oh){if(!sh)throw new Error("");try{await Du.sendTransaction({validUntil:Math.floor(Date.now()/1e3)+60,messages:[sh]}),zu("multisigScreen")}catch(e){console.error(e)}return}const e=gh(Ru("#newOrder_orderId"));if(null===e||e<0)return void alert("Invalid Order ID");const t=th.selectedIndex,r=eh[t],n={};for(let e in r.fields)if(r.fields.hasOwnProperty(e)){const i=r.fields[e],o=Ru(`#newOrder_${t}_${e}`).value,s=Wu(i.name,o,i.type);if(s.error)return void alert(s.error);n[e]=s.value}ih(!0);const i=await Xu(e);if(i.error)return alert(i.error),void ah("fill");if(r.check){const e=await r.check(n);if(e.error)return alert(e.error),void ah("fill")}const o=r.makeMessage(n),s=Vu.proposers.findIndex((e=>e.equals($u))),l=Vu.signers.findIndex((e=>e.equals($u)));if(-1===s&&-1===l)return alert("Error: you are not proposer and not signer"),void ah("fill");const c=l>-1,d=o.toAddress,u=o.tonAmount,h=o.body,f=Math.floor(Date.now()/1e3)+2592e3,p=sd.packOrder([{type:"transfer",sendMode:a.SendMode.PAY_GAS_SEPARATELY,message:{info:{type:"internal",ihrDisabled:!1,bounce:!0,bounced:!1,dest:d.address,value:{coins:u},ihrFee:0n,forwardFee:0n,createdLt:0n,createdAt:0},body:h}}]),g=sd.newOrderMessage(p,f,c,c?l:s,e,0n),m=g.toBoc().toString("base64");console.log({toAddress:d,tonAmount:u,payloadCell:h,message:g,orderId:e});const y=Qc(Vu.address),b=Gu.toString();sh={address:y,amount:b,payload:m},ah("confirm"),nh(!1)})),Ru("#newOrder_backButton").addEventListener("click",(()=>{"fill"==oh?zu("multisigScreen"):ah("fill")}));const lh=()=>{ah("fill"),sh=null,th.selectedIndex=0,rh(0),Ru("#newOrder_orderId").value=""},ch=Ru("#newMultisig_signersCount"),dh=Ru("#newMultisig_proposersCount"),uh=Ru("#newMultisig_threshold"),hh=Ru("#newMultisig_orderId"),fh=()=>{ch.value="",dh.value="",uh.value="",ju(Ru("#newMultisig_orderIdLabel"),"update"===mh),ju(Ru("#newMultisig_orderId"),"update"===mh)},ph=e=>{if(""==e.value)return null;try{const t=parseInt(e.value);return isNaN(t)?null:t}catch(e){return null}},gh=e=>{if(""==e.value)return null;try{return BigInt(e.value)}catch(e){return null}};let mh="create",yh=null;Ru("#newMultisig1_nextButton").addEventListener("click",(async()=>{const e=ph(ch);if(null===e||e<=0)return void alert("Signers count: not valid number");const t=ph(dh);if(null===t||t<0)return void alert("Proposers count: not valid number");const r=ph(uh);if(null===r||r<=0||r>e)return void alert("Threshold count: not valid number");let n;if("update"===mh){if(n=gh(hh),null===n||n<0)return void alert("Invalid order Id");Ru("#newMultisig1_nextButton").disabled=!0,Ru("#newMultisigScreen1").style.pointerEvents="none";const e=await Xu(n);if(Ru("#newMultisig1_nextButton").disabled=!1,Ru("#newMultisigScreen1").style.pointerEvents="auto",e.error)return void alert(e.error)}yh={signersCount:e,proposersCount:t,threshold:r,orderId:n};let i="";for(let t=0;t
#${t}.
`;Ru("#newMultisig_signers").innerHTML=i;let o="";for(let e=0;e
#${e}.
`;Ru("#newMultisig_proposers").innerHTML=o,Ru("#newMultisig2_createButton").innerText="create"===mh?"Create":"Update",zu("newMultisigScreen2")})),Ru("#newMultisig1_backButton").addEventListener("click",(()=>{zu("create"===mh?"startScreen":"multisigScreen")})),Ru("#newMultisig2_createButton").addEventListener("click",(async()=>{if(!$u)return void alert("Please connect wallet");const e={},t=[];for(let r=0;r{null!=n.splitDepth?(e.storeBit(!0),e.storeUint(n.splitDepth,5)):e.storeBit(!1),null!=n.special?(e.storeBit(!0),e.store(function(e){return t=>{t.storeBit(e.tick),t.storeBit(e.tock)}}(n.special))):e.storeBit(!1),e.storeMaybeRef(n.code),e.storeMaybeRef(n.data),e.storeDict(n.libraries)})(s),console.log({stateInitCell:s.endCell()});const l={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:i.toString({urlSafe:!0,bounceable:!0,testOnly:Nu}),amount:o,stateInit:s.endCell().toBoc().toString("base64")}]};try{await Du.sendTransaction(l),Hu(Qc({address:i,isBounceable:!0,isTestOnly:Nu}))}catch(e){console.error(e)}}else{const e=Vu.proposers.findIndex((e=>e.equals($u))),n=Vu.signers.findIndex((e=>e.equals($u)));if(-1===e&&-1===n)return void alert("Error: you are not proposer and not signer");const i=n>-1,o=Math.floor(Date.now()/1e3)+2592e3,s=sd.packOrder([{type:"update",threshold:yh.threshold,signers:t,proposers:r}]),a=sd.newOrderMessage(s,o,i,i?n:e,yh.orderId,0n).toBoc().toString("base64"),l=Qc(Vu.address),c=Yu.toString(),d={validUntil:Math.floor(Date.now()/1e3)+60,messages:[{address:l,amount:c,payload:a}]};try{await Du.sendTransaction(d),Hu(l)}catch(e){console.error(e)}}var n})),Ru("#newMultisig2_backButton").addEventListener("click",(()=>{zu("newMultisigScreen1")})),Ru("#multisig_updateButton").addEventListener("click",(()=>{mh="update",fh(),zu("newMultisigScreen1")}));let bh=localStorage.getItem("multisigAddress");bh?Hu(bh):zu("startScreen")})()})(); \ No newline at end of file