Orchestration

Orchestration functions are plain-english wrappers for the function defined in Data and Computation.

Functions suffixed with WithData are synchronous, and require token reserves to be passed in as arguments. Functions without the suffix are asychronous, and require token addresses to be passed in as arguments.

tradeExactEthForTokensWithData

The function facilitates trading an exact amount of ETH for a specified token.

Function Signature

export function tradeExactEthForTokensWithData(reserves: OptionalReserves, ethAmount: BigNumberish): TradeDetails

Input Parameters

ParameterTypeDescription
reservesOptionalReservesReserves data for the output token.
ethAmountBigNumberishThe input amount of ETH.

Example Usage

const tradeDetails: TradeDetails = tradeExactEthForTokensWithData(reserves, '1000000000000000000')

tradeExactEthForTokens

The function facilitates trading an exact amount of ETH for a specified token.

Function Signature

export async function tradeExactEthForTokens(
tokenAddress: string,
ethAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressstringAddress of output token.
ethAmountBigNumberishThe input amount of ETH.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeExactEthForTokens(tokenAddress, '1000000000000000000')

tradeEthForExactTokensWithData

The function facilitates trading ETH for an exact amount of a specified token.

Function Signature

export function tradeEthForExactTokensWithData(reserves: OptionalReserves, tokenAmount: BigNumberish): TradeDetails

Input Parameters

ParameterTypeDescription
reservesOptionalReservesReserves data for the output token.
tokenAmountBigNumberishThe output amount of tokens.

Example Usage

const tradeDetails: TradeDetails = tradeEthForExactTokensWithData(reserves, '1000000000000000000')

tradeEthForExactTokens

The function facilitates trading ETH for an exact amount of a specified token.

Function Signature

export async function tradeEthForExactTokens(
tokenAddress: string,
tokenAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressstringAddress of output token.
tokenAmountBigNumberishThe output amount of tokens.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeEthForExactTokens(tokenAddress, '1000000000000000000')

tradeExactTokensForEthWithData

The function facilitates trading an exact amount of a specified token for ETH.

Function Signature

export function tradeExactTokensForEthWithData(reserves: OptionalReserves, tokenAmount: BigNumberish): TradeDetails

Input Parameters

ParameterTypeDescription
reservesOptionalReservesReserves data for the input token.
tokenAmountBigNumberishThe input amount of tokens.

Example Usage

const tradeDetails: TradeDetails = tradeExactTokensForEthWithData(reserves, '1000000000000000000')

tradeExactTokensForEth

The function facilitates trading an exact amount of a specified token for ETH.

Function Signature

export async function tradeExactTokensForEth(
tokenAddress: string,
tokenAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressstringAddress of input token.
tokenAmountBigNumberishThe input amount of tokens.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeExactTokensForEth(tokenAddress, '1000000000000000000')

tradeTokensForExactEthWithData

The function facilitates trading a specified token for an exact amount of ETH.

Function Signature

export function tradeTokensForExactEthWithData(reserves: OptionalReserves, ethAmount: BigNumberish): TradeDetails

Input Parameters

ParameterTypeDescription
reservesOptionalReservesReserves data for the input token.
ethAmountBigNumberishThe outpute amount of ETH.

Example Usage

const tradeDetails: TradeDetails = tradeTokensForExactEthWithData(reserves, '1000000000000000000')

tradeTokensForExactEth

The function facilitates trading a specified token for an exact amount of ETH.

Function Signature

export async function tradeTokensForExactEth(
tokenAddress: string,
ethAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressstringAddress of input token.
ethAmountBigNumberishThe output amount of ETH.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeTokensForExactEth(tokenAddress, '1000000000000000000')

tradeExactTokensForTokensWithData

The function facilitates trading an exact amount of a specified token for another token.

Function Signature

export function tradeExactTokensForTokensWithData(
reservesInput: OptionalReserves,
reservesOutput: OptionalReserves,
tokenAmount: BigNumberish
): TradeDetails

Input Parameters

ParameterTypeDescription
reservesInputOptionalReservesReserves data for the input token.
reservesOutputOptionalReservesReserves data for the output token.
tokenAmountBigNumberishThe input amount of tokens.

Example Usage

const tradeDetails: TradeDetails = tradeExactTokensForTokensWithData(
reservesInput,
reservesOutput,
'1000000000000000000'
)

tradeExactTokensForTokens

The function facilitates trading an exact amount of a specified token for another token.

Function Signature

export async function tradeExactTokensForTokens(
tokenAddressInput: string,
tokenAddressOutput: string,
tokenAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressInputstringAddress of input token.
tokenAddressOutputstringAddress of output token.
tokenAmountBigNumberishThe input amount of tokens.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeExactTokensForTokens(
tokenAddressInput,
tokenAddressOutput,
'1000000000000000000'
)

tradeTokensForExactTokensWithData

The function facilitates trading a specified token for an exact amount of another token.

Function Signature

export function tradeTokensForExactTokensWithData(
reservesInput: OptionalReserves,
reservesOutput: OptionalReserves,
tokenAmount: BigNumberish
): TradeDetails

Input Parameters

ParameterTypeDescription
reservesInputOptionalReservesReserves data for the input token.
reservesOutputOptionalReservesReserves data for the output token.
tokenAmountBigNumberishThe output amount of tokens.

Example Usage

const tradeDetails: TradeDetails = tradeTokensForExactTokensWithData(
reservesInput,
reservesOutput,
'1000000000000000000'
)

tradeTokensForExactTokens

The function facilitates trading an exact amount of a specified token for another token.

Function Signature

export async function tradeTokensForExactTokens(
tokenAddressInput: string,
tokenAddressOutput: string,
tokenAmount: BigNumberish,
chainIdOrProvider?: ChainIdOrProvider
): Promise<TradeDetails>

Input Parameters

ParameterTypeDescription
tokenAddressInputstringAddress of input token.
tokenAddressOutputstringAddress of output token.
tokenAmountBigNumberishThe output amount of tokens.
chainIdOrProvider?ChainIdOrProviderA supported chain id (1, 3, 4, or 42), or an underlying web3 provider connected to a chain with a supported chain id.

Example Usage

const tradeDetails: TradeDetails = await tradeTokensForExactTokens(
tokenAddressInput,
tokenAddressOutput,
'1000000000000000000'
)