-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from lukechoi/kingdomstory
add kingdomstory-market-bsc-1 adapter
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
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,51 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "seller", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "buyer", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "uint256", | ||
"name": "tokenId", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "totalPricePaid", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "currencyContract", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "nftContract", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "tradeId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "NewSale", | ||
"type": "event" | ||
} | ||
] |
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,72 @@ | ||
import moment from "moment"; | ||
import BigNumber from "bignumber.js"; | ||
import {ISaleEntity} from "../../sdk/Interfaces"; | ||
import {EventData} from "web3-eth-contract"; | ||
import BasicProvider, {IBasicProviderOptions} from "../../sdk/basic-provider"; | ||
|
||
// event NewSale( | ||
// address indexed seller, | ||
// address indexed buyer, | ||
// uint256 indexed tokenId, | ||
// uint256 totalPricePaid, | ||
// address currencyContract, | ||
// address nftContract, | ||
// uint256 tradeId | ||
// ); | ||
|
||
class KingdomStoryMarket extends BasicProvider { | ||
constructor(options: IBasicProviderOptions) { | ||
super(options); | ||
this.requireDefaultPaymentToken(); | ||
this.events = ["NewSale"]; | ||
} | ||
|
||
private getToken = (event: EventData): string => { | ||
let token = event.returnValues["currencyContract"].toLowerCase(); | ||
|
||
// bnb | ||
if (token === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") { | ||
token = this.defaultPaymentToken; | ||
} | ||
|
||
return token; | ||
}; | ||
|
||
process = async (event: EventData): Promise<ISaleEntity> => { | ||
const block = await this.sdk.getBlock(event.blockNumber); | ||
const timestamp = moment.unix(block.timestamp).utc(); | ||
|
||
// const nftContract = await this.sdk.callContractMethod("nftContract", [], undefined, event.blockNumber); | ||
const nftContract = event.returnValues.nftContract; | ||
|
||
if (!nftContract) { | ||
throw new Error(`Failed to fetch NFT contract address for transaction "${event.transactionHash}". Provider - "${this.name}"`); | ||
} | ||
|
||
const entity: ISaleEntity = { | ||
providerName: this.name, | ||
providerContract: this.contract, | ||
nfts: [{ | ||
contract: nftContract.toLowerCase(), | ||
id: event.returnValues.tokenId, | ||
amount: 1 | ||
}], | ||
token: this.getToken(event), | ||
price: new BigNumber(event.returnValues.totalPricePaid), | ||
seller: event.returnValues.seller.toLowerCase(), | ||
buyer: event.returnValues.buyer.toLowerCase(), | ||
soldAt: timestamp, | ||
blockNumber: event.blockNumber, | ||
transactionHash: event.transactionHash, | ||
chainId: this.sdk.chainId, | ||
}; | ||
|
||
return this.addToDatabase(entity); | ||
}; | ||
|
||
addToDatabase = async (entity: ISaleEntity): Promise<ISaleEntity> => { | ||
return entity; | ||
}; | ||
} | ||
|
||
export default KingdomStoryMarket; |
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