How to use the @0x/order-utils.generatePseudoRandomSalt function in @0x/order-utils

To help you get started, we’ve selected a few @0x/order-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / website / ts / redux / reducer.ts View on Github external
flashMessage: string | React.ReactNode;
    providerType: ProviderType;
    injectedProviderName: string;
    translate: Translate;
}

export const INITIAL_STATE: State = {
    // Portal
    blockchainErr: BlockchainErrs.NoError,
    blockchainIsLoaded: false,
    networkId: undefined,
    orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(),
    orderFillAmount: undefined,
    orderSignature: '',
    orderTakerAddress: constants.NULL_ADDRESS,
    orderSalt: generatePseudoRandomSalt(),
    nodeVersion: undefined,
    screenWidth: utils.getScreenWidth(),
    shouldBlockchainErrDialogBeOpen: false,
    sideToAssetToken: {
        [Side.Deposit]: {},
        [Side.Receive]: {},
    },
    tokenByAddress: {},
    lastForceTokenStateRefetch: moment().unix(),
    userAddress: '',
    userEtherBalanceInWei: undefined,
    userSuppliedOrderCache: undefined,
    portalOnboardingStep: 0,
    isPortalOnboardingShowing: false,
    hasPortalOnboardingBeenClosed: false,
    // Docs
github melonproject / protocol / src / contracts / exchanges / third-party / 0x / utils / createOrder.ts View on Github external
: constants.ZERO_AMOUNT;

  // tslint:disable:object-literal-sort-keys
  const order: Order = {
    exchangeAddress: `${exchange.toLowerCase()}`,
    makerAddress: `${makerAddress.toLowerCase()}`,
    takerAddress: constants.NULL_ADDRESS,
    senderAddress: constants.NULL_ADDRESS,
    feeRecipientAddress: (
      feeRecipientAddress || constants.NULL_ADDRESS
    ).toLowerCase(),
    expirationTimeSeconds: new BigNumber(
      add(toBI(latestBlock.timestamp), toBI(duration)).toString(),
    ),
    salt: new BigNumber(
      generatePseudoRandomSalt()
        .toString()
        .slice(0, 10),
    ),
    makerAssetAmount: new BigNumber(`${makerQuantity.quantity}`),
    takerAssetAmount: new BigNumber(`${takerQuantity.quantity}`),
    makerAssetData,
    takerAssetData,
    makerFee: constants.ZERO_AMOUNT,
    takerFee: formattedTakerFee,
  };

  return order;
};
github 0xProject / 0x-monorepo / contracts / asset-proxy / src / erc721_wrapper.ts View on Github external
public async setBalancesAndAllowancesAsync(): Promise {
        this._validateDummyTokenContractsExistOrThrow();
        this._validateProxyContractExistsOrThrow();
        this._initialTokenIdsByOwner = {};
        for (const dummyTokenContract of this._dummyTokenContracts) {
            for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
                // tslint:disable-next-line:no-unused-variable
                for (const i of _.times(constants.NUM_ERC721_TOKENS_TO_MINT)) {
                    const tokenId = generatePseudoRandomSalt();
                    await this.mintAsync(dummyTokenContract.address, tokenId, tokenOwnerAddress);
                    if (this._initialTokenIdsByOwner[tokenOwnerAddress] === undefined) {
                        this._initialTokenIdsByOwner[tokenOwnerAddress] = {
                            [dummyTokenContract.address]: [],
                        };
                    }
                    if (this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address] === undefined) {
                        this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address] = [];
                    }
                    this._initialTokenIdsByOwner[tokenOwnerAddress][dummyTokenContract.address].push(tokenId);

                    await this.approveProxyForAllAsync(dummyTokenContract.address, tokenOwnerAddress, true);
                }
            }
        }
    }
