Skip to content

NFT valuation based on Magic Eden's real-time floor price #15060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions projects/Erratic-Finance/Erratic-Finance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Erratic-Finance",
"slug": "airdrop",
"chains": ["solana"],
"category": "NFT",
"url": "https://erratic.finance",
"description": "Erratic Identity Mark (EIM) is an exclusive early-stage identity credential within the Erratic Finance ecosystem. Minting and holding an EIM provides permanent rights and privileges within the Erratic ecosystem.",
"tokenContracts": {
"solana": {
"nft_mint": "FPm55sjSoMdBTCMhZzVWeTB5EdDH6EZuRaW5vAyvDqkW",
"main_contract": "AC6hxrHufwguXYcPdCibahS7nemw8SQhPSHGEArQ97sJ"
}
},
"module": "Erratic-Finance/index.js",
"airdrop": true
}
86 changes: 86 additions & 0 deletions projects/Erratic-Finance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const https = require('https');
const NFT_MINT_ADDRESS = 'FPm55sjSoMdBTCMhZzVWeTB5EdDH6EZuRaW5vAyvDqkW';
const CONTRACT_ADDRESS = 'AC6hxrHufwguXYcPdCibahS7nemw8SQhPSHGEArQ97sJ';

const SOLANA_RPC_URL = 'https://api.mainnet-beta.solana.com';

async function getSolanaBalance(publicKey) {
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getBalance",
params: [publicKey]
});

const req = https.request(SOLANA_RPC_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length
}
}, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
if (result.error) {
reject(result.error.message);
} else {
resolve(result.result.value);
}
} catch (e) {
reject(e);
}
});
});

req.on('error', reject);
req.write(postData);
req.end();
});
}

async function getMagicEdenCollectionStats(collectionSymbol) {
return new Promise((resolve, reject) => {
https.get(`https://api-mainnet.magiceden.io/collection_stats?collection_symbol=${collectionSymbol}`, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
resolve(JSON.parse(data));
} catch (e) {
reject(e);
}
});
}).on('error', reject);
});
}

async function tvl() {
try {
const contractBalance = await getSolanaBalance(CONTRACT_ADDRESS);

const stats = await getMagicEdenCollectionStats(NFT_MINT_ADDRESS);

const nftValue = (stats.floor_price * stats.total_supply) || 0;

const totalSOL = (contractBalance / 1e9) + nftValue;

return {
solana: totalSOL
};
} catch (e) {
console.error('TVL calculation error:', e);
return {
solana: 0
};
}
}

module.exports = {
solana: {
tvl
}
};
Loading