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
andpresign
.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 thetradeId
.Guards against tampering and unauthorized settlements.
π Signature Verification
Verifies a pre-signature from the ephemeral asset signer.
Confirms the settlement recipient (
toAddress
) and authorizedamount
.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 toprotocol.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
andephemeralSignature
.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 theDeposited
state.Prevents settlement after the trade has expired.
Validates that the provided
TradeDetail
matches the recorded hash for thetradeId
.Guards against tampering and unauthorized settlements.
π Signature Verification
Verifies a signature from the ephemeral asset signer.
Confirms the settlement recipient (
toAddress
) and authorizedamount
.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 toprotocol
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
toSettled
π 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