BuniCornRouter02

Code

Address

BuniCornRouter02 is deployed at 0x689E37aFb4236A5cF808cA05a8D1c564200fA0E4 on the Binance SmartChain mainnet.

Read-Only Functions

factory

1
function factory() external pure returns (address);
Copied!
Returns the factory address.

quote

1
function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
Copied!
Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.

getAmountsOut

1
function getAmountsOut(uint256 amountIn, address[] memory poolsPath, IERC20[] memory path) external view returns (uint256[] memory amounts);
Copied!
First calls verifyPoolsPathSwap to verify the validity of the poolsPath and path variables.
Then, given an input asset amount and an array of token and corresponding pool addresses, calculates all subsequent maximum output token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountOut.

getAmountsIn

1
function getAmountsIn(uint256 amountOut, address[] memory poolsPath, IERC20[] memory path) external view returns (uint256[] memory amounts);
Copied!
First calls verifyPoolsPathSwap to verify the validity of the poolsPath and path variables.
Then, given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountIn.

State-Changing Functions

addLiquidity

1
function addLiquidity(
2
IERC20 tokenA,
3
IERC20 tokenB,
4
address pool,
5
uint256 amountADesired,
6
uint256 amountBDesired,
7
uint256 amountAMin,
8
uint256 amountBMin,
9
uint256[2] memory vReserveRatioBounds,
10
address to,
11
uint256 deadline
12
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
Copied!
Adds liquidity to an existing stable pool.
    pool should already be an existing pool of the token pair of tokenA and tokenB. Otherwise, the transaction will revert.
    msg.sender should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.
    Always adds assets at the ideal ratio, according to the price when the transaction is executed.
Name
Type
tokenA
IERC20
The contract address of the desired token.
tokenB
IERC20
The contract address of the desired token.
pool
address
The contract address of the desired pool to add liquidity to.
amountADesired
uint256
The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates).
amountBDesired
uint256
The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates).
amountAMin
uint256
Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.
amountBMin
uint256
Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired.
vReserveRatioBounds
uint256[2]
Bounds the extent to which the virtual B/A price can move before the transaction reverts.
to
address
Recipient of the liquidity tokens.
deadline
uint256
Unix timestamp after which the transaction will revert.
amountA
uint256
The amount of tokenA sent to the pool.
amountB
uint256
The amount of tokenB sent to the pool.
liquidity
uint256
The amount of liquidity tokens minted.

removeLiquidity

1
function removeLiquidity(
2
IERC20 tokenA,
3
IERC20 tokenB,
4
address pool,
5
uint256 liquidity,
6
uint256 amountAMin,
7
uint256 amountBMin,
8
address to,
9
uint256 deadline
10
) external returns (uint256 amountA, uint256 amountB);
Copied!
Removes liquidity from a specified stable pool.
    msg.sender should have already given the router an allowance of at least liquidity on the pool.
Name
Type
tokenA
IERC20
The contract address of the desired token.
tokenB
IERC20
The contract address of the desired token.
pool
address
The contract address of the desired pool to remove liquidity from.
liquidity
uint256
The amount of liquidity tokens to remove.
amountAMin
uint256
The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMin
uint256
The minimum amount of tokenB that must be received for the transaction not to revert.
to
address
Recipient of the underlying assets.
deadline
uint256
Unix timestamp after which the transaction will revert.
amountA
uint256
The amount of tokenA received.
amountB
uint256
The amount of tokenB received.

removeLiquidityWithPermit

1
function removeLiquidityWithPermit(
2
IERC20 tokenA,
3
IERC20 tokenB,
4
address pool,
5
uint256 liquidity,
6
uint256 amountAMin,
7
uint256 amountBMin,
8
address to,
9
uint256 deadline,
10
bool approveMax, uint8 v, bytes32 r, bytes32 s
11
) external returns (uint256 amountA, uint256 amountB);
Copied!
Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval, thanks to permit.
Name
Type
tokenA
IERC20
The contract address of the desired token.
tokenB
IERC20
The contract address of the desired token.
pool
address
The contract address of the desired pool to remove liquidity from.
liquidity
uint256
The amount of liquidity tokens to remove.
amountAMin
uint256
The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMin
uint256
The minimum amount of tokenB that must be received for the transaction not to revert.
to
address
Recipient of the underlying assets.
deadline
uint256
Unix timestamp after which the transaction will revert.
approveMax
bool
Whether or not the approval amount in the signature is for liquidity or uint256(-1).
v
uint8
The v component of the permit signature.
r
bytes32
The r component of the permit signature.
s
bytes32
The s component of the permit signature.
amountA
uint256
The amount of tokenA received.
amountB
uint256
The amount of tokenB received.

swapExactTokensForTokens

1
function swapExactTokensForTokens(
2
uint256 amountIn,
3
uint256 amountOutMin,
4
address[] calldata poolsPath,
5
IERC20[] calldata path,
6
address to,
7
uint256 deadline
8
) external returns (uint256[] memory amounts);
Copied!
Swaps an exact amount of input tokens for as many output tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.
The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.
    msg.sender should have already given the router an allowance of at least amountIn on the input token.
Name
Type
amountIn
uint256
The amount of input tokens to send.
amountOutMin
uint256
The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPath
address[] calldata
An array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
path
IERC20[] calldata
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Recipient of the output tokens.
deadline
uint256
Unix timestamp after which the transaction will revert.
amounts
uint256[] memory
The input token amount and all subsequent output token amounts.

swapTokensForExactTokens

1
function swapTokensForExactTokens(
2
uint256 amountOut,
3
uint256 amountInMax,
4
address[] calldata poolsPath,
5
IERC20[] calldata path,
6
address to,
7
uint256 deadline
8
) external returns (uint256[] memory amounts);
Copied!
Receive an exact amount of output tokens for as few input tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.
The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.
    msg.sender should have already given the router an allowance of at least amountInMax on the input token.
