You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
SwapManager gets the following new on-chain methods and fields which are now "source of truth":
private externalSwaps[ExternalSwap] gated by the LP address or some admin and private activeExternalSwaps[uint256] that keeps track of the external swaps
requestExternalSwap() external - transfers the origin token from user to LP and appends a record to externalSwap and activeExternalSwaps
settleExternalSwap() external - transfers the target token from LP to user, removes the record from activeExternalSwaps
recoverExternalSwap() external - transfers origin token from LP back to user, removes the record from activeExternalSwaps
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.
LiFi execution calls requestExternalSwap(), then withdraws the token to LiFi, waits for the deposit to arrive back and executes settleExternalSwap().
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().
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:
SwapManagergets the following new on-chain methods and fields which are now "source of truth":private externalSwaps[ExternalSwap]gated by the LP address or some admin andprivate activeExternalSwaps[uint256]that keeps track of the external swapsrequestExternalSwap() external- transfers the origin token from user to LP and appends a record to externalSwap and activeExternalSwapssettleExternalSwap() external- transfers the target token from LP to user, removes the record from activeExternalSwapsrecoverExternalSwap() external- transfers origin token from LP back to user, removes the record from activeExternalSwapsrequestExternalSwap(), then withdraws the token to LiFi, waits for the deposit to arrive back and executessettleExternalSwap().activeExternalSwaps[]. CallsettleExternalSwap()or if there is no target token liquidityrecoverExternalSwap().