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

sam/DX-251 #795

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

sam/DX-251 #795

wants to merge 27 commits into from

Conversation

parhim
Copy link
Contributor

@parhim parhim commented Mar 3, 2025

This serves as a wrapper over @orca/whirlpools sdk that enables building and sending transactions with the appropriate fee settings

every function, except harvestAllPositionFees will return an object containing a callback and either a quote or initialization cost (so that it can be checked before sending the transaction)

await callback() will build and send the transaction

https://linear.app/orca-so/issue/DX-251/orca-actions-ts-package

@parhim parhim requested a review from odcheung March 3, 2025 22:40
@@ -0,0 +1,38 @@
{
"name": "@orca-so/actions",
Copy link
Member

Choose a reason for hiding this comment

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

Can we do @orca-so/whirlpools-actions?


// Calculate total size in one pass
const totalSize = [...currentInstructions, ...instructionsToAdd].reduce(
(sum, ix) => sum + INSTRUCTION_OVERHEAD + (ix.data?.length ?? 0),
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this calculation is correct. Looks like this doesn't take instruction account addresses

} from "@orca-so/whirlpools-core";

// Open a concentrated liquidity position
export async function openConcentratedPosition(
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be possible to create s builder function for this that takes as arguments and argument 'the function to be wrapped'. Would save some boilerplate

const owner = getPayer();

try {
const pools = await fetchWhirlpoolsByTokenPair(rpc, inputMint, outputMint);
Copy link
Member

Choose a reason for hiding this comment

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

Here I would just wrap the function from high-level sdk. The sdk is not meant to be a router so just supplying the pool you want to swap through is fine

@@ -0,0 +1,5 @@
export * from "./pools";
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to follow the same file structure as high-level sdk?

We might even want to reexport some of the 'fetch' functions here but I think we have a separate project for that

@@ -92,8 +92,8 @@ impl U256Muldiv {
}

for i in (1..NUM_WORDS).rev() {
result.items[i] = result.items[i] << shift_amount
Copy link
Member

Choose a reason for hiding this comment

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

Can you undo changes in this file? If we change program code then our program will no longer be a verified build (unless we redeploy)

(sum, ix) => {
let ixSize = INSTRUCTION_HEADER_SIZE;

const numAccounts = (ix.accounts?.length ?? 0) + 1; // +1 for programAddress
Copy link
Member

Choose a reason for hiding this comment

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

This does not take into account that versionedTransactions compile (dedup) the accounts. I don't know the exact logic so might be better to just try to compile it and see if it fails/succeeds? (or if it always succeeds you can check the size of the serialized message)

...params: [...T, TransactionSigner]
) => Promise<R & { instructions: IInstruction[] }>,
...params: T
): Promise<R & { callback: () => Promise<string> }> {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be callback: () => Promise<Signature> instead of callback: () => Promise<string>?

import { executeWhirlpoolInstruction } from "./helpers";

// Open a concentrated liquidity position
export async function openConcentratedPosition(
Copy link
Member

Choose a reason for hiding this comment

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

This you might even be able to make shorter so you don't have to make the parameters and return type explicit.

function wrapFunctionWithExecution<P, R extends { instructions: IInstruction[] }>(
  function: (...P) => R
): Promise<Omit<R, "instructions> & { callback: () => Promise<Signature> } {
  ...
}

export const openConcentratedPostion = wrapFunctionWithExecution(openPositionInstructions);

} from "./helpers";

// Harvest fees from all positions owned by an address
export async function harvestAllPositionFees(): Promise<string[]> {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add this to @orca-so/whirlpools instead and then here just have the wrapper again? We can just have the harvestAllInstructions function return all the instructions (regardless of whether they fit in a tx or not). Then when building the TX we can just split it up there and fire the in parallel (instead of sequentially)

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.

2 participants