This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from grandizzy/generate_dai_script
Add script to generate DAI for given testchain address
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// usage: | ||
// > node_modules/.bin/babel-node packages/test-helpers/scripts/generateDai.js <address> <daiAmount> | ||
|
||
import { isAddress } from 'web3-utils'; | ||
import { MDAI, ETH } from '@makerdao/dai-plugin-mcd/src/index'; | ||
import { mcdMaker } from '@makerdao/dai-plugin-mcd/test/helpers'; | ||
|
||
async function main() { | ||
const maker = await mcdMaker(); | ||
const address = process.argv[process.argv.length - 2]; | ||
const amount = process.argv[process.argv.length - 1]; | ||
if (!isAddress(address)) { | ||
console.log('Pass a valid address as the last argument.'); | ||
return; | ||
} | ||
|
||
maker.service('accounts').useAccountWithAddress(address); | ||
console.log(`Generating ${amount} MDAI for ${address}`); | ||
const cdpMgr = maker.service('mcd:cdpManager'); | ||
|
||
await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount)); | ||
|
||
const dai = cdpMgr.get('token').getToken(MDAI); | ||
const balance = await dai.balanceOf(address) | ||
console.log(`Balance of ${address}: ${balance}`) | ||
|
||
} | ||
|
||
(async fn => { | ||
try { | ||
await fn(); | ||
process.exit(); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
})(main); |