Settle Trade Payment

EVM-Compatible Networks

Authorized Settlement with Fee Deduction

function settlement(
    bytes32 tradeId,
    uint256 totalFee,
    address toAddress,
    TradeDetail calldata detail,
    bytes calldata presign,
    bytes calldata mpcSignature
) external nonReentrant;

πŸ” Permissioned Execution

  • Can only be executed by authorized actors capable of producing valid mpcSignature and presign.

  • Ensures that settlement is authorized through off-chain coordination and validation.

πŸ”Ž Trade Validation

  • Callable only if block.timestamp <= detail.timeout.

  • Prevents settlement after the trade has expired.

  • Validates that the provided TradeDetail matches the recorded hash for the tradeId.

  • Guards against tampering and unauthorized settlements.

πŸ”‘ Signature Verification

  • Verifies a pre-signature from the ephemeral asset signer.

  • Confirms the settlement recipient (toAddress) and authorized amount.

  • Requires a valid signature from the MPC to authorize settlement.

  • Ensures consensus among off-chain nodes has been reached before finalizing the trade.

πŸ’° Protocol Fee Handling

  • If totalFee is non-zero, the specified amount is transferred to protocol.pFeeAddr() before proceeding with settlement.

  • Guarantees protocol fee collection before fund distribution.

πŸ’Έ Transfer Execution

  • Transfers the remaining amount (amount - totalFee) to the PMM’s designated receiving address (toAddress).

πŸ“’ Event Emission

  • Emits a Settled event containing all relevant data: tradeId, fee recipient, final recipient, total fee, and transferred amount.

Bitcon networks

Solana Networks

Authorized Settlement with Fee Deduction

pub struct SettlementArgs {
    /// The tradeId, unique identifier for the trade
    pub trade_id: [u8; 32], // uint256
}
pub fn handler_settlement<'c: 'info, 'info>(
    ctx: Context<'_, '_, 'c, 'info, SettlementAccounts<'info>>,
    settlement_args: SettlementArgs,
) -> Result<()>                                                                                        

πŸ” Permissioned Execution

  • Can only be executed by authorized actors capable of producing valid mpcSignature and ephemeralSignature.

  • Ensures that settlement is authorized through off-chain coordination and validation.

πŸ”Ž Trade Validation

  • Callable only if Clock::get().unix_timestamp <= trade_detail.timeout.

  • Can only be executed for the TradeDatail in the Deposited state.

  • Prevents settlement after the trade has expired.

  • Validates that the provided TradeDetail matches the recorded hash for the tradeId.

  • Guards against tampering and unauthorized settlements.

πŸ”‘ Signature Verification

  • Verifies a signature from the ephemeral asset signer.

  • Confirms the settlement recipient (toAddress) and authorized amount.

  • Requires a valid signature from the MPC to authorize settlement.

  • Ensures consensus among off-chain nodes has been reached before finalizing the trade.

πŸ’° Protocol Fee Handling

  • If totalFee is non-zero, the specified amount is transferred to protocol account before proceeding with settlement.

  • Guarantees protocol fee collection before fund distribution.

πŸ’Έ Transfer Execution

  • Transfers the remaining amount (amount - totalFee) to the PMM’s designated receiving address (toAddress).

  • Update the status of corresponding TradeDetail account from Deposited to Settled

πŸ“Œ Note: This function represents the final stage of a successful trade. It finalizes the transfer of funds according to MPC authorization and ensures both the PMM and protocol receive their respective payments securely.

Last updated