remove getTokens from the factory
This commit is contained in:
@ -9,7 +9,6 @@ contract UniswapV2Factory is IUniswapV2Factory {
|
|||||||
address public feeRecipient;
|
address public feeRecipient;
|
||||||
|
|
||||||
mapping (address => mapping(address => address)) private _getExchange;
|
mapping (address => mapping(address => address)) private _getExchange;
|
||||||
mapping (address => address[2]) private _getTokens;
|
|
||||||
address[] public exchanges;
|
address[] public exchanges;
|
||||||
|
|
||||||
event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint);
|
event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint);
|
||||||
@ -29,10 +28,6 @@ contract UniswapV2Factory is IUniswapV2Factory {
|
|||||||
return _getExchange[token0][token1];
|
return _getExchange[token0][token1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTokens(address exchange) external view returns (address token0, address token1) {
|
|
||||||
return (_getTokens[exchange][0], _getTokens[exchange][1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function exchangesCount() external view returns (uint) {
|
function exchangesCount() external view returns (uint) {
|
||||||
return exchanges.length;
|
return exchanges.length;
|
||||||
}
|
}
|
||||||
@ -49,7 +44,6 @@ contract UniswapV2Factory is IUniswapV2Factory {
|
|||||||
}
|
}
|
||||||
IUniswapV2(exchange).initialize(token0, token1);
|
IUniswapV2(exchange).initialize(token0, token1);
|
||||||
_getExchange[token0][token1] = exchange;
|
_getExchange[token0][token1] = exchange;
|
||||||
_getTokens[exchange] = [token0, token1];
|
|
||||||
emit ExchangeCreated(token0, token1, exchange, exchanges.push(exchange));
|
emit ExchangeCreated(token0, token1, exchange, exchanges.push(exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ interface IUniswapV2Factory {
|
|||||||
|
|
||||||
function sortTokens(address tokenA, address tokenB) external pure returns (address token0, address token1);
|
function sortTokens(address tokenA, address tokenB) external pure returns (address token0, address token1);
|
||||||
function getExchange(address tokenA, address tokenB) external view returns (address exchange);
|
function getExchange(address tokenA, address tokenB) external view returns (address exchange);
|
||||||
function getTokens(address exchange) external view returns (address token0, address token1);
|
|
||||||
function exchanges(uint) external view returns (address exchange);
|
function exchanges(uint) external view returns (address exchange);
|
||||||
function exchangesCount() external view returns (uint);
|
function exchangesCount() external view returns (uint);
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,6 @@ describe('UniswapV2Factory', () => {
|
|||||||
await expect(factory.createExchange(...tokens.slice().reverse())).to.be.reverted // UniswapV2Factory: EXCHANGE_EXISTS
|
await expect(factory.createExchange(...tokens.slice().reverse())).to.be.reverted // UniswapV2Factory: EXCHANGE_EXISTS
|
||||||
expect(await factory.getExchange(...tokens)).to.eq(create2Address)
|
expect(await factory.getExchange(...tokens)).to.eq(create2Address)
|
||||||
expect(await factory.getExchange(...tokens.slice().reverse())).to.eq(create2Address)
|
expect(await factory.getExchange(...tokens.slice().reverse())).to.eq(create2Address)
|
||||||
expect(await factory.getTokens(create2Address)).to.deep.eq([TEST_ADDRESSES.token0, TEST_ADDRESSES.token1])
|
|
||||||
expect(await factory.exchanges(0)).to.eq(create2Address)
|
expect(await factory.exchanges(0)).to.eq(create2Address)
|
||||||
expect(await factory.exchangesCount()).to.eq(1)
|
expect(await factory.exchangesCount()).to.eq(1)
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export async function exchangeFixture(provider: providers.Web3Provider, [wallet]
|
|||||||
const exchangeAddress = await factory.getExchange(tokenA.address, tokenB.address)
|
const exchangeAddress = await factory.getExchange(tokenA.address, tokenB.address)
|
||||||
const exchange = new Contract(exchangeAddress, JSON.stringify(UniswapV2.abi), provider)
|
const exchange = new Contract(exchangeAddress, JSON.stringify(UniswapV2.abi), provider)
|
||||||
|
|
||||||
const [token0Address] = await factory.getTokens(exchangeAddress)
|
const token0Address = (await exchange.token0()).address
|
||||||
const token0 = tokenA.address === token0Address ? tokenA : tokenB
|
const token0 = tokenA.address === token0Address ? tokenA : tokenB
|
||||||
const token1 = tokenA.address === token0Address ? tokenB : tokenA
|
const token1 = tokenA.address === token0Address ? tokenB : tokenA
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user