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

Crypto-to-fiat: Resolve edge cases with liquidation addresses #2794

Merged
merged 16 commits into from
Aug 14, 2024

Conversation

jakubcolony
Copy link
Collaborator

@jakubcolony jakubcolony commented Jul 29, 2024

Description

See issue #2793 for details.

This PR resolves a number of potential issues with liquidation addresses:

  1. Check KYC handler was checking for existence of any liquidation address, instead of one linked to the user's bank account. If it doesn't exist, it will create one.
  2. When updating bank account details, a new bank account is created
    1. For accounts with the same currency, the existing liquidation address needed to be updated with the new account ID.
    2. For accounts with different currencies, a new liquidation address should be created.
  3. As there can be multiple liquidation addresses that can change at any point (primarily when user updates their bank details), we cannot rely on the ones stored in our DB. For that, a new query was added to get liquidation address for a given user.

It also removes the bridgeXYZQuery lambda, as handling both queries and mutations in a single lambda allows for less code duplication and easier deployments.

Note: In this PR I'm also testing the possibility of splitting amplify schema into multiple files in hope to make it more manageable, considering the existing schema is already nearly 4k lines long.

Testing

Restart your dev env - otherwise the separate schemas will not get picked up.

Issue 1:

  1. Make sure you set the Posthog and Persona env variables and run npm run prepare.
  2. Start KYC flow (you don't need to finish it though).
  3. Add USD bank account details (EUR accounts can't be tested in sandbox). You will also need to use a US address.

On next refetch the CheckKYCStatus query should return a liquidation address.

Issue 2:

  1. Update bank details to another USD account.
  2. Check that the liquidation address is still the same.

In production, if you updated bank details to EUR account, new liquidation address should be created. In sandbox however we can't really test subpoint 2).

Issue 3

You can run the following query with your user address to confirm it returns the liquidation address:

query LiqAdd {
  bridgeGetUserLiquidationAddress(userAddress: "")
}

Resolves #2793

@jakubcolony jakubcolony self-assigned this Jul 29, 2024
@jakubcolony jakubcolony force-pushed the feat/2793-liquidation-address branch 2 times, most recently from 1903d2e to 722b1bd Compare August 1, 2024 00:12
@jakubcolony jakubcolony marked this pull request as ready for review August 1, 2024 00:39
@jakubcolony jakubcolony requested review from a team as code owners August 1, 2024 00:39
@jakubcolony jakubcolony linked an issue Aug 1, 2024 that may be closed by this pull request
4 tasks
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

When trying to test this, loading the Crypto to fiat user profile tab, the bridgeXYZMutation crashes

Screenshot from 2024-08-02 15-02-51

So the KYC button doesn't show up:

Screenshot from 2024-08-02 15-02-53

I have all the env vars properly set, and have ran npm run prepare (I've also tried setting the apiKey inside the bridgeXYZMutation to the sandbox key, but still no change)

Screenshot from 2024-08-02 15-04-10
Screenshot from 2024-08-02 15-03-40

@jakubcolony jakubcolony force-pushed the feat/2572-wire-drains-history branch from 8de12e9 to 06906fe Compare August 6, 2024 07:13
@jakubcolony jakubcolony force-pushed the feat/2793-liquidation-address branch from 03168c5 to a6876a0 Compare August 6, 2024 07:44
@jakubcolony jakubcolony requested a review from rdig August 6, 2024 07:51
@jakubcolony
Copy link
Collaborator Author

@rdig looks like the import path was off, the joys of vanilla JS development 😃

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

I keep running into issues. Sorry about that :(

I'm attempting to start the KYC process, but the mutation lambda errors out
Screenshot from 2024-08-06 18-45-23
Screenshot from 2024-08-06 18-45-19

Note that as far as I'm aware the sendbox key and url are correctly set:
Screenshot from 2024-08-06 18-46-16

Base automatically changed from feat/2572-wire-drains-history to master August 6, 2024 20:59
@jakubcolony
Copy link
Collaborator Author

@rdig I wondered if it's because of the obviously fake email you used but even with the same details, it works fine on my end. I am also connected to the sandbox API with the same key.

Screen.Recording.2024-08-06.at.23.25.32.mov

Let's catch up on this tomorrow

@rdig
Copy link
Member

rdig commented Aug 6, 2024

Yeah, it's possible I'm doing something wrong with my setup.

@rumzledz
Copy link
Contributor

rumzledz commented Aug 7, 2024

Hey @rdig just chiming in -- I've seen this happen to me when I came from a branch that had a different network hash. Just thought I'd double check if you've restarted your dev again on this branch? But knowing you, you probably already have!

@rdig
Copy link
Member

rdig commented Aug 7, 2024

As I remember yes, I rand this fresh, but if there are any doubts I can test again just to make sure my findings are not faulty

rumzledz
rumzledz previously approved these changes Aug 9, 2024
Copy link
Contributor

@rumzledz rumzledz left a comment

Choose a reason for hiding this comment

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

I've stuck with using a US address and a US bank account all seems to be working @jakubcolony

I can prove that I updated it because the id field of the bankAccount object has been updated yet the liquidationAddress remained the same 👌

same liquidation

@jakubcolony jakubcolony force-pushed the feat/2793-liquidation-address branch from c36a424 to 297858f Compare August 13, 2024 23:25
@jakubcolony jakubcolony requested review from rumzledz and rdig August 14, 2024 00:15
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

Re-tested this (live, with @jakubcolony), with proper US and EUR accounts and not it's working as expected.

Screenshot from 2024-08-14 14-06-41

@jakubcolony jakubcolony merged commit b225170 into master Aug 14, 2024
4 of 6 checks passed
@jakubcolony jakubcolony deleted the feat/2793-liquidation-address branch August 14, 2024 11:23
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.

Crypto-to-fiat: Resolve edge cases with liquidation addresses
3 participants