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

feat: move drift from svm-dev back into master #682

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions programs/svm-spoke/src/instructions/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn fill_v3_relay(
relay_hash: [u8; 32], // include in props, while not using it, to enable us to access it from the #Instruction Attribute within the accounts. This enables us to pass in the relay_hash PDA.
relay_data: V3RelayData,
repayment_chain_id: u64,
repayment_address: Pubkey,
) -> Result<()> {
let state = &mut ctx.accounts.state;
let current_time = get_current_time(state)?;
Expand Down Expand Up @@ -166,7 +167,7 @@ pub fn fill_v3_relay(
fill_deadline: relay_data.fill_deadline,
exclusivity_deadline: relay_data.exclusivity_deadline,
exclusive_relayer: relay_data.exclusive_relayer,
relayer: *ctx.accounts.signer.key,
relayer: repayment_address,
depositor: relay_data.depositor,
recipient: relay_data.recipient,
message: relay_data.message,
Expand Down Expand Up @@ -225,4 +226,3 @@ pub fn close_fill_pda(
Ok(())
}

// Events.
2 changes: 1 addition & 1 deletion programs/svm-spoke/src/instructions/slow_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub fn execute_v3_slow_relay_leaf(
fill_deadline: relay_data.fill_deadline,
exclusivity_deadline: relay_data.exclusivity_deadline,
exclusive_relayer: relay_data.exclusive_relayer,
relayer: *ctx.accounts.signer.key,
relayer: Pubkey::default(), // There is no repayment address for slow
depositor: relay_data.depositor,
recipient: relay_data.recipient,
message: relay_data.message,
Expand Down
9 changes: 8 additions & 1 deletion programs/svm-spoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,15 @@ pub mod svm_spoke {
relay_hash: [u8; 32],
relay_data: V3RelayData,
repayment_chain_id: u64,
repayment_address: Pubkey,
) -> Result<()> {
instructions::fill_v3_relay(ctx, relay_hash, relay_data, repayment_chain_id)
instructions::fill_v3_relay(
ctx,
relay_hash,
relay_data,
repayment_chain_id,
repayment_address,
)
}

pub fn close_fill_pda(
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/simpleFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function fillV3Relay(): Promise<void> {
}))
);

const tx = await (program.methods.fillV3Relay(Array.from(relayHashUint8Array), relayData, chainId) as any)
const tx = await (program.methods.fillV3Relay(Array.from(relayHashUint8Array), relayData, chainId, signer) as any)
.accounts({
state: statePda,
signer: signer,
Expand Down
63 changes: 49 additions & 14 deletions test/svm/SvmSpoke.Fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ describe("svm_spoke.fill", () => {
assertSE(relayerAccount.amount, seedBalance, "Relayer's balance should be equal to seed balance before the fill");

const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();

// Verify relayer's balance after the fill
relayerAccount = await getAccount(connection, relayerTA);
Expand All @@ -110,7 +114,11 @@ describe("svm_spoke.fill", () => {

it("Verifies FilledV3Relay event after filling a relay", async () => {
const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(420), otherRelayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();

// Fetch and verify the FilledV3Relay event
await new Promise((resolve) => setTimeout(resolve, 500));
Expand All @@ -122,14 +130,21 @@ describe("svm_spoke.fill", () => {
Object.keys(relayData).forEach((key) => {
assertSE(event[key], relayData[key], `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
});
// These props below are not part of relayData.
assertSE(event.repaymentChainId, new BN(420), "Repayment chain id should match");
assertSE(event.relayer, otherRelayer.publicKey, "Repayment address should match");
});

it("Fails to fill a V3 relay after the fill deadline", async () => {
updateRelayData({ ...relayData, fillDeadline: new BN(Math.floor(Date.now() / 1000) - 69) }); // 69 seconds ago

const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
try {
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();
assert.fail("Fill should have failed due to fill deadline passed");
} catch (err: any) {
assert.include(err.toString(), "ExpiredFillDeadline", "Expected ExpiredFillDeadline error");
Expand All @@ -144,7 +159,7 @@ describe("svm_spoke.fill", () => {
const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
try {
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1))
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([otherRelayer])
.rpc();
Expand All @@ -165,7 +180,11 @@ describe("svm_spoke.fill", () => {
const relayerAccountBefore = await getAccount(connection, otherRelayerTA);

const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([otherRelayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([otherRelayer])
.rpc();

// Verify relayer's balance after the fill
const relayerAccountAfter = await getAccount(connection, otherRelayerTA);
Expand All @@ -188,11 +207,19 @@ describe("svm_spoke.fill", () => {
const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));

// First fill attempt
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();

// Second fill attempt with the same data
try {
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();
assert.fail("Fill should have failed due to RelayFilled error");
} catch (err: any) {
assert.include(err.toString(), "RelayFilled", "Expected RelayFilled error");
Expand All @@ -210,7 +237,11 @@ describe("svm_spoke.fill", () => {
};

// Execute the fill_v3_relay call
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();

// Verify the fill PDA exists before closing
const fillStatusAccountBefore = await connection.getAccountInfo(accounts.fillStatus);
Expand All @@ -225,7 +256,7 @@ describe("svm_spoke.fill", () => {
}

// Set the current time to past the fill deadline
await setCurrentTime(program, state, relayer, relayData.fillDeadline.add(new BN(1)));
await setCurrentTime(program, state, relayer, relayData.fillDeadline.add(new BN(1), relayer.publicKey));

// Close the fill PDA
await program.methods.closeFillPda(relayHash, relayData).accounts(closeFillPdaAccounts).signers([relayer]).rpc();
Expand All @@ -245,7 +276,7 @@ describe("svm_spoke.fill", () => {

// Fill the relay
await program.methods
.fillV3Relay(Array.from(relayHash), relayData, new BN(1))
.fillV3Relay(Array.from(relayHash), relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();
Expand All @@ -267,7 +298,11 @@ describe("svm_spoke.fill", () => {
// Try to fill the relay. This should fail because fills are paused.
const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
try {
await program.methods.fillV3Relay(relayHash, relayData, new BN(1)).accounts(accounts).signers([relayer]).rpc();
await program.methods
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();
assert.fail("Should not be able to fill relay when fills are paused");
} catch (err: any) {
assert.include(err.toString(), "Fills are currently paused!", "Expected fills paused error");
Expand All @@ -284,7 +319,7 @@ describe("svm_spoke.fill", () => {

try {
await program.methods
.fillV3Relay(Array.from(relayHash), relayData, new BN(1))
.fillV3Relay(Array.from(relayHash), relayData, new BN(1), relayer.publicKey)
.accounts({
...accounts,
recipient: wrongRecipient,
Expand Down Expand Up @@ -312,7 +347,7 @@ describe("svm_spoke.fill", () => {

try {
await program.methods
.fillV3Relay(Array.from(relayHash), relayData, new BN(1))
.fillV3Relay(Array.from(relayHash), relayData, new BN(1), relayer.publicKey)
.accounts({
...accounts,
mintAccount: wrongMint,
Expand All @@ -339,7 +374,7 @@ describe("svm_spoke.fill", () => {

const relayHash = Array.from(calculateRelayHashUint8Array(relayData, chainId));
const txSignature = await program.methods
.fillV3Relay(relayHash, relayData, new BN(1))
.fillV3Relay(relayHash, relayData, new BN(1), relayer.publicKey)
.accounts(accounts)
.signers([relayer])
.rpc();
Expand Down
Loading