Skip to main content

trident_sdk/evm/
abi.rs

1#![allow(clippy::too_many_arguments)]
2
3use alloy_sol_types::sol;
4
5sol! {
6    /// Cross-chain spend specification used for identity hashing.
7    #[derive(Default, Debug, PartialEq, Eq, Hash)]
8    struct SpendSpec {
9        bytes32 srcSpender;
10        uint32 srcDomain;
11        bytes32 srcToken;
12        bytes32 srcDepositContract;
13        uint32 dstDomain;
14        bytes32 dstToken;
15        bytes32 dstDeliveryContract;
16        bytes32 dstRecipient;
17        bytes32 dstCaller;
18        uint256 amount;
19        bytes32 salt;
20    }
21
22    /// EIP-712 typed struct matching the Solidity `SpendIntent`.
23    #[derive(Default, Debug, PartialEq, Eq, Hash)]
24    struct SpendIntent {
25        uint256 maxFee;
26        uint256 expiryHeight;
27        SpendSpec spec;
28    }
29
30    /// Signed payload authorizing one `TridentDelivery` execution.
31    ///
32    /// `expiryHeight` is an exclusive upper bound:
33    /// the attestation is valid only while the destination contract's
34    /// chain-specific block clock is less than `expiryHeight`.
35    #[derive(Default, Debug, PartialEq, Eq, Hash)]
36    struct SpendAttestation {
37        SpendSpec spec;
38        uint256 expiryHeight;
39        uint8 liquidityPath;
40        bytes liquidityPathData;
41    }
42
43    /// Spender/depositor-facing subset of the `TridentDeposits` contract ABI.
44    #[sol(rpc, all_derives)]
45    contract TridentDeposits {
46        error ZeroAmount();
47        error InvalidClaimDomain();
48        error InvalidClaimDepositContract();
49        error InvalidClaimAmount();
50        error InvalidSpendIntentSigner();
51        error ClaimSpendSpecHashAlreadyUsed(bytes32 hash);
52        error SpendIntentExpired();
53        error UnsupportedToken(address token);
54        error EnforcedPause();
55
56        event Deposit(address indexed depositor, address indexed token, uint256 amount);
57        event DepositClaimed(
58            bytes32 indexed spendSpecHash,
59            address indexed token,
60            uint256 amount,
61            address indexed recipient,
62            address signer,
63            uint256 fee,
64            address feeCollector
65        );
66        event DepositBalanceDeficit(
67            address indexed depositor,
68            address indexed token,
69            bytes32 indexed spendSpecHash,
70            uint256 claimAmount,
71            uint256 fee,
72            uint256 availableBalance
73        );
74
75        /// Deposits a supported token into `TridentDeposits`.
76        function deposit(address token, uint256 amount) external;
77
78        /// Returns whether `token` is currently depositable on this deployment.
79        function isTokenSupported(address token) external view returns (bool);
80
81        /// Returns the current supported-token allowlist for this deployment.
82        function getSupportedTokens() external view returns (address[] memory);
83
84        /// Returns the source-side balance tracked in `TridentDeposits` for `depositor` and `token`.
85        ///
86        /// This is the contract's own reimbursement ledger after processed claims.
87        /// It is not the delivery-service balance returned by `TridentClient::get_balance`,
88        /// and it is not a projected or attested amount.
89        function depositedAmount(address depositor, address token) external view returns (uint256);
90
91        /// Returns whether `spendSpecHash` has already been consumed on the source-side contract.
92        function usedSpendSpecHashes(bytes32 spendSpecHash) external view returns (bool);
93
94        /// Returns the source domain this deployment is configured for.
95        function domain() external view returns (uint32);
96
97        /// Returns the paired `TridentDelivery` contract address for this domain.
98        function tridentDelivery() external view returns (address);
99
100        /// Returns the configured withdrawal delay in blocks.
101        function withdrawalDelay() external view returns (uint256);
102
103        /// Returns the current source-side fee collector.
104        function feeCollector() external view returns (address);
105
106        /// Returns the EIP-712 struct hash for `intent`.
107        function spendIntentStructHash(SpendIntent calldata intent) external pure returns (bytes32);
108
109        /// Returns the EIP-712 digest a source spender signs for `intent`.
110        function spendIntentDigest(SpendIntent calldata intent) external pure returns (bytes32);
111
112        /// Recovers the signer of `intent` from its EIP-712 signature.
113        function recoverSpendIntentSigner(SpendIntent calldata intent, bytes calldata signature)
114            external
115            pure
116            returns (address);
117    }
118
119    /// Spender/depositor-facing subset of the `TridentDelivery` contract ABI.
120    #[sol(rpc, all_derives)]
121    contract TridentDelivery {
122        error InvalidAttestationDomain();
123        error InvalidAttestationCaller();
124        error InvalidAttestationRecipient();
125        error InvalidAttestationDeliveryContract();
126        error InvalidAttestationAmount();
127        error InvalidAttestationExpired();
128        error InvalidAttestationToken();
129        error AttestationSpendSpecHashAlreadyUsed(bytes32 hash);
130        error InvalidLiquidityPath();
131        error NotSameChainSpend();
132        error TridentDepositsNotSet();
133        error InvalidAttestationSigner();
134        error UnsupportedToken(address token);
135        error EnforcedPause();
136
137        event SpendAttestationProcessed(
138            bytes32 indexed spendSpecHash,
139            address indexed token,
140            uint256 amount,
141            uint256 usdcMinted,
142            address indexed signer
143        );
144
145        /// Executes a signed spend attestation.
146        function tridentSpend(bytes calldata attestation, bytes calldata signature) external;
147
148        /// Validates `attestation` against the destination contract's current state.
149        ///
150        /// This is useful for preflight simulation before sending `tridentSpend`.
151        function validateSpendAttestation(bytes calldata attestation)
152            external
153            view
154            returns (SpendAttestation memory spendAttestation);
155
156        /// Returns whether `token` is currently spendable on this deployment.
157        function isTokenSupported(address token) external view returns (bool);
158
159        /// Returns the current supported-token allowlist for this deployment.
160        function getSupportedTokens() external view returns (address[] memory);
161
162        /// Returns whether `spendSpecHash` has already been consumed on the destination-side contract.
163        function usedSpendSpecHashes(bytes32 spendSpecHash) external view returns (bool);
164
165        /// Returns the destination domain this deployment is configured for.
166        function domain() external view returns (uint32);
167
168        /// Returns the paired `TridentDeposits` contract used for same-chain settlement.
169        function tridentDeposits() external view returns (address);
170
171        /// Returns whether `signer` is currently authorized to sign spend attestations.
172        function isAttestationSigner(address signer) external view returns (bool);
173
174        /// Returns the keccak256 hash of the encoded attestation payload bytes.
175        function hashSpendAttestation(bytes calldata attestation) external pure returns (bytes32);
176
177        /// Returns the EIP-191 digest of the encoded attestation payload bytes.
178        function digestSpendAttestation(bytes calldata attestation) external pure returns (bytes32);
179    }
180
181    /// Minimal ERC-20 surface used by the SDK's deposit allowance flow.
182    #[sol(rpc)]
183    interface IERC20 {
184        /// Returns the remaining allowance `spender` can pull from `owner`.
185        function allowance(address owner, address spender) external view returns (uint256);
186        /// Sets `spender`'s allowance on the caller's balance to `value`.
187        function approve(address spender, uint256 value) external returns (bool);
188    }
189}