-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniswapV2Factory.rb
63 lines (42 loc) · 1.75 KB
/
UniswapV2Factory.rb
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
pragma :rubidity, "1.0.0"
import 'UniswapV2Pair'
contract :UniswapV2Factory do
address :public, :feeTo
address :public, :feeToSetter
mapping ({ address: mapping({ address: :address })}), :public, :getPair
array :address, :public, :allPairs
event :PairCreated, { token0: :address, token1: :address, pair: :address, pairLength: :uint256 }
constructor(_feeToSetter: :address) {
s.feeToSetter = _feeToSetter
}
function :allPairsLength, :public, :view, returns: :uint256 do
return s.allPairs.length
end
function :getAllPairs, :public, :view, returns: [:address] do
return s.allPairs
end
function :createPair, { tokenA: :address, tokenB: :address }, :public, returns: :address do
require(tokenA != tokenB, 'Scribeswap: IDENTICAL_ADDRESSES')
token0, token1 = tokenA.cast(:uint256) < tokenB.cast(:uint256) ? [tokenA, tokenB] : [tokenB, tokenA]
require(token0 != address(0), "Scribeswap: ZERO_ADDRESS");
require(s.getPair[token0][token1] == address(0), "Scribeswap: PAIR_EXISTS");
salt = keccak256(abi.encodePacked(token0, token1))
pair = new UniswapV2Pair({ salt: salt })
pair.init(token0, token1)
s.getPair[token0][token1] = pair;
s.getPair[token1][token0] = pair;
s.allPairs.push(pair)
emit(:PairCreated, { token0: token0, token1: token1, pair: pair, pairLength: s.allPairs.length })
return pair
end
function :setFeeTo, { _feeTo: :address }, :public do
require(msg.sender == feeToSetter, "Scribeswap: FORBIDDEN")
s.feeTo = _feeTo
return nil
end
function :setFeeToSetter, { _feeToSetter: :address }, :public do
require(msg.sender == feeToSetter, "Scribeswap: FORBIDDEN")
s.feeToSetter = _feeToSetter
return nil
end
end