Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Simulate Maker transfer in order validation #1714

Merged
merged 23 commits into from
Mar 28, 2019

Conversation

dekz
Copy link
Member

@dekz dekz commented Mar 19, 2019

Description

Simulate a one sided maker transfer in order validation.

This will trigger the case where the maker has the sufficient balance and allowance, but the asset is non-tradeable. For example in a Paused contract or when the maker has not performed some action to unlock their account.

Pulled from a number of SRA endpoints and walked through the orderbooks with this change. This has flagged a few orders which are currently sitting on orderbooks which are invalid. I.e there are a few tokens where the Maker is "frozen" on live orderbooks.

By default the order.takerAddress is used to simulate the receiver from maker. With Open orderbooks this results in the NULL_ADDRESS This also has a few false positives where some ERC20 tokens cannot be transferred to the NULL_ADDRESS, e.g Bloom token.

In this case the developer is in the best position to determine an alternative address to use. The receiver address during the simulation can be set by specifying simulationTakerAddress in ValidateOrderFillableOpts. Whilst 0x could assign a non NULL_ADDRESS default, this is unlikely to be fool proof across ALL token standards and networks.

Testing instructions

Pulled from a number of SRA endpoints and walked through the orderbooks with this change.

import { HttpClient, SignedOrder } from '@0x/connect';
import { ContractWrappers } from '@0x/contract-wrappers';
import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { providerUtils } from '@0x/utils';

const uri = 'https://api.radarrelay.com/0x/v2/';

const client = new HttpClient(uri);
(async () => {
    const response = await client.getAssetPairsAsync();
    const orders: SignedOrder[] = [];
    for (const record of response.records) {
        const { assetDataA, assetDataB } = record;
        const orderBook = await client.getOrderbookAsync({
            baseAssetData: assetDataA.assetData,
            quoteAssetData: assetDataB.assetData,
        });
        for (const order of orderBook.asks.records) {
            orders.push(order.order);
        }
        for (const order of orderBook.bids.records) {
            orders.push(order.order);
        }
    }
    const rpcSubprovider = new RPCSubprovider('https://mainnet.infura.io');
    const provider = new Web3ProviderEngine();
    provider.addProvider(rpcSubprovider);
    providerUtils.startProviderEngine(provider);
    const contractWrappers = new ContractWrappers(provider, { networkId: 1 });
    for (const order of orders) {
        try {
            await contractWrappers.exchange.validateOrderFillableOrThrowAsync(order, {
                validateRemainingOrderAmountIsFillable: false,
            });
        } catch (e) {
            console.log(e.message);
            console.log(order);
        }
    }
    console.log(orders.length);
})();

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@dekz dekz changed the title Simulate Maker transfer in order validation [WIP]Simulate Maker transfer in order validation Mar 20, 2019
@0xProject 0xProject deleted a comment from coveralls Mar 20, 2019
@dekz dekz requested review from abandeali1 and hysz as code owners March 20, 2019 16:17
@0xProject 0xProject deleted a comment from coveralls Mar 20, 2019
@dekz dekz requested a review from feuGeneA as a code owner March 21, 2019 11:05
@dekz dekz changed the title [WIP]Simulate Maker transfer in order validation Simulate Maker transfer in order validation Mar 21, 2019
@dekz dekz force-pushed the feature/order-utils/one-sided-transfer-validation branch from 7556438 to 33f9f0a Compare March 21, 2019 13:22
@dekz dekz force-pushed the feature/order-utils/one-sided-transfer-validation branch from 13ccc03 to d295421 Compare March 21, 2019 16:27
@dekz dekz force-pushed the feature/order-utils/one-sided-transfer-validation branch from 7e35108 to 1144770 Compare March 26, 2019 10:48
@dekz dekz force-pushed the feature/order-utils/one-sided-transfer-validation branch from 1144770 to 1f2214f Compare March 28, 2019 13:20
@dekz dekz merged commit f9921d2 into development Mar 28, 2019
@dekz dekz deleted the feature/order-utils/one-sided-transfer-validation branch March 28, 2019 14:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants