Skip to content

Commit

Permalink
fix typescript errors (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Jan 31, 2024
1 parent 40d119d commit d9fdf2f
Show file tree
Hide file tree
Showing 102 changed files with 6,952 additions and 4,879 deletions.
7 changes: 3 additions & 4 deletions common/lib/apis/api-alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { BigNumber } from "ethers";
import type { CollectionFilterType, CollectionType, NftType } from "@kredeum/common/lib/common/types";
import type { FetchResponse } from "@kredeum/common/lib/common/fetch";
import { fetchJson, FETCH_LIMIT } from "@kredeum/common/lib/common/fetch";
import { getChecksumAddress, isAddressNotZero } from "@kredeum/common/lib/common/config";
import { ADDRESS_ZERO, getChecksumAddress, isAddressNotZero } from "@kredeum/common/lib/common/config";
import { keyCollections, keyNft } from "@kredeum/common/lib/common/keys";
import { constants } from "ethers";
import { networks } from "@kredeum/common/lib/common/networks";

const alchemyCollections = async (chainId: number, account: string): Promise<Map<string, CollectionType>> => {
Expand Down Expand Up @@ -82,7 +81,7 @@ const alchemyNftList = async (
collection: CollectionType,
filter: CollectionFilterType = {}
): Promise<Map<string, NftType>> => {
const owner = filter.owner || constants.AddressZero;
const owner = filter.owner || ADDRESS_ZERO;
const limit = filter.limit || FETCH_LIMIT;
const address = getChecksumAddress(collection.address);
// console.log("alchemyNftList", chainId, address, owner, limit);
Expand All @@ -105,7 +104,7 @@ const alchemyNftList = async (
nextToken: string;
};

if (owner == constants.AddressZero) {
if (owner == ADDRESS_ZERO) {
const req = `/getNFTsForCollection?contractAddress=${collection.address}&limit=${limit}&withMetadata=true`;

const alchemyAnswerNftsCollection = (await alchemyFetch(chainId, req)) as AlchemyAnwserNftsCollection;
Expand Down
4 changes: 2 additions & 2 deletions common/lib/apis/api-covalent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, constants } from "ethers";

import type { FetchResponse } from "@kredeum/common/lib/common/fetch";
import type { CollectionFilterType, CollectionType, NftType } from "@kredeum/common/lib/common/types";
import { getChecksumAddress } from "@kredeum/common/lib/common/config";
import { ADDRESS_ZERO, getChecksumAddress } from "@kredeum/common/lib/common/config";
import { DEFAULT_NAME, DEFAULT_SYMBOL } from "@kredeum/common/lib/common/config";
import { fetchJson, FETCH_LIMIT } from "@kredeum/common/lib/common/fetch";
import { keyCollection, keyNft } from "@kredeum/common/lib/common/keys";
Expand Down Expand Up @@ -100,7 +100,7 @@ const covalentNftList = async (
collection: CollectionType,
filter: CollectionFilterType = {}
): Promise<Map<string, NftType>> => {
const owner = filter.owner || constants.AddressZero;
const owner = filter.owner || ADDRESS_ZERO;
const limit = filter.limit || FETCH_LIMIT;
const address = getChecksumAddress(collection.address);
// console.log("covalentNftList", chainId, address, owner, limit);
Expand Down
9 changes: 5 additions & 4 deletions common/lib/apis/api-thegraph.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { BigNumber, constants } from "ethers";
import { BigNumber } from "ethers";

import type { CollectionType, CollectionFilterType, NftType } from "@kredeum/common/lib/common/types";
import { getChecksumAddress } from "@kredeum/common/lib/common/config";
import { ADDRESS_ZERO, getChecksumAddress } from "@kredeum/common/lib/common/config";

import { fetchGQL, FETCH_LIMIT } from "@kredeum/common/lib/common/fetch";
import { keyCollection, keyNft } from "@kredeum/common/lib/common/keys";
import { networks } from "@kredeum/common/lib/common/networks";


const thegraphNftList = async (
chainId: number,
collection: CollectionType,
filter: CollectionFilterType = {}
): Promise<Map<string, NftType>> => {
const owner = filter.owner || constants.AddressZero;
const owner = filter.owner || ADDRESS_ZERO;
const limit = filter.limit || FETCH_LIMIT;
const offset = filter.offset || 0;
const address = getChecksumAddress(collection.address);
Expand All @@ -21,7 +22,7 @@ const thegraphNftList = async (
const nfts: Map<string, NftType> = new Map();
if (!(chainId && address && thegraphActive(chainId))) return nfts;

const whereOwner = owner == constants.AddressZero ? "" : `where: { account: "${owner.toLowerCase()}" }`;
const whereOwner = owner == ADDRESS_ZERO ? "" : `where: { account: "${owner.toLowerCase()}" }`;
const skip = offset == 0 ? "" : `skip: "${offset}"`;
const query = `{
tokenContract( id: "${address.toLowerCase()}" ) {
Expand Down
6 changes: 3 additions & 3 deletions common/lib/collection/collection-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TransactionResponse, TransactionReceipt } from "@ethersproject/pro
import type { BigNumberish } from "ethers";
import { utils, constants } from "ethers";

import { explorerTxLog } from "@kredeum/common/lib/common/config";
import { ADDRESS_ZERO, explorerTxLog } from "@kredeum/common/lib/common/config";
import { factoryGetContract } from "@kredeum/common/lib/common/factory-get";
import { resolverGetCount } from "@kredeum/common/lib/resolver/resolver-get";

Expand All @@ -12,7 +12,7 @@ async function* collectionClone(
symbol: string,
templateConfig: string,
mintPrice: BigNumberish = 0,
royaltyReceiver: string = constants.AddressZero,
royaltyReceiver: string = ADDRESS_ZERO,
royaltyFee = 0,
minimum = false
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
Expand All @@ -36,7 +36,7 @@ async function* collectionClone(
options = [conf == "generic"];
optionsBytes = utils.defaultAbiCoder.encode(
["uint256", "address", "uint96", "bool[]"],
[0, constants.AddressZero, 0, options]
[0, ADDRESS_ZERO, 0, options]
);
} else if (template == "OpenAutoMarket") {
options = [conf == "generic", minimum];
Expand Down
10 changes: 3 additions & 7 deletions common/lib/collection/collection-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getAbi } from "@kredeum/common/lib/common/artifacts";
import { resolverGetCollection } from "@kredeum/common/lib/resolver/resolver-get-collection";
import { providerGetSignerOrProvider } from "@kredeum/common/lib/common/provider-get";
import { keyCollectionContract, keyCollection } from "@kredeum/common/lib/common/keys";
import { explorerAddressUrl, getChecksumAddress, isAddressNotZero } from "@kredeum/common/lib/common/config";
import { ADDRESS_ZERO, explorerAddressUrl, getChecksumAddress, isAddressNotZero } from "@kredeum/common/lib/common/config";
import { isAddress } from "ethers/lib/utils";
import { collectionSupports } from "./collection";

Expand All @@ -23,7 +23,7 @@ const collectionGetContract = async (
// console.log(`collectionGetContract IN ${keyCollection(chainId, address)}\n`);

const collection = await collectionGet(chainId, address);
if (!(chainId && address && address != constants.AddressZero)) return { collection };
if (!(chainId && address && address != ADDRESS_ZERO)) return { collection };

let signer = "";
let contract = contractsCache.get(keyCollectionContract(chainId, address, getSigner));
Expand Down Expand Up @@ -73,11 +73,7 @@ const collectionMerge = (col1: CollectionType, col2: CollectionType): Collection
return collMerged;
};

const collectionGet = async (
chainId: number,
address: string,
account = constants.AddressZero
): Promise<CollectionType> => {
const collectionGet = async (chainId: number, address: string, account = ADDRESS_ZERO): Promise<CollectionType> => {
let collection: CollectionType = { chainId, address };
if (!(chainId && isAddressNotZero(address) && isAddress(account))) return collection;
// console.log(`collectionGet ${explorerAddressUrl(chainId, address)}`);
Expand Down
8 changes: 3 additions & 5 deletions common/lib/collection/collection.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { CollectionType } from "@kredeum/common/lib/common/types";

import { BigNumber, constants } from "ethers";
import { feeAmount, treasuryAmount } from "@kredeum/common/lib/common/config";

const ZeroAddress = constants.AddressZero;
import { BigNumber } from "ethers";
import { ADDRESS_ZERO, feeAmount, treasuryAmount } from "@kredeum/common/lib/common/config";

const collectionPrice = (coll: CollectionType): BigNumber => coll?.price || BigNumber.from(0);
const collectionOwner = (coll: CollectionType): string => String(coll?.owner || "");
Expand All @@ -19,7 +17,7 @@ const collectionIsERC1155 = (coll: CollectionType): boolean => Boolean(coll?.sup
const collectionOpenOrOwner = (coll: CollectionType, owner: string): boolean =>
Boolean(coll?.owner === owner || coll?.open);

const collectionRoyaltyAccount = (coll: CollectionType): string => coll?.royalty?.account || ZeroAddress;
const collectionRoyaltyAccount = (coll: CollectionType): string => coll?.royalty?.account || ADDRESS_ZERO;
const collectionRoyaltyFee = (coll: CollectionType): number => Number(coll?.royalty?.fee || 0);
const collectionRoyaltyEnforcement = (coll: CollectionType): boolean => Boolean(coll?.royaltyEnforcement);

Expand Down
5 changes: 3 additions & 2 deletions common/lib/common/beejs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Bee } from "@ethersphere/bee-js";

import { DEFAULT_NAME, config } from "@kredeum/common/lib/common/config";
import { swarmApiEndpoint, swarmApiKey, SWARM_ZERO_APIKEY } from "@kredeum/common/lib/nft/storage/swarm";

const getBee = (nodeUrl: string): Bee => {
const getBee = (nodeUrl: string) => {
return new Bee(nodeUrl ? nodeUrl : config.storage.swarm.apiEndpoint);
};

Expand All @@ -12,7 +13,7 @@ const swarmUploadFile = async (file: File | string): Promise<string> => {
// console.log("swarmUploadFile ~ nodeUrl:", nodeUrl);
// console.log("swarmUploadFile ~ batchId:", batchId);

const bee: Bee = getBee(nodeUrl);
const bee = getBee(nodeUrl);

const isFile = file instanceof File;
const isPinnableBatchID = batchId && batchId !== SWARM_ZERO_APIKEY;
Expand Down
13 changes: 6 additions & 7 deletions common/lib/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ const tokenIdSelected = (tokenIDs: string, tokenID: string): boolean =>
const isCollection = (refHash: RefPageType) => networks.has(refHash.chainId) && isAddressNotZero(refHash.address);

const isAddress = (address = ""): boolean => utils.isAddress(address);
const isAddressNotZero = (account = ""): boolean => utils.isAddress(account) && account != constants.AddressZero;
const isAddressNotZero = (account = ""): boolean => utils.isAddress(account) && account != ADDRESS_ZERO;

const getChecksumAddress = (address = ""): string =>
isAddress(address) ? utils.getAddress(address) : constants.AddressZero;
const getChecksumAddress = (address = ""): string => (isAddress(address) ? utils.getAddress(address) : ADDRESS_ZERO);

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const addresses = JSON.parse(JSON.stringify(addressesRaw));
Expand All @@ -59,7 +58,7 @@ const getAutoswarmUrl = (chainId: number, ref: NftType | { address: string; toke
const nftUrl3 = (chainId: number, address: string, tokenID = "", n = 999): string => {
const network = networks.get(chainId);

if (!(chainId && address && address != constants.AddressZero && tokenID && network)) return "";
if (!(chainId && address && address != ADDRESS_ZERO && tokenID && network)) return "";
const ret =
"nft://" +
(network
Expand Down Expand Up @@ -127,7 +126,7 @@ const blockscanUrl = (path: string): string =>
"https://blockscan.com/" + path.replace(/^\//, "");

// ADDRESS URL
const explorerAddressUrl = (chainId: number, address: string): string =>
const explorerAddressUrl = (chainId: number, address = ""): string =>
// https://etherscan.io/address/0x4b7992F03906F7bBE3d48E5Fb724f52c56cFb039
// https://blockscan.com/address/0x4b7992F03906F7bBE3d48E5Fb724f52c56cFb039
chainId > 0 ? explorerUrl(chainId, `/address/${address}`) : blockscanUrl(`/address/${address}`);
Expand Down Expand Up @@ -237,7 +236,7 @@ const explorerNftLink = (chainId: number, nft: NftType, label?: string): string
/////////////////////////////////////////////////////////////////////////////////////////////////////
// URIs helpers
/////////////////////////////////////////////////////////////////////////////////////////////////////
const uriShort = (uri: string) => {
const uriShort = (uri: string): string => {
const [storage, hash] = uri.split("://");
if (!(storage && hash && hash.length > 20)) return uri;

Expand Down Expand Up @@ -300,7 +299,7 @@ const displayEther = (chainId: number, price: BigNumberish): string =>
/////////////////////////////////////////////////////////////////////////////////////////////////////
const feeAmount = (price = BigNumber.from(0), fee = 0): BigNumber => price.mul(fee).div(MAX_FEE);
/////////////////////////////////////////////////////////////////////////////////////////////////////
const treasuryAccount = (): string => config?.treasury?.account || constants.AddressZero;
const treasuryAccount = (): string => config?.treasury?.account || ADDRESS_ZERO;
const treasuryFee = (): number => config?.treasury?.fee || 0;
const treasuryAmount = (price = BigNumber.from(0)): BigNumber => feeAmount(price, treasuryFee());
/////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion common/lib/common/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const keyCollectionInverse = (key: string): CollectionType => {
return { chainId, address };
};

const keyCollectionDefault = (chainId: number, account: string): string =>
const keyCollectionDefault = (chainId: number, account?: string): string =>
`collectionDefault://${String(chainId)}${account ? "@" + account : ""}`;

const keyCollectionContract = (chainId: number, address: string, getSigner: boolean): string =>
Expand Down
4 changes: 2 additions & 2 deletions common/lib/common/provider-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import type { Provider } from "@ethersproject/abstract-provider";
import type { FallbackProviderConfig, Web3Provider } from "@ethersproject/providers";
import type { Signer } from "ethers";
import { ADDRESS_ZERO } from "@kredeum/common/lib/common/config";

import type { WindowExternalProvider } from "./types";
import { getChecksumAddress, sleep } from "@kredeum/common/lib/common/config";
import { ethers } from "ethers";
import { constants } from "ethers";
import { networks } from "./networks";

let _providerSetting = false;
Expand Down Expand Up @@ -37,7 +37,7 @@ const providerGetSigner = async (chainId = 0, accountOrIndex: string | number =

const providerGetAccount = async (): Promise<string> => {
const provider = await providerGetWindow();
let account = constants.AddressZero;
let account = ADDRESS_ZERO;

if (provider) {
const accounts = await provider.listAccounts();
Expand Down
9 changes: 5 additions & 4 deletions common/lib/nft/nft-automarket-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { IOpenMarketable } from "@kredeum/contracts/types/IOpenMarketable";
import type { IERC2981, IERC721 } from "@kredeum/contracts/types/index";
import type { BigNumberish } from "ethers";
import { BigNumber, constants } from "ethers";
import { ADDRESS_ZERO } from "@kredeum/common/lib/common/config";

import type { ReceiverType } from "@kredeum/common/lib/common/types";
import { collectionGetContract } from "@kredeum/common/lib/collection/collection-get";
Expand All @@ -26,7 +27,7 @@ const getNftPrice = async (chainId: number, address: string, tokenID: string): P
const getNftRoyalty = async (chainId: number, address: string, tokenID: string): Promise<ReceiverType> => {
const { contract, collection } = await collectionGetContract(chainId, address);

if (!collectionIsOpenMarketable(collection)) return { account: constants.AddressZero, fee: 0 };
if (!collectionIsOpenMarketable(collection)) return { account: ADDRESS_ZERO, fee: 0 };

const receiver = await (contract as IOpenMarketable).getTokenRoyalty(tokenID);

Expand All @@ -41,7 +42,7 @@ const getNftRoyaltyInfo = async (
nftPrice: string
): Promise<{ receiver: string; royaltyAmount: BigNumber }> => {
const royalty = {
receiver: constants.AddressZero,
receiver: ADDRESS_ZERO,
royaltyAmount: constants.Zero
};

Expand All @@ -68,7 +69,7 @@ const getDefaultCollRoyaltyInfos = async (
): Promise<{ receiver: string; fee: BigNumber }> => {
const { contract, collection } = await collectionGetContract(chainId, address);

if (!collectionIsOpenMarketable(collection)) return { receiver: constants.AddressZero, fee: constants.Zero };
if (!collectionIsOpenMarketable(collection)) return { receiver: ADDRESS_ZERO, fee: constants.Zero };

const royaltyInfostest = await (contract as IOpenMarketable).getDefaultRoyalty();

Expand All @@ -77,7 +78,7 @@ const getDefaultCollRoyaltyInfos = async (

const getApproved = async (chainId: number, address: string, tokenID: string): Promise<string> => {
const { contract, collection } = await collectionGetContract(chainId, address);
if (!(contract && collectionIsERC721(collection))) return constants.AddressZero;
if (!(contract && collectionIsERC721(collection))) return ADDRESS_ZERO;

return await (contract as IERC721).getApproved(tokenID);
};
Expand Down
16 changes: 7 additions & 9 deletions common/lib/nft/nft-automarket-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type { OpenAutoMarket } from "@kredeum/contracts/types/OpenAutoMarket";
import type { IOpenMarketable } from "@kredeum/contracts/types/IOpenMarketable";
import type { IERC721 } from "@kredeum/contracts/types/index";
import { collectionGetContract } from "@kredeum/common/lib/collection/collection-get";
import { explorerTxLog } from "@kredeum/common/lib/common/config";
import { constants } from "ethers";
import { ADDRESS_ZERO, explorerTxLog } from "@kredeum/common/lib/common/config";
import { collectionIsERC721, collectionIsOpenMarketable } from "@kredeum/common/lib/collection/collection";

async function* setTokenRoyaltyInfos(
Expand All @@ -19,7 +18,7 @@ async function* setTokenRoyaltyInfos(
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("setTokenRoyaltyInfos", chainId, address, tokenID, fee, receiver);

if (!(chainId && address && address != constants.AddressZero && tokenID && fee && receiver)) return {};
if (!(chainId && address && address != ADDRESS_ZERO && tokenID && fee && receiver)) return {};

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer)) return {};
Expand Down Expand Up @@ -47,7 +46,7 @@ async function* setTokenApprove(
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("transferNft", chainId, address, tokenID, to);

if (!(chainId && address && address != constants.AddressZero && tokenID)) return {};
if (!(chainId && address && address != ADDRESS_ZERO && tokenID)) return {};

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer && collectionIsERC721(collection))) return {};
Expand All @@ -68,7 +67,7 @@ async function* setCollectionApproval(
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("transferNft", chainId, address, tokenID, to);

if (!(chainId && address && address != constants.AddressZero && approval)) return {};
if (!(chainId && address && address != ADDRESS_ZERO && approval)) return {};

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer && collectionIsERC721(collection))) return;
Expand All @@ -90,7 +89,7 @@ async function* setTokenPrice(
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("setTokenPrice", chainId, address, tokenID, tokenPrice);

if (!(chainId && address && address != constants.AddressZero && tokenID && tokenPrice)) return {};
if (!(chainId && address && address != ADDRESS_ZERO && tokenID && tokenPrice)) return {};

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer && collectionIsOpenMarketable(collection))) return {};
Expand All @@ -110,7 +109,7 @@ async function* setDefautCollectionPrice(
mintPrice: BigNumber
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("setDefautCollectionPrice", chainId, address, mintPrice);
if (!(chainId && address && address != constants.AddressZero && mintPrice)) return;
if (!(chainId && address && address != ADDRESS_ZERO && mintPrice)) return;

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer && collectionIsOpenMarketable(collection))) return {};
Expand All @@ -130,8 +129,7 @@ async function* setDefautCollectionRoyalty(
): AsyncGenerator<TransactionResponse | TransactionReceipt | Record<string, never>> {
// console.log("transferNft", chainId, address, tokenID, to);

if (!(chainId && address && address != constants.AddressZero && defaultRoyaltyAmount && defaultRoyaltiesReceiver))
return {};
if (!(chainId && address && address != ADDRESS_ZERO && defaultRoyaltyAmount && defaultRoyaltiesReceiver)) return {};

const { contract, collection, signer } = await collectionGetContract(chainId, address, true);
if (!(contract && signer)) return {};
Expand Down
Loading

0 comments on commit d9fdf2f

Please sign in to comment.