-
Notifications
You must be signed in to change notification settings - Fork 193
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
base: main
Are you sure you want to change the base?
sam/DX-251 #795
Conversation
ts-sdk/actions/package.json
Outdated
@@ -0,0 +1,38 @@ | |||
{ | |||
"name": "@orca-so/actions", |
There was a problem hiding this comment.
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?
ts-sdk/actions/src/helpers.ts
Outdated
|
||
// Calculate total size in one pass | ||
const totalSize = [...currentInstructions, ...instructionsToAdd].reduce( | ||
(sum, ix) => sum + INSTRUCTION_OVERHEAD + (ix.data?.length ?? 0), |
There was a problem hiding this comment.
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
ts-sdk/actions/src/positions.ts
Outdated
} from "@orca-so/whirlpools-core"; | ||
|
||
// Open a concentrated liquidity position | ||
export async function openConcentratedPosition( |
There was a problem hiding this comment.
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
ts-sdk/actions/src/swap.ts
Outdated
const owner = getPayer(); | ||
|
||
try { | ||
const pools = await fetchWhirlpoolsByTokenPair(rpc, inputMint, outputMint); |
There was a problem hiding this comment.
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
ts-sdk/actions/src/index.ts
Outdated
@@ -0,0 +1,5 @@ | |||
export * from "./pools"; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
ts-sdk/actions/src/helpers.ts
Outdated
(sum, ix) => { | ||
let ixSize = INSTRUCTION_HEADER_SIZE; | ||
|
||
const numAccounts = (ix.accounts?.length ?? 0) + 1; // +1 for programAddress |
There was a problem hiding this comment.
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)
ts-sdk/actions/src/helpers.ts
Outdated
...params: [...T, TransactionSigner] | ||
) => Promise<R & { instructions: IInstruction[] }>, | ||
...params: T | ||
): Promise<R & { callback: () => Promise<string> }> { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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);
ts-sdk/actions/src/harvest.ts
Outdated
} from "./helpers"; | ||
|
||
// Harvest fees from all positions owned by an address | ||
export async function harvestAllPositionFees(): Promise<string[]> { |
There was a problem hiding this comment.
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)
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 transactionhttps://linear.app/orca-so/issue/DX-251/orca-actions-ts-package