Aleksandar Hadzibabic
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    In the [previous article](https://t.co/xpYCru6vsd), we explored different approaches to **key management**, from hardware wallets to distributed cryptography and smart accounts. Each solution defines how users hold, recover, and secure their keys. But key custody is only half the story. The next challenge is **interaction**: how do we let users engage with DeFi apps seamlessly, without compromising self-custody or security? In this article, we’ll tackle that question through a practical example: building a **self-custodial DCA (Dollar-Cost Averaging) tool** for everyday investing. Along the way, we’ll examine how different architectures shape both the security model and user experience. ### From Keys to Actions: The UX Challenge Take **Tangem**, for example, a hardware-based wallet that removes seed phrases. To interact with a DeFi app, a user connects their Tangem mobile wallet just like any browser-based self-custodial wallet. It’s secure, but not ideal for automation. A **DCA (Dollar-Cost Averaging)** tool needs to: - allow users to set an investment interval, and - automatically execute trades on their behalf. This introduces a new challenge: > How can the app act **autonomously** while keeping the user in **full control** of their funds? To achieve this, we can imagine a **DCA vault** that holds the user’s funds and investment logic. The user deposits tokens into the vault, and a scheduler triggers swaps on Uniswap (or similar DEXs) at specified intervals, but **only** according to the user’s defined rules. ![ChatGPT Image Oct 25, 2025, 01_19_47 PM](https://hackmd.io/_uploads/B1ngQN9Cll.png) That brings us to two key architectural questions: ### 1. Where is the vault logic located? There are two broad options: - **On-chain:** - The vault is implemented as a **smart contract**. - Logic and rules are enforced transparently on-chain (e.g. using Safe modules or custom DCA contracts). - The scheduler only triggers swaps using an **authorized session keys** (e.g. [Rhinestone](https://docs.rhinestone.dev/home/concepts/session-keys#session-keys)), if all conditions (like timestamp, asset pair, limits) pass. - **Off-chain:** - The vault logic runs on external infrastructure — either a centralized server or a **distributed execution network** like [Lit Protocol](https://developer.litprotocol.com/) or [Chainlink CRE](https://chain.link/chainlink-runtime-environment). - In this model, private keys (or key shares) sign transactions according to defined policies, and the execution environment enforces the rules. ### 2. Who controls the vault? There are also two control models: - **User-controlled:** - The user maintains custody, while granting the app limited access via **session keys** or **Programmable Key Pairs (PKPs)**. - Policies like spending caps or whitelisted functions are enforced either on-chain (Smart Account sessions) or off-chain (Lit network). - **App-controlled:** - The vault belongs to the app. The app has direct access to funds and executes actions on behalf of the user (similar to centralized solutions like [Calculated Finance](https://calculated.fi/)). - This model sacrifices full self-custody for simplicity. With those two questions in mind, the design space narrows to two main approaches: **Smart Account sessions** or **PKPs** (generated via Distributed Key Generation). ## Smart account sessions vs PKPs Both **Smart Account sessions** and **PKPs (Programmable Key Pairs)** provide ways to delegate control securely, but they differ in **where logic is executed** and **who enforces policies**. | Aspect | Smart Account Sessions | PKPs (Lit Network) | | ------------------------ | ---------------------------------- | ----------------------------------------- | | **Vault Logic Location** | On-chain (smart contract) | Off-chain (Lit distributed network) | | **Control** | User-owned smart account | User-linked key pair managed by Lit nodes | | **Policy Enforcement** | Enforced by blockchain consensus | Enforced by Lit Network consensus | | **Recovery** | Managed via smart account recovery | Managed via linked authentication methods | **Key differences:** - **Smart Account Sessions:** Vault logic runs **on-chain**, secured by blockchain consensus. All rules are verifiable and immutable, and any DCA trades triggered by a session key are enforced directly by the smart contract. Updates or changes require contract upgrades. - **PKPs via Lit Network:** Vault logic runs **off-chain** on the Lit distributed network. Trades still execute on-chain, but the rules are enforced by **Lit node consensus** instead of blockchain consensus. This allows more flexible automation and smoother UX while retaining user control via the programmable key pair. the main distinction is where the **vault logic resides** and which consensus guarantees policy enforcement (blockchain vs Lit Network) while the DeFi interactions themselves remain on-chain in both cases. ## Conclusion Building a self-custodial DCA tool highlights the delicate balance between **security, control, and user experience**. Smart Account sessions and PKPs both enable autonomous, rule-driven execution, but differ in **where vault logic lives** and **who enforces it**. Ultimately, the choice comes down to the trade-off your product prioritizes: **absolute on-chain security** or **efficient, user-friendly automation**, while still keeping funds in the user’s control. Understanding this distinction is **essential** to designing the next generation of self-custodial DeFi tools. ## Reference - https://hackmd.io/@AHadzibabic/r1TiNN-Ree - https://developer.litprotocol.com/ - https://docs.rhinestone.dev/home/concepts/session-keys#session-keys

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully