Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload metadata to ipfs #55

Open
wants to merge 5 commits into
base: audit-20241118
Choose a base branch
from
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
30 changes: 20 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Used for fork testing
NETWORK_RPC_URL=
# GENERAL

VERIFIER=
ETHERSCAN_API_KEY=
NETWORK_RPC_URL=
# The osx supported network name used for testing purposes and deployment
NETWORK_NAME="devSepolia" # ["mainnet", "sepolia", "polygon", "polygonMumbai", "base", "baseSepolia", "arbitrum", "arbitrumSepolia"]

DEPLOYER_KEY=
DEPLOYER_ADDR=
# One or multiple hex encoded private keys separated by commas `,` replacing the hardhat default accounts.
DEPLOYER_KEY=0xe4dc625275ded38ed377253b8b5d464e8b9414b036e8fba4f49aae908384adb0

CHAIN=
NETWORK_NAME=
PROTOCOL_VERSION=
# The osx protocol version used
PROTOCOL_VERSION="v1.3.0"


# Deployment

# The chain name, this is used to determine the chain id and the rpc url
CHAIN=sepolia

VERIFIER='etherscan'
ETHERSCAN_API_KEY=WQ7EFJVI6QCN9XKY3ET6IS4S7IX8CJ8QCW
NETWORK_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/odroQEdm5NV-FzxILCFWA4bvWql6uivF"


PUB_PINATA_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiI1NTAyNjU3MS0xODQ3LTQwMGEtOWM1Ni1mNWFhNGRmMzQ0MTgiLCJlbWFpbCI6ImFjY291bnRzQGFyYWdvbi5vcmciLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwicGluX3BvbGljeSI6eyJyZWdpb25zIjpbeyJkZXNpcmVkUmVwbGljYXRpb25Db3VudCI6MSwiaWQiOiJGUkExIn1dLCJ2ZXJzaW9uIjoxfSwibWZhX2VuYWJsZWQiOmZhbHNlLCJzdGF0dXMiOiJBQ1RJVkUifSwiYXV0aGVudGljYXRpb25UeXBlIjoic2NvcGVkS2V5Iiwic2NvcGVkS2V5S2V5IjoiZTVjYTllODYxYzE5ODExYTIwMDYiLCJzY29wZWRLZXlTZWNyZXQiOiI0YzlmZjIxOGY5MWJmNGZjYWE0YmEyMjBkNDAzNzUyZmEwOTUxZmNmY2RjNjVmNjJhM2UyNGUxMTY2YjUzYjAwIiwiZXhwIjoxNzYzNDcyMDU5fQ.3I9n6RdfhVLFGPY75YgFaLOcuVr7kPac_NdFtsIrhMY
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"solhint": "^3.6.2",
"solhint-plugin-prettier": "^0.0.5"
"solhint-plugin-prettier": "^0.0.5",
"ts-node": "^10.9.2"
},
"dependencies": {
"@aragon/osx": "1.3.0",
"@aragon/osx-commons-configs": "^0.5.0",
"@aragon/osx-commons-contracts": "1.4.0-alpha.5",
"@aragon/osx-commons-sdk": "0.0.1-alpha.11",
"@ensdomains/ens-contracts": "^1.1.4",
"@openzeppelin/contracts": "^4.9.6",
"@openzeppelin/contracts-upgradeable": "^4.9.6"
Expand Down
23 changes: 20 additions & 3 deletions script/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ contract BaseScript is Script, Constants {
revert InvalidVersionBuild(PluginSettings.VERSION_BUILD, uint8(latestBuild));
}

// get build and release metadata ipfs cids
(string memory _buildCID, string memory _releaseCID) = _uploadMetadataToIPFS();

// create plugin version
sppRepo.createVersion(
PluginSettings.VERSION_RELEASE,
address(_sppSetup),
PluginSettings.BUILD_METADATA,
PluginSettings.RELEASE_METADATA
bytes(_buildCID),
bytes(_releaseCID)
);

// check version was created correctly
Expand All @@ -109,7 +112,7 @@ contract BaseScript is Script, Constants {

console.log(
"Published Staged Proposal Plugin at ",
address(sppSetup),
address(_sppSetup),
" with ",
_versionString(PluginSettings.VERSION_RELEASE, PluginSettings.VERSION_BUILD)
);
Expand Down Expand Up @@ -151,4 +154,18 @@ contract BaseScript is Script, Constants {
)
);
}

