Skip to content

Commit 9de0cb5

Browse files
eee4017hydai
authored andcommitted
[Example] Add description on testing Factory/Pair
1 parent d6a41d6 commit 9de0cb5

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

example/uniswap-v2/README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,43 @@ Some interfaces inherented from ERC20 and some basic function could still be tes
127127
python uniswap-test.py --input UniswapV2Pair.wasm
128128
```
129129

130-
The listed IERC20 interface below could be tested after the testing environment support deployment.
131-
132-
```solidity
133-
function factory() external view returns (address);
134-
function token0() external view returns (address);
135-
function token1() external view returns (address);
136-
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
137-
function price0CumulativeLast() external view returns (uint);
138-
function price1CumulativeLast() external view returns (uint);
139-
function kLast() external view returns (uint);
140-
141-
function mint(address to) external returns (uint liquidity);
142-
function burn(address to) external returns (uint amount0, uint amount1);
143-
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
144-
function skim(address to) external;
145-
function sync() external;
146-
147-
function initialize(address, address) external;
148-
```
130+
### Uniswap V2 Factory
131+
132+
After ERC20 tokens are deployed at some address, say `tokenA` is deployed at `addressA` and `tokenB` is deployed at `addressB` , we could create pair with Uniswap V2 Factory. We could call `createPair` API to create a pair of tokens.
133+
134+
```
135+
function createPair(address tokenA, address tokenB) external returns (address pair);
136+
```
137+
138+
Further, after we create a pair of tokens, we could then validate the factory by checking its read-only functions.
139+
140+
```
141+
function getPair(address tokenA, address tokenB) external view returns (address pair);
142+
function allPairs(uint) external view returns (address pair);
143+
```
144+
145+
With the above process with could test the correctness of Uniswap V2 Factory.
146+
147+
For more testing process, please checkout [UniswapV2Factory test script](https://github.com/Uniswap/v2-core/blob/master/test/UniswapV2Factory.spec.ts)
148+
149+
150+
151+
### Uniswap V2 Pair
152+
153+
After we validate Uniswap V2 Factory, we could then validate Uniswap V2 Pair, which is the main interface of Uniswap. Pairs serve as automated market makers and keep track of pool token balances. List 5 test below,
154+
155+
1. Mint `function mint(address to) external returns (uint liquidity);`
156+
+ Creates pool tokens to some address
157+
2. Swap token `function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;`
158+
+ Two direction of swapping
159+
+ pay for the withdrawn ERC20 tokens with the corresponding pair tokens
160+
+ return the withdrawn ERC20 tokens along with a small fee
161+
3. burn `function burn(address to) external returns (uint amount0, uint amount1);`
162+
+ Destroys pool tokens of some address
163+
4. price Cumulative `function price{0,1}CumulativeLast() external view returns (uint);`
164+
+ The `price{0,1}CumulativeLast` is used by oracle to fetch the current accumulated price value
165+
+ price0CumulativeLast = Token_1 / Token_0
166+
+ price1CumulativeLast = Token_0 / Token_1
167+
+ To calculate the correct price, please check [utilities.ts:encodePrice](https://github.com/Uniswap/v2-core/blob/master/test/shared/utilities.ts#L97), it divide the liquidity of 2 toekns
168+
169+
For more testing process, please checkout [UniswapV2Pair test script](https://github.com/Uniswap/v2-core/blob/master/test/UniswapV2Pair.spec.ts)

0 commit comments

Comments
 (0)