github 0xProject / 0x-monorepo / contracts / test-utils / src / order_factory.ts View on Github external
public async newSignedOrderAsync(
        customOrderParams: Partial = {},
        signatureType: SignatureType = SignatureType.EthSign,
    ): Promise {
        const fifteenMinutesInSeconds = 15 * 60;
        const currentBlockTimestamp = await getLatestBlockTimestampAsync();
        const order = ({
            takerAddress: constants.NULL_ADDRESS,
            senderAddress: constants.NULL_ADDRESS,
            expirationTimeSeconds: new BigNumber(currentBlockTimestamp).plus(fifteenMinutesInSeconds),
            salt: generatePseudoRandomSalt(),
            ...this._defaultOrderParams,
            ...customOrderParams,
        } as any) as Order;
        const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
        const signature = signingUtils.signMessage(orderHashBuff, this._privateKey, signatureType);
        const signedOrder = {
            ...order,
            signature: `0x${signature.toString('hex')}`,
        };
        return signedOrder;
    }
}
github 0xProject / 0x-monorepo / contracts / test-utils / src / transaction_factory.ts View on Github external
public async newSignedTransactionAsync(
        customTransactionParams: Partial,
        signatureType: SignatureType = SignatureType.EthSign,
    ): Promise {
        if (customTransactionParams.data === undefined) {
            throw new Error('Error: ZeroExTransaction data field must be supplied');
        }
        const tenMinutesInSeconds = 10 * 60;
        const currentBlockTimestamp = await getLatestBlockTimestampAsync();
        const salt = generatePseudoRandomSalt();
        const signerAddress = `0x${this._signerBuff.toString('hex')}`;
        const transaction = {
            salt,
            signerAddress,
            data: customTransactionParams.data,
            expirationTimeSeconds: new BigNumber(currentBlockTimestamp).plus(tenMinutesInSeconds),
            gasPrice: new BigNumber(constants.DEFAULT_GAS_PRICE),
            domain: {
                verifyingContract: this._exchangeAddress,
                chainId: this._chainId,
            },
            ...customTransactionParams,
        };

        const transactionHashBuffer = transactionHashUtils.getTransactionHashBuffer(transaction);
        const signature = signingUtils.signMessage(transactionHashBuffer, this._privateKey, signatureType);
github 0xProject / 0x-monorepo / contracts / test-utils / src / order_utils.ts View on Github external
generatePseudoRandomOrderHash(): string {
        const randomBigNum = generatePseudoRandomSalt();
        const randomBuff = crypto.solSHA3([randomBigNum]);
        const randomHash = `0x${randomBuff.toString('hex')}`;
        return randomHash;
    },
};
github 0xProject / 0x-monorepo / contracts / coordinator / src / client / index.ts View on Github external
private async _generateSignedZeroExTransactionAsync(
        data: string,
        signerAddress: string,
        gasPrice?: BigNumber | string | number,
    ): Promise {
        const transaction: ZeroExTransaction = {
            salt: generatePseudoRandomSalt(),
            signerAddress,
            data,
            domain: {
                verifyingContract: this.exchangeAddress,
                chainId: await this._web3Wrapper.getChainIdAsync(),
            },
            expirationTimeSeconds: new BigNumber(
                Math.floor(Date.now() / 1000) +
                    DEFAULT_APPROVAL_EXPIRATION_TIME_SECONDS -
                    DEFAULT_EXPIRATION_TIME_BUFFER_SECONDS,
            ),
            gasPrice: gasPrice ? new BigNumber(gasPrice) : new BigNumber(1),
        };
        const signedZrxTx = await signatureUtils.ecSignTransactionAsync(
            this._web3Wrapper.getProvider(),
            transaction,
github 0xProject / 0x-monorepo / packages / asset-swapper / src / utils / market_operation_utils / create_order.ts View on Github external
makerAssetAmount: BigNumber,
    takerAssetAmount: BigNumber,
    slippage: number,
    isBuy: boolean = false,
): CommonOrderFields {
    const makerAssetAmountAdjustedWithSlippage = isBuy
        ? makerAssetAmount
        : makerAssetAmount.times(1 - slippage).integerValue(BigNumber.ROUND_DOWN);
    const takerAssetAmountAdjustedWithSlippage = isBuy
        ? takerAssetAmount.times(slippage + 1).integerValue(BigNumber.ROUND_UP)
        : takerAssetAmount;
    return {
        takerAddress: NULL_ADDRESS,
        senderAddress: NULL_ADDRESS,
        feeRecipientAddress: NULL_ADDRESS,
        salt: generatePseudoRandomSalt(),
        expirationTimeSeconds: INFINITE_TIMESTAMP_SEC,
        makerFeeAssetData: NULL_BYTES,
        takerFeeAssetData: NULL_BYTES,
        makerFee: ZERO_AMOUNT,
        takerFee: ZERO_AMOUNT,
        makerAssetAmount: makerAssetAmountAdjustedWithSlippage,
        fillableMakerAssetAmount: makerAssetAmountAdjustedWithSlippage,
        takerAssetAmount: takerAssetAmountAdjustedWithSlippage,
        fillableTakerAssetAmount: takerAssetAmountAdjustedWithSlippage,
        fillableTakerFeeAmount: ZERO_AMOUNT,
        signature: WALLET_SIGNATURE,
        ...orderDomain,
    };
}
github ethfinex / efx-api-node / src / api / contract / create_order.js View on Github external
takerAddress: '0x0000000000000000000000000000000000000000',

    feeRecipientAddress: efx.config['0x'].ethfinexAddress.toLowerCase(),
    senderAddress: efx.config['0x'].ethfinexAddress.toLowerCase(),

    makerAssetAmount: sellAmount,

    takerAssetAmount: buyAmount,

    makerFee: new BigNumber(0),

    takerFee: new BigNumber(0),

    expirationTimeSeconds: new BigNumber(expiration),

    salt: generatePseudoRandomSalt(),

    makerAssetData: assetDataUtils.encodeERC20AssetData(sellCurrency.wrapperAddress.toLowerCase()),

    takerAssetData: assetDataUtils.encodeERC20AssetData(buyCurrency.wrapperAddress.toLowerCase()),

    exchangeAddress: efx.config['0x'].exchangeAddress.toLowerCase()
  }

  return order
}