Skip to content

Commit

Permalink
[v0.2.0] ERC20 / ERC721 Support (#18)
Browse files Browse the repository at this point in the history
* v0.1.1 Release

Signed-off-by: hfuss <[email protected]>

* latest DX

Signed-off-by: hfuss <[email protected]>

* latest token connector images

Signed-off-by: hfuss <[email protected]>

* debugging test failure, downgrading to 0.11.5 temporarily

Signed-off-by: hfuss <[email protected]>

* downgrading postgres chart

Signed-off-by: hfuss <[email protected]>

* started on migrating to erc20-erc721 support

Signed-off-by: hfuss <[email protected]>

* ethconnect contract registration refactored and more idempotent; ethconnect catchupmode support; migrating to new erc20-erc-721 connector

Signed-off-by: hfuss <[email protected]>

* ready for testing

Signed-off-by: hfuss <[email protected]>

* updated firefly.core

Signed-off-by: hfuss <[email protected]>

* fixing erc20-erc721 labels helper

Signed-off-by: hfuss <[email protected]>

* fixing erc20-erc721 image ref; ensuring erc20-erc721 templating is tested

Signed-off-by: hfuss <[email protected]>

* im not a js developer can you tell ;)

Signed-off-by: hfuss <[email protected]>

* shoulda used bash 😬

Signed-off-by: hfuss <[email protected]>

* or not bitwise or; other fixes

Signed-off-by: hfuss <[email protected]>

* debugging script

Signed-off-by: hfuss <[email protected]>

* Fixing deploy-contracts job

Signed-off-by: hfuss <[email protected]>

* latest ethconnect

Signed-off-by: hfuss <[email protected]>

* catchupModeBlockGap

Signed-off-by: hfuss <[email protected]>

* debugging deploy contracts

Signed-off-by: hfuss <[email protected]>

* fixing contracts lookup in erc20-erc721 job; latest erc20-erc721; docs update

Signed-off-by: hfuss <[email protected]>

* fix lint

Signed-off-by: hfuss <[email protected]>

* renaming erc20erc721 values

Signed-off-by: hfuss <[email protected]>

* updating makefile

Signed-off-by: hfuss <[email protected]>

* debugging script

Signed-off-by: hfuss <[email protected]>

* script fixed with longer sleep

Signed-off-by: hfuss <[email protected]>
  • Loading branch information
onelapahead authored Feb 7, 2022
1 parent f1e9239 commit c534110
Show file tree
Hide file tree
Showing 22 changed files with 540 additions and 183 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clean:
kind delete cluster

lint:
helm template charts/firefly --set "erc20.enabled=true" --set "erc1155.enabled=true" --set "ethconnect.enabled=true"
helm template charts/firefly --set "erc20erc721.enabled=true" --set "erc1155.enabled=true" --set "ethconnect.enabled=true"
ct lint \
--target-branch=main \
--exclude-deprecated \
Expand All @@ -26,7 +26,7 @@ deps:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts || true
helm upgrade --install --set kubeStateMetrics.enabled=false --set nodeExporter.enabled=false --set grafana.enabled=false kube-prometheus prometheus-community/kube-prometheus-stack
helm repo add bitnami https://charts.bitnami.com/bitnami || true
helm upgrade --install --set postgresqlPassword=firef1y --set extraEnv[0].name=POSTGRES_DATABASE --set extraEnv[0].value=firefly postgresql bitnami/postgresql
helm upgrade --install --set postgresqlPassword=firef1y --set extraEnv[0].name=POSTGRES_DATABASE --set extraEnv[0].value=firefly postgresql bitnami/postgresql --version 10.16.2
kubectl create secret generic custom-psql-config --dry-run --from-literal="url=postgres://postgres:[email protected]:5432/postgres?sslmode=disable" -o json | kubectl apply -f -

starter: charts/firefly/local-values.yaml
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export HELM_EXPERIMENTAL_OCI=1

