Skip to content

Commit

Permalink
add: celo deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Aug 17, 2023
1 parent dcd1e82 commit 359d57c
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 301 deletions.
4 changes: 4 additions & 0 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# for deployment
MNEMONIC=
# for verification
CELOSCAN_KEY=
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ contract DirectPaymentsFactory is AccessControlUpgradeable, UUPSUpgradeable {
pool.grantRole(pool.MINTER_ROLE(), _settings.manager);

//access control to project is determinted by the first pool access control rules
projectIdToControlPool[keccak256(bytes(_projectId))] = pool;
if (address(projectIdToControlPool[keccak256(bytes(_projectId))]) == address(0))
projectIdToControlPool[keccak256(bytes(_projectId))] = pool;
registry[address(pool)].ipfs = _ipfs;
registry[address(pool)].projectId = _projectId;

Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'hardhat-abi-exporter';
import 'hardhat-contract-sizer';
import '@openzeppelin/hardhat-upgrades';
import 'hardhat-deploy';
import 'hardhat-celo';
import { HardhatUserConfig } from 'hardhat/config';

dotenv.config();
Expand Down Expand Up @@ -67,6 +68,12 @@ const config: HardhatUserConfig = {
accounts: {
mnemonic: process.env.MNEMONIC,
},
verify: {
etherscan: {
apiKey: process.env.CELOSCAN_KEY,
apiUrl: 'https://api.celoscan.io/',
},
},
},
},
etherscan: {
Expand Down
6 changes: 4 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "2.*",
"@nomicfoundation/hardhat-verify": "^1.0.1",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@openzeppelin/contracts": "^4.9.2",
Expand All @@ -35,6 +35,7 @@
"graphql": "^16.7.1",
"hardhat": "2.14.*",
"hardhat-abi-exporter": "^2.10.1",
"hardhat-celo": "^0.0.4",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.31",
"hardhat-gas-reporter": "^1.0.8",
Expand Down Expand Up @@ -63,6 +64,7 @@
"deploy": "hardhat deploy --export-all ./releases/deployment.json",
"prepublish": "yarn version patch && yarn compile && git add package.json && git commit -m \"version bump\"",
"publish": "yarn npm publish --access public",
"test:setup": "yarn exec ./scripts/deployContracts.sh"
"test:setup": "yarn exec ./scripts/deployContracts.sh",
"verify": "npx hardhat run scripts/verify.ts --network ${0}"
}
}
307 changes: 19 additions & 288 deletions packages/contracts/releases/deployment.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions packages/contracts/scripts/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import hre, { ethers } from 'hardhat';
import fetch from 'node-fetch';
const main = async () => {
const contract = await hre.deployments.get('DirectPaymentsFactory');
const poolImpl = await hre.deployments.get('DirectPaymentsPool');
const factory = await ethers.getContractAt('DirectPaymentsFactory', contract.address);

//verify beacon which is internal to the factory
const beacon = await factory.impl();
const verifyBecon = hre.run('verify', {
address: beacon,
constructorArgsParams: [poolImpl.address],
contract: '@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol:UpgradeableBeacon',
});
await Promise.all([verifyBecon, hre.run('sourcify'), hre.run('etherscan-verify')]);

//copy beacon to sourcify
const res = await fetch('https://sourcify.dev/server/session/verify/etherscan', {
method: 'POST',
body: JSON.stringify({ address: beacon, chainId: String(hre.network.config.chainId) }),
headers: {
'Content-Type': 'application/json',
},
});
console.log('sourcify beacon copy result', res.statusText);
};

main().catch((e) => console.log(e));
3 changes: 3 additions & 0 deletions packages/sdk-js/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# nft.storage key for createpool.ts script/tests
VITE_NFTSTORAGE_KEY=
# private key for running createPool.ts script
PRIVATE_KEY=
3 changes: 1 addition & 2 deletions packages/sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@gooddollar/goodcollective-sdk",
"license": "MIT",
"version": "1.0.6",
"type": "module",
"main": "./dist/sdk.umd.cjs",
"module": "./dist/sdk.js",
"types": "./types/index.d.ts",
Expand Down Expand Up @@ -51,4 +50,4 @@
"nft.storage": "^7.1.1"
},
"packageManager": "yarn@3.6.0"
}
}
36 changes: 36 additions & 0 deletions packages/sdk-js/scripts/createPool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Run with npx ts-node --esm
import * as ethers from 'ethers';
import { GoodCollectiveSDK } from '../src/goodcollective/goodcollective';

// const provider = new ethers.providers.JsonRpcProvider('https://alfajores-forno.celo-testnet.org');
const provider = new ethers.providers.JsonRpcProvider('https://forno.celo.org');
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY || '').connect(provider);
const sdk = new GoodCollectiveSDK('42220', provider, { nftStorageKey: process.env.VITE_NFTSTORAGE_KEY });

const main = async () => {
const projectId = 'your project id';
const poolAttributes = {
name: 'pool name',
description: 'pool description',
email: 'contact@email.com',
twitter: '@handle',
};
const poolSettings = {
validEvents: [1, 2],
rewardPerEvent: [ethers.constants.WeiPerEther, ethers.constants.WeiPerEther.mul(2)],
manager: wallet.address,
membersValidator: ethers.constants.AddressZero,
uniquenessValidator: ethers.constants.AddressZero,
rewardToken: '0x03d3daB843e6c03b3d271eff9178e6A96c28D25f',
};

const poolLimits = {
maxTotalPerMonth: ethers.constants.WeiPerEther.mul(1000),
maxMemberPerMonth: ethers.constants.WeiPerEther.mul(10),
maxMemberPerDay: ethers.constants.WeiPerEther.mul(5),
};
const pool = await sdk.createPoolWithAttributes(wallet, projectId, poolAttributes, poolSettings, poolLimits);
console.log(pool.address);
};

