Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
Background
ERC-2266 proposes using atomic swaps for direct token exchanges and American call options without a trusted intermediary.
This article explains and expands on the following proposal.
The Japanese article recorded ERC-2266 as Last Call on December 30, 2023. That is a historical snapshot.
I also cover other ERCs here.
Overview
This proposed standard lets token contracts support American call options. An American call gives its holder the right to buy an asset at a fixed price before a deadline. The proposal uses an atomic swap to coordinate the exchange so the assets can be claimed only under the agreed conditions.
Atomic swaps
Atomic swaps allow parties to exchange digital assets directly without a trusted intermediary. In cross-chain settings, separate transactions coordinate the exchange. The intended outcome is that both sides complete it or both can recover their original assets.
How atomic swaps work
- Cross-chain exchange
- An atomic swap can coordinate an exchange across different chains, such as Bitcoin and Ethereum.
- Reduced counterparty trust
- Smart contracts or protocol rules enforce the agreed conditions. The parties do not have to rely solely on each other's promises.
- Hashed timelock contracts (HTLCs)
- HTLCs commonly lock assets until a party supplies a secret that hashes to an agreed value.
- Time limits
- After the deadline, the original owner can reclaim assets that have not been redeemed.
Atomic swap process
- Initiate the exchange.
- One party creates an HTLC and locks assets against a hash.
- Accept the exchange.
- The other party locks assets under another HTLC using the same hash.
- Reveal the secret.
- The initiator uses the secret to redeem the other party's assets. This reveals the secret so the other party can redeem the initiator's assets.
- Complete the exchange.
- Both parties redeem their respective assets from the HTLCs.
Benefits of atomic swaps
- Decentralization
- Parties can transact directly without relying on a centralized exchange for settlement.
- Costs
- In some cases, fees may be lower than through an intermediary.
- Interoperability
- Atomic swaps can support liquidity across chains.
Implementation can be complex, and only compatible chains can participate. The approach can nevertheless support more decentralized asset exchange.
American call options
An American call option gives its holder the right to buy an asset, often a share of stock, at a predetermined strike price at any time through expiration. Calls can also cover other types of assets.
Main features of American call options
- Right to buy
- The holder may buy the asset at the strike price and can also let the option expire.
- Exercise period
- An American-style option may be exercised before or on expiration. A European-style option can be exercised only on the expiration date.
- Premium
- The buyer pays a premium. Its value depends on factors such as the asset price, strike price, time remaining, and volatility.
Benefits of American call options
- Flexibility
- The holder can exercise during the option's term as market conditions change.
- Potential upside
- If the asset price exceeds the strike, exercising can yield value. Net profit also depends on the premium and costs.
- Risk management
- For the holder of a standalone long call, the option position can expire worthless, limiting the loss on the option itself to the premium paid.
Use cases
- Speculation
- A call provides exposure to a possible increase in the asset's price.
- Hedging
- Options can be part of hedges. A long call generally hedges an increase in the cost of buying an asset, while a standalone long call does not protect an existing long holding against a price decline.
Considerations
- Time decay
- An option's time value can fall as the expiration date approaches.
- Volatility
- Changes in market volatility can materially affect the option's value.
Exercise flexibility makes American calls useful in certain strategies, but their value and risk depend on the terms and market conditions.
An HTLC locks an asset until a party provides the secret or the refund time arrives. It lets the parties enforce the exchange conditions without handing assets to an intermediary.
HTLCs
A hashed timelock contract is a smart contract that conditions settlement on a valid secret and defines how the original depositor can reclaim an asset if settlement does not occur.
Main features of HTLCs
- Hashlock
- The initiator chooses a random secret and shares its hash.
- A party must submit a secret that matches the hash to redeem the asset.
- The other participant can learn the secret when it is revealed during redemption.
- Timelock
- The contract defines a refund deadline.
- After that deadline, the original owner can reclaim assets that have not been redeemed.
Benefits of HTLCs
- Reduced counterparty trust
- Both sides can check the required conditions in advance.
- Decentralization
- The contracts coordinate the exchange directly onchain.
- Atomic settlement
- The intended result is that both sides exchange their assets or can reclaim them if the swap is abandoned.
Examples of HTLC use
- Atomic swaps
- Parties can exchange assets on different chains, such as Bitcoin and Ethereum.
- Conditional payments
- A payment can settle once an agreed condition unlocks the required secret.
HTLCs are a building block for these arrangements. The security of a particular flow depends on the implementation and the surrounding protocol.
The proposal defines terminology, interfaces, and a reference implementation for incorporating the approach into token contracts. It is intended to support compatible option flows involving tokens such as ERC-20 and ERC-721 assets.
Motivation
Atomic swaps let users exchange tokens directly. HTLCs supply the hashlocks and time limits that coordinate the two sides.
An HTLC swap also gives the initiator optionality. Once the other party locks assets, the initiator may have several hours to decide whether to proceed. That provides time to observe exchange rates before revealing the secret or abandoning the swap.
This timing resembles an American call option. Its holder can choose whether to buy an asset at the agreed price during a specified period, and the initiator of the atomic swap has a comparable choice about completing the exchange.
The cited research proposes an atomic-swap protocol for American calls without a trusted intermediary. Its design addresses the risk that one party could lock the other's funds while retaining an unfair advantage.
ERC-2266 aims to integrate this approach with existing token standards such as ERC-20 and ERC-721 so applications can offer a common option and exchange flow.
Specification
Definitions
The contract sets the terms for exchanging tokens between two parties.
- Initiator
- Advertises the swap and sets its terms.
- Participant
- Accepts the advertised terms and takes part.
- Asset
- The token quantity to be exchanged.
- Premium
- The amount the initiator pays the participant for the option.
- Redeem
- Claim tokens deposited by the other party.
- Refund
- Reclaim one's own tokens once the applicable timelock expires.
- Secret
- A random value chosen by the initiator.
- Secret hash
- The hash of the secret used to set up the HTLC.
- Timelock
- A timestamp defining the deadline for redeeming an asset and when the refund path becomes available.
Hashlocks and timelocks coordinate the exchange and specify what each party can do when the other party does not complete its side.
Storage variables
The contract records the swap terms and tracks each asset and the premium.
swap
mapping(bytes32 => Swap) public swap;Stores the parties and tokens involved in the transaction. The secretHash identifies the swap.
initiatorAsset
mapping(bytes32 => InitiatorAsset) public initiatorAsset;Tracks the initiator's asset amount, refund time, and status for a particular secretHash.
participantAsset
mapping(bytes32 => ParticipantAsset) public participantAsset;Tracks the participant's asset amount, refund time, and status for the same swap identifier.
premiumAsset
mapping(bytes32 => Premium) public premium;Tracks the initiator's premium amount, refund time, and status by secretHash.
Using the same swap identifier across the mappings connects the status of the assets and the premium to the corresponding parties and swap terms.
Methods
The methods define how parties set up, fund, redeem, and refund a swap.
setup
Records the parties, token contracts, amounts, premium, and secret hash.
function setup(bytes32 secretHash, address payable initiator, address tokenA, address tokenB, uint256 initiatorAssetAmount, address payable participant, uint256 participantAssetAmount, uint256 premiumAmount) public payableinitiate
Lets the initiator lock its tokens in the contract and set the asset refund time.
function initiate(bytes32 secretHash, uint256 assetRefundTime) public payablefillPremium
Lets the initiator deposit the premium and set its refund time.
function fillPremium(bytes32 secretHash, uint256 premiumRefundTime) public payableparticipate
Lets the participant accept the terms and lock its own tokens.
function participate(bytes32 secretHash, uint256 assetRefundTime) public payableredeemAsset
Lets one party claim the other's tokens by supplying the secret that unlocks the hashlock.
function redeemAsset(bytes32 secret, bytes32 secretHash) publicrefundAsset
Lets a depositor reclaim an unredeemed asset after the timelock expires.
function refundAsset(bytes32 secretHash) publicredeemPremium
Lets the participant claim the premium after participating, once the participant's asset has been redeemed or refunded.
function redeemPremium(bytes32 secretHash) publicrefundPremium
Lets the initiator reclaim the premium after its refund time under the contract's conditions.
function refundPremium(bytes32 secretHash) publicTogether these functions define the sequence from configuring the trade through settling each asset or recovering it after a deadline.
Events
Events mark changes in swap state so the parties can track the exchange.
SetUp
event SetUp(bytes32 secretHash, address initiator, address participant, address tokenA, address tokenB, uint256 initiatorAssetAmount, uint256 participantAssetAmount, uint256 premiumAmount);SetUp records the initial terms, including the parties, tokens, asset amounts, and premium.
Initiated
event Initiated(uint256 initiateTimestamp, bytes32 secretHash, address initiator, address participant, address initiatorAssetToken, uint256 initiatorAssetAmount, uint256 initiatorAssetRefundTimestamp);Initiated indicates that the initiator locked their asset in the contract.
Participated
event Participated(uint256 participateTimestamp, bytes32 secretHash, address initiator, address participant, address participantAssetToken, uint256 participantAssetAmount, uint256 participantAssetRefundTimestamp);Participated indicates that the participant joined the swap and locked their asset.
PremiumFilled
event PremiumFilled(uint256 fillPremiumTimestamp, bytes32 secretHash, address initiator, address participant, address premiumToken, uint256 premiumAmount, uint256 premiumRefundTimestamp);PremiumFilled indicates that the initiator deposited and locked the premium.
InitiatorAssetRedeemed/ParticipantAssetRedeemed
event InitiatorAssetRedeemed(uint256 redeemTimestamp, bytes32 secretHash, bytes32 secret, address redeemer, address assetToken, uint256 amount);event ParticipantAssetRedeemed(uint256 redeemTimestamp, bytes32 secretHash, bytes32 secret, address redeemer, address assetToken, uint256 amount);These events indicate that a counterparty redeemed a deposited asset before its deadline by supplying the required secret.
InitiatorAssetRefunded/ParticipantAssetRefunded
event InitiatorAssetRefunded(uint256 refundTimestamp, bytes32 secretHash, address refunder, address assetToken, uint256 amount);event ParticipantAssetRefunded(uint256 refundTimestamp, bytes32 secretHash, address refunder, address assetToken, uint256 amount);These events indicate that an unredeemed asset was returned to its depositor after its timelock expired.
PremiumRedeemed
event PremiumRedeemed(uint256 redeemTimestamp,bytes32 secretHash,address redeemer,address token,uint256 amount);PremiumRedeemed indicates that the participant claimed the premium after the initiator redeemed the participant's asset or the participant recovered it after the deadline.
PremiumRefunded
event PremiumRefunded(uint256 refundTimestamp, bytes32 secretHash, address refunder, address token, uint256 amount);PremiumRefunded indicates that the initiator recovered the premium when the participant did not join by the deadline.
Together these events show which swap stage completed, letting participants and applications track the status from the event log.
Additional notes
The protocol aims to let both parties inspect the conditions before committing assets.
Using HTLCs
The contracts coordinate redemption with a shared secret and provide refund paths when the exchange is not completed.
The participant's choice
After the initiator locks its tokens, the participant checks the terms and decides whether to join.
The initiator's choice
After the participant locks its tokens, the initiator decides whether to complete the exchange.
Claiming the premium
The participant must join the swap and meet the relevant conditions to claim the premium. This gives the participant an incentive to lock the asset.
Recovering the premium
If the participant never joins, the initiator can recover the premium under the refund rules.
These rules let the parties make decisions using the terms and state of the swap.
Security considerations
Timing the exchange
The initiator's asset must stay locked long enough for the whole exchange. The original article refers to initiateTimestamp; that is the recorded start time, while the relevant refund deadline controls how long the asset remains locked.
Checking the premium
The participant should verify that the initiator has deposited the premium before locking its own asset. This helps ensure the premium is available under the agreed terms.
Compatibility
The proposal adds a swap contract interface without changing existing ERC-20 or ERC-721 interfaces.
Implementation
The reference implementation is available here.
https://eips.ethereum.org/assets/eip-2266/Example.sol
References
- Hash Time Locked Contracts
- An Argument For Single-Asset Lightning Network
- On the optionality and fairness of Atomic Swaps
Citation
Runchao Han runchao.han@monash.edu, Haoyu Lin chris.haoyul@gmail.com, Jiangshan Yu jiangshan.yu@monash.edu, "ERC-2266: Atomic Swap-based American Call Option Contract Standard [DRAFT]," Ethereum Improvement Proposals, no. 2266, August 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2266.
Conclusion
ERC-2266 proposes a way to build American call options from direct token exchanges. Hashlocks and deadlines coordinate redemption and refunds, while the premium compensates the participant for taking part.
Questions are welcome by direct message.
You can find more of my writing here.


