-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap.sol
33 lines (27 loc) · 1 KB
/
swap.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Atoken is ERC20 {
constructor(string memory _name, string memory _symbol, uint256 amount) ERC20(_name, _symbol) {
_mint(msg.sender, amount * (10 ** decimals()));
}
}
contract Btoken is ERC20 {
constructor(string memory _name, string memory _symbol, uint256 amount) ERC20(_name, _symbol) {
_mint(msg.sender, amount * (10 ** decimals()));
}
}
contract swap {
Atoken public immutable a;
Btoken public immutable b;
constructor(address _tokenA, address _tokenB) {
a = Atoken(_tokenA);
b = Btoken(_tokenB);
}
//_ownerA should approve this contract to spend token on its behalf
//same comment for _ownerB
function swapToken(address _ownerA, uint256 _amountA, address _ownerB, uint256 _amountB) external {
a.transferFrom(_ownerA, _ownerB, _amountA);
b.transferFrom(_ownerB, _ownerA, _amountB);
}
}