Validate Zupass ticket on a smart contract, sending funds to a user. Based on the Devconnect Zupass: SE2 Starter Kit https://github.com/BuidlGuidl/devconnect-zupass-se2
๐งช Based on the Devconnect Zupass: SE2 Starter Kit https://github.com/BuidlGuidl/devconnect-zupass-se2
Validate Zupass ticket on a smart contract.
Created a ZupassVerifier contract https://github.com/damianmarti/fruit-market-land/blob/zupass-claim/packages/hardhat/contracts/ZupassVerifier.sol
And then the ZupassDispenser is ZupassVerifier https://github.com/damianmarti/fruit-market-land/blob/zupass-claim/packages/hardhat/contracts/ZupassDispenser.sol
ZupassDispenser getFunds method checks for valid ticket and event, and send funds to user:
function getFunds(
ProofArgs calldata proof
)
public
verifiedProof(proof)
validEventIds(proof._pubSignals)
validSigner(proof._pubSignals)
notSent(proof._pubSignals)
{
sent[proof._pubSignals[5]] = true;
(bool daiTransferred, ) = payable(msg.sender).call{value: DAI_FAUCET_AMOUNT}("");
require(daiTransferred, "Dai transfer failed");
bool creditTokenTransferred = creditToken.transfer(msg.sender, SALT_FAUCET_AMOUNT);
require(creditTokenTransferred, "Credit token transfer failed");
}
sent
flag use the attendeeSemaphoreId to avoid sending more than one time to each user.
modifier notSent(uint256[38] memory _pubSignals) {
require(!sent[_pubSignals[5]], "Already sent");
_;
}
Get Zupass proof https://github.com/damianmarti/fruit-market-land/blob/zupass-claim/packages/nextjs/components/screens/Main.tsx#L63
Call ZupassDispenser contract with proof https://github.com/damianmarti/fruit-market-land/blob/zupass-claim/packages/nextjs/components/screens/Main.tsx#L253
More information at Devconnect Zupass: SE2 Starter Kit
๐งช this is forked from the fruit market repo here
๐ต Buy Land and Grow Strawberries!
<img width="719" alt="image" src="https://github.com/austintgriffith/fruit-market-land/assets/2653167/8ec660c1-bd7c-4e10-97b6-3d0fff5a86f5">๐ฑ very ugly buttons for each land tile:
<img width="592" alt="image" src="https://github.com/austintgriffith/fruit-market-land/assets/2653167/c45dc837-2ecd-452a-b011-e7e584ef73b8">๐บ check out the land contract in packages/hardhat/contracts/Land.sol
git clone https://github.com/BuidlGuidl/fruit-market-land
cd /fruit-market-land
yarn install
โ๏ธ bring up the chain and deploy your contracts
yarn chain
yarn deploy
yarn start
๐จ copy packages/nextjs/.env.example
to the name .env
and edit your frontend env:
๐ฟ you'll need to spin up a KV (key value storage) in vercel and copy/paste in the env.local fields:
NEXT_PUBLIC_DEPLOY_BLOCK=0
NEXT_PUBLIC_LIVE_URL=https://event-wallet.vercel.app
KV_URL=
KV_REST_API_URL=
KV_REST_API_TOKEN=
KV_REST_API_READ_ONLY_TOKEN=
๐ฑ hit the frontend at http://localhost:3000
๐ next, inspect the targetNetwork
var in packages/nextjs/scaffold.config.ts
(if you are deploying locally it needs to be chains.hardhat
or chains.gnosis
out in prod)
๐โโ๏ธ login as with your nickname:
๐ท now you can use the browser to navigate to the /checkedIn
route to drop tokens and gas to players:
โ ๏ธ your frontend address will need to be an admin to drop tokens to players
๐ edit packages/hardhat/deploy/00_deploy_your_contract.ts
and add your address to dexPausers
โ๏ธ redeploy the whole stack with yarn deploy --reset
๐ค try visiting http://localhost:3000 from an incognito window or another browser to have a fresh burner to play with
(check in with a burner and drop some funds to it using your other account and the /checkedIn
page)
โ๏ธ at this point, player should be able to trade credits for resources on the dexes:
If you want to keep the charts and leaderboard updated you have to run a cron job requesting /api/admin/track-prices:
* * * * * /usr/bin/curl https://domain/api/admin/track-prices >> prices.log
Or you can set the cron job at Vercel using the /packages/nextjs/vercel.json config file.
(On localhost you can just use the browser to hit http://localhost:3000/api/admin/track-prices
manually)
If you want prices to randomly fluctuate you need to run bots that have a bunch of liquidity and trade randomly:
git clone https://github.com/BuidlGuidl/fruit-market-trader
cd fruit-market-trader
yarn install
๐พ you will need to copy your fruit-market
packages/nextjs/generated/deployedContracts.ts
into this fruit-market-trader/deployedContracts.js
โ ๏ธ notice it changes from .ts
to .js
- you will also have to remove the as const
from the end
(this tells your bots about the new contracts you've deployed)
โข๏ธ Notice: any time you need to redeploy, do yarn deploy --reset
and recopy over your deployedContracts.js
โ๏ธ copy the .env.example
to .env
file in the fruit-market-trader
dir with the following info filled in:
DEPLOYER_PRIVATE_KEY=0xYOUR_PRIVATE_KEY_FROM_YOUR_LOCAL_STORAGE
GNOSIS_RPC=http://127.0.0.1:8545
GNOSIS_NETWORK_ID=31337
(you can get this private key from the local storage. it's called scaffoldEth2.burnerWallet.sk
)
โฝ๏ธ if your this address is loaded up with local funds, you should be good to run:
node batchPrep.js
โ๏ธ this is going to generate a bunch of trader accounts, send them tokens, and save the private keys up in your .env
file:
(if anything fails here it probably means your burner is not correctly funded with credits and assets and you can debug balances using http://localhost:3000/debug)
๐ now you can start a trading bot for each resource like:
node tradeDex.js Apple