Skip to content

Move LiFi swaps DB to the chain+memory #105

Description

@matevz

While working on #103 I realized there are too many LiFi swap states after the request is submitted to the swap endpoint. This makes business logic too complex to fully grasp, it increases attack surface and we do not have direct access to DB from outside ROFL.

Generally I'd do the following:

  1. SwapManager gets the following new on-chain methods and fields which are now "source of truth":
    1. private externalSwaps[ExternalSwap] gated by the LP address or some admin and private activeExternalSwaps[uint256] that keeps track of the external swaps
    2. requestExternalSwap() external - transfers the origin token from user to LP and appends a record to externalSwap and activeExternalSwaps
    3. settleExternalSwap() external - transfers the target token from LP to user, removes the record from activeExternalSwaps
    4. recoverExternalSwap() external - transfers origin token from LP back to user, removes the record from activeExternalSwaps
  2. Keep two separate workers from feat: Async Swap #103 . But when a swap request comes to privana-services endpoint, the schedule queue now lives in memory.
  3. LiFi execution calls requestExternalSwap(), then withdraws the token to LiFi, waits for the deposit to arrive back and executes settleExternalSwap().
  4. If privana-services crashes, the schedule queue is simply lost. External swaps in progress are fulfilled by reading activeExternalSwaps[]. Call settleExternalSwap() or if there is no target token liquidity recoverExternalSwap().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions