mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-01-31 02:35:36 +00:00
vault: disallow transfer of flowing tokens
This commit is contained in:
parent
c16673e2d6
commit
7e1e71d25e
@ -123,12 +123,19 @@ abstract contract VaultBase {
|
||||
Recipient to,
|
||||
uint128 amount
|
||||
) internal {
|
||||
require(
|
||||
amount <= _balances[controller][context][from].available,
|
||||
InsufficientBalance()
|
||||
);
|
||||
_balances[controller][context][from].available -= amount;
|
||||
_balances[controller][context][to].available += amount;
|
||||
Balance memory senderBalance = _getBalance(controller, context, from);
|
||||
Balance memory receiverBalance = _getBalance(controller, context, to);
|
||||
require(amount <= senderBalance.available, InsufficientBalance());
|
||||
|
||||
senderBalance.available -= amount;
|
||||
receiverBalance.available += amount;
|
||||
|
||||
Flow memory senderFlow = _flows[controller][context][from];
|
||||
Lock memory lock = _locks[controller][context];
|
||||
_checkFlowInvariant(senderBalance, lock, senderFlow);
|
||||
|
||||
_balances[controller][context][from] = senderBalance;
|
||||
_balances[controller][context][to] = receiverBalance;
|
||||
}
|
||||
|
||||
function _designate(
|
||||
|
@ -588,6 +588,16 @@ describe("Vault", function () {
|
||||
vault.flow(context, sender, receiver, 1)
|
||||
).to.be.revertedWith("InsufficientBalance")
|
||||
})
|
||||
|
||||
it("cannot transfer tokens that are flowing", async function () {
|
||||
await vault.flow(context, sender, receiver, 5)
|
||||
await expect(
|
||||
vault.transfer(context, sender, receiver, 500)
|
||||
).not.to.be.reverted
|
||||
await expect(
|
||||
vault.transfer(context, sender, receiver, 1)
|
||||
).to.be.revertedWith("InsufficientBalance")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user