Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Minswap DEX transaction and DEX Utility calculation #7

Merged
merged 24 commits into from
Aug 2, 2023

Conversation

ljttl3q04t
Copy link
Contributor

@ljttl3q04t ljttl3q04t commented Apr 28, 2023

Testcases:

  • Swap Exact In
  • Swap Exact Out
  • Limit Order
  • Deposit
  • Withdraw
  • Zap In
  • Cancel Order

@CreatureGeorge
Copy link

Have you had any success? Even after submitting an order and calling the graphql endpoint logTx (which was only endpoint I was able to see that is called after a tx is submitted), I haven't had any success with the order being batched successfully.

@TwilightDuck
Copy link

Have you had any success? Even after submitting an order and calling the graphql endpoint logTx (which was only endpoint I was able to see that is called after a tx is submitted), I haven't had any success with the order being batched successfully.

I've actually had great success with this. No problems thus far.

@CreatureGeorge
Copy link

Just looked my tx closer and for my script I was attaching the datum as inline. Works now after removing that.

Copy link

@ItsDaveB ItsDaveB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great for me, super useful thanks!

@h2physics h2physics changed the title add minswap dex transaction Add Minswap DEX transaction and DEX Utility calculation Jul 25, 2023
@h2physics h2physics requested a review from longngn July 25, 2023 08:11
longngn added 2 commits July 26, 2023 16:08
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
longngn and others added 11 commits July 27, 2023 15:40
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
longngn added 2 commits July 31, 2023 18:38
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Comment on lines +69 to +92
async function getPoolById(
network: Network,
blockfrostAdapter: BlockfrostAdapter,
poolId: string
): Promise<{ poolState: PoolState; poolDatum: PoolDatum }> {
const pool = await blockfrostAdapter.getPoolById({
id: poolId,
});
if (!pool) {
throw new Error(`Not found PoolState of ID: ${poolId}`);
}

const rawRoolDatum = await blockfrostAdapter.getDatumByDatumHash(
pool.datumHash
);
const poolDatum = PoolDatum.fromPlutusData(
network === "Mainnet" ? NetworkId.MAINNET : NetworkId.TESTNET,
Data.from(rawRoolDatum) as Constr<Data>
);
return {
poolState: pool,
poolDatum: poolDatum,
};
}
Copy link

@theeldermillenial theeldermillenial Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl; dr

On preprod testnet, the total liquidity acquired from this poolDatum seems to be incorrect. Can you confirm that the getPoolById info sent into the calculateZapIn is giving a correct estimate?

Example

When accessing the ADA/MIN datum, I get a total liquidity value of 262828735.

When I use this number for calculating the Zap In expected LP with 50 ADA, I get 237,556. That seems correct, but when I submit the zap in order I get back 2,143,510 LP, an order of magnitude difference.

When I look at the datum of the order contract, it's telling me a completely different number for the total liquidity: 8,197,014.

Looking at the datum more closely, it looks like it is operating as a pool with ADA on one side and LP on the other according to the assets in the datum.

It seems to me that the datum is either incorrect for the ADA/MIN pool or a different address needs to be used for the datum. Or theres a bug in how the order contract is storing datum in the pool UTxO.

My main concern is that if the total liquidity is incorrect here, then I won't be able to properly calculate how much I should expect to receive. I could always set the expected liquidity to 1 to ensure my transaction goes thorugh, but I don't like it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heres the completed order transaction for reference:
https://preprod.cardanoscan.io/transaction/75c0646d5879bc3a4318eb4b36582c8b1a6180c2125e12c27fb6cc8d3fc019ce?tab=utxo

Ignore what I have in the datum with an 8 in the minimum receive part. I found a bug in my code that inverted a set of numbers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this also reminds me...

The total_liquidity in the pool datum seems to roughly match the quantity returned when you get the asset info from the asset endpoing:
https://docs.blockfrost.io/#tag/Cardano-Assets/paths/~1assets~1{asset}/get

However, the datum in the pool UTxO doesn't match it at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theeldermillenial To avoid empty pool, in creating pool transaction, we burned 10 LP Asset of Pool Creator. So the Total Liquidity Pool in the datum is always larger than quantity of LP Asset 10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h2physics That accounts for 10LP. What about the order of magnitude difference in LP?
262,828,735 is a big difference compared to 8,197,014.

That seems to be leading to an order of magnitude difference in the estimated zap in deposit.

@longngn longngn merged commit 573ba41 into main Aug 2, 2023
@longngn longngn deleted the dungph/minswap-dex-tx branch August 2, 2023 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants