Skip to content

Commit

Permalink
cairo template fix + readme + init db fun
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Aug 21, 2024
1 parent bec95c3 commit cb70c70
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 95 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,47 @@ Tech stack:
- React Native for the mobile app - [Learn React Native now](https://reactnative.dev/docs/tutorial)
- Typescript for the Nostr relayer - [Learn Typescript now](https://www.typescriptlang.org/docs/handbook/2/basic-types.html)


## Monorepo

We use Turborepo for the monorepo.

- Onchain (Cairo & Solidity): /onchain
- Scripts: Run & deploy Cairo code

Apps:

- Mobile: apps/mobile
- Website landing page: apps/website
- Backend: apps/data-backend
- Indexer Apibara: apps/indexer

Packages:

- Common: packages/common
- Prisma indexer pull: packages/indexer-prisma
- Nostr sdk: packages/afk_nostr_sdk

## Roadmap

### MVP

- [x] Cairo implementation of Nostr signature verification
- [x] Starknet account contract implementation, controlled by Nostr keypair
- [ ] AFK landing page
- [X] AFK landing page
- [x] SocialPay feature to send and receive tips through Nostr signed messages
- [x] Implement a full Nostr client application with Starknet integration
- [x] Implement a Nostr client application with Starknet integration
- [x] Run Nostr relay server

### Now

- [ ] Complete Nostr client
- [ ] ZAP
- [ ] Launchpad & Pump it
- [ ] Questings
- [ ] Social games
- [ ] BTCFi and Bridge
- [ ] Onramp offramp
- [ ] Crossover with [Vault](https://github.com/keep-starknet-strange/vault) to bring Social features to the Vault application

## Architecture
Expand Down
2 changes: 2 additions & 0 deletions apps/data-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ INDEXER_DATABASE_URL="postgresql://postgres"
TELEGRAM_BOT_TOKEN=TG_BOT_FATHER
TG_ADMIN_CHAT_ID=
WEBHOOK_DOMAIN=https://data-backend.xyz

BACKEND_DATABASE_URL=
7 changes: 6 additions & 1 deletion apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"start:dev": "ts-node-dev src/index.ts",
"start:prod": "ts-node dist/index.js",
"start:node": "node dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prisma:generate":"npx prisma generate",
"prisma:push":"npx prisma db push",
"prisma:setup":"npx prisma generate && npx prisma db push"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^5.18.0",
"@telegraf/types": "^7.1.0",
"apollo-server": "^3.13.0",
"cors": "^2.8.5",
Expand All @@ -33,6 +37,7 @@
"devDependencies": {
"@types/express": "^4.17.21",
"@types/node": "^20.16.1",
"prisma": "^5.18.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsup": "^8.0.2",
Expand Down
67 changes: 67 additions & 0 deletions apps/data-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("BACKEND_DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
email String @unique
starknetAddress String? @unique
kakarotAddress String?
nostrAddress String?
role Role @default(USER)
posts Post[]
profile Profile?
Faction Faction[]
}

model Profile {
id Int @id @default(autoincrement())
bio String
user User @relation(fields: [userId], references: [id])
userId Int @unique
}

model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
eventId String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
categories Category[]
}

model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}

enum Role {
USER
ADMIN
}

model Canvas {
id Int @id @default(autoincrement())
name String
}

model Quest {
id Int @id @default(autoincrement())
name String
}

model Faction {
id Int @id @default(autoincrement())
name String
members User[]
}
2 changes: 0 additions & 2 deletions apps/data-backend/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import express from 'express'
import deploy from './routes/indexer/deploy-token'
import deployLaunch from './routes/indexer/deploy-launch'
import buyCoin from './routes/indexer/buy-coin'
import telegramApp from './routes/telegram-app'

const Router = express.Router()
Router.use('/deploy', deploy)
Router.use('/deploy-launch', deployLaunch)
Router.use("/buy-coin", buyCoin)
Router.use("/telegram-app", telegramApp)

export default Router
82 changes: 0 additions & 82 deletions apps/data-backend/src/routes/telegram-app.ts

This file was deleted.

1 change: 0 additions & 1 deletion onchain/cairo/src/id/afk_id.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub trait IAfkId<T> {

#[starknet::contract]
mod AfkIdentity {
const DAILY_TIMESTAMP_SECONDS:u256=60*60*24;
use starknet::{
ContractAddress, get_caller_address, storage_access::StorageBaseAddress,
contract_address_const, get_block_timestamp, get_contract_address, ClassHash
Expand Down
5 changes: 4 additions & 1 deletion onchain/cairo/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub mod types {
pub mod jediswap_types;
pub mod keys_types;
pub mod launchpad_types;
pub mod tap_types;
}
pub mod quests {
pub mod tap;
}

pub mod examples {
Expand All @@ -21,7 +25,6 @@ pub mod tokens {
pub mod erc20;
}


#[cfg(test)]
pub mod tests {
pub mod keys_tests;
Expand Down
1 change: 1 addition & 0 deletions onchain/cairo/src/quests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod quests;
3 changes: 3 additions & 0 deletions onchain/cairo/src/quests/mod.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod quests {
pub mod tap;
}
13 changes: 8 additions & 5 deletions onchain/cairo/src/quests/tap.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use starknet::{
ContractAddress, ClassHash
};
use afk::types::tap_types::{
TapUserStats,
TapDailyEvent
};

#[starknet::interface]
pub trait ITapsQuests<T> {
fn get_tap_user_stats(self: @T) -> TapUserStats;
fn get_tap_user_stats(self: @T , user:ContractAddress) -> TapUserStats;
fn handle_tap_daily(ref self: T);
}

#[starknet::contract]
mod TapQuests {

const DAILY_TIMESTAMP_SECONDS:u256=60*60*24;
const DAILY_TIMESTAMP_SECONDS:u64=60*60*24;
use super::{
TapUserStats,
TapDailyEvent
Expand Down Expand Up @@ -54,12 +57,12 @@ mod TapQuests {
self.tap_by_users.write(caller, tap);
self
.emit(
TapDailyEvent { owner: caller, last_tap:timestamp, total_tap:total }
TapDailyEvent { owner: caller, last_tap:timestamp, total_tap:1 }
);
} else {
let tap = tap_old.clone();
let mut tap = tap_old.clone();
let last_tap = tap.last_tap;
assert!(timestamp-last_tap < DAILY_TIMESTAMP_SECONDS, "too early")
assert!(timestamp-last_tap < DAILY_TIMESTAMP_SECONDS, "too early");
tap.last_tap= timestamp;

let total=tap_old.total_tap+1;
Expand Down
1 change: 1 addition & 0 deletions onchain/cairo/src/types/mod.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod types {
pub mod jediswap_types;
pub mod keys_types;
pub mod launchpad_types;
pub mod tap_types;
}
2 changes: 1 addition & 1 deletion scripts/.env.exemple
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ IS_DEPLOY_CONTRACT=true
REDECLARE_ACCOUNT=false # Set to true on devnet
REDECLARE_CONTRACT=true
TOKEN_CLASS_HASH=0x58daf8998746438d557781b7a9ec1fbda1252c47196f158dcce2df55682644a

TAP_CLASS_HASH=

# To run Nostr relayer, not needed
POSTGRES_DB=mydatabase
Expand Down
40 changes: 40 additions & 0 deletions scripts/deploy/tap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
provider,
} from "../utils/starknet";
import { Account,} from "starknet";
import dotenv from "dotenv";
import { prepareAndConnectContract } from "../utils/contract";
import { createTapQuests } from "../utils/tap";

dotenv.config();

export const deployTapQuest= async () => {
console.log("deployTapQuest")

let tapContract:any|undefined;
let tap;
let tap_address: string | undefined;
const privateKey0 = process.env.DEV_PK as string;
const accountAddress0 = process.env.DEV_PUBLIC_KEY as string;
const account = new Account(provider, accountAddress0, privateKey0, "1");
const chainId = await provider.getChainId()
if (process.env.IS_DEPLOY_CONTRACT == "true") {
let tapContract = await createTapQuests();
console.log("tap address", tapContract?.contract_address)
if (tapContract?.contract_address) {
tap_address = tapContract?.contract_address
tap = await prepareAndConnectContract(tap_address ?? tapContract?.contract_address, account)
}

} else {

}

/** TODO script to save constants address */

return {
tapContract, tap_address, tap
}
}

deployTapQuest()
Loading

0 comments on commit cb70c70

Please sign in to comment.