{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-366/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-366.md","frontmatter":{"sip":366,"sccp":null,"title":"Asynchronous Delegation","network":"Ethereum, Optimism, Base & Arbitrum","author":"Jared Borders (@jaredborders), kaleb (@kaleb-keny)","type":"Governance","proposal":"https://snapshot.org/#/snxgov.eth/proposal/0xfff673d535369488fed83333f397725ff36a0e45adcf9c2831e628f9e8bc4595","implementor":null,"release":null,"created":"2024-03-04T00:00:00.000Z","updated":null,"status":"Rejected"},"html":"<!--You can leave these HTML comments in your merged SIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new SIPs. Note that an SIP number will be assigned by an editor. When opening a pull request to submit your SIP, please use an abbreviated title in the filename, `sip-draft_title_abbrev.md`. The title should be 44 characters or less.-->\n<h2 id=\"simple-summary\" style=\"position:relative;\"><a href=\"#simple-summary\" aria-label=\"simple summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Simple Summary</h2>\n<!--\"If you can't explain it simply, you don't understand it well enough.\" Simply describe the outcome the proposed changes intends to achieve. This should be non-technical and accessible to a casual community member.-->\n<p>This SIP proposes adding functionality such that markets can require liquidity providers to first declare an intent to change the amount of collateral delegated and then process it after a configurable delay.</p>\n<h2 id=\"abstract\" style=\"position:relative;\"><a href=\"#abstract\" aria-label=\"abstract permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Abstract</h2>\n<!--A short (~200 word) description of the proposed change, the abstract should clearly describe the proposed change. This is what *will* be done if the SIP is implemented, not *why* it should be done or *how* it will be done. If the SIP proposes deploying a new contract, write, \"we propose to deploy a new contract that will do x\".-->\n<p>As an improvement over the Minimum Collateral Delegation Duration (per <a href=\"https://sips.synthetix.io/sips/sip-320/\">SIP-320</a>), this SIP proposes to replace the concept of a minimum delegation time with a pattern in which liquidity providers call a <code>declareIntentToDelegateCollateral</code> function, wait a <code>delegateCollateralDelay</code> or <code>undelegateCollateralDelay</code> (depending on whether their delegated collateral is increasing or decreasing), and then have anyone call a <code>processIntentToDelegateCollateral</code> function within a <code>delegateCollateralWindow</code> or <code>undelegateCollateralWindow</code> to apply the change.</p>\n<h2 id=\"motivation\" style=\"position:relative;\"><a href=\"#motivation\" aria-label=\"motivation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Motivation</h2>\n<!--This is the problem statement. This is the *why* of the SIP. It should clearly explain *why* the current state of the protocol is inadequate.  It is critical that you explain *why* the change is needed, if the SIP proposes changing how something is calculated, you must address *why* the current calculation is inaccurate or wrong. This is not the place to describe how the SIP will address the issue!-->\n<p>This functionality allows markets to prevent adversarial dynamics between liquidity providers. For example, if a liquidity provider anticipates a large increase or decrease in debt to a pool (without this feature enabled), they could quickly exit or enter the pool such that other liquidity providers assume the change. This is effectively a concern of \"just-in-time liquidity.\"</p>\n<p>Note that this functionality would be implemented in addition to the Core System Precautionary Security Features (per <a href=\"https://sips.synthetix.io/sips/sip-316/\">SIP-316</a>).</p>\n<h2 id=\"rationale\" style=\"position:relative;\"><a href=\"#rationale\" aria-label=\"rationale permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Rationale</h2>\n<!--This is where you explain the reasoning behind how you propose to solve the problem. Why did you propose to implement the change in this way, what were the considerations and trade-offs. The rationale fleshes out what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->\n<p>It would be possible to have governance or pool owners configure these values rather than having market builders decide on the configuration, but this would complicate liquidity provisioning for all integrators, as it makes delegation non-atomic. Further, because the opportunities of adversarial liquidity provisioning are specific to a market's implementations, it makes sense to configure these values in this way.</p>\n<h2 id=\"technical-specification\" style=\"position:relative;\"><a href=\"#technical-specification\" aria-label=\"technical specification permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Technical Specification</h2>\n<!--The technical specification should outline the public API of the changes proposed. That is, changes to any of the interfaces Synthetix currently exposes or the creations of new ones.-->\n<h3 id=\"marketmanagermodule--imarketmanagermodule\" style=\"position:relative;\"><a href=\"#marketmanagermodule--imarketmanagermodule\" aria-label=\"marketmanagermodule  imarketmanagermodule permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>MarketManagerModule</code> &#x26; <code>IMarketManagerModule</code></h3>\n<h4 id=\"configuration\" style=\"position:relative;\"><a href=\"#configuration\" aria-label=\"configuration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configuration</h4>\n<p>Replace logic and state associated with the minimum delegation time by omitting <code>minDelegationTime</code> and its respective setter method (<code>setMarketMinDelegateTime</code>) with the following logic and state associated with the delegation delay and window functionality:</p>\n<ol>\n<li><code>unit256 undelegateCollateralDelay</code> and its respective setter method <code>setUndelegateCollateralDelay</code></li>\n<li><code>unit256 undelegateCollateralWindow</code> and its respective setter method <code>setUndelegateCollateralWindow</code></li>\n<li><code>unit256 delegateCollateralDelay</code> and its respective setter method <code>setDelegateCollateralDelay</code></li>\n<li><code>unit256 delegateCollateralWindow</code> and its respective setter method <code>setDelegateCollateralWindow</code></li>\n</ol>\n<p>All of these values should be configurable only by the market.</p>\n<h3 id=\"vault--ivault\" style=\"position:relative;\"><a href=\"#vault--ivault\" aria-label=\"vault  ivault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Vault</code> &#x26; <code>IVault</code></h3>\n<h4 id=\"intents\" style=\"position:relative;\"><a href=\"#intents\" aria-label=\"intents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Intents</h4>\n<p>Define the following object (i.e., <code>struct</code>) that defines all aspects of an <strong>intent</strong> to <em>delegate</em> or <em>undelegate</em> collateral. This object should closely resemble the following <code>DelegateCollateralIntent</code> object:</p>\n<pre><code class=\"language-solidity\">/**\n * Intent Lifecycle:\n *\n *          |&#x3C;---- Delay ---->|&#x3C;-- Processing Window -->|\n * Time ----|-----------------|-------------------------|---->\n *          ^                 ^                         ^\n *          |                 |                         |\n *  declarationTime    processingStartTime    processingEndTime\n *\n * Key:\n * - declarationTime: Timestamp at which the intent is declared.\n * - processingStartTime: Timestamp from which the intent can start being processed.\n * - processingEndTime: Timestamp after which the intent cannot be processed.\n *\n * The intent can be processed only between processingStartTime and processingEndTime.\n */\nstruct DelegateCollateralIntent {\n    /**\n     * @notice An incrementing nonce to ensure the\n     * uniqueness of the intent and prevent replay attacks\n     */\n    uint256 nonce;\n    /**\n     * @notice The ID of the pool for which the account has an\n     * outstanding intent to delegate a new amount of collateral to\n     */\n    uint128 poolId;\n    /**\n     * @notice The address of the collateral type that the account has an\n     * outstanding intent to delegate a new amount of\n     */\n    address collateralType;\n    /**\n     * @notice The amount of collateral that the account has an\n     * outstanding intent to delegate a new amount of to the pool,\n     * denominated with 18 decimals of precision\n     */\n    uint256 collateralAmountD18;\n    /**\n     * @notice The intended amount of leverage associated with the new\n     * amount of collateral that the account has an outstanding intent\n     * to delegate to the pool\n     * @dev The system currently only supports 1x leverage\n     */\n    uint256 leverage;\n    /**\n     * @notice The timestamp at which the intent was declared\n     */\n    uint256 declarationTime;\n    /**\n     * @notice The timestamp before which the intent cannot be processed\n     * @dev dependent on\n     * {VaultModule.undelegateCollateralDelay} or\n     * {VaultModule.delegateCollateralDelay}\n     */\n    uint256 processingStartTime;\n    /**\n     * @notice The timestamp after which the intent cannot be processed\n     * (i.e., intent expiry)\n     * @dev dependent on\n     * {VaultModule.undelegateCollateralWindow} or\n     * {VaultModule.delegateCollateralWindow}\n     */\n    uint256 processingEndTime;\n}\n</code></pre>\n<h4 id=\"storage\" style=\"position:relative;\"><a href=\"#storage\" aria-label=\"storage permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Storage</h4>\n<p>Add the following <code>intentNoncesByAccount</code> field to the <code>Data</code> <code>struct</code> to store an array of all outstanding intent nonces for a given account in a mapping:</p>\n<pre><code class=\"language-solidity\">mapping(uint128 accountId => uint256[] nonces) intentNoncesByAccount;\n</code></pre>\n<p>Add the following <code>intentByNonce</code> field to the <code>Data</code> <code>struct</code> to map an intent nonce to a <code>DelegateCollateralIntent</code> object:</p>\n<pre><code class=\"language-solidity\">mapping(uint256 nonce => DelegateCollateralIntent intent) intentByNonce;\n</code></pre>\n<p>Add the following <code>delegateCollateralCachePerAccountPerPool</code> and <code>delegateCollateralCachePerAccount</code> fields to the <code>Data</code> <code>struct</code> to store the amount of collateral that is currently declared to be delegated for a given account due to all outstanding <code>DelegateCollateralIntent</code> intents:</p>\n<pre><code class=\"language-solidity\">mapping(uint128 accountId => mapping(uint128 poolId => uint256 amount) amountPerPool) delegateCollateralCachePerAccountPerPool;\nmapping(uint128 accountId => uint256 amount) delegateCollateralCachePerAccount;\n</code></pre>\n<p>Add the following <code>undelegateCollateralCachePerAccountPerPool</code> and <code>undelegateCollateralCachePerAccount</code> fields to the <code>Data</code> <code>struct</code> to store the amount of collateral that is currently declared to be undelegated for a given account due to all outstanding <code>DelegateCollateralIntent</code> intents:</p>\n<pre><code class=\"language-solidity\">mapping(uint128 accountId => mapping(uint128 poolId => uint256 amount) amountPerPool) undelegateCollateralCachePerAccountPerPool;\nmapping(uint128 accountId => uint256 amount) undelegateCollateralCachePerAccount;\n</code></pre>\n<blockquote>\n<p>The proposed approach of using several fields to store granular intent details per account, rather than a single field mapping of an <code>accountId</code> to <code>DelegateCollateralIntent</code> objects, is more effective. It avoids conflicts that would occur when <code>DelegateCollateralIntent</code> objects are updated, as discussed in the article <a href=\"https://medium.com/@0xFluffyBeard/migrating-the-eip-2535-diamond-storage-layout-cb28b9c47e71\">here</a>. Storing intent nonces in an array allows for far less complicated updates to the <code>DelegateCollateralIntent</code> object. Moreover, detailed accounting is necessary to avoid errors caused by deliberately malicious declarations of intent.</p>\n</blockquote>\n<h4 id=\"nonce-management\" style=\"position:relative;\"><a href=\"#nonce-management\" aria-label=\"nonce management permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Nonce Management</h4>\n<p>Implement a rudimentary nonce management system to ensure the uniqueness of each intent declaration. This system should track the current nonce that will be assigned to the next declared intent for a given account. The nonce should be incremented after each declaration. The system should also allow for the invalidation of nonces that can be initiated by the account owner or by the system in the event of account liquidation.</p>\n<h3 id=\"vaultmodule--ivaultmodule\" style=\"position:relative;\"><a href=\"#vaultmodule--ivaultmodule\" aria-label=\"vaultmodule  ivaultmodule permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>VaultModule</code> &#x26; <code>IVaultModule</code></h3>\n<h4 id=\"events\" style=\"position:relative;\"><a href=\"#events\" aria-label=\"events permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Events</h4>\n<p>Add the following event to emit when an intent to delegate a new amount of collateral is successfully declared:</p>\n<pre><code class=\"language-solidity\">DelegateCollateralIntentDeclared(\n    uint128 accountId,\n    uint256 nonce,\n    uint128 poolId,\n    address collateralType,\n    uint256 collateralAmountD18,\n    uint256 leverage\n);\n</code></pre>\n<p>Add the following event to emit when an intent to delegate a new amount of collateral is successfully processed:</p>\n<pre><code class=\"language-solidity\">DelegateCollateralIntentProcessed(\n    uint128 accountId,\n    uint256 nonce,\n    uint128 poolId,\n    address collateralType,\n    uint256 collateralAmountD18,\n    uint256 leverage\n);\n</code></pre>\n<h4 id=\"submitting-intents\" style=\"position:relative;\"><a href=\"#submitting-intents\" aria-label=\"submitting intents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Submitting Intents</h4>\n<p>Add the following function to <strong>declare</strong> and record an intent to delegate a new amount of collateral (refer to the NatSpec annotations for further implementation guidance):</p>\n<pre><code class=\"language-solidity\">/**\n * @notice Declare an intent to delegate a new amount of collateral\n * @dev The {msg.sender} is not necessarily the account owner but it\n * must be authorized to act on behalf of the account\n * @param accountId The ID of the account intending to delegate a new\n * amount of collateral\n * @param poolId The ID of the pool to which the account intends to\n * delegate a new amount of collateral\n * @param collateralType The address of the collateral type that the\n * account intends to delegate\n * @param newCollateralAmountD18 The new amount of collateral that\n * the account intends to delegate, denominated with 18 decimals of\n * precision\n * @param leverage The new intended leverage used in the position\n */\nfunction declareIntentToDelegateCollateral(\n    uint128 accountId,\n    uint128 poolId,\n    address collateralType,\n    uint256 newCollateralAmountD18,\n    uint256 leverage\n) public;\n</code></pre>\n<p>The <code>declareIntentToDelegateCollateral</code> function should, at minimum, satisfy the following requirements:</p>\n<ol>\n<li>Ensure the caller is authorized to represent the account.</li>\n<li>Verify the account holds enough collateral to execute the intent.</li>\n<li>Check the validity of the collateral amount to be delegated, respecting the caches that track outstanding intents to delegate or undelegate collateral.</li>\n<li>Update the appropriate caches to reflect the collateral amount declared in the intent for the identified account and pool.</li>\n<li>Update the <code>intentNoncesByAccount</code> to include the new intent nonce associated with the account.</li>\n<li>Update the <code>intentByNonce</code> to represent the newly declared intent using the specific nonce.</li>\n<li>Emit a <code>DelegateCollateralIntentDeclared</code> event.</li>\n</ol>\n<h4 id=\"processing-intents\" style=\"position:relative;\"><a href=\"#processing-intents\" aria-label=\"processing intents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Processing Intents</h4>\n<p>Add the following functions to <strong>process</strong> outstanding intent(s) to delegate a new amount of collateral (refer to the NatSpec annotations for further implementation guidance):</p>\n<pre><code class=\"language-solidity\">/**\n * @notice Attempt to process an outstanding intent to delegate a\n * new amount of collateral\n * @dev The {msg.sender} can be any address\n * @param accountId The ID of the account for which the outstanding\n * intent to delegate a new amount of collateral is being processed\n * @param poolId The ID of the pool for which the intent of the account\n * to delegate a new amount of collateral is being processed\n * @param collateralType The address of the collateral type that the\n * account has an outstanding intent to delegate a new amount of\n */\nfunction processIntentToDelegateCollateral(\n    uint128 accountId,\n    uint128 poolId,\n    address collateralType\n) public;\n</code></pre>\n<p>The <code>processIntentToDelegateCollateral</code> function should, at minimum, satisfy the following requirements:</p>\n<ol>\n<li>Allow anyone to call it without requiring permissions, enabling the processing of any open intent.</li>\n<li>Verify the existence of the specified intent for the given account, pool, and type of collateral.</li>\n<li>Ensure the intent's submission timestamp is greater than the current timestamp plus the applicable delay.</li>\n<li>Ensure the intent's submission timestamp does not surpass the current timestamp plus both the delay and window period.</li>\n<li>Check that processing the intent won't cause the collateralization ratio to fall below the required issuance ratio.</li>\n<li>Validate that the collateral amount to be processed is within the bounds defined by the appropriate caches that track outstanding intents to delegate or undelegate collateral.</li>\n<li>Update the appropriate caches to reflect the collateral amount processed in the intent for the identified account and pool.</li>\n<li>Delete the intent nonce from <code>intentNoncesByAccount</code> for the involved account.</li>\n<li>Delete the intent from <code>intentByNonce</code> using the specific nonce.</li>\n<li>Update the amount of collateral delegated to the pool according to the intent.</li>\n<li>Emit a <code>DelegateCollateralIntentProcessed</code> event upon successful processing.</li>\n<li>Execute steps 2 to 11 for every intent ready for processing for the mentioned account, pool, and collateral type.</li>\n</ol>\n<blockquote>\n<p>The order by which the intents are processed should not matter so long as the cache mappings are properly maintained.</p>\n</blockquote>\n<pre><code class=\"language-solidity\">function processIntentToDelegateCollateral(\n    uint128 accountId,\n    uint256[] intentNonces\n) public;\n</code></pre>\n<p>The overloaded <code>processIntentToDelegateCollateral</code> function should, at minimum, satisfy the following requirements:</p>\n<ol>\n<li>Follow the same requirements (steps 1 to 11) originally outlined for the <code>processIntentToDelegateCollateral</code> function that processes specific intents queued for an account, pool, and collateral type.</li>\n<li>Only process intents that are included in the <code>intentNonces</code> array.</li>\n<li>Remove intents with nonces included in the <code>intentNonces</code> array from the <code>intentNoncesByAccount</code> mapping if they are expired or processed.</li>\n</ol>\n<h5 id=\"edge-cases\" style=\"position:relative;\"><a href=\"#edge-cases\" aria-label=\"edge cases permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Edge Cases</h5>\n<p>If an attempt is made to process an intent but constraints such as (but not limited to) issuance ratio restrictions, debt fluctuations, or partial account liquidations prevent the full amount of collateral from being processed, then the maximum permissible amount of collateral should be determined and processed as allowed.</p>\n<h4 id=\"delegating-collateral-entry-point\" style=\"position:relative;\"><a href=\"#delegating-collateral-entry-point\" aria-label=\"delegating collateral entry point permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Delegating Collateral Entry Point</h4>\n<p>The <code>delegateCollateral</code> function is designed to invoke <code>requestDelegateCollateral</code> and/or <code>processDelegateCollateral</code> as needed, ensuring compatibility with the pre-existing <code>delegateCollateral</code> function. Initially, it aims to declare an intent to delegate a new amount of collateral based on the provided parameters. Subsequently, it seeks to process any existing intents linked to the specified account, pool, and type of collateral.</p>\n<p>If an account has a ready-to-process intent but does not wish to declare a new one, it should directly use <code>processDelegateCollateral</code>.</p>\n<p>Conversely, if an account has no pending intents but wishes to declare a new one, <code>requestDelegateCollateral</code> should be utilized directly.</p>\n<h3 id=\"liquidationmodule--iliquidationmodule\" style=\"position:relative;\"><a href=\"#liquidationmodule--iliquidationmodule\" aria-label=\"liquidationmodule  iliquidationmodule permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>LiquidationModule</code> &#x26; <code>ILiquidationModule</code></h3>\n<h4 id=\"account-liquidation\" style=\"position:relative;\"><a href=\"#account-liquidation\" aria-label=\"account liquidation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Account Liquidation</h4>\n<p>In the event an account is liquidated, all outstanding intents to delegate collateral should be canceled/forcibly expired. This can be achieved by batch invalidating all outstanding intent nonces associated with the account within the <code>liquidate</code> function.</p>\n<h3 id=\"collateralmodule--icollateralmodule\" style=\"position:relative;\"><a href=\"#collateralmodule--icollateralmodule\" aria-label=\"collateralmodule  icollateralmodule permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>CollateralModule</code> &#x26; <code>ICollateralModule</code></h3>\n<h4 id=\"withdrawal-restrictions\" style=\"position:relative;\"><a href=\"#withdrawal-restrictions\" aria-label=\"withdrawal restrictions permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Withdrawal Restrictions</h4>\n<p>The <code>CollateralModule</code> should be updated to ensure that any collateral balance intended to be delegated is not available for withdrawal until the intent is processed (i.e. executed or expired). This can be achieved by adding a check to the <code>withdraw</code> function to ensure that the account has sufficient collateral available to withdraw after accounting for any outstanding intents to delegate collateral.</p>\n<h4 id=\"available-collateral\" style=\"position:relative;\"><a href=\"#available-collateral\" aria-label=\"available collateral permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Available Collateral</h4>\n<p>The <code>CollateralModule</code> should also be updated to ensure that the available collateral balance for an account is calculated correctly, accounting for any outstanding intents to delegate collateral. This can be achieved by adding logic to the <code>getAccountAvailableCollateral</code> function to deduct the amount of collateral declared in any outstanding intents to delegate collateral. This information can be obtained from the <code>delegateCollateralCachePerAccount</code> mapping.</p>\n<h3 id=\"test-cases\" style=\"position:relative;\"><a href=\"#test-cases\" aria-label=\"test cases permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Test Cases</h3>\n<!--Test cases for an implementation are mandatory for SIPs but can be included with the implementation..-->\n<p>Relevant tests will be developed during implementation.</p>\n<h3 id=\"configurable-values-via-sccp\" style=\"position:relative;\"><a href=\"#configurable-values-via-sccp\" aria-label=\"configurable values via sccp permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configurable Values (Via SCCP)</h3>\n<!--Please list all values configurable via SCCP under this implementation.-->\n<p>N/A</p>\n<h2 id=\"copyright\" style=\"position:relative;\"><a href=\"#copyright\" aria-label=\"copyright permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Copyright</h2>\n<p>Copyright and related rights waived via <a href=\"https://creativecommons.org/publicdomain/zero/1.0/\">CC0</a>.</p>"}},"pageContext":{"id":"239c3462-4284-5edb-88a5-218705135667","frontmatter__sip":366,"__params":{"frontmatter__sip":"366"}}},"staticQueryHashes":[]}