There is opensource asset exchange called Peatio written in ruby. You can look into its source code to see what happens with assets during their lifetime there.
Mainly there are 3 steps for exchange:
- Deposit - put real coins to exchange's accounts
- Exchange - change coins, by changing just values of accounts' balances
- Withdraw - send real coins from exchange's accounts to end user
When user sends deposit request, exchange generates new address (sends rpc request to btc node), and assigns it to deposit entity in db. User have to send sufficient amount of btc, to fulfill deposit. When special daemon watcher finds incoming transaction to the address assigned to some deposit entity, it compares incoming amount with required one and waits for confirmations. If there are enough btcs and confirmations - daemon increases amount of user's account balance.
Then, during user's exchanges, exchange engine just changes numbers in db, so no real transactions are provided. This allows very fast fast and network fee free exchanges.
When user decides to spend bitcoins from account, he sends withdrawal request to exchange. Exchange checks user's balance and if there are enough coins, sends them from its wallet to user's address and decreases user's balance
In such system security of the main server is critical. All coins are stored on wallets of the system and can be spent by it. So cold wallet is usually used in such exchanges. Nearly 90% of total amount of all coins are sent to some secured wallet: hardware wallet or at least wallet, that is stored on a system that doesn't have internet connection. When there is not enough coins on hot wallet to create withdrawal, alert is sent to admin, and he manually sends some coins from cold wallet to hot.
If you don't want to allow trading, and just want exchange, you can remove Exchange step, and create withdrawal just after deposit fulfillment. But then you have to determine price of the pair.
This is not the only approach to asset exchanges. There are also approaches when users control their wallets on exchange, and approaches when decisions to change user's balance are taken by several nodes together.