Decentralized exchanges based on automated market makers (AMMs) use smart contracts to execute crypto-asset swaps without order matching by a centralized exchange operator. This article examines the role of such code under Indonesian contract law, the assessment of token swaps under Islamic law, and legal protection for DEX users. The research is normative and applies statutory, conceptual, and limited comparative approaches covering Malaysia, Singapore, the United Arab Emirates, and the European Union. It finds that smart-contract code may form or perform part of a transaction, while legal validity still depends on consent, capacity, a sufficiently certain object, and a lawful cause. Pseudonymity chiefly complicates verification, evidence, and remedies. Under Islamic law, a smart contract is not a contracting subject. Bai‘ al-mu‘athah may explain consent expressed through conduct, but the parties must still be identified by examining ownership, protocol structure, and the allocation of control. Token classification and the possible presence of riba, gharar, maysir, tadlis, and qabd must be assessed in light of the asset's function and the circumstances of the transaction. User protection may be strengthened through identifiable responsibility, risk disclosure, security governance, complaint handling, and clear dispute-resolution arrangements. The legal assessment of DEX transactions is therefore fact-specific rather than determined solely by the technology employed. Keywords: smart contract; decentralized exchange; automated market maker; Islamic contract; consumer protection; crypto-assets