From 8e798a81052e846088c6e2cfc76ebcdd428d0ef6 Mon Sep 17 00:00:00 2001 From: AcrossFireX Date: Tue, 12 Sep 2023 10:19:56 -0400 Subject: [PATCH 1/8] adding initial draft of SIP-026 --- sips/sip-026 | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 sips/sip-026 diff --git a/sips/sip-026 b/sips/sip-026 new file mode 100644 index 00000000..adb87cdb --- /dev/null +++ b/sips/sip-026 @@ -0,0 +1,89 @@ +# Preamble + +SIP-Number: SIP-025 +Title: Clarity DeFi Vault +Author: Tycho Onnasch, Fernando Foy, Philip de Smedt, Christian Hresko +Consideration: Technical +Type: Standard +Status: Draft +Created: Sep 7, 2023 +Last-Modified: Sep 7, 2023 +Sign-off: +Discussions-To: https://forum.stacks.org/t/clarity-defi-vault-sip/15567 +License: Creative Commons CC0 1.0 Universal license +Layer: Trait + +# Abstract + +This Stacks Improvement Proposal (SIP) aims to address the issue of commingled collateral positions on the Stacks blockchain's Clarity-based DeFi applications. Currently, due to Clarity's design, it is challenging for users to identify their specific collateral positions within the Stacks Explorer. This SIP proposes the creation of a common interface for contracts that hold SIP-010 assets. Implementing this interface will enable users to view their collateral positions distinctly, improving the overall user experience of Stacks DeFi applications. + +# License and Copyright + +This SIP is made available under the terms of the Creative Commons CC0 1.0 Universal license, available at https://creativecommons.org/publicdomain/zero/1.0/. This SIP's copyright is held by the Stacks Open Internet Foundation. + +# Introduction + +#### Problem Statement +Clarity, the smart contract language of the Stacks blockchain, presents a challenge in providing users with the ability to identify their collateral positions within Clarity-based DeFi applications. Unlike other blockchain ecosystems like Ethereum, where users can distinctly view their collateral in separate smart contracts on the chain's explorer, Clarity currently lacks this capability. + +As a result, users who post collateral on Stacks DeFi apps might perceive their collateral funds as commingled with other users' collateral, leading to a suboptimal user experience. The ability to natively inspect collateral positions on-chain is a crucial value proposition of DeFi over CeFi. + +#### Technical Background of the Problem +In Solidity, the Ethereum smart contract language, contracts can be deployed by executing Solidity code in transactions. This allows the deployment of contracts that represent vaults holding ERC-20s separately. These distinct collateral-holding contracts can be effortlessly looked up on explorers such as Etherscan, facilitating users' oversight of DeFi protocol collateralization. + +However, Clarity's design differs significantly. It does not allow contract deployment during transaction execution to maintain deterministic behavior and avoid infinite recursion. Consequently, representing entities that hold SIP-010 assets requires implementing logic within a single contract address. + +# Specification +The proposed solution is to create a common interface for contracts that hold SIP-010 assets. While Clarity does not permit contract deployment during transactions, different entities can be logically separated within the same contract. If the Stacks Explorer implements this common interface, users will be able to view their collateral positions distinctly, providing a user experience similar to DeFi on other blockchain platforms like Ethereum and Solana. + +The SIPXXX Vault trait, `sipxxx-vault-trait`, has 3 functions. These functions +do not update state, they are view-only and they allow for a common interface: +## Trait functions +### asset-contract + +`(asset-contract ((vault-id uint)) (response principal uint))` + +Returns the principal of the asset being held by the vault identified by `vault-id`. + +### holdings + +`(holdings ((vault-id uint) (asset )) (response uint uint))` + +Returns the total amount of the underlying asset held by the vault identified by `vault-id`. + +### holdings-of + +`(holdings-of ((vault-id uint) (asset ) (owner principal)) (response uint uint))` + +Returns the total amount of the underlying asset held by the vault identified by +their vault ID for `owner`. This is used when underlying assets are divided by vault id +and are grouped by the principal of `owner`. + +If the implementation does not group the vault assets by owner, return `0`. + + +```clarity +(use-trait sip-010-trait .sip-010-trait-ft-standard.sip-010-trait) + +(define-trait vault-trait + ( + (asset-contract (uint) (response principal uint)) + + (holdings (uint) (response uint uint)) + + (holdings-of (uint principal) (response uint uint)) + ) +) +``` +# Related Work +The dicussion on a vault Solidity implementation can be found here [Forum Discussion](https://www.usenix.org/conference/atc16/technical-sessions/presentation/ali) + +# Backwards Compatibility +N/A + +# Activation + +This trait will be considered activated when this trait is deployed to mainnet, and 3 different implementations of the trait have been deployed to mainnet, no later than Bitcoin block 900000. +# Reference Implementation +The reference implementation of this SIP can be found in the following GitHub repository: +GitHub: https://github.com/FriendsFerdinand/sips/blob/vault-standard/sips/sip-vault/sip-vault.md From 94dd777e9a87c29bc1e1a8dcf620505927156b77 Mon Sep 17 00:00:00 2001 From: AcrossFireX Date: Tue, 12 Sep 2023 10:20:50 -0400 Subject: [PATCH 2/8] update initial draft of sip-026 --- sips/sip-026 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sips/sip-026 b/sips/sip-026 index adb87cdb..c593c062 100644 --- a/sips/sip-026 +++ b/sips/sip-026 @@ -1,6 +1,6 @@ # Preamble -SIP-Number: SIP-025 +SIP-Number: SIP-026 Title: Clarity DeFi Vault Author: Tycho Onnasch, Fernando Foy, Philip de Smedt, Christian Hresko Consideration: Technical From 140ac925e6aaff2c5e59f9f55d1699687225aad8 Mon Sep 17 00:00:00 2001 From: AcrossFireX Date: Wed, 13 Sep 2023 11:53:58 -0400 Subject: [PATCH 3/8] update file structure for sip026 --- sips/{sip-026 => sip-026/sip-026-clarity-defi-vault.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sips/{sip-026 => sip-026/sip-026-clarity-defi-vault.md} (100%) diff --git a/sips/sip-026 b/sips/sip-026/sip-026-clarity-defi-vault.md similarity index 100% rename from sips/sip-026 rename to sips/sip-026/sip-026-clarity-defi-vault.md From 1aa47be21c2cbe101fc01bd715583d9c1d16f2e0 Mon Sep 17 00:00:00 2001 From: FriendsFerdinand Date: Thu, 5 Oct 2023 22:29:36 -0400 Subject: [PATCH 4/8] Clarified use of vault IDs --- sips/sip-026/sip-026-clarity-defi-vault.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sips/sip-026/sip-026-clarity-defi-vault.md b/sips/sip-026/sip-026-clarity-defi-vault.md index c593c062..2b401f75 100644 --- a/sips/sip-026/sip-026-clarity-defi-vault.md +++ b/sips/sip-026/sip-026-clarity-defi-vault.md @@ -36,6 +36,8 @@ However, Clarity's design differs significantly. It does not allow contract depl # Specification The proposed solution is to create a common interface for contracts that hold SIP-010 assets. While Clarity does not permit contract deployment during transactions, different entities can be logically separated within the same contract. If the Stacks Explorer implements this common interface, users will be able to view their collateral positions distinctly, providing a user experience similar to DeFi on other blockchain platforms like Ethereum and Solana. +New vault IDs are generated incrementally starting from 0. Vaults are separated logically based on this ID with a numerical value. + The SIPXXX Vault trait, `sipxxx-vault-trait`, has 3 functions. These functions do not update state, they are view-only and they allow for a common interface: ## Trait functions @@ -45,6 +47,12 @@ do not update state, they are view-only and they allow for a common interface: Returns the principal of the asset being held by the vault identified by `vault-id`. +Returns the token type balance `token-id` of a specific principal `who` as an +unsigned integer wrapped in an `ok` response. It has to respond with `u0` if the +principal does not have a balance of the specified token or if no token with +`token-id` exists. The function should never return an `err` response and is +recommended to be defined as read-only. + ### holdings `(holdings ((vault-id uint) (asset )) (response uint uint))` From 963044bfcad8a6e69fa03302356210f2269104d0 Mon Sep 17 00:00:00 2001 From: FriendsFerdinand Date: Wed, 11 Oct 2023 00:12:08 -0400 Subject: [PATCH 5/8] update Backwards Compatibility and added inspiration from Arkadiko contracts --- sips/sip-026/sip-026-clarity-defi-vault.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sips/sip-026/sip-026-clarity-defi-vault.md b/sips/sip-026/sip-026-clarity-defi-vault.md index 2b401f75..dec08279 100644 --- a/sips/sip-026/sip-026-clarity-defi-vault.md +++ b/sips/sip-026/sip-026-clarity-defi-vault.md @@ -34,7 +34,7 @@ In Solidity, the Ethereum smart contract language, contracts can be deployed by However, Clarity's design differs significantly. It does not allow contract deployment during transaction execution to maintain deterministic behavior and avoid infinite recursion. Consequently, representing entities that hold SIP-010 assets requires implementing logic within a single contract address. # Specification -The proposed solution is to create a common interface for contracts that hold SIP-010 assets. While Clarity does not permit contract deployment during transactions, different entities can be logically separated within the same contract. If the Stacks Explorer implements this common interface, users will be able to view their collateral positions distinctly, providing a user experience similar to DeFi on other blockchain platforms like Ethereum and Solana. +The proposed solution is to create a common interface for contracts that hold SIP-010 assets. While Clarity does not permit contract deployment during transactions, different entities can be logically separated within the same contract. This is used in the Arkadiko protocol contracts to differentiate between different vaults. If the Stacks Explorer implements this common interface, users will be able to view their collateral positions distinctly, providing a user experience similar to DeFi on other blockchain platforms like Ethereum and Solana. New vault IDs are generated incrementally starting from 0. Vaults are separated logically based on this ID with a numerical value. @@ -87,7 +87,7 @@ If the implementation does not group the vault assets by owner, return `0`. The dicussion on a vault Solidity implementation can be found here [Forum Discussion](https://www.usenix.org/conference/atc16/technical-sessions/presentation/ali) # Backwards Compatibility -N/A +The vault implementation was inspired by the vaults used in the Arkadiko protocol. Specifically, the Vault manager contract that is meant to abstract the data used in Arkadiko vaults. A vault trait contract can be deployed to interface with the Vault manager contract to be compliant with the standard (wrapping the original contract). # Activation From fa28ea76d861fd6f93e30137b0abcc5f5b2df84a Mon Sep 17 00:00:00 2001 From: Acrossfire <128664897+AcrossfireX@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:48:16 -0400 Subject: [PATCH 6/8] Update sip-026 to accepted by SIP Editors --- sips/sip-026/sip-026-clarity-defi-vault.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sips/sip-026/sip-026-clarity-defi-vault.md b/sips/sip-026/sip-026-clarity-defi-vault.md index dec08279..03c3cb95 100644 --- a/sips/sip-026/sip-026-clarity-defi-vault.md +++ b/sips/sip-026/sip-026-clarity-defi-vault.md @@ -5,7 +5,7 @@ Title: Clarity DeFi Vault Author: Tycho Onnasch, Fernando Foy, Philip de Smedt, Christian Hresko Consideration: Technical Type: Standard -Status: Draft +Status: Accepted Created: Sep 7, 2023 Last-Modified: Sep 7, 2023 Sign-off: From 81af6df11f0f6711eece217da63b25bdf0c11cf7 Mon Sep 17 00:00:00 2001 From: FriendsFerdinand Date: Mon, 6 Nov 2023 19:24:30 -0500 Subject: [PATCH 7/8] updated some links --- sips/sip-026/sip-026-clarity-defi-vault.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sips/sip-026/sip-026-clarity-defi-vault.md b/sips/sip-026/sip-026-clarity-defi-vault.md index dec08279..6b23c8e2 100644 --- a/sips/sip-026/sip-026-clarity-defi-vault.md +++ b/sips/sip-026/sip-026-clarity-defi-vault.md @@ -24,23 +24,28 @@ This SIP is made available under the terms of the Creative Commons CC0 1.0 Unive # Introduction #### Problem Statement + Clarity, the smart contract language of the Stacks blockchain, presents a challenge in providing users with the ability to identify their collateral positions within Clarity-based DeFi applications. Unlike other blockchain ecosystems like Ethereum, where users can distinctly view their collateral in separate smart contracts on the chain's explorer, Clarity currently lacks this capability. As a result, users who post collateral on Stacks DeFi apps might perceive their collateral funds as commingled with other users' collateral, leading to a suboptimal user experience. The ability to natively inspect collateral positions on-chain is a crucial value proposition of DeFi over CeFi. #### Technical Background of the Problem + In Solidity, the Ethereum smart contract language, contracts can be deployed by executing Solidity code in transactions. This allows the deployment of contracts that represent vaults holding ERC-20s separately. These distinct collateral-holding contracts can be effortlessly looked up on explorers such as Etherscan, facilitating users' oversight of DeFi protocol collateralization. However, Clarity's design differs significantly. It does not allow contract deployment during transaction execution to maintain deterministic behavior and avoid infinite recursion. Consequently, representing entities that hold SIP-010 assets requires implementing logic within a single contract address. # Specification + The proposed solution is to create a common interface for contracts that hold SIP-010 assets. While Clarity does not permit contract deployment during transactions, different entities can be logically separated within the same contract. This is used in the Arkadiko protocol contracts to differentiate between different vaults. If the Stacks Explorer implements this common interface, users will be able to view their collateral positions distinctly, providing a user experience similar to DeFi on other blockchain platforms like Ethereum and Solana. New vault IDs are generated incrementally starting from 0. Vaults are separated logically based on this ID with a numerical value. The SIPXXX Vault trait, `sipxxx-vault-trait`, has 3 functions. These functions do not update state, they are view-only and they allow for a common interface: + ## Trait functions + ### asset-contract `(asset-contract ((vault-id uint)) (response principal uint))` @@ -69,7 +74,6 @@ and are grouped by the principal of `owner`. If the implementation does not group the vault assets by owner, return `0`. - ```clarity (use-trait sip-010-trait .sip-010-trait-ft-standard.sip-010-trait) @@ -83,15 +87,20 @@ If the implementation does not group the vault assets by owner, return `0`. ) ) ``` + # Related Work -The dicussion on a vault Solidity implementation can be found here [Forum Discussion](https://www.usenix.org/conference/atc16/technical-sessions/presentation/ali) + +The dicussion on a vault Solidity implementation can be found here [Forum Discussion](https://ethereum-magicians.org/t/eip-4626-yield-bearing-vault-standard/7900) # Backwards Compatibility + The vault implementation was inspired by the vaults used in the Arkadiko protocol. Specifically, the Vault manager contract that is meant to abstract the data used in Arkadiko vaults. A vault trait contract can be deployed to interface with the Vault manager contract to be compliant with the standard (wrapping the original contract). # Activation This trait will be considered activated when this trait is deployed to mainnet, and 3 different implementations of the trait have been deployed to mainnet, no later than Bitcoin block 900000. + # Reference Implementation -The reference implementation of this SIP can be found in the following GitHub repository: -GitHub: https://github.com/FriendsFerdinand/sips/blob/vault-standard/sips/sip-vault/sip-vault.md + +A reference implementation of this SIP can be found in the following GitHub repository: +GitHub: https://github.com/FriendsFerdinand/clarity-defi-vault From 4f3ba542ee414c8954b8002c330e793c39f816c1 Mon Sep 17 00:00:00 2001 From: Acrossfire <128664897+AcrossfireX@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:28:07 -0500 Subject: [PATCH 8/8] Update formatting of sip-026-clarity-defi-vault.md --- sips/sip-026/sip-026-clarity-defi-vault.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sips/sip-026/sip-026-clarity-defi-vault.md b/sips/sip-026/sip-026-clarity-defi-vault.md index f89aa457..69cc5f76 100644 --- a/sips/sip-026/sip-026-clarity-defi-vault.md +++ b/sips/sip-026/sip-026-clarity-defi-vault.md @@ -1,16 +1,27 @@ # Preamble SIP-Number: SIP-026 + Title: Clarity DeFi Vault + Author: Tycho Onnasch, Fernando Foy, Philip de Smedt, Christian Hresko + Consideration: Technical + Type: Standard + Status: Accepted + Created: Sep 7, 2023 -Last-Modified: Sep 7, 2023 + +Last-Modified: Nov 9, 2023 + Sign-off: + Discussions-To: https://forum.stacks.org/t/clarity-defi-vault-sip/15567 + License: Creative Commons CC0 1.0 Universal license + Layer: Trait # Abstract @@ -90,7 +101,7 @@ If the implementation does not group the vault assets by owner, return `0`. # Related Work -The dicussion on a vault Solidity implementation can be found here [Forum Discussion](https://ethereum-magicians.org/t/eip-4626-yield-bearing-vault-standard/7900) +The dicussion on a vault Solidity implementation can be found here: https://ethereum-magicians.org/t/eip-4626-yield-bearing-vault-standard/7900 # Backwards Compatibility