Skip to content

Commit d89d703

Browse files
typecheck tests, refactor tests, add quantity to orders
1 parent 8c69fad commit d89d703

File tree

13 files changed

+310
-238
lines changed

13 files changed

+310
-238
lines changed

lib/seaport.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export declare class OpenSeaPort {
191191
}): Promise<Order>;
192192
/**
193193
* Create a sell order to auction an asset.
194-
* Will throw a 'You do not own this asset' error if the maker doesn't have the asset.
194+
* Will throw a 'You do not own enough of this asset' error if the maker doesn't have the asset or not enough of it to sell the specific `quantity`.
195195
* If the user hasn't approved access to the token yet, this will emit `ApproveAllAssets` (or `ApproveAsset` if the contract doesn't support approve-all) before asking for approval.
196196
* @param param0 __namedParameters Object
197197
* @param tokenId DEPRECATED: Token ID. Use `asset` instead.

lib/seaport.js

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/seaport.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export interface Asset {
176176
tokenAddress: string;
177177
version?: TokenStandardVersion;
178178
name?: string;
179+
decimals?: number;
179180
}
180181
/**
181182
* Annotated asset contract with OpenSea metadata
@@ -288,6 +289,7 @@ export interface UnhashedOrder extends WyvernOrder {
288289
side: OrderSide;
289290
saleKind: SaleKind;
290291
howToCall: HowToCall;
292+
quantity: BigNumber;
291293
makerReferrerFee: BigNumber;
292294
waitingForBestCounterOrder: boolean;
293295
metadata: {

lib/utils.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"main": "lib/index.js",
1010
"scripts": {
11-
"test": "./node_modules/.bin/mocha test/*.ts --require ts-node/register --timeout 15000",
11+
"test": "./node_modules/.bin/mocha test/**/*.ts --require ts-node/register --timeout 15000",
1212
"lint": "tslint --project . 'src/**/*.ts' --fix",
1313
"build": "npm run lint && tsc",
1414
"docs": "npm run docsHtml",

src/seaport.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,8 @@ export class OpenSeaPort {
18321832

18331833
accountAddress = validateAndFormatWalletAddress(this.web3, accountAddress)
18341834
const schema = this._getSchema(schemaName)
1835-
const wyAsset = getWyvernAsset(schema, asset, new BigNumber(quantity))
1835+
const quantityBN = WyvernProtocol.toBaseUnitAmount(makeBigNumber(quantity), asset.decimals || 0)
1836+
const wyAsset = getWyvernAsset(schema, asset, quantityBN)
18361837

18371838
let makerRelayerFee
18381839
let takerRelayerFee
@@ -1867,6 +1868,7 @@ export class OpenSeaPort {
18671868
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
18681869
maker: accountAddress,
18691870
taker,
1871+
quantity: quantityBN,
18701872
makerRelayerFee,
18711873
takerRelayerFee,
18721874
makerProtocolFee: makeBigNumber(0),
@@ -1913,6 +1915,7 @@ export class OpenSeaPort {
19131915

19141916
accountAddress = validateAndFormatWalletAddress(this.web3, accountAddress)
19151917
const schema = this._getSchema(schemaName)
1918+
const quantityBN = WyvernProtocol.toBaseUnitAmount(makeBigNumber(quantity), asset.decimals || 0)
19161919
const wyAsset = getWyvernAsset(schema, asset, new BigNumber(quantity))
19171920
const isPrivate = buyerAddress != NULL_ADDRESS
19181921
const { totalSellerFeeBPS,
@@ -1925,7 +1928,7 @@ export class OpenSeaPort {
19251928
? SaleKind.DutchAuction
19261929
: SaleKind.FixedPrice
19271930

1928-
const { basePrice, extra } = await this._getPriceParameters(paymentTokenAddress, expirationTime, startAmount, endAmount, waitForHighestBid)
1931+
const { basePrice, extra, } = await this._getPriceParameters(paymentTokenAddress, expirationTime, startAmount, endAmount, waitForHighestBid)
19291932
const times = this._getTimeParameters(expirationTime, waitForHighestBid)
19301933
// Use buyer as the maker when it's an English auction, so Wyvern sets prices correctly
19311934
const feeRecipient = waitForHighestBid
@@ -1945,6 +1948,7 @@ export class OpenSeaPort {
19451948
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
19461949
maker: accountAddress,
19471950
taker: buyerAddress,
1951+
quantity: quantityBN,
19481952
makerRelayerFee,
19491953
takerRelayerFee,
19501954
makerProtocolFee: makeBigNumber(0),
@@ -2022,6 +2026,7 @@ export class OpenSeaPort {
20222026
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
20232027
maker: accountAddress,
20242028
taker: NULL_ADDRESS,
2029+
quantity: makeBigNumber(1),
20252030
makerRelayerFee,
20262031
takerRelayerFee,
20272032
makerProtocolFee: makeBigNumber(0),
@@ -2102,6 +2107,7 @@ export class OpenSeaPort {
21022107
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
21032108
maker: accountAddress,
21042109
taker: buyerAddress,
2110+
quantity: makeBigNumber(1),
21052111
makerRelayerFee: makeBigNumber(totalSellerFeeBPS),
21062112
takerRelayerFee: makeBigNumber(totalBuyerFeeBPS),
21072113
makerProtocolFee: makeBigNumber(0),
@@ -2176,6 +2182,7 @@ export class OpenSeaPort {
21762182
exchange: order.exchange,
21772183
maker: accountAddress,
21782184
taker: order.maker,
2185+
quantity: order.quantity,
21792186
makerRelayerFee: order.makerRelayerFee,
21802187
takerRelayerFee: order.takerRelayerFee,
21812188
makerProtocolFee: order.makerProtocolFee,

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ export interface Asset {
229229
version?: TokenStandardVersion,
230230
// Optional for ENS names
231231
name?: string,
232+
// Optional for fungible items
233+
decimals?: number
232234
}
233235

234236
/**

test/api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import { ORDERBOOK_VERSION } from '../src/api'
1212
import { Order, OrderSide, OrderJSON } from '../src/types'
1313
import { orderToJSON } from '../src'
14-
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE, MAINNET_API_KEY, CK_ADDRESS } from './constants'
15-
import { getOrderHash } from '../src/utils';
14+
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE, RINKEBY_API_KEY, CK_ADDRESS } from './constants'
15+
import { getOrderHash } from '../src/utils'
1616

1717
suite('api', () => {
1818

@@ -35,20 +35,20 @@ suite('api', () => {
3535
})
3636

3737
test('Includes API key in token request', async () => {
38-
const oldLogger = apiToTest.logger
38+
const oldLogger = rinkebyApi.logger
3939

4040
const logPromise = new Promise((resolve, reject) => {
41-
apiToTest.logger = log => {
41+
rinkebyApi.logger = log => {
4242
try {
43-
assert.include(log, `"X-API-KEY":"${MAINNET_API_KEY}"`)
43+
assert.include(log, `"X-API-KEY":"${RINKEBY_API_KEY}"`)
4444
resolve()
4545
} catch (e) {
4646
reject(e)
4747
} finally {
48-
apiToTest.logger = oldLogger
48+
rinkebyApi.logger = oldLogger
4949
}
5050
}
51-
apiToTest.getPaymentTokens({ symbol: "MANA" })
51+
rinkebyApi.getPaymentTokens({ symbol: "WETH" })
5252
})
5353

5454
await logPromise

0 commit comments

Comments
 (0)