-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16641bd
commit 9ed98fe
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/commonwealth/server/workers/knock/eventHandlers/tradeEvent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
EventHandler, | ||
notificationsProvider, | ||
WorkflowKeys, | ||
} from '@hicommonwealth/core'; | ||
import { models } from '@hicommonwealth/model'; | ||
import { QueryTypes } from 'sequelize'; | ||
import z from 'zod'; | ||
|
||
const output = z.boolean(); | ||
|
||
export const processTradeEvent: EventHandler< | ||
'TradeEvent', | ||
typeof output | ||
> = async ({ payload }) => { | ||
const provider = notificationsProvider(); | ||
|
||
const results = await models.sequelize.query<{ | ||
user_id: number; | ||
community_id: string; | ||
symbol: string; | ||
}>( | ||
` | ||
SELECT U.user_id, C.community_id, T.symbol from "Users" U | ||
JOIN "Addresses" A ON U.user_id = A.user_id | ||
JOIN "Communities" C ON C.id = A.community_id | ||
JOIN "Tokens" T ON T.namespace = C.namespace | ||
WHERE :token_address = T.token_address; | ||
`, | ||
{ | ||
replacements: { token_address: payload.token_address }, | ||
type: QueryTypes.SELECT, | ||
}, | ||
); | ||
|
||
await provider.triggerWorkflow({ | ||
key: WorkflowKeys.TradeEvent, | ||
users: results.map((u) => ({ id: String(u.user_id) })), | ||
data: { | ||
community_id: results[0].community_id, | ||
symbol: results[0].symbol, | ||
is_buy: payload.is_buy, | ||
}, | ||
}); | ||
|
||
// if (payload.floating_supply) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters