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

fix: mix delegated and owned compressed token accounts #1050

Merged

Conversation

ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Aug 4, 2024

Issue:

  • consider an escrow program with an compressed escrow token account owned by a pda
  • when compressing into this escrow account we have token accounts of two different owners which both need to sign (pda, depositing user)
  • The straightforward way is to just transfer the deposit amount to the pda. However, this way every deposit creates an additional escrow account -> the escrowed tokens are fragmented and need to be merged.
  • We could merge escrow accounts in the deposit transaction in a second cpi. The implementation is difficult since we need to dynamically get the leaf index of the newly inserted compressed account onchain, then spend the newly created compressed account and verify two zkps in this process. This would only work if there is no activity on the Merkle tree otherwise the second zkp will fail.
  • A feasible workaround is approve the funds to escrow and transfer the approved funds to the escrow token account (2 inputs, escrow, approved token account, 1 output escrow)

Changes:

  • enable two owners for input compressed accounts

@ananas-block ananas-block marked this pull request as draft August 4, 2024 05:53

Unverified

The committer email address is not verified.
@ananas-block ananas-block force-pushed the jorrit/fix-mix-delegated-and-owned-compressed-accounts branch from c9cf287 to 03bf605 Compare August 4, 2024 23:11
@ananas-block ananas-block marked this pull request as ready for review August 4, 2024 23:11
Comment on lines 1167 to 1170
// let lamports_output_amount = input_compressed_accounts
// .iter()
// .map(|x| x.compressed_account.compressed_account.lamports)
// .sum::<u64>();
Copy link
Contributor

Choose a reason for hiding this comment

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

comment?

@ananas-block ananas-block merged commit 03e374e into main Aug 5, 2024
7 of 13 checks passed
@ananas-block ananas-block deleted the jorrit/fix-mix-delegated-and-owned-compressed-accounts branch August 5, 2024 04:07
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

2 participants