Sha256: dc27a35a0afa857d3893d0a950dc292ad082a8594b04ed2b7cf07019afa58c29

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
0xfacet-uniswap-0.0.1 lib/0xfacet/uniswap/UniswapV2Factory.rb