SDK
We have open-sourced the SDK for the swap functionality in Mimo V3.
You can check it out here:
API (Recommended)
curl 'https://swap-api.mimo.exchange/api/trade' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json' \
--data-raw '{"chainId":4689,"protocols":"v2,v3,mixed","token0":{"address":"IOTX","decimals":18},"token1":{"address":"0x97e6c48867fdc391a8dfe9d169ecd005d1d90283","decimals":18},"recipient":"0x7890256910829ECc1CDD50AB50B1E92EC90A28da","amount":"10000000000000000000","slippage":{"numerator":50,"denominator":10000},"tradeType":"EXACT_INPUT"}'
repo: https://github.com/mimoprotocol/mimo-api the input and output params please refer uniswap sdk
chainId
Integer
The ID of the blockchain network (e.g., Binance Smart Chain, IoTeX).
Yes
4689
protocols
String
Comma-separated list of supported protocols. Valid options are v2
, v3
, and mixed
.
Yes
"v2,v3,mixed"
token0
Object
Details of the first token in the trade.
Yes
{"address":"IOTX","decimals":18}
address
String
Address of the first token.
Yes
"IOTX"
decimals
Integer
Number of decimal places for the token.
Yes
18
token1
Object
Details of the second token in the trade.
Yes
{"address":"0x97e6c48867fdc391a8dfe9d169ecd005d1d90283","decimals":18}
address
String
Address of the second token.
Yes
"0x97e6c48867fdc391a8dfe9d169ecd005d1d90283"
decimals
Integer
Number of decimal places for the token.
Yes
18
recipient
String
The wallet address that will receive the output token.
Yes
"0x7890256910829ECc1CDD50AB50B1E92EC90A28da"
amount
String
The amount of the input token ( token0
) to exchange. Represented as a string to handle large numbers.
Yes
"10000000000000000000"
slippage
Object
Allowed slippage tolerance. Expressed as a fraction.
Yes
{"numerator":50,"denominator":10000}
numerator
Integer
The numerator of the slippage fraction.
Yes
50
denominator
Integer
The denominator of the slippage fraction.
Yes
10000
tradeType
String
The type of trade. Typically "EXACT_INPUT"
.
Yes
"EXACT_INPUT"
Sdk
npm install @dappworks/mimoswap-sdk
sdk repo: https://github.com/mimoprotocol/mimoswap-sdk
import dotenv from 'dotenv';
dotenv.config();
import { parseUnits } from 'viem';
import {
ChainId,
Token,
CurrencyAmount,
TradeType,
Percent,
} from '../src/sdk-core';
import { JsonRpcProvider } from '@ethersproject/providers';
import {
AlphaRouter,
ID_TO_CHAIN_ID,
ID_TO_PROVIDER,
// NATIVE_NAMES_BY_ID,
// nativeOnChain,
SwapType,
} from '@dappworks/mimoswap-sdk';
import _ from 'lodash';
// const getCurrency = ({
// chainId,
// tokenStr,
// decimals,
// }: {
// chainId: number;
// tokenStr: string;
// decimals: number;
// }) => {
// const currency = NATIVE_NAMES_BY_ID[chainId]!.includes(tokenStr)
// ? nativeOnChain(chainId)
// : new Token(chainId, tokenStr, decimals);
// return currency;
// };
describe('IOTEX Trade Test', () => {
const chainId = ID_TO_CHAIN_ID(ChainId.IOTEX);
const chainProvider = ID_TO_PROVIDER(chainId);
const provider = new JsonRpcProvider(chainProvider, chainId);
// it(`trade-wiotx-vita-v3`, async () => {
// const t1 = new Token(
// chainId,
// '0xa00744882684c3e4747faefd68d283ea44099d03',
// 18
// );
// const t2 = new Token(
// chainId,
// '0xb8744ae4032be5e5ef9fab94ee9c3bf38d5d2ae0',
// 18
// );
// const router = new AlphaRouter({
// chainId,
// provider,
// });
// const route = await router.route(
// CurrencyAmount.fromRawAmount(t1, parseUnits('10', 18).toString()),
// t2,
// TradeType.EXACT_INPUT,
// {
// recipient: '0x0000000000000000000000000000000000000000',
// slippageTolerance: new Percent(1000, 10_000),
// deadline: Math.floor(Date.now() / 1000 + 1800),
// type: SwapType.SWAP_ROUTER_02,
// },
// {
// protocols: [Protocol.V3],
// }
// );
// console.log('route=>', route);
// expect(route.swapRoute).not.toBeNull();
// });
// it(`trade-wiotx-usdc.e`, async () => {
// const t1 = new Token(
// chainId,
// '0xa00744882684c3e4747faefd68d283ea44099d03',
// 18
// );
// const t2 = new Token(
// chainId,
// '0xcdf79194c6c285077a58da47641d4dbe51f63542',
// 6
// );
// const router = new AlphaRouter({
// chainId,
// provider,
// });
// const route = await router.route(
// CurrencyAmount.fromRawAmount(t1, parseUnits('1', 18).toString()),
// t2,
// TradeType.EXACT_INPUT,
// {
// recipient: '0x0000000000000000000000000000000000000000',
// slippageTolerance: new Percent(1000, 10_000),
// deadline: Math.floor(Date.now() / 1000 + 1800),
// type: SwapType.SWAP_ROUTER_02,
// },
// {
// protocols: [Protocol.V3],
// }
// );
// console.log('route=>', route);
// expect(route.swapRoute).not.toBeNull();
// });
// it(`trade-usdt-wen-mixed`, async () => {
// const t1 = new Token(
// chainId,
// '0x6fbcdc1169b5130c59e72e51ed68a84841c98cd1',
// 6
// );
// const t2 = new Token(
// chainId,
// '0x6c0bf4b53696b5434a0d21c7d13aa3cbf754913e',
// 6
// );
// const router = new AlphaRouter({
// chainId,
// provider,
// });
// const route = await router.route(
// CurrencyAmount.fromRawAmount(t1, parseUnits('1', 6).toString()),
// t2,
// TradeType.EXACT_INPUT,
// {
// recipient: '0x0000000000000000000000000000000000000000',
// slippageTolerance: new Percent(1000, 10_000),
// // deadline: Math.floor(Date.now() / 1000 + 1800),
// type: SwapType.UNIVERSAL_ROUTER,
// },
// {
// protocols: [Protocol.MIXED],
// }
// );
// console.log('route=>', route);
// console.log(
// 'tokenPath=>',
// JSON.stringify(route?.swapRoute?.route?.[0]?.tokenPath, null, 2)
// );
// expect(route.swapRoute).not.toBeNull();
// });
it(`trade-dwin-dimo-mixed`, async () => {
const t1 = new Token(
chainId,
'0xa7108637552cec7e8c2dd08a9cd995caff8b4280',
18
);
const t2 = new Token(
chainId,
'0x61db9b084326d2251ccb0252c18fd9b0e887ca4f',
18
);
const router = new AlphaRouter({
chainId,
provider,
});
const route = await router.route(
CurrencyAmount.fromRawAmount(t1, parseUnits('1', 6).toString()),
t2,
TradeType.EXACT_INPUT,
{
recipient: '0x0000000000000000000000000000000000000000',
slippageTolerance: new Percent(1000, 10_000),
// deadline: Math.floor(Date.now() / 1000 + 1800),
type: SwapType.UNIVERSAL_ROUTER,
},
{
protocols: [Protocol.MIXED],
}
);
console.log('route=>', route);
console.log(
'tokenPath=>',
JSON.stringify(route?.swapRoute?.route?.[0]?.tokenPath, null, 2)
);
expect(route.swapRoute).not.toBeNull();
});
// it(`trade-iotx-ioUSD-v3`, async () => {
// const t1 = getCurrency({
// chainId,
// tokenStr: 'IOTX',
// decimals: 18,
// });
// const t2 = new Token(
// chainId,
// '0xa1a1531f6ae90192edcc32e9f38e98f303708144',
// 18
// );
// const router = new AlphaRouter({
// chainId,
// provider,
// });
// const route = await router.route(
// CurrencyAmount.fromRawAmount(t1, parseUnits('100000', 18).toString()),
// t2,
// TradeType.EXACT_INPUT,
// {
// recipient: '0x0000000000000000000000000000000000000000',
// slippageTolerance: new Percent(1000, 10_000),
// // deadline: Math.floor(Date.now() / 1000 + 1800),
// type: SwapType.UNIVERSAL_ROUTER,
// },
// {
// protocols: [Protocol.V3],
// }
// );
// console.log('route=>', route);
// console.log('tokenPath=>', JSON.stringify(route?.swapRoute?.route));
// expect(route.swapRoute).not.toBeNull();
// });
// it(`trade-wiotx-wen-EXACT_OUTPUT`, async () => {
// const tokenIn = new Token(
// chainId,
// '0xa00744882684c3e4747faefd68d283ea44099d03',
// 18
// );
// const tokenOut = new Token(
// chainId,
// '0x6c0bf4b53696b5434a0d21c7d13aa3cbf754913e',
// 18
// );
// const router = new AlphaRouter({
// chainId,
// provider,
// });
// const route = await router.route(
// CurrencyAmount.fromRawAmount(tokenOut, '10000000000000000000'),
// tokenIn,
// TradeType.EXACT_OUTPUT,
// {
// recipient: '0x0000000000000000000000000000000000000000',
// slippageTolerance: new Percent(1000, 10_000),
// // deadline: Math.floor(Date.now() / 1000 + 1800),
// type: SwapType.UNIVERSAL_ROUTER,
// },
// {
// protocols: [Protocol.V3],
// }
// );
// console.log('route=>', route);
// // expect(route.swapRoute).not.toBeNull();
// });
});
Last updated
Was this helpful?