Skip to content

Commit

Permalink
stonks
Browse files Browse the repository at this point in the history
  • Loading branch information
ingawei committed Dec 12, 2024
1 parent c1cc69f commit a5782eb
Show file tree
Hide file tree
Showing 377 changed files with 517,408 additions and 49 deletions.
19 changes: 19 additions & 0 deletions backend/api/src/create-stonk-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createSupabaseDirectClient } from 'shared/supabase/init'
import { APIHandler } from './helpers/endpoint'

export const createStonkImage: APIHandler<'create-stonk-image'> = async (
props,
_auth
) => {
const { contractId, imageUrl } = props

const pg = createSupabaseDirectClient()

const image = await pg.oneOrNone(

Check warning on line 12 in backend/api/src/create-stonk-image.ts

View workflow job for this annotation

GitHub Actions / test

'image' is assigned a value but never used. Allowed unused vars must match /^_/u
`insert into stonk_images (contract_id, image_url)
values ($1, $2) returning *`,
[contractId, imageUrl]
)

return { success: true }
}
25 changes: 25 additions & 0 deletions backend/api/src/get-stonk-images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StonkImage } from 'common/stonk-images'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import { APIHandler } from './helpers/endpoint'

export const getStonkImages: APIHandler<'get-stonk-images'> = async ({
contracts,
}) => {
const pg = createSupabaseDirectClient()

const images = await pg.manyOrNone<{
contract_id: string
image_url: string
}>(
`select * from stonk_images where contract_id in (${contracts
.map((id) => `'${id}'`)
.join(',')})`
)

return {
images: images.map((i) => ({
contractId: i.contract_id,
imageUrl: i.image_url,
})),
}
}
4 changes: 4 additions & 0 deletions backend/api/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ import { generateAIAnswers } from './generate-ai-answers'
import { getmonthlybets2024 } from './get-monthly-bets-2024'
import { getmaxminprofit2024 } from './get-max-min-profit-2024'
import { getNextLoanAmount } from './get-next-loan-amount'
import { createStonkImage } from './create-stonk-image'
import { getStonkImages } from './get-stonk-images'

// we define the handlers in this object in order to typecheck that every API has a handler
export const handlers: { [k in APIPath]: APIHandler<k> } = {
Expand Down Expand Up @@ -297,4 +299,6 @@ export const handlers: { [k in APIPath]: APIHandler<k> } = {
'get-monthly-bets-2024': getmonthlybets2024,
'get-max-min-profit-2024': getmaxminprofit2024,
'get-next-loan-amount': getNextLoanAmount,
'create-stonk-image': createStonkImage,
'get-stonk-images': getStonkImages,
}
1 change: 0 additions & 1 deletion backend/api/src/search-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ const search = async (
groupIds,
marketTier: marketTier as TierParamsType,
})