helm registry login ghcr.io
```
> **NOTE**: it is recommended to use a [GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)

> **NOTE**: you must use a [GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
> when authenticating to the GHCR registry as opposed to using your GitHub password.
## Development
Expand Down
4 changes: 2 additions & 2 deletions charts/firefly/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ apiVersion: v2
name: firefly
description: A Helm chart for deploying FireFly and FireFly HTTPS Dataexchange onto Kubernetes.
type: application
appVersion: "0.11.5"
version: "0.1.0"
appVersion: "0.12.0"
version: "0.2.0"

maintainers:
- name: hfuss
Expand Down
187 changes: 158 additions & 29 deletions charts/firefly/README.md

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions charts/firefly/contracts/erc20.json

This file was deleted.

65 changes: 0 additions & 65 deletions charts/firefly/contracts/erc20Factory.json

This file was deleted.

129 changes: 129 additions & 0 deletions charts/firefly/scripts/ff-deploy-erc20-erc721-contracts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
'use strict';

// Copyright © 2022 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://swww.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const axios = require('axios');

const erc20ContractJson = require('/root/solidity/build/contracts/ERC20WithData.json');
const erc721ContractJson = require('/root/solidity/build/contracts/ERC721WithData.json');

const deployContracts = async () => {
let FormData = require("form-data");
const ETHCONNECT_BASE_URL = process.env.ETHCONNECT_URL;
const ETHCONNECT_PREFIX = process.env.ETHCONNECT_PREFIX || "firefly";
const ABIS_URI = process.env.ABIS_URI || "/abis";
const CONTRACTS_URI = process.env.CONTRACTS_URI || "/contracts";

// does not currently support using an address resolver to look up the wallet address i.e. must be in hex format
const TOKENS_OWNER_KEY = process.env.TOKENS_OWNER_KEY;

const ERC20_ENABLED = process.env.ERC20_ENABLED === "true";
const ERC20_TOKEN_NAME = process.env.ERC20_TOKEN_NAME;

const ERC721_ENABLED = process.env.ERC721_ENABLED === "true";
const ERC721_TOKEN_NAME = process.env.ERC721_TOKEN_NAME;

async function deployTokenContract(jsonLink, tokenName) {
const abi = jsonLink.abi;
const byteCode = jsonLink.bytecode;

// POST /abis
const bodyFormData = new FormData();
bodyFormData.append("abi", JSON.stringify(abi));
bodyFormData.append("bytecode", byteCode);
console.log(`POST ${ETHCONNECT_BASE_URL}${ABIS_URI} with abi/bytecode form data`);
const abiRes = await axios
.post(`${ETHCONNECT_BASE_URL}${ABIS_URI}`, bodyFormData, {
headers: bodyFormData.getHeaders(),
})
.catch((err) => {
throw `Error in POST ${ETHCONNECT_BASE_URL}${ABIS_URI} with form data. ${err}`;
});

console.log("Sleeping 10s for sync...");
await new Promise((f) => setTimeout(f, 10000));

// POST /abis/<id>
console.log(`POST ${ETHCONNECT_BASE_URL}${ABIS_URI}/${abiRes.data.id}`);
const contractRes = await axios
.post(
`${ETHCONNECT_BASE_URL}${ABIS_URI}/${abiRes.data.id}`,
JSON.stringify({
name: tokenName,
symbol: tokenName,
}),
{
headers: {
accept: "application/json",
"Content-Type": "application/json",
[`x-${ETHCONNECT_PREFIX}-from`]: TOKENS_OWNER_KEY,
},
}
)
.catch((err) => {
throw `Error in POST ${ETHCONNECT_BASE_URL}${ABIS_URI}/${abiRes.data.id}. ${err}`;
});

console.log("Sleeping 10s for sync...");
await new Promise((f) => setTimeout(f, 10000));

console.log(`GET ${ETHCONNECT_BASE_URL}${CONTRACTS_URI}`);
const contracts = await axios
.get(`${ETHCONNECT_BASE_URL}${CONTRACTS_URI}`, {
headers: {
accept: "application/json",
"Content-Type": "application/json",
},
})
.catch((err) => {
console.log(`Error in GET ${ETHCONNECT_BASE_URL}${CONTRACTS_URI}. ${err}`);
});

const contract = contracts.data.filter(contract => contract.abi === abiRes.data.id)[0];

return {
address: `0x${contract.address}`,
abiId: abiRes.data.id
};
}


console.log("\n\n");

if (ERC20_ENABLED) {
const erc20Contract = await deployTokenContract(erc20ContractJson, ERC20_TOKEN_NAME);
console.log("ERC20");
console.log(`\tAddress: ${erc20Contract.address}`);
console.log(`\tABI ID: ${erc20Contract.abiId}\n`);
}

if (ERC721_ENABLED) {
const erc721Contract = await deployTokenContract(erc721ContractJson, ERC721_TOKEN_NAME);
console.log("ERC721");
console.log(`\tAddress: ${erc721Contract.address}`);
console.log(`\tABI ID: ${erc721Contract.abiId}\n`);
}
};

(async () => {
try {
await deployContracts();
} catch (e) {
console.error(`Failed to deploy contracts due to: ${e}`);
process.exit(1);
}
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ff-deploy-erc20-erc721-contracts",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": true,
"author": "",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.25.0",
"form-data": "^4.0.0"
}
}
32 changes: 17 additions & 15 deletions charts/firefly/scripts/ff-register-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set -e

apk add curl jq

until STATUS=$(curl -s ${ETHCONNECT_URL}/contracts); do
until STATUS=$(curl --fail -s ${ETHCONNECT_URL}/contracts); do
echo "Waiting for Ethconnect..."
sleep 5
done
Expand All @@ -36,22 +36,24 @@ done

# FF contract

publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/firefly.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/firefly.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
curl -s --fail -H "Content-Type: application/json" -X POST -H "x-${ETHCONNECT_PREFIX}-sync: true" -H "x-${ETHCONNECT_PREFIX}-register: firefly" "${ETHCONNECT_URL}$(echo -n $publishResponse | jq -r .path)/${FIREFLY_CONTRACT_ADDRESS}"
if ! curl --fail -s "${ETHCONNECT_URL}/contracts/${FIREFLY_CONTRACT_ADDRESS}"; then
echo "[${FIREFLY_CONTRACT_ADDRESS}] has not been registered for the FireFly contract, registering now..."
publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/firefly.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/firefly.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
curl -s --fail -H "Content-Type: application/json" -X POST -H "x-${ETHCONNECT_PREFIX}-sync: true" -H "x-${ETHCONNECT_PREFIX}-register: firefly" "${ETHCONNECT_URL}$(echo -n $publishResponse | jq -r .path)/${FIREFLY_CONTRACT_ADDRESS}"
else
echo "[${FIREFLY_CONTRACT_ADDRESS}] is already registered for the FireFly contract."
fi


# ERC1155 contract
if [[ "${FIREFLY_ERC1155_ENABLED}" == "true" ]]; then
# publish and register ERC1155
publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/erc1155.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/erc1155.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
curl -s --fail -H "Content-Type: application/json" -X POST -H "x-${ETHCONNECT_PREFIX}-sync: true" -H "x-${ETHCONNECT_PREFIX}-register: firefly-erc1155" "${ETHCONNECT_URL}$(echo -n $publishResponse | jq -r .path)/${FIREFLY_ERC1155_CONTRACT_ADDRESS}"
fi

if [[ "${FIREFLY_ERC20_ENABLED}" == "true" ]]; then
# publish and register ERC20 factory
publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/erc20Factory.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/erc20Factory.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
curl --fail -H "Content-Type: application/json" -X POST -H "x-${ETHCONNECT_PREFIX}-sync: true" -H "x-${ETHCONNECT_PREFIX}-register: firefly-erc20-factory" "${ETHCONNECT_URL}$(echo -n $publishResponse | jq -r .path)/${FIREFLY_ERC20_FACTORY_CONTRACT_ADDRESS}"

# publish ERC20
publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/erc20.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/erc20.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
echo "ERC20 ABI URI: $(echo -n $publishResponse | jq -r .path)"
if ! curl --fail -s "${ETHCONNECT_URL}/contracts/${FIREFLY_ERC1155_CONTRACT_ADDRESS}"; then
# publish and register ERC1155
echo "[${FIREFLY_ERC1155_CONTRACT_ADDRESS}] has not been registered for the FireFly ERC1155 contract, registering now..."
publishResponse=$(curl -s --fail -F "abi=$(cat /var/lib/ethconnect/contracts/erc1155.json | jq -r '.abi')" -F bytecode=$(cat /var/lib/ethconnect/contracts/erc1155.json | jq -r '.bytecode') "${ETHCONNECT_URL}/abis")
curl -s --fail -H "Content-Type: application/json" -X POST -H "x-${ETHCONNECT_PREFIX}-sync: true" -H "x-${ETHCONNECT_PREFIX}-register: firefly-erc1155" "${ETHCONNECT_URL}$(echo -n $publishResponse | jq -r .path)/${FIREFLY_ERC1155_CONTRACT_ADDRESS}"
else
echo "[${FIREFLY_ERC1155_CONTRACT_ADDRESS}] is already registered for the FireFly ERC1155 contract."
fi
fi
24 changes: 16 additions & 8 deletions charts/firefly/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kuberentes.io/part-of: {{ .Chart.Name }}
{{- end }}

{{- define "firefly.erc20Labels" -}}
{{- define "firefly.erc20erc721Labels" -}}
helm.sh/chart: {{ include "firefly.chart" . }}
{{ include "firefly.erc20SelectorLabels" . }}
{{ include "firefly.erc20erc721SelectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down Expand Up @@ -125,10 +125,10 @@ app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: erc1155
{{- end }}

{{- define "firefly.erc20SelectorLabels" -}}
{{- define "firefly.erc20erc721SelectorLabels" -}}
app.kubernetes.io/name: {{ include "firefly.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: erc20
app.kubernetes.io/component: erc20-erc721
{{- end }}

{{- define "firefly.ethconnectSelectorLabels" -}}
Expand All @@ -137,6 +137,14 @@ app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: ethconnect
{{- end }}

{{- define "firefly.ethconnectRegisterContractsJobName" -}}
{{ printf "%s-%s-%s-register-contracts" (include "firefly.fullname" .) (.Values.config.organizationName | lower) .Chart.Version | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "firefly.erc20erc721DeployContractsJobName" -}}
{{ printf "%s-%s-%s-erc20-erc-721-deploy-contracts" (include "firefly.fullname" .) (.Values.config.organizationName | lower) .Chart.Version | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Config helpers
*/}}
Expand Down Expand Up @@ -300,17 +308,17 @@ dataexchange:
{{- if .Values.config.tokensOverride }}
tokens:
{{- tpl .Values.config.tokensOverride . | nindent 2 }}
{{- else if or .Values.erc1155.enabled .Values.erc20.enabled }}
{{- else if or .Values.erc1155.enabled .Values.erc20erc721.enabled }}
tokens:
{{- if .Values.erc1155.enabled }}
- plugin: fftokens
name: erc1155
url: http://{{ include "firefly.fullname" . }}-erc1155.{{ .Release.Namespace }}.svc:{{ .Values.erc1155.service.port }}
{{- end }}
{{- if .Values.erc20.enabled }}
{{- if .Values.erc20erc721.enabled }}
- plugin: fftokens
name: erc20
url: http://{{ include "firefly.fullname" . }}-erc20.{{ .Release.Namespace }}.svc:{{ .Values.erc20.service.port }}
name: erc20-erc721
url: http://{{ include "firefly.fullname" . }}-erc20-erc721.{{ .Release.Namespace }}.svc:{{ .Values.erc20erc721.service.port }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
4 changes: 3 additions & 1 deletion charts/firefly/templates/core/job-migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ template "firefly.fullname" . }}-{{ .Values.core.image.tag | default (printf "v%s" .Chart.AppVersion) }}-migrations"
name: "{{ include "firefly.fullname" . }}-{{ .Values.core.image.tag | default (printf "v%s" .Chart.AppVersion) }}-migrations"
labels:
{{- include "firefly.coreLabels" . | nindent 4 }}
spec:
backoffLimit: 5
activeDeadlineSeconds: 12000
Expand Down
4 changes: 3 additions & 1 deletion charts/firefly/templates/core/job-registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ template "firefly.fullname" . }}-{{ .Values.config.organizationName | lower }}-registration"
name: "{{ include "firefly.fullname" . }}-{{ .Values.config.organizationName | lower }}-{{ .Values.core.image.tag | default (printf "v%s" .Chart.AppVersion) }}-registration"
labels:
{{- include "firefly.coreLabels" . | nindent 4 }}
spec:
backoffLimit: 5
activeDeadlineSeconds: 12000
Expand Down
28 changes: 28 additions & 0 deletions charts/firefly/templates/erc20erc721/configmap-deploy-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{/*
Copyright © 2022 Kaleido, Inc.

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://swww.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if and .Values.erc20erc721.enabled .Values.erc20erc721.job.deployContracts.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "firefly.fullname" . }}-erc20-erc721-deploy-scripts
labels:
{{- include "firefly.erc20erc721Labels" . | nindent 4 }}
data:
{{ (.Files.Glob "scripts/ff-deploy-erc20-erc721-contracts/*").AsConfig | indent 2 }}
{{- end }}
Loading

0 comments on commit c534110

Please sign in to comment.