Skip to content

Commit

Permalink
Added in UI initializeBalance before depositing
Browse files Browse the repository at this point in the history
  • Loading branch information
manudev97 committed Jul 19, 2024
1 parent 0468f45 commit 5ecfda9
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 91 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

- Actualizado README.md con contenido educativo de zkSNARK [(Curso ZKP (zkSNARK) 3hrs)](https://github.com/manudev97/dapp-zkatm/blob/main/packages/hardhat/README.md)

# IMPORTANTE !
- No utilizar en producción este proyecto es solo con fines educativos sobre la tecnología ZK.

Scroll Sepolia
Address Contract ZKATM: 0x4c0Fd51D88216250507Ec303ACbE76473a19AfE9
Tx: 0x984adea86081cb1a5eee8a9121b249d986e98c981edf199b59f5576b70a61c86
Address Contract ATM 0x3A4b991018579ee83f1Bb3954D71Eaecb9d8149f (solamente 2 niveles)
Tx: 0x9de6591e5f67d88f40e825079e4c44fbbcfc756c99af54d9232f8ff2816ff6a3

# Comandos (zk_ATM - Hasher y Verifier.sol)

### Bridge ETHSepolia Tesnet <---> Scroll Sepolia
Expand All @@ -43,7 +52,7 @@ yarn account #imprimir balances de cuentas
# Inicialmente no se tiene fondo para deploy. Enviamos fondos a Public address: 0x...
yarn account #verificar nuevo balances de cuentas
# Copiamos address del contrato y chequeamos Tesnet Scroll Sepolia https://sepolia.scrollscan.com/
yarn add circomlibjs-old@npm:[email protected] # necesario para hacer
yarn add circomlibjs-old@npm:[email protected] # necesario para hacer match con poseidon en el circuito
yarn add big-integer
mkdir build
node scripts/compileHasher.js
Expand All @@ -66,7 +75,7 @@ snarkjs r1cs export json withdraw.r1cs withdraw.r1cs.json # mejor lectura del
#### Testigo (Crear archivo input.json)
```sh
cd withdraw_js
nano input.json # agregar valores de las señales
nano input.json # agregar valores de las señales: Ejemplo
{
"root": "0x14fede0676ad0f9cf51a5624214ef16b8ed71acf28346cb295ffb93da237d604",
"nullifierHash": "0x1ceba1ab7f0672deab84b6595732266fc91bd24cc69cd435ceafdf1067cfce85",
Expand Down
8 changes: 2 additions & 6 deletions packages/hardhat/contracts/ATM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ contract ATM is MerkleTree {
// _merkleTreeHeight --> la altura del árbol Merkle de los depósitos
// Hasher address (Poseidon 1 args): 0xCc735e52E393f125cAFc4E0aEbD80AEd81eA4B41
// Verifier address: 0x0918fe077e800b24E1D64c2FE9bb6a12E0255CA9
// ZKATM_TOKEN address: 0x2a8f9804C5f830ECbe831B2717D210B6d9895134
// ZKATM_TOKEN new address: 0xa78a484c097d27a4922fF07033c702c2Da85b6FC
// ATM address: 0x556E6C30C2a28ef3C9c9C464E8Cf0F561678F779
// ATM new address: 0xdB7a0b5fB1c909cdBcB19F3748cB957470E94B57 --> 0xd1020f336bebdd4649Daa32B6bAb0660492A7C5b
//0xE77d6D6982fF47D3fe83CeBd11BC6f7a2cc0Aef5

constructor(
IVerifier _verifier,
address _hasher,
Expand Down Expand Up @@ -87,7 +83,7 @@ contract ATM is MerkleTree {
// commitment el compromiso de nota, que es poseidonhash(anulador + secreto)
function deposit(bytes32 commitment, uint256 _amount) public {
require(!commitments[commitment], "El compromiso ya se ha insertado");
if(balance[msg.sender] < _amount) revert InsufficientBalance();
if(zkatmToken.balanceOf(msg.sender) < _amount) revert InsufficientBalance();
require(_amount == (denomination * (10 ** zkatmToken.decimals())), "La cantidad depositada no es admitida");

// Transfiere los tokens desde el usuario que llama a la función hacia este contrato
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/02_deploy_atm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const deployATM: DeployFunction = async function (hre: HardhatRuntimeEnvironment
await deploy("ATM", {
from: deployer,
// Contract constructor arguments
args: ["0x0918fe077e800b24E1D64c2FE9bb6a12E0255CA9", "0xCc735e52E393f125cAFc4E0aEbD80AEd81eA4B41", "5", "5", "0xDD8fA77500F94b2286AbE41c81B4a08EdD0429B9"],
args: ["0x0918fe077e800b24E1D64c2FE9bb6a12E0255CA9", "0xCc735e52E393f125cAFc4E0aEbD80AEd81eA4B41", "5", "2", "0x4c0Fd51D88216250507Ec303ACbE76473a19AfE9"],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
Expand Down
54 changes: 27 additions & 27 deletions packages/hardhat/deployments/scrollSepolia/ATM.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions packages/hardhat/deployments/scrollSepolia/ZKATM_Token.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

28 changes: 0 additions & 28 deletions packages/hardhat/test/YourContract.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
.vercel

.vercel
31 changes: 26 additions & 5 deletions packages/nextjs/app/atm/deposit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const AtmDeposit: NextPage = () => {
}
});

const { writeContractAsync: sendAction } = useScaffoldWriteContract("ATM");
const { writeContractAsync: deposit } = useScaffoldWriteContract("ATM");
const { writeContractAsync: initialized, isSuccess, isPending } = useScaffoldWriteContract("ATM");

const handleGenerate = useCallback(_handleGenerate, [comitment_isRefetch])

Expand Down Expand Up @@ -89,7 +90,7 @@ const AtmDeposit: NextPage = () => {
}
</ul>

<form className="space-y-2" onSubmit={handleSubmit(handleDeposit)}>
<form id="deposit" className="space-y-2" onSubmit={handleSubmit(handleDeposit)}>
<label className="form-control w-full">
<div className="label">
<span className="label-text"> Compromiso </span>
Expand All @@ -108,16 +109,25 @@ const AtmDeposit: NextPage = () => {
<span className="badge badge-info">wei</span>
</div>
</label>
</form>

<div className="card-actions">
<button
className="md:ms-auto btn btn-outline text-base"
onClick={handleInitialized}
>
Iniciar Balance
{ isPending && <span className="loading loading-spinner"></span> }
</button>
<button
form="deposit"
type="submit"
className="md:ms-auto w-full md:w-auto btn btn-primary text-white text-base"
className="btn btn-primary text-white text-base"
>
Depositar
</button>

</div>
</form>
</>

async function _handleGenerate() {
Expand All @@ -127,7 +137,7 @@ const AtmDeposit: NextPage = () => {

async function handleDeposit(data: TDeposit) {
try {
await sendAction({
await deposit({
functionName: "deposit",
args: [data.commitment, BigInt(data.ammount)]
});
Expand All @@ -137,6 +147,17 @@ const AtmDeposit: NextPage = () => {
console.error(e)
}
}

async function handleInitialized() {
if(isSuccess || isPending) return;
try{
await initialized({
functionName: "initializeBalance",
})
} catch(e){
console.error(e)
}
}
}

export default AtmDeposit
4 changes: 2 additions & 2 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const deployedContracts = {
534351: {
ATM: {
address: "0x2b912c55769B50ca71834774f808143513769969",
address: "0x7c05E68f0A835459D82532756E7c932cc0aA607f",
abi: [
{
inputs: [
Expand Down Expand Up @@ -805,7 +805,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
ZKATM_Token: {
address: "0xDD8fA77500F94b2286AbE41c81B4a08EdD0429B9",
address: "0x4c0Fd51D88216250507Ec303ACbE76473a19AfE9",
abi: [
{
inputs: [
Expand Down

0 comments on commit 5ecfda9

Please sign in to comment.