return pg
.map(searchSQL, null, (r) => ({
data: convertContract(r),
Expand Down
10 changes: 7 additions & 3 deletions backend/shared/src/supabase/search-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export function getSearchContractSQL(args: {
),
],

orderBy(getSearchContractSortSQL(sort)),
orderBy(getSearchContractSortSQL(sort, args.contractType)),
sqlLimit(limit, offset)
)
}
Expand Down Expand Up @@ -457,7 +457,8 @@ export const sortFields: SortFields = {
order: 'DESC',
},
'prob-descending': {
sql: "resolution DESC, (data->>'p')::numeric",
// sql: "resolution DESC, (data->>'p')::numeric",
sql: "resolution DESC, (data->>'prob')::numeric",
sortCallback: (c: Contract) => ('p' in c && c.p) || 0,
order: 'DESC NULLS LAST',
},
Expand All @@ -467,7 +468,10 @@ export const sortFields: SortFields = {
order: 'ASC',
},
}
function getSearchContractSortSQL(sort: string) {
function getSearchContractSortSQL(sort: string, contractType?: string) {
if (sort === 'prob-descending' && contractType === 'STONK') {
return `resolution DESC, (data->>'prob')::numeric DESC NULLS LAST`
}
return `${sortFields[sort].sql} ${sortFields[sort].order}`
}

Expand Down
97 changes: 58 additions & 39 deletions common/src/api/schema.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
import { z } from 'zod'
import { MAX_ANSWER_LENGTH, type Answer } from 'common/answer'
import { coerceBoolean, contentSchema } from 'common/api/zod-types'
import { AnyBalanceChangeType } from 'common/balance-change'
import type { Bet, LimitBet } from 'common/bet'
import { adContract } from 'common/boost'
import { ChatMessage, PrivateChatMessage } from 'common/chat-message'
import { MAX_COMMENT_LENGTH, type ContractComment } from 'common/comment'
import { AIGeneratedMarket, Contract, MarketContract } from 'common/contract'
import { Dashboard } from 'common/dashboard'
import { SWEEPS_MIN_BET } from 'common/economy'
import {
Group,
LiteGroup,
MAX_ID_LENGTH,
MySearchGroupShape,
LiteGroup,
SearchGroupParams,
SearchGroupShape,
Topic,
} from 'common/group'
import {
createMarketProps,
resolveMarketProps,
type LiteMarket,
FullMarket,
updateMarketProps,
} from './market-types'
import { type Answer } from 'common/answer'
import { MAX_COMMENT_LENGTH, type ContractComment } from 'common/comment'
import { CandidateBet } from 'common/new-bet'
import type { Bet, LimitBet } from 'common/bet'
import { coerceBoolean, contentSchema } from 'common/api/zod-types'
import { Lover } from 'common/love/lover'
import { AIGeneratedMarket, Contract, MarketContract } from 'common/contract'
import { CompatibilityScore } from 'common/love/compatibility-score'
import type { Txn, ManaPayTxn } from 'common/txn'
import { LiquidityProvision } from 'common/liquidity-provision'
import { DisplayUser, FullUser } from './user-types'
import { League } from 'common/leagues'
import { searchProps } from './market-search-types'
import { MAX_ANSWER_LENGTH } from 'common/answer'
import { type LinkPreview } from 'common/link-preview'
import { LiquidityProvision } from 'common/liquidity-provision'
import { CompatibilityScore } from 'common/love/compatibility-score'
import { Lover } from 'common/love/lover'
import { CandidateBet } from 'common/new-bet'
import { Headline } from 'common/news'
import { Row } from 'common/supabase/utils'
import { LikeData, ShipData } from './love-types'
import { AnyBalanceChangeType } from 'common/balance-change'
import { Dashboard } from 'common/dashboard'
import { ChatMessage, PrivateChatMessage } from 'common/chat-message'
import { PrivateUser, User } from 'common/user'
import { ManaSupply } from 'common/stats'
import { Repost } from 'common/repost'
import { adContract } from 'common/boost'
import { PERIODS } from 'common/period'
import { SWEEPS_MIN_BET } from 'common/economy'
import {
LivePortfolioMetrics,
PortfolioMetrics,
} from 'common/portfolio-metrics'
import { Repost } from 'common/repost'
import { ManaSupply } from 'common/stats'
import { Row } from 'common/supabase/utils'
import type { ManaPayTxn, Txn } from 'common/txn'
import { PrivateUser, User } from 'common/user'
import { z } from 'zod'
import { ModReport } from '../mod-report'
import { LikeData, ShipData } from './love-types'
import { searchProps } from './market-search-types'
import {
FullMarket,
createMarketProps,
resolveMarketProps,
updateMarketProps,
type LiteMarket,
} from './market-types'
import { DisplayUser, FullUser } from './user-types'

import { RegistrationReturnType } from 'common/reason-codes'
import { ContractMetric } from 'common/contract-metric'
import {
CheckoutSession,
GIDXDocument,
GPSProps,
PaymentDetail,
checkoutParams,
verificationParams,
cashoutRequestParams,
PendingCashoutStatusData,
cashoutParams,
cashoutRequestParams,
checkoutParams,
verificationParams,
} from 'common/gidx/gidx'
import { notification_preference } from 'common/user-notification-preferences'
import { PrivateMessageChannel } from 'common/supabase/private-messages'
import { Notification } from 'common/notification'
import { RegistrationReturnType } from 'common/reason-codes'
import { NON_POINTS_BETS_LIMIT } from 'common/supabase/bets'
import { ContractMetric } from 'common/contract-metric'
import { PrivateMessageChannel } from 'common/supabase/private-messages'
import { notification_preference } from 'common/user-notification-preferences'

import { JSONContent } from '@tiptap/core'
import { StonkImage } from 'common/stonk-images'
// mqp: very unscientific, just balancing our willingness to accept load
// with user willingness to put up with stale data
export const DEFAULT_CACHE_STRATEGY =
Expand Down Expand Up @@ -1913,6 +1913,25 @@ export const API = (_apiTypeCheck = {
userId: z.string(),
}),
},
'create-stonk-image': {
method: 'POST',
visibility: 'public',
authed: false,
props: z
.object({
contractId: z.string(),
imageUrl: z.string(),
})
.strict(),
returns: { success: true },
},
'get-stonk-images': {
method: 'GET',
visibility: 'public',
authed: false,
props: z.object({ contracts: z.array(z.string()) }),
returns: { images: [] as StonkImage[] },
},
} as const)

export type APIPath = keyof typeof API
Expand Down
4 changes: 4 additions & 0 deletions common/src/stonk-images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type StonkImage = {
contractId: string
imageUrl: string
}
34 changes: 34 additions & 0 deletions stonks-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

ENV=${1:-dev}
DEBUG=${2:-false}

case $ENV in
dev)
FIREBASE_PROJECT=dev
NEXT_ENV=DEV ;;
prod)
FIREBASE_PROJECT=prod
NEXT_ENV=PROD ;;
*)
echo "Invalid environment; must be dev or prod."
exit 1
esac

firebase use $FIREBASE_PROJECT

API_COMMAND="dev"
if [ "$DEBUG" = "true" ]; then
API_COMMAND="debug"
fi

# Run all services concurrently
npx concurrently \
-n API,STONKS,TS \
-c white,magenta,cyan \
"cross-env NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=backend/api $API_COMMAND" \
"cross-env NEXT_PUBLIC_API_URL=localhost:8088 \
NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=stonks dev" \
"cross-env yarn --cwd=stonks ts-watch"
3 changes: 3 additions & 0 deletions stonks/.next/app-build-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pages": {}
}
54 changes: 54 additions & 0 deletions stonks/.next/build-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"pages": {
"/_app": [
"static/chunks/node_modules_next_dist_fda55f._.js",
"static/chunks/08b5e_react-dom_82bb97._.js",
"static/chunks/08b5e_4258f4._.js",
"static/chunks/[root of the server]__aee949._.js",
"static/chunks/[root of the server]__1fb947._.css",
"static/chunks/pages__app_5771e1._.js",
"static/chunks/pages__app_519130._.js"
],
"/": [
"static/chunks/[root of the server]__f4d4c0._.js",
"static/chunks/node_modules_next_dist_fda55f._.js",
"static/chunks/08b5e_react-dom_82bb97._.js",
"static/chunks/08b5e_@firebase_auth_dist_esm2017_e15f0c._.js",
"static/chunks/08b5e_lodash_87206f._.js",
"static/chunks/08b5e_zod_lib_index_mjs_02ef09._.js",
"static/chunks/08b5e_@supabase_gotrue-js_dist_module_b16fed._.js",
"static/chunks/08b5e_prosemirror-view_dist_index_bca8cb.js",
"static/chunks/08b5e_@tiptap_core_dist_tiptap-core_esm_8c5828.js",
"static/chunks/08b5e_@firebase_storage_dist_index_esm2017_0c4756.js",
"static/chunks/[project]__6eceda._.js",
"static/chunks/08b5e_@supabase_node-fetch_browser_bb8cad.js",
"static/chunks/pages_index_5771e1._.js",
"static/chunks/pages_index_7f8975._.js"
],
"/uploader": [
"static/chunks/[root of the server]__b2c1f9._.js",
"static/chunks/node_modules_next_dist_fda55f._.js",
"static/chunks/08b5e_react-dom_82bb97._.js",
"static/chunks/08b5e_@firebase_auth_dist_esm2017_e15f0c._.js",
"static/chunks/08b5e_lodash_778523._.js",
"static/chunks/08b5e_zod_lib_index_mjs_02ef09._.js",
"static/chunks/08b5e_@supabase_gotrue-js_dist_module_b16fed._.js",
"static/chunks/08b5e_prosemirror-view_dist_index_bca8cb.js",
"static/chunks/08b5e_@tiptap_core_dist_tiptap-core_esm_8c5828.js",
"static/chunks/08b5e_@firebase_storage_dist_index_esm2017_0c4756.js",
"static/chunks/08b5e_993a80._.js",
"static/chunks/08b5e_@supabase_node-fetch_browser_d61b7b.js",
"static/chunks/pages_uploader_5771e1._.js",
"static/chunks/pages_uploader_a9ebf5._.js"
]
},
"devFiles": [],
"ampDevFiles": [],
"polyfillFiles": [],
"lowPriorityFiles": [
"static/development/_ssgManifest.js",
"static/development/_buildManifest.js"
],
"rootMainFiles": [],
"ampFirstPages": []
}
Loading

0 comments on commit a5782eb

Please sign in to comment.