Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g defi
$ defi COMMAND
running command...
$ defi (-v|--version|version)
defi/0.0.1 linux-x64 node-v12.16.3
defi/0.0.1 linux-x64 node-v10.22.0
$ defi --help [COMMAND]
USAGE
$ defi COMMAND
Expand Down
898 changes: 898 additions & 0 deletions build/contracts/Migrations.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;

contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;

modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
5 changes: 5 additions & 0 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = function (deployer) {
deployer.deploy(Migrations);
};
1 change: 1 addition & 0 deletions oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"0.0.1","commands":{"chainlink":{"id":"chainlink","description":"Chainlink CLI","pluginName":"defi","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"name":{"name":"name","type":"option","char":"n","description":"name to print"},"force":{"name":"force","type":"boolean","char":"f","allowNo":false}},"args":[{"name":"file"}]},"config":{"id":"config","description":"Configure DeFi CLI","pluginName":"defi","pluginType":"core","aliases":[],"examples":["$ defi config session set","$ defi config accounts view","$ defi config uniswap view"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"default":{"name":"default","type":"boolean","description":"set default config","allowNo":false},"all":{"name":"all","type":"boolean","description":"view full config","allowNo":false}},"args":[{"name":"item","required":true,"options":["session","networks","accounts","chainlink","uniswap","tokens","all","path"]},{"name":"subcommand","required":true,"options":["view","set"]}]},"eth":{"id":"eth","description":"Send and View Eth balance","pluginName":"defi","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"subcommand","required":true,"options":["balance","send"]}]},"hello":{"id":"hello","description":"describe the command here","pluginName":"defi","pluginType":"core","aliases":[],"examples":["$ defi hello\nhello world from ./src/hello.ts!\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"name":{"name":"name","type":"option","char":"n","description":"name to print"},"force":{"name":"force","type":"boolean","char":"f","allowNo":false}},"args":[{"name":"file"}]},"tokens":{"id":"tokens","description":"Interact with ERC20 Tokens","pluginName":"defi","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"token","required":true},{"name":"subcommand","required":true,"options":["balance","send"]}]},"uniswap":{"id":"uniswap","description":"Uniswap CLI","pluginName":"defi","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"name":{"name":"name","type":"option","char":"n","description":"name to print"},"force":{"name":"force","type":"boolean","char":"f","allowNo":false}},"args":[{"name":"file"}]}}}
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.0",
"@types/inquirer": "^7.3.1",
"fs-extra": "^9.0.1",
"inquirer": "^7.3.3",
"node-emoji": "^1.10.0",
Expand Down
114 changes: 60 additions & 54 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Command, flags } from '@oclif/command'
import { lookupService } from 'dns'
//@ts-ignore
import inquirer from 'inquirer'
import { join } from 'path'
import Web3 from 'web3'
import {help} from '../utils/flags'

import credentials, { setCredentials } from '../utils/credentials'
import defaultConfig from '../utils/defaultConfig'
Expand All @@ -22,43 +24,47 @@ export default class Config extends Command {
static description = 'Configure DeFi CLI'

static examples = [
'$ defi config session set',
'$ defi config accounts view',
'$ defi config uniswap view',
'$ defi config session',
'$ defi config accounts',
'$ defi config networks',
]

static flags: any = {
help: flags.help({ char: 'h' }),
//--help flag
help: help,
//--view flag
view: flags.boolean({ char: 'v', description: "logs current status in config"}),
default: flags.boolean({ description: 'set default config' }),
all: flags.boolean({ description: 'view full config' })
}
all: flags.boolean({description: 'view full config' })
}

static args = [{
name: 'item',
required: true,
options: ['session', 'networks', 'accounts', 'chainlink', 'uniswap', 'tokens', 'all', 'path'],
},
{ name: 'subcommand', required: true, options: ["view", "set"] }
]
options: ['session', 'networks', 'accounts', 'chainlink', 'uniswap', 'tokens', 'all', 'path']
}]

