---
tags: Spec-Revenue-Sharing
---
# Forced Take-out Spec POC
## Visualization
### Mapping Legend
Cylinder: Entity
Orange Diamond: Behavioral Action
Red Square: Policy
Blue Circle: Mechanism
Colored Arrow: Message Passing with Specific Message
Dotted Arrow: Optional Call (Depends on Implementation)
### Message Legend
beige: ForceUnstakeMessage -> {'currency_amount': <class 'int'>, 'pool_id': <class 'str'>, 'stream_id': <class 'str'>, 'called_at': <class 'int'>, 'called_by': <class 'str'>}
cyan: CurrencyStakingMessage -> {'currency_amount': <class 'int'>, 'pool_id': <class 'str'>, 'stream_id': <class 'str'>}
blue: CurrencyAmountMessage -> {'delegator_id': <class 'str'>, 'pool_id': <class 'str'>, 'currency_amount': <class 'int'>}
<div style="width: 1311pt; height: 548pt;"><svg width="1311pt" height="548pt" viewBox="0.00 0.00 1310.98 548.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="width: 100%; height: 100%;">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 544)">
<title>Trigger Force Unstake</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-544 1306.98,-544 1306.98,4 -4,4"></polygon>
<!-- Delegator -->
<g id="node1" class="node">
<title>Delegator</title>
<path fill="none" stroke="black" d="M901.39,-536.73C901.39,-538.53 885.26,-540 865.39,-540 845.53,-540 829.39,-538.53 829.39,-536.73 829.39,-536.73 829.39,-507.27 829.39,-507.27 829.39,-505.47 845.53,-504 865.39,-504 885.26,-504 901.39,-505.47 901.39,-507.27 901.39,-507.27 901.39,-536.73 901.39,-536.73"></path>
<path fill="none" stroke="black" d="M901.39,-536.73C901.39,-534.92 885.26,-533.45 865.39,-533.45 845.53,-533.45 829.39,-534.92 829.39,-536.73"></path>
<text text-anchor="middle" x="865.39" y="-518.3" font-family="Times,serif" font-size="14.00">Delegator</text>
</g>
<!-- Trigger Force Unstake -->
<g id="node2" class="node">
<title>Trigger Force Unstake</title>
<polygon fill="orange" stroke="orange" points="865.39,-468 734.01,-450 865.39,-432 996.77,-450 865.39,-468"></polygon>
<text text-anchor="middle" x="865.39" y="-446.3" font-family="Times,serif" font-size="14.00">Trigger Force Unstake</text>
</g>
<!-- Delegator->Trigger Force Unstake -->
<g id="edge1" class="edge">
<title>Delegator->Trigger Force Unstake</title>
<path fill="none" stroke="black" d="M865.39,-503.7C865.39,-495.98 865.39,-486.71 865.39,-478.11"></path>
<polygon fill="black" stroke="black" points="868.89,-478.1 865.39,-468.1 861.89,-478.1 868.89,-478.1"></polygon>
</g>
<!-- Check Force Unstake -->
<g id="node3" class="node">
<title>Check Force Unstake</title>
<polygon fill="red" stroke="red" points="933.89,-396 796.89,-396 796.89,-360 933.89,-360 933.89,-396"></polygon>
<text text-anchor="middle" x="865.39" y="-374.3" font-family="Times,serif" font-size="14.00">Check Force Unstake</text>
</g>
<!-- Trigger Force Unstake->Check Force Unstake -->
<g id="edge2" class="edge">
<title>Trigger Force Unstake->Check Force Unstake</title>
<path fill="none" stroke="beige" d="M865.39,-431.7C865.39,-423.98 865.39,-414.71 865.39,-406.11"></path>
<polygon fill="beige" stroke="beige" points="868.89,-406.1 865.39,-396.1 861.89,-406.1 868.89,-406.1"></polygon>
</g>
<!-- Decrease Stake Policy -->
<g id="node4" class="node">
<title>Decrease Stake Policy</title>
<polygon fill="red" stroke="red" points="936.39,-324 794.39,-324 794.39,-288 936.39,-288 936.39,-324"></polygon>
<text text-anchor="middle" x="865.39" y="-302.3" font-family="Times,serif" font-size="14.00">Decrease Stake Policy</text>
</g>
<!-- Check Force Unstake->Decrease Stake Policy -->
<g id="edge3" class="edge">
<title>Check Force Unstake->Decrease Stake Policy</title>
<path fill="none" stroke="cyan" stroke-dasharray="5,2" d="M865.39,-359.7C865.39,-351.98 865.39,-342.71 865.39,-334.11"></path>
<polygon fill="cyan" stroke="cyan" points="868.89,-334.1 865.39,-324.1 861.89,-334.1 868.89,-334.1"></polygon>
</g>
<!-- Diverted Unstake -->
<g id="node5" class="node">
<title>Diverted Unstake</title>
<ellipse fill="blue" stroke="blue" cx="592.39" cy="-234" rx="74.99" ry="18"></ellipse>
<text text-anchor="middle" x="592.39" y="-230.3" font-family="Times,serif" font-size="14.00">Diverted Unstake</text>
</g>
<!-- Decrease Stake Policy->Diverted Unstake -->
<g id="edge4" class="edge">
<title>Decrease Stake Policy->Diverted Unstake</title>
<path fill="none" stroke="cyan" stroke-dasharray="5,2" d="M798.96,-287.97C753.86,-276.4 694.76,-261.25 651.34,-250.11"></path>
<polygon fill="cyan" stroke="cyan" points="652.04,-246.68 641.49,-247.59 650.3,-253.46 652.04,-246.68"></polygon>
</g>
<!-- Regular Unstake -->
<g id="node6" class="node">
<title>Regular Unstake</title>
<ellipse fill="blue" stroke="blue" cx="767.39" cy="-234" rx="71.49" ry="18"></ellipse>
<text text-anchor="middle" x="767.39" y="-230.3" font-family="Times,serif" font-size="14.00">Regular Unstake</text>
</g>
<!-- Decrease Stake Policy->Regular Unstake -->
<g id="edge5" class="edge">
<title>Decrease Stake Policy->Regular Unstake</title>
<path fill="none" stroke="cyan" stroke-dasharray="5,2" d="M841.42,-287.88C828.47,-278.62 812.33,-267.1 798.43,-257.17"></path>
<polygon fill="cyan" stroke="cyan" points="800.28,-254.19 790.11,-251.23 796.21,-259.89 800.28,-254.19"></polygon>
</g>
<!-- Decrement Stake (Stream) -->
<g id="node7" class="node">
<title>Decrement Stake (Stream)</title>
<ellipse fill="blue" stroke="blue" cx="964.39" cy="-234" rx="107.48" ry="18"></ellipse>
<text text-anchor="middle" x="964.39" y="-230.3" font-family="Times,serif" font-size="14.00">Decrement Stake (Stream)</text>
</g>
<!-- Decrease Stake Policy->Decrement Stake (Stream) -->
<g id="edge6" class="edge">
<title>Decrease Stake Policy->Decrement Stake (Stream)</title>
<path fill="none" stroke="cyan" d="M889.61,-287.88C902.5,-278.76 918.53,-267.43 932.43,-257.6"></path>
<polygon fill="cyan" stroke="cyan" points="934.62,-260.34 940.77,-251.71 930.58,-254.62 934.62,-260.34"></polygon>
</g>
<!-- Decrement Stake (Broker) -->
<g id="node8" class="node">
<title>Decrement Stake (Broker)</title>
<ellipse fill="blue" stroke="blue" cx="1196.39" cy="-234" rx="106.68" ry="18"></ellipse>
<text text-anchor="middle" x="1196.39" y="-230.3" font-family="Times,serif" font-size="14.00">Decrement Stake (Broker)</text>
</g>
<!-- Decrease Stake Policy->Decrement Stake (Broker) -->
<g id="edge7" class="edge">
<title>Decrease Stake Policy->Decrement Stake (Broker)</title>
<path fill="none" stroke="cyan" d="M936.4,-289.98C991.41,-278.35 1067.38,-262.28 1122.99,-250.52"></path>
<polygon fill="cyan" stroke="cyan" points="1123.72,-253.95 1132.78,-248.45 1122.27,-247.1 1123.72,-253.95"></polygon>
</g>
<!-- Pay Off Withdraw Queue -->
<g id="node9" class="node">
<title>Pay Off Withdraw Queue</title>
<ellipse fill="blue" stroke="blue" cx="353.39" cy="-162" rx="103.18" ry="18"></ellipse>
<text text-anchor="middle" x="353.39" y="-158.3" font-family="Times,serif" font-size="14.00">Pay Off Withdraw Queue</text>
</g>
<!-- Diverted Unstake->Pay Off Withdraw Queue -->
<g id="edge8" class="edge">
<title>Diverted Unstake->Pay Off Withdraw Queue</title>
<path fill="none" stroke="blue" d="M546.88,-219.67C509.01,-208.58 454.8,-192.7 413.39,-180.57"></path>
<polygon fill="blue" stroke="blue" points="414.28,-177.19 403.7,-177.73 412.31,-183.9 414.28,-177.19"></polygon>
</g>
<!-- Decrease Pool Value -->
<g id="node10" class="node">
<title>Decrease Pool Value</title>
<ellipse fill="blue" stroke="blue" cx="592.39" cy="-162" rx="85.59" ry="18"></ellipse>
<text text-anchor="middle" x="592.39" y="-158.3" font-family="Times,serif" font-size="14.00">Decrease Pool Value</text>
</g>
<!-- Diverted Unstake->Decrease Pool Value -->
<g id="edge9" class="edge">
<title>Diverted Unstake->Decrease Pool Value</title>
<path fill="none" stroke="blue" d="M592.39,-215.7C592.39,-207.98 592.39,-198.71 592.39,-190.11"></path>
<polygon fill="blue" stroke="blue" points="595.89,-190.1 592.39,-180.1 588.89,-190.1 595.89,-190.1"></polygon>
</g>
<!-- Increase Pool Free Funds -->
<g id="node11" class="node">
<title>Increase Pool Free Funds</title>
<ellipse fill="blue" stroke="blue" cx="798.39" cy="-162" rx="102.88" ry="18"></ellipse>
<text text-anchor="middle" x="798.39" y="-158.3" font-family="Times,serif" font-size="14.00">Increase Pool Free Funds</text>
</g>
<!-- Regular Unstake->Increase Pool Free Funds -->
<g id="edge10" class="edge">
<title>Regular Unstake->Increase Pool Free Funds</title>
<path fill="none" stroke="cyan" d="M774.9,-216.05C778.42,-208.09 782.71,-198.41 786.65,-189.51"></path>
<polygon fill="cyan" stroke="cyan" points="789.89,-190.84 790.74,-180.28 783.49,-188 789.89,-190.84"></polygon>
</g>
<!-- Stream.stake -->
<g id="node13" class="node">
<title>Stream.stake</title>
<ellipse fill="none" stroke="black" cx="976.39" cy="-162" rx="57.39" ry="18"></ellipse>
<text text-anchor="middle" x="976.39" y="-158.3" font-family="Times,serif" font-size="14.00">Stream.stake</text>
</g>
<!-- Decrement Stake (Stream)->Stream.stake -->
<g id="edge12" class="edge">
<title>Decrement Stake (Stream)->Stream.stake</title>
<path fill="none" stroke="black" d="M967.36,-215.7C968.68,-207.98 970.27,-198.71 971.74,-190.11"></path>
<polygon fill="black" stroke="black" points="975.22,-190.55 973.46,-180.1 968.32,-189.37 975.22,-190.55"></polygon>
</g>
<!-- Pool.stake -->
<g id="node15" class="node">
<title>Pool.stake</title>
<ellipse fill="none" stroke="black" cx="1155.39" cy="-162" rx="48.19" ry="18"></ellipse>
<text text-anchor="middle" x="1155.39" y="-158.3" font-family="Times,serif" font-size="14.00">Pool.stake</text>
</g>
<!-- Decrement Stake (Broker)->Pool.stake -->
<g id="edge14" class="edge">
<title>Decrement Stake (Broker)->Pool.stake</title>
<path fill="none" stroke="black" d="M1186.47,-216.05C1181.63,-207.8 1175.72,-197.7 1170.35,-188.54"></path>
<polygon fill="black" stroke="black" points="1173.3,-186.65 1165.23,-179.79 1167.26,-190.19 1173.3,-186.65"></polygon>
</g>
<!-- Vault.token_balances -->
<g id="node17" class="node">
<title>Vault.token_balances</title>
<ellipse fill="none" stroke="black" cx="88.39" cy="-90" rx="88.28" ry="18"></ellipse>
<text text-anchor="middle" x="88.39" y="-86.3" font-family="Times,serif" font-size="14.00">Vault.token_balances</text>
</g>
<!-- Pay Off Withdraw Queue->Vault.token_balances -->
<g id="edge16" class="edge">
<title>Pay Off Withdraw Queue->Vault.token_balances</title>
<path fill="none" stroke="black" d="M299.13,-146.67C255.82,-135.23 195.13,-119.2 150,-107.27"></path>
<polygon fill="black" stroke="black" points="150.89,-103.89 140.33,-104.72 149.11,-110.66 150.89,-103.89"></polygon>
</g>
<!-- Vault.internal_balances -->
<g id="node18" class="node">
<title>Vault.internal_balances</title>
<ellipse fill="none" stroke="black" cx="290.39" cy="-90" rx="95.58" ry="18"></ellipse>
<text text-anchor="middle" x="290.39" y="-86.3" font-family="Times,serif" font-size="14.00">Vault.internal_balances</text>
</g>
<!-- Pay Off Withdraw Queue->Vault.internal_balances -->
<g id="edge18" class="edge">
<title>Pay Off Withdraw Queue->Vault.internal_balances</title>
<path fill="none" stroke="black" d="M338.14,-144.05C330.4,-135.46 320.86,-124.86 312.35,-115.4"></path>
<polygon fill="black" stroke="black" points="314.79,-112.88 305.5,-107.79 309.59,-117.56 314.79,-112.88"></polygon>
</g>
<!-- Pool.withdraw_queue -->
<g id="node19" class="node">
<title>Pool.withdraw_queue</title>
<ellipse fill="none" stroke="black" cx="494.39" cy="-90" rx="90.18" ry="18"></ellipse>
<text text-anchor="middle" x="494.39" y="-86.3" font-family="Times,serif" font-size="14.00">Pool.withdraw_queue</text>
</g>
<!-- Pay Off Withdraw Queue->Pool.withdraw_queue -->
<g id="edge20" class="edge">
<title>Pay Off Withdraw Queue->Pool.withdraw_queue</title>
<path fill="none" stroke="black" d="M386.09,-144.76C406.08,-134.84 431.82,-122.07 453.19,-111.46"></path>
<polygon fill="black" stroke="black" points="454.95,-114.49 462.35,-106.91 451.84,-108.22 454.95,-114.49"></polygon>
</g>
<!-- Pool.pool_value -->
<g id="node20" class="node">
<title>Pool.pool_value</title>
<ellipse fill="none" stroke="black" cx="673.39" cy="-90" rx="70.39" ry="18"></ellipse>
<text text-anchor="middle" x="673.39" y="-86.3" font-family="Times,serif" font-size="14.00">Pool.pool_value</text>
</g>
<!-- Decrease Pool Value->Pool.pool_value -->
<g id="edge22" class="edge">
<title>Decrease Pool Value->Pool.pool_value</title>
<path fill="none" stroke="black" d="M611.59,-144.41C622.08,-135.34 635.24,-123.97 646.71,-114.06"></path>
<polygon fill="black" stroke="black" points="649.06,-116.66 654.33,-107.47 644.48,-111.36 649.06,-116.66"></polygon>
</g>
<!-- Pool.free_funds -->
<g id="node21" class="node">
<title>Pool.free_funds</title>
<ellipse fill="none" stroke="black" cx="830.39" cy="-90" rx="68.79" ry="18"></ellipse>
<text text-anchor="middle" x="830.39" y="-86.3" font-family="Times,serif" font-size="14.00">Pool.free_funds</text>
</g>
<!-- Increase Pool Free Funds->Pool.free_funds -->
<g id="edge24" class="edge">
<title>Increase Pool Free Funds->Pool.free_funds</title>
<path fill="none" stroke="black" d="M806.3,-143.7C809.94,-135.73 814.35,-126.1 818.39,-117.26"></path>
<polygon fill="black" stroke="black" points="821.6,-118.65 822.57,-108.1 815.23,-115.74 821.6,-118.65"></polygon>
</g>
<!-- Stream_2 -->
<g id="node12" class="node">
<title>Stream_2</title>
<path fill="none" stroke="black" d="M1004.39,-104.73C1004.39,-106.53 991.84,-108 976.39,-108 960.94,-108 948.39,-106.53 948.39,-104.73 948.39,-104.73 948.39,-75.27 948.39,-75.27 948.39,-73.47 960.94,-72 976.39,-72 991.84,-72 1004.39,-73.47 1004.39,-75.27 1004.39,-75.27 1004.39,-104.73 1004.39,-104.73"></path>
<path fill="none" stroke="black" d="M1004.39,-104.73C1004.39,-102.92 991.84,-101.45 976.39,-101.45 960.94,-101.45 948.39,-102.92 948.39,-104.73"></path>
<text text-anchor="middle" x="976.39" y="-86.3" font-family="Times,serif" font-size="14.00">Stream</text>
</g>
<!-- Stream.stake->Stream_2 -->
<g id="edge11" class="edge">
<title>Stream.stake->Stream_2</title>
<path fill="none" stroke="black" d="M976.39,-143.7C976.39,-135.98 976.39,-126.71 976.39,-118.11"></path>
<polygon fill="black" stroke="black" points="979.89,-118.1 976.39,-108.1 972.89,-118.1 979.89,-118.1"></polygon>
</g>
<!-- Pool_2 -->
<g id="node14" class="node">
<title>Pool_2</title>
<path fill="none" stroke="black" d="M778.39,-32.73C778.39,-34.53 766.29,-36 751.39,-36 736.49,-36 724.39,-34.53 724.39,-32.73 724.39,-32.73 724.39,-3.27 724.39,-3.27 724.39,-1.47 736.49,0 751.39,0 766.29,0 778.39,-1.47 778.39,-3.27 778.39,-3.27 778.39,-32.73 778.39,-32.73"></path>
<path fill="none" stroke="black" d="M778.39,-32.73C778.39,-30.92 766.29,-29.45 751.39,-29.45 736.49,-29.45 724.39,-30.92 724.39,-32.73"></path>
<text text-anchor="middle" x="751.39" y="-14.3" font-family="Times,serif" font-size="14.00">Pool</text>
</g>
<!-- Pool.stake->Pool_2 -->
<g id="edge13" class="edge">
<title>Pool.stake->Pool_2</title>
<path fill="none" stroke="black" d="M1135.49,-145.23C1109.11,-125.14 1060.41,-90.77 1013.39,-72 936.98,-41.5 840.75,-27.83 788.8,-22.3"></path>
<polygon fill="black" stroke="black" points="789.01,-18.81 778.71,-21.27 788.3,-25.77 789.01,-18.81"></polygon>
</g>
<!-- Vault_2 -->
<g id="node16" class="node">
<title>Vault_2</title>
<path fill="none" stroke="black" d="M216.39,-32.73C216.39,-34.53 204.29,-36 189.39,-36 174.49,-36 162.39,-34.53 162.39,-32.73 162.39,-32.73 162.39,-3.27 162.39,-3.27 162.39,-1.47 174.49,0 189.39,0 204.29,0 216.39,-1.47 216.39,-3.27 216.39,-3.27 216.39,-32.73 216.39,-32.73"></path>
<path fill="none" stroke="black" d="M216.39,-32.73C216.39,-30.92 204.29,-29.45 189.39,-29.45 174.49,-29.45 162.39,-30.92 162.39,-32.73"></path>
<text text-anchor="middle" x="189.39" y="-14.3" font-family="Times,serif" font-size="14.00">Vault</text>
</g>
<!-- Vault.token_balances->Vault_2 -->
<g id="edge15" class="edge">
<title>Vault.token_balances->Vault_2</title>
<path fill="none" stroke="black" d="M112.07,-72.59C125.72,-63.13 143.05,-51.12 157.84,-40.87"></path>
<polygon fill="black" stroke="black" points="159.98,-43.64 166.21,-35.07 156,-37.89 159.98,-43.64"></polygon>
</g>
<!-- Vault.internal_balances->Vault_2 -->
<g id="edge17" class="edge">
<title>Vault.internal_balances->Vault_2</title>
<path fill="none" stroke="black" d="M266.46,-72.41C252.9,-63.02 235.77,-51.15 221.11,-40.98"></path>
<polygon fill="black" stroke="black" points="223.02,-38.05 212.81,-35.23 219.03,-43.8 223.02,-38.05"></polygon>
</g>
<!-- Pool.withdraw_queue->Pool_2 -->
<g id="edge19" class="edge">
<title>Pool.withdraw_queue->Pool_2</title>
<path fill="none" stroke="black" d="M545.47,-75.09C595.32,-61.51 669.93,-41.19 714.33,-29.1"></path>
<polygon fill="black" stroke="black" points="715.4,-32.43 724.13,-26.43 713.56,-25.68 715.4,-32.43"></polygon>
</g>
<!-- Pool.pool_value->Pool_2 -->
<g id="edge21" class="edge">
<title>Pool.pool_value->Pool_2</title>
<path fill="none" stroke="black" d="M691.88,-72.41C701.81,-63.5 714.22,-52.36 725.14,-42.56"></path>
<polygon fill="black" stroke="black" points="727.66,-45 732.77,-35.71 722.99,-39.79 727.66,-45"></polygon>
</g>
<!-- Pool.free_funds->Pool_2 -->
<g id="edge23" class="edge">
<title>Pool.free_funds->Pool_2</title>
<path fill="none" stroke="black" d="M811.67,-72.41C801.61,-63.5 789.04,-52.36 777.98,-42.56"></path>
<polygon fill="black" stroke="black" points="780.06,-39.72 770.25,-35.71 775.42,-44.96 780.06,-39.72"></polygon>
</g>
</g>
</svg></div>
<h2>Behavioral Action Space</h2><h3>Trigger Force Unstake</h3><p>When a delegator feels that the broker is not making an effort to unstake quickly enough, they may call this function. If the requirements are met, and entire stream will be unstaked from.</p><h4>Called By:</h4>
<p>1. Delegator</p><h4>Constraints:</h4>
<p>1. The delegator must have tokens in the agreement.</p><h2>Policies</h2><h3>Check Force Unstake</h3><p>The policy which determines if a force unstake can take place</p><h4>Preceded By:</h4>
<p>1. Trigger Force Unstake</p><h4>Input Messages:</h4>
<p>1. ForceUnstakeMessage</p><h4>Followed By:</h4>
<p>1. Decrease Stake Policy</p><h4>Output Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Constraints:</h4>
<p>1. ForceUnstakeMessage.stream_id must be a valid stream address
</p><p>2. ForceUnstakeMessage.pool_id must be a valid pool address
</p><h4>Policy Options:</h4>
<details><summary><b>1. Grace Period</b></summary><p>This function checks whether the top of the withdraw queue is older than the grace period parameter.</p><p>Input Messages:</p><p>1. ForceUnstakeMessage
</p>Output Messages:<p>1. CurrencyStakingMessage</p><p>Logic: <br/>1. Grab the pool object with the pool address [pool]
<br/>
2. Find the length of the withdraw queue, if it is 0, then terminate the function here
<br/>
3. Grab the first element in the queue (which will be the oldest), w = pool.withdraw_queue[0]
<br/>
4. Check if ForceUnstakeMessage.called_at - w.Time >= PARAMS.grace_period, if not then terminate the function here
<br/>
5. Find the amount staked on the stream, amount = pool.stake[ForceUnstakeMessage.stream_address]
<br/>
6. Create message = CurrencyStakingMessage(currency_amount = -amount,
pool_id = ForceUnstakeMessage.pool_id,
stream_id = ForceUnstakeMessage.stream_id)
<br/>
7. Call "Decrease Stake Policy" and pass the message
</p></details><details><summary><b>2. Auto-Accept</b></summary><p>This function automatically allows for the force withdraw to take place.</p><p>Input Messages:</p><p>1. ForceUnstakeMessage
</p>Output Messages:<p>1. CurrencyStakingMessage</p><p>Logic: <br/>1. Grab the pool object with the pool address [pool]
<br/>
2. Find the amount staked on the stream, amount = pool.stake[ForceUnstakeMessage.stream_address]
<br/>
3. Create message = CurrencyStakingMessage(currency_amount = -amount,
pool_id = ForceUnstakeMessage.pool_id,
stream_id = ForceUnstakeMessage.stream_id)
<br/>
4. Call "Decrease Stake Policy" and pass the message
</p></details><br/><h3>Decrease Stake Policy</h3><p>The policy which takes care of unstaking from a stream and how the money is allocated after</p><h4>Preceded By:</h4>
<p>1. Decrease Stake in Stream</p><p>2. Check Force Unstake</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<p>1. Diverted Unstake</p><p>2. Regular Unstake</p><p>3. Decrement Stake (Stream)</p><p>4. Decrement Stake (Broker)</p><h4>Output Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Constraints:</h4>
<h4>Policy Options:</h4>
<details><summary><b>1. Withdraw Queue First</b></summary><p>This implementation pays out the withdraw queue before the regular unstake mechanism.</p><p>Input Messages:</p><p>1. CurrencyStakingMessage
</p>Output Messages:<p>1. CurrencyStakingMessage</p><p>Logic: <br/>1. Grab the pool object at CurrencyStakingMessage.pool_address
<br/>
2. Find the value in DATA that the current withdraw queue would have based on total number of tokens, which we will assign to the variable "debt"
<br/>
3. diverted_payout = MIN(-CurrencyStakingMessage.currency_amount, debt)
<br/>
4. regular_payout = CurrencyStakingMessage.currency_amount - diverted_payout
<br/>
5. IF diverted_payout > 0: Call Diverted Unstake with CurrencyStakingMessage(currency_amount = diverted_payout,
pool_id = CurrencyStakingMessage.pool_id,
stream_id = CurrencyStakingMessage.stream_id)
<br/>
6. IF regular_payout > 0: Call Regular Unstake with CurrencyStakingMessage(currency_amount = regular_payout,
pool_id = CurrencyStakingMessage.pool_id,
stream_id = CurrencyStakingMessage.stream_id)
<br/>
7. Pass the input message through to Decrement Stake (Stream)
<br/>
8. Pass the input message through to Decrement Stake (Broker)
</p></details><br/><h2>Mechanisms</h2><h3>Diverted Unstake</h3><p>This mechanism diverts funds from unstaking to pay off the withdraw queue</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<p>1. Pay Off Withdraw Queue</p><p>2. Decrease Pool Value</p><h4>Output Messages:</h4>
<p>1. CurrencyAmountMessage</p><h4>Constraints:</h4>
<p>1. CurrencyStakingMessage.currency_amount > total withdraw queue value in DATA
</p><h4>Logic:</h4>
<p><br/>1. Create an output message of CurrencyAmountMessage(delegator_id = CurrencyStakingMessage.delegator_id
pool_id: CurrencyStakingMessage.pool_id,
currency_amount: CurrencyStakingMessage.delegator_id)
<br/>
2. Call "Pay Off Withdraw Queue" with the message
<br/>
3. Call "Decrease Pool Value" with the message
<br/>
</p><h3>Pay Off Withdraw Queue</h3><p>The function to take care of paying off the withdraw queue</p><h4>Input Messages:</h4>
<p>1. CurrencyAmountMessage</p><h4>Followed By:</h4>
<h4>Output Messages:</h4>
<h4>Constraints:</h4>
<h4>Logic:</h4>
<p>Variables:
1. currency_amount (CurrencyAmountMessage)
2. pool_id (CurrencyAmountMessage)
Functions
1. EXCHANGE_RATE1(pool_tokens) -> data
2. EXCHANGE_RATE2(data) -> pool_tokens
Pseudocode:
<pre>
amount_left = currency_amount
d = withdraw_queue at pool_id
while amount_left > 0:
if amount_left > EXCHANGE_RATE1(d[0].amount):
amount_left -= d[0].amount
funds at d[0].delegator_id += d[0].amount
d.pop(0)
else:
funds at d[0].delegator_id += amount_left
d[0].amount -= EXCHANGE_RATE2(amount_left)
amount_left = 0
</pre></p><h3>Decrease Pool Value</h3><p>Simple mechanism that reduces the pool value</p><h4>Input Messages:</h4>
<p>1. CurrencyAmountMessage</p><h4>Followed By:</h4>
<h4>Output Messages:</h4>
<h4>Constraints:</h4>
<p>1. CurrencyAmountMessage.currency_amount <= (pool at CurrencyAmountMessage.pool_address).pool_value
</p><h4>Logic:</h4>
<p>Find the pool at CurrencyAmountMessage.pool_address then reduce its value by CurrencyAmountMessage.currency_amount</p><h3>Regular Unstake</h3><p>The mechanism which takes care of unstaking in any regular scenario</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<p>1. Increase Pool Free Funds</p><h4>Output Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Constraints:</h4>
<h4>Logic:</h4>
<p>Pass the message along to Increase Pool Free Funds
</p><h3>Increase Pool Free Funds</h3><p>Simple mechanism for increasing the free funds in a pool.</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<h4>Output Messages:</h4>
<h4>Constraints:</h4>
<h4>Logic:</h4>
<p>Find the pool at CurrencyAmountMessage.pool_address then increase its free_funds by CurrencyAmountMessage.currency_amount</p><h3>Decrement Stake (Stream)</h3><p>This mechanism changes the stake value on the stream side.</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<h4>Output Messages:</h4>
<h4>Constraints:</h4>
<h4>Logic:</h4>
<p>For the stream at CurrencyStakingMessage.stream_address, decrease the stake variable for index CurrencyStakingMessage.pool_address by CurrencyStakingMessage.currency_amount</p><h3>Decrement Stake (Broker)</h3><p>This mechanism changes the stake value on the broker side.</p><h4>Input Messages:</h4>
<p>1. CurrencyStakingMessage</p><h4>Followed By:</h4>
<h4>Output Messages:</h4>
<h4>Constraints:</h4>
<h4>Logic:</h4>
<p>For the pool at CurrencyStakingMessage.pool_address, decrease the stake variable for index CurrencyStakingMessage.stream_address by CurrencyStakingMessage.currency_amount</p>
Pool Value = Free Funds + Stake + Unearned