Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@many-things/osmosis-router
Advanced tools
@many-things/osmosis-router
Minimal SDK for Osmosis Swap Estimation
yarn add @many-things/osmosis-router
# or use NPM
npm install @many-things/osmosis-router
USDC
(axlUSDC
) as tokenOutCurrency
)First, Define Currencies for your in/out tokens.
import { Currency } from '@keplr-wallet/types';
const tokenInCurrency: Currency = {
coinDenom: 'OSMO',
coinMinimalDenom: 'uosmo',
coinDecimals: 6,
};
const tokenOutCurrency: Currency = {
coinDenom: 'USDC',
coinMinimalDenom:
'ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858',
coinDecimals: 6,
};
And just call estimateSwap
with the params.
Works like magic!
import { estimateSwap } from '@many-things/osmosis-router';
// 1 OSMO = 0.899660 USDC
const amount: string = (1 * 10 ** 6).toString();
estimateSwap(tokenInCurrency, tokenOutCurrency, amount); // CoinPretty (0.899660 USDC)
Note
estimateSwap
does the following:
- Update pools in Osmosis
- Get Routes (in -> out)
- Estimate swap using resolved route
The following is the current code for
estimateSwap
. You can use build your own custom implementation for efficiency, if you're estimating multiple times(e.g. using pools that are already fetched/cached).
import { type Pool } from '@many-things/osmosis-router';
import Axios, { AxiosInstance } from 'axios';
const defaultInstance = Axios.create({
baseURL: OSMOSIS_CHAIN_REST,
});
export const estimateSwap = async (
tokenInCurrency: Currency,
tokenOutCurrency: Currency,
amount: string,
pools?: Pool[],
instance: AxiosInstance = defaultInstance,
): Promise<CoinPretty> => {
const { getOsmosisPools, getOsmosisRoutes, getOsmosisSwapEstimation } =
await import('@many-things/osmosis-router');
if (!pools) {
pools = await getOsmosisPools({
instance,
}).catch((e) => {
console.log(e);
return [];
});
}
const routes = getOsmosisRoutes({
tokenInCurrency,
tokenOutCurrency,
amount,
pools,
});
const tokenOut = getOsmosisSwapEstimation({
tokenInCurrency,
tokenOutCurrency,
amount,
pools,
routes,
});
return tokenOut;
};
FAQs
Minimal SDK for Osmosis Swap Estimation
The npm package @many-things/osmosis-router receives a total of 3 weekly downloads. As such, @many-things/osmosis-router popularity was classified as not popular.
We found that @many-things/osmosis-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.