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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ src
│ ├── <a href="./src/interfaces/IStablecoinDEX.sol">IStablecoinDEX.sol</a>: Stablecoin DEX | <a href="https://docs.tempo.xyz/protocol/exchange/spec#stablecoin-dex">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/stablecoin_dex/mod.rs">Implementation</a>
│ ├── <a href="./src/interfaces/ITempoStreamChannel.sol">ITempoStreamChannel.sol</a>: Streaming payment channel escrow (concept) | <a href="https://github.com/tempoxyz/tempo/blob/main/tips/ref-impls/src/TempoStreamChannel.sol">Implementation</a>
│ ├── <a href="./src/interfaces/ITIP20Factory.sol">ITIP20Factory.sol</a>: TIP-20: Factory Contract | <a href="https://docs.tempo.xyz/protocol/tip20/spec#tip20factory">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/tip20_factory/mod.rs">Implementation</a>
│ ├── <a href="./src/interfaces/ITIP20RewardsRegistry.sol">ITIP20RewardsRegistry.sol</a>: TIP-20: Reward Distribution | <a href="https://docs.tempo.xyz/protocol/tip20-rewards/spec">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/tip20/rewards.rs">Implementation</a>
│ ├── <a href="./src/interfaces/ITIP20RolesAuth.sol">ITIP20RolesAuth.sol</a>: TIP-20: Roles & Permissions | <a href="https://docs.tempo.xyz/protocol/tip20/spec#role-based-access-control">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/tip20/roles.rs">Implementation</a>
│ ├── <a href="./src/interfaces/ITIP20.sol">ITIP20.sol</a>: TIP-20: Core Token Standard | <a href="https://docs.tempo.xyz/protocol/tip20/overview">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/tip20/mod.rs">Implementation</a>
│ ├── <a href="./src/interfaces/ITIP403Registry.sol">ITIP403Registry.sol</a>: TIP-403: Policy Registry System | <a href="https://docs.tempo.xyz/protocol/tip403/overview">Docs</a> | <a href="https://github.com/tempoxyz/tempo/blob/main/crates/precompiles/src/tip403_registry/mod.rs">Implementation</a>
Expand Down
3 changes: 0 additions & 3 deletions src/StdPrecompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {IFeeManager} from "./interfaces/IFeeManager.sol";
import {ISignatureVerifier} from "./interfaces/ISignatureVerifier.sol";
import {ITIP403Registry} from "./interfaces/ITIP403Registry.sol";
import {ITIP20Factory} from "./interfaces/ITIP20Factory.sol";
import {ITIP20RewardsRegistry} from "./interfaces/ITIP20RewardsRegistry.sol";
import {IStablecoinDEX} from "./interfaces/IStablecoinDEX.sol";
import {IValidatorConfig} from "./interfaces/IValidatorConfig.sol";
import {IValidatorConfigV2} from "./interfaces/IValidatorConfigV2.sol";
Expand All @@ -32,8 +31,6 @@ library StdPrecompiles {
IFeeManager internal constant TIP_FEE_MANAGER = IFeeManager(TIP_FEE_MANAGER_ADDRESS);
ITIP403Registry internal constant TIP403_REGISTRY = ITIP403Registry(TIP403_REGISTRY_ADDRESS);
ITIP20Factory internal constant TIP20_FACTORY = ITIP20Factory(TIP20_FACTORY_ADDRESS);
ITIP20RewardsRegistry internal constant TIP20_REWARDS_REGISTRY =
ITIP20RewardsRegistry(TIP20_REWARDS_REGISTRY_ADDRESS);
IStablecoinDEX internal constant STABLECOIN_DEX = IStablecoinDEX(STABLECOIN_DEX_ADDRESS);
INonce internal constant NONCE_PRECOMPILE = INonce(NONCE_ADDRESS);
IValidatorConfig internal constant VALIDATOR_CONFIG = IValidatorConfig(VALIDATOR_CONFIG_ADDRESS);
Expand Down
7 changes: 3 additions & 4 deletions src/interfaces/IFeeAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
pragma solidity >=0.8.13 <0.9.0;

interface IFeeAMM {
error DivisionByZero();
error IdenticalAddresses();
error InvalidAmount();
error InvalidSwapCalculation();
error InvalidToken();
error InsufficientLiquidity();
error InsufficientReserves();
error InvalidAmount();
error DivisionByZero();
error InvalidSwapCalculation();
error InvalidCurrency();

event Burn(
address indexed sender,
Expand Down
32 changes: 29 additions & 3 deletions src/interfaces/IFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,45 @@ pragma solidity >=0.8.13 <0.9.0;
import {IFeeAMM} from "./IFeeAMM.sol";

interface IFeeManager is IFeeAMM {
error CannotChangeWithinBlock();
error InsufficientFeeTokenBalance();

event UserTokenSet(address indexed user, address indexed token);
event ValidatorTokenSet(address indexed validator, address indexed token);
event FeesDistributed(address indexed validator, address indexed token, uint256 amount);

/// @notice Transfers a validator's accumulated fee balance to their address and zeroes the
/// ledger. No-ops when the balance is zero.
/// @param validator The validator to pay out.
/// @param token The fee token to distribute.
function distributeFees(address validator, address token) external;

/// @notice Returns the accumulated fee balance for a validator in a given token.
/// @param validator The validator address.
/// @param token The fee token address.
/// @return The amount of fees accumulated and pending distribution.
function collectedFees(address validator, address token) external view returns (uint256);

/// @notice Sets the caller's preferred fee token for paying transaction fees.
/// Must be a USD-denominated TIP-20 registered in TIP20Factory.
/// @param token The USD-denominated TIP-20 token address.
function setUserToken(address token) external;

/// @notice Sets the caller's preferred fee token for receiving transaction fees.
/// Must be a USD-denominated TIP-20 registered in TIP20Factory.
/// Reverts with `CannotChangeWithinBlock` if the caller is the current block's beneficiary.
/// @param token The USD-denominated TIP-20 token address.
function setValidatorToken(address token) external;

function userTokens(address) external view returns (address);

function validatorTokens(address) external view returns (address);
/// @notice Returns the raw stored fee token preference for a user.
/// Returns the zero address if no preference has been set.
/// @param user The user address.
/// @return The token address stored for the user, or zero if unset.
function userTokens(address user) external view returns (address);

/// @notice Returns the raw stored fee token preference for a validator.
/// Returns the zero address if no preference has been set.
/// @param validator The validator address.
/// @return The token address stored for the validator, or zero if unset.
function validatorTokens(address validator) external view returns (address);
}
9 changes: 9 additions & 0 deletions src/interfaces/INonce.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ interface INonce {
/// @notice Thrown when a nonce value would overflow
error NonceOverflow();

/// @notice Thrown when an expiring nonce has already been used
error ExpiringNonceReplay();

/// @notice Thrown when the expiring nonce set is full and cannot accept more entries
error ExpiringNonceSetFull();

/// @notice Thrown when the expiry timestamp for an expiring nonce is invalid
error InvalidExpiringNonceExpiry();

/// @notice Get the current nonce for a specific account and nonce key
/// @param account The account address
/// @param nonceKey The nonce key (must be > 0, protocol nonce key 0 not supported)
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/ISignatureVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pragma solidity >=0.8.13 <0.9.0;
/// @notice Interface for the TIP-1020 Signature Verification Precompile
/// @dev Deployed at 0x5165300000000000000000000000000000000000
interface ISignatureVerifier {
/// @notice Thrown when the signature bytes are not in the expected encoding format
error InvalidFormat();
/// @notice Thrown when the signature verification fails
error InvalidSignature();

/// @notice Recovers the signer of a Tempo signature (secp256k1, P256, WebAuthn).
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/IStablecoinDEX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ interface IStablecoinDEX {
);
event PairCreated(bytes32 indexed key, address indexed base, address indexed quote);

function MAX_PRICE() external view returns (uint32);
function MAX_PRICE() external pure returns (uint32);

function MAX_TICK() external view returns (int16);
function MAX_TICK() external pure returns (int16);

function MIN_PRICE() external view returns (uint32);
function MIN_PRICE() external pure returns (uint32);

function MIN_TICK() external view returns (int16);
function MIN_TICK() external pure returns (int16);

function TICK_SPACING() external view returns (int16);
function TICK_SPACING() external pure returns (int16);

function PRICE_SCALE() external view returns (uint32);
function PRICE_SCALE() external pure returns (uint32);

function MIN_ORDER_AMOUNT() external view returns (uint128);
function MIN_ORDER_AMOUNT() external pure returns (uint128);

function nextOrderId() external view returns (uint128);

Expand Down
22 changes: 14 additions & 8 deletions src/interfaces/ITIP20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,38 @@ interface ITIP20 {

/// @notice Error when an account has insufficient balance for the requested operation.
error InsufficientBalance(uint256 currentBalance, uint256 expectedBalance, address);
/// @notice Error when an invalid token amount is provided.
error InvalidAmount();

/// @notice Error when an invalid currency identifier is provided.
error InvalidCurrency();
/// @notice Error when an invalid quote token is provided.
error InvalidQuoteToken();
error InvalidBaseToken();
/// @notice Error when an invalid token address is provided.
error InvalidToken();
/// @notice Error when an invalid transfer policy identifier is provided.
error InvalidTransferPolicyId();

/// @notice Error when attempting to transfer to an invalid recipient address.
error InvalidRecipient();
/// @notice Error when an invalid supply cap value is provided.
error InvalidSupplyCap();
/// @notice Error when there is no opted-in supply for the operation.
error NoOptedInSupply();

/// @notice Error when a transfer is blocked by the current transfer policy.
error PolicyForbids();

/// @notice Error when attempting to burn from a protected address.
error ProtectedAddress();
/// @notice Error when minting would exceed the supply cap.
error SupplyCapExceeded();
/// @notice Error when the transaction payload is invalid.
error InvalidPayload();
/// @notice Error when the caller lacks authorization for the requested action.
error Unauthorized();
/// @notice Error when that precompile instance has not been initialized yet.
error Uninitialized();

/// @notice Emitted when an allowance is set between owner and spender.
/// @param owner The address that owns the tokens.
Expand Down Expand Up @@ -183,8 +195,6 @@ interface ITIP20 {

function symbol() external view returns (string memory);

function systemTransferFrom(address from, address to, uint256 amount) external returns (bool);

/// @notice Returns the total token supply.
/// @return The total amount of tokens in circulation.
function totalSupply() external view returns (uint256);
Expand All @@ -195,10 +205,6 @@ interface ITIP20 {
/// @return success True if the transfer was successful.
function transfer(address to, uint256 amount) external returns (bool);

function transferFeePostTx(address to, uint256 refund, uint256 actualUsed) external;

function transferFeePreTx(address from, uint256 amount) external;

/// @notice Transfers tokens from one address to another using allowance.
/// @param from The address to transfer tokens from.
/// @param to The address to transfer tokens to.
Expand Down Expand Up @@ -236,7 +242,7 @@ interface ITIP20 {
/// @dev Returns the total pending claimable reward amount, including stored balance and newly accrued rewards.
/// @param account The address to query pending rewards for.
/// @return The total pending claimable reward amount.
function getPendingRewards(address account) external view returns (uint256);
function getPendingRewards(address account) external view returns (uint128);

// EIP-2612 Permit (TIP-1004)

Expand Down
24 changes: 0 additions & 24 deletions src/interfaces/ITIP20RewardsRegistry.sol

This file was deleted.

5 changes: 5 additions & 0 deletions src/interfaces/ITIP20RolesAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
pragma solidity >=0.8.13 <0.9.0;

interface ITIP20RolesAuth {
/// @notice Thrown when the caller lacks the required role for the requested action
error Unauthorized();

event RoleMembershipUpdated(bytes32 indexed role, address indexed account, address indexed sender, bool hasRole);
event RoleAdminUpdated(bytes32 indexed role, bytes32 indexed newAdminRole, address indexed sender);

function hasRole(address account, bytes32 role) external view returns (bool);

function getRoleAdmin(bytes32 role) external view returns (bytes32);

function grantRole(bytes32 role, address account) external;

function revokeRole(bytes32 role, address account) external;
Expand Down
29 changes: 29 additions & 0 deletions src/interfaces/IValidatorConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ interface IValidatorConfig {
string outboundAddress;
}

/// @notice Get the total number of validators
/// @return The number of validators
function validatorCount() external view returns (uint64);

/// @notice Get validator info by address
/// @param validatorAddress The validator's address
/// @return publicKey The validator's communication public key
/// @return active Whether the validator is active
/// @return index The validator's index
/// @return addr The validator's address
/// @return inboundAddress The validator's inbound address
/// @return outboundAddress The validator's outbound address
function validators(address validatorAddress)
external
view
returns (
bytes32 publicKey,
bool active,
uint64 index,
address addr,
string memory inboundAddress,
string memory outboundAddress
);

/// @notice Get validator address at a given array index
/// @param index The index in the validators array
/// @return The validator's address
function validatorsArray(uint256 index) external view returns (address);

/// @notice Get the complete set of validators
/// @return validators Array of all validators with their information
function getValidators() external view returns (Validator[] memory validators);
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IValidatorConfigV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ interface IValidatorConfigV2 {
/// @notice Thrown when the Ed25519 signature verification fails
error InvalidSignature();

/// @notice Thrown when the signature bytes are not in the expected format
error InvalidSignatureFormat();

/// @notice Thrown when V2 is not yet initialized (writes blocked before init)
error NotInitialized();

Expand Down