Code Monkey home page Code Monkey logo

sdk's People

Contributors

0xj4m35 avatar hieupnh avatar lednhatkhanh avatar ljttl3q04t avatar longngn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk's Issues

calculateSwapExactIn return wrong value

I use calculateSwapExactIn function to calculate amount out but it is returning different data than the interface.
Tried with the ADA/tMELD pair and it is displaying amount out correctly with the interface. But it doesn't need divide by 10^6

Where is it going wrong?

async function getPool(
  assetA: string,
  assetB: string
): Promise<PoolState | undefined> {
  for (let i = 1; ; i++) {
    const pools = await blockfrostAdapter.getPools({
      page: i,
    });
    if (pools.length === 0) {
      // last page
      break;
    }
    const pool = pools.find((p) => p.assetA === assetA && p.assetB === assetB);
    if (pool) {
      return pool;
    }
  }
  return;
}

async function main(): Promise<void> {
  {
    // tMELD/tMIN
    const pool = await getPool(
      "88dc7cd1c28d3a0c7ef4df99036c7c9688d309d91a1bb6fe4b08fee9744d454c44",
      "f6f49b186751e61f1fb8c64e7504e771f968cea9f4d11f5222b169e3744d494e"
    );
    if (pool) {
      const amountIn = 10_000_000n;
      const data = calculateSwapExactIn({
        amountIn,
        reserveIn: pool.reserveA,
        reserveOut: pool.reserveB,
      });
      const amountOut = new Big(data.amountOut.toString()).div(
        new Big(10).pow(6)
      );
      console.log("amountOutFull", data.amountOut.toString());
      console.log("amountOut", amountOut.toString());
      console.log("priceImpact", data.priceImpact.toString());
    }
  }
}

Output:

amountOutFull 907854
amountOut 0.907854
priceImpact 90.60331783793637772309

UI:
image

Pool.getAmountOut returns strange numbers

When I want to trade 350 ADA for C4 on miniswap it shows me that price impact is 18.72%.

But when I try to use the getAmountOut method it returns strange numbers
const pool = await this.api.getPoolById({ id: "64c84332705ee884c881219d380349b038e85afe77578ade923107ee1e36da2a"});
const { priceImpact, amountOut } = pool.getAmountOut( pool.assetA, BigInt(350), );
console.log(priceImpact.toString(), amountOut.toString());

Output for this will be "0.00002304559479445564 0"

So the question is how to calculate price impact by myself or how to use the returned numbers?

Get Pools fails to return certain tokens since recent stake key changes.

I've noticed when using getPools the pools for certain tokens are now not returned, these returned fine a few days ago, tokens affected that I am currently using in my implementation are AADA, AGIX SNEK, WMT.

When investigating further I can see that the pools are queried using the blockfrost method addressesUtxos which takes in the MAINNET Pool address in this case addr1z8snz7c4974vzdpxu65ruphl3zjdvtxw8strf2c2tmqnxz2j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq0xmsha

Which I believe is the wrong pool address now for AGIX etc, resulting in these being filtered out of the response.

When doing a plain addressesUtxos directly using the blockfrost API, with the same parameters as this adapter and then filtering on 'lovelace' and assetB of f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc53541474958 (AGIX's Asset Subject) I can see the pool address was different on the outputs for the AGIX token. I hope this helps identify pinpoint issue.

getAmountOut does not return the same amount as the UI (May not be deducting fees)

I've been testing this adapter, it works really well so far, great work guys, it's extremely valuable.
I've been tested this in conjunction with Wingriders Adapter, this actually returns the correct amount and this is mimicked in the UI.

But with this implementation, the getAmountOut function, is returning a quantity much higher than what I am getting in the UI. I assume this amount is excluding any fees, whereas the UI indicates the quantity after fees are taken.

This may be by design so may need some guidance here, @longngn, but without knowing the correct quantity or fee deduction it is difficult for me to estimate a valid swaps quantity output, because of the large difference here, I could potentially offset this with a function to minus of the fees, but I think it would be extremely valuable to indicate its intention either way in documentation or if this function is returning the incorrect value and it should be the amount after fees or something else even better, as this is preventing me from calculating amounts and submitting transactions. Or if I am missing something completely, which could also be the case.

Details.
500 ADA Swap amount, to SUNDAE returns 10613 SUNDAE from this function, however the UI returns 10329 SUNDAE.

image

const amountOfTokenReceived = pool?.getAmountOut(adaAssetId, BigInt(amountToSwap));
image

Happy to provide further details if it helps at all! :)

(Testnet) - Uncaught TypeError TypeError: utxos.filter is not a function

Firstly, I'm really excited about this integration!
When I installed this package into a blank typescript project, I am receiving the following, from using the listed example in the ReadMe.

Uncaught TypeError TypeError: utxos.filter is not a function
at getPools (/Users/username/source/personal/node-typescript-template/node_modules/@minswap/blockfrost-adapter/src/adapter.ts:34:18)
    at processTicksAndRejections (internal/process/task_queues:96:5)

https://github.com/minswap/blockfrost-adapter/blob/4f6221402b4504896f5c08eaf80541292d7753ce/src/adapter.ts#L74

Edit - Just done some digging and this only occurs when the network is set to testnet, mainnet works fine and pools are returned, I hope this helps.

Can not get pool ID

Dear,
Months ago I've used below code to get pool ID, but it seems not work recently

`async function runExample() {
while(true){
try {

for (let i = 1; ; i++) {
const pools = await api.getPools({ page: i });
if (pools.length === 0) {
// last page
break;
}
const ABPool = (pools.find(
(p) =>
p.assetA === "lovelace" &&
p.assetB ===
"279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f534e454b") //SNEK
);

console.log(ABPool);
break;

}

await delay(10000);

} catch (err) {
console.log('error', err);
}
};
};

runExample();
`

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.