Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client/{asset,core}: ReserveBondFunds and dexAccount.tierChange
This adds the new Bonder methods, RegisterUnspent and ReserveBondFunds: RegisterUnspent informs the wallet of a certain amount already locked in unspent bonds that will eventually be refunded with RefundBond. This should be used prior to ReserveBondFunds. This alone does not enable reserves enforcement, and it should be called on bring-up when existing bonds that may refund to this wallet are known. Once ReserveBondFunds is called, even with 0 for future bonds, these live bond amounts will become enforced reserves when they are refunded via RefundBond. ReserveBondFunds (un)reserves funds for creation of future bonds. MakeBondTx will create transactions that decrement these reserves, while RefundBond will replenish the reserves. If the wallet's available balance should be respected when adding reserves, the boolean argument may be set to indicate this, in which case the return value indicates if it was able to reserve the funds. In this manner, funds may be pre-reserved so that when the wallet receives funds (from either external deposits or refunding of live bonds), they will go directly into locked balance. When the reserves are decremented to zero (by the amount that they were incremented), all enforcement including any fee buffering is disabled. Previously registered unspent/active bonds are not forgotten however; they total amount of these are tracked in case the wallet is used for reserves again in the future. In core.Core, the new wallet reserves methods are used to maintain adequate reserves based on the account's target tier and observed tier change. The dexAccount type has new fields to support this: - tierChange int64, is the total tier change that needs to be actuated with wallet reserves. Facilitates maintenance with changing tier. - totalReserved int64, helps track and debug the total amount reserved with the wallet's ReserveBondFunds method *only* for this dexAccount. Use of ReserveBondFunds and RegisterUnspent, facilitated by the new dexAccount fields, happens in: - connectWallets() via initialize(), after connectDEX(). Here it calls RegisterUnspent for all known bonds across all dexConnections. - authDEX. On reconnect, any observed tier change is acctuated with wallet reserves. Initial auth on login is handled slightly differently, (re)reserving the full required amount given the known unspent bonds. - handleTier change, which is called on penalization only, updates the tierChange field of the dexAccount. - rotateBonds. Any tierChange value is actuated with reserves. - PostBond. When making the initial bond for a new account, with maintenance enabled, ReserveBondFunds is used to pre-reseve. Here the boolean input is true, and the return is checked to ensure the wallet is sufficiently funded to increase reserves by the requested amount for the new bonds. - UpdateBondOptions. When modifying target tier or changing the bond asset. The boolean input and output are also used here.
- Loading branch information