Skip to content

Commit

Permalink
Merge branch 'dev' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Jan 25, 2024
2 parents 8c60565 + abda237 commit a872d7f
Show file tree
Hide file tree
Showing 64 changed files with 637 additions and 630 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
.env*
.turbo
8 changes: 0 additions & 8 deletions common/build-config.ts

This file was deleted.

11 changes: 0 additions & 11 deletions common/build-others.ts

This file was deleted.

3 changes: 0 additions & 3 deletions common/config/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion common/lib/apis/api-alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BigNumber } from "ethers";
import type { CollectionFilterType, CollectionType, NftType } from "@lib/common/types";
import type { FetchResponse } from "@lib/common/fetch";
import { fetchJson, FETCH_LIMIT } from "@lib/common/fetch";
import { getChecksumAddress, isAddressNotZero } from "@lib/common/config";
import { getChecksumAddress, isAddressNotZero } from "@lib/common/config";
import { keyCollections, keyNft } from "@lib/common/keys";
import { constants } from "ethers";
import { networks } from "@lib/common/networks";
Expand Down
2 changes: 1 addition & 1 deletion common/lib/apis/api-covalent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getChecksumAddress } from "@lib/common/config";
import { DEFAULT_NAME, DEFAULT_SYMBOL } from "@lib/common/config";
import { fetchJson, FETCH_LIMIT } from "@lib/common/fetch";
import { keyCollection, keyNft } from "@lib/common/keys";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";
import { networks } from "@lib/common/networks";

