Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/svm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"litesvm": "=0.1.0"
},
"devDependencies": {
"@mimicprotocol/sdk": "0.0.1-rc.39",
"@mimicprotocol/sdk": "0.0.1-rc.40",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.20",
"@types/mocha": "^10.0.10",
Expand Down
14 changes: 4 additions & 10 deletions packages/svm/programs/settler/src/instructions/create_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use crate::{
controller::{self, accounts::EntityRegistry, types::EntityType},
errors::SettlerError,
state::{Intent, Proposal, ProposalInstruction},
types::TokenFee,
};

#[derive(Accounts)]
#[instruction(instructions: Vec<ProposalInstruction>, fees: Vec<TokenFee>,)]
#[instruction(instructions: Vec<ProposalInstruction>, fees: Vec<u64>,)]
pub struct CreateProposal<'info> {
#[account(mut)]
pub solver: Signer<'info>,
Expand Down Expand Up @@ -45,7 +44,7 @@ pub struct CreateProposal<'info> {
pub fn create_proposal(
ctx: Context<CreateProposal>,
instructions: Vec<ProposalInstruction>,
fees: Vec<TokenFee>,
fees: Vec<u64>,
deadline: u64,
is_final: bool,
) -> Result<()> {
Expand All @@ -70,13 +69,8 @@ pub fn create_proposal(

fees.iter()
.zip(&intent.max_fees)
.try_for_each(|(fee, max_fee)| {
require_keys_eq!(fee.mint, max_fee.mint, SettlerError::InvalidFeeMint);
require_gte!(
max_fee.amount,
fee.amount,
SettlerError::FeeAmountExceedsMaxFee
);
.try_for_each(|(&fee, max_fee)| {
require_gte!(max_fee.amount, fee, SettlerError::FeeAmountExceedsMaxFee);
Ok(())
})?;

Expand Down
2 changes: 1 addition & 1 deletion packages/svm/programs/settler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub mod settler {
pub fn create_proposal(
ctx: Context<CreateProposal>,
instructions: Vec<ProposalInstruction>,
fees: Vec<TokenFee>,
fees: Vec<u64>,
deadline: u64,
is_final: bool,
) -> Result<()> {
Expand Down
11 changes: 4 additions & 7 deletions packages/svm/programs/settler/src/state/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use anchor_lang::prelude::*;

use crate::{
types::TokenFee,
utils::{add, mul, sub, Proposal as Eip712Proposal},
};
use crate::utils::{add, mul, sub, Proposal as Eip712Proposal};

#[account]
pub struct Proposal {
Expand All @@ -13,7 +10,7 @@ pub struct Proposal {
pub is_final: bool,
pub is_signed: bool,
pub instructions: Vec<ProposalInstruction>,
pub fees: Vec<TokenFee>,
pub fees: Vec<u64>,
pub bump: u8,
}

Expand Down Expand Up @@ -43,7 +40,7 @@ impl Proposal {
}

pub fn fees_size(len: usize) -> Result<usize> {
add(4, mul(TokenFee::INIT_SPACE, len)?)
add(4, mul(8, len)?)
}

pub fn extended_size(
Expand All @@ -64,7 +61,7 @@ impl Proposal {
solver: self.creator.to_string(),
deadline: U256::from(self.deadline),
data: vec![].into(),
fees: self.fees.iter().map(|fee| U256::from(fee.amount)).collect(),
fees: self.fees.iter().map(|&fee| U256::from(fee)).collect(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/svm/programs/settler/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod eip712_domain;
pub mod intent_event;
pub mod token_fee;
pub mod op_type;
pub mod token_fee;

pub use eip712_domain::*;
pub use intent_event::*;
pub use token_fee::*;
pub use op_type::*;
pub use token_fee::*;
2 changes: 1 addition & 1 deletion packages/svm/programs/settler/src/types/token_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anchor_lang::prelude::*;

#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct TokenFee {
pub mint: Pubkey,
pub token: Pubkey,
pub amount: u64,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svm/tests/helpers/intents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function createValidatedIntent(
*/
export function mapIntentFeesToTokenFees(intent: IntentAccount): SvmTokenFee[] {
return intent.maxFees.map((maxFee) => ({
token: maxFee.mint,
token: maxFee.token,
amount: maxFee.amount.toString(),
}))
}
Expand Down
4 changes: 2 additions & 2 deletions packages/svm/tests/helpers/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as SettlerIDL from '../../target/idl/settler.json'
import { Settler } from '../../target/types/settler'
import { makeTxSignAndSend } from '../utils'
import { PROPOSAL_DEADLINE_OFFSET, TEST_DATA_HEX_3 } from './constants'
import { createValidatedIntent, mapIntentFeesToTokenFees } from './intents'
import { createValidatedIntent } from './intents'
import { getCurrentTimestamp, randomPubkey } from './misc'

export type InstructionAccount = {
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function createProposalParams(
const program = new Program<Settler>(SettlerIDL, solverProvider)
const intentKey = solverSdk.getIntentKey(intentHash)
const intent = await program.account.intent.fetch(intentKey)
const fees = mapIntentFeesToTokenFees(intent)
const fees = intent.maxFees.map((maxFee) => maxFee.amount.toString())

return {
intentHash,
Expand Down
2 changes: 1 addition & 1 deletion packages/svm/tests/helpers/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function createAxiaSignature(
solver: proposal.creator.toString(),
deadline: proposal.deadline.toString(),
data: '0x', // TODO
fees: proposal.fees.map((fee) => fee.amount.toString()),
fees: proposal.fees.map((fee) => fee.toString()),
}

const signature = await axia.signTypedData(domain, PROPOSAL_712_TYPE_SVM, values)
Expand Down
46 changes: 7 additions & 39 deletions packages/svm/tests/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
SolanaEip712Domain,
SvmController,
SvmSettler,
SvmTokenFee,
ValidatorSigner,
} from '@mimicprotocol/sdk'
import {
Expand Down Expand Up @@ -403,7 +402,7 @@ describe('Settler', () => {
const nonceArray = Array.from(hexToBytes(nonce))
const dataArray = hexToBytes(data)
const maxFeesBn = maxFees.map((tokenFee) => ({
mint: translateAddress(tokenFee.token),
token: translateAddress(tokenFee.token),
amount: new BN(tokenFee.amount),
}))
const eventsArray = events.map((eventHex) => ({
Expand Down Expand Up @@ -532,7 +531,7 @@ describe('Settler', () => {
const intent = await program.account.intent.fetch(sdk.getIntentKey(intentHash))
expect(intent.maxFees.length).to.be.eq(2)
expect(intent.maxFees[0].amount.toNumber()).to.be.eq(DEFAULT_MAX_FEE)
expect(intent.maxFees[1].mint.toString()).to.be.eq(extendParams.moreMaxFees![0].token.toString())
expect(intent.maxFees[1].token.toString()).to.be.eq(extendParams.moreMaxFees![0].token.toString())
expect(intent.maxFees[1].amount.toString()).to.be.eq(extendParams.moreMaxFees![0].amount)
})
})
Expand Down Expand Up @@ -1071,7 +1070,7 @@ describe('Settler', () => {

params = await createProposalParams(solverSdk, solverProvider, client, {
intentHash,
proposalParams: { fees: testMaxFees },
proposalParams: { fees: testMaxFees.map((fee) => fee.amount) },
})
})

Expand All @@ -1082,10 +1081,8 @@ describe('Settler', () => {
sdk.getProposalKey(params.intentHash, solver.publicKey)
)
expect(proposal.fees.length).to.be.eq(2)
expect(proposal.fees[0].mint.toString()).to.be.eq(testMaxFees[0].token.toString())
expect(proposal.fees[0].amount.toString()).to.be.eq(testMaxFees[0].amount.toString())
expect(proposal.fees[1].mint.toString()).to.be.eq(testMaxFees[1].token.toString())
expect(proposal.fees[1].amount.toString()).to.be.eq(testMaxFees[1].amount.toString())
expect(proposal.fees[0].toString()).to.be.eq(testMaxFees[0].amount)
expect(proposal.fees[1].toString()).to.be.eq(testMaxFees[1].amount)
})
})
})
Expand Down Expand Up @@ -1153,41 +1150,12 @@ describe('Settler', () => {

params = await createProposalParams(solverSdk, solverProvider, client, {
intentHash,
proposalParams: { fees: largerMaxFees },
proposalParams: { fees: largerMaxFees.map((fee) => fee.amount) },
})
})

itThrowsAnErrorWhenCreatingProposalFromParams('FeeAmountExceedsMaxFee')
})

context('when fees have wrong mint', () => {
const testMaxFees = [
{
token: randomPubkey(),
amount: `${DEFAULT_MAX_FEE}`,
},
]

const otherMaxFees = [
{
token: randomPubkey(),
amount: `${DEFAULT_MAX_FEE}`,
},
]

beforeEach('create intent and proposal params', async () => {
const intentHash = await createValidatedIntent(solverSdk, solverProvider, client, {
maxFees: testMaxFees,
})

params = await createProposalParams(solverSdk, solverProvider, client, {
intentHash,
proposalParams: { fees: otherMaxFees },
})
})

itThrowsAnErrorWhenCreatingProposalFromParams('InvalidFeeMint')
})
})

context('when proposal with same intent_hash and solver already exists', () => {
Expand Down Expand Up @@ -1276,7 +1244,7 @@ describe('Settler', () => {
let intentHash: string
let deadline: string
let instructions: ProposalInstruction[]
let fees: SvmTokenFee[]
let fees: string[]

beforeEach('generate non-existent intent hash and proposal params', async () => {
intentHash = generateIntentHash()
Expand Down
Loading