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

Feat/order hash #25

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion __test__/bulk-listing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe('fulfill listing main process', () => {

const sdk = init({
apiKey,
baseUrl: 'https://data-api.nftgo.dev',
baseUrl: process.env.BASE_URL,
web3Provider,
walletConfig: {
address,
Expand Down
4 changes: 2 additions & 2 deletions __test__/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export function initConfig() {
const provider = initWeb3Provider();
const config: Config = {
apiKey: process.env.API_KEY || '', // Replace with your own API Key.
baseUrl: 'https://data-api.nftgo.dev',
chain: EVMChain.ETH,
baseUrl: process.env.BASE_URL || '',
chain: EVMChain.ETHEREUM,
web3Provider: provider,
walletConfig: {
address: process.env.ADDRESS || '',
Expand Down
2 changes: 1 addition & 1 deletion __test__/common/create-env-test-skd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createEnvTestSdk() {

const sdk = init({
apiKey,
baseUrl: 'https://data-api.nftgo.dev',
baseUrl: process.env.BASE_URL,
web3Provider,
walletConfig: {
address,
Expand Down
20 changes: 13 additions & 7 deletions __test__/create-offer.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { OrderKind, Orderbook, init } from '../src';
import { HttpsProxyAgent } from 'https-proxy-agent';
import Web3 from 'web3';

describe('create offer main process', () => {
const endpoint = process.env.PROVIDER_URL!,
address = process.env.ADDRESS!,
privateKey = process.env.PRIVATE_KEY!,
apiKey = process.env.API_KEY!,
baseUrl = process.env.BASE_URL!,
web3Provider = new Web3.providers.HttpProvider(endpoint);

const sdk = init({
apiKey,
web3Provider,
baseUrl,
walletConfig: {
address,
privateKey,
},
agent: new HttpsProxyAgent('http://127.0.0.1:7890'),
});

test('should return buy actions', async () => {
Expand All @@ -26,18 +26,24 @@ describe('create offer main process', () => {
{
collection: '0xed5af388653567af2f388e6224dc7c4b3241c544',
quantity: 1,
weiPrice: '10000000000000',
weiPrice: '10000000000000000',
orderKind: OrderKind.SeaportV15,
orderbook: Orderbook.Opensea,
listingTime: '1692605611',
expirationTime: '1692615611',
listingTime: (Date.now() / 1000).toFixed(0),
expirationTime: (Date.now() / 1000 + 3 * 60 * 60).toFixed(0),
automatedRoyalties: true,
currency: 'WETH',
},
],
});

const { actions } = res;
console.log({ actions });
const { actions, executeActions } = res;
console.log(actions);
await executeActions({
onTaskExecuted: task => {
console.log(task.action, task.result);
},
});
expect(Array.isArray(actions)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion __test__/go-trading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Test go-trading sdk', () => {

const sdk = init({
apiKey,
baseUrl: 'https://data-api.nftgo.dev',
baseUrl: process.env.BASE_URL,
web3Provider,
walletConfig: {
address,
Expand Down
71 changes: 71 additions & 0 deletions __test__/order-fetcher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require('dotenv').config();

import { OrderType } from '@/types';
import { init } from '../src';
import Web3 from 'web3';

describe('Test order fetcher sdk', () => {
const endpoint = process.env.PROVIDER_URL!,
// address = process.env.ADDRESS!,
// privateKey = process.env.PRIVATE_KEY!,
apiKey = process.env.API_KEY!,
web3Provider = new Web3.providers.HttpProvider(endpoint);

const contractAddress = '0xED5AF388653567Af2F388E6224dC7C4b3241C544';

const sdk = init({
apiKey,
baseUrl: process.env.BASE_URL,
web3Provider,
// agent:
// walletConfig: {
// address,
// privateKey,
// },
});

it('fetch Azuki Listing NFT', async () => {
const orders = await sdk.orderFetcher.getOrdersByContract({
contractAddress,
limit: 1,
offset: 0,
orderType: OrderType.Listing,
});
expect(orders.listingDTOs.length).toBe(1);
expect(typeof orders.listingDTOs?.[0].orderHash).toBe('string');
});

it('fetch orders by ids', async () => {
const orders = await sdk.orderFetcher.getOrdersByIds({
orders: [
{
orderId: '650d79013a36395019514b9d',
orderType: OrderType.Listing,
},
],
});
expect(orders.listingDTOs.length).toBe(1);
expect(typeof orders.listingDTOs?.[0].orderHash).toBe('string');
});

it('fetch orders by maker', async () => {
const orders = await sdk.orderFetcher.getOrdersByMaker({
maker: '0x08c1ae7e46d4a13b766566033b5c47c735e19f6f',
orderType: OrderType.Offer,
includePrivate: true,
});
console.log(orders, orders.offerDTOs?.[0]?.orderHash);
expect(orders.offerDTOs.length > 0).toBe(true);
expect(typeof orders.offerDTOs?.[0].orderHash).toBe('string');
});

it('fetch orders by NFT', async () => {
const orders = await sdk.orderFetcher.getOrdersByNFT({
contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
tokenId: '2632',
orderType: OrderType.Offer,
});
expect(orders.offerDTOs.length > 0).toBe(true);
expect(typeof orders.offerDTOs?.[0].orderHash).toBe('string');
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nftgo/gotrading",
"version": "1.0.8",
"version": "1.0.9",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
Expand Down
68 changes: 34 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/http/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { HttpsProxyAgent } from 'https-proxy-agent';
import { AggregatorApiException } from '@/exceptions';

import { HTTPClient } from '@/types';
import { Agent } from 'https';
import { SafeAny } from 'src/types/safe-any';

export class HTTPClientStable implements HTTPClient {
constructor(private agent?: HttpsProxyAgent<string>) {}
constructor(private agent?: Agent) {}
fetch<R>(input: RequestInfo | URL, init?: RequestInit | undefined) {
const agentOption = this.agent ? { agent: this.agent } : {};
return new Promise<R>((resolve, reject) => {
Expand Down Expand Up @@ -39,7 +40,7 @@ export class HTTPClientStable implements HTTPClient {
let actualUrl = url;
for (const key in query) {
if (query[key] instanceof Array) {
for (const value of query[key] as unknown as Array<any>) {
for (const value of query[key] as unknown as Array<SafeAny>) {
value !== null && value !== undefined && params.push(`${key}=${value}`);
}
} else {
Expand Down
Loading