MagicAction
#361
Replies: 1 comment
-
Thanks @taco-paco. LGTM! For the SDK API I would propose use a builder pattern and it could look something like: let builder = MagicBuilder::new_bundle()
.payer(&ctx.accounts.payer)
.accounts(&[ctx.accounts.counter.to_account_info()])
.commit()
.undelegate()
.add_instruction(
system_instruction::transfer(
&ctx.accounts.payer.key(),
&ctx.accounts.counter.key(),
1_000_000,
)
)
.add_instruction(
increment_counter_instruction(ctx.accounts.counter.key())
);
builder.build_and_send()?; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Magic Action
To support custom actions post commit or post undelegation, or even standalone actions on behalf of actor PDA, we would need to modify: magicblock-program, ephemeral-rollup-sdk & validator.
Current implementation
First let’s recap on the way the current commit & undelegation is scheduled on smart-contract level.
At the moment SDK provides users with 2 convenient methods:
Those CPI into magiblock-program which does some checks and eventually adds an entry into the array of ScheduledCommits
Problem
We want to support custom “actions”. Custom actions are defined as follows:
With custom actions now we have 7 combinations:
Standalone action, commit, commit with action, commit and undelegate, commit with action and undelegate, commit and undelegate with action, commit with action and undelegate with action
Supporting those in the existing ScheduledCommit struct would get out of hand pretty fast, and the SDK would be cumbersome.
Proposal
The proposal is to evolve ScheduledCommit -> ScheduledAction to more explicitly support possible combinations.
Now the structure is more explicit and evolution friendly, while cases would to some extent have to be supported individually it is easier to do so and without cumbersome preprocessing, less error-prone since no invalid combinations are discarded by compiler and enum structure itself. No way to have “action-commit-with-action”
SDK
How would this look for a user? The modified ephemeral-sdk would be constructor-like(It would also support old methods).
The idea as follows:
User would have to all users would have to do is to create an instance of MagicInstructionBuilder, call build_and_invoke and SDK handles all for them
magicblock-program
To integrate feature we would need to change magicblock-program:
For backwards compatibility adapt existing method process_schedule_commit to create proper ScheduledAction instances
Add new entrypoint which would look like this
And corresponding process_schedule_action
It would contain all necessary descriptions of scheduled action by user and push entry into modified
Beta Was this translation helpful? Give feedback.
All reactions