-
Notifications
You must be signed in to change notification settings - Fork 61
/
NiftyswapFactory.sol
40 lines (32 loc) · 1.4 KB
/
NiftyswapFactory.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
34
35
36
37
38
39
40
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;
import {NiftyswapExchange} from "./NiftyswapExchange.sol";
import {INiftyswapFactory} from "../interfaces/INiftyswapFactory.sol";
contract NiftyswapFactory is INiftyswapFactory {
//
// Events and Variables
//
// tokensToExchange[erc1155_token_address][currency_address][currency_token_id]
mapping(address => mapping(address => mapping(uint256 => address))) public override tokensToExchange;
//
// Functions
//
/**
* @notice Creates a NiftySwap Exchange for given token contract
* @param _token The address of the ERC-1155 token contract
* @param _currency The address of the currency token contract
* @param _currencyID The id of the currency token
*/
function createExchange(address _token, address _currency, uint256 _currencyID) public override {
require(
tokensToExchange[_token][_currency][_currencyID] == address(0x0),
"NiftyswapFactory#createExchange: EXCHANGE_ALREADY_CREATED"
);
// Create new exchange contract
NiftyswapExchange exchange = new NiftyswapExchange(_token, _currency, _currencyID);
// Store exchange and token addresses
tokensToExchange[_token][_currency][_currencyID] = address(exchange);
// Emit event
emit NewExchange(_token, _currency, _currencyID, address(exchange));
}
}