mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-07 06:04:26 +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,
|
Recipient to,
|
||||||
uint128 amount
|
uint128 amount
|
||||||
) internal {
|
) internal {
|
||||||
require(
|
Balance memory senderBalance = _getBalance(controller, context, from);
|
||||||
amount <= _balances[controller][context][from].available,
|
Balance memory receiverBalance = _getBalance(controller, context, to);
|
||||||
InsufficientBalance()
|
require(amount <= senderBalance.available, InsufficientBalance());
|
||||||
);
|
|
||||||
_balances[controller][context][from].available -= amount;
|
senderBalance.available -= amount;
|
||||||
_balances[controller][context][to].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(
|
function _designate(
|
||||||
|
@ -588,6 +588,16 @@ describe("Vault", function () {
|
|||||||
vault.flow(context, sender, receiver, 1)
|
vault.flow(context, sender, receiver, 1)
|
||||||
).to.be.revertedWith("InsufficientBalance")
|
).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