1- const _ = require ( "lodash" ) ;
2-
31// USDT has its own ABI because of non standard returns
42const usdtAbi = require ( "../test/abi/usdt.json" ) . abi ;
53const daiAbi = require ( "../test/abi/erc20.json" ) ;
@@ -15,12 +13,6 @@ const defaultAccountIndex = 4;
1513// By default, fund each test account with 10k worth of each stable coin.
1614const defaultFundAmount = 10000 ;
1715
18- // By default, mint 1k worth of OUSD for each test account.
19- const defaultMintAmount = 1000 ;
20-
21- // By default, redeem 1k worth of OUSD for each test account.
22- const defaultRedeemAmount = 1000 ;
23-
2416/**
2517 * Prints test accounts.
2618 */
@@ -55,7 +47,6 @@ async function fund(taskArguments, hre) {
5547 usdtUnits,
5648 daiUnits,
5749 usdcUnits,
58- tusdUnits,
5950 isFork,
6051 isLocalhost,
6152 } = require ( "../test/helpers" ) ;
@@ -173,219 +164,6 @@ async function fund(taskArguments, hre) {
173164 }
174165}
175166
176- /**
177- * Mints OUSD using USDT on local or fork.
178- */
179- async function mint ( taskArguments , hre ) {
180- const addresses = require ( "../utils/addresses" ) ;
181- const { usdtUnits, isFork, isLocalhost } = require ( "../test/helpers" ) ;
182-
183- if ( ! isFork ) {
184- throw new Error ( "Task can only be used on fork" ) ;
185- }
186-
187- const ousd = await ethers . getContractAt ( "OUSD" , addresses . mainnet . OUSDProxy ) ;
188- const vault = await ethers . getContractAt (
189- "IVault" ,
190- addresses . mainnet . VaultProxy
191- ) ;
192-
193- const usdt = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . USDT ) ;
194-
195- const numAccounts = Number ( taskArguments . num ) || defaultNumAccounts ;
196- const accountIndex = Number ( taskArguments . index ) || defaultAccountIndex ;
197- const mintAmount = taskArguments . amount || defaultMintAmount ;
198-
199- const signers = await hre . ethers . getSigners ( ) ;
200- for ( let i = accountIndex ; i < accountIndex + numAccounts ; i ++ ) {
201- const signer = signers [ i ] ;
202- const address = signer . address ;
203- console . log (
204- `Minting ${ mintAmount } OUSD for account ${ i } at address ${ address } `
205- ) ;
206-
207- // Ensure the account has sufficient USDT balance to cover the mint.
208- const usdtBalance = await usdt . balanceOf ( address ) ;
209- if ( usdtBalance . lt ( usdtUnits ( mintAmount ) ) ) {
210- throw new Error (
211- `Account USDT balance insufficient to mint the requested amount`
212- ) ;
213- }
214-
215- // for some reason we need to call impersonateAccount even on default list of signers
216- await hre . network . provider . request ( {
217- method : "hardhat_impersonateAccount" ,
218- params : [ signer . address ] ,
219- } ) ;
220-
221- // Reset approval before requesting a fresh one, or non first approve calls will fail
222- await usdt
223- . connect ( signer )
224- . approve ( vault . address , "0x0" , { gasLimit : 1000000 } ) ;
225- await usdt
226- . connect ( signer )
227- . approve ( vault . address , usdtUnits ( mintAmount ) , { gasLimit : 1000000 } ) ;
228-
229- // Mint.
230- await vault
231- . connect ( signer )
232- . mint ( usdt . address , usdtUnits ( mintAmount ) , 0 , { gasLimit : 2000000 } ) ;
233-
234- // Show new account's balance.
235- const ousdBalance = await ousd . balanceOf ( address ) ;
236- console . log (
237- "New OUSD balance=" ,
238- hre . ethers . utils . formatUnits ( ousdBalance , 18 )
239- ) ;
240- }
241- }
242-
243- /**
244- * Redeems OUSD on fork for specific account
245- */
246- async function redeemFor ( taskArguments , hre ) {
247- const addresses = require ( "../utils/addresses" ) ;
248- const {
249- ousdUnits,
250- ousdUnitsFormat,
251- daiUnitsFormat,
252- usdcUnitsFormat,
253- usdtUnitsFormat,
254- isFork,
255- isLocalhost,
256- } = require ( "../test/helpers" ) ;
257-
258- if ( ! isFork ) {
259- throw new Error ( "Task can only be used on fork" ) ;
260- }
261-
262- const ousd = await ethers . getContractAt ( "OUSD" , addresses . mainnet . OUSDProxy ) ;
263- const vault = await ethers . getContractAt (
264- "IVault" ,
265- addresses . mainnet . VaultProxy
266- ) ;
267- const dai = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . DAI ) ;
268- const usdc = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . USDC ) ;
269- const usdt = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . USDT ) ;
270-
271- const address = taskArguments . account ;
272-
273- const signer = await hre . ethers . getSigner ( address ) ;
274- await hre . network . provider . request ( {
275- method : "hardhat_impersonateAccount" ,
276- params : [ address ] ,
277- } ) ;
278-
279- const redeemAmount = taskArguments . amount ;
280-
281- console . log ( `Redeeming ${ redeemAmount } OUSD for address ${ address } ` ) ;
282-
283- // Show the current balances.
284- let ousdBalance = await ousd . balanceOf ( address ) ;
285- let daiBalance = await dai . balanceOf ( address ) ;
286- let usdcBalance = await usdc . balanceOf ( address ) ;
287- let usdtBalance = await usdt . balanceOf ( address ) ;
288- console . log ( "OUSD balance=" , ousdUnitsFormat ( ousdBalance , 18 ) ) ;
289- console . log ( "DAI balance=" , daiUnitsFormat ( daiBalance , 18 ) ) ;
290- console . log ( "USDC balance=" , usdcUnitsFormat ( usdcBalance , 6 ) ) ;
291- console . log ( "USDT balance=" , usdtUnitsFormat ( usdtBalance , 6 ) ) ;
292-
293- const redeemAmountInt = parseInt ( redeemAmount ) ;
294- // Redeem.
295- await vault
296- . connect ( signer )
297- . redeem (
298- ousdUnits ( redeemAmount ) ,
299- ousdUnits ( ( redeemAmountInt - redeemAmountInt * 0.05 ) . toString ( ) ) ,
300- { gasLimit : 2500000 }
301- ) ;
302-
303- // Show the new balances.
304- ousdBalance = await ousd . balanceOf ( address ) ;
305- daiBalance = await dai . balanceOf ( address ) ;
306- usdcBalance = await usdc . balanceOf ( address ) ;
307- usdtBalance = await usdt . balanceOf ( address ) ;
308- console . log ( "New OUSD balance=" , ousdUnitsFormat ( ousdBalance , 18 ) ) ;
309- console . log ( "New DAI balance=" , daiUnitsFormat ( daiBalance , 18 ) ) ;
310- console . log ( "New USDC balance=" , usdcUnitsFormat ( usdcBalance , 18 ) ) ;
311- console . log ( "New USDT balance=" , usdtUnitsFormat ( usdtBalance , 18 ) ) ;
312- }
313-
314- /**
315- * Redeems OUSD on local or fork.
316- */
317- async function redeem ( taskArguments , hre ) {
318- const addresses = require ( "../utils/addresses" ) ;
319- const {
320- ousdUnits,
321- ousdUnitsFormat,
322- daiUnitsFormat,
323- usdcUnitsFormat,
324- usdtUnitsFormat,
325- isFork,
326- isLocalhost,
327- } = require ( "../test/helpers" ) ;
328-
329- if ( ! isFork && ! isLocalhost ) {
330- throw new Error ( "Task can only be used on local or fork" ) ;
331- }
332-
333- const ousdProxy = await ethers . getContract ( "OUSDProxy" ) ;
334- const ousd = await ethers . getContractAt ( "OUSD" , ousdProxy . address ) ;
335-
336- const vaultProxy = await ethers . getContract ( "VaultProxy" ) ;
337- const vault = await ethers . getContractAt ( "IVault" , vaultProxy . address ) ;
338-
339- let dai , usdc , usdt ;
340- if ( isFork ) {
341- dai = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . DAI ) ;
342- usdc = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . USDC ) ;
343- usdt = await hre . ethers . getContractAt ( usdtAbi , addresses . mainnet . USDT ) ;
344- } else {
345- dai = await hre . ethers . getContract ( "MockDAI" ) ;
346- usdc = await hre . ethers . getContract ( "MockUSDC" ) ;
347- usdt = await hre . ethers . getContract ( "MockUSDT" ) ;
348- }
349-
350- const numAccounts = Number ( taskArguments . num ) || defaultNumAccounts ;
351- const accountIndex = Number ( taskArguments . index ) || defaultAccountIndex ;
352- const redeemAmount = taskArguments . amount || defaultRedeemAmount ;
353-
354- const signers = await hre . ethers . getSigners ( ) ;
355- for ( let i = accountIndex ; i < accountIndex + numAccounts ; i ++ ) {
356- const signer = signers [ i ] ;
357- const address = signer . address ;
358- console . log (
359- `Redeeming ${ redeemAmount } OUSD for account ${ i } at address ${ address } `
360- ) ;
361-
362- // Show the current balances.
363- let ousdBalance = await ousd . balanceOf ( address ) ;
364- let daiBalance = await dai . balanceOf ( address ) ;
365- let usdcBalance = await usdc . balanceOf ( address ) ;
366- let usdtBalance = await usdt . balanceOf ( address ) ;
367- console . log ( "OUSD balance=" , ousdUnitsFormat ( ousdBalance , 18 ) ) ;
368- console . log ( "DAI balance=" , daiUnitsFormat ( daiBalance , 18 ) ) ;
369- console . log ( "USDC balance=" , usdcUnitsFormat ( usdcBalance , 6 ) ) ;
370- console . log ( "USDT balance=" , usdtUnitsFormat ( usdtBalance , 6 ) ) ;
371-
372- // Redeem.
373- await vault
374- . connect ( signer )
375- . redeem ( ousdUnits ( redeemAmount ) , 0 , { gasLimit : 2000000 } ) ;
376-
377- // Show the new balances.
378- ousdBalance = await ousd . balanceOf ( address ) ;
379- daiBalance = await dai . balanceOf ( address ) ;
380- usdcBalance = await usdc . balanceOf ( address ) ;
381- usdtBalance = await usdt . balanceOf ( address ) ;
382- console . log ( "New OUSD balance=" , ousdUnitsFormat ( ousdBalance , 18 ) ) ;
383- console . log ( "New DAI balance=" , daiUnitsFormat ( daiBalance , 18 ) ) ;
384- console . log ( "New USDC balance=" , usdcUnitsFormat ( usdcBalance , 18 ) ) ;
385- console . log ( "New USDT balance=" , usdtUnitsFormat ( usdtBalance , 18 ) ) ;
386- }
387- }
388-
389167// Sends OUSD to a destination address.
390168async function transfer ( taskArguments ) {
391169 const {
@@ -437,8 +215,5 @@ async function transfer(taskArguments) {
437215module . exports = {
438216 accounts,
439217 fund,
440- mint,
441- redeem,
442- redeemFor,
443218 transfer,
444219} ;
0 commit comments