-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: queryPriceListing and getTokenList features
- Loading branch information
Showing
14 changed files
with
479 additions
and
14 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
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,27 @@ | ||
import { TheaNetwork, TokenListResponsePayload } from "src/types"; | ||
import { consts } from "src/utils/consts"; | ||
import { HttpClient } from "../shared"; | ||
|
||
export class GetTokenList { | ||
readonly httpClient: HttpClient; | ||
readonly network: TheaNetwork; | ||
|
||
constructor(network: TheaNetwork) { | ||
this.network = network; | ||
this.httpClient = new HttpClient("https://api.rarible.org/v0.1"); | ||
} | ||
async getTokenList() { | ||
const response = await this.httpClient.get<TokenListResponsePayload>("/items/byCollection", { | ||
collection: consts[`${this.network}`].networkName + ":" + consts[`${this.network}`].theaERC1155Contract | ||
}); | ||
// eslint-disable-next-line no-var | ||
var tokenIdsList: string[] = []; | ||
if (response.items.length > 0) { | ||
response.items.forEach((item) => { | ||
tokenIdsList.push(item.tokenId); | ||
}); | ||
} | ||
|
||
return tokenIdsList; | ||
} | ||
} |
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,74 @@ | ||
import { | ||
OrderSide, | ||
SearchOrdersParams, | ||
// PostOrderRequestPayload, | ||
// PostOrderResponsePayload, | ||
SearchOrdersResponsePayload, | ||
// SignedERC1155OrderStruct, | ||
// SignedERC1155OrderStructSerialized, | ||
TheaNetwork | ||
} from "src/types"; | ||
import { consts } from "src/utils/consts"; | ||
import { HttpClient } from "../shared/httpClient"; | ||
|
||
export class QueryPriceListing { | ||
readonly orderBook: HttpClient; | ||
readonly network: TheaNetwork; | ||
|
||
constructor(network: TheaNetwork) { | ||
this.network = network; | ||
this.orderBook = new HttpClient("https://api.trader.xyz/orderbook"); | ||
} | ||
// private async postOrderToOrderbook( | ||
// signedOrder: SignedERC1155OrderStruct, | ||
// chainId: string | number, | ||
// metadata: Record<string, string> = {} | ||
// ) { | ||
// const payload: PostOrderRequestPayload = { | ||
// order: this.serializeNftOrder(signedOrder), | ||
// chainId: chainId.toString(10), | ||
// metadata | ||
// }; | ||
// try { | ||
// const response = await this.orderBook.post<string, PostOrderResponsePayload>("/orders", JSON.stringify(payload)); | ||
// return response; | ||
// } catch (error) { | ||
// throw new TheaError(error.message); | ||
// } | ||
// } | ||
async queryPriceListing(tokenId: string, side: OrderSide) { | ||
const response = await this.orderBook.get<SearchOrdersResponsePayload>("/orders", { | ||
nftToken: consts[`${this.network}`].theaERC1155Contract, | ||
nftTokenId: tokenId, | ||
sellOrBuyNft: side, | ||
status: "open", | ||
erc20Token: consts[`${this.network}`].stableCoinContract | ||
} as Partial<SearchOrdersParams>); | ||
const priceList: number[] = []; | ||
response.orders.forEach((element) => { | ||
priceList.push(parseInt(element.nftTokenAmount) / (parseInt(element.erc20TokenAmount) / 10 ** 18)); | ||
}); | ||
return priceList; | ||
} | ||
// private serializeNftOrder = (signedOrder: SignedERC1155OrderStruct): SignedERC1155OrderStructSerialized => { | ||
// if ("erc1155Token" in signedOrder) { | ||
// return { | ||
// ...signedOrder, | ||
// direction: parseInt(signedOrder.direction.toString()), | ||
// expiry: signedOrder.expiry.toString(), | ||
// nonce: signedOrder.nonce.toString(), | ||
// erc20TokenAmount: signedOrder.erc20TokenAmount.toString(), | ||
// fees: signedOrder.fees.map((fee) => ({ | ||
// ...fee, | ||
// amount: fee.amount.toString(), | ||
// feeData: fee.feeData.toString() | ||
// })), | ||
// erc1155TokenAmount: signedOrder.erc1155TokenAmount.toString(), | ||
// erc1155TokenId: signedOrder.erc1155TokenId.toString() | ||
// }; | ||
// } else { | ||
// console.log("unknown order format type erc1155", signedOrder); | ||
// throw new TheaError({ message: "Unknown asset type", type: "NFT_ORDER_SERILIZATION_ERROR" }); | ||
// } | ||
// }; | ||
} |
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,28 @@ | ||
import { OrderSide, SearchOrdersParams, SearchOrdersResponsePayload, TheaNetwork } from "src/types"; | ||
import { consts } from "src/utils/consts"; | ||
import { HttpClient } from "../shared/httpClient"; | ||
|
||
export class QueryPriceListing { | ||
readonly orderBook: HttpClient; | ||
readonly network: TheaNetwork; | ||
|
||
constructor(network: TheaNetwork) { | ||
this.network = network; | ||
this.orderBook = new HttpClient("https://api.trader.xyz/orderbook"); | ||
} | ||
|
||
async queryPriceListing(tokenId: string, side: OrderSide) { | ||
const response = await this.orderBook.get<SearchOrdersResponsePayload>("/orders", { | ||
nftToken: consts[`${this.network}`].theaERC1155Contract, | ||
nftTokenId: tokenId, | ||
sellOrBuyNft: side, | ||
status: "open", | ||
erc20Token: consts[`${this.network}`].stableCoinContract | ||
} as Partial<SearchOrdersParams>); | ||
const priceList: number[] = []; | ||
response.orders.forEach((element) => { | ||
priceList.push(parseInt(element.nftTokenAmount) / (parseInt(element.erc20TokenAmount) / 10 ** 18)); | ||
}); | ||
return priceList; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.