From fef39f91e328e09273ef3adec76bf77c96c4d31a Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Sun, 9 Aug 2020 20:04:46 -0700 Subject: [PATCH 01/12] Initial PIP-17 Draft --- README.mediawiki | 7 ++ pip-0017 .mediawiki | 201 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 pip-0017 .mediawiki diff --git a/README.mediawiki b/README.mediawiki index 87371fd..f81f495 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -49,6 +49,13 @@ It should be known without consensus from the miners and users of the protocol, | David Johnston, Steven Masley | Standard | Draft +|- +| [[pip-0017.mediawiki|17]] +| Consensus (hard fork) +| Leveraged Positions +| Devon Katz +| Standard +| Draft |} diff --git a/pip-0017 .mediawiki b/pip-0017 .mediawiki new file mode 100644 index 0000000..fe61daf --- /dev/null +++ b/pip-0017 .mediawiki @@ -0,0 +1,201 @@ + +
+  PIP: 17
+  Title: Leveraged Positions
+  Layer: Consensus (hard fork)
+  Author: Devon Katz 
+  Comments-Summary: No comments yet.
+  Comments-URI: https://github.com/pegnet/pips/wiki/Comments:PIP-0017
+  Status: Draft
+  Type: Standards Track
+  Created: 2020-08-08
+  License: BSD-2-Clause
+
+ +==Abstract== + +This PIP details a design to achieve leveraged positions within PegNet, based on the proposed "Burn and Mint" mechanism and a flat fee structure. The design detailed in this PIP enables "short" and "long" positions to be made using a user's pAssets with a selectable leverage multiplier. + +A leveraged position is entered into by locking pAssets as collateral, defining a leverage multiplier and position direction, and opening the position. By doing so there is now a set liquidation price, whereby if the asset goes against the traders position by a certain amount, less fees, the collateral is burned in a liquidation event. If not liquidated, upon a decision to close the position by the trader, a profit or loss is determined and for a loss that portion of collateral is burned, and for a gain the protocol mints that amount of additional tokens to reward the trade in the same way that current conversions function within the protocol. + +Taking a leveraged position in PegNet is similar to any other conversion in PegNet, but the rate at which a trader loses or gains on that position has leverage applied to it. If the leveraged position is profitable, the protocol mints the profit back to the position holder upon closing just as if the user engaged in and exited a traditional long margin trade, only the profit comes from the protocol rather than a counterparty. Conversely, if the leveraged position holder’s position is losing, the protocol burns through the collateral in the trade at a faster rate, and depending on the final design for leverage within PegNet, can burn the entire collateral when a liquidation price is hit. + +==Motivation== + +As a DeFi asset conversion network that mints it’s own tokens used for arbitrage, PegNet is in a unique position to provide leveraged positions to market participants without requiring 3rd parties, counterparties or lending fees. Traditional approaches to leverage vary by market, but all require some combination of borrowing other people's money to leverage position size or sell their assets, a counterparty, and managers maintaining a position for a fee. + +As it exists today, margin trading cryptocurrency and other assets carries regulatory burden, counterparty risk, and a variety of fees. These burdens gravitate around centralized parties, such as exchanges, as they represent central points of failure. They are responsible for paying out profits and taking losses from traders, for maintaining custody of funds, from protecting positions from a variety of attack vectors, and for keeping up with regulatory oversight of their customers without leaking customer data. All of these duties increase risks, fees, and regulatory burdens. PegNet is uniquely suited to solve each of these problems. + + +==Specification== + +=== USD Denomination === +The leveraged positions described in this PIP are exclusively denominated in terms of USD. For example, a leveraged position based on pXBT leverages price movements of USD/pXBT as determined by the Oracle Price Record derived rate. + +=== Enabled Pegged Assets === +Only certain large-cap pAssets are enabled for leveraged positions: +*pXBT +*pETH + +(More TBD) + +=== Fee Structure & Calculation === +Unlike a normal conversion or transfer, an open leveraged position carries an ongoing computational cost to each daemon due to the requirement of perform position maintainance tasks such as calculating the unrealized profits & losses and liquidation status for each open position. + +To help protect PegNet from a denial of service attack, a flat fee structure is applied to leveraged positions each block, for the duration of the position, with the exception of the placement block. + +The fee for each open position will be $0.001 USD per-block, which is deducted on an ongoing basis from the collateral of the position until it is either manually closed or automatically liquidated. The USD fee amount to deduct from the open position is calculated based on the OPR derived rate for the block of the placement asset. Fees collected are burnt from the protocol entirely. + + +(EQUATION PLACEHOLDER) + + +For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi. + +=== Determining Liquidation Status === +Each block the daemon will determine the liquidation status of each open position based on: +#The collateral amount +#The placement price +#The placement block +#The leverage +#The current price +#The current block +#Total fees + +Liquidation of a position occurs when the unrealized losses, including fees of the trade, become greater than or equal to the total collateral amount. Until those conditions are met, the trade may be manually exited by the user at any time. + + +(EQUATION PLACEHOLDER) + + +=== Entering & Exiting A Leveraged Position === +To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction. + +Once the transaction is submitted and picked up by the daemon, the collateral is deducted from their address in the target pAsset and removed from circulation until the trade is exited. The user may exit the position at any time before a liquidation event occurs to realize their profits or losses. + +Exiting a leveraged position applies the profits, losses, and fees from the leveraged position to the collateral and closes the position. If the position was a partial or complete loss, the collateral is burnt away. If the position was profitable, the profits are tabulated and minted back to the creator of the position. + +=== Transaction Format === + +The transaction formats to enter and exit from leveraged positions draw up on the existing transaction format in PegNet 2.0. + +==== Position Entry Format ==== + +{ + "version": 1, + "position": { + "address": "FA2xwG47oyWCefAHfYg8r87mWr9JLUXpdZ7PeE8rXEb9xtDvdxbQ", + "amount": 1000000000, + "type": "pXBT" + "leverage": 2 + } +} + + +{| class="wikitable" +|- style="font-weight:bold;" +! Field +! Type +! Description +! Validation +! style="font-weight:normal;" | Required +|- +| version +| number +| The protocol version +| +| Y +|- +| position +| object +| The object containing the required information for placing a position +| +| Y +|- +| position.address +| string +| The input address to the leveraged position +| Follows existing validation and FAT-103 signing standard where address is the 0th input +| Y +|- +| position.amount +| number +| The amount of collateral placed into the leveraged trade +| Must be a positive whole number greater than or equal to the per-block open position fee calculated via the OPR of the placement block +| Y +|- +| position.type +| string +| The desired pAsset symbol used in entering a leveraged position +| Must be a valid pAsset symbol. Must be a pAsset enabled for leveraged positions in the current block +| Y +|- +| position.leverage +| number +| The desired leverage for the position, where a negative number represents a short position and a positive position represents a long +| Must be a whole number on the range from -10 to 10 inclusive, excluding zero. +| Y +|} + +For a position entry transaction to be valid, the following criteria must be met: +#All field level validation criteria featured in the above table must be met +#The input address position.address must have properly signed the entry and the signature must be valid via FAT-103 +#The input address position.address must own position.amount of the pAsset position.type in the current block after any conversions or transfers are applied + + +==== Position Exit Format ==== + +{ + "version": 1, + "position": { + "close": "66f9bef30e10c867e09d0927f01660cca34d0bc0df859cd73f4acae167ae8fca" + } +} + + +{| class="wikitable" +|- style="font-weight:bold;" +! Field +! Type +! Description +! Validation +! Required +|- +| version +| number +| The protocol version +| +| Y +|- +| position +| object +| The object containing the required information for placing a position +| +| Y +|- +| position.close +| string +| The entryhash of the position to exit from +| Must be a valid entryhash +| Y +|} + +For a position exit transaction to be valid, the following criteria must be met: +#The entryhash in the position.close field must correspond to a position +#The position corresponding to position.close field must still be open, and must not have been liquidated in a previous block +#The open position's source input address(position.address in the Position Entry entry) must have validly signed the position exit entry via FAT-103 + +==Rationale== + +=== Fees === +Fees are included as a mechanism to help prevent potential purposeful or accidental abuse of the system by placing large numbers of small positions that may be opened indeterminately, causing a poor cost-benefit scaling for each additional small position. Programmatic trading bots made for traditional exchanges typically place large numbers of small orders. Since fees are flat and fixed, it is optimal to create a smaller number of larger positions. + +=== Fee Burning === +Burning of fees is included as a mechanism in leveraged positions to help conterbalance inflation created by successful positions, which mint back profits to the position creator at the protocol level. This also creates an incentive to open lower numbers of larger positions instead of many small ones to minimize fees. + +=== 1:1 Position To Entryhash Relationship === +Instead of using the existing transaction batch format, this PIP proposes a new key "position" be created under the JSON root of each transaction entry. The purpose of this is to force a 1:1 relationship between opening a position and the resulting entryhash while not interfering with the existing validation of conversions and transfers. This allows positions to be identified uniquely, be checked on, and be cancelled in a succinct way using their entryhash. + +==Reference implementation== + +Implementation in progress, TBD From ee112db242922a6afe9750323ac7520b8f82e596 Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Sun, 9 Aug 2020 20:06:22 -0700 Subject: [PATCH 02/12] Fix filename for PIP-17 --- pip-0017 .mediawiki => pip-0017.mediawiki | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pip-0017 .mediawiki => pip-0017.mediawiki (100%) diff --git a/pip-0017 .mediawiki b/pip-0017.mediawiki similarity index 100% rename from pip-0017 .mediawiki rename to pip-0017.mediawiki From 915ecae858b55e2acfddb3783c01a85721afa688 Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Sun, 9 Aug 2020 20:09:22 -0700 Subject: [PATCH 03/12] Fix closing code tag, code preformatting --- pip-0017 .mediawiki | 205 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 pip-0017 .mediawiki diff --git a/pip-0017 .mediawiki b/pip-0017 .mediawiki new file mode 100644 index 0000000..d126b50 --- /dev/null +++ b/pip-0017 .mediawiki @@ -0,0 +1,205 @@ + +
+  PIP: 17
+  Title: Leveraged Positions
+  Layer: Consensus (hard fork)
+  Author: Devon Katz 
+  Comments-Summary: No comments yet.
+  Comments-URI: https://github.com/pegnet/pips/wiki/Comments:PIP-0017
+  Status: Draft
+  Type: Standards Track
+  Created: 2020-08-08
+  License: BSD-2-Clause
+
+ +==Abstract== + +This PIP details a design to achieve leveraged positions within PegNet, based on the proposed "Burn and Mint" mechanism and a flat fee structure. The design detailed in this PIP enables "short" and "long" positions to be made using a user's pAssets with a selectable leverage multiplier. + +A leveraged position is entered into by locking pAssets as collateral, defining a leverage multiplier and position direction, and opening the position. By doing so there is now a set liquidation price, whereby if the asset goes against the traders position by a certain amount, less fees, the collateral is burned in a liquidation event. If not liquidated, upon a decision to close the position by the trader, a profit or loss is determined and for a loss that portion of collateral is burned, and for a gain the protocol mints that amount of additional tokens to reward the trade in the same way that current conversions function within the protocol. + +Taking a leveraged position in PegNet is similar to any other conversion in PegNet, but the rate at which a trader loses or gains on that position has leverage applied to it. If the leveraged position is profitable, the protocol mints the profit back to the position holder upon closing just as if the user engaged in and exited a traditional long margin trade, only the profit comes from the protocol rather than a counterparty. Conversely, if the leveraged position holder’s position is losing, the protocol burns through the collateral in the trade at a faster rate, and depending on the final design for leverage within PegNet, can burn the entire collateral when a liquidation price is hit. + +==Motivation== + +As a DeFi asset conversion network that mints it’s own tokens used for arbitrage, PegNet is in a unique position to provide leveraged positions to market participants without requiring 3rd parties, counterparties or lending fees. Traditional approaches to leverage vary by market, but all require some combination of borrowing other people's money to leverage position size or sell their assets, a counterparty, and managers maintaining a position for a fee. + +As it exists today, margin trading cryptocurrency and other assets carries regulatory burden, counterparty risk, and a variety of fees. These burdens gravitate around centralized parties, such as exchanges, as they represent central points of failure. They are responsible for paying out profits and taking losses from traders, for maintaining custody of funds, from protecting positions from a variety of attack vectors, and for keeping up with regulatory oversight of their customers without leaking customer data. All of these duties increase risks, fees, and regulatory burdens. PegNet is uniquely suited to solve each of these problems. + + +==Specification== + +=== USD Denomination === +The leveraged positions described in this PIP are exclusively denominated in terms of USD. For example, a leveraged position based on pXBT leverages price movements of USD/pXBT as determined by the Oracle Price Record derived rate. + +=== Enabled Pegged Assets === +Only certain large-cap pAssets are enabled for leveraged positions: +*pXBT +*pETH + +(More TBD) + +=== Fee Structure & Calculation === +Unlike a normal conversion or transfer, an open leveraged position carries an ongoing computational cost to each daemon due to the requirement of perform position maintainance tasks such as calculating the unrealized profits & losses and liquidation status for each open position. + +To help protect PegNet from a denial of service attack, a flat fee structure is applied to leveraged positions each block, for the duration of the position, with the exception of the placement block. + +The fee for each open position will be $0.001 USD per-block, which is deducted on an ongoing basis from the collateral of the position until it is either manually closed or automatically liquidated. The USD fee amount to deduct from the open position is calculated based on the OPR derived rate for the block of the placement asset. Fees collected are burnt from the protocol entirely. + + +(EQUATION PLACEHOLDER) + + +For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi. + +=== Determining Liquidation Status === +Each block the daemon will determine the liquidation status of each open position based on: +#The collateral amount +#The placement price +#The placement block +#The leverage +#The current price +#The current block +#Total fees + +Liquidation of a position occurs when the unrealized losses, including fees of the trade, become greater than or equal to the total collateral amount. Until those conditions are met, the trade may be manually exited by the user at any time. + + +(EQUATION PLACEHOLDER) + + +=== Entering & Exiting A Leveraged Position === +To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction. + +Once the transaction is submitted and picked up by the daemon, the collateral is deducted from their address in the target pAsset and removed from circulation until the trade is exited. The user may exit the position at any time before a liquidation event occurs to realize their profits or losses. + +Exiting a leveraged position applies the profits, losses, and fees from the leveraged position to the collateral and closes the position. If the position was a partial or complete loss, the collateral is burnt away. If the position was profitable, the profits are tabulated and minted back to the creator of the position. + +=== Transaction Format === + +The transaction formats to enter and exit from leveraged positions draw up on the existing transaction format in PegNet 2.0. + +==== Position Entry Format ==== +
+
+{
+  "version": 1,
+  "position": {
+    "address": "FA2xwG47oyWCefAHfYg8r87mWr9JLUXpdZ7PeE8rXEb9xtDvdxbQ",
+    "amount": 1000000000,
+    "type": "pXBT"
+    "leverage": 2
+  }
+}
+
+
+ +{| class="wikitable" +|- style="font-weight:bold;" +! Field +! Type +! Description +! Validation +! style="font-weight:normal;" | Required +|- +| version +| number +| The protocol version +| +| Y +|- +| position +| object +| The object containing the required information for placing a position +| +| Y +|- +| position.address +| string +| The input address to the leveraged position +| Follows existing validation and FAT-103 signing standard where address is the 0th input +| Y +|- +| position.amount +| number +| The amount of collateral placed into the leveraged trade +| Must be a positive whole number greater than or equal to the per-block open position fee calculated via the OPR of the placement block +| Y +|- +| position.type +| string +| The desired pAsset symbol used in entering a leveraged position +| Must be a valid pAsset symbol. Must be a pAsset enabled for leveraged positions in the current block +| Y +|- +| position.leverage +| number +| The desired leverage for the position, where a negative number represents a short position and a positive position represents a long +| Must be a whole number on the range from -10 to 10 inclusive, excluding zero. +| Y +|} + +For a position entry transaction to be valid, the following criteria must be met: +#All field level validation criteria featured in the above table must be met +#The input address position.address must have properly signed the entry and the signature must be valid via FAT-103 +#The input address position.address must own position.amount of the pAsset position.type in the current block after any conversions or transfers are applied + + +==== Position Exit Format ==== +
+
+{
+  "version": 1,
+  "position": {
+    "close": "66f9bef30e10c867e09d0927f01660cca34d0bc0df859cd73f4acae167ae8fca"
+  }
+}
+
+
+ +{| class="wikitable" +|- style="font-weight:bold;" +! Field +! Type +! Description +! Validation +! Required +|- +| version +| number +| The protocol version +| +| Y +|- +| position +| object +| The object containing the required information for placing a position +| +| Y +|- +| position.close +| string +| The entryhash of the position to exit from +| Must be a valid entryhash +| Y +|} + +For a position exit transaction to be valid, the following criteria must be met: +#The entryhash in the position.close field must correspond to a position +#The position corresponding to position.close field must still be open, and must not have been liquidated in a previous block +#The open position's source input address(position.address in the Position Entry) must have validly signed the position exit entry via FAT-103 + +==Rationale== + +=== Fees === +Fees are included as a mechanism to help prevent potential purposeful or accidental abuse of the system by placing large numbers of small positions that may be opened indeterminately, causing a poor cost-benefit scaling for each additional small position. Programmatic trading bots made for traditional exchanges typically place large numbers of small orders. Since fees are flat and fixed, it is optimal to create a smaller number of larger positions. + +=== Fee Burning === +Burning of fees is included as a mechanism in leveraged positions to help conterbalance inflation created by successful positions, which mint back profits to the position creator at the protocol level. This also creates an incentive to open lower numbers of larger positions instead of many small ones to minimize fees. + +=== 1:1 Position To Entryhash Relationship === +Instead of using the existing transaction batch format, this PIP proposes a new key "position" be created under the JSON root of each transaction entry. The purpose of this is to force a 1:1 relationship between opening a position and the resulting entryhash while not interfering with the existing validation of conversions and transfers. This allows positions to be identified uniquely, be checked on, and be cancelled in a succinct way using their entryhash. + +==Reference implementation== + +Implementation in progress, TBD From e0bf7a7baf08ce41a2395e6730b9d53c4a0f48a7 Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Sun, 9 Aug 2020 20:11:32 -0700 Subject: [PATCH 04/12] Replace misnamed version --- pip-0017 .mediawiki | 205 -------------------------------------------- pip-0017.mediawiki | 8 +- 2 files changed, 6 insertions(+), 207 deletions(-) delete mode 100644 pip-0017 .mediawiki diff --git a/pip-0017 .mediawiki b/pip-0017 .mediawiki deleted file mode 100644 index d126b50..0000000 --- a/pip-0017 .mediawiki +++ /dev/null @@ -1,205 +0,0 @@ - -
-  PIP: 17
-  Title: Leveraged Positions
-  Layer: Consensus (hard fork)
-  Author: Devon Katz 
-  Comments-Summary: No comments yet.
-  Comments-URI: https://github.com/pegnet/pips/wiki/Comments:PIP-0017
-  Status: Draft
-  Type: Standards Track
-  Created: 2020-08-08
-  License: BSD-2-Clause
-
- -==Abstract== - -This PIP details a design to achieve leveraged positions within PegNet, based on the proposed "Burn and Mint" mechanism and a flat fee structure. The design detailed in this PIP enables "short" and "long" positions to be made using a user's pAssets with a selectable leverage multiplier. - -A leveraged position is entered into by locking pAssets as collateral, defining a leverage multiplier and position direction, and opening the position. By doing so there is now a set liquidation price, whereby if the asset goes against the traders position by a certain amount, less fees, the collateral is burned in a liquidation event. If not liquidated, upon a decision to close the position by the trader, a profit or loss is determined and for a loss that portion of collateral is burned, and for a gain the protocol mints that amount of additional tokens to reward the trade in the same way that current conversions function within the protocol. - -Taking a leveraged position in PegNet is similar to any other conversion in PegNet, but the rate at which a trader loses or gains on that position has leverage applied to it. If the leveraged position is profitable, the protocol mints the profit back to the position holder upon closing just as if the user engaged in and exited a traditional long margin trade, only the profit comes from the protocol rather than a counterparty. Conversely, if the leveraged position holder’s position is losing, the protocol burns through the collateral in the trade at a faster rate, and depending on the final design for leverage within PegNet, can burn the entire collateral when a liquidation price is hit. - -==Motivation== - -As a DeFi asset conversion network that mints it’s own tokens used for arbitrage, PegNet is in a unique position to provide leveraged positions to market participants without requiring 3rd parties, counterparties or lending fees. Traditional approaches to leverage vary by market, but all require some combination of borrowing other people's money to leverage position size or sell their assets, a counterparty, and managers maintaining a position for a fee. - -As it exists today, margin trading cryptocurrency and other assets carries regulatory burden, counterparty risk, and a variety of fees. These burdens gravitate around centralized parties, such as exchanges, as they represent central points of failure. They are responsible for paying out profits and taking losses from traders, for maintaining custody of funds, from protecting positions from a variety of attack vectors, and for keeping up with regulatory oversight of their customers without leaking customer data. All of these duties increase risks, fees, and regulatory burdens. PegNet is uniquely suited to solve each of these problems. - - -==Specification== - -=== USD Denomination === -The leveraged positions described in this PIP are exclusively denominated in terms of USD. For example, a leveraged position based on pXBT leverages price movements of USD/pXBT as determined by the Oracle Price Record derived rate. - -=== Enabled Pegged Assets === -Only certain large-cap pAssets are enabled for leveraged positions: -*pXBT -*pETH - -(More TBD) - -=== Fee Structure & Calculation === -Unlike a normal conversion or transfer, an open leveraged position carries an ongoing computational cost to each daemon due to the requirement of perform position maintainance tasks such as calculating the unrealized profits & losses and liquidation status for each open position. - -To help protect PegNet from a denial of service attack, a flat fee structure is applied to leveraged positions each block, for the duration of the position, with the exception of the placement block. - -The fee for each open position will be $0.001 USD per-block, which is deducted on an ongoing basis from the collateral of the position until it is either manually closed or automatically liquidated. The USD fee amount to deduct from the open position is calculated based on the OPR derived rate for the block of the placement asset. Fees collected are burnt from the protocol entirely. - - -(EQUATION PLACEHOLDER) - - -For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi. - -=== Determining Liquidation Status === -Each block the daemon will determine the liquidation status of each open position based on: -#The collateral amount -#The placement price -#The placement block -#The leverage -#The current price -#The current block -#Total fees - -Liquidation of a position occurs when the unrealized losses, including fees of the trade, become greater than or equal to the total collateral amount. Until those conditions are met, the trade may be manually exited by the user at any time. - - -(EQUATION PLACEHOLDER) - - -=== Entering & Exiting A Leveraged Position === -To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction. - -Once the transaction is submitted and picked up by the daemon, the collateral is deducted from their address in the target pAsset and removed from circulation until the trade is exited. The user may exit the position at any time before a liquidation event occurs to realize their profits or losses. - -Exiting a leveraged position applies the profits, losses, and fees from the leveraged position to the collateral and closes the position. If the position was a partial or complete loss, the collateral is burnt away. If the position was profitable, the profits are tabulated and minted back to the creator of the position. - -=== Transaction Format === - -The transaction formats to enter and exit from leveraged positions draw up on the existing transaction format in PegNet 2.0. - -==== Position Entry Format ==== -
-
-{
-  "version": 1,
-  "position": {
-    "address": "FA2xwG47oyWCefAHfYg8r87mWr9JLUXpdZ7PeE8rXEb9xtDvdxbQ",
-    "amount": 1000000000,
-    "type": "pXBT"
-    "leverage": 2
-  }
-}
-
-
- -{| class="wikitable" -|- style="font-weight:bold;" -! Field -! Type -! Description -! Validation -! style="font-weight:normal;" | Required -|- -| version -| number -| The protocol version -| -| Y -|- -| position -| object -| The object containing the required information for placing a position -| -| Y -|- -| position.address -| string -| The input address to the leveraged position -| Follows existing validation and FAT-103 signing standard where address is the 0th input -| Y -|- -| position.amount -| number -| The amount of collateral placed into the leveraged trade -| Must be a positive whole number greater than or equal to the per-block open position fee calculated via the OPR of the placement block -| Y -|- -| position.type -| string -| The desired pAsset symbol used in entering a leveraged position -| Must be a valid pAsset symbol. Must be a pAsset enabled for leveraged positions in the current block -| Y -|- -| position.leverage -| number -| The desired leverage for the position, where a negative number represents a short position and a positive position represents a long -| Must be a whole number on the range from -10 to 10 inclusive, excluding zero. -| Y -|} - -For a position entry transaction to be valid, the following criteria must be met: -#All field level validation criteria featured in the above table must be met -#The input address position.address must have properly signed the entry and the signature must be valid via FAT-103 -#The input address position.address must own position.amount of the pAsset position.type in the current block after any conversions or transfers are applied - - -==== Position Exit Format ==== -
-
-{
-  "version": 1,
-  "position": {
-    "close": "66f9bef30e10c867e09d0927f01660cca34d0bc0df859cd73f4acae167ae8fca"
-  }
-}
-
-
- -{| class="wikitable" -|- style="font-weight:bold;" -! Field -! Type -! Description -! Validation -! Required -|- -| version -| number -| The protocol version -| -| Y -|- -| position -| object -| The object containing the required information for placing a position -| -| Y -|- -| position.close -| string -| The entryhash of the position to exit from -| Must be a valid entryhash -| Y -|} - -For a position exit transaction to be valid, the following criteria must be met: -#The entryhash in the position.close field must correspond to a position -#The position corresponding to position.close field must still be open, and must not have been liquidated in a previous block -#The open position's source input address(position.address in the Position Entry) must have validly signed the position exit entry via FAT-103 - -==Rationale== - -=== Fees === -Fees are included as a mechanism to help prevent potential purposeful or accidental abuse of the system by placing large numbers of small positions that may be opened indeterminately, causing a poor cost-benefit scaling for each additional small position. Programmatic trading bots made for traditional exchanges typically place large numbers of small orders. Since fees are flat and fixed, it is optimal to create a smaller number of larger positions. - -=== Fee Burning === -Burning of fees is included as a mechanism in leveraged positions to help conterbalance inflation created by successful positions, which mint back profits to the position creator at the protocol level. This also creates an incentive to open lower numbers of larger positions instead of many small ones to minimize fees. - -=== 1:1 Position To Entryhash Relationship === -Instead of using the existing transaction batch format, this PIP proposes a new key "position" be created under the JSON root of each transaction entry. The purpose of this is to force a 1:1 relationship between opening a position and the resulting entryhash while not interfering with the existing validation of conversions and transfers. This allows positions to be identified uniquely, be checked on, and be cancelled in a succinct way using their entryhash. - -==Reference implementation== - -Implementation in progress, TBD diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki index fe61daf..d126b50 100644 --- a/pip-0017.mediawiki +++ b/pip-0017.mediawiki @@ -48,7 +48,7 @@ The fee for each open position will be $0.001 USD per-block, which is deducted o (EQUATION PLACEHOLDER) - + For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi. @@ -80,6 +80,7 @@ Exiting a leveraged position applies the profits, losses, and fees from the leve The transaction formats to enter and exit from leveraged positions draw up on the existing transaction format in PegNet 2.0. ==== Position Entry Format ==== +
 
 {
   "version": 1,
@@ -91,6 +92,7 @@ The transaction formats to enter and exit from leveraged positions draw up on th
   }
 }
 
