Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal for transfers #965

Open
wants to merge 56 commits into
base: dev
Choose a base branch
from
Open

Temporal for transfers #965

wants to merge 56 commits into from

Conversation

youngkidwarrior
Copy link
Collaborator

Create transfer tempora workflow

New trpc route that starts transfer workflow

Encapsulate temporal into a package

Call transfer trpc mutation from frontend

Create transfer temporal workflow

Encapsulate temporal into a package

Create transfer tempora workflow

Encapsulate temporal into a package

Temporal cloud changes

remove debug env

Show pending transfers from temporal in UI

Copy link
Collaborator Author

youngkidwarrior commented Dec 23, 2024

@youngkidwarrior youngkidwarrior changed the title Create transfer tempora workflow Tempo Dec 23, 2024
@youngkidwarrior youngkidwarrior changed the title Tempo Temporal for transfers Dec 23, 2024
@youngkidwarrior youngkidwarrior marked this pull request as ready for review December 23, 2024 02:19
@youngkidwarrior youngkidwarrior changed the base branch from dev to fix_mobile_button_row_refetches_and_fix_types December 26, 2024 23:43
@youngkidwarrior youngkidwarrior force-pushed the fix_mobile_button_row_refetches_and_fix_types branch from 8b23b52 to 6d8bd56 Compare December 27, 2024 00:16
@youngkidwarrior youngkidwarrior changed the base branch from fix_mobile_button_row_refetches_and_fix_types to graphite-base/965 December 27, 2024 00:25
@youngkidwarrior youngkidwarrior changed the base branch from graphite-base/965 to dev January 14, 2025 05:54
@youngkidwarrior youngkidwarrior force-pushed the temporal-2 branch 3 times, most recently from 808686b to 5088a28 Compare January 21, 2025 07:26

const workflowId = await transfer({ userOp })

if (workflowId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there cases where we don't get a workflowId? we should throw an error if we don't get one back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we throw in the temporal api

try {
const client = await getTemporalClient()
const chainId = baseMainnetClient.chain.id
const entryPoint = entryPointAddress[chainId]
const userOpHash = getUserOperationHash({
userOperation: userOp,
entryPoint,
chainId,
})
const { workflowId } = await client.workflow.start(TransferWorkflow, {
taskQueue: 'monorepo',
workflowId: `temporal/transfer/${user.id}/${userOpHash}`,
args: [userOp],
})
log(`Workflow Created: ${workflowId}`)
return workflowId
} catch (error) {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error instanceof Error ? error.message : 'Unknown error',
})
}

the catch should handle it. Though we could probably clean it up

left join profiles from_p on a.from_user_id = from_p.id
left join profiles to_p on a.to_user_id = to_p.id
where a.from_user_id = ( select auth.uid() )
or (a.to_user_id = ( select auth.uid() ) and a.event_name not like 'temporal_%')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so we don't show pending transfers to the recipient right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

LANGUAGE plpgsql
SECURITY DEFINER
AS $$
BEGINa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

CREATE TABLE temporal.send_account_transfers(
id serial primary key,
workflow_id text not null,
user_id uuid not null DEFAULT uuid_nil(), -- rely on trigger to set user_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not set a default then.


-- Validate user_id
IF _user_id IS NULL THEN
RAISE EXCEPTION 'No user found for the given address';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. most likely not going to happen, but instead of blocking the write. Let's just raise a notice with the workflow ID and then return early.

CREATE INDEX temporal_send_account_transfers_created_at_idx ON temporal.send_account_transfers(created_at);
CREATE UNIQUE INDEX temporal_send_account_transfers_workflow_id_idx ON temporal.send_account_transfers(workflow_id);

CREATE OR REPLACE FUNCTION temporal.handle_transfer_upsert()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a one liner comment explaining why this is a good idea or why we did it this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants