@georgeroman/wyvern-v2-sdk
Advanced tools
Comparing version 0.0.31 to 0.0.32
@@ -76,3 +76,29 @@ [ | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "operator", | ||
"type": "address" | ||
} | ||
], | ||
"name": "isApprovedForAll", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
@@ -43,3 +43,26 @@ [ | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "spender", | ||
"type": "address" | ||
} | ||
], | ||
"name": "allowance", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
@@ -87,3 +87,50 @@ [ | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "operator", | ||
"type": "address" | ||
} | ||
], | ||
"name": "isApprovedForAll", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "tokenId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "getApproved", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
@@ -68,2 +68,6 @@ "use strict"; | ||
} | ||
if (Number(order.makerRelayerFee) > 10000 || | ||
Number(order.takerRelayerFee) > 10000) { | ||
return false; | ||
} | ||
mock.taker = order.taker; | ||
@@ -70,0 +74,0 @@ mock.makerRelayerFee = order.makerRelayerFee; |
@@ -56,2 +56,6 @@ "use strict"; | ||
} | ||
if (Number(order.makerRelayerFee) > 10000 || | ||
Number(order.takerRelayerFee) > 10000) { | ||
return false; | ||
} | ||
mock.taker = order.taker; | ||
@@ -58,0 +62,0 @@ mock.makerRelayerFee = order.makerRelayerFee; |
@@ -0,4 +1,6 @@ | ||
import { Provider } from "@ethersproject/abstract-provider"; | ||
import { Signer } from "@ethersproject/abstract-signer"; | ||
import { Order } from "../types"; | ||
export default class OrderHelper { | ||
static isApproved(provider: Provider, order: Order): Promise<boolean>; | ||
static normalize(order: Order): Order; | ||
@@ -5,0 +7,0 @@ static rawHash(order: Order): string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const abi_1 = require("@ethersproject/abi"); | ||
const bytes_1 = require("@ethersproject/bytes"); | ||
const contracts_1 = require("@ethersproject/contracts"); | ||
const hash_1 = require("@ethersproject/hash"); | ||
const solidity_1 = require("@ethersproject/solidity"); | ||
const wallet_1 = require("@ethersproject/wallet"); | ||
const Erc20_json_1 = __importDefault(require("../abis/Erc20.json")); | ||
const Erc721_json_1 = __importDefault(require("../abis/Erc721.json")); | ||
const Erc1155_json_1 = __importDefault(require("../abis/Erc1155.json")); | ||
const ProxyRegistry_json_1 = __importDefault(require("../abis/ProxyRegistry.json")); | ||
const types_1 = require("../types"); | ||
const utils_1 = require("../utils"); | ||
const address_1 = __importDefault(require("../utils/address")); | ||
const __1 = require(".."); | ||
const WYVERN_ORDER_FIELDS = [ | ||
@@ -39,2 +51,45 @@ "address", | ||
class OrderHelper { | ||
static async isApproved(provider, order) { | ||
try { | ||
const chainId = (await provider.getNetwork()).chainId; | ||
if (order.side === types_1.Side.BUY) { | ||
const paymentToken = new contracts_1.Contract(order.paymentToken, new abi_1.Interface(Erc20_json_1.default)); | ||
const allowance = await paymentToken | ||
.connect(provider) | ||
.allowance(order.maker, address_1.default.tokenTransferProxy(chainId)); | ||
return (0, utils_1.bn)(allowance).gte((0, utils_1.bn)(order.basePrice)); | ||
} | ||
else { | ||
const proxyRegistry = new contracts_1.Contract(address_1.default.proxyRegistry(chainId), new abi_1.Interface(ProxyRegistry_json_1.default)); | ||
const proxy = await proxyRegistry | ||
.connect(provider) | ||
.proxies(order.maker); | ||
if (!proxy) { | ||
return false; | ||
} | ||
if (__1.Builders.Erc721.SingleItem.isWellFormatted(order)) { | ||
const token = new contracts_1.Contract(order.target, new abi_1.Interface(Erc721_json_1.default)); | ||
const isApprovedForAll = await token | ||
.connect(provider) | ||
.isApprovedForAll(order.maker, proxy); | ||
if (!isApprovedForAll) { | ||
const tokenId = __1.Builders.Erc721.SingleItem.extractTokenId(order); | ||
const approved = await token.connect(provider).getApproved(tokenId); | ||
return approved && approved.toLowerCase() === proxy.toLowerCase(); | ||
} | ||
return isApprovedForAll; | ||
} | ||
else if (__1.Builders.Erc1155.SingleItem.isWellFormatted(order)) { | ||
const token = new contracts_1.Contract(order.target, new abi_1.Interface(Erc1155_json_1.default)); | ||
return token.connect(provider).isApprovedForAll(order.maker, proxy); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
} | ||
catch { | ||
return false; | ||
} | ||
} | ||
static normalize(order) { | ||
@@ -41,0 +96,0 @@ // - convert all BigNumbers to string |
export default class Address { | ||
static eth(chainId: number): string | undefined; | ||
static weth(chainId: number): string | undefined; | ||
static wyvernV2(chainId: number): string | undefined; | ||
static exchange(chainId: number): string | undefined; | ||
static tokenTransferProxy(chainId: number): string | undefined; | ||
static proxyRegistry(chainId: number): string | undefined; | ||
} | ||
//# sourceMappingURL=address.d.ts.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
} | ||
static wyvernV2(chainId) { | ||
static exchange(chainId) { | ||
switch (chainId) { | ||
@@ -32,4 +32,22 @@ case 1: | ||
} | ||
static tokenTransferProxy(chainId) { | ||
switch (chainId) { | ||
case 1: | ||
return "0xe5c783ee536cf5e63e792988335c4255169be4e1"; | ||
case 4: | ||
return "0x82d102457854c985221249f86659c9d6cf12aa72"; | ||
} | ||
return undefined; | ||
} | ||
static proxyRegistry(chainId) { | ||
switch (chainId) { | ||
case 1: | ||
return "0xa5409ec958c83c3f309868babaca7c86dcb077c1"; | ||
case 4: | ||
return "0xf57b2c51ded3a29e6891aba85459d600256cf317"; | ||
} | ||
return undefined; | ||
} | ||
} | ||
exports.default = Address; | ||
//# sourceMappingURL=address.js.map |
{ | ||
"name": "@georgeroman/wyvern-v2-sdk", | ||
"version": "0.0.31", | ||
"version": "0.0.32", | ||
"description": "Wyvern V2 SDK", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153129
3369