use defuse_core::{
Deadline, Result, accounts::AccountEvent, engine::deltas::InvariantViolated, fees::Pips,
intents::IntentEvent, payload::multi::MultiPayload,
};
use near_plugins::AccessControllable;
use near_sdk::{Promise, PublicKey, ext_contract, near};
use serde_with::serde_as;
use crate::fees::FeesManager;
#[ext_contract(ext_intents)]
pub trait Intents: FeesManager {
fn execute_intents(&mut self, signed: Vec<MultiPayload>);
fn simulate_intents(&self, signed: Vec<MultiPayload>) -> SimulationOutput;
}
#[cfg_attr(
all(feature = "abi", not(target_arch = "wasm32")),
serde_as(schemars = true)
)]
#[cfg_attr(
not(all(feature = "abi", not(target_arch = "wasm32"))),
serde_as(schemars = false)
)]
#[near(serializers = [json])]
#[derive(Debug, Clone)]
pub struct SimulationOutput {
pub intents_executed: Vec<IntentEvent<AccountEvent<'static, ()>>>,
pub min_deadline: Deadline,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub invariant_violated: Option<InvariantViolated>,
pub state: StateOutput,
}
impl SimulationOutput {
pub fn into_result(self) -> Result<(), InvariantViolated> {
if let Some(unmatched_deltas) = self.invariant_violated {
return Err(unmatched_deltas);
}
Ok(())
}
}
#[near(serializers = [json])]
#[derive(Debug, Clone)]
pub struct StateOutput {
pub fee: Pips,
}
#[ext_contract(ext_relayer_keys)]
pub trait RelayerKeys: AccessControllable {
fn add_relayer_key(&mut self, public_key: PublicKey) -> Promise;
fn do_add_relayer_key(&mut self, public_key: PublicKey);
fn delete_relayer_key(&mut self, public_key: PublicKey) -> Promise;
}