LIT-Protocol / Issues-and-Reports

For bug reports, feature requests, and implementation questions related to Lit Protocol and use of the Lit SDK.
0 stars 0 forks source link

[Discord] Automate transfer #60

Closed awisniew207 closed 2 months ago

awisniew207 commented 3 months ago

Description of the issue

From user:

Hi there ! I'm working on an automation flow of pay/transfer/swaps. My idea is that the user should connect the wallet, create a new pair with SIWE. Then ask to automate a flow, like transfer 1 usdc to X wallet each wednesday. The user should add money to the new wallet created and fogot about it. We should call every wednesday the function with the created PKP that only allows us to send X amount of money or interact with Y contract. Is there any code example for that, guidelines or recommendation? The idea is to be as non-custodial as we can.

Message link

Additional context

No response

awisniew207 commented 3 months ago

Hi there!

For the first part of your inquiry, the user could create a PKP and fund it through sending tokens to the PKP's Ethereum address.

For sending X amount of money or interacting with Y contract, this can be done through Lit Actions and Session Signatures. By generating Session Signatures and specifying a specific Lit Action IPFS CID hash in the LitAccessControlConditionResource, similar to:

LitAccessControlConditionResource("<IPFS CID Hash Here>")

This would permit the PKP to only interact with that specific Lit Action, where you could either hardcode a contract address or pass it in as a parameter.

For a very long timeframe, Session Signatures would either need to be regenerated, have a very long expiry date, or you could generate Session Signatures using a Lit Action that checks only generates sigs if there's an execution scheduled.

For automating the execution of transactions (i.e. every Wednesday), there's a lot that could be done for this. Simplest is there's some CRON job/scheduler on a server that makes a request to Lit, however that is pretty centralized. There's always going to be someone off-chain executing code to start the process. You could consider something like loading in a schedule set by the user from IPFS/a smart contract, so that the off-chain executor only has the authority to check if there's an execution scheduled.

We currently don't have an example very similar to this, but you may find this repository helpful for seeing other implementations of Lit.

We do have some users using Lit for a similar implementation to what you described. We can also assist you with designing an architecture if you could specify your build requirements!