|
1 | 1 | import { Signer, TypedDataSigner } from '@ethersproject/abstract-signer'; |
2 | 2 | import { BigNumber } from '@ethersproject/bignumber'; |
3 | 3 | import { hexDataLength, hexDataSlice } from '@ethersproject/bytes'; |
4 | | -import { BaseProvider } from '@ethersproject/providers'; |
| 4 | +import type { BaseProvider } from '@ethersproject/providers'; |
| 5 | +import type { ContractTransaction } from '@ethersproject/contracts'; |
5 | 6 | import getUnixTime from 'date-fns/getUnixTime'; |
6 | | -import { ContractTransaction } from 'ethers'; |
7 | 7 | import { v4 } from 'uuid'; |
| 8 | +import warning from 'tiny-warning'; |
8 | 9 | import { |
9 | 10 | ERC1155__factory, |
10 | 11 | ERC20__factory, |
@@ -39,7 +40,6 @@ import { |
39 | 40 | PROPERTY_ABI, |
40 | 41 | ETH_ADDRESS_AS_ERC20, |
41 | 42 | } from './constants'; |
42 | | -import warning from 'tiny-warning'; |
43 | 43 |
|
44 | 44 | export const signOrderWithEoaWallet = async ( |
45 | 45 | order: NftOrderV4, |
@@ -314,7 +314,7 @@ export const generateErc721Order = ( |
314 | 314 | expiry: orderData.expiry |
315 | 315 | ? getUnixTime(orderData.expiry).toString() |
316 | 316 | : INFINITE_EXPIRATION_TIMESTAMP_SEC.toString(), |
317 | | - nonce: orderData.nonce?.toString() ?? generateRandomNonce(), |
| 317 | + nonce: orderData.nonce?.toString() ?? generateRandomV4OrderNonce(), |
318 | 318 | taker: orderData.taker?.toLowerCase() ?? NULL_ADDRESS, |
319 | 319 | }; |
320 | 320 |
|
@@ -351,15 +351,21 @@ export const generateErc1155Order = ( |
351 | 351 | expiry: orderData.expiry |
352 | 352 | ? getUnixTime(orderData.expiry).toString() |
353 | 353 | : INFINITE_EXPIRATION_TIMESTAMP_SEC.toString(), |
354 | | - nonce: orderData.nonce?.toString() ?? generateRandomNonce(), |
| 354 | + nonce: orderData.nonce?.toString() ?? generateRandomV4OrderNonce(), |
355 | 355 | taker: orderData.taker?.toLowerCase() ?? NULL_ADDRESS, |
356 | 356 | }; |
357 | 357 |
|
358 | 358 | return erc1155Order; |
359 | 359 | }; |
360 | 360 |
|
361 | | -const generateRandomNonce = () => { |
362 | | - return `0x${v4().toString().split('-').join('')}`; |
| 361 | +/** |
| 362 | + * @returns 128bit nonce as string (0x orders can handle up to 256 bit nonce) |
| 363 | + */ |
| 364 | +export const generateRandomV4OrderNonce = (): string => { |
| 365 | + const hex = '0x' + v4().replace(/-/g, ''); |
| 366 | + const value = BigInt(hex); |
| 367 | + const decimal = value.toString(); // don't convert this to a number, will lose precision |
| 368 | + return decimal; |
363 | 369 | }; |
364 | 370 |
|
365 | 371 | export const serializeNftOrder = ( |
|
0 commit comments