@mojito-inc/secondary-market
Version:
Mojito secondary market is the platform to purchase NFT.
2 lines (1 loc) • 7.47 kB
JavaScript
"use strict";var e=require("@solana/web3.js"),i=require("buffer"),n=require("bn.js"),r=require("bs58"),l=require("./getEtherScanURL.utils.js"),o=require("../constant/index.js"),a=require("./customErrorMessage.utils.js"),t=require("./getSolanaBalance.utils.js"),s=require("./fetchSolanaPriorityFee.utils.js");exports.removeListingSolanaItem=async(u,c,d,v,g,b,m,y,p,f=.00228288)=>{var h,S,w,P,E,k,T,L,A,B,R,C,I,K,W;try{if(!d)return{success:!1,error:"Your wallet session has been closed. Please reconnect your wallet to continue."};const c=l.getSolanaEnvByChainId(b),K=await t.getSolanaBalance(u,c,y),{err:W,instruction:D,connectedPublicKey:_,connection:M}=await(async(o,t,s,u)=>{var c,d,v,g,b,m,y,p,f,h,S,w,P,E,k,T,L,A,B,R,C,I;try{const a=l.getSolanaEnvByChainId(t),K=new e.Connection(u||e.clusterApiUrl(a),{confirmTransactionInitialTimeout:3e5,commitment:"confirmed"}),W=new e.PublicKey(null!==(c=null==s?void 0:s.bubblegumProgram)&&void 0!==c?c:""),D=new e.PublicKey(null!==(d=null==s?void 0:s.compressionProgram)&&void 0!==d?d:""),_=new e.PublicKey(null!==(v=null==s?void 0:s.newLeafDelegate)&&void 0!==v?v:""),M=new e.PublicKey(null!==(g=null==s?void 0:s.mintAccount)&&void 0!==g?g:""),U=new e.PublicKey(o),O=new e.PublicKey(null!==(b=null==s?void 0:s.newLeafDelegate)&&void 0!==b?b:""),q=[i.Buffer.from("marketplace")],[j,F]=e.PublicKey.findProgramAddressSync(q,O),H=new n(null===(m=null==s?void 0:s.bubblegumListArg)||void 0===m?void 0:m.nonce).toArray("le",8),x=new e.PublicKey(null!==(y=null==s?void 0:s.listingReceipt)&&void 0!==y?y:""),V=new e.PublicKey(null!==(p=null==s?void 0:s.treeAuthority)&&void 0!==p?p:""),J=new e.PublicKey(null!==(f=null==s?void 0:s.logWrapper)&&void 0!==f?f:""),N=new e.PublicKey(null!==(h=null==s?void 0:s.merkleTree)&&void 0!==h?h:""),z=r.decode(null!==(w=null===(S=null==s?void 0:s.bubblegumListArg)||void 0===S?void 0:S.dataHash)&&void 0!==w?w:""),Y=r.decode(null!==(E=null===(P=null==s?void 0:s.bubblegumListArg)||void 0===P?void 0:P.creatorHash)&&void 0!==E?E:""),G=r.decode(null!==(T=null===(k=null==s?void 0:s.bubblegumListArg)||void 0===k?void 0:k.root)&&void 0!==T?T:""),Q=Array.from(Array(10).keys()).map((i=>{var n,r,l;return{pubkey:new e.PublicKey(null!==(l=null===(r=null===(n=null==s?void 0:s.bubblegumListArg)||void 0===n?void 0:n.proof)||void 0===r?void 0:r[i])&&void 0!==l?l:""),isSigner:!1,isWritable:!1}}));if(32!==z.length||32!==Y.length)throw new Error("Hash length is not 32 bytes");const X=new e.PublicKey(null!==(L=null==s?void 0:s.systemProgram)&&void 0!==L?L:""),Z=new e.PublicKey(null!==(A=null==s?void 0:s.tokenProgram)&&void 0!==A?A:""),$=new e.PublicKey(null!==(B=null==s?void 0:s.rent)&&void 0!==B?B:"");return{instruction:new e.TransactionInstruction({programId:_,keys:[{pubkey:U,isSigner:!0,isWritable:!0},{pubkey:M,isSigner:!1,isWritable:!0},{pubkey:x,isSigner:!1,isWritable:!0},{pubkey:X,isSigner:!1,isWritable:!0},{pubkey:Z,isSigner:!1,isWritable:!0},{pubkey:$,isSigner:!1,isWritable:!0},{pubkey:W,isSigner:!1,isWritable:!0},{pubkey:D,isSigner:!1,isWritable:!0},{pubkey:V,isSigner:!1,isWritable:!0},{pubkey:U,isSigner:!1,isWritable:!0},{pubkey:j,isSigner:!1,isWritable:!0},{pubkey:U,isSigner:!1,isWritable:!0},{pubkey:J,isSigner:!1,isWritable:!0},{pubkey:N,isSigner:!1,isWritable:!0},...Q],data:i.Buffer.concat([i.Buffer.from(null!==(R=null==s?void 0:s.listDiscriminator)&&void 0!==R?R:[]),i.Buffer.from(Uint8Array.of(...G,...z,...Y,...H,...new n(null!==(I=null===(C=null==s?void 0:s.bubblegumListArg)||void 0===C?void 0:C.index)&&void 0!==I?I:0).toArray("le",8)))])}),connectedPublicKey:U,connection:K,err:null}}catch(e){return{err:a.customErrorMessage(e)}}})(u,b,m,y);if(!W&&D){if("phantom"===v.toLowerCase()||"backpack"===v.toLowerCase()){const i=new e.Transaction({feePayer:_}).add(D),n=await M.getLatestBlockhash("confirmed");i.recentBlockhash=n.blockhash,i.lastValidBlockHeight=n.lastValidBlockHeight,i.add(e.ComputeBudgetProgram.setComputeUnitLimit({units:14e5}));const r=await s.fetchSolanaPriorityFee(y,i.serialize({verifySignatures:!1})),l=e.ComputeBudgetProgram.setComputeUnitPrice({microLamports:r});i.add(l);const t=await M.getFeeForMessage(i.compileMessage(),"confirmed"),c=(null!==(h=null==t?void 0:t.value)&&void 0!==h?h:0)+f*e.LAMPORTS_PER_SOL,m=K.native*e.LAMPORTS_PER_SOL;if(m<=0||m<c)return{success:!1,error:"Insufficient SOL for initiating the transaction."};try{g("Initiating remove listing transaction.");const e=await(null===(w=null===(S=null==d?void 0:d.adapter)||void 0===S?void 0:S.sendTransaction)||void 0===w?void 0:w.call(S,i,M,{skipPreflight:!0,preflightCommitment:"confirmed"}));await M.confirmTransaction(Object.assign({signature:e},n),"confirmed");const r=await M.getSignatureStatus(e);return null===(null===(P=null==r?void 0:r.value)||void 0===P?void 0:P.err)?{success:!0,response:{hash:e}}:{success:!1,error:"Transaction Failed"}}catch(e){return(null===(k=null===(E=null==e?void 0:e.message)||void 0===E?void 0:E.includes)||void 0===k?void 0:k.call(E,o.ErrorsType.USER_REJECTED))||(null===(T=null==e?void 0:e.includes)||void 0===T?void 0:T.call(e,o.ErrorsType.USER_REJECTED))||(null===(L=null==e?void 0:e.includes)||void 0===L?void 0:L.call(e,o.ErrorsType.USER_DENIED))||(null===(B=null===(A=null==e?void 0:e.message)||void 0===A?void 0:A.includes)||void 0===B?void 0:B.call(A,o.ErrorsType.USER_DENIED))?{success:!1,error:"Transaction has been cancelled by user"}:(null==p||p({key:"Additional Data",value:{address:u,balance:K,providerType:v,chainId:b,path:"Inside an remove listing solana contract function - 215"}},{exception:e}),{success:!1,error:a.customErrorMessage(e)})}}if("magic"===v.toLowerCase()){const n=new e.Transaction({feePayer:_}).add(D),r=await M.getLatestBlockhash("confirmed");n.recentBlockhash=r.blockhash,n.lastValidBlockHeight=r.lastValidBlockHeight,n.add(e.ComputeBudgetProgram.setComputeUnitLimit({units:14e5}));const l=await s.fetchSolanaPriorityFee(y,n.serialize({verifySignatures:!1})),o=e.ComputeBudgetProgram.setComputeUnitPrice({microLamports:l});n.add(o);const a=await M.getFeeForMessage(n.compileMessage(),"confirmed"),t=(null!==(R=null==a?void 0:a.value)&&void 0!==R?R:0)+f*e.LAMPORTS_PER_SOL,u=K.native*e.LAMPORTS_PER_SOL;if(u<=0||u<t)return{success:!1,error:"Insufficient SOL for initiating the transaction."};g("Initiating remove listing transaction.");const c=await(null===(C=null==d?void 0:d.solana)||void 0===C?void 0:C.signTransaction(n,{requireAllSignatures:!1,verifySignatures:!0})),v=await M.sendRawTransaction(i.Buffer.from(c.rawTransaction,"base64"),{skipPreflight:!0,preflightCommitment:"confirmed"});await M.confirmTransaction(Object.assign({signature:v},r),"confirmed");const b=await M.getSignatureStatus(v);return null===(null===(I=null==b?void 0:b.value)||void 0===I?void 0:I.err)?{success:!0,response:{hash:v}}:{success:!1,error:"Transaction Failed"}}}return W?(null==p||p({key:"Additional Data",value:{address:u,balance:K,providerType:v,chainId:b,path:"Inside an remove listing solana contract function - 292"}},{exception:W}),{success:!1,error:a.customErrorMessage(W)}):null}catch(e){return(null===(K=e.message)||void 0===K?void 0:K.includes(o.ErrorsType.USER_REJECTED))||(null===(W=e.message)||void 0===W?void 0:W.includes(o.ErrorsType.USER_DENIED))?{success:!1,error:"Transaction has been cancelled by user"}:(null==p||p({key:"Additional Data",value:{address:u,providerType:v,chainId:b,path:"Inside an remove listing solana contract function - 319"}},{exception:e}),{success:!1,error:a.customErrorMessage(e)})}};