Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Pool add getDepositQuote, getWithdrawQuote api's #47

Merged
10 commits merged into from
Oct 8, 2021

Conversation

ghost
Copy link

@ghost ghost commented Oct 5, 2021

Context

  • Currently, the client has to do math to figure out parameters for pool deposit and withdraw. We should provide functions that calculates these values

Changes

  • new pool api getDepositQuote(maxTokenAIn, maxTokenBIn, slippage?)
  • new pool api getWithdrawQuote(poolTokenIn, slippage?)

Usage Example

const orca = getOrca(connection);
const pool = orca.getPool(OrcaPoolConfig.ORCA_SOL);

const orcaAmount = new Decimal(10);
const quote = await pool.getQuote(pool.getTokenA(), orcaAmount);
const solAmount = quote.getMinOutputAmount();
const poolTokenAmount = await pool.getDepositQuote(orcaAmount, solAmount); // <-- NEW

console.log(`Deposit at most ${orcaAmount} ORCA and ${solAmount} SOL, for at least ${
  poolTokenAmount
} pool tokens`);

const depositPayload = await pool.deposit(owner, orcaAmount, solAmount, poolTokenAmount);
const depositTxId = await depositPayload.execute();

console.log("Confirmation:", depositTxId);

@ghost ghost requested a review from odcheung October 5, 2021 08:16
@ghost
Copy link
Author

ghost commented Oct 7, 2021

@odcheung - Thanks for the review! Pushed new commits which makes these changes:

  • Allow percentage based input for both getDepositQuote and getWithdrawQuote]
  • Updated return values of both getDepositQuote and getWithdrawQuote
  • Allow constraintToken based for getWithdrawQuote

@ghost ghost requested a review from odcheung October 7, 2021 01:21
Copy link
Collaborator

@odcheung odcheung left a comment

Choose a reason for hiding this comment

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

Hey @0xscuba,

Thank you for being patient with me so far! Public APIs are often difficult to adjust/recall after it goes out, so I want to make sure we get it right to make the right balance between feature-support & our burden of maintenance responsibility. I promise you that I only have this many opinions on 1 way door type decisions ><

We have a slight miscommunication on the %-usecase in the previous review. I don't think we should explicitly support that inside the SDK because it requires orca-pool to be aware of the user-wallet & it adds input-type complexity that is difficult for the user to use & especially difficult for us to maintain down the road.

@ghost
Copy link
Author

ghost commented Oct 7, 2021

Hey @odcheung, haha no worries! I really appreciate all the feedback, and sdk is better for it 🙂

Agree that we should be thoughtful around one-way-door decisions. I think in this case we definitely wanted to get it right because getDepositQuote, getWithdrawQuote will be an integral part of the SDK. Tangentially though, I think it's ok to push an api, then deprecate and add new versions of it without having api breaking changes (e.g. pool.someCoolMethod, later introduce pool.someCoolMethodV2).

Updated the PR with the following changes:

  • Remove having different types of inputs
  • Update comments, inputs, outputs
  • New logic for calculating poolTokenIn_U64 using withdrawTokenAmount & withdrawTokenMint
  • Also updated Update Usage section of readme #48 to match the changes

Copy link
Collaborator

@odcheung odcheung left a comment

Choose a reason for hiding this comment

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

thank you for addressing the comments! Looks real good to me. Approved
one nit on the description of getPoolTokenMint. (no need to wait for further approve)

@ghost
Copy link
Author

ghost commented Oct 8, 2021

@odcheung - thanks for the review! updated the commented, and merging now. I'll also bump the version and publish it

@ghost ghost merged commit f3de5c2 into main Oct 8, 2021
@ghost ghost deleted the scuba/depositQuote-and-withdrawQuote branch October 8, 2021 01:29
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant