Skip to content

Commit

Permalink
Feat/mvp beta soon please (#383)
Browse files Browse the repository at this point in the history
* start launch token bonding curve selection and test + changes

* clean and fix script

* try deploy launch

* deploy new launch contract

* fixing few things

* start add enum for launch token bonding type

* issue docker still here, not generated prisma

* start change hooks launchpad and ui
  • Loading branch information
MSghais authored Dec 18, 2024
1 parent 5c53ec6 commit 4427c56
Show file tree
Hide file tree
Showing 26 changed files with 1,295 additions and 394 deletions.
5 changes: 2 additions & 3 deletions Dockerfile.data-backend.railway
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ RUN pnpm run build:indexer-prisma
RUN pnpm --filter indexer-prisma build

# Build the data-backend package
# Build indexer-prisma and owned prisma
# RUN pnpm --filter data-backend build:all_repo
# RUN pnpm --filter data-backend build:all
RUN pnpm --filter data-backend build:prisma
RUN pnpm --filter data-backend build
# RUN pnpm --filter data-backend build:prisma
# RUN pnpm --filter data-backend build

# Use a smaller production base image
FROM node:20-alpine AS production
Expand Down
1 change: 1 addition & 0 deletions apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prisma:generate": "npx prisma generate",
"prisma:push": "npx prisma db push",
"prisma:setup": "npx prisma generate && npx prisma db pull",
"prisma:setup_push": "npx prisma generate && npx prisma db push",
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
"ts:check": "tsc --noEmit"
Expand Down
12 changes: 8 additions & 4 deletions apps/indexer/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ create table token_launch(
threshold_liquidity TEXT,
price TEXT,
_cursor BIGINT,
time_stamp TEXT
time_stamp TEXT,
total_token_holded TEXT,
);

create table token_deploy(
Expand Down Expand Up @@ -133,7 +134,6 @@ create table username_changed(
block_number BIGINT,
block_timestamp TIMESTAMP,
transaction_hash TEXT PRIMARY KEY,

name TEXT,
old_name TEXT,
paid TEXT,
Expand All @@ -150,7 +150,6 @@ create table renew_subscription(
block_number BIGINT,
block_timestamp TIMESTAMP,
transaction_hash TEXT PRIMARY KEY,

name TEXT,
old_name TEXT,
paid TEXT,
Expand All @@ -165,5 +164,10 @@ create table shares_token_user(
id TEXT,
owner TEXT,
token_address TEXT,
amount_owned TEXT
total_token_holded TEXT,
amount_owned TEXT,
time_stamp DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
_cursor BIGINT

);
2 changes: 1 addition & 1 deletion apps/mobile/src/context/TokenCreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TokenCreateModalProvider: React.FC<React.PropsWithChildren> = ({chi
if (!account?.address) {
setStarknetAddress(undefined);
}
}, [account]);
}, [account, account?.address]);
const show = useCallback(
(event?: NDKEvent, starknetAddress?: string, action?: KeyModalAction) => {
setEvent(event);
Expand Down
33 changes: 30 additions & 3 deletions apps/mobile/src/hooks/launchpad/useCreateToken.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {LAUNCHPAD_ADDRESS} from 'common';
import {AccountInterface, cairo, CallData, constants} from 'starknet';
import { LAUNCHPAD_ADDRESS } from 'common';
import { AccountInterface, cairo, CairoCustomEnum, CallData, constants } from 'starknet';

// import { LAUNCHPAD_ADDRESS, UNRUGGABLE_FACTORY_ADDRESS } from "../../constants/contracts";
import {formatFloatToUint256} from '../../utils/format';
import { formatFloatToUint256 } from '../../utils/format';
import { BondingType } from '../../types/keys';

export type DeployTokenFormValues = {
recipient?: string;
Expand All @@ -11,6 +12,7 @@ export type DeployTokenFormValues = {
initialSupply: number | undefined;
contract_address_salt: string | undefined;
is_unruggable?: boolean;
bonding_type?: BondingType
};

export const useCreateToken = () => {
Expand All @@ -27,6 +29,9 @@ export const useCreateToken = () => {
const initial_supply = formatFloatToUint256(data?.initialSupply ?? 100_000_000);

console.log('initial supply', initial_supply);



const deployCall = {
contractAddress: LAUNCHPAD_ADDRESS[constants.StarknetChainId.SN_SEPOLIA],
entrypoint: 'create_token',
Expand All @@ -38,6 +43,7 @@ export const useCreateToken = () => {
// initialSupply: cairo.uint256(data?.initialSupply ?? 100_000_000),
contract_address_salt: new Date().getTime(),
is_unruggable: cairo.felt(String(data?.is_unruggable)),
// bonding_type:bondingEnum
// contract_address_salt:CONTRACT_ADDRESS_SALT_DEFAULT + Math.random() + Math.random() / 1000
// contract_address_salt:cairo.felt(Math.random())
}),
Expand All @@ -64,6 +70,26 @@ export const useCreateToken = () => {
// : '0x36d8be2991d685af817ef9d127ffb00fbb98a88d910195b04ec4559289a99f6';

const initial_supply = formatFloatToUint256(data?.initialSupply ?? 100_000_000);
let bondingEnum = new CairoCustomEnum({ Linear: {} });
console.log('bondingEnum', bondingEnum);
let bonding = data?.bonding_type

console.log('bonding', bonding);


if (data.bonding_type) {
console.log('bondingEnum', bondingEnum);
bondingEnum = new CairoCustomEnum({ bonding });

/** TODO finish corret formatin like above depends on the selected value */
// if (data?.bonding_type == BondingType.Linear) {
// bondingEnum = new CairoCustomEnum({ Linear: {} });
// }
// else {
// bondingEnum = new CairoCustomEnum({ Exponential: {} });
// }

}

console.log('initial supply', initial_supply);
const deployCall = {
Expand All @@ -76,6 +102,7 @@ export const useCreateToken = () => {
contract_address_salt: new Date().getTime(),
// is_unruggable: data?.is_unruggable
is_unruggable: cairo.felt(String(data?.is_unruggable)),
bonding_type: bondingEnum
}),
};

Expand Down
26 changes: 19 additions & 7 deletions apps/mobile/src/hooks/launchpad/useLaunchToken.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {useNetwork} from '@starknet-react/core';
import { useNetwork } from '@starknet-react/core';
// import { LAUNCHPAD_ADDRESS} from '../../constants/contracts';
import {LAUNCHPAD_ADDRESS} from 'common';
import {AccountInterface, CallData, constants, RpcProvider} from 'starknet';
import { LAUNCHPAD_ADDRESS } from 'common';
import { AccountInterface, CallData, constants, RpcProvider, CairoCustomEnum } from 'starknet';
// import { CairoOption, CairoOptionVariant } from 'starknet';
import {STRK} from '../../constants/tokens';
import {formatFloatToUint256} from '../../utils/format';
import { STRK } from '../../constants/tokens';
import { formatFloatToUint256 } from '../../utils/format';
import { BondingType } from '../../types/keys';

export const useLaunchToken = () => {
const chain = useNetwork();
const chainId = chain?.chain?.id;
const provider = new RpcProvider({nodeUrl: process.env.EXPO_PUBLIC_PROVIDER_URL});
const provider = new RpcProvider({ nodeUrl: process.env.EXPO_PUBLIC_PROVIDER_URL });
const handleLaunchCoin = async (
account?: AccountInterface,
coin_address?: string,
contractAddress?: string,
bonding_type?:BondingType
) => {
try {
if (!account) return;
Expand All @@ -28,11 +30,21 @@ export const useLaunchToken = () => {
console.log('read asset');
if (!account) return;

// const orderToSend: BondingType = { Linear: {} };
// const myCustomEnum = new CairoCustomEnum({ Linear: {} });
let bondingEnum = new CairoCustomEnum({Linear:{} });
if(bonding_type){
bondingEnum = new CairoCustomEnum({bonding_type});
}
// const orderToSend: BondingType = { Linear };
// const myCustomEnum = new CairoCustomEnum({ Response: orderToSend });
// const myCustomEnum = new CairoCustomEnum({ Response: orderToSend });
const launchDeployCall = {
contractAddress: addressContract,
entrypoint: 'launch_token',
calldata: CallData.compile({
coin_address: coin_address,
bonding_type: bondingEnum
// ekubo_pool:CairoOptionVariant.None
}),
};
Expand All @@ -47,5 +59,5 @@ export const useLaunchToken = () => {
}
};

return {handleLaunchCoin};
return { handleLaunchCoin };
};
93 changes: 65 additions & 28 deletions apps/mobile/src/modules/LaunchTokenPump/FormLaunchToken.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {NDKEvent} from '@nostr-dev-kit/ndk';
import {useAccount} from '@starknet-react/core';
import {useQueryClient} from '@tanstack/react-query';
import {useProfile} from 'afk_nostr_sdk';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useAccount } from '@starknet-react/core';
import { useQueryClient } from '@tanstack/react-query';
import { useProfile } from 'afk_nostr_sdk';
// import { useAuth } from '../../store/auth';
import {useAuth} from 'afk_nostr_sdk';
import {Formik, FormikProps} from 'formik';
import {useRef, useState} from 'react';
import {ScrollView, View} from 'react-native';

import {Button, SquareInput, Text} from '../../components';
import {useStyles, useWaitConnection} from '../../hooks';
import {DeployTokenFormValues, useCreateToken} from '../../hooks/launchpad/useCreateToken';
import {useToast, useWalletModal} from '../../hooks/modals';
import { useAuth } from 'afk_nostr_sdk';
import { Formik, FormikProps } from 'formik';
import { useRef, useState } from 'react';
import { ScrollView, View } from 'react-native';

import { Button, SquareInput, Text } from '../../components';
import { useStyles, useWaitConnection } from '../../hooks';
import { DeployTokenFormValues, useCreateToken } from '../../hooks/launchpad/useCreateToken';
import { useToast, useWalletModal } from '../../hooks/modals';
import stylesheet from '../../screens/CreateChannel/styles';
import {TipSuccessModalProps} from '../TipSuccessModal';
import { TipSuccessModalProps } from '../TipSuccessModal';
import { Picker } from '@react-native-picker/picker';
import { BondingType } from '../../types/keys';

const UsernameInputLeft = (
<Text weight="bold" color="inputPlaceholder">
Expand All @@ -40,12 +42,12 @@ export const FormLaunchToken: React.FC<FormTokenCreatedProps> = () => {
const walletModal = useWalletModal();
const styles = useStyles(stylesheet);
const publicKey = useAuth((state) => state.publicKey);
const profile = useProfile({publicKey});
const profile = useProfile({ publicKey });
const queryClient = useQueryClient();
const {showToast} = useToast();
const { showToast } = useToast();
const account = useAccount();
const waitConnection = useWaitConnection();
const {deployToken, deployTokenAndLaunch} = useCreateToken();
const { deployToken, deployTokenAndLaunch } = useCreateToken();

const [type, setType] = useState(TypeCreate.CREATE);
const initialFormValues: FormValues = {
Expand Down Expand Up @@ -78,29 +80,40 @@ export const FormLaunchToken: React.FC<FormTokenCreatedProps> = () => {
if (!result) return;
}

const data: DeployTokenFormValues = {
recipient: account?.address,
name: values.name,
symbol: values.symbol,
initialSupply: values?.initialSupply,
contract_address_salt: values.contract_address_salt,
is_unruggable: values.is_unruggable,
};
if (!account || !account?.account) return;
console.log('test deploy');

let tx;
if (type == TypeCreate.CREATE) {

const data: DeployTokenFormValues = {
recipient: account?.address,
name: values.name,
symbol: values.symbol,
initialSupply: values?.initialSupply,
contract_address_salt: values.contract_address_salt,
is_unruggable: values.is_unruggable,
};
tx = await deployToken(account?.account, data);
} else {

const data: DeployTokenFormValues = {
recipient: account?.address,
name: values.name,
symbol: values.symbol,
initialSupply: values?.initialSupply,
contract_address_salt: values.contract_address_salt,
is_unruggable: values.is_unruggable,
bonding_type: values.bonding_type
};
tx = await deployTokenAndLaunch(account?.account, data);
}

if (tx) {
showToast({type: 'success', title: 'Token launch created successfully'});
showToast({ type: 'success', title: 'Token launch created successfully' });
}
} catch (error) {
showToast({type: 'error', title: 'Failed to create token and launch'});
showToast({ type: 'error', title: 'Failed to create token and launch' });
}
};

Expand All @@ -116,7 +129,7 @@ export const FormLaunchToken: React.FC<FormTokenCreatedProps> = () => {
onSubmit={onFormSubmit}
validate={validateForm}
>
{({handleChange, handleBlur, values, errors}) => (
{({ handleChange, handleBlur, values, errors }) => (
<View style={styles.form}>
<SquareInput
placeholder="Token name"
Expand All @@ -143,6 +156,30 @@ export const FormLaunchToken: React.FC<FormTokenCreatedProps> = () => {
error={errors.initialSupply?.toString()}
/>


<View>
<Text>Only Linear is available atm.</Text>

<Picker
// label="Please select a token"
selectedValue={values.bonding_type?.toString()}
// selectedValue={values.bonding_type?.toString()}
onValueChange={(itemValue) => {
handleChange('bonding_type')
// values.bonding_type= BondingType {itemValue}
}}
>
{Object.values(BondingType).map((bonding) => (
<Picker.Item
key={bonding?.toString()}
label={bonding?.toString()}
value={bonding?.toString()}
/>
))}
</Picker>
</View>


<Button onPress={() => onSubmitPress(TypeCreate.CREATE)}>Create coin</Button>

<Button onPress={() => onSubmitPress(TypeCreate.CREATE_AND_LAUNCH)}>
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/modules/LaunchTokenPump/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default ThemedStyleSheet((theme) => ({
},

form: {
backgroundColor: theme.colors.background,
gap: Spacing.xsmall,
paddingVertical: Spacing.medium,
paddingHorizontal: Spacing.pagePadding,
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/modules/TokenCreatedModal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Spacing, ThemedStyleSheet} from '../../styles';
export default ThemedStyleSheet((theme) => ({
modal: {
paddingBottom: Spacing.xxlarge,
background:theme.colors.background
},

header: {
Expand Down
8 changes: 4 additions & 4 deletions apps/mobile/src/types/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export interface SharesKeys {
}

export enum BondingType {
Linear,
Scoring, // Nostr data with Appchain connected to a Relayer
Exponential,
Limited,
Linear=0,
Exponential=1,
// Scoring, // Nostr data with Appchain connected to a Relayer
// Limited,
}
4 changes: 3 additions & 1 deletion apps/nestjs-indexer/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export default {
'0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc',
},
sepolia: {
// LAUNCHPAD_ADDRESS:
// '0x1e00d0d7167938c2aa289850c96d7129ff16c1ed02b7542030bc2e39dc41885',
LAUNCHPAD_ADDRESS:
'0x1e00d0d7167938c2aa289850c96d7129ff16c1ed02b7542030bc2e39dc41885',
'0x3cb02be4090f94929a7d964266fdb1c74cefdd9066f7be08fb8a6bc33c619cd',
NAMESERVICE_ADDRESS:
'0x15dcd3c28c07846fa98d3a40d29446de21b5e6cd8d49a43773da0f237d5ea7f',
},
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs-indexer/src/indexer/name-service.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class NameServiceIndexer {
)
: '';

const expiry = new Date(Number(FieldElement.toBigInt(expiryFelt)) * 1000);
const expiry = new Date(Number(FieldElement.toBigInt(expiryFelt)) * 1000)?.toString();

const paidRaw = uint256.uint256ToBN({
low: FieldElement.toBigInt(paidLow),
Expand Down
Loading

0 comments on commit 4427c56

Please sign in to comment.