Skip to content

Commit

Permalink
UI deposit and withdrawal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
manudev97 committed Jul 18, 2024
1 parent 9b0a879 commit 09b01b3
Show file tree
Hide file tree
Showing 29 changed files with 1,191 additions and 240 deletions.
5 changes: 3 additions & 2 deletions packages/hardhat/contracts/ATM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract ATM is MerkleTree {
// ZKATM_TOKEN new address: 0xa78a484c097d27a4922fF07033c702c2Da85b6FC
// ATM address: 0x556E6C30C2a28ef3C9c9C464E8Cf0F561678F779
// ATM new address: 0xdB7a0b5fB1c909cdBcB19F3748cB957470E94B57 --> 0xd1020f336bebdd4649Daa32B6bAb0660492A7C5b
//0xE77d6D6982fF47D3fe83CeBd11BC6f7a2cc0Aef5
constructor(
IVerifier _verifier,
address _hasher,
Expand All @@ -58,7 +59,7 @@ contract ATM is MerkleTree {
require(!initialized[msg.sender], "El saldo ya ha sido inicializado");
// Transferir 50 tokens ZKATM al usuario que llama la función
uint256 tokenAmount = 50 * (10 ** zkatmToken.decimals()); // Ajuste según los decimales del token
zkatmToken.transfer(msg.sender, tokenAmount);
zkatmToken.mint(msg.sender, tokenAmount);
initialized[msg.sender] = true;
balance[msg.sender] = zkatmToken.balanceOf(msg.sender);
}
Expand Down Expand Up @@ -87,7 +88,7 @@ contract ATM is MerkleTree {
function deposit(bytes32 commitment, uint256 _amount) public {
require(!commitments[commitment], "El compromiso ya se ha insertado");
if(balance[msg.sender] < _amount) revert InsufficientBalance();
require(_amount == denomination, "La cantidad depositada no es admitida");
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
bool transferSuccess = zkatmToken.transferFrom(msg.sender, address(this), _amount);
Expand Down
13 changes: 11 additions & 2 deletions packages/hardhat/contracts/ZKATM_Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import "@openzeppelin/contracts/access/Ownable.sol";

contract ZKATM_Token is ERC20, ERC20Pausable, Ownable {
string public greeting = "Deploy token ZKATM";

address public atmAddress;

constructor(address initialOwner)
ERC20("ZKATM_Token", "ZKATM")
Ownable(initialOwner)
{
_mint(msg.sender, 1000000 * 10 ** decimals());
}

function updateATMAddress(address _atm) external onlyOwner {
atmAddress = _atm;
}

function pause() public onlyOwner {
_pause();
Expand All @@ -24,7 +29,7 @@ contract ZKATM_Token is ERC20, ERC20Pausable, Ownable {
_unpause();
}

function mint(address to, uint256 amount) public onlyOwner {
function mint(address to, uint256 amount) public onlyATM {
_mint(to, amount);
}

Expand All @@ -37,4 +42,8 @@ contract ZKATM_Token is ERC20, ERC20Pausable, Ownable {
super._update(from, to, value);
}

modifier onlyATM(){
require(msg.sender == atmAddress, "only_atm");
_;
}
}
4 changes: 2 additions & 2 deletions 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", "2", "0xd1020f336bebdd4649Daa32B6bAb0660492A7C5b"],
args: ["0x0918fe077e800b24E1D64c2FE9bb6a12E0255CA9", "0xCc735e52E393f125cAFc4E0aEbD80AEd81eA4B41", "5", "2", "0xDD8fA77500F94b2286AbE41c81B4a08EdD0429B9"],
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 All @@ -34,7 +34,7 @@ const deployATM: DeployFunction = async function (hre: HardhatRuntimeEnvironment

// Get the deployed contract to interact with it after deploying.
const ATM = await hre.ethers.getContract<Contract>("ATM", deployer);
console.log("👋 Saludo Inicial:", await ATM.greeting());
console.log("👋 Saludo Inicial:", await ATM.getAddress());
};

export default deployATM;
Expand Down
50 changes: 25 additions & 25 deletions packages/hardhat/deployments/scrollSepolia/ATM.json

Large diffs are not rendered by default.

84 changes: 59 additions & 25 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.

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/hardhat/prover/proof1.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"pi_a": [
"15610497059691956035252491506848626911735552927523219101705418352897110394961",
"6935556491942605023345017061848679200612220759855072886068160065267325098792",
"20327919964488986012669931654446671072486312956860033859444372886831101270908",
"18302908021303179413354404373271001712401906131544561113713720688880715493548",
"1"
],
"pi_b": [
[
"4191136645756518990235268327929900762076605183087794444539638719327958737292",
"1668063499757034116969778207573842296987746247396844748178383032773169571286"
"8365303223926408499925918477419296795226869547312132235566731528492413456153",
"11458909321803561269528743695423273395163773942596697323223612592608440103941"
],
[
"689624125900386562345764048500814766628683029719634633615302763708508236269",
"5785150316575724395019058012764903226018464197346840175394865546424804783812"
"13480203184404289154344962162278415106784694674532646309725844831061790220923",
"10535443019264722083664260825241936392260441010644557364064220117072880477727"
],
[
"1",
"0"
]
],
"pi_c": [
"15278007640223608456607296240935591538184745715844485970898642343214241323461",
"21512958455359336217957052130510178353331330877954337233673987472684720627822",
"14452871733290734803268693308808125168795627896143672065815755943781864774321",
"1709610203807641566355523469597379874323862211359201944945391252312518881352",
"1"
],
"protocol": "groth16",
Expand Down
28 changes: 28 additions & 0 deletions packages/hardhat/prover/proof2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pi_a": [
"11409560475887737190072199937387400790801273289449809779147483202283169567496",
"5524669478717190826094921161694051987450336327732418378068841237710381923005",
"1"
],
"pi_b": [
[
"2768536174298919791725085041676967157786344139666682597221151291546192168157",
"15143870382023490402951796294091536633597652142332467481564012768184220483198"
],
[
"12167641276665461542625483810143504619626917391915166940406960995020061282148",
"274188343504325266340932118896916781516639900407313505638025956079574458812"
],
[
"1",
"0"
]
],
"pi_c": [
"3960689247112632550971506125950199106959757664238152944294626930884099082309",
"16800796171178889947676465857939870018154686303899130046598645278010311120148",
"1"
],
"protocol": "groth16",
"curve": "bn128"
}
28 changes: 28 additions & 0 deletions packages/hardhat/prover/proof3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pi_a": [
"11236300597472183602684044863841182206500142280378857326142301530279936973582",
"19884032081945218490317561519809739108613367286377716404649699109783103371260",
"1"
],
"pi_b": [
[
"2427797158638647806049142829463635232289171520181193862554807482527098588293",
"3852484339551903593863030259138021035705353373867966750433390420643526676536"
],
[
"9398098001578843073209849634465597057657141380909914641488804327275242570525",
"6609232595262082133509373614241239359065428421038756671161583102318108527476"
],
[
"1",
"0"
]
],
"pi_c": [
"4842721183971875135820206785924653513098712517061847772702615377890620287013",
"9185778959184794839034443865850354871680778674962315776549274602060940984445",
"1"
],
"protocol": "groth16",
"curve": "bn128"
}
4 changes: 4 additions & 0 deletions packages/hardhat/prover/public2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"7998156038024386212248324169752773107020882108161389030375061360593131128298",
"9719310942818382580626812540950309168735855044625659354930391833116447577615"
]
4 changes: 4 additions & 0 deletions packages/hardhat/prover/public3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"7998156038024386212248324169752773107020882108161389030375061360593131128298",
"9719310942818382580626812540950309168735855044625659354930391833116447577615"
]
149 changes: 0 additions & 149 deletions packages/nextjs/app/ATM.tsx

This file was deleted.

Loading

0 comments on commit 09b01b3

Please sign in to comment.