github.com/Finschia/finschia-sdk@v0.48.1/docs/uml/svg/delegation_sequence.svg (about)

     1  <?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="1931px" preserveAspectRatio="none" style="width:1929px;height:1931px;" version="1.1" viewBox="0 0 1929 1931" width="1929px" zoomAndPan="magnify"><defs><filter height="300%" id="fcmqo0ou3ae7m" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><text fill="#000000" font-family="sans-serif" font-size="18" lengthAdjust="spacing" textLength="478" x="723.5" y="28.708">Delegating (currently undelegated funds delegator)</text><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="711.5" x="29" y="148.3828"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="158.3359" style="stroke:#000000;stroke-width:2.0;" width="842" x="84" y="208.6484"/><rect fill="#FFFFFF" height="56.9375" style="stroke:none;stroke-width:1.0;" width="842" x="84" y="310.0469"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="883.8672" style="stroke:#000000;stroke-width:2.0;" width="1351.5" x="563.5" y="380.9844"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="454.5313" style="stroke:#000000;stroke-width:2.0;" width="863" x="1042" y="434.25"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="339.1328" style="stroke:#000000;stroke-width:2.0;" width="843" x="1052" y="542.6484"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="90.2031" style="stroke:#000000;stroke-width:2.0;" width="813" x="1072" y="651.0469"/><rect fill="#FFFFFF" height="43.9375" style="stroke:none;stroke-width:1.0;" width="813" x="1072" y="697.3125"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="119.5313" style="stroke:#000000;stroke-width:2.0;" width="620" x="1062" y="755.25"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="600" x="1072" y="821.5156"/><rect fill="#FFFFFF" height="339.9375" style="stroke:none;stroke-width:1.0;" width="1351.5" x="563.5" y="924.9141"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="90.2031" style="stroke:#000000;stroke-width:2.0;" width="672.5" x="583.5" y="946.7188"/><rect fill="#FFFFFF" height="43.9375" style="stroke:none;stroke-width:1.0;" width="672.5" x="583.5" y="992.9844"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="206.9297" style="stroke:#000000;stroke-width:2.0;" width="1311.5" x="573.5" y="1050.9219"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="672.5" x="583.5" y="1146.3203"/><rect fill="#FFFFFF" filter="url(#fcmqo0ou3ae7m)" height="71.3984" style="stroke:#000000;stroke-width:2.0;" width="1663" x="222" y="1519.9141"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="120" x2="120" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="661.5" x2="661.5" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="920.5" x2="920.5" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="1164" x2="1164" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="1597" x2="1597" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="1746" x2="1746" y1="102.25" y2="1863.5078"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:5.0,5.0;" x1="1853" x2="1853" y1="102.25" y2="1863.5078"/><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="158" x="39" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="144" x="46" y="86.9482">msgServer (staking)</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="158" x="39" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="144" x="46" y="1882.5029">msgServer (staking)</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="133" x="593.5" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="119" x="600.5" y="86.9482">keeper (staking)</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="133" x="593.5" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="119" x="600.5" y="1882.5029">keeper (staking)</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="77" x="880.5" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="63" x="887.5" y="86.9482">validator</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="77" x="880.5" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="63" x="887.5" y="1882.5029">validator</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="160" x="1082" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="146" x="1089" y="86.9482">keeper.bankKeeper</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="160" x="1082" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="146" x="1089" y="1882.5029">keeper.bankKeeper</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="126" x="1532" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="112" x="1539" y="86.9482">vestingAccount</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="126" x="1532" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="112" x="1539" y="1882.5029">vestingAccount</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="145" x="1672" y="66.9531"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="131" x="1679" y="86.9482">ctx.EventManager</text><rect fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" height="30.2969" style="stroke:#A80036;stroke-width:1.5;" width="145" x="1672" y="1862.5078"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="131" x="1679" y="1882.5029">ctx.EventManager</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="38" x="1831" y="98.9482">store</text><path d="M1835,49.9531 C1835,39.9531 1853,39.9531 1853,39.9531 C1853,39.9531 1871,39.9531 1871,49.9531 L1871,75.9531 C1871,85.9531 1853,85.9531 1853,85.9531 C1853,85.9531 1835,85.9531 1835,75.9531 L1835,49.9531 " fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" style="stroke:#000000;stroke-width:1.5;"/><path d="M1835,49.9531 C1835,59.9531 1853,59.9531 1853,59.9531 C1853,59.9531 1871,59.9531 1871,49.9531 " fill="none" style="stroke:#000000;stroke-width:1.5;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="38" x="1831" y="1875.5029">store</text><path d="M1835,1888.8047 C1835,1878.8047 1853,1878.8047 1853,1878.8047 C1853,1878.8047 1871,1878.8047 1871,1888.8047 L1871,1914.8047 C1871,1924.8047 1853,1924.8047 1853,1924.8047 C1853,1924.8047 1835,1924.8047 1835,1914.8047 L1835,1888.8047 " fill="#FEFECE" filter="url(#fcmqo0ou3ae7m)" style="stroke:#000000;stroke-width:1.5;"/><path d="M1835,1888.8047 C1835,1898.8047 1853,1898.8047 1853,1898.8047 C1853,1898.8047 1871,1898.8047 1871,1888.8047 " fill="none" style="stroke:#000000;stroke-width:1.5;"/><polygon fill="#A80036" points="650,129.3828,660,133.3828,650,137.3828,654,133.3828" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="120" x2="656" y1="133.3828" y2="133.3828"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="518" x="127" y="128.3169">Delegate(Context, DelegatorAddress, Amount, Validator, tokenSrc := Unbonded)</text><path d="M29,148.3828 L95,148.3828 L95,155.3828 L85,165.3828 L29,165.3828 L29,148.3828 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="711.5" x="29" y="148.3828"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="44" y="161.4497">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="336" x="110" y="160.5933">[exchange rate is invalid (tokens in validator is 0)]</text><polygon fill="#A80036" points="131,182.6484,121,186.6484,131,190.6484,127,186.6484" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="125" x2="661" y1="186.6484" y2="186.6484"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="31" x="137" y="181.5825">error</text><path d="M84,208.6484 L150,208.6484 L150,215.6484 L140,225.6484 L84,225.6484 L84,208.6484 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="158.3359" style="stroke:#000000;stroke-width:2.0;" width="842" x="84" y="208.6484"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="99" y="221.7153">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="184" x="165" y="220.8589">[perform a new delegation]</text><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="704" y1="246.9141" y2="246.9141"/><line style="stroke:#A80036;stroke-width:1.0;" x1="704" x2="704" y1="246.9141" y2="259.9141"/><line style="stroke:#A80036;stroke-width:1.0;" x1="663" x2="704" y1="259.9141" y2="259.9141"/><polygon fill="#A80036" points="673,255.9141,663,259.9141,673,263.9141,669,259.9141" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="245" x="669" y="241.8481">delegation := create delegation object</text><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="704" y1="289.0469" y2="289.0469"/><line style="stroke:#A80036;stroke-width:1.0;" x1="704" x2="704" y1="289.0469" y2="302.0469"/><line style="stroke:#A80036;stroke-width:1.0;" x1="663" x2="704" y1="302.0469" y2="302.0469"/><polygon fill="#A80036" points="673,298.0469,663,302.0469,673,306.0469,669,302.0469" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="197" x="669" y="283.981">BeforeDelegationCreated hook</text><path d="M94,274.4141 L94,299.4141 L653,299.4141 L653,284.4141 L643,274.4141 L94,274.4141 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M643,274.4141 L643,284.4141 L653,284.4141 L643,274.4141 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="538" x="100" y="291.481">Calls IncrementValidatorPeriod (Used to calculate distribution) in keeper/validator.go</text><line style="stroke:#000000;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="84" x2="926" y1="311.0469" y2="311.0469"/><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="303" x="89" y="321.2573">[delegation exists, more tokens being added]</text><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="704" y1="345.9844" y2="345.9844"/><line style="stroke:#A80036;stroke-width:1.0;" x1="704" x2="704" y1="345.9844" y2="358.9844"/><line style="stroke:#A80036;stroke-width:1.0;" x1="663" x2="704" y1="358.9844" y2="358.9844"/><polygon fill="#A80036" points="673,354.9844,663,358.9844,673,362.9844,669,358.9844" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="199" x="669" y="340.9185">BeforeDelegationModified hook</text><path d="M245,331.3516 L245,356.3516 L653,356.3516 L653,341.3516 L643,331.3516 L245,331.3516 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M643,331.3516 L643,341.3516 L653,341.3516 L643,331.3516 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="387" x="251" y="348.4185">withdraw current delegation rewards (and increment period)</text><path d="M563.5,380.9844 L629.5,380.9844 L629.5,387.9844 L619.5,397.9844 L563.5,397.9844 L563.5,380.9844 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="883.8672" style="stroke:#000000;stroke-width:2.0;" width="1351.5" x="563.5" y="380.9844"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="578.5" y="394.0513">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="372" x="644.5" y="393.1948">[delegating from an account (subtractTokens == true)]</text><polygon fill="#A80036" points="1152,415.25,1162,419.25,1152,423.25,1156,419.25" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="1158" y1="419.25" y2="419.25"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="239" x="669" y="414.1841">DelegateCoinsFromAccountToModule</text><path d="M1042,434.25 L1442,434.25 L1442,441.25 L1432,451.25 L1042,451.25 L1042,434.25 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="454.5313" style="stroke:#000000;stroke-width:2.0;" width="863" x="1042" y="434.25"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="355" x="1057" y="447.3169">DelegateCoinsFromAccountToModule function</text><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1206" y1="472.5156" y2="472.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1206" x2="1206" y1="472.5156" y2="485.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1165" x2="1206" y1="485.5156" y2="485.5156"/><polygon fill="#A80036" points="1175,481.5156,1165,485.5156,1175,489.5156,1171,485.5156" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="239" x="1171" y="467.4497">DelegateCoinsFromAccountToModule</text><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1206" y1="514.6484" y2="514.6484"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1206" x2="1206" y1="514.6484" y2="527.6484"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1165" x2="1206" y1="527.6484" y2="527.6484"/><polygon fill="#A80036" points="1175,523.6484,1165,527.6484,1175,531.6484,1171,527.6484" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="93" x="1171" y="509.5825">DelegateCoins</text><path d="M1052,542.6484 L1275,542.6484 L1275,549.6484 L1265,559.6484 L1052,559.6484 L1052,542.6484 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="339.1328" style="stroke:#000000;stroke-width:2.0;" width="843" x="1052" y="542.6484"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="178" x="1067" y="555.7153">DelegateCoins function</text><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1164" x2="1206" y1="580.9141" y2="580.9141"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1206" x2="1206" y1="580.9141" y2="593.9141"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1165" x2="1206" y1="593.9141" y2="593.9141"/><polygon fill="#A80036" points="1175,589.9141,1165,593.9141,1175,597.9141,1171,593.9141" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="419" x="1171" y="575.8481">Check the delegator has enough balances of all tokens delegated</text><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1164" x2="1206" y1="623.0469" y2="623.0469"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1206" x2="1206" y1="623.0469" y2="636.0469"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1165" x2="1206" y1="636.0469" y2="636.0469"/><polygon fill="#A80036" points="1175,632.0469,1165,636.0469,1175,640.0469,1171,636.0469" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="370" x="1171" y="617.981">Track delegation (register that it exists to keep track of it)</text><path d="M1072,651.0469 L1138,651.0469 L1138,658.0469 L1128,668.0469 L1072,668.0469 L1072,651.0469 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="90.2031" style="stroke:#000000;stroke-width:2.0;" width="813" x="1072" y="651.0469"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="1087" y="664.1138">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="204" x="1153" y="663.2573">[validator is currently bonded]</text><polygon fill="#A80036" points="1841,685.3125,1851,689.3125,1841,693.3125,1845,689.3125" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1164" x2="1847" y1="689.3125" y2="689.3125"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="347" x="1171" y="684.2466">Transfer tokens from delegator to BondedTokensPool.</text><line style="stroke:#000000;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1072" x2="1885" y1="698.3125" y2="698.3125"/><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="312" x="1077" y="708.5229">[validator is currently unbonded or unbonding]</text><polygon fill="#A80036" points="1841,729.25,1851,733.25,1841,737.25,1845,733.25" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="1164" x2="1847" y1="733.25" y2="733.25"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="369" x="1171" y="728.1841">Transfer tokens from delegator to NotBondedTokensPool.</text><path d="M1062,755.25 L1299,755.25 L1299,762.25 L1289,772.25 L1062,772.25 L1062,755.25 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="119.5313" style="stroke:#000000;stroke-width:2.0;" width="620" x="1062" y="755.25"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="192" x="1077" y="768.3169">trackDelegation function</text><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1206" y1="793.5156" y2="793.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1206" x2="1206" y1="793.5156" y2="806.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1165" x2="1206" y1="806.5156" y2="806.5156"/><polygon fill="#A80036" points="1175,802.5156,1165,806.5156,1175,810.5156,1171,806.5156" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="101" x="1171" y="788.4497">trackDelegation</text><path d="M1072,821.5156 L1138,821.5156 L1138,828.5156 L1128,838.5156 L1072,838.5156 L1072,821.5156 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="600" x="1072" y="821.5156"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="1087" y="834.5825">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="214" x="1153" y="833.7261">[delegator is a vesting account]</text><polygon fill="#A80036" points="1585,855.7813,1595,859.7813,1585,863.7813,1589,859.7813" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1591" y1="859.7813" y2="859.7813"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="182" x="1171" y="854.7153">keep track of this delegation</text><polygon fill="#A80036" points="673,912.9141,663,916.9141,673,920.9141,669,916.9141" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="667" x2="1163" y1="916.9141" y2="916.9141"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="79" x="679" y="911.8481">nil (success)</text><line style="stroke:#000000;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="563.5" x2="1915" y1="925.9141" y2="925.9141"/><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="390" x="568.5" y="936.1245">[moving tokens between pools (subtractTokens == false)]</text><path d="M583.5,946.7188 L649.5,946.7188 L649.5,953.7188 L639.5,963.7188 L583.5,963.7188 L583.5,946.7188 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="90.2031" style="stroke:#000000;stroke-width:2.0;" width="672.5" x="583.5" y="946.7188"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="598.5" y="959.7856">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="393" x="664.5" y="958.9292">[delegator tokens are not bonded but validator is bonded]</text><polygon fill="#A80036" points="1152,980.9844,1162,984.9844,1152,988.9844,1156,984.9844" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="1158" y1="984.9844" y2="984.9844"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="436" x="669" y="979.9185">SendCoinsFromModuleToModule(notBondedPool, bondedPool, coins)</text><line style="stroke:#000000;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="583.5" x2="1256" y1="993.9844" y2="993.9844"/><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="393" x="588.5" y="1004.1948">[delegator tokens are bonded but validator is not bonded]</text><polygon fill="#A80036" points="1152,1024.9219,1162,1028.9219,1152,1032.9219,1156,1028.9219" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="1158" y1="1028.9219" y2="1028.9219"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="436" x="669" y="1023.856">SendCoinsFromModuleToModule(bondedPool, notBondedPool, coins)</text><path d="M573.5,1050.9219 L764.5,1050.9219 L764.5,1057.9219 L754.5,1067.9219 L573.5,1067.9219 L573.5,1050.9219 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="206.9297" style="stroke:#000000;stroke-width:2.0;" width="1311.5" x="573.5" y="1050.9219"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="146" x="588.5" y="1063.9888">SendCoins function</text><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1206" y1="1089.1875" y2="1089.1875"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1206" x2="1206" y1="1089.1875" y2="1102.1875"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1165" x2="1206" y1="1102.1875" y2="1102.1875"/><polygon fill="#A80036" points="1175,1098.1875,1165,1102.1875,1175,1106.1875,1171,1102.1875" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="67" x="1171" y="1084.1216">SendCoins</text><polygon fill="#A80036" points="1734.5,1127.3203,1744.5,1131.3203,1734.5,1135.3203,1738.5,1131.3203" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1740.5" y1="1131.3203" y2="1131.3203"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="244" x="1171" y="1126.2544">Emit TransferEvent(to, from, amount)</text><path d="M583.5,1146.3203 L649.5,1146.3203 L649.5,1153.3203 L639.5,1163.3203 L583.5,1163.3203 L583.5,1146.3203 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="46.2656" style="stroke:#000000;stroke-width:2.0;" width="672.5" x="583.5" y="1146.3203"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="598.5" y="1159.3872">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="369" x="664.5" y="1158.5308">[amount of spendable (balance - locked) coins too low]</text><polygon fill="#A80036" points="673,1180.5859,663,1184.5859,673,1188.5859,669,1184.5859" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="667" x2="1163" y1="1184.5859" y2="1184.5859"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="31" x="679" y="1179.52">error</text><polygon fill="#A80036" points="1841,1216.7188,1851,1220.7188,1841,1224.7188,1845,1220.7188" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1847" y1="1220.7188" y2="1220.7188"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="190" x="1171" y="1215.6528">subtract balance from sender</text><polygon fill="#A80036" points="1841,1245.8516,1851,1249.8516,1841,1253.8516,1845,1249.8516" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="1164" x2="1847" y1="1249.8516" y2="1249.8516"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="154" x="1171" y="1244.7856">add balance to recipient</text><polygon fill="#A80036" points="909,1288.9844,919,1292.9844,909,1296.9844,913,1292.9844" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="915" y1="1292.9844" y2="1292.9844"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="125" x="669" y="1287.9185">AddTokensFromDel</text><line style="stroke:#A80036;stroke-width:1.0;" x1="921" x2="963" y1="1335.75" y2="1335.75"/><line style="stroke:#A80036;stroke-width:1.0;" x1="963" x2="963" y1="1335.75" y2="1348.75"/><line style="stroke:#A80036;stroke-width:1.0;" x1="922" x2="963" y1="1348.75" y2="1348.75"/><polygon fill="#A80036" points="932,1344.75,922,1348.75,932,1352.75,928,1348.75" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="229" x="928" y="1330.6841">calculate number of shares to issue</text><path d="M278,1305.9844 L278,1360.9844 L912,1360.9844 L912,1315.9844 L902,1305.9844 L278,1305.9844 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M902,1305.9844 L902,1315.9844 L912,1315.9844 L902,1305.9844 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="455" x="284" y="1323.0513">If there are no shares (validator being created) then 1 token = 1 share.</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="207" x="284" y="1338.1841">If there are already shares, then</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="613" x="284" y="1353.3169">added shares =  (added tokens amount) * (current validator shares) / (current validator tokens)</text><line style="stroke:#A80036;stroke-width:1.0;" x1="921" x2="963" y1="1391.5156" y2="1391.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="963" x2="963" y1="1391.5156" y2="1404.5156"/><line style="stroke:#A80036;stroke-width:1.0;" x1="922" x2="963" y1="1404.5156" y2="1404.5156"/><polygon fill="#A80036" points="932,1400.5156,922,1404.5156,932,1408.5156,928,1404.5156" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="216" x="928" y="1386.4497">add delegated tokens to validator</text><polygon fill="#A80036" points="673,1429.6484,663,1433.6484,673,1437.6484,669,1433.6484" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="667" x2="920" y1="1433.6484" y2="1433.6484"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="148" x="679" y="1428.5825">validator, addedShares</text><polygon fill="#A80036" points="1841,1458.7813,1851,1462.7813,1841,1466.7813,1845,1462.7813" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="1847" y1="1462.7813" y2="1462.7813"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="142" x="669" y="1457.7153">update validator state</text><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="704" y1="1491.9141" y2="1491.9141"/><line style="stroke:#A80036;stroke-width:1.0;" x1="704" x2="704" y1="1491.9141" y2="1504.9141"/><line style="stroke:#A80036;stroke-width:1.0;" x1="663" x2="704" y1="1504.9141" y2="1504.9141"/><polygon fill="#A80036" points="673,1500.9141,663,1504.9141,673,1508.9141,669,1504.9141" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="202" x="669" y="1486.8481">calculate new validator's power</text><path d="M34,1477.2813 L34,1502.2813 L653,1502.2813 L653,1487.2813 L643,1477.2813 L34,1477.2813 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M643,1477.2813 L643,1487.2813 L653,1487.2813 L643,1477.2813 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="598" x="40" y="1494.3481">Number of tokens divided by PowerReduction (default: 1,000,000,000,000,000,000 = 10^18)</text><path d="M222,1519.9141 L288,1519.9141 L288,1526.9141 L278,1536.9141 L222,1536.9141 L222,1519.9141 " fill="#EEEEEE" style="stroke:#000000;stroke-width:1.0;"/><rect fill="none" height="71.3984" style="stroke:#000000;stroke-width:2.0;" width="1663" x="222" y="1519.9141"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="21" x="237" y="1532.981">alt</text><text fill="#000000" font-family="sans-serif" font-size="11" font-weight="bold" lengthAdjust="spacing" textLength="154" x="303" y="1532.1245">[validator is not jailed]</text><polygon fill="#A80036" points="1841,1566.7461,1851,1570.7461,1841,1574.7461,1845,1570.7461" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="1847" y1="1570.7461" y2="1570.7461"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="257" x="669" y="1565.6802">update validator's power in power index</text><path d="M232,1542.0469 L232,1582.0469 L653,1582.0469 L653,1552.0469 L643,1542.0469 L232,1542.0469 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M643,1542.0469 L643,1552.0469 L653,1552.0469 L643,1542.0469 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="400" x="238" y="1559.1138">the power index has entries shaped as 35 || power || address.</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="356" x="238" y="1574.2466">This makes the validators sorted by power, high to low.</text><line style="stroke:#A80036;stroke-width:1.0;" x1="662" x2="704" y1="1648.2109" y2="1648.2109"/><line style="stroke:#A80036;stroke-width:1.0;" x1="704" x2="704" y1="1648.2109" y2="1661.2109"/><line style="stroke:#A80036;stroke-width:1.0;" x1="663" x2="704" y1="1661.2109" y2="1661.2109"/><polygon fill="#A80036" points="673,1657.2109,663,1661.2109,673,1665.2109,669,1661.2109" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="189" x="669" y="1643.145">AfterDelegationModified hook</text><path d="M5,1603.3125 L5,1688.3125 L653,1688.3125 L653,1613.3125 L643,1603.3125 L5,1603.3125 " fill="#FBFB77" filter="url(#fcmqo0ou3ae7m)" style="stroke:#A80036;stroke-width:1.0;"/><path d="M643,1603.3125 L643,1613.3125 L653,1613.3125 L643,1603.3125 " fill="#FBFB77" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="154" x="11" y="1620.3794">Calls initializeDelegation</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="162" x="11" y="1635.5122">Store the previous period</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="284" x="11" y="1650.645">Calculate the number of tokens from shares</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="627" x="11" y="1665.7778">(shares the delegator has) * (tokens in delegation object)/(total tokens delegated to the validator)</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="190" x="11" y="1680.9106">Store delegation starting info.</text><polygon fill="#A80036" points="131,1715.1094,121,1719.1094,131,1723.1094,127,1719.1094" style="stroke:#A80036;stroke-width:1.0;"/><line style="stroke:#A80036;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="125" x2="661" y1="1719.1094" y2="1719.1094"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="271" x="137" y="1714.0435">newShares (ignored by Delegate function)</text><line style="stroke:#A80036;stroke-width:1.0;" x1="120" x2="162" y1="1748.2422" y2="1748.2422"/><line style="stroke:#A80036;stroke-width:1.0;" x1="162" x2="162" y1="1748.2422" y2="1761.2422"/><line style="stroke:#A80036;stroke-width:1.0;" x1="121" x2="162" y1="1761.2422" y2="1761.2422"/><polygon fill="#A80036" points="131,1757.2422,121,1761.2422,131,1765.2422,127,1761.2422" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="267" x="127" y="1743.1763">Emit event: Delegation(ValidatorAddress)</text><line style="stroke:#A80036;stroke-width:1.0;" x1="120" x2="162" y1="1790.375" y2="1790.375"/><line style="stroke:#A80036;stroke-width:1.0;" x1="162" x2="162" y1="1790.375" y2="1803.375"/><line style="stroke:#A80036;stroke-width:1.0;" x1="121" x2="162" y1="1803.375" y2="1803.375"/><polygon fill="#A80036" points="131,1799.375,121,1803.375,131,1807.375,127,1803.375" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="260" x="127" y="1785.3091">Emit event: Message(DelegatorAddress)</text><line style="stroke:#A80036;stroke-width:1.0;" x1="120" x2="162" y1="1832.5078" y2="1832.5078"/><line style="stroke:#A80036;stroke-width:1.0;" x1="162" x2="162" y1="1832.5078" y2="1845.5078"/><line style="stroke:#A80036;stroke-width:1.0;" x1="121" x2="162" y1="1845.5078" y2="1845.5078"/><polygon fill="#A80036" points="131,1841.5078,121,1845.5078,131,1849.5078,127,1845.5078" style="stroke:#A80036;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="179" x="127" y="1827.4419">telemetry(Amount, Denom)</text><!--MD5=[f19c2397b2fc767e311b1c2c610156f8]
     2  @startuml
     3  'https://plantuml.com/sequence-diagram
     4  
     5  title: Delegating (currently undelegated funds delegator)
     6  
     7  participant "msgServer (staking)"
     8  participant  "keeper (staking)" as keeper
     9  participant validator
    10  participant keeper.bankKeeper
    11  participant vestingAccount
    12  participant ctx.EventManager
    13  
    14  database store
    15  
    16  "msgServer (staking)" -> keeper : Delegate(Context, DelegatorAddress, Amount, Validator, tokenSrc := Unbonded)
    17  
    18  alt exchange rate is invalid (tokens in validator is 0)
    19      keeper - ->  "msgServer (staking)" : error
    20  end
    21  
    22  alt perform a new delegation
    23      keeper -> keeper : delegation := create delegation object
    24      keeper -> keeper : BeforeDelegationCreated hook
    25      note left: Calls IncrementValidatorPeriod (Used to calculate distribution) in keeper/validator.go
    26  else delegation exists, more tokens being added
    27      keeper -> keeper : BeforeDelegationModified hook
    28      note left: withdraw current delegation rewards (and increment period)
    29  end
    30  
    31  alt delegating from an account (subtractTokens == true)
    32      keeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule
    33      group DelegateCoinsFromAccountToModule function
    34          keeper.bankKeeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule
    35          keeper.bankKeeper -> keeper.bankKeeper : DelegateCoins
    36          group DelegateCoins function
    37              keeper.bankKeeper - -> keeper.bankKeeper : Check the delegator has enough balances of all tokens delegated
    38              keeper.bankKeeper - -> keeper.bankKeeper : Track delegation (register that it exists to keep track of it)
    39              alt validator is currently bonded
    40                  keeper.bankKeeper - -> store : Transfer tokens from delegator to BondedTokensPool.
    41              else validator is currently unbonded or unbonding
    42                  keeper.bankKeeper - -> store : Transfer tokens from delegator to NotBondedTokensPool.
    43              end
    44              group trackDelegation function
    45                  keeper.bankKeeper -> keeper.bankKeeper : trackDelegation
    46                  alt delegator is a vesting account
    47                      keeper.bankKeeper -> vestingAccount : keep track of this delegation
    48                  end
    49              end
    50          end
    51      end
    52      keeper <- - keeper.bankKeeper : nil (success)
    53  else moving tokens between pools (subtractTokens == false)
    54      alt delegator tokens are not bonded but validator is bonded
    55         keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(notBondedPool, bondedPool, coins)
    56      else delegator tokens are bonded but validator is not bonded
    57         keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(bondedPool, notBondedPool, coins)
    58      end
    59      group SendCoins function
    60          keeper.bankKeeper -> keeper.bankKeeper : SendCoins
    61          keeper.bankKeeper -> ctx.EventManager : Emit TransferEvent(to, from, amount)
    62          alt amount of spendable (balance - locked) coins too low
    63              keeper <- - keeper.bankKeeper : error
    64          end
    65          keeper.bankKeeper -> store : subtract balance from sender
    66          keeper.bankKeeper -> store : add balance to recipient
    67      end
    68  end
    69  
    70  keeper -> validator : AddTokensFromDel
    71  validator -> validator : calculate number of shares to issue
    72  note left: If there are no shares (validator being created) then 1 token = 1 share.\nIf there are already shares, then\nadded shares =  (added tokens amount) * (current validator shares) / (current validator tokens)
    73  
    74  validator -> validator : add delegated tokens to validator
    75  keeper <- - validator : validator, addedShares
    76  keeper -> store : update validator state
    77  keeper -> keeper: calculate new validator's power
    78  note left : Number of tokens divided by PowerReduction (default: 1,000,000,000,000,000,000 = 10^18)
    79  alt validator is not jailed
    80      keeper -> store : update validator's power in power index
    81      note left : the power index has entries shaped as 35 || power || address.\nThis makes the validators sorted by power, high to low.
    82  end
    83  
    84  keeper -> keeper : AfterDelegationModified hook
    85  note left: Calls initializeDelegation\nStore the previous period\nCalculate the number of tokens from shares\n(shares the delegator has) * (tokens in delegation object)/(total tokens delegated to the validator)\nStore delegation starting info.
    86  "msgServer (staking)" <- - keeper : newShares (ignored by Delegate function)
    87  
    88  
    89  "msgServer (staking)" -> "msgServer (staking)" : Emit event: Delegation(ValidatorAddress)
    90  "msgServer (staking)" -> "msgServer (staking)" : Emit event: Message(DelegatorAddress)
    91  "msgServer (staking)" -> "msgServer (staking)" : telemetry(Amount, Denom)
    92  @enduml
    93  
    94  @startuml
    95  
    96  title: Delegating (currently undelegated funds delegator)
    97  
    98  participant "msgServer (staking)"
    99  participant  "keeper (staking)" as keeper
   100  participant validator
   101  participant keeper.bankKeeper
   102  participant vestingAccount
   103  participant ctx.EventManager
   104  
   105  database store
   106  
   107  "msgServer (staking)" -> keeper : Delegate(Context, DelegatorAddress, Amount, Validator, tokenSrc := Unbonded)
   108  
   109  alt exchange rate is invalid (tokens in validator is 0)
   110      keeper - ->  "msgServer (staking)" : error
   111  end
   112  
   113  alt perform a new delegation
   114      keeper -> keeper : delegation := create delegation object
   115      keeper -> keeper : BeforeDelegationCreated hook
   116      note left: Calls IncrementValidatorPeriod (Used to calculate distribution) in keeper/validator.go
   117  else delegation exists, more tokens being added
   118      keeper -> keeper : BeforeDelegationModified hook
   119      note left: withdraw current delegation rewards (and increment period)
   120  end
   121  
   122  alt delegating from an account (subtractTokens == true)
   123      keeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule
   124      group DelegateCoinsFromAccountToModule function
   125          keeper.bankKeeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule
   126          keeper.bankKeeper -> keeper.bankKeeper : DelegateCoins
   127          group DelegateCoins function
   128              keeper.bankKeeper - -> keeper.bankKeeper : Check the delegator has enough balances of all tokens delegated
   129              keeper.bankKeeper - -> keeper.bankKeeper : Track delegation (register that it exists to keep track of it)
   130              alt validator is currently bonded
   131                  keeper.bankKeeper - -> store : Transfer tokens from delegator to BondedTokensPool.
   132              else validator is currently unbonded or unbonding
   133                  keeper.bankKeeper - -> store : Transfer tokens from delegator to NotBondedTokensPool.
   134              end
   135              group trackDelegation function
   136                  keeper.bankKeeper -> keeper.bankKeeper : trackDelegation
   137                  alt delegator is a vesting account
   138                      keeper.bankKeeper -> vestingAccount : keep track of this delegation
   139                  end
   140              end
   141          end
   142      end
   143      keeper <- - keeper.bankKeeper : nil (success)
   144  else moving tokens between pools (subtractTokens == false)
   145      alt delegator tokens are not bonded but validator is bonded
   146         keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(notBondedPool, bondedPool, coins)
   147      else delegator tokens are bonded but validator is not bonded
   148         keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(bondedPool, notBondedPool, coins)
   149      end
   150      group SendCoins function
   151          keeper.bankKeeper -> keeper.bankKeeper : SendCoins
   152          keeper.bankKeeper -> ctx.EventManager : Emit TransferEvent(to, from, amount)
   153          alt amount of spendable (balance - locked) coins too low
   154              keeper <- - keeper.bankKeeper : error
   155          end
   156          keeper.bankKeeper -> store : subtract balance from sender
   157          keeper.bankKeeper -> store : add balance to recipient
   158      end
   159  end
   160  
   161  keeper -> validator : AddTokensFromDel
   162  validator -> validator : calculate number of shares to issue
   163  note left: If there are no shares (validator being created) then 1 token = 1 share.\nIf there are already shares, then\nadded shares =  (added tokens amount) * (current validator shares) / (current validator tokens)
   164  
   165  validator -> validator : add delegated tokens to validator
   166  keeper <- - validator : validator, addedShares
   167  keeper -> store : update validator state
   168  keeper -> keeper: calculate new validator's power
   169  note left : Number of tokens divided by PowerReduction (default: 1,000,000,000,000,000,000 = 10^18)
   170  alt validator is not jailed
   171      keeper -> store : update validator's power in power index
   172      note left : the power index has entries shaped as 35 || power || address.\nThis makes the validators sorted by power, high to low.
   173  end
   174  
   175  keeper -> keeper : AfterDelegationModified hook
   176  note left: Calls initializeDelegation\nStore the previous period\nCalculate the number of tokens from shares\n(shares the delegator has) * (tokens in delegation object)/(total tokens delegated to the validator)\nStore delegation starting info.
   177  "msgServer (staking)" <- - keeper : newShares (ignored by Delegate function)
   178  
   179  
   180  "msgServer (staking)" -> "msgServer (staking)" : Emit event: Delegation(ValidatorAddress)
   181  "msgServer (staking)" -> "msgServer (staking)" : Emit event: Message(DelegatorAddress)
   182  "msgServer (staking)" -> "msgServer (staking)" : telemetry(Amount, Denom)
   183  @enduml
   184  
   185  PlantUML version 1.2021.5beta3(Unknown compile time)
   186  (GPL source distribution)
   187  Java Runtime: Java(TM) SE Runtime Environment
   188  JVM: Java HotSpot(TM) 64-Bit Server VM
   189  Default Encoding: UTF-8
   190  Language: en
   191  Country: US
   192  --></g></svg>