-
Notifications
You must be signed in to change notification settings - Fork 285
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
NeoDashboard
wants to merge
7
commits into
dappradar:main
Choose a base branch
from
NeoDashboard:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7fd888
Add GhostMarket adapter
NeoDashboard 3425c4b
Fix naming convention + avalanche bug + add ETH proxy contract
NeoDashboard fae9e53
Add new ABI support after wrapper realease
NeoDashboard 0af4cf4
Fix naming convention
NeoDashboard a2cac26
Fix bug GM adapter
NeoDashboard 17f7e31
Fix get token issue
NeoDashboard c896ecf
Merge branch 'dappradar:main' into main
NeoDashboard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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]; | ||||||
const tokenId = event.returnValues["leftAsset"]["data"][1]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.