How to use the ethereum-types.BlockParamLiteral.Latest function in ethereum-types

To help you get started, we’ve selected a few ethereum-types 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 / order-watcher / src / order_watcher / event_watcher.ts View on Github external
private async _blockstreamGetLatestBlockOrNullAsync(): Promise {
        const shouldIncludeTransactionData = false;
        const blockOrNull = await this._web3Wrapper.sendRawPayloadAsync({
            method: 'eth_getBlockByNumber',
            params: [BlockParamLiteral.Latest, shouldIncludeTransactionData],
        });
        return blockOrNull;
    }
    // This method only exists in order to comply with the expected interface of Blockstream's constructor
github 0xProject / 0x-monorepo / packages / pipeline / src / data_sources / etherscan / index.ts View on Github external
public async getContractEventsAsync(
        contractAddress: string,
        fromBlock: BlockParam = BlockParamLiteral.Earliest,
        toBlock: BlockParam = BlockParamLiteral.Latest,
    ): Promise {
        const fullURL = `${ETHERSCAN_URL}?module=logs&action=getLogs&address=${contractAddress}&fromBlock=${fromBlock}&toBlock=${toBlock}&apikey=${
            this._apiKey
        }`;
        const resp = await axios.get(fullURL);
        // TODO(albrow): Check response code.
        return resp.data;
    }
}
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
public async validateOrderFillableOrThrowAsync(
        signedOrder: SignedOrder,
        opts: ValidateOrderFillableOpts = {},
    ): Promise {
        assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
        assert.doesConformToSchema('opts', opts, validateOrderFillableOptsSchema);

        const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
            this._erc20TokenWrapper,
            this._erc721TokenWrapper,
            BlockParamLiteral.Latest,
        );
        const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
        const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
        const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);

        let fillableTakerAssetAmount;
        const shouldValidateRemainingOrderAmountIsFillable =
            opts.validateRemainingOrderAmountIsFillable === undefined
                ? true
                : opts.validateRemainingOrderAmountIsFillable;
        if (opts.expectedFillTakerTokenAmount) {
            // If the caller has specified a taker fill amount, we use this for all validation
            fillableTakerAssetAmount = opts.expectedFillTakerTokenAmount;
        } else if (shouldValidateRemainingOrderAmountIsFillable) {
            // Default behaviour is to validate the amount left on the order.
            const filledTakerTokenAmount = await this.getFilledTakerAssetAmountAsync(
                orderHashUtils.getOrderHashHex(signedOrder),
            );
            fillableTakerAssetAmount = signedOrder.takerAssetAmount.minus(filledTakerTokenAmount);
        } else {
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / order_watcher.ts View on Github external
[orderHash: string]: SignedOrder;
}

interface OrderStateByOrderHash {
    [orderHash: string]: OrderState;
}

const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = {
    orderExpirationCheckingIntervalMs: 50,
    eventPollingIntervalMs: 200,
    expirationMarginMs: 0,
    // tslint:disable-next-line:custom-no-magic-numbers
    cleanupJobIntervalMs: 1000 * 60 * 60, // 1h
    isVerbose: true,
};
const STATE_LAYER = BlockParamLiteral.Latest;

/**
 * This class includes all the functionality related to watching a set of orders
 * for potential changes in order validity/fillability. The orderWatcher notifies
 * the subscriber of these changes so that a final decision can be made on whether
 * the order should be deemed invalid.
 */
export class OrderWatcher {
    private readonly _dependentOrderHashesTracker: DependentOrderHashesTracker;
    private readonly _orderStateByOrderHashCache: OrderStateByOrderHash = {};
    private readonly _orderByOrderHash: OrderByOrderHash = {};
    private readonly _lock = new Lock();
    private readonly _eventWatcher: EventWatcher;
    private readonly _provider: ZeroExProvider;
    private readonly _collisionResistantAbiDecoder: CollisionResistanceAbiDecoder;
    private readonly _expirationWatcher: ExpirationWatcher;
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / exchange_wrapper.ts View on Github external
public async validateOrderFillableOrThrowAsync(
        signedOrder: SignedOrder,
        opts: ValidateOrderFillableOpts = {},
    ): Promise {
        assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
        assert.doesConformToSchema('opts', opts, validateOrderFillableOptsSchema);

        const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
            this._erc20TokenWrapper,
            this._erc721TokenWrapper,
            BlockParamLiteral.Latest,
        );
        const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
        const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
        const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);

        let fillableTakerAssetAmount;
        const shouldValidateRemainingOrderAmountIsFillable =
            opts.validateRemainingOrderAmountIsFillable === undefined
                ? true
                : opts.validateRemainingOrderAmountIsFillable;
        if (opts.expectedFillTakerTokenAmount) {
            // If the caller has specified a taker fill amount, we use this for all validation
            fillableTakerAssetAmount = opts.expectedFillTakerTokenAmount;
        } else if (shouldValidateRemainingOrderAmountIsFillable) {
            // Default behaviour is to validate the amount left on the order.
            const filledTakerTokenAmount = await this.getFilledTakerAssetAmountAsync(
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers / contract_wrapper.ts View on Github external
private async _reconcileBlockAsync(): Promise {
        const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest);
        // We need to coerce to Block type cause Web3.Block includes types for mempool blocks
        if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
            // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
            await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block);
        }
    }
}
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / marshaller.ts View on Github external
marshalBlockParam(blockParam: BlockParam | string | number | undefined): string | undefined {
        if (_.isUndefined(blockParam)) {
            return BlockParamLiteral.Latest;
        }
        const encodedBlockParam = _.isNumber(blockParam) ? utils.numberToHex(blockParam) : blockParam;
        return encodedBlockParam;
    },
    /**