From 9bda7716764ccae76d554b10404efb68361425f6 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Thu, 5 Dec 2019 10:07:31 +0200 Subject: [PATCH 1/3] Add script to generate DAI for given testchain address usage: > node_modules/.bin/babel-node scripts/generateDai.js
--- scripts/generateDai.js | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/generateDai.js diff --git a/scripts/generateDai.js b/scripts/generateDai.js new file mode 100644 index 000000000..0c4867d01 --- /dev/null +++ b/scripts/generateDai.js @@ -0,0 +1,45 @@ +// usage: +// > node_modules/.bin/babel-node scripts/fundTestAccount.js
+ +import Maker from '../packages/dai/src'; +import McdPlugin from '../packages/dai-plugin-mcd/src'; +import { isAddress } from 'web3-utils'; +import map from 'lodash/map'; +import uniq from 'lodash/uniq'; +import { MDAI, ETH } from '../packages/dai-plugin-mcd/src/index'; +import { mcdMaker, setupCollateral } from '../packages/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); + const savingsService = maker.service('mcd:savings'); + const dai = maker.getToken(MDAI); + const proxyAddress = await maker.service('proxy').ensureProxy(); + process.stdout.write(`Proxy address ${proxyAddress} `); + await dai.approveUnlimited(proxyAddress); + + console.log(`Generating DAI for ${address}`); + const cdpMgr = maker.service('mcd:cdpManager'); + await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); + await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount)); + + await maker.service('allowance').removeAllowance('MDAI', proxyAddress); + +} + +(async fn => { + try { + await fn(); + process.exit(); + } catch (err) { + console.error(err); + process.exit(1); + } +})(main); From 210772c1b6f78cb6da9e5e8c860548aafa3187d1 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 6 Dec 2019 12:25:59 +0200 Subject: [PATCH 2/3] Updates after review: - updated usage command - cleaned up script to only generate MDAI - use absolute imports - print account MDAI balance after generating MDAI --- scripts/generateDai.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/generateDai.js b/scripts/generateDai.js index 0c4867d01..70e343968 100644 --- a/scripts/generateDai.js +++ b/scripts/generateDai.js @@ -1,13 +1,9 @@ // usage: -// > node_modules/.bin/babel-node scripts/fundTestAccount.js
+// > node_modules/.bin/babel-node scripts/fundTestAccount.js
-import Maker from '../packages/dai/src'; -import McdPlugin from '../packages/dai-plugin-mcd/src'; import { isAddress } from 'web3-utils'; -import map from 'lodash/map'; -import uniq from 'lodash/uniq'; -import { MDAI, ETH } from '../packages/dai-plugin-mcd/src/index'; -import { mcdMaker, setupCollateral } from '../packages/dai-plugin-mcd/test/helpers'; +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(); @@ -19,18 +15,14 @@ async function main() { } maker.service('accounts').useAccountWithAddress(address); - const savingsService = maker.service('mcd:savings'); - const dai = maker.getToken(MDAI); - const proxyAddress = await maker.service('proxy').ensureProxy(); - process.stdout.write(`Proxy address ${proxyAddress} `); - await dai.approveUnlimited(proxyAddress); - - console.log(`Generating DAI for ${address}`); + console.log(`Generating ${amount} MDAI for ${address}`); const cdpMgr = maker.service('mcd:cdpManager'); - await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 }); + await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount)); - await maker.service('allowance').removeAllowance('MDAI', proxyAddress); + const dai = cdpMgr.get('token').getToken(MDAI); + const balance = await dai.balanceOf(address) + console.log(`Balance of ${address}: ${balance}`) } From 612a456f53a2cab2b11dbdefb51003baf8f12bc4 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 10 Dec 2019 09:34:20 +0200 Subject: [PATCH 3/3] Move generateDai.js in test-helpers package, fix usage --- {scripts => packages/test-helpers/scripts}/generateDai.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {scripts => packages/test-helpers/scripts}/generateDai.js (90%) diff --git a/scripts/generateDai.js b/packages/test-helpers/scripts/generateDai.js similarity index 90% rename from scripts/generateDai.js rename to packages/test-helpers/scripts/generateDai.js index 70e343968..fa20718b8 100644 --- a/scripts/generateDai.js +++ b/packages/test-helpers/scripts/generateDai.js @@ -1,5 +1,5 @@ // usage: -// > node_modules/.bin/babel-node scripts/fundTestAccount.js
+// > node_modules/.bin/babel-node packages/test-helpers/scripts/generateDai.js
import { isAddress } from 'web3-utils'; import { MDAI, ETH } from '@makerdao/dai-plugin-mcd/src/index';