-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33e0fe1
commit fa4a3ad
Showing
7 changed files
with
397 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BERKELEY_MINA= | ||
BERKELEY_ARCHIVE= | ||
BERKELEY_COMMITTEE_ADDRESS= | ||
BERKELEY_DKG_ADDRESS= | ||
BERKELEY_ROUND_1_ADDRESS= | ||
BERKELEY_ROUND_2_ADDRESS= | ||
BERKELEY_REQUEST_ADDRESS= | ||
BERKELEY_RESPONSE_ADDRESS= | ||
BERKELEY_PROJECT_ADDRESS= | ||
BERKELEY_CAMPAIGN_ADDRESS= | ||
BERKELEY_PARTICIPATION_ADDRESS= | ||
BERKELEY_FUNDING_ADDRESS= | ||
BERKELEY_TREASURY_ADDRESS= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'dotenv/config.js'; | ||
import fs from 'fs'; | ||
import { Cache, Mina, PrivateKey, PublicKey, fetchAccount } from 'o1js'; | ||
import { Config, JSONKey, Key } from '../helper/config.js'; | ||
import { wait } from '../helper/deploy.js'; | ||
import { Contract, ZkAppEnum } from '../../constants.js'; | ||
import { | ||
EMPTY_ADDRESS_MT, | ||
AddressStorage, | ||
} from '../../contracts/SharedStorage.js'; | ||
|
||
export async function prepare() { | ||
// Cache folder | ||
const cache = Cache.FileSystem('./caches'); | ||
|
||
// Network configuration | ||
const network = Mina.Network({ | ||
mina: process.env.BERKELEY_MINA as string, | ||
archive: process.env.BERKELEY_ARCHIVE as string, | ||
}); | ||
Mina.setActiveInstance(network); | ||
const FEE = 0.101 * 1e9; | ||
|
||
// Accounts configuration | ||
let configJson: Config = JSON.parse(fs.readFileSync('config.json', 'utf8')); | ||
let acc1: JSONKey = JSON.parse( | ||
fs.readFileSync(configJson.deployAliases['acc1'].keyPath, 'utf8') | ||
); | ||
let acc2: JSONKey = JSON.parse( | ||
fs.readFileSync(configJson.deployAliases['acc2'].keyPath, 'utf8') | ||
); | ||
let acc3: JSONKey = JSON.parse( | ||
fs.readFileSync(configJson.deployAliases['acc3'].keyPath, 'utf8') | ||
); | ||
let acc4: JSONKey = JSON.parse( | ||
fs.readFileSync(configJson.deployAliases['acc4'].keyPath, 'utf8') | ||
); | ||
|
||
let feePayerKey: Key; | ||
feePayerKey = { | ||
privateKey: PrivateKey.fromBase58(acc1.privateKey), | ||
publicKey: PublicKey.fromBase58(acc1.publicKey), | ||
}; | ||
let sender, feePayerNonce; | ||
do { | ||
console.log('Fetch nonce...'); | ||
sender = await fetchAccount({ publicKey: feePayerKey.publicKey }); | ||
feePayerNonce = Number(sender.account?.nonce); | ||
if (!isNaN(feePayerNonce)) { | ||
console.log('Nonce:', feePayerNonce); | ||
break; | ||
} | ||
await wait(1000); // 1s | ||
} while (true); | ||
|
||
let addressMerkleTree = EMPTY_ADDRESS_MT(); | ||
|
||
// Read contract address from config | ||
await Promise.all( | ||
Object.keys(Contract) | ||
.filter((item) => isNaN(Number(item))) | ||
.map(async (e) => { | ||
let config = configJson.deployAliases[e.toLowerCase()]; | ||
let keyBase58: { privateKey: string; publicKey: string } = JSON.parse( | ||
fs.readFileSync(config.keyPath, 'utf8') | ||
); | ||
let key = { | ||
privateKey: PrivateKey.fromBase58(keyBase58.privateKey), | ||
publicKey: PublicKey.fromBase58(keyBase58.publicKey), | ||
}; | ||
addressMerkleTree.setLeaf( | ||
AddressStorage.calculateIndex(ZkAppEnum[e]).toBigInt(), | ||
AddressStorage.calculateLeaf(key.publicKey) | ||
); | ||
}) | ||
); | ||
|
||
return { | ||
feePayer: { | ||
key: feePayerKey, | ||
nonce: feePayerNonce, | ||
fee: FEE, | ||
}, | ||
cache, | ||
addressMerkleTree, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import fs from 'fs'; | ||
import { | ||
Cache, | ||
Field, | ||
Mina, | ||
PrivateKey, | ||
Provable, | ||
PublicKey, | ||
Reducer, | ||
fetchAccount, | ||
} from 'o1js'; | ||
import { Config, JSONKey, Key } from '../../helper/config.js'; | ||
import { | ||
ContractList, | ||
compile, | ||
wait, | ||
proveAndSend, | ||
} from '../../helper/deploy.js'; | ||
import { fetchActions, fetchZkAppState } from '../../helper/deploy.js'; | ||
import { | ||
ProjectContract, | ||
ProjectAction, | ||
CreateProject, | ||
CreateProjectInput, | ||
ProjectProof, | ||
} from '../../../contracts/Project.js'; | ||
import { | ||
MemberStorage, | ||
InfoStorage, | ||
MemberArray, | ||
} from '../../../contracts/ProjectStorage.js'; | ||
import axios from 'axios'; | ||
import { IPFSHash } from '@auxo-dev/auxo-libs'; | ||
import { prepare } from '../prepare.js'; | ||
|
||
async function main() { | ||
const { cache, feePayer } = await prepare(); | ||
|
||
// Compile programs | ||
await compile(CreateProject, cache); | ||
await compile(ProjectContract, cache); | ||
|
||
const projectAddress = | ||
'B62qoGy5GKNRaa2P8uh4ppdRqnCVjNyHqVSsaD4JMcE6FawLRKmmN4u'; | ||
const projectContract = new ProjectContract( | ||
PublicKey.fromBase58(projectAddress) | ||
); | ||
|
||
// Do this and state value of contract is fetched in Mina | ||
const rawState = (await fetchZkAppState(projectAddress)) || []; | ||
|
||
let arrayPublicKey = [ | ||
'B62qjvrida5Kr4rj7f4gDZyG77TdFMp2ntZ9uf5Xzb7iPodykUgwYqm', | ||
'B62qnhBkHqUeUTmYiAvvGdywce7j5PeTdU6t6mi7UAL8emD3mDPtQW2', | ||
'B62qnk1is4cK94PCX1QTwPM1SxfeCF9CcN6Nr7Eww3JLDgvxfWdhR5S', | ||
'B62qmtfTkHLzmvoKYcTLPeqvuVatnB6wtnXsP6jrEi6i2eUEjcxWauH', | ||
].map((e) => PublicKey.fromBase58(e)); | ||
let memberArray = new MemberArray(arrayPublicKey); | ||
|
||
let input = new CreateProjectInput({ | ||
members: memberArray, | ||
ipfsHash: IPFSHash.fromString( | ||
'QmNQLoDczHM3HXKodoYQnRszgd4JR4ZxzEKYe534eEBCc2' | ||
), | ||
payeeAccount: PublicKey.fromBase58( | ||
'B62qnk1is4cK94PCX1QTwPM1SxfeCF9CcN6Nr7Eww3JLDgvxfWdhR5S' | ||
), | ||
}); | ||
|
||
let tx = await Mina.transaction( | ||
{ | ||
sender: feePayer.key.publicKey, | ||
fee: feePayer.fee, | ||
nonce: feePayer.nonce++, | ||
}, | ||
() => { | ||
projectContract.createProject(input); | ||
} | ||
); | ||
await proveAndSend(tx, feePayer.key, 'projectContract', 'createProject'); | ||
} | ||
|
||
main() | ||
.then() | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.