Giter Site home page Giter Site logo

Comments (4)

ItsDaveB avatar ItsDaveB commented on August 22, 2024

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.

ItsDaveB avatar ItsDaveB commented on August 22, 2024

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.

ItsDaveB avatar ItsDaveB commented on August 22, 2024

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.

ItsDaveB avatar ItsDaveB commented on August 22, 2024
// 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.