Skip to content
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

Add GhostMarket adapter #238

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
980 changes: 980 additions & 0 deletions src/adapters/ghostmarket-avalanche/abi.json

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions src/adapters/ghostmarket-avalanche/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import * as dotenv from "dotenv";

dotenv.config();

import BigNumber from "bignumber.js";
import moment from "moment";
import { EventData } from "web3-eth-contract";
import path from "path";
import priceSdk from "../../sdk/price";
import Avalanche from "../../sdk/avalanche";
import symbolSdk from "../../sdk/symbol";
import { ISaleEntity, ISymbolAPIResponse } from "../../sdk/Interfaces";

class Element {
name: string;
token: string;
protocol: string;
block: number;
deprecatedAtBlock: number;
contract: string;
events: string[];
pathToAbi: string;
range: number;
chunkSize: number;
sdk: any;

constructor() {
this.name = "ghostmarket-avalanche";
this.protocol = "avalanche";
this.block = 15385077;
this.contract = "0xeb4aba7aeba732fc2fc92a673585d950ccfc1de0";
this.events = ["OrderFilled"];
this.pathToAbi = path.join(__dirname, "./abi.json");
this.range = 500;
this.chunkSize = 6;
}

run = async (): Promise<void> => {
this.sdk = await this.loadSdk();

await this.sdk.run();
};

loadSdk = (): any => {
return new Avalanche(this);
};

stop = async (): Promise<void> => {
this.sdk.stop();
};

_getToken = (event: EventData): string => {
let token = "avax";
if (event.returnValues["rightAsset"]["data"] != "0x") {
token = event.returnValues["rightAsset"]["data"][0].toLowerCase();
}

return token;
};

process = async (event: EventData): Promise<void> => {
const block = await this.sdk.getBlock(event.blockNumber);
const timestamp = moment.unix(block.timestamp).utc();
const token = this._getToken(event);
const symbol: ISymbolAPIResponse = await symbolSdk.get(token, this.protocol);
const po = await priceSdk.get(token, this.protocol, block.timestamp);
const price = event.returnValues["newLeftFill"];
const nativePrice = new BigNumber(price).dividedBy(10 ** (symbol?.decimals || 0));
const seller = event.returnValues["leftMaker"];
const buyer = event.returnValues["rightMaker"];
const nftContract = event.returnValues["leftAsset"]["data"][0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const nftContract = event.returnValues["leftAsset"]["data"][0];
let params = this.sdk.web3.eth.abi.decodeParameters(['address', 'uint256'], event.returnValues["leftAsset"]["data"]);
let nftContract = params[0];

const tokenId = event.returnValues["leftAsset"]["data"][1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const tokenId = event.returnValues["leftAsset"]["data"][1];
let tokenId = params[1];


const entity = {
providerName: this.name,
providerContract: this.contract,
protocol: this.protocol,
nftContract: nftContract.toLowerCase(),
nftId: tokenId,
token: token.toLowerCase(),
tokenSymbol: symbol?.symbol || "",
amount: 1,
price: nativePrice.toNumber(),
priceUsd: !symbol?.decimals ? null : nativePrice.multipliedBy(po.price).toNumber(),
seller: seller.toLowerCase(),
buyer: buyer.toLowerCase(),
soldAt: timestamp.format("YYYY-MM-DD HH:mm:ss"),
blockNumber: event.blockNumber,
transactionHash: event.transactionHash,
};

await this.addToDatabase(entity);
};

addToDatabase = async (entity: ISaleEntity): Promise<ISaleEntity> => {
console.log(`creating sale for ${entity.nftContract} with id ${entity.nftId}`);
return entity;
};
}

export default Element;
Loading