Skip to content

Instantly share code, notes, and snippets.

@mertimus
Last active June 13, 2024 15:55
Show Gist options
  • Save mertimus/2093e4c64682c02a279684df42e5cf74 to your computer and use it in GitHub Desktop.
Save mertimus/2093e4c64682c02a279684df42e5cf74 to your computer and use it in GitHub Desktop.
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