function _uploadMetadataToIPFS()
internal
returns (string memory buildCID, string memory releaseCID)
{
string[] memory inputs = new string[](4);
inputs[0] = "npx";
inputs[1] = "ts-node";
inputs[2] = "script/upload-metadata-to-pinnata.ts";
inputs[3] = PluginSettings.PLUGIN_REPO_ENS_SUBDOMAIN_NAME;

bytes memory res = vm.ffi(inputs);
(buildCID, releaseCID) = abi.decode(res, (string, string));
}
}
10 changes: 7 additions & 3 deletions script/NewVersion.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract NewVersion is BaseScript {

function _buildProposalData(
address _sppSetup
) internal view returns (ProposalData memory _proposalData) {
) internal returns (ProposalData memory _proposalData) {
_proposalData.title = string(
abi.encodePacked(
"Publish Staged Proposal Plugin ",
Expand All @@ -66,6 +66,10 @@ contract NewVersion is BaseScript {
" of the Staged Proposal Plugin"
)
);

// get build and release metadata ipfs cids
(string memory _buildCID, string memory _releaseCID) = _uploadMetadataToIPFS();

_proposalData.actions = new Action[](1);
_proposalData.actions[0] = Action({
to: address(sppRepo),
Expand All @@ -74,8 +78,8 @@ contract NewVersion is BaseScript {
sppRepo.createVersion.selector,
PluginSettings.VERSION_RELEASE,
_sppSetup,
PluginSettings.BUILD_METADATA,
PluginSettings.RELEASE_METADATA
bytes(_buildCID),
bytes(_releaseCID)
)
});
}
Expand Down
24 changes: 24 additions & 0 deletions script/upload-metadata-to-pinnata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {uploadToPinata} from '@aragon/osx-commons-sdk';

import buildMetadata from '../src/build-metadata.json';
import releaseMetadata from '../src/release-metadata.json';

import {ethers} from 'ethers';

async function uploadMetadataToIPFS(subdomainName: string): Promise<string> {
const buildMetadataCIDPath = await uploadToPinata(
JSON.stringify(buildMetadata, null, 2),
`${subdomainName}-build-metadata`
);

const releaseMetadataCIDPath = await uploadToPinata(
JSON.stringify(releaseMetadata, null, 2),
`${subdomainName}-release-metadata`
);

return ethers.utils.defaultAbiCoder.encode(['string', 'string'], [buildMetadataCIDPath, releaseMetadataCIDPath]);
}

(async () => {
console.log(await uploadMetadataToIPFS(process.argv[2]));
})();
9 changes: 1 addition & 8 deletions src/utils/PluginSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@ pragma solidity ^0.8.18;
library PluginSettings {
string public constant PLUGIN_CONTRACT_NAME = "StagedProposalProcessor";
string public constant PLUGIN_SETUP_CONTRACT_NAME = "StagedProposalProcessorSetup";
string public constant PLUGIN_REPO_ENS_SUBDOMAIN_NAME = "testting"; // 'spp.plugin.dao.eth'
string public constant PLUGIN_REPO_ENS_SUBDOMAIN_NAME = "spp"; // 'spp.plugin.dao.eth'

// Specify the version of your plugin that you are currently working on. The first version is v1.1.
// For more details, visit https://devs.aragon.org/docs/osx/how-it-works/framework/plugin-management/plugin-repo.
uint8 public constant VERSION_RELEASE = 1;
uint8 public constant VERSION_BUILD = 1;

// 1. upload build-metadata and release-metadata jsons to the IPFS.
// 2. use ethers to convert it to utf8 bytes:
// ethers.utils.hexlify(ethers.utils.toUtf8Bytes(`ipfs://${cid}`))
// 3. Copy/paste the bytes into BUILD_METADATA and RELEASE_METADATA
bytes public constant BUILD_METADATA = "dummy";
bytes public constant RELEASE_METADATA = "dummy";
}
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"removeComments": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "es6"
},
"exclude": ["node_modules"],
"include": [
"script/**/*"
]
}