Name
Type
amountOut
uint256
The amount of output tokens to receive.
amountInMax
uint256
The maximum amount of input tokens that can be required before the transaction reverts.
poolsPath
address[] calldata
An array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
path
IERC20[] calldata
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Recipient of the output tokens.
deadline
uint256
Unix timestamp after which the transaction will revert.
amounts
uint256[] memory
The input token amount and all subsequent output token amounts.

Interface

1
pragma solidity 0.6.12;
2
3
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
4
5
/// @dev an simple interface for integration dApp to swap
6
interface IBuniCornExchangeRouter {
7
function swapExactTokensForTokens(
8
uint256 amountIn,
9
uint256 amountOutMin,
10
address[] calldata poolsPath,
11
IERC20[] calldata path,
12
address to,
13
uint256 deadline
14
) external returns (uint256[] memory amounts);
15
16
function swapTokensForExactTokens(
17
uint256 amountOut,
18
uint256 amountInMax,
19
address[] calldata poolsPath,
20
IERC20[] calldata path,
21
address to,
22
uint256 deadline
23
) external returns (uint256[] memory amounts);
24
25
function getAmountsOut(
26
uint256 amountIn,
27
address[] calldata poolsPath,
28
IERC20[] calldata path
29
) external view returns (uint256[] memory amounts);
30
31
function getAmountsIn(
32
uint256 amountOut,
33
address[] calldata poolsPath,
34
IERC20[] calldata path
35
) external view returns (uint256[] memory amounts);
36
}
37
38
/// @dev an simple interface for integration dApp to contribute liquidity
39
interface IBuniCornLiquidityRouter {
40
/**
41
* @param tokenA address of token in the pool
42
* @param tokenB address of token in the pool
43
* @param pool the address of the pool
44
* @param amountADesired the amount of tokenA users want to add to the pool
45
* @param amountBDesired the amount of tokenB users want to add to the pool
46
* @param amountAMin bounds to the extents to which amountB/amountA can go up
47
* @param amountBMin bounds to the extents to which amountB/amountA can go down
48
* @param vReserveRatioBounds bounds to the extents to which vReserveB/vReserveA can go (precision: 2 ** 112)
49
* @param to Recipient of the liquidity tokens.
50
* @param deadline Unix timestamp after which the transaction will revert.
51
*/
52
function addLiquidity(
53
IERC20 tokenA,
54
IERC20 tokenB,
55
address pool,
56
uint256 amountADesired,
57
uint256 amountBDesired,
58
uint256 amountAMin,
59
uint256 amountBMin,
60
uint256[2] calldata vReserveRatioBounds,
61
address to,
62
uint256 deadline
63
)
64
external
65
returns (
66
uint256 amountA,
67
uint256 amountB,
68
uint256 liquidity
69
);
70
71
function addLiquidityNewPool(
72
IERC20 tokenA,
73
IERC20 tokenB,
74
uint32 ampBps,
75
uint256 amountADesired,
76
uint256 amountBDesired,
77
uint256 amountAMin,
78
uint256 amountBMin,
79
address to,
80
uint256 deadline
81
)
82
external
83
returns (
84
uint256 amountA,
85
uint256 amountB,
86
uint256 liquidity
87
);
88
89
/**
90
* @param tokenA address of token in the pool
91
* @param tokenB address of token in the pool
92
* @param pool the address of the pool
93
* @param liquidity the amount of lp token users want to burn
94
* @param amountAMin the minimum token retuned after burning
95
* @param amountBMin the minimum token retuned after burning
96
* @param to Recipient of the returned tokens.
97
* @param deadline Unix timestamp after which the transaction will revert.
98
*/
99
function removeLiquidity(
100
IERC20 tokenA,
101
IERC20 tokenB,
102
address pool,
103
uint256 liquidity,
104
uint256 amountAMin,
105
uint256 amountBMin,
106
address to,
107
uint256 deadline
108
) external returns (uint256 amountA, uint256 amountB);
109
110
/**
111
* @param tokenA address of token in the pool
112
* @param tokenB address of token in the pool
113
* @param pool the address of the pool
114
* @param liquidity the amount of lp token users want to burn
115
* @param amountAMin the minimum token retuned after burning
116
* @param amountBMin the minimum token retuned after burning
117
* @param to Recipient of the returned tokens.
118
* @param deadline Unix timestamp after which the transaction will revert.
119
* @param approveMax whether users permit the router spending max lp token or not.
120
* @param r s v Signature of user to permit the router spending lp token
121
*/
122
function removeLiquidityWithPermit(
123
IERC20 tokenA,
124
IERC20 tokenB,
125
address pool,
126
uint256 liquidity,
127
uint256 amountAMin,
128
uint256 amountBMin,
129
address to,
130
uint256 deadline,
131
bool approveMax,
132
uint8 v,
133
bytes32 r,
134
bytes32 s
135
) external returns (uint256 amountA, uint256 amountB);
136
137
/**
138
* @param amountA amount of 1 side token added to the pool
139
* @param reserveA current reserve of the pool
140
* @param reserveB current reserve of the pool
141
* @return amountB amount of the other token added to the pool
142
*/
143
function quote(
144
uint256 amountA,
145
uint256 reserveA,
146
uint256 reserveB
147
) external pure returns (uint256 amountB);
148
}
149
150
/// @dev full interface for router
151
interface IBuniCornRouter01 is IBuniCornExchangeRouter, IBuniCornLiquidityRouter {
152
function factory() external pure returns (address);
153
}
154
Copied!
Last modified 3mo ago