async run() {
const { args, flags }: any = this.parse(Config)
const config = await credentials(this)
const networksView = Object.values(config.networks).map((network: any) => {
return {
name: `${network.networkId} (${network.name})`,
value: network.networkId
}
})

try {
if (args.item === 'path') {
const configPath = join(this.config.configDir, 'config.json')
this.log(configPath)
} else if (args.item === 'session') {
if (args.subcommand === 'view') {
this.log(config.session)
} else if (args.subcommand === 'set') {
const answers = await inquirer
if (flags.view) { console.log(config.session) }
else { const answers = await inquirer
.prompt([{
type: 'list',
name: 'networkId',
message: 'Select networkId:',
choices: Object.keys(config.networks),
choices: networksView,
default: config.session.networkId
},
{
Expand All @@ -74,17 +80,13 @@ export default class Config extends Command {
config.session = answers
await setCredentials(this, config)
this.log('Session configured.')

}

} else if (args.item === 'networks') {
const networks = config.networks
const networkNames = Object.values(networks).map((n: any) => n.name)
if (args.subcommand === 'view') {
this.log(config.networks)

} else if (args.subcommand === 'set') {
const answers = await inquirer
const networks = config.networks
const networkNames = Object.values(networks).map((n: any) => n.name)
if (flags.view) { console.log(config.networks) }
else { const answers = await inquirer
.prompt([
{
type: 'list',
Expand Down Expand Up @@ -143,32 +145,13 @@ export default class Config extends Command {
this.log('Networks configured.')
}
} else if (args.item === 'accounts') {
const accounts = config.accounts
if (args.subcommand === 'view') {
if (flags.all) {
this.log(accounts)
} else {
const addressesByNetwork: any = {}
Object.entries(accounts).forEach(([networkId, networkAccounts]: [any, any]) => {
addressesByNetwork[networkId] = Object.keys(networkAccounts)
})
this.log(addressesByNetwork)
}

} else if (args.subcommand === 'set') {

const networks = Object.values(config.networks).map((network: any) => {
return {
name: `${network.networkId} (${network.name})`,
value: network.networkId
}
})

if (flags.view) { this.log(config.accounts) }
else {
const accountTypes = [
{ name: 'Signing (generate)', value: 'generatePrivateKey' },
{ name: 'Watch only (public key)', value: 'watchOnly' },
{ name: 'Signing (private key)', value: 'inputPrivateKey' },
{ name: 'HD Wallet (BIP-39', value: 'HDWallet' }
{ name: 'HD Wallet (BIP-39)', value: 'HDWallet' }
]

const answers = await inquirer
Expand All @@ -184,7 +167,7 @@ export default class Config extends Command {
type: 'list',
name: 'networkId',
message: 'Select network id:',
choices: networks,
choices: networksView,
default: config.session.networkId
},
{
Expand Down Expand Up @@ -252,21 +235,44 @@ export default class Config extends Command {
} else if (args.item === 'uniswap') {

} else if (args.item === 'tokens') {
//@ts-ignore
if (flags.view) { this.log(config.tokens) }
else {
const answers = await inquirer
.prompt([{
type: 'list',
name: 'networkId',
message: 'Select networkId:',
choices: networksView
},
{
type: 'input',
name: 'name',
message: 'Enter Token Name:'
},
{
type: 'input',
name: 'address',
message: 'Enter Token Address:'
}
])

} else if (args.item === 'all') {
if (args.subcommand === 'view') {
this.log(config)
} else if (args.subcommand === 'set') {
config.tokens[answers.networkId] [answers.address] = { address: answers.address, name: answers.name }

if (flags.default) {
await setCredentials(this, config)
this.log('Token configured')
}
} else if (args.item === 'all') {
if (flags.view) { console.log(config)}
else if (flags.default) {
await setCredentials(this, defaultConfig)
this.log('Default config set.')
} else {
throw new Error('configure all Unimplemented!')
}

}
}



} catch (error) {
this.error(error || 'A DeFi CLI error has occurred.', {
Expand Down
Loading