-
-
Save yat1ma30/60c293313b8552cee79e1e0e02b37eb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const solanaWeb3 = require('@solana/web3.js'); | |
const rpc = "https://ssc-dao.genesysgo.net"; | |
const magicEdenPubKey = new solanaWeb3.PublicKey("M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K") | |
const solanaConnection = new solanaWeb3.Connection(rpc, 'confirmed'); | |
const runMagicEdenParser = async () => { | |
// get latest 1000 transactions happening on Magic Eden | |
const magicEdenSignatures = await solanaConnection.getSignaturesForAddress(magicEdenPubKey); | |
for (const { signature } of magicEdenSignatures) { | |
const txn = await solanaConnection.getTransaction(signature) | |
await MagicEdenOverlay(txn) | |
} | |
} | |
runMagicEdenParser(); | |
const WithdrawInstruction = 'Program log: Instruction: Withdraw'; | |
const CancelOfferInstruction = 'Program log: Instruction: CancelBuy'; | |
const ListingInstruction = 'Program log: Instruction: Sell'; | |
const MakeOfferInstruction = 'Program log: Instruction: Buy'; | |
const SaleInstruction = 'Program log: Instruction: Deposit'; | |
const CancelListingInstruction = 'Program log: Instruction: CancelSell' | |
// TODO: add useful metadata for each event, this is just for identifying different cases | |
const MagicEdenOverlay = async (txn) => { | |
const logs = txn.meta.logMessages; | |
switch(logs[1]) { | |
case WithdrawInstruction: | |
console.log("this is a withdraw") | |
break; | |
case CancelOfferInstruction: | |
console.log("this is a cancelled offer") | |
break; | |
case ListingInstruction: | |
if (logs.length == 11) { console.log("this is a listing")} | |
if (logs.length == 5) {console.log("this is an updated price on a listing")} | |
if(logs.length == 41) { console.log("this is an accepted offer")} | |
break; | |
case MakeOfferInstruction: | |
console.log("this is an offer made") | |
break; | |
case SaleInstruction: | |
console.log("this is a sale") | |
break; | |
case CancelListingInstruction: | |
console.log("this is a canceled listing") | |
break; | |
default: | |
console.log("unknown event") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment