diff --git a/Makefile b/Makefile index c4e91d9..a659685 100644 --- a/Makefile +++ b/Makefile @@ -25,14 +25,14 @@ anvil: deploy-anvil: @echo "Deploying DiamondCutFacet..." - @forge create ./src/facets/DiamondCutFacet.sol:DiamondCutFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondCut to:/g' | tee deployment-anvil.txt - @forge create ./src/Diamond.sol:Diamond --rpc-url anvil --interactive --constructor-args 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 "$$(grep "Deployed DiamondCut to:" deployment-anvil.txt | awk '{print $$4}')" | sed 's/Deployed to:/Deployed Diamond to:/g' | tee -a deployment-anvil.txt - @forge create ./src/upgradeInitializers/DiamondInit.sol:DiamondInit --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondInit to:/g' | tee -a deployment-anvil.txt - @forge create ./src/GenericToken.sol:GenericToken --rpc-url anvil --interactive --constructor-args "GenericToken" "GT" | sed 's/Deployed to:/Deployed GenericToken to:/g' | tee -a deployment-anvil.txt - @forge create ./src/facets/OwnershipFacet.sol:OwnershipFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed OwnershipFacet to:/g' | tee -a deployment-anvil.txt - @forge create ./src/facets/ERC1155Facet.sol:ERC1155Facet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed ERC1155Facet to:/g' | tee -a deployment-anvil.txt - @forge create ./src/facets/DiamondLoupeFacet.sol:DiamondLoupeFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondLoupeFacet to:/g' | tee -a deployment-anvil.txt - @forge create ./src/facets/BondFacet.sol:BondFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed BondFacet to:/g' | tee -a deployment-anvil.txt + @forge create ./src/facets/DiamondCutFacet.sol:DiamondCutFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondCut to:/g' | sed 's/Transaction hash:/Transaction hash DiamondCut:/g' | tee deployment-anvil.txt + @forge create ./src/Diamond.sol:Diamond --rpc-url anvil --interactive --constructor-args 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 "$$(grep "Deployed DiamondCut to:" deployment-anvil.txt | awk '{print $$4}')" | sed 's/Deployed to:/Deployed Diamond to:/g' | sed 's/Transaction hash:/Transaction hash Diamond:/g' | tee -a deployment-anvil.txt + @forge create ./src/upgradeInitializers/DiamondInit.sol:DiamondInit --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondInit to:/g' | sed 's/Transaction hash:/Transaction hash DiamondInit:/g' | tee -a deployment-anvil.txt + @forge create ./src/GenericToken.sol:GenericToken --rpc-url anvil --interactive --constructor-args "GenericToken" "GT" | sed 's/Deployed to:/Deployed GenericToken to:/g' | sed 's/Transaction hash:/Transaction hash GenericToken:/g' | tee -a deployment-anvil.txt + @forge create ./src/facets/OwnershipFacet.sol:OwnershipFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed OwnershipFacet to:/g' | sed 's/Transaction hash:/Transaction hash OwnershipFacet:/g' | tee -a deployment-anvil.txt + @forge create ./src/facets/ERC1155Facet.sol:ERC1155Facet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed ERC1155Facet to:/g' | sed 's/Transaction hash:/Transaction hash ERC1155Facet:/g' | tee -a deployment-anvil.txt + @forge create ./src/facets/DiamondLoupeFacet.sol:DiamondLoupeFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed DiamondLoupeFacet to:/g' | sed 's/Transaction hash:/Transaction hash DiamondLoupeFacet:/g' | tee -a deployment-anvil.txt + @forge create ./src/facets/BondFacet.sol:BondFacet --rpc-url anvil --interactive | sed 's/Deployed to:/Deployed BondFacet to:/g' | sed 's/Transaction hash:/Transaction hash BondFacet:/g' | tee -a deployment-anvil.txt @echo "Retrieving selectors for each facet..." $(eval ADDRESS_OWNERSHIP=$(shell grep "Deployed OwnershipFacet to:" deployment-anvil.txt | awk '{print $$4}')) $(eval ADDRESS_ERC1155=$(shell grep "Deployed ERC1155Facet to:" deployment-anvil.txt | awk '{print $$4}')) @@ -89,14 +89,14 @@ deploy-btp: args="$$args --legacy"; \ fi; \ - @forge create ./src/facets/DiamondCutFacet.sol:DiamondCutFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondCut to:/g' | tee deployment.txt - @forge create ./src/Diamond.sol:Diamond $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args --constructor-args $${BTP_FROM} "$$(grep "Deployed DiamondCut to:" deployment.txt | awk '{print $$4}')" | sed 's/Deployed to:/Deployed Diamond to:/g' | tee -a deployment.txt - @forge create ./src/upgradeInitializers/DiamondInit.sol:DiamondInit $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondInit to:/g' | tee -a deployment.txt - @forge create ./src/GenericToken.sol:GenericToken $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args --constructor-args "GenericToken" "GT" | sed 's/Deployed to:/Deployed GenericToken to:/g' | tee -a deployment.txt - @forge create ./src/facets/OwnershipFacet.sol:OwnershipFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed OwnershipFacet to:/g' | tee -a deployment.txt - @forge create ./src/facets/ERC1155Facet.sol:ERC1155Facet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed ERC1155Facet to:/g' | tee -a deployment.txt - @forge create ./src/facets/DiamondLoupeFacet.sol:DiamondLoupeFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondLoupeFacet to:/g' | tee -a deployment.txt - @forge create ./src/facets/BondFacet.sol:BondFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed BondFacet to:/g' | tee -a deployment.txt + @forge create ./src/facets/DiamondCutFacet.sol:DiamondCutFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondCut to:/g' | sed 's/Transaction hash:/Transaction hash DiamondCut:/g' | tee deployment.txt + @forge create ./src/Diamond.sol:Diamond $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args --constructor-args $${BTP_FROM} "$$(grep "Deployed DiamondCut to:" deployment.txt | awk '{print $$4}')" | sed 's/Deployed to:/Deployed Diamond to:/g' | sed 's/Transaction hash:/Transaction hash Diamond:/g' |tee -a deployment.txt + @forge create ./src/upgradeInitializers/DiamondInit.sol:DiamondInit $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondInit to:/g' | sed 's/Transaction hash:/Transaction hash DiamondInit:/g' | tee -a deployment.txt + @forge create ./src/GenericToken.sol:GenericToken $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args --constructor-args "GenericToken" "GT" | sed 's/Deployed to:/Deployed GenericToken to:/g' | sed 's/Transaction hash:/Transaction hash GenericToken:/g' | tee -a deployment.txt + @forge create ./src/facets/OwnershipFacet.sol:OwnershipFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed OwnershipFacet to:/g' | sed 's/Transaction hash:/Transaction hash OwnershipFacet:/g' | tee -a deployment.txt + @forge create ./src/facets/ERC1155Facet.sol:ERC1155Facet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed ERC1155Facet to:/g' | sed 's/Transaction hash:/Transaction hash ERC1155Facet:/g' | tee -a deployment.txt + @forge create ./src/facets/DiamondLoupeFacet.sol:DiamondLoupeFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed DiamondLoupeFacet to:/g' | sed 's/Transaction hash:/Transaction hash DiamondLoupeFacet:/g' | tee -a deployment.txt + @forge create ./src/facets/BondFacet.sol:BondFacet $${EXTRA_ARGS} --rpc-url $${BTP_RPC_URL} $$args | sed 's/Deployed to:/Deployed BondFacet to:/g' | sed 's/Transaction hash:/Transaction hash BondFacet:/g' | tee -a deployment.txt @echo "Retrieving selectors for each facet..." $(eval ADDRESS_OWNERSHIP=$(shell grep "Deployed OwnershipFacet to:" deployment.txt | awk '{print $$4}')) $(eval ADDRESS_ERC1155=$(shell grep "Deployed ERC1155Facet to:" deployment.txt | awk '{print $$4}')) @@ -129,6 +129,28 @@ deploy-btp: @echo "Diamond cut transaction broadcasted." +subgraph: + @echo "Deploying the subgraph..." + @rm -Rf subgraph/subgraph.config.json + @DEPLOYED_ERC20_ADDRESS= $$(grep "Deployed GenericToken to:" deployment | awk '{print $$4}') DEPLOYED_ADDRESS=$$(grep "Deployed Diamond to:" deployment.txt | awk '{print $$4}') TRANSACTION_HASH=$$(grep "Transaction hash Diamond:" deployment.txt | awk '{print $$4}') BLOCK_NUMBER=$$(cast receipt --rpc-url btp $${TRANSACTION_HASH} TRANSACTION_HASH_ERC20=$$(grep "Transaction hash GenericToken:" deployment.txt | awk '{print $$4}') BLOCK_NUMBER_ERC20=$$(cast receipt --rpc-url btp $${TRANSACTION_HASH_ERC20} | grep "blockNumber" | awk '{print $$2}' | sed '2d') ; \ + yq e -p=json -o=json '.datasources[0].address = env(DEPLOYED_ADDRESS) | .datasources[0].startBlock = env(BLOCK_NUMBER) | .datasources[1].address = env(DEPLOYED_ADDRESS) | .datasources[1].startBlock = env(BLOCK_NUMBER) | .datasources[2].address = env(DEPLOYED_ADDRESS) | .datasources[2].startBlock = env(BLOCK_NUMBER) | .datasources[3].address = env(DEPLOYED_ADDRESS) | .datasources[3].startBlock = env(BLOCK_NUMBER) | .datasources[4].address = env(DEPLOYED_ADDRESS) | .datasources[4].startBlock = env(BLOCK_NUMBER) | .datasources[5].address = env(DEPLOYED_ADDRESS) | .datasources[5].startBlock = env(BLOCK_NUMBER) | .datasources[6].address = env(DEPLOYED_ADDRESS) | .datasources[6].startBlock = env(BLOCK_NUMBER) | .datasources[8].address = env(DEPLOYED_ADDRESS) | .datasources[8].startBlock = env(BLOCK_NUMBER) | .datasources[7].address = env(DEPLOYED_ERC20_ADDRESS) | .datasources[7].startBlock = env(BLOCK_NUMBER_ERC20) |.chain = env(BTP_NODE_UNIQUE_NAME)' subgraph/subgraph.config.template.json > subgraph/subgraph.config.json + @cd subgraph && npx graph-compiler --config subgraph.config.json --include node_modules/@openzeppelin/subgraphs/src/datasources subgraph/datasources --export-schema --export-subgraph + @cd subgraph && yq e '.specVersion = "0.0.4"' -i generated/solidity-token-diamond-bond.subgraph.yaml + @cd subgraph && yq e '.description = "Solidity Token diamond-bond"' -i generated/solidity-token-diamond-bond.subgraph.yaml + @cd subgraph && yq e '.repository = "https://github.com/settlemint/solidity-token-diamond-bond"' -i generated/solidity-token-diamond-bond.subgraph.yaml + @cd subgraph && yq e '.features = ["nonFatalErrors", "fullTextSearch", "ipfsOnEthereumContracts"]' -i generated/solidity-token-diamond-bond.subgraph.yaml + @cd subgraph && npx graph codegen generated/solidity-token-diamond-bond.subgraph.yaml + @cd subgraph && npx graph build generated/solidity-token-diamond-bond.subgraph.yaml + @eval $$(curl -H "x-auth-token: $${BTP_SERVICE_TOKEN}" -s $${BTP_CLUSTER_MANAGER_URL}/ide/foundry/$${BTP_SCS_ID}/env | sed 's/^/export /'); \ + if [ -z "$${BTP_MIDDLEWARE}" ]; then \ + echo "\033[1;31mERROR: You have not launched a graph middleware for this smart contract set, aborting...\033[0m"; \ + exit 1; \ + else \ + cd subgraph; \ + npx graph create --node $${BTP_MIDDLEWARE} $${BTP_SCS_NAME}; \ + npx graph deploy --version-label v1.0.$$(date +%s) --node $${BTP_MIDDLEWARE} --ipfs $${BTP_IPFS}/api/v0 $${BTP_SCS_NAME} generated/solidity-token-diamond-bond.subgraph.yaml; \ + fi + cast: @echo "Interacting with EVM via Cast..." @cast $(SUBCOMMAND) diff --git a/subgraph/subgraph.config.template.json b/subgraph/subgraph.config.template.json new file mode 100644 index 0000000..7e765fd --- /dev/null +++ b/subgraph/subgraph.config.template.json @@ -0,0 +1,54 @@ +{ + "output": "generated/solidity-diamond-bond.", + "chain": "localhost", + "datasources": [ + { + "name": "BondFacet", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "Diamond", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "DiamondCutFacet", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "DiamondInit", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "DiamondLoupeFacet", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "ERC1155Facet", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + }, + { + "name": "GenericToken", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["erc20", "pausable", "accesscontrol"] + }, + { + "name": "OwnershipFacet", + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 0, + "module": ["diamond"] + } + ] +}