Skip to content

Commit

Permalink
fix: invoke handler in slow fills
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <[email protected]>
  • Loading branch information
Reinis-FRP committed Nov 13, 2024
1 parent d1d0b01 commit cb7e421
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 7 additions & 3 deletions programs/svm-spoke/src/instructions/slow_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
error::{CommonError, SvmError},
get_current_time,
state::{FillStatus, FillStatusAccount, RootBundle, State},
utils::verify_merkle_proof,
utils::{invoke_handler, verify_merkle_proof},
};

use crate::event::{FillType, FilledV3Relay, RequestedV3SlowFill, V3RelayExecutionEventInfo};
Expand Down Expand Up @@ -166,8 +166,8 @@ pub struct ExecuteV3SlowRelayLeaf<'info> {
pub system_program: Program<'info, System>,
}

pub fn execute_v3_slow_relay_leaf(
ctx: Context<ExecuteV3SlowRelayLeaf>,
pub fn execute_v3_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteV3SlowRelayLeaf<'info>>,
slow_fill_leaf: V3SlowFill,
proof: Vec<[u8; 32]>,
) -> Result<()> {
Expand Down Expand Up @@ -225,6 +225,10 @@ pub fn execute_v3_slow_relay_leaf(
// Emit the FilledV3Relay event
let message_clone = relay_data.message.clone(); // Clone the message before it is moved

if message_clone.len() > 0 {
invoke_handler(ctx.accounts.signer.as_ref(), ctx.remaining_accounts, &message_clone)?;
}

emit_cpi!(FilledV3Relay {
input_token: relay_data.input_token,
output_token: relay_data.output_token,
Expand Down
4 changes: 2 additions & 2 deletions programs/svm-spoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ pub mod svm_spoke {
instructions::request_v3_slow_fill(ctx, relay_data)
}

pub fn execute_v3_slow_relay_leaf(
ctx: Context<ExecuteV3SlowRelayLeaf>,
pub fn execute_v3_slow_relay_leaf<'info>(
ctx: Context<'_, '_, '_, 'info, ExecuteV3SlowRelayLeaf<'info>>,
_relay_hash: [u8; 32],
slow_fill_leaf: V3SlowFill,
_root_bundle_id: u32,
Expand Down
21 changes: 18 additions & 3 deletions test/svm/SvmSpoke.SlowFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
import { PublicKey, Keypair } from "@solana/web3.js";
import { common } from "./SvmSpoke.common";
import { MerkleTree } from "@uma/common/dist/MerkleTree";
import { slowFillHashFn, SlowFillLeaf, readProgramEvents, calculateRelayHashUint8Array } from "./utils";
import {
slowFillHashFn,
SlowFillLeaf,
readProgramEvents,
calculateRelayHashUint8Array,
testAcrossPlusMessage,
} from "./utils";

const { provider, connection, program, owner, chainId, seedBalance, initializeState } = common;
const { recipient, setCurrentTime, assertSE, assert } = common;
Expand All @@ -30,6 +36,7 @@ describe("svm_spoke.slow_fill", () => {
const payer = (anchor.AnchorProvider.env().wallet as anchor.Wallet).payer;
const relayer = Keypair.generate();
const otherRelayer = Keypair.generate();
const { encodedMessage, fillRemainingAccounts } = testAcrossPlusMessage();

let state: PublicKey,
mint: PublicKey,
Expand Down Expand Up @@ -92,7 +99,7 @@ describe("svm_spoke.slow_fill", () => {
depositId: new BN(Math.floor(Math.random() * 1000000)), // Unique ID for each test.
fillDeadline: new BN(Math.floor(Date.now() / 1000) + 60), // 1 minute from now
exclusivityDeadline: new BN(Math.floor(Date.now() / 1000) - 30), // Note we set time in past to avoid exclusivity deadline
message: Buffer.from("Test message"),
message: encodedMessage,
},
chainId: slowRelayLeafChainId,
updatedOutputAmount: new BN(relayAmount),
Expand Down Expand Up @@ -168,7 +175,7 @@ describe("svm_spoke.slow_fill", () => {
depositId: new BN(1),
fillDeadline: new BN(Math.floor(Date.now() / 1000) + 60), // 1 minute from now
exclusivityDeadline: new BN(Math.floor(Date.now() / 1000) + 30), // 30 seconds from now
message: Buffer.from("Test message"),
message: encodedMessage,
};

await updateRelayData(initialRelayData);
Expand Down Expand Up @@ -222,6 +229,7 @@ describe("svm_spoke.slow_fill", () => {
.fillV3Relay(relayHash, formatRelayData(relayData), new BN(1), relayer.publicKey)
.accounts(fillAccounts)
.signers([relayer])
.remainingAccounts(fillRemainingAccounts)
.rpc();

try {
Expand Down Expand Up @@ -335,6 +343,7 @@ describe("svm_spoke.slow_fill", () => {
proofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
assert.fail("Execution should have failed due to fill status account not being initialized");
} catch (err: any) {
Expand All @@ -357,6 +366,7 @@ describe("svm_spoke.slow_fill", () => {
proofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();

// Verify the results
Expand Down Expand Up @@ -433,6 +443,7 @@ describe("svm_spoke.slow_fill", () => {
proofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
assert.fail("Execution should have failed due to wrong recipient token account");
} catch (err: any) {
Expand Down Expand Up @@ -492,6 +503,7 @@ describe("svm_spoke.slow_fill", () => {
firstProofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
const fFirstRecipientBal = (await connection.getTokenAccountBalance(firstRecipientTA)).value.amount;
assert.strictEqual(
Expand Down Expand Up @@ -522,6 +534,7 @@ describe("svm_spoke.slow_fill", () => {
firstProofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
assert.fail("Execution should have failed due to wrong fill status account");
} catch (err: any) {
Expand Down Expand Up @@ -566,6 +579,7 @@ describe("svm_spoke.slow_fill", () => {
proofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
assert.fail("Execution should have failed for inconsistent mint");
} catch (err: any) {
Expand Down Expand Up @@ -609,6 +623,7 @@ describe("svm_spoke.slow_fill", () => {
proofAsNumbers
)
.accounts(executeSlowRelayLeafAccounts)
.remainingAccounts(fillRemainingAccounts)
.rpc();
assert.fail("Execution should have failed for another chain");
} catch (err: any) {
Expand Down

0 comments on commit cb7e421

Please sign in to comment.