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

withdraw and call spl raydium swap poc #76

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Feb 7, 2025

this will remain draft PR, it is just to demonstration. so code is a bit messy, eventually can be moved to localnet, there will be separate PRs for withdraw and call code

it contains some code for raydium instructions to set up tests, most can be ignored - to review relevant code:

  • gateway tests swap test
  • connected spl contract
  • execute_spl gateway function

Poc demonstrates the following:

  • arbirtrary program with on_call function can be called with arbirtrary accounts
  • this program can sign tx using its own pda and manipulate withdrawn spl tokens
  • use case that is more complicated and resembles real use case

Poc works in a following way:

Test:

  • raydium accounts and programs needed for swap are cloned from mainnet
  • gateway swap test prepares raydium related things for swap (sets up input and output tokens, ATAs, accounts etc)
  • this test creates withdraw and call spl for gateway, but preparing all accounts needed for swap and putting them in remaining_accounts, and passes amount as argument for function

Gateway:

  • gateway execute_spl_token formats and passes data, args and accounts to connected_spl test program which then performs the swap
  • before on_call is called, this function withdraws spl tokens to connected_spl PDA

Connected program:

  • on_call function in connected_spl program calls swap, using it's own PDA as a signer, and it swaps half amount to provided account

Security considerations atm:

  • since users can put whatever accounts in remaining accounts, maybe zetaclient can remove signers, leaving it to connected programs to further sign using pda only? to be considered

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 131 lines in your changes missing coverage. Please review.

Please upload report for BASE (withdraw-and-call-spl@ae426df). Learn more about missing BASE report.

Files with missing lines Patch % Lines
programs/connectedSPL/src/lib.rs 0.00% 45 Missing ⚠️
.../connectedSPL/src/instructions/proxy_initialize.rs 0.00% 32 Missing ⚠️
...ams/connectedSPL/src/instructions/proxy_deposit.rs 0.00% 30 Missing ⚠️
...ectedSPL/src/instructions/proxy_swap_base_input.rs 0.00% 24 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##             withdraw-and-call-spl     #76   +/-   ##
=======================================================
  Coverage                         ?   0.33%           
=======================================================
  Files                            ?       6           
  Lines                            ?     890           
  Branches                         ?       0           
=======================================================
  Hits                             ?       3           
  Misses                           ?     887           
  Partials                         ?       0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

// NOTE: this will swap 2 provided tokens using raydium
// half amount is swaped using pda as signer to provided output account
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// half amount is swaped using pda as signer to provided output account
// half amount is swapped using pda as signer to provided output account

Base automatically changed from withdraw-and-call-spl to main February 24, 2025 17:20
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.

3 participants