`);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+="
`);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+="
`;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