Skip to content

Commit

Permalink
feat(nftx.js): new package
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Dec 16, 2022
1 parent 21be313 commit 45079e7
Show file tree
Hide file tree
Showing 312 changed files with 14,071 additions and 5,756 deletions.
Binary file modified .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy
on:
push:
branches: [main, develop]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: Build
run: yarn ci
- name: Deploy
env: GH_TOKEN ${{secrets.GH_TOKEN}}
NPM_TOKEN ${{secrets.NPM_TOKEN}}
run: yarn lerna publish
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# nftxjs
# nftxjs

## Development

1. do your changes in the nftx.js repo
2. run `yarn yalc`
> this will publish each package in the repo (@nftx/core @nftx/react etc.) to the local yalc repository on your machine
3. head to <insert-app>
4. run `yalc add @nftx/<specific-nftxjs-package>` for each package you've changed
5. run `rm -rf node_modules .next && yarn install`
> because of how yalc does its symlinking, yarn/npm doesn't realise that node_modules needs rebuilding so we have to manually wipe it
6. profit
10 changes: 4 additions & 6 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"packages": ["packages/*"],
"version": "0.1.0",
"version": "0.0.0",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"publish": {
"allowBranch": "main",
"allowBranch": "develop",
"conventionalCommits": true,
"yes": true,
"registry": "https://registry.npmjs.org/"
},
"version": {
"allowBranch": "main",
"conventionalCommits": true,
"yes": true
"allowBranch": "develop",
"conventionalCommits": true
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint-config-prettier": "^8.5.0",
"ethers": "^5.6.2",
"jest": "^27.5.1",
"lerna": "^3.22.1",
"lerna": "^6.1.0",
"rollup": "^2.70.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
Expand Down
Binary file modified packages/.DS_Store
Binary file not shown.
Binary file added packages/api/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/api/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
src/constants/abis
115 changes: 115 additions & 0 deletions packages/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# @nftx/core

## assets

### fetchUserAssets

### fetchAssetMetadata

### isCryptoPunk

### isCryptoKitty

### isNonStandard721

## pools

### fetchPool

### fetchPools

## tokens

### fetchReservesForToken

### fetchReservesForTokens

## vaults

### fetchVaultActivity

### fetchVaultHoldings

### fetchVaults

### fetchVault

### fetchVaultApy

### fetchVaultApys

### fetchVaultFees

### fetchXTokenShare

### fetchXTokenShares

### isVaultSwappable

### doesVaultHaveTargetSwapFee

### doesVAutHaveRandomSwapFee

### searchVaults

### matchVault

### prices

### fetch0xQuote

### fetchBuyPrice

### fetchEthPrice

### fetchSellPrice

### fetchSpotPrice

### fetchVaultBuyPrice

### fetchVaultSellPrice

### fetchVaultSwapPrice

### doesNetworkSupport0x

## trade

### approve

### buyFromVault

### estimateGasAndFees

### increaseGasLimit

### isApproved

### mintIntoVault

### redeemFromVault

### sellIntoVault

### swapWithVault

## web3

### addressEqual

### fetchTokenBalance

### fetchTotalSupply

### getContract

### MulticallContract

### parseLogEvent

### getChainConstant

## Environment Variables

`NFTX_MULTICALL=true|false`
20 changes: 20 additions & 0 deletions packages/api/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const isTest = process.env.NODE_ENV === "test";

module.exports = {
presets: [
// "@babel/preset-react",
"@babel/preset-typescript",
[
"@babel/preset-env",
{
targets: {
browsers: ["> 2%"],
},
modules: isTest ? "commonjs" : false,
useBuiltIns: false,
loose: true,
},
],
],
sourceMaps: isTest ? "inline" : true,
};
39 changes: 39 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@nftx/api",
"version": "0.0.0",
"description": "",
"homepage": "https://github.com/NFTX-project/nftxjs",
"license": "MIT",
"main": "dist/cjs/api.js",
"module": "dist/es/api.js",
"types": "dist/ts/index.d.ts",
"publishConfig": {
"registry": "https://registry.yarnpkg.com",
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NFTX-project/nftxjs.git"
},
"scripts": {
"lint": "eslint --fix -c ../../.eslintrc.js --ext ts,tsx src && tsc --noEmit",
"test": "echo \"no tests\" #jest --config ../../jest.config.js",
"build": "rm -rf dist && rollup -c && tsc -d --outDir dist/ts --emitDeclarationOnly",
"prepublishOnly": "yarn build"
},
"peerDependencies": {
"@ethersproject/bignumber": "^5.6.0",
"@nftx/config": "<1.0.0",
"@nftx/types": "<1.0.0"
},
"devDependencies": {
"@ethersproject/bignumber": "^5.6.0",
"@nftx/config": "*",
"@nftx/types": "*"
},
"bugs": {
"url": "https://github.com/NFTX-project/nftxjs/issues"
},
"sideEffects": false,
"dependencies": {}
}
13 changes: 13 additions & 0 deletions packages/api/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readdirSync } from 'fs';
import base from '../../rollup.base';

