stellar_interchain_token_service/executable.rs
1//! InterchainTokenExecutable
2//!
3//! This is an executable interface that accepts an interchain token from ITS contract
4//! along with an arbitrary message.
5//!
6//! This is similar to the [`AxelarExecutableInterface`](stellar_axelar_gateway::executable::AxelarExecutableInterface) but meant for messages sent with an ITS token.
7
8pub use stellar_axelar_std::InterchainTokenExecutable;
9use stellar_axelar_std::{
10 contractclient, derive_only, soroban_sdk, Address, Bytes, BytesN, Env, String,
11};
12
13/// This trait must be implemented by a contract to be compatible with the [`InterchainTokenExecutableInterface`].
14///
15/// To make a contract executable by the interchain token service contract, it must implement the [`InterchainTokenExecutableInterface`] trait.
16/// For security purposes and convenience, sender authorization and other commonly shared code necessary to implement that trait can be automatically generated with the [`InterchainTokenExecutable`] derive macro.
17/// All parts that are specific to an individual ITS executable contract are collected in this [`CustomInterchainTokenExecutable`] trait and must be implemented by the contract to be compatible with the [`InterchainTokenExecutableInterface`] trait.
18///
19/// Do NOT add the implementation of [`CustomInterchainTokenExecutable`] to the public interface of the contract, i.e. do not annotate the `impl` block with `#[contractimpl]`
20pub trait CustomInterchainTokenExecutable {
21 /// The type of error the [`CustomInterchainTokenExecutable::__authorized_execute_with_token`] function returns. Generally matches the error type of the whole contract.
22 type Error: Into<stellar_axelar_std::Error>;
23
24 /// Returns the address of the interchain token service contract that is authorized to execute arbitrary payloads on this contract
25 fn __interchain_token_service(env: &Env) -> Address;
26
27 /// The custom execution logic that takes in an arbitrary payload and a token.
28 /// At the time this function is called, the calling address has already been verified as the correct interchain token service contract.
29 fn __authorized_execute_with_token(
30 env: &Env,
31 source_chain: String,
32 message_id: String,
33 source_address: Bytes,
34 payload: Bytes,
35 token_id: BytesN<32>,
36 token_address: Address,
37 amount: i128,
38 ) -> Result<(), Self::Error>;
39}
40
41derive_only!();
42
43/// Interface for an Interchain Token Executable app. Use the [`InterchainTokenExecutable`] derive macro to implement this interface.
44///
45/// **DO NOT IMPLEMENT THIS MANUALLY!**
46#[contractclient(name = "InterchainTokenExecutableClient")]
47pub trait InterchainTokenExecutableInterface: CustomInterchainTokenExecutable + DeriveOnly {
48 /// Returns the address of the interchain token service contract that is authorized to execute arbitrary payloads on this contract
49 fn interchain_token_service(env: &Env) -> Address;
50
51 /// Execute a cross-chain message with the given payload and token.
52 /// # Authorization
53 /// - Only callable by ITS contract.
54 fn execute_with_interchain_token(
55 env: &Env,
56 source_chain: String,
57 message_id: String,
58 source_address: Bytes,
59 payload: Bytes,
60 token_id: BytesN<32>,
61 token_address: Address,
62 amount: i128,
63 ) -> Result<(), stellar_axelar_std::Error>;
64}