Comments (4)
I have produced a replication example based on the current example implementation in the readme below. I was doing this slightly differently by storing the pools in json after the initial response, so wanted to test it again without that additional logic. As below.
for (let i = 1; ; i++) {
const pools = await this.api.getPools({ page: i });
if (pools.length === 0) {
// last page
break;
}
const sundaePool = pools.find((p) => p.assetA === 'lovelace' && p.assetB === '9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145');
if (sundaePool) {
const [a, b] = await this.api.getPoolPrice({ pool: sundaePool });
var amounts = sundaePool.getAmountOut('lovelace', BigInt(500));
// amounts.amoutOut is 10613n
console.log(ADA/SUNDAE price: ${a.toString()}; SUNDAE/ADA price: ${b.toString()}
);
// we can later use this ID to call getPoolById
console.log(ADA/MIN pool ID: ${sundaePool.id}
);
break;
}
}
from sdk.
This could also be related to the above, doing a SWAP from ADA to AGIX, again 500 ADA Quantity, the getAmountOut
function is actually returning the same amount as the UI interestingly, however as it returns as a bigint without precision like 71874n
when formatting using the tokens precision, AGIX being 6 decimals. I receive an incorrect value, I think there it should be 2 decimals to match the UI's figure of 71.87
precision, but not sure if this is 2 decimals across all tokens?
from sdk.
I have managed to resolve this issue last night, it is actually a non issue after I investigated further and more down to how I was formatting and passing in the amounts, especially when each token varied with its precision but the ADA input amount also needed its 6 decimal precision but represented as a bigint, without this the value returned was completely different, especially tokens with larger precision which also needed converting back, I will add my findings below with an example in hope it helps others when using this package.
from sdk.
// ADA / TOKEN
var amountWithPrecision = ethers.parseUnits(amountToSwap?.toString(), 6);
const amountOfTokenReceived = pool?.getAmountOut(adaAssetId, amountWithPrecision);
const amountOfTokenReceivedWithPrecision = ethers.formatUnits(amountOfTokenReceived?.amountOut ?? 0, tokenIdToFetch.decimals);
// TOKEN / ADA
var amountWithPrecision = ethers.parseUnits(amountToSwap?.toString(), tokenIdToFetch?.decimals);
const amountOfAdaReceived = pool?.getAmountOut(tokenIdToFetch?.assetSubject ?? '', amountWithPrecision);
const amountOfAdaReceivedWithPrecision = ethers.formatUnits(amountOfAdaReceived?.amountOut ?? '', 6);
from sdk.
Related Issues (13)
- (Testnet) - Uncaught TypeError TypeError: utxos.filter is not a function
- Get Pools fails to return certain tokens since recent stake key changes. HOT 7
- Pool.getAmountOut returns strange numbers HOT 2
- Can not get pool ID HOT 1
- Get pools without passing address HOT 1
- The requested module does not provide an export named 'BlockfrostAdapter' in Nuxt3 HOT 1
- Finding a specific pool requires massive amount of requests to Blockfrost HOT 1
- The requested module '@minswap/sdk' does not provide an export named 'BlockfrostAdapter' HOT 1
- Cannot find module '@minswap/sdk' or its corresponding type declarations. HOT 6
- Use Provider architecture and integrate Maestro as a Provider
- calculateSwapExactIn return wrong value HOT 4
- Full V2 protocol support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.