Skip to content

Commit

Permalink
Merge pull request #256 from lukechoi/kingdomstory
Browse files Browse the repository at this point in the history
add kingdomstory-market-bsc-1 adapter
  • Loading branch information
liutaurasjanuskas authored Feb 20, 2024
2 parents 14daf42 + 99441f7 commit e0c7289
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/adapters/kingdomstory-market-bp-1/abi.json
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"
}
]
72 changes: 72 additions & 0 deletions src/adapters/kingdomstory-market-bp-1/index.ts
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;
8 changes: 8 additions & 0 deletions src/config/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ const BSC: IBasicProviderOptions[] = [
chainId: 15,
defaultPaymentToken: "0xd069599e718f963bd84502b49ba8f8657faf5b3a"
},
{
name: "kingdomstory-market-bsc-1",
basicProvider: "kingdomstory-market-bp-1",
block: 32932915,
contract: "0x0e37943581489f7771981bb5ca882b474d0d5ad2",
chainId: 15,
defaultPaymentToken: "bnb",
},
];

const POLYGON: IBasicProviderOptions[] = [
Expand Down

0 comments on commit e0c7289

Please sign in to comment.