1
- const Maker = artifacts . require ( "LiquidityMaker " ) ;
1
+ const Token = artifacts . require ( "Token " ) ;
2
2
const Weth = artifacts . require ( "WrappedEther" ) ;
3
+ const Maker = artifacts . require ( "LiquidityMaker" ) ;
4
+ const Factory = artifacts . require ( "ISwapsFactory" ) ;
5
+ const helpers = require ( "@nomicfoundation/hardhat-network-helpers" ) ;
3
6
// const catchRevert = require("./exceptionsHelpers.js").catchRevert;
4
7
const { expectRevert } = require ( '@openzeppelin/test-helpers' ) ;
5
8
require ( "./utils" ) ;
6
9
7
10
// const BN = web3.utils.BN;
8
11
9
- const ONE_ETH = web3 . utils . toWei ( "1" ) ;
10
- const FOUR_ETH = web3 . utils . toWei ( "4" ) ;
11
- const FIVE_ETH = web3 . utils . toWei ( "5" ) ;
12
- const NINE_ETH = web3 . utils . toWei ( "9" ) ;
12
+ const tokens = ( value ) => {
13
+ return web3 . utils . toWei ( value ) ;
14
+ }
15
+
16
+ const ONE_ETH = tokens ( "1" ) ;
17
+ const FOUR_ETH = tokens ( "4" ) ;
18
+ const FIVE_ETH = tokens ( "5" ) ;
19
+ const NINE_ETH = tokens ( "9" ) ;
20
+
21
+ const HALF_ETH = tokens ( "0.5" ) ;
22
+
23
+ const testBlock = 17274000 ;
13
24
14
25
const getLastEvent = async ( eventName , instance ) => {
15
26
const events = await instance . getPastEvents ( eventName , {
@@ -19,15 +30,43 @@ const getLastEvent = async (eventName, instance) => {
19
30
return events . pop ( ) . returnValues ;
20
31
} ;
21
32
22
- contract ( "Maker" , ( [ owner , alice , bob , random ] ) => {
23
33
24
- const MAINNET_ROUTER = "0xB4B0ea46Fe0E9e8EAB4aFb765b527739F2718671" ;
25
- const MAINNET_FACTORY = "0xee3E9E46E34a27dC755a63e2849C9913Ee1A06E2" ;
26
- const MAINNET_WRAPPED_ETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" ;
27
- const MAINNET_VERSE_TOKEN = "0x249cA82617eC3DfB2589c4c17ab7EC9765350a18" ;
34
+ const MAINNET_ROUTER = "0xB4B0ea46Fe0E9e8EAB4aFb765b527739F2718671" ;
35
+ const MAINNET_FACTORY = "0xee3E9E46E34a27dC755a63e2849C9913Ee1A06E2" ;
36
+ const MAINNET_WRAPPED_ETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" ;
37
+ const MAINNET_VERSE_TOKEN = "0x249cA82617eC3DfB2589c4c17ab7EC9765350a18" ;
38
+ const MAINNET_DAI_TOKEN = "0x6B175474E89094C44Da98b954EedeAC495271d0F" ;
39
+ const MAINNET_DEV_ADDRESS = "0x641AD78BAca220C5BD28b51Ce8e0F495e85Fe689" ;
28
40
29
- let maker ;
41
+ const getSomeDai = async (
42
+ beneficiary ,
43
+ amount
44
+ ) => {
45
+ await helpers . impersonateAccount (
46
+ MAINNET_DEV_ADDRESS
47
+ ) ;
48
+
49
+ const impersonatedSigner = await ethers . getSigner (
50
+ MAINNET_DEV_ADDRESS
51
+ ) ;
52
+
53
+ let daiEthers = await ethers . getContractAt (
54
+ "Token" ,
55
+ MAINNET_DAI_TOKEN
56
+ ) ;
57
+
58
+ await daiEthers . connect ( impersonatedSigner ) . transfer (
59
+ beneficiary ,
60
+ amount
61
+ ) ;
62
+ }
63
+
64
+ contract ( "LiquidityMaker" , ( [ owner , alice , bob , random ] ) => {
65
+
66
+ let dai ;
30
67
let weth ;
68
+ let maker ;
69
+ let verse ;
31
70
32
71
beforeEach ( async ( ) => {
33
72
maker = await Maker . new (
@@ -38,6 +77,14 @@ contract("Maker", ([owner, alice, bob, random]) => {
38
77
weth = await Weth . at (
39
78
MAINNET_WRAPPED_ETH
40
79
) ;
80
+
81
+ dai = await Token . at (
82
+ MAINNET_DAI_TOKEN
83
+ ) ;
84
+
85
+ verse = await Token . at (
86
+ MAINNET_VERSE_TOKEN
87
+ ) ;
41
88
} ) ;
42
89
43
90
describe ( "Initial deployment functionality" , ( ) => {
@@ -61,17 +108,18 @@ contract("Maker", ([owner, alice, bob, random]) => {
61
108
62
109
describe ( "Initial liquidity functionality" , ( ) => {
63
110
64
- it ( "should be able to provide liquidity" , async ( ) => {
111
+ it ( "should be able to provide liquidity (WETH/DAI) using WEHT " , async ( ) => {
65
112
66
113
const depositor = alice ;
67
- const amount = FOUR_ETH ;
114
+ const depositAmountEth = ONE_ETH ;
115
+ const minDaiExpected = tokens ( "900" ) ;
68
116
69
117
const balanceBefore = await weth . balanceOf (
70
118
depositor
71
119
) ;
72
120
73
121
await weth . send (
74
- amount ,
122
+ depositAmountEth ,
75
123
{
76
124
from : depositor
77
125
}
@@ -87,22 +135,68 @@ contract("Maker", ([owner, alice, bob, random]) => {
87
135
88
136
assert . equal (
89
137
balanceChange . toString ( ) ,
90
- amount . toString ( )
138
+ depositAmountEth . toString ( )
91
139
) ;
92
140
93
141
await weth . approve (
94
142
maker . address ,
95
- ONE_ETH ,
143
+ depositAmountEth ,
144
+ {
145
+ from : depositor
146
+ }
147
+ ) ;
148
+
149
+ await maker . makeLiquidityDual (
150
+ MAINNET_WRAPPED_ETH ,
151
+ MAINNET_DAI_TOKEN ,
152
+ depositAmountEth ,
153
+ minDaiExpected ,
154
+ 0 ,
155
+ 0 ,
156
+ {
157
+ from : depositor
158
+ }
159
+ ) ;
160
+
161
+ const swapResultData = await getLastEvent (
162
+ "SwapResults" ,
163
+ maker
164
+ ) ;
165
+
166
+ console . log ( swapResultData , 'swapResultData' ) ;
167
+
168
+ const liquidityData = await getLastEvent (
169
+ "LiquidityAdded" ,
170
+ maker
171
+ ) ;
172
+
173
+ console . log ( liquidityData , 'liquidityData' ) ;
174
+ } ) ;
175
+
176
+ it ( "should be able to provide liquidity (WETH/DAI) using DAI" , async ( ) => {
177
+
178
+ const depositor = alice ;
179
+ const depositAmountDai = tokens ( "1820" ) ;
180
+ const minEthExpected = HALF_ETH ;
181
+
182
+ await getSomeDai (
183
+ depositor ,
184
+ depositAmountDai
185
+ ) ;
186
+
187
+ await dai . approve (
188
+ maker . address ,
189
+ depositAmountDai ,
96
190
{
97
191
from : depositor
98
192
}
99
193
) ;
100
194
101
- await maker . makeLiquidity (
195
+ await maker . makeLiquidityDual (
196
+ MAINNET_DAI_TOKEN ,
102
197
MAINNET_WRAPPED_ETH ,
103
- MAINNET_VERSE_TOKEN ,
104
- ONE_ETH ,
105
- 1 ,
198
+ depositAmountDai ,
199
+ minEthExpected ,
106
200
0 ,
107
201
0 ,
108
202
{
0 commit comments