Skip to main content

Class: SmartRouter

Example

 const router = new SmartRouter('abc-123-987-beef')
const {details, txn} = await router.getRouteBase(CELO, CUSD, '10000', { includeTxn: true, maxHops: 3 })
const await provider.signTransaction(txn);

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new SmartRouter(_apiKey?, _wallet?)

Parameters

NameType
_apiKey?string
_wallet?Wallet<Signer>

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:88

Properties

_apiKey

Private Optional _apiKey: string

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:88


_wallet

Private Optional _wallet: Wallet<Signer>

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:88

Methods

getRouteBase

getRouteBase(input, output, amountIn, chainId, options?): Promise<{ details?: NodeRoute ; error?: string ; expectedOut?: string ; priceImpact?: number ; routerAddress?: string ; txn?: TransactionRequest | { error: string } }>

Pings the minima service to find the most efficient trade to go from input to output.

Parameters

NameTypeDescription
inputstring | TokenToken to be traded in. Provide either the address or the Token object
outputstringToken to be traded for. Provide either the address or the Token object
amountInBigintIshTotal input amount for the trade
chainIdChainId-
options?Partial<MinimaOptions>Additional options

Returns

Promise<{ details?: NodeRoute ; error?: string ; expectedOut?: string ; priceImpact?: number ; routerAddress?: string ; txn?: TransactionRequest | { error: string } }>

Trade information, including a pre-formatted txn to sign and send to execute a trade

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:99

getRouteBase(input, output, amountIn, chainId, options?): Promise<{ details?: NodeRoute ; error?: string ; expectedOut?: TokenAmount ; priceImpact?: number ; routerAddress?: string ; txn?: TransactionRequest | { error: string } }>

Parameters

NameType
inputstring | Token
outputToken
amountInBigintIsh
chainIdChainId
options?Partial<MinimaOptions>

Returns

Promise<{ details?: NodeRoute ; error?: string ; expectedOut?: TokenAmount ; priceImpact?: number ; routerAddress?: string ; txn?: TransactionRequest | { error: string } }>

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:113


performSwap

performSwap(route, to, slippage, routerAddress): Promise<TransactionReceipt>

If a Wallet object is attached, will execute the given swal

Parameters

NameType
routeNodeRoute
tostring
slippagenumber
routerAddressstring

Returns

Promise<TransactionReceipt>

transaction receipt

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:238


formatTransaction

Static formatTransaction(route, to, slippage, routerAddress): TransactionRequest

Formats the route as a transaction to sign and execute.

Example

const { details, routerAddress } = await router.getRouteBase(
CELO,
CUSD,
"10000"
);
const transactionConfig = router.formatTransaction(
details,
wallet.address,
10,
routerAddress
);

Parameters

NameTypeDescription
routeNodeRouteRoute returned from getRouteBase
tostringRecipient address of trade
slippagenumberAllowed slippage for the trade, in bips
routerAddressstringAddress of router that will execute the trade

Returns

TransactionRequest

TransactionRequest corresponding to the given route

Defined in

packages/sdk-core/src/Routing/SmartRouter.ts:201