const _covalentUrlPath = (chainId: number, path: string): string => {
Expand Down
2 changes: 1 addition & 1 deletion common/lib/apis/api-thegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const thegraphCollections = async (chainId: number, account: string): Promise<Ma
// console.log(`thegraphCollections ${keyCollections(chainId, account)}\n`);

const collections: Map<string, CollectionType> = new Map();
const network = networks.get(chainId);
const network = networks.get(chainId);

if (account) {
const query = `
Expand Down
4 changes: 2 additions & 2 deletions common/lib/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Fragment, Interface } from "@ethersproject/abi";

import type { CollectionType, NftType, RefPageType, AddressesType } from "@lib/common/types";

import config from "@config/config.json";
import addressesRaw from "@contracts/addresses.json";
import config from "@kredeum/config/dist/config.json";
import addressesRaw from "@kredeum/contracts/addresses.json";

import { formatEther } from "ethers/lib/utils";
import { networks } from "./networks";
Expand Down
7 changes: 2 additions & 5 deletions common/lib/common/ens-get.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { providers } from "ethers";

import { JsonRpcProvider } from "@ethersproject/providers";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";

const ens = (() => {
let ensProvider: JsonRpcProvider;
const ensProvider: JsonRpcProvider = new providers.JsonRpcProvider(config.ens.rpcUrl);

const getName = async (address: string): Promise<string> => {
ensProvider ||= new providers.JsonRpcProvider(config.ens.rpcUrl);
console.log("getName ~ ensProvider:", ensProvider);
let name = "";

try {
Expand All @@ -21,7 +19,6 @@ const ens = (() => {
};

const getAvatar = async (address: string): Promise<string> => {
ensProvider ||= new providers.JsonRpcProvider(config.ens.rpcUrl);
let avatar = "";

try {
Expand Down
48 changes: 28 additions & 20 deletions common/lib/common/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { NetworkType, NftType } from "@lib/common/types";
import mainnetsJson from "@config/mainnets.json";
import testnetsJson from "@config/testnets.json";
import mainnetsJson from "@kredeum/config/dist/mainnets.json";
import testnetsJson from "@kredeum/config/dist/testnets.json";

type chainIdish = number | string | undefined;

const networks = (() => {
const _networksMap = new Map(
Expand All @@ -10,35 +12,40 @@ const networks = (() => {
// const _getMap = (): Map<number, NetworkType> | undefined => _networksMap;
const _getAll = (): NetworkType[] => [...(_networksMap?.values() || [])];
const _getAllActive = (): NetworkType[] => _getAll().filter((nw: NetworkType) => !(nw.active === false));
const getAllSameType = (chainId: number): NetworkType[] =>
const getAllSameType = (chainId: chainIdish): NetworkType[] =>
_getAllActive().filter((nw: NetworkType) => isMainnet(nw.chainId) === isMainnet(chainId));

const get = (chainId: number | string | undefined): NetworkType | undefined => _networksMap?.get(Number(chainId));
const getChainName = (chainId: number | string | undefined): string | undefined => get(chainId)?.chainName;
const get = (chainId: chainIdish): NetworkType | undefined => _networksMap?.get(Number(chainId));

const getChainId = (chainName: string): number | undefined =>
_getAll()?.find((nw: NetworkType) => nw.chainName === chainName)?.chainId;
const getExplorer = (chainId: number): string => get(chainId)?.blockExplorerUrls[0] || "";
const getOpenSea = (chainId: number): string => get(chainId)?.openSea || "";
const getBlur = (chainId: number): string => get(chainId)?.blur || "";
const getCreate = (chainId: number): boolean => Boolean(get(chainId)?.create);
const getLinkedMainnet = (chainId: number | string): number => get(chainId)?.linkedMainnet || 0;
const getLinkedLayer1 = (chainId: number | string): number => get(chainId)?.linkedLayer1 || 0;
const getCurrency = (chainId: number): string => get(chainId)?.nativeCurrency.symbol || "";
const getExplorer = (chainId: chainIdish): string => get(chainId)?.blockExplorerUrls[0] || "";
const getOpenSea = (chainId: chainIdish): string => get(chainId)?.openSea || "";
const getBlur = (chainId: chainIdish): string => get(chainId)?.blur || "";
const getCreate = (chainId: chainIdish): boolean => Boolean(get(chainId)?.create);
const getLinkedMainnet = (chainId: chainIdish): number => get(chainId)?.linkedMainnet || 0;
const getLinkedLayer1 = (chainId: chainIdish): number => get(chainId)?.linkedLayer1 || 0;
const getCurrency = (chainId: chainIdish): string => get(chainId)?.nativeCurrency.symbol || "";
const getOpenSeaUrl = (chainId: number, ref: NftType | { address: string; tokenID: string }): string =>
`${getOpenSea(chainId)}/${ref?.address}/${ref?.tokenID}`;
const getBlurUrl = (chainId: number, ref: NftType | { address: string; tokenID: string }): string =>
`${getBlur(chainId)}/${ref?.address?.toLowerCase()}/${ref?.tokenID}`;

const getRpcUrl = (chainId: number | string): string => get(chainId)?.rpcUrls[0] || "";
const getRpcUrl = (chainId: chainIdish): string => get(chainId)?.rpcUrls[0] || "";

const has = (chainId: chainIdish): boolean => _networksMap?.has(Number(chainId));

const has = (chainId: number | string | undefined): boolean => _networksMap?.has(Number(chainId));
const isActive = (chainId: chainIdish): boolean => get(chainId)?.active || false;
const isEip1559 = (chainId: chainIdish): boolean => Boolean(get(chainId)?.eip1559);
const isMainnet = (chainId: chainIdish): boolean => getLinkedMainnet(chainId) == 0;
const isTestnet = (chainId: chainIdish): boolean => !isMainnet(chainId);
const isLayer1 = (chainId: chainIdish): boolean => getLinkedLayer1(chainId) == 0;
const isLayer2 = (chainId: chainIdish): boolean => !isLayer1(chainId);

const isActive = (chainId: number | string): boolean => get(chainId)?.active || false;
const isEip1559 = (chainId: number | string): boolean => Boolean(get(chainId)?.eip1559);
const isMainnet = (chainId: number | string): boolean => getLinkedMainnet(chainId) == 0;
const isTestnet = (chainId: number | string): boolean => !isMainnet(chainId);
const isLayer1 = (chainId: number | string): boolean => getLinkedLayer1(chainId) == 0;
const isLayer2 = (chainId: number | string): boolean => !isLayer1(chainId);
const getChainName = (chainId: chainIdish): string | undefined => get(chainId)?.chainName;
const getMainnetName = (chainId: chainIdish) =>
isTestnet(chainId) ? getChainName(getLinkedMainnet(chainId)) : getChainName(chainId);
const getIconName = (chainId: chainIdish) => `icon-${getMainnetName(chainId)}.png`;

// console.log("networks.getAll", getAll());
// console.log("networks.getAllSameType mainnet", getAllSameType(1));
Expand All @@ -60,6 +67,7 @@ const networks = (() => {
getOpenSea,
getExplorer,
getChainName,
getIconName,
getLinkedMainnet,
getLinkedLayer1,
isLayer1,
Expand Down
2 changes: 1 addition & 1 deletion common/lib/nft/nft-get-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NftType, NftMetadata } from "@lib/common/types";
import { fetchJson } from "@lib/common/fetch";
import { getChecksumAddress } from "@lib/common/config";
import { getChecksumAddress } from "@lib/common/config";
import { keyNft } from "@lib/common/keys";
import { constants } from "ethers";
import { swarmGatewayUrl, swarmGetLink } from "./storage/swarm";
Expand Down
1 change: 0 additions & 1 deletion common/lib/nft/nft-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { alchemyActive, alchemyNftList } from "@lib/apis/api-alchemy";
import { covalentActive, covalentNftList } from "@lib/apis/api-covalent";
import { thegraphActive, thegraphNftList } from "@lib/apis/api-thegraph";


import { FETCH_LIMIT } from "@lib/common/fetch";
import { networks } from "@lib/common/networks";

Expand Down
2 changes: 1 addition & 1 deletion common/lib/nft/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { NftType, StorageConfigType, StorageParamsType, StorageType } from "@lib/common/types";
import { ipfsGateway, ipfsGatewayUrl, ipfsLinkToUrlHttp, ipfsGetLink } from "./ipfs";
import { swarmGateway, swarmGatewayUrl, swarmLinkToUrlHttp, swarmGetLink } from "./swarm";
import config from "@config/config.json";
import config from "@kredeum/config/dist/config.json";

// IN MEMORY Storage Config
let _storageConfig: StorageConfigType;
Expand Down
2 changes: 1 addition & 1 deletion common/lib/resolver/resolver-conv-collection-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { constants, BigNumber } from "ethers";
import type { IOpenNFTsInfos, IERCNftInfos } from "@soltypes/OpenNFTsResolver";

import type { CollectionType, ReceiverType } from "@lib/common/types";
import { getChecksumAddress, DEFAULT_NAME, DEFAULT_SYMBOL } from "@lib/common/config";
import { getChecksumAddress, DEFAULT_NAME, DEFAULT_SYMBOL } from "@lib/common/config";
import { resolverConvSupports } from "@lib/resolver/resolver-conv-supports";
import { networks } from "@lib/common/networks";

Expand Down
2 changes: 1 addition & 1 deletion common/lib/resolver/resolver-conv-nft-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, constants } from "ethers";

import type { IERCNftInfos, IOpenNFTsInfos } from "@soltypes/IOpenNFTsResolver";
import type { NftType, CollectionType, ReceiverType } from "@lib/common/types";
import { getChecksumAddress } from "@lib/common/config";
import { getChecksumAddress } from "@lib/common/config";
import { networks } from "@lib/common/networks";

const resolverConvNftInfos = (
Expand Down
26 changes: 14 additions & 12 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "common",
"version": "2.0.0",
"name": "@kredeum/common",
"version": "1.4.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"clean": "rm -rf node_modules types abis config/networks.json",
"format": "prettier lib/**/*.ts --write --list-different --loglevel log",
"check": "eslint lib/**/*.ts",
"build": "pnpx ts-node build-config && pnpx ts-node build-others"
"clean": "rm -rf node_modules types abis",
"format": "prettier lib/**/*.ts --write --list-different",
"check": "eslint lib/**/*.ts"
},
"keywords": [],
"author": "",
Expand All @@ -27,21 +26,24 @@
"@ipld/dag-pb": "^4.0.8",
"@types/findup-sync": "^4.0.4",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"dotenv": "^16.3.1",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"dotenv": "^16.3.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"ethers": "^5.7.2",
"findup-sync": "^5.0.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",
"multiformats": "^12.1.3",
"pdfjs-dist": "^3.11.174",
"prettier": "^3.2.1",
"prettier": "^3.2.4",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@kredeum/config": "workspace:^",
"@kredeum/contracts": "workspace:^"
}
}
4 changes: 1 addition & 3 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
"paths": {
"@lib/*": ["common/lib/*"],
"@utils/*": ["common/utils/*"],
"@config/*": ["common/config/*"],
"@soltypes/*": ["contracts/types/*"],
"@artifacts/*": ["contracts/out/*"],
"@contracts/*": ["contracts/*"]
"@artifacts/*": ["contracts/out/*"]
}
},
"include": ["**/*.ts"],
Expand Down
19 changes: 0 additions & 19 deletions common/utils/getNonce.ts

This file was deleted.

18 changes: 0 additions & 18 deletions common/utils/runHandlebarsConfig.ts

This file was deleted.

31 changes: 0 additions & 31 deletions common/utils/runHandlebarsEnv.ts

This file was deleted.

1 change: 1 addition & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
19 changes: 19 additions & 0 deletions config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@kredeum/config",
"version": "1.4.0",
"description": "",
"main": "index.ts",
"scripts": {
"clean": "rm -rf node_modules dist",
"build": "pnpx ts-node scripts/build.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.6",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8"
}
}
9 changes: 9 additions & 0 deletions config/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { runHandlebarsEnv, runHandlebarsConfig } from "./handlebars";

const main = async (): Promise<void> => {
await runHandlebarsEnv("src/config.handlebars.json", "dist/config.json");
await runHandlebarsEnv("src/mainnets.handlebars.json", "dist/mainnets.json");
await runHandlebarsEnv("src/testnets.handlebars.json", "dist/testnets.json");
};

main().catch(console.error);
Loading

0 comments on commit a872d7f

Please sign in to comment.