owned this note
owned this note
Published
Linked with GitHub
# Minion DeFi - Initial Findings
## How JSON blobs work
- JSON blobs contain the ABI data for a contract. New ABIs for various Defi contracts can be found via Github, Etherscan, etc.
- Add them to `moloch-minion/src/abi/xxx.json`
- These blobs get imported into the project in the `/src/App.vue` file
```js
...
import abiDecoder from "abi-decoder";
import gql from "graphql-tag";
import minionAbi from "./abi/minion.json";
import molochAbi from "./abi/moloch_v2.json";
import subdomainRegistrarAbi from "./abi/minion_subdomain_registrar.json";
...
const abis = [
minionAbi,
require("./abi/certnft.json"),
require("./abi/ctoken.json"),
require("./abi/erc20.json"),
require("./abi/erc721.json"),
require("./abi/moloch_v1.json"),
require("./abi/moloch_v1_pool.json"),
require("./abi/moloch_v2.json"),
require("./abi/moloch_v2_guildbank.json"),
require("./abi/uniswap_v2_router.json")
];
abis.map(abi => abiDecoder.addABI(abi));
```
- Interaction with these blobs is exposed to the front end in `/src/views/NewMinion.vue`
```js
...
<v-select
label="Select ABI"
:items="abiItems"
@change="chooseABI"
></v-select>
<v-textarea
v-if="!selectedABI"
name="input-7-1"
v-model="abiData"
filled
label="ABI String"
:rules="abiStringRules"
required
value=""
@change="getFunctions"
></v-textarea>
<v-select
label="Functions"
v-model="selectedFunction"
:items="abiFunctions"
@change="chooseFunction"
></v-select>
...
```
The above code generates UI elements that show available contract ABIs. Users can select one, and then a set of available function calls is shown.
```js
abis: {
CertNFT: require("../abi/certnft.json"),
"Compound cToken": require("../abi/ctoken.json"),
"ENS Registrar": require("../abi/ens_registrar.json"),
ERC20: require("../abi/erc20.json"),
ERC721: require("../abi/erc721.json"),
Minion: require("../abi/minion.json"),
"Minion Subdomain Registrar": require("../abi/minion_subdomain_registrar.json"),
"Moloch v1": require("../abi/moloch_v1.json"),
"Moloch v1 Pool": require("../abi/moloch_v1_pool.json"),
"Moloch v2": require("../abi/moloch_v2.json"),
"Moloch v2 GuildBank": require("../abi/moloch_v2_guildbank.json"),
"Uniswap v2 Router": require("../abi/uniswap_v2_router.json")
},
abiItems: [
"Custom ABI",
"CertNFT",
"Compound cToken",
"ENS Registrar",
"ERC20",
"ERC721",
"Minion",
"Minion Subdomain Registrar",
"Moloch v1",
"Moloch v1 Pool",
"Moloch v2",
"Moloch v2 GuildBank",
"Uniswap v2 Router"
],
abiFunctions: [],
abiData: "",
abiStringRules: [
v => {
try {
JSON.parse(v);
} catch (e) {
return "invalid ABI string";
}
return true;
}
],
checkbox: false
}),
methods: {
chooseABI(contractName) {
if (contractName === "Custom ABI") {
this.selectedABI = null;
} else {
this.selectedABI = contractName;
this.getFunctions(this.abis[contractName]);
}
},
chooseFunction(fName) {
this.inputs = [];
this.inputValues = [];
const func = this.abiFunctions.find(({ name }) => name === fName);
this.selectedFunction = func;
this.inputs = func.inputs;
this.inputValues.length = func.inputs.length;
},
getFunctions(abiParam) {
this.hexData = "";
this.selectedFunction = null;
this.inputs = [];
this.inputValues = [];
let abi;
if (typeof abiParam === "object") {
abi = abiParam;
} else {
try {
abi = JSON.parse(abiParam);
} catch (e) {
// let validation handle errors
return [];
}
}
this.abiFunctions = abi
.filter(({ type, constant }) => type === "function" && !constant)
.map((f, id) => ({ ...f, text: f.name, id }));
},
```
## Potential Defi interactions
- Uniswap - access to swaps and pools
- Balancer
- Compound - borrow and lend
- TokenSets - purchase sets
- Maker?