@moromoro/moro-sdk
v1.1.0
Published
- Update src/config.ts to add more tables
Readme
Moromoro SDK
An JavaScript/TypeScript SDK library for querying trading quotes from Moromoro platform. In order to begin trading on Moromoro, we need the trading path that provide the best rate. The SDK help finding the path with ease!
For more information, check out our documentation here: https://docs.moro.exchange
Installation
# For NPM
npm install @moromoro/moro-sdk
# For Yarn
yarn add @moromoro/moro-sdkExample
Here is the example if JavaScript code for querying best rate and perform a simple swap via Moromoro SDK.
// npm install @moromoro/moro-sdk ethers
const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')
// MoroRouter_2_0.abi.json can be found here:
// https://hyperevmscan.io/address/0x3195cAd938d417703312246e376342C553FD4cC2#code
const moroRouterAbi = require('./MoroRouter_2_0.abi.json')
const MORO_ROUTER_ADDRESS = '0x3195cAd938d417703312246e376342C553FD4cC2'
const src = '0x5555555555555555555555555555555555555555' // source Token Address: HYPE
const dest = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb' // destination Token Address: USDT0
const amountIn = ethers.utils.parseUnits('10', 18) // 10 HYPE in BigNumber
const gasFee = ethers.BigNumber.from('5000000000') // default HyperEVM gas fee for rate calculation
const options = { enableSplit: false } // calculate without using split trades
// initialize provider, requires version of ether.js >= 5.4.0
const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
async function getQuote() {
// initialize the moro client
const moroClient = new MoroBestRate(provider, 'hyperevm')
// get the quote detail with moro client
const quote = await moroClient.getQuote(src, dest, amountIn, gasFee, options)
console.log('quote:', quote)
return quote
}
async function swap(quote) {
// add the acceptable slippage of 1% to amountOut
// since the actual amount can be lower or higher.
const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)
// Get the signer with private key
// For using with Metamask, see: https://docs.ethers.io/v5/getting-started/#getting-started--connecting
const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
const moroContract = new ethers.Contract(MORO_ROUTER_ADDRESS, moroRouterAbi, signer)
// send a swap transaction to moro contract
const swapTx = await moroContract.swap(
quote.swapAddress,
quote.data,
quote.depositAddress,
src,
amountIn,
dest,
minAmountOut,
signer.address, // dest token receiver
0, // Partner ID for profit sharing, default to 0
0) // metadata, reserved for future use
console.log(`swap tx successfully submitted, tx hash: ${swapTx.hash}`)
}
getQuote().then(quote => swap(quote))