Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Maree <[email protected]>
  • Loading branch information
chrismaree committed Jan 20, 2025
1 parent 76f6f8a commit 74198f5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 85 deletions.
44 changes: 22 additions & 22 deletions programs/svm-spoke/src/instructions/slow_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ use crate::{
constants::DISCRIMINATOR_SIZE,
constraints::is_relay_hash_valid,
error::{CommonError, SvmError},
state::{ExecuteV3SlowRelayLeafParams, FillStatus, FillStatusAccount, RequestV3SlowFillParams, RootBundle, State},
state::{ExecuteSlowRelayLeafParams, FillStatus, FillStatusAccount, RequestSlowFillParams, RootBundle, State},
utils::{get_current_time, hash_non_empty_message, invoke_handler, verify_merkle_proof},
};

#[event_cpi]
#[derive(Accounts)]
#[instruction(relay_hash: [u8; 32], relay_data: Option<V3RelayData>)]
pub struct RequestV3SlowFill<'info> {
pub struct RequestSlowFill<'info> {
#[account(mut)]
pub signer: Signer<'info>,

// This is required as fallback when None instruction params are passed in arguments.
#[account(mut, seeds = [b"instruction_params", signer.key().as_ref()], bump, close = signer)]
pub instruction_params: Option<Account<'info, RequestV3SlowFillParams>>,
pub instruction_params: Option<Account<'info, RequestSlowFillParams>>,

#[account(
seeds = [b"state", state.seed.to_le_bytes().as_ref()],
Expand All @@ -44,9 +44,9 @@ pub struct RequestV3SlowFill<'info> {
pub system_program: Program<'info, System>,
}