+
{| class="wikitable" |- style="font-weight:bold;" @@ -144,6 +146,7 @@ For a position entry transaction to be valid, the following criteria must be met ==== Position Exit Format ==== +
 
 {
   "version": 1,
@@ -152,6 +155,7 @@ For a position entry transaction to be valid, the following criteria must be met
   }
 }
 
+
{| class="wikitable" |- style="font-weight:bold;" @@ -183,7 +187,7 @@ For a position entry transaction to be valid, the following criteria must be met For a position exit transaction to be valid, the following criteria must be met: #The entryhash in the position.close field must correspond to a position #The position corresponding to position.close field must still be open, and must not have been liquidated in a previous block -#The open position's source input address(position.address in the Position Entry entry) must have validly signed the position exit entry via FAT-103 +#The open position's source input address(position.address in the Position Entry) must have validly signed the position exit entry via FAT-103 ==Rationale== From 0960e4de0bf7c571777d3d6edab401f8c02aac2d Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Sun, 9 Aug 2020 20:15:04 -0700 Subject: [PATCH 05/12] Fix unused tag, add protocol version validation requirement --- pip-0017.mediawiki | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki index d126b50..e7e44b8 100644 --- a/pip-0017.mediawiki +++ b/pip-0017.mediawiki @@ -81,7 +81,6 @@ The transaction formats to enter and exit from leveraged positions draw up on th ==== Position Entry Format ====
-
 {
   "version": 1,
   "position": {
@@ -91,7 +90,6 @@ The transaction formats to enter and exit from leveraged positions draw up on th
     "leverage": 2
   }
 }
-
 
{| class="wikitable" @@ -105,7 +103,7 @@ The transaction formats to enter and exit from leveraged positions draw up on th | version | number | The protocol version -| +| Must be set to 1 | Y |- | position @@ -147,14 +145,12 @@ For a position entry transaction to be valid, the following criteria must be met ==== Position Exit Format ====
-
 {
   "version": 1,
   "position": {
     "close": "66f9bef30e10c867e09d0927f01660cca34d0bc0df859cd73f4acae167ae8fca"
   }
 }
-
 
{| class="wikitable" @@ -168,7 +164,7 @@ For a position entry transaction to be valid, the following criteria must be met | version | number | The protocol version -| +| Must be set to 1 | Y |- | position From 3472fa731007992b8f08376f5054c98316ed7fd8 Mon Sep 17 00:00:00 2001 From: Devon Katz Date: Mon, 10 Aug 2020 13:19:03 -0700 Subject: [PATCH 06/12] Revise transaction format text, point towards rationale section Make key "position" exclusive with "transactions" --- pip-0017.mediawiki | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki index e7e44b8..0e2f355 100644 --- a/pip-0017.mediawiki +++ b/pip-0017.mediawiki @@ -77,9 +77,9 @@ Exiting a leveraged position applies the profits, losses, and fees from the leve === Transaction Format === -The transaction formats to enter and exit from leveraged positions draw up on the existing transaction format in PegNet 2.0. +The transaction datastructures format to enter and exit from leveraged positions are differentiated from the existing transaction/conversion datastructure format in PegNet using a new object under the root key "position". See "1:1 Position To Entryhash Relationship" in the Rationale section for more details. -==== Position Entry Format ==== +==== Position Entry Transaction Format ====
 {
   "version": 1,
@@ -108,7 +108,7 @@ The transaction formats to enter and exit from leveraged positions draw up on th
 |-
 | position
 | object
-| The object containing the required information for placing a position
+| The object containing the required information for placing a position. The key "position" and the key "transactions" may not coexist in the same entry.
 | 
 | Y
 |-
@@ -143,7 +143,7 @@ For a position entry transaction to be valid, the following criteria must be met
 #The input address position.address must own position.amount of the pAsset position.type in the current block after any conversions or transfers are applied
 
 
-==== Position Exit Format ====
+==== Position Exit Transaction Format ====
 
 {
   "version": 1,
@@ -169,7 +169,7 @@ For a position entry transaction to be valid, the following criteria must be met
 |-
 | position
 | object
-| The object containing the required information for placing a position
+| The object containing the required information for placing a position. The key "position" and the key "transactions" may not coexist in the same entry.
 | 
 | Y
 |-
@@ -198,4 +198,4 @@ Instead of using the existing transaction batch format, this PIP proposes a new
 
 ==Reference implementation== 
 
-Implementation in progress, TBD
+Implementation in progress, TBD. Preliminary activation height on the Factom Mainnet is 

From 2f40b44bad9a66006d48d8c85f53bd9b95fe5d79 Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 13:27:44 -0700
Subject: [PATCH 07/12] Move entry & exit section to below fees section

---
 pip-0017.mediawiki | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index 0e2f355..edc3950 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -52,6 +52,13 @@ The fee for each open position will be $0.001 USD per-block, which is deducted o
 
 For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi.
 
+=== Entering & Exiting A Leveraged Position ===
+To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction.
+
+Once the transaction is submitted and picked up by the daemon, the collateral is deducted from their address in the target pAsset and removed from circulation until the trade is exited. The user may exit the position at any time before a liquidation event occurs to realize their profits or losses.
+
+Exiting a leveraged position applies the profits, losses, and fees from the leveraged position to the collateral and closes the position. If the position was a partial or complete loss, the collateral is burnt away. If the position was profitable, the profits are tabulated and minted back to the creator of the position.
+
 === Determining Liquidation Status ===
 Each block the daemon will determine the liquidation status of each open position based on:
 #The collateral amount
@@ -68,13 +75,6 @@ Liquidation of a position occurs when the unrealized losses, including fees of t
 (EQUATION PLACEHOLDER)
 
 
-=== Entering & Exiting A Leveraged Position ===
-To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction.
-
-Once the transaction is submitted and picked up by the daemon, the collateral is deducted from their address in the target pAsset and removed from circulation until the trade is exited. The user may exit the position at any time before a liquidation event occurs to realize their profits or losses.
-
-Exiting a leveraged position applies the profits, losses, and fees from the leveraged position to the collateral and closes the position. If the position was a partial or complete loss, the collateral is burnt away. If the position was profitable, the profits are tabulated and minted back to the creator of the position.
-
 === Transaction Format ===
 
 The transaction datastructures format to enter and exit from leveraged positions are differentiated from the existing transaction/conversion datastructure format in PegNet using a new object under the root key "position". See "1:1 Position To Entryhash Relationship" in the Rationale section for more details.

From 9185f76720f8b06379e28aa1be2f39df98a3ed62 Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 13:41:10 -0700
Subject: [PATCH 08/12] Add competitive fee example from Kraken

---
 pip-0017.mediawiki | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index edc3950..9578532 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -52,6 +52,8 @@ The fee for each open position will be $0.001 USD per-block, which is deducted o
 
 For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi.
 
+With a $0.001 fee per block, this makes borrowing margin cheaper on Pegnet than on Kraken which has a 0.01% per 4 hour margin fee, for example, at the point you are borrowing $250 or more. At that point the fee on Pegnet is cheaper for margin borrowing, and this isnt including the trading fees themselves or margin open fee on kraken, only ongoing margin rollover costs.
+
 === Entering & Exiting A Leveraged Position ===
 To enter a leveraged position, a user first holds an amount of the target asset they wish to short or long against the target asset's USD price. To enter into the position, they create and submit a signed transaction entry using their address with the details of the position they wish to enter, including the pAsset type, collateral amount, leverage multiplier, and direction.
 

From 78f20a16a8695a8c19eca2ff00e6df2e1224e254 Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 13:46:13 -0700
Subject: [PATCH 09/12] remove "used for arbitrage"

---
 pip-0017.mediawiki | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index 9578532..fb94b3a 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -22,7 +22,7 @@ Taking a leveraged position in PegNet is similar to any other conversion in PegN
 
 ==Motivation==
 
-As a DeFi asset conversion network that mints it’s own tokens used for arbitrage, PegNet is in a unique position to provide leveraged positions to market participants without requiring 3rd parties, counterparties or lending fees. Traditional approaches to leverage vary by market, but all require some combination of borrowing other people's money to leverage position size or sell their assets, a counterparty, and managers maintaining a position for a fee.
+As a DeFi asset conversion network that mints it’s own tokens, PegNet is in a unique position to provide leveraged positions to market participants without requiring 3rd parties, counterparties or lending fees. Traditional approaches to leverage vary by market, but all require some combination of borrowing other people's money to leverage position size or sell their assets, a counterparty, and managers maintaining a position for a fee.
 
 As it exists today, margin trading cryptocurrency and other assets carries regulatory burden, counterparty risk, and a variety of fees. These burdens gravitate around centralized parties, such as exchanges, as they represent central points of failure. They are responsible for paying out profits and taking losses from traders, for maintaining custody of funds, from protecting positions from a variety of attack vectors, and for keeping up with regulatory oversight of their customers without leaking customer data. All of these duties increase risks, fees, and regulatory burdens. PegNet is uniquely suited to solve each of these problems.
 

From 1f0a6c890b2675816e08ea729b4ec4c266fdf50e Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 13:50:51 -0700
Subject: [PATCH 10/12] Add preliminary activation height

---
 pip-0017.mediawiki | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index fb94b3a..56215e7 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -200,4 +200,4 @@ Instead of using the existing transaction batch format, this PIP proposes a new
 
 ==Reference implementation== 
 
-Implementation in progress, TBD. Preliminary activation height on the Factom Mainnet is 
+Implementation in progress, TBD. Preliminary activation height on the Factom Mainnet is 270491, approximately November 10th 2020. 

From 18d55fcc5adf28b9958da4e2cb6d1e2cc2489c25 Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 15:16:43 -0700
Subject: [PATCH 11/12] Add fee and profit calculation equations

---
 pip-0017.mediawiki | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index 56215e7..aaebf9a 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -46,8 +46,9 @@ To help protect PegNet from a denial of service attack, a flat fee structure is
 
 The fee for each open position will be $0.001 USD per-block, which is deducted on an ongoing basis from the collateral of the position until it is either manually closed or automatically liquidated. The USD fee amount to deduct from the open position is calculated based on the OPR derived rate for the block of the placement asset. Fees collected are burnt from the protocol entirely.
 
+To calculate the per-block fee for an open position:
 
-(EQUATION PLACEHOLDER)
+Block Fee = 0.001 ÷ Block OPR Price
 
 
 For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi.
@@ -63,18 +64,22 @@ Exiting a leveraged position applies the profits, losses, and fees from the leve
 
 === Determining Liquidation Status ===
 Each block the daemon will determine the liquidation status of each open position based on:
-#The collateral amount
-#The placement price
-#The placement block
-#The leverage
-#The current price
-#The current block
-#Total fees
+*The collateral amount
+*The entry OPR price
+*The leverage
+*The current OPR price
+*Cumulative fees
 
 Liquidation of a position occurs when the unrealized losses, including fees of the trade, become greater than or equal to the total collateral amount. Until those conditions are met, the trade may be manually exited by the user at any time.
 
+For a long trade, the profit is calculated as:
 
-(EQUATION PLACEHOLDER)
+Profit = ((Collateral × Leverage × Current OPR Price ÷ Entry OPR Price) - (Collateral × Leverage)) - Cumulative Fees
+
+
+For a short trade, the profit is calculated as:
+
+Profit = ((Collateral × Leverage) - (Margin × Leverage × Current OPR Price ÷ Entry OPR Price)) - Cumulative Fees
 
 
 === Transaction Format ===

From 4d7919ce79a89d887e920a5445940c4afec6da15 Mon Sep 17 00:00:00 2001
From: Devon Katz 
Date: Mon, 10 Aug 2020 15:17:58 -0700
Subject: [PATCH 12/12] Switch equations to preformatted text

---
 pip-0017.mediawiki | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pip-0017.mediawiki b/pip-0017.mediawiki
index aaebf9a..cdfdc0a 100644
--- a/pip-0017.mediawiki
+++ b/pip-0017.mediawiki
@@ -47,9 +47,9 @@ To help protect PegNet from a denial of service attack, a flat fee structure is
 The fee for each open position will be $0.001 USD per-block, which is deducted on an ongoing basis from the collateral of the position until it is either manually closed or automatically liquidated. The USD fee amount to deduct from the open position is calculated based on the OPR derived rate for the block of the placement asset. Fees collected are burnt from the protocol entirely.
 
 To calculate the per-block fee for an open position:
-
+
 Block Fee = 0.001 ÷ Block OPR Price
-
+
For example, for a leveraged position in pXBT, if the current USD/XBT price is 11,668 USD/XBT as determined by OPR for the block, the fee calculated for the position for the block would be 9 satoshi. @@ -73,14 +73,14 @@ Each block the daemon will determine the liquidation status of each open positio Liquidation of a position occurs when the unrealized losses, including fees of the trade, become greater than or equal to the total collateral amount. Until those conditions are met, the trade may be manually exited by the user at any time. For a long trade, the profit is calculated as: - +
 Profit = ((Collateral × Leverage × Current OPR Price ÷ Entry OPR Price) - (Collateral × Leverage)) - Cumulative Fees
-
+
For a short trade, the profit is calculated as: - +
 Profit = ((Collateral × Leverage) - (Margin × Leverage × Current OPR Price ÷ Entry OPR Price)) - Cumulative Fees
-
+
=== Transaction Format ===