main();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const wallet = ethers.Wallet.fromMnemonic('test test test test test test test te
localProvider
);
const contracts =
GoodCollectiveContracts[31337][GoodCollectiveContracts['31337'].findIndex((_) => _.name === 'localhost') || 0]
GoodCollectiveContracts['31337'][GoodCollectiveContracts['31337'].findIndex((_) => _.name === 'localhost') || 0]
.contracts;

const registry = new ethers.Contract(
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-js/src/goodcollective/goodcollective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class GoodCollectiveSDK {
const data = Buffer.from(JSON.stringify(attrs));
const file = new File([data], 'pool.json', { type: 'application/json' });
const uri = await this.nftStorage.storeBlob(file);
console.log({ uri });
return uri;
}
/**
Expand Down
13 changes: 13 additions & 0 deletions packages/sdk-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"ts-node": {
"compilerOptions": {
"lib": ["es2021"],
"module": "commonjs",
"target": "es2021",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
}
},
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-js/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
entry: './src/index.ts',
name: 'sdk',
fileName: 'sdk',
formats: ['cjs', 'es'],
},
},
test: {
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"installConfig": {
"hoistingLimits": "workspaces"
}
}
}
49 changes: 44 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4333,7 +4333,7 @@ __metadata:
"@nomicfoundation/hardhat-chai-matchers": ^1.0.0
"@nomicfoundation/hardhat-network-helpers": ^1.0.0
"@nomicfoundation/hardhat-toolbox": 2.*
"@nomicfoundation/hardhat-verify": ^1.0.1
"@nomicfoundation/hardhat-verify": ^1.1.1
"@nomiclabs/hardhat-ethers": ^2.0.0
"@nomiclabs/hardhat-etherscan": ^3.0.0
"@openzeppelin/contracts": ^4.9.2
Expand All @@ -4354,6 +4354,7 @@ __metadata:
graphql: ^16.7.1
hardhat: 2.14.*
hardhat-abi-exporter: ^2.10.1
hardhat-celo: ^0.0.4
hardhat-contract-sizer: ^2.10.0
hardhat-deploy: ^0.11.31
hardhat-gas-reporter: ^1.0.8
Expand Down Expand Up @@ -5770,9 +5771,36 @@ __metadata:
languageName: node
linkType: hard

"@nomicfoundation/hardhat-verify@npm:^1.0.1":
version: 1.0.1
resolution: "@nomicfoundation/hardhat-verify@npm:1.0.1"
"@nomicfoundation/hardhat-toolbox@npm:^1.0.2":
version: 1.0.2
resolution: "@nomicfoundation/hardhat-toolbox@npm:1.0.2"
peerDependencies:
"@ethersproject/abi": ^5.4.7
"@ethersproject/providers": ^5.4.7
"@nomicfoundation/hardhat-chai-matchers": ^1.0.0
"@nomicfoundation/hardhat-network-helpers": ^1.0.0
"@nomiclabs/hardhat-ethers": ^2.0.0
"@nomiclabs/hardhat-etherscan": ^3.0.0
"@typechain/ethers-v5": ^10.1.0
"@typechain/hardhat": ^6.1.2
"@types/chai": ^4.2.0
"@types/mocha": ^9.1.0
"@types/node": ">=12.0.0"
chai: ^4.2.0
ethers: ^5.4.7
hardhat: ^2.9.9
hardhat-gas-reporter: ^1.0.8
solidity-coverage: ^0.7.21
ts-node: ">=8.0.0"
typechain: ^8.1.0
typescript: ">=4.5.0"
checksum: d13b3e9f08d8be5f72a25872b6a9d3609fdb34f46b47dbf10963a6fb5003ac1cd0d0c107ef6d91807b864a8766d9e5092518f21db3116902ee5a8ae73fdcaaa2
languageName: node
linkType: hard

"@nomicfoundation/hardhat-verify@npm:^1.1.1":
version: 1.1.1
resolution: "@nomicfoundation/hardhat-verify@npm:1.1.1"
dependencies:
"@ethersproject/abi": ^5.1.2
"@ethersproject/address": ^5.0.2
Expand All @@ -5785,7 +5813,7 @@ __metadata:
undici: ^5.14.0
peerDependencies:
hardhat: ^2.0.4
checksum: d7a92c8659f7ed5c24ee7913c296e1817b6d7d9c4055191e9d454a751d0b7ef0f53b18646576fd56abafb6d5d2c6fc1fb93299a845964afd905f6dae873de77b
checksum: 2d83d32d6833f23fb62c30c68c9a2ab3956098030edcf459e69639960f059c72572d203bcf92f191c69c9cb0fbbf011a1113bacde1e3cbb28d5e812334f04f32
languageName: node
linkType: hard

Expand Down Expand Up @@ -23286,6 +23314,17 @@ __metadata:
languageName: node
linkType: hard

"hardhat-celo@npm:^0.0.4":
version: 0.0.4
resolution: "hardhat-celo@npm:0.0.4"
dependencies:
"@nomicfoundation/hardhat-toolbox": ^1.0.2
peerDependencies:
hardhat: ^2.0.0
checksum: f32e8745081bc5ffaadebb320a4bf5b2ec4a0de5502efb12b0cbff55c84d91ad494d5b6c63874f20cc382ad9bd475a657071b7b38bb2bd632635744e76bce80e
languageName: node
linkType: hard

"hardhat-contract-sizer@npm:^2.10.0":
version: 2.10.0
resolution: "hardhat-contract-sizer@npm:2.10.0"
Expand Down

0 comments on commit 359d57c

Please sign in to comment.