pub fn request_v3_slow_fill(ctx: Context<RequestV3SlowFill>, relay_data: Option<V3RelayData>) -> Result<()> {
let RequestV3SlowFillParams { relay_data } =
unwrap_request_v3_slow_fill_params(relay_data, &ctx.accounts.instruction_params);
pub fn request_slow_fill(ctx: Context<RequestSlowFill>, relay_data: Option<V3RelayData>) -> Result<()> {
let RequestSlowFillParams { relay_data } =
unwrap_request_slow_fill_params(relay_data, &ctx.accounts.instruction_params);

let state = &ctx.accounts.state;

Expand Down Expand Up @@ -92,15 +92,15 @@ pub fn request_v3_slow_fill(ctx: Context<RequestV3SlowFill>, relay_data: Option<
}

// Helper to unwrap optional instruction params with fallback loading from buffer account.
fn unwrap_request_v3_slow_fill_params(
fn unwrap_request_slow_fill_params(
relay_data: Option<V3RelayData>,
account: &Option<Account<RequestV3SlowFillParams>>,
) -> RequestV3SlowFillParams {
account: &Option<Account<RequestSlowFillParams>>,
) -> RequestSlowFillParams {
match relay_data {
Some(relay_data) => RequestV3SlowFillParams { relay_data },
Some(relay_data) => RequestSlowFillParams { relay_data },
_ => account
.as_ref()
.map(|account| RequestV3SlowFillParams { relay_data: account.relay_data.clone() })
.map(|account| RequestSlowFillParams { relay_data: account.relay_data.clone() })
.unwrap(), // We do not expect this to panic here as missing instruction_params is unwrapped in context.
}
}
Expand Down Expand Up @@ -134,12 +134,12 @@ impl V3SlowFill {
#[event_cpi]
#[derive(Accounts)]
#[instruction(relay_hash: [u8; 32], slow_fill_leaf: Option<V3SlowFill>, root_bundle_id: Option<u32>)]
pub struct ExecuteV3SlowRelayLeaf<'info> {
pub struct ExecuteSlowRelayLeaf<'info> {
pub signer: Signer<'info>,

// This is required as fallback when None instruction params are passed in arguments.
#[account(mut, seeds = [b"instruction_params", signer.key().as_ref()], bump, close = signer)]
pub instruction_params: Option<Account<'info, ExecuteV3SlowRelayLeafParams>>,
pub instruction_params: Option<Account<'info, ExecuteSlowRelayLeafParams>>,

#[account(seeds = [b"state", state.seed.to_le_bytes().as_ref()], bump)]
pub state: Account<'info, State>,
Expand Down Expand Up @@ -206,13 +206,13 @@ pub struct ExecuteV3SlowRelayLeaf<'info> {
pub system_program: Program<'info, System>,
}

pub fn execute_v3_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteV3SlowRelayLeaf<'info>>,
pub fn execute_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteSlowRelayLeaf<'info>>,
slow_fill_leaf: Option<V3SlowFill>,
proof: Option<Vec<[u8; 32]>>,
) -> Result<()> {
let ExecuteV3SlowRelayLeafParams { slow_fill_leaf, proof, .. } =
unwrap_execute_v3_slow_relay_leaf_params(slow_fill_leaf, proof, &ctx.accounts.instruction_params);
let ExecuteSlowRelayLeafParams { slow_fill_leaf, proof, .. } =
unwrap_execute_slow_relay_leaf_params(slow_fill_leaf, proof, &ctx.accounts.instruction_params);

let current_time = get_current_time(&ctx.accounts.state)?;

Expand Down Expand Up @@ -292,20 +292,20 @@ pub fn execute_v3_slow_relay_leaf<'info>(
}

// Helper to unwrap optional instruction params with fallback loading from buffer account.
fn unwrap_execute_v3_slow_relay_leaf_params(
fn unwrap_execute_slow_relay_leaf_params(
slow_fill_leaf: Option<V3SlowFill>,
proof: Option<Vec<[u8; 32]>>,
account: &Option<Account<ExecuteV3SlowRelayLeafParams>>,
) -> ExecuteV3SlowRelayLeafParams {
account: &Option<Account<ExecuteSlowRelayLeafParams>>,
) -> ExecuteSlowRelayLeafParams {
match (slow_fill_leaf, proof) {
(Some(slow_fill_leaf), Some(proof)) => ExecuteV3SlowRelayLeafParams {
(Some(slow_fill_leaf), Some(proof)) => ExecuteSlowRelayLeafParams {
slow_fill_leaf,
root_bundle_id: 0, // This is not used in the caller.
proof,
},
_ => account
.as_ref()
.map(|account| ExecuteV3SlowRelayLeafParams {
.map(|account| ExecuteSlowRelayLeafParams {
slow_fill_leaf: account.slow_fill_leaf.clone(),
root_bundle_id: account.root_bundle_id,
proof: account.proof.clone(),
Expand Down
14 changes: 7 additions & 7 deletions programs/svm-spoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ pub mod svm_spoke {
/// token via PoolRebalanceRoutes. Slow fills are created by inserting slow fill objects into a Merkle tree that is
/// included in the next HubPool "root bundle". Once the optimistic challenge window has passed, the HubPool will
/// relay the slow root to this chain via relayRootBundle(). Once the slow root is relayed, the slow fill can be
/// executed by anyone who calls executeV3SlowRelayLeaf(). Cant request a slow fill if the fill deadline has
/// executed by anyone who calls executeSlowRelayLeaf(). Cant request a slow fill if the fill deadline has
/// passed. Cant request a slow fill if the relay has already been filled or a slow fill has already been requested.
///
/// ### Required Accounts:
Expand All @@ -699,12 +699,12 @@ pub mod svm_spoke {
/// fill for the intended deposit. See fill_relay & V3RelayData struct for more details.
/// Note: relay_data is optional parameter. If None for it is passed, the caller must load it via the
/// instruction_params account.
pub fn request_v3_slow_fill(
ctx: Context<RequestV3SlowFill>,
pub fn request_slow_fill(
ctx: Context<RequestSlowFill>,
_relay_hash: [u8; 32],
relay_data: Option<V3RelayData>,
) -> Result<()> {
instructions::request_v3_slow_fill(ctx, relay_data)
instructions::request_slow_fill(ctx, relay_data)
}

/// Executes a slow relay leaf stored as part of a root bundle relayed by the HubPool.
Expand Down Expand Up @@ -743,14 +743,14 @@ pub mod svm_spoke {
/// - proof: Inclusion proof for this leaf in slow relay root in root bundle.
/// Note: slow_fill_leaf, _root_bundle_id, and proof are optional parameters. If None for any of these is passed,
/// the caller must load them via the instruction_params account.
pub fn execute_v3_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteV3SlowRelayLeaf<'info>>,
pub fn execute_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteSlowRelayLeaf<'info>>,
_relay_hash: [u8; 32],
slow_fill_leaf: Option<V3SlowFill>,
_root_bundle_id: Option<u32>,
proof: Option<Vec<[u8; 32]>>,
) -> Result<()> {
instructions::execute_v3_slow_relay_leaf(ctx, slow_fill_leaf, proof)
instructions::execute_slow_relay_leaf(ctx, slow_fill_leaf, proof)
}

/// **************************************
Expand Down
4 changes: 2 additions & 2 deletions programs/svm-spoke/src/state/instruction_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ pub struct FillV3RelayParams {

#[account]
#[derive(InitSpace)]
pub struct RequestV3SlowFillParams {
pub struct RequestSlowFillParams {
pub relay_data: V3RelayData,
}

#[account]
#[derive(InitSpace)]
pub struct ExecuteV3SlowRelayLeafParams {
pub struct ExecuteSlowRelayLeafParams {
pub slow_fill_leaf: V3SlowFill,
pub root_bundle_id: u32,
#[max_len(0)]
Expand Down
2 changes: 1 addition & 1 deletion programs/svm-spoke/src/utils/message_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn invoke_handler<'info>(
}

// Writable accounts must be passed first. This enforces the same write permissions as set in the message. Note
// that this would fail if any of mutable FillV3Relay / ExecuteV3SlowRelayLeaf accounts are passed as read-only
// that this would fail if any of mutable FillV3Relay / ExecuteSlowRelayLeaf accounts are passed as read-only
// in the bridged message as the calling client deduplicates the accounts and applies maximum required
// privileges. Though it is unlikely that any practical application would require this.
// We also explicitly disable all signer privileges for all the accounts to protect the relayer from being
Expand Down
8 changes: 4 additions & 4 deletions src/svm/instructionParamsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ export async function loadFillV3RelayParams(
/**
* Loads requestV3 slow fill parameters.
*/
export async function loadRequestV3SlowFillParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData) {
export async function loadRequestSlowFillParams(program: Program<SvmSpoke>, signer: Keypair, relayData: RelayData) {
// Close the instruction params account if the caller has used it before.
await closeInstructionParams(program, signer);

// Execute load instructions sequentially.
const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.

const accountCoder = new LargeAccountsCoder(program.idl);
const instructionParamsBytes = await accountCoder.encode("requestV3SlowFillParams", { relayData });
const instructionParamsBytes = await accountCoder.encode("requestSlowFillParams", { relayData });

const loadInstructions: TransactionInstruction[] = [];
loadInstructions.push(
Expand All @@ -154,7 +154,7 @@ export async function loadRequestV3SlowFillParams(program: Program<SvmSpoke>, si
/**
* Loads executeV3 slow relay leaf parameters.
*/
export async function loadExecuteV3SlowRelayLeafParams(
export async function loadExecuteSlowRelayLeafParams(
program: Program<SvmSpoke>,
signer: Keypair,
slowFillLeaf: SlowFillLeaf,
Expand All @@ -168,7 +168,7 @@ export async function loadExecuteV3SlowRelayLeafParams(
const maxInstructionParamsFragment = 900; // Should not exceed message size limit when writing to the data account.

const accountCoder = new LargeAccountsCoder(program.idl);
const instructionParamsBytes = await accountCoder.encode("executeV3SlowRelayLeafParams", {
const instructionParamsBytes = await accountCoder.encode("executeSlowRelayLeafParams", {
slowFillLeaf,
rootBundleId,
proof,
Expand Down
42 changes: 21 additions & 21 deletions test/svm/SvmSpoke.SlowFill.AcrossPlus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import {
readEventsUntilFound,
calculateRelayEventHashUint8Array,
slowFillHashFn,
loadRequestV3SlowFillParams,
loadExecuteV3SlowRelayLeafParams,
loadRequestSlowFillParams,
loadExecuteSlowRelayLeafParams,
intToU8Array32,
} from "../../src/svm";
import { MulticallHandler } from "../../target/types/multicall_handler";
import { common } from "./SvmSpoke.common";
import {
ExecuteV3SlowRelayLeafDataParams,
ExecuteV3SlowRelayLeafDataValues,
RequestV3SlowFillDataParams,
RequestV3SlowFillDataValues,
ExecuteSlowRelayLeafDataParams,

Check failure on line 37 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataParams'. Did you mean 'ExecuteV3SlowRelayLeafDataParams'?

Check failure on line 37 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Test (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataParams'. Did you mean 'ExecuteV3SlowRelayLeafDataParams'?

Check failure on line 37 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Forge (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataParams'. Did you mean 'ExecuteV3SlowRelayLeafDataParams'?
ExecuteSlowRelayLeafDataValues,

Check failure on line 38 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataValues'. Did you mean 'ExecuteV3SlowRelayLeafDataValues'?

Check failure on line 38 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Test (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataValues'. Did you mean 'ExecuteV3SlowRelayLeafDataValues'?

Check failure on line 38 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Forge (20)

'"../../src/types/svm"' has no exported member named 'ExecuteSlowRelayLeafDataValues'. Did you mean 'ExecuteV3SlowRelayLeafDataValues'?
RequestSlowFillDataParams,

Check failure on line 39 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataParams'. Did you mean 'RequestV3SlowFillDataParams'?

Check failure on line 39 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Test (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataParams'. Did you mean 'RequestV3SlowFillDataParams'?

Check failure on line 39 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Forge (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataParams'. Did you mean 'RequestV3SlowFillDataParams'?
RequestSlowFillDataValues,

Check failure on line 40 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataValues'. Did you mean 'RequestV3SlowFillDataValues'?

Check failure on line 40 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Test (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataValues'. Did you mean 'RequestV3SlowFillDataValues'?

Check failure on line 40 in test/svm/SvmSpoke.SlowFill.AcrossPlus.ts

View workflow job for this annotation

GitHub Actions / Forge (20)

'"../../src/types/svm"' has no exported member named 'RequestSlowFillDataValues'. Did you mean 'RequestV3SlowFillDataValues'?
SlowFillLeaf,
} from "../../src/types/svm";
const { provider, connection, program, owner, chainId, setCurrentTime } = common;
Expand Down Expand Up @@ -136,20 +136,20 @@ describe("svm_spoke.slow_fill.across_plus", () => {
// Relay root bundle with slow fill leaf.
const { relayHash, leaf, rootBundleId, proofAsNumbers, rootBundle } = await relaySlowFillRootBundle();

const requestV3SlowFillValues: RequestV3SlowFillDataValues = [Array.from(relayHash), leaf.relayData];
const requestSlowFillValues: RequestSlowFillDataValues = [Array.from(relayHash), leaf.relayData];
let loadRequestParamsInstructions: TransactionInstruction[] = [];
if (bufferParams) {
loadRequestParamsInstructions = await loadRequestV3SlowFillParams(program, relayer, requestV3SlowFillValues[1]);
loadRequestParamsInstructions = await loadRequestSlowFillParams(program, relayer, requestSlowFillValues[1]);
[requestAccounts.instructionParams] = PublicKey.findProgramAddressSync(
[Buffer.from("instruction_params"), relayer.publicKey.toBuffer()],
program.programId
);
}
const requestV3SlowFillParams: RequestV3SlowFillDataParams = bufferParams
? [requestV3SlowFillValues[0], null]
: requestV3SlowFillValues;
const requestSlowFillParams: RequestSlowFillDataParams = bufferParams
? [requestSlowFillValues[0], null]
: requestSlowFillValues;
const requestIx = await program.methods
.requestV3SlowFill(...requestV3SlowFillParams)
.requestSlowFill(...requestSlowFillParams)
.accounts(requestAccounts)
.instruction();

Expand All @@ -169,31 +169,31 @@ describe("svm_spoke.slow_fill.across_plus", () => {
{ pubkey: handlerProgram.programId, isSigner: false, isWritable: false },
...multicallHandlerCoder.compiledKeyMetas,
];
const executeV3SlowRelayLeafValues: ExecuteV3SlowRelayLeafDataValues = [
const executeSlowRelayLeafValues: ExecuteSlowRelayLeafDataValues = [
Array.from(relayHash),
leaf,
rootBundleId,
proofAsNumbers,
];
let loadExecuteParamsInstructions: TransactionInstruction[] = [];
if (bufferParams) {
loadExecuteParamsInstructions = await loadExecuteV3SlowRelayLeafParams(
loadExecuteParamsInstructions = await loadExecuteSlowRelayLeafParams(
program,
relayer,
executeV3SlowRelayLeafValues[1],
executeV3SlowRelayLeafValues[2],
executeV3SlowRelayLeafValues[3]
executeSlowRelayLeafValues[1],
executeSlowRelayLeafValues[2],
executeSlowRelayLeafValues[3]
);
[requestAccounts.instructionParams] = PublicKey.findProgramAddressSync(
[Buffer.from("instruction_params"), relayer.publicKey.toBuffer()],
program.programId
);
}
const executeV3SlowRelayLeafParams: ExecuteV3SlowRelayLeafDataParams = bufferParams
? [executeV3SlowRelayLeafValues[0], null, null, null]
: executeV3SlowRelayLeafValues;
const executeSlowRelayLeafParams: ExecuteSlowRelayLeafDataParams = bufferParams
? [executeSlowRelayLeafValues[0], null, null, null]
: executeSlowRelayLeafValues;
const executeIx = await program.methods
.executeV3SlowRelayLeaf(...executeV3SlowRelayLeafParams)
.executeSlowRelayLeaf(...executeSlowRelayLeafParams)
.accounts(executeAccounts)
.remainingAccounts(executeRemainingAccounts)
.instruction();
Expand Down
Loading

0 comments on commit 74198f5

Please sign in to comment.