Skip to content

Commit

Permalink
Fix: Expected LP HUGE (#96)
Browse files Browse the repository at this point in the history
* fix: expected lp too massivo

* chore: rm extra console logs
  • Loading branch information
LukasDeco authored and kilgaloon committed Aug 6, 2024
1 parent c2e201e commit a33725e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 19 additions & 5 deletions lib/client/rpc/market-clients/ammMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient {
ammAccount.quoteMint,
this.rpcProvider
);
const lpToken = await enrichTokenMetadata(
ammAccount.lpMint,
this.rpcProvider
);

const ammMintAccountSupply =
await this.rpcProvider.connection.getTokenSupply(ammAccount.lpMint);

return {
baseAmount: ammAccount.baseAmount,
quoteAmount: ammAccount.quoteAmount,
lpToken,
lpMintSupply: parseInt(ammMintAccountSupply.value.amount),
baseMint: ammAccount.baseMint,
baseToken,
Expand Down Expand Up @@ -245,16 +250,25 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient {
quoteAmountArg
);

const simulationBase =
simulation.baseAmount.toNumber() / 10 ** ammMarket.baseToken.decimals;
const simulationQuote =
simulation.quoteAmount.toNumber() / 10 ** ammMarket.quoteToken.decimals;
const simulationBase = PriceMath.getHumanAmount(
simulation.baseAmount,
ammMarket.baseToken.decimals
);
const simulationQuote = PriceMath.getHumanAmount(
simulation.quoteAmount,
ammMarket.quoteToken.decimals
);

const simulationExpectedLp = PriceMath.getHumanAmount(
simulation.expectedLpTokens,
ammMarket.lpToken.decimals
);

return {
baseAmount: simulationBase,
quoteAmount: simulationQuote,
// warning this value is not divided by the lot size of the LP tokens
expectedLpTokens: simulation.expectedLpTokens.toNumber()
expectedLpTokens: simulationExpectedLp
};
}

Expand Down
3 changes: 2 additions & 1 deletion lib/types/amm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PublicKey } from "@solana/web3.js";
import { Market, MarketFetchRequest } from "./markets";
import { BN } from "@coral-xyz/anchor";
import { TokenProps } from "./tokens";

export class AmmMarketFetchRequest implements MarketFetchRequest {
public marketKey: PublicKey;
Expand All @@ -15,6 +16,7 @@ export type AmmMarket = Market & {
baseAmount: BN;
quoteAmount: BN;
lpMintSupply: number;
lpToken: TokenProps;
createdAtSlot: BN;
twapLastUpdatedSlot: BN;
twapAggregator: BN;
Expand All @@ -34,7 +36,6 @@ export type AddLiquiditySimulationResponse = {
expectedLpTokens: number;
};


export type RemoveLiquiditySimulationResponse = {
baseAmount: number;
quoteAmount: number;
Expand Down

0 comments on commit a33725e

Please sign in to comment.