Trading revenue tokens for credit tokens in the SpigotedLine contract should somehow link the trade output amount to the amount of credit tokens needed (to pay for a particular credit or credits deposited in that credit token), otherwise this may exchange revenue tokens for excessive credit tokens while not taking into account other credits nominated in other tokens.
The functions claimAndRepay
and claimAndTrade
in the SpigotedLine contract will take revenue tokens from the spigot and potentially exchange them for credit tokens to repay debt.
This is done using the 0x protocol, these function will take an arbitrary zeroExTradeData
payload that is used to make the call to the exchange to swap the tokens. The issue here is that there is no link between the amount of tokens needed to repay debt in that particular credit token, and the output amount of the trade.
This may lead to situations where revenue tokens are traded in excess in relation to how much debt is pending in that particular credit token. Other credits nominated in other credit tokens may exist, but won't be able to be repaid with that excess since that revenue was already swapped to another token.
Enforce a relation between the amount of tokens needed to repay debt and the amount of tokens outputted from the trade. It can be a limit with a certain degree of padding to allow an error margin or exchange a bit more just in case. Another idea would be to make it possible to exchange unused credit tokens for other credit tokens to be able to repay debts (note that this may lead to other potential issues).