Skip to content

Commit

Permalink
🧧 Mina Berkeley Learn2Earn yeni adrese deploy et
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed May 19, 2024
1 parent 85bfb10 commit 6f78acd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
10 changes: 6 additions & 4 deletions blog/mina-berkeley/contracts/Learn2Earn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import {
HumanIDv1Witness,
PerHumanIDv1Contract,
} from "@kimlikdao/sdk/mina/HumanIDv1";
import { method } from "o1js";
import { PublicKey, method } from "o1js";

const MINA = 1e9;

const LEARN2EARN = "B62qrzBYPHRZ6FsQpZCw5FbgvRbFh2jFHY2DT35pWjJc9K5Mbq2zppH";
const LEARN2EARN = "B62qnnFm3SEtrMgStoj4SRVxKSTERh8Ho3Y9jCCa8TvgBF1mqa97Sij";

class Learn2Earn extends PerHumanIDv1Contract {
class Learn2EarnContract extends PerHumanIDv1Contract {
@method async claimReward(humanIDv1: HumanIDv1, witness: HumanIDv1Witness) {
const sender = this.sender.getUnconstrained();
this.acceptHumanIDv1(sender, humanIDv1, witness);
this.send({ to: sender, amount: 10 * MINA });
}
}

export { LEARN2EARN, Learn2Earn };
const Learn2Earn = new Learn2EarnContract(PublicKey.fromBase58(LEARN2EARN));

export { LEARN2EARN, Learn2Earn, Learn2EarnContract };
33 changes: 22 additions & 11 deletions blog/mina-berkeley/contracts/Learn2EarnWorker.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { HumanIDv1, HumanIDv1Witness, readPublicKey } from "@kimlikdao/sdk/mina/HumanIDv1";
import { Field, MerkleTree, Mina, Poseidon, PrivateKey, PublicKey, Signature } from "o1js";
import { LEARN2EARN, Learn2Earn as Learn2EarnContract } from "./Learn2Earn";
import {
HumanIDv1,
HumanIDv1Witness,
readPublicKey,
} from "@kimlikdao/sdk/mina/HumanIDv1";
import {
Field,
MerkleTree,
Mina,
Poseidon,
PrivateKey,
PublicKey,
Signature,
} from "o1js";
import { Learn2Earn, Learn2EarnContract } from "./Learn2Earn";

console.log("Worker loaded and parsed");

console.time("compiling Learn2Earn")
console.time("compiling Learn2Earn");

const Learn2EarnCompiled = Learn2EarnContract.compile().then(() => {
console.timeEnd("compiling Learn2Earn");
postMessage("compiled");
});

const Network = Mina.Network('https://api.minascan.io/node/devnet/v1/graphql');
const Network = Mina.Network("https://api.minascan.io/node/devnet/v1/graphql");
console.log("Devnet network instance configured.");
Mina.setActiveInstance(Network);

const Learn2Earn = new Learn2EarnContract(PublicKey.fromBase58(LEARN2EARN));

const getWitness = (humanIDv1Id: bigint) =>
Promise.resolve(new HumanIDv1Witness(new MerkleTree(33).getWitness(humanIDv1Id & 0xFFFFFFFFn)));

Promise.resolve(new HumanIDv1Witness(new MerkleTree(33).getWitness(humanIDv1Id & 0xffffffffn)));

const blindingCommit = (sender: PublicKey) => {
const commitmentR = Field.random();
Expand All @@ -46,10 +55,12 @@ onmessage = async (event) => {
const humanIDv1 = signHumanIDv1(100n, sender); // HumanIDv1.fromBytes(event.data.subarray(33));

const witness = await getWitness(humanIDv1.id.toBigInt());
const tx = await Mina.transaction(sender, () => Learn2Earn.claimReward(humanIDv1, witness))
const tx = await Mina.transaction(sender, () =>
Learn2Earn.claimReward(humanIDv1, witness)
);
console.log("proving tx");
console.time("proving tx");
const proven = await tx.prove();
console.timeEnd("proving tx");
postMessage(proven.toJSON());
}
};
3 changes: 3 additions & 0 deletions blog/mina-berkeley/sayfa.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ <h1 id=blh1 data-en="Mina Berkeley Upgrade">Mina Berkeley güncellemesi</h1>
<li>Removal of Supercharged Rewards (MIP 1)</li>
</ul>
<h2>Installing the Auro wallet</h2>
<a id=mbau href="javascript:" class="act btn" data-en="Get Auro Wallet">Auro Wallet kur</a>
<h2 data-en="Minting your KPass">KPass'ini mintle</h2>
<a id=mbkp href="javascript:" class="act btn" data-en="Mint KPass">KPass al</a>

<h2 data-en="Claim your reward">Ödülünü al</h2>
<a id=mbcl href="javascript:" class="act btn" data-en="Claim ✨">Ödülünü al ✨</a>
</div>
Expand Down
3 changes: 2 additions & 1 deletion blog/mina-berkeley/sayfa.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ClaimButton.onclick = () => {

Learn2EarnWorker.postMessage(message);
Learn2EarnWorker.onmessage = (/** @type {!MessageEvent} */ msg) =>
window.mina.sendTransaction({ transaction: msg.data });
window.mina.sendTransaction({ transaction: msg.data })
.then(console.log);
};
2 changes: 1 addition & 1 deletion dapp
Submodule dapp updated 1 files
+1 −1 lib

0 comments on commit 6f78acd

Please sign in to comment.