const abis = readdirSync('../constants/abis')
.filter((filename) => filename.endsWith('.json'))
.map((filename) => `@nftx/constants/abis/${filename}`);

const config = {
...base,
external: [...base.external, ...abis],
};

export default config;
115 changes: 115 additions & 0 deletions packages/api/src/assets/Stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
export interface IStream<T> {
errored: boolean;
ended: boolean;

on(e: 'data', cb: (data: T) => any): void;
on(e: 'end', cb: () => any): void;
on(e: 'error', cb: (e: any) => void): any;

read(): Promise<T>;
}

type ReadEvt = 'data' | 'end' | 'error';
type WriteEvt = 'read';

export default class Stream<T> implements IStream<T> {
listeners: {
[K in ReadEvt | WriteEvt]?: (...args: any[]) => any;
};
errored: boolean;
ended: boolean;
reading: boolean;

constructor() {
this.reading = false;
this.errored = false;
this.ended = false;
this.listeners = {};
}

on(e: ReadEvt | WriteEvt, cb: (...args: any[]) => void) {
this.listeners[e] = cb;

if (e === 'data') {
this.reading = true;
this.listeners.read?.();
}
}

read() {
return new Promise<T>((res, rej) => {
if (this.listeners.data) {
return rej(
new Error(
'stream is automatically reading as there is a data listener'
)
);
}
if (this.ended) {
return rej(new Error('stream has ended'));
}
if (this.reading) {
return rej(new Error('stream is already reading'));
}

const onEnd = this.listeners.end;
const onError = this.listeners.error;

const revert = () => {
this.reading = false;
this.listeners.data = null;
this.listeners.error = onError;
this.listeners.end = onEnd;
};

this.listeners.data = (data) => {
revert();
res(data);
};
this.listeners.error = (e) => {
revert();
onError?.(e);
rej(e);
};
this.listeners.end = () => {
revert();
onEnd?.();
};

this.reading = true;
this.listeners.read?.();
});
}

write(data: T) {
if (this.ended) {
return;
}

this.listeners.data?.(data);

if (this.listeners.data) {
this.listeners.read?.();
}
}

error(e: any) {
if (!this.ended) {
this.errored = true;
this.ended = true;
this.listeners.error?.(e);
}
}

end(data: T) {
if (this.ended) {
return;
}

this.listeners.data?.(data);

this.ended = true;
this.reading = false;
this.listeners.end?.();
}
}
20 changes: 20 additions & 0 deletions packages/api/src/assets/fetchUserCollections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import config from '@nftx/config';
import type { Collection } from '@nftx/types';
import { queryApi } from '../utils';

type Response = Collection[];

const fetchUserCollections = ({
network = config.network,
userAddress,
}: {
network?: number;
userAddress: string;
}) => {
const url = `/${network}/users/${userAddress}/collections`;
return queryApi<Response>({
url,
});
};

export default fetchUserCollections;
Loading

0 comments on commit 45079e7

Please sign in to comment.