Skip to content

Commit

Permalink
add local rsk deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ewingrj committed Nov 8, 2018
1 parent 5e7849e commit 8ecafed
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Welcome to the server code for Giveth's [dapp](https://github.com/Giveth/giveth-
- [Debugging](#debugging)
- [Usage](#usage)
- [Production](#production)
- [RSK](#rsk)
- [Help](#help)

## Getting Started
Expand Down Expand Up @@ -159,6 +160,37 @@ module.exports = {
};
```
## RSK
1. You will need to download the [rsk node](https://github.com/rsksmart/rskj/wiki/Install-RskJ-and-join-the-RSK-Orchid-Mainnet-Beta). After installing, you will run the node w/ the `regtest` network for local development.
```
java -jar rskj-core-0.5.2-ORCHID-all.jar co.rsk.Start --regtest
```
or
```
java -Drsk.conf.file=rsk.conf -jar rskj-core-0.5.2-ORCHID-all.jar co.rsk.Start
```
2. We need to deploy any contracts that we intend to call. *NOTE:* You will also need to ensure that your rsk node is in a clean state (reset) for the configured addresses to be correct.
```
npm run deploy-local:rsk
```
3. Optionally open a new terminal window and start the ipfs daemon
```
ipfs daemon
```
4. Start your app
```
yarn start:rsk
```
## Help
For more info on how to work with feathers checkout out their docs on [service methods](https://docs.feathersjs.com/api/databases/common.html#service-methods), [service events](https://docs.feathersjs.com/api/events.html#service-events), and [database querying](https://docs.feathersjs.com/api/databases/querying.html).
Expand Down
48 changes: 48 additions & 0 deletions config/rsk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"mongodb": "mongodb://localhost:27017/giveth_rsk",
"blockchain": {
"nodeUrl": "ws://localhost:8445",
"homeNodeUrl": "ws://localhost:8445",
"vaultAddress": "0x61b279350c827BC4128FD720F61787bfB30b7b30",
"liquidPledgingAddress": "0x12A9de49704A576f53e2F651eB648563B3fc0a20",
"ethFunderPK": "",
"walletFundingBlacklist": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0x7986b3DF570230288501EEa3D890bd66948C9B79",
"0x0a3aA774752ec2042c46548456c094A76C7F3a79",
"0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036",
"0x39B12C05E8503356E3a7DF0B7B33efA4c054C409"
]
},
"useReviewerWhitelist": true,
"reviewerWhitelist": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0x7986b3DF570230288501EEa3D890bd66948C9B79",
"0x0a3aA774752ec2042c46548456c094A76C7F3a79",
"0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036",
"0x39B12C05E8503356E3a7DF0B7B33efA4c054C409"
],
"useDelegateWhitelist": true,
"delegateWhitelist": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0x7986b3DF570230288501EEa3D890bd66948C9B79",
"0x0a3aA774752ec2042c46548456c094A76C7F3a79",
"0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036",
"0x39B12C05E8503356E3a7DF0B7B33efA4c054C409"
],
"useProjectOwnerWhitelist": true,
"projectOwnerWhitelist": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0x7986b3DF570230288501EEa3D890bd66948C9B79",
"0x0a3aA774752ec2042c46548456c094A76C7F3a79",
"0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036",
"0x39B12C05E8503356E3a7DF0B7B33efA4c054C409"
],
"tokenWhitelist": [
{ "name": "MiniMe Test Token",
"address": "0x14f6504A7ca4e574868cf8b49e85187d3Da9FA70",
"symbol": "ANT",
"decimals": 18
}
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"eslint": "eslint src/. test/.",
"eslint:fix": "eslint src/. test/. --fix",
"deploy-local": "npm run reset-db && node scripts/deploy.js",
"deploy-local:rsk": "npm run reset-db && START_NETWORK=false PROVIDER=http://localhost:4444 node scripts/deployNative.js",
"start": "nodemon --inspect src",
"start:rsk": "NODE_ENV=rsk nodemon --inspect src",
"start:networks": "node scripts/startBridge.js",
"start:networks:debug": "LOG_LEVEL=debug node scripts/startBridge.js",
"serve": "pm2 startOrRestart ecosystem.config.js --env production",
Expand Down
195 changes: 195 additions & 0 deletions scripts/deployNative.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/* eslint-disable import/no-extraneous-dependencies */
const Web3 = require('web3');
const { Kernel, ACL, LPVault, LiquidPledging, LPFactory, test } = require('giveth-liquidpledging');
const { LPPCampaign, LPPCampaignFactory } = require('lpp-campaign');
const { LPPCappedMilestone, LPPCappedMilestoneFactory } = require('lpp-capped-milestone');
const { MiniMeTokenFactory, MiniMeToken, MiniMeTokenState } = require('minimetoken');
const startNetworks = require('./startNetworks');

const { RecoveryVault } = test;

// NOTE: do not use the bridge account (account[10]) for any txs outside of the bridge
// if you do, the nonce will become off and the bridge will fail
let processStartNetwork = process.env.START_NETWORK;
if (processStartNetwork) {
processStartNetwork = !['f', 'false'].includes(processStartNetwork.toLowerCase());
}
const START_NETWORK = processStartNetwork === undefined ? true : processStartNetwork;
const PROVIDER = process.env.PROVIDER || 'http://localhost:8546';

async function deploy() {
try {
if (START_NETWORK) {
console.log('------------------- Starting Networks -------------------------\n');
const { foreignNetwork } = await startNetworks();

await foreignNetwork.waitForStart();
}
console.log('------------------- Deploying -------------------------\n');

const web3 = new Web3(PROVIDER);

const accounts = await web3.eth.getAccounts();

const from = accounts[0];

const baseVault = await LPVault.new(web3);
const baseLP = await LiquidPledging.new(web3);
const lpFactory = await LPFactory.new(web3, baseVault.$address, baseLP.$address, {
gas: 6700000,
});
const recoveryVault = (await RecoveryVault.new(web3)).$address;
const r = await lpFactory.newLP(from, recoveryVault, { $extraGas: 100000 });

const vaultAddress = r.events.DeployVault.returnValues.vault;
const vault = new LPVault(web3, vaultAddress);

const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
const liquidPledging = new LiquidPledging(web3, lpAddress);

// set permissions
const kernel = new Kernel(web3, await liquidPledging.kernel());
const acl = new ACL(web3, await kernel.acl());
await acl.createPermission(
accounts[0],
vault.$address,
await vault.CANCEL_PAYMENT_ROLE(),
accounts[0],
{ $extraGas: 200000 },
);
await acl.createPermission(
accounts[0],
vault.$address,
await vault.CONFIRM_PAYMENT_ROLE(),
accounts[0],
{ $extraGas: 200000 },
);
await acl.createPermission(
accounts[0],
vault.$address,
await vault.SET_AUTOPAY_ROLE(),
accounts[0],
{ $extraGas: 200000 },
);
await vault.setAutopay(true, { from: accounts[0], $extraGas: 100000 });

// deploy campaign plugin
const tokenFactory = await MiniMeTokenFactory.new(web3);
const lppCampaignFactory = await LPPCampaignFactory.new(web3, kernel.$address, {
$extraGas: 100000,
});
await acl.grantPermission(
lppCampaignFactory.$address,
acl.$address,
await acl.CREATE_PERMISSIONS_ROLE(),
{
$extraGas: 100000,
},
);
await acl.grantPermission(
lppCampaignFactory.$address,
liquidPledging.$address,
await liquidPledging.PLUGIN_MANAGER_ROLE(),
{ $extraGas: 100000 },
);

const campaignApp = await LPPCampaign.new(web3);
await kernel.setApp(
await kernel.APP_BASES_NAMESPACE(),
await lppCampaignFactory.CAMPAIGN_APP_ID(),
campaignApp.$address,
{ $extraGas: 100000 },
);

// deploy milestone plugin
const lppCappedMilestoneFactory = await LPPCappedMilestoneFactory.new(web3, kernel.$address, {
$extraGas: 100000,
});
await acl.grantPermission(
lppCappedMilestoneFactory.$address,
acl.$address,
await acl.CREATE_PERMISSIONS_ROLE(),
{
$extraGas: 100000,
},
);
await acl.grantPermission(
lppCappedMilestoneFactory.$address,
liquidPledging.$address,
await liquidPledging.PLUGIN_MANAGER_ROLE(),
{ $extraGas: 100000 },
);

const milestoneApp = await LPPCappedMilestone.new(web3);
await kernel.setApp(
await kernel.APP_BASES_NAMESPACE(),
await lppCappedMilestoneFactory.MILESTONE_APP_ID(),
milestoneApp.$address,
{ $extraGas: 100000 },
);

// deploy ERC20 test token
const miniMeToken = await MiniMeToken.new(
web3,
tokenFactory.$address,
0,
0,
'MiniMe Test Token',
18,
'MMT',
true,
{ from: accounts[0] },
);

// generate tokens for all accounts

// we first generate all tokens, then transfer, otherwise MetaMask will not show token balances
// await miniMeToken.generateTokens(accounts[10], web3.utils.toWei('200000'), {
// from: accounts[0],
// });
await miniMeToken.generateTokens(accounts[0], web3.utils.toWei('10000'), {
from: accounts[0],
});

// transfer tokens to all other home accounts, so that Meta mask will detect these tokens
// note: rsk node sucks at handling async txs & will fail, so we have to do it 1 by 1
// console.log('here', await miniMeToken.balanceOf(accounts[10]));
// await miniMeToken.transfer(accounts[0], web3.utils.toWei('10000'), { from: accounts[10] });
// console.log('here');
// await miniMeToken.transfer(accounts[1], web3.utils.toWei('10000'), { from: accounts[10] });
// console.log('here');
// for (const a of accounts) {
// await miniMeToken.transfer(a, web3.utils.toWei('10000'), { from: accounts[10] });
// }
// await Promise.all(
// accounts.map(async a =>
// miniMeToken.transfer(a, web3.utils.toWei('10000'), { from: accounts[10] }),
// ),
// );

const miniMeTokenState = new MiniMeTokenState(miniMeToken);
const st = await miniMeTokenState.getState();
accounts.map(a =>
console.log('MMT balance of address ', a, ' > ', web3.utils.fromWei(st.balances[a])),
);

console.log('\n\n', {
vault: vault.$address,
liquidPledging: liquidPledging.$address,
lppCampaignFactory: lppCampaignFactory.$address,
lppCappedMilestoneFactory: lppCappedMilestoneFactory.$address,
miniMeToken: {
name: 'MiniMe Token',
address: miniMeToken.$address,
symbol: 'MMT',
decimals: 18,
},
});
process.exit(); // some reason, this script won't exit. I think it has to do with web3 subscribing to tx confirmations?
} catch (e) {
console.log(e);
process.exit();
}
}

deploy();

0 comments on commit 8ecafed

Please sign in to comment.