Skip to content

Commit

Permalink
Remove some usage of wyvern-js (#884)
Browse files Browse the repository at this point in the history
* Remove Wyvern from constants.ts

* Remove wyvern from utils/tokens/index

* Define AbiType

* Remove wyvern-js dependencies in src/utils/schemas

* Remove wyvern-js from types

* Remove wyvern-js dep from src/utils/utils

* Remove ReplacementEncoder dep on wyvern-js
  • Loading branch information
JoshuaSchmidt-OpenSea committed Mar 27, 2023
1 parent fa8b573 commit a00089c
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 103 deletions.
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { WyvernProtocol } from "wyvern-js";
import { Network } from "./types";

export const DEFAULT_GAS_INCREASE_FACTOR = 1.01;
export const NULL_ADDRESS = WyvernProtocol.NULL_ADDRESS;
export const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
export const NULL_BLOCK_HASH =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const OPENSEA_LEGACY_FEE_RECIPIENT =
Expand Down
3 changes: 1 addition & 2 deletions src/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { AnnotatedFunctionABI } from "wyvern-js/lib/types";
import type { PartialReadonlyContractAbi } from "./types";
import type { AnnotatedFunctionABI, PartialReadonlyContractAbi } from "./types";

export const getMethod = (
abi: PartialReadonlyContractAbi,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable import/no-unused-modules */
import { OpenSeaAPI } from "./api";
import { OpenSeaSDK } from "./sdk";
import { OpenSeaSDK, WyvernProtocol } from "./sdk";
import { Network, EventData, EventType } from "./types";
export { orderToJSON, orderFromJSON, WyvernProtocol } from "./utils/utils";
export { orderToJSON, orderFromJSON } from "./utils/utils";
export {
encodeCall,
encodeSell,
encodeAtomicizedBuy,
encodeAtomicizedSell,
encodeDefaultCall,
encodeReplacementPattern,
AbiType,
} from "./utils/schemas/schema";
export { WyvernProtocol };

/**
* Example setup:
Expand Down
1 change: 0 additions & 1 deletion src/orders/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const orderSchema: JSONSchemaType<PartialOrderV2Type> = {
"cancelled",
"finalized",
"markedInvalid",
"clientSignature",
"makerAssetBundle",
"takerAssetBundle",
],
Expand Down
2 changes: 2 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ import {
isValidProtocol,
} from "./utils/utils";

export { WyvernProtocol };

export class OpenSeaSDK {
// Web3 instance to use
public web3: Web3;
Expand Down
124 changes: 112 additions & 12 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
/* eslint-disable import/no-unused-modules */
import BigNumber from "bignumber.js";
import { AbiItem } from "web3-utils";
import {
ECSignature,
HowToCall,
Network,
Order as WyvernOrder,
WyvernProtocolConfig,
} from "wyvern-js/lib/types";
import type { OrderV2 } from "./orders/types";

export { HowToCall, Network };
export type { ECSignature };

/**
* Events emitted by the SDK. There are five types:
* 1. Transaction events, which tell you when a new transaction was
Expand Down Expand Up @@ -105,7 +95,20 @@ export interface OpenSeaAPIConfig {
wyvernConfig?: WyvernConfig;
}

export type WyvernConfig = WyvernProtocolConfig & {
export enum Network {
Main = "main",
Goerli = "goerli",
Rinkeby = "rinkeby",
}

export type WyvernConfig = {
network: Network;
gasPrice?: BigNumber;
wyvernExchangeContractAddress?: string;
wyvernProxyRegistryContractAddress?: string;
wyvernDAOContractAddress?: string;
wyvernTokenContractAddress?: string;
wyvernAtomicizerContractAddress?: string;
wyvernTokenTransferProxyContractAddress?: string;
};

Expand Down Expand Up @@ -567,7 +570,27 @@ export type ExchangeMetadata =
| ExchangeMetadataForAsset
| ExchangeMetadataForBundle;

export interface UnhashedOrder extends WyvernOrder {
export interface UnhashedOrder {
exchange: string;
maker: string;
taker: string;
makerRelayerFee: BigNumber;
takerRelayerFee: BigNumber;
makerProtocolFee: BigNumber;
takerProtocolFee: BigNumber;
feeRecipient: string;
target: string;
calldata: string;
replacementPattern: string;
staticTarget: string;
staticExtradata: string;
paymentToken: string;
basePrice: BigNumber;
extra: BigNumber;
listingTime: BigNumber;
expirationTime: BigNumber;
salt: BigNumber;

feeMethod: FeeMethod;
side: OrderSide;
saleKind: SaleKind;
Expand All @@ -582,10 +605,23 @@ export interface UnhashedOrder extends WyvernOrder {
metadata: ExchangeMetadata;
}

export enum HowToCall {
Call = 0,
DelegateCall = 1,
StaticCall = 2,
Create = 3,
}

export interface UnsignedOrder extends UnhashedOrder {
hash?: string;
}

export interface ECSignature {
v: number;
r: string;
s: string;
}

/**
* Orders don't need to be signed if they're pre-approved
* with a transaction on the contract to approveOrder_
Expand Down Expand Up @@ -722,3 +758,67 @@ export type Web3Callback<T> = (err: Error | null, result: T) => void;
export type TxnCallback = (result: boolean) => void;

export type PartialReadonlyContractAbi = AbiItem[];

// Types extracted from wyvern-js: https://github.com/ProjectOpenSea/wyvern-js#7429b1f2dd123f012cae1f3144a069e91ecd0682
export interface AnnotatedFunctionABI {
type: AbiType;
name: string;
target: string;
inputs: AnnotatedFunctionInput[];
outputs: AnnotatedFunctionOutput[];
constant: boolean;
stateMutability: StateMutability;
payable: boolean;
}

export enum AbiType {
Function = "function",
Constructor = "constructor",
Event = "event",
Fallback = "fallback",
}

export interface AnnotatedFunctionInput {
name: string;
type: string;
kind: FunctionInputKind;
value?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}

export interface AnnotatedFunctionOutput {
name: string;
type: string;
kind: FunctionOutputKind;
}

export enum FunctionInputKind {
Replaceable = "replaceable",
Asset = "asset",
Owner = "owner",
Index = "index",
Count = "count",
Data = "data",
}

export enum FunctionOutputKind {
Owner = "owner",
Asset = "asset",
Count = "count",
Other = "other",
}

export enum StateMutability {
Pure = "pure",
View = "view",
Payable = "payable",
Nonpayable = "nonpayable",
}

export enum SolidityTypes {
Address = "address",
Uint256 = "uint256",
Uint8 = "uint8",
Uint = "uint",
Bytes = "bytes",
String = "string",
}
6 changes: 3 additions & 3 deletions src/utils/schemas/ContractRole/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../schema";
import {
AbiType,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../schema";
} from "../types";

interface ContractRoleType {
roleGetter: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/ERC1155/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../schema";
import {
AbiType,
StateMutability,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../schema";
} from "../types";

export interface SemiFungibleTradeType {
id: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/ERC20/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../schema";
import {
AbiType,
StateMutability,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../schema";
} from "../types";

interface FungibleTradeType {
address: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/ERC721/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../schema";
import {
AbiType,
StateMutability,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../schema";
} from "../types";

interface NonFungibleContractType {
id: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/main/CryptoKitties/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from "axios";
import { AbiType } from "ethereum-types";
import { Schema } from "../../schema";
import {
AbiType,
EventInputKind,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../../schema";
import { EventInputKind } from "../../types";
} from "../../types";

type CryptoKittiesType = string;

Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/main/CryptoPunks/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../../schema";
import {
AbiType,
EventInputKind,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../../schema";
import { EventInputKind } from "../../types";
} from "../../types";

type CryptoPunksType = string;

Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/main/ENSName/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AbiType } from "ethereum-types";
import { ENSName, ENSNameBaseSchema } from "../../ens";
import { Schema } from "../../schema";
import {
AbiType,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { ENSName, ENSNameBaseSchema } from "../../ens";
import { Schema } from "../../schema";
} from "../../types";

export const ENSNameSchema: Schema<ENSName> = {
...ENSNameBaseSchema,
Expand Down
9 changes: 6 additions & 3 deletions src/utils/schemas/main/ENSShortNameAuction/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { AbiType } from "ethereum-types";
import { namehash } from "ethers/lib/utils";
import { FunctionInputKind, StateMutability } from "wyvern-js/lib/types";
import { ENSName, ENSNameBaseSchema, nodehash } from "../../ens";
import { Schema } from "../../schema";
import { EventInputKind } from "../../types";
import {
AbiType,
EventInputKind,
FunctionInputKind,
StateMutability,
} from "../../types";

const ENS_SHORT_NAME_AUCTION_ADDRESS =
"0x699c7f511c9e2182e89f29b3bfb68bd327919d17";
Expand Down
10 changes: 5 additions & 5 deletions src/utils/schemas/main/EnjinItem/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AbiType } from "ethereum-types";
import { SemiFungibleTradeType, ERC1155Schema } from "../../ERC1155";
import { Schema } from "../../schema";
import {
AbiType,
StateMutability,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { SemiFungibleTradeType, ERC1155Schema } from "../../ERC1155";
import { Schema } from "../../schema";
} from "../../types";

/* eslint-disable @typescript-eslint/no-explicit-any */
export const EnjinItemSchema: Schema<SemiFungibleTradeType> = {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/main/OwnableContract/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../../schema";
import {
AbiType,
StateMutability,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../../schema";
} from "../../types";

interface OwnableContractType {
name?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schemas/rinkeby/rinkebyCryptoKitties/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AbiType } from "ethereum-types";
import { Schema } from "../../schema";
import {
AbiType,
EventInputKind,
FunctionInputKind,
FunctionOutputKind,
StateMutability,
} from "wyvern-js/lib/types";
import { Schema } from "../../schema";
import { EventInputKind } from "../../types";
} from "../../types";

type RinkebyCryptoKittiesType = string;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/schemas/rinkeby/rinkebyCustom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnnotatedFunctionABI } from "wyvern-js/lib/types";
import { Schema } from "../../schema";
import { AnnotatedFunctionABI } from "../../types";

interface RinkebyCustomType {
name: string;
Expand Down
Loading

0 comments on commit a00089c

Please sign in to comment.