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

feat: Find price impact of swap #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

secretshardul
Copy link
Contributor

Pseudo-code in #86

  1. Low impact (blue color)

image

  1. High impact (red color)

image

Values match with numbers shown by Raydium

@secretshardul
Copy link
Contributor Author

Merged in cyclos-prod

@@ -39,21 +44,40 @@ export function InfoLabel() {
let fromTokenInfo = tokenMap.get(fromMint.toString());
let toTokenInfo = tokenMap.get(toMint.toString());

// Use last route item to find impact
const route = useRoute(fromMint, toMint);
const impact = usePriceImpact(route?.at(-1));

Choose a reason for hiding this comment

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

const impact = usePriceImpact(route?.[route?.length - 1]);

Array.at() is experimental and causing issues

@matt-scientist
Copy link

Looks like this only goes through 1 market - for a transitive swap (A -> B + B -> C) wouldn't you have to sum price impact against both markets?

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.

None yet

3 participants