Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Withdrawn event to Vault and add balanceAfter params #158

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions contracts/FungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ access(all) contract interface FungibleToken: ViewResolver {
access(all) entitlement Withdraw

/// The event that is emitted when tokens are withdrawn from a Vault
access(all) event Withdrawn(type: String, amount: UFix64, from: Address?, fromUUID: UInt64, withdrawnUUID: UInt64)
access(all) event Withdrawn(type: String, amount: UFix64, from: Address?, fromUUID: UInt64, withdrawnUUID: UInt64, balanceAfter: UFix64)

/// The event that is emitted when tokens are deposited to a Vault
access(all) event Deposited(type: String, amount: UFix64, to: Address?, toUUID: UInt64, depositedUUID: UInt64)
access(all) event Deposited(type: String, amount: UFix64, to: Address?, toUUID: UInt64, depositedUUID: UInt64, balanceAfter: UFix64)

/// Event that is emitted when the global burn method is called with a non-zero balance
access(all) event Burned(type: String, amount: UFix64, fromUUID: UInt64)
Expand Down Expand Up @@ -94,7 +94,6 @@ access(all) contract interface FungibleToken: ViewResolver {
// `result` refers to the return value
result.balance == amount:
"Withdrawal amount must be the same as the balance of the withdrawn Vault"
emit Withdrawn(type: self.getType().identifier, amount: amount, from: self.owner?.address, fromUUID: self.uuid, withdrawnUUID: result.uuid)
}
}
}
Expand Down Expand Up @@ -187,6 +186,14 @@ access(all) contract interface FungibleToken: ViewResolver {
//
self.balance == before(self.balance) - amount:
"New Vault balance must be the difference of the previous balance and the withdrawn Vault balance"
emit Withdrawn(
type: result.getType().identifier,
amount: amount,
from: self.owner?.address,
fromUUID: self.uuid,
withdrawnUUID: result.uuid,
balanceAfter: self.balance
)
}
}

Expand All @@ -198,9 +205,16 @@ access(all) contract interface FungibleToken: ViewResolver {
pre {
from.isInstance(self.getType()):
"Cannot deposit an incompatible token type"
emit Deposited(type: from.getType().identifier, amount: from.balance, to: self.owner?.address, toUUID: self.uuid, depositedUUID: from.uuid)
}
post {
emit Deposited(
type: before(from.getType().identifier),
amount: before(from.balance),
to: self.owner?.address,
toUUID: self.uuid,
depositedUUID: before(from.uuid),
balanceAfter: self.balance
)
self.balance == before(self.balance) + before(from.balance):
"New Vault balance must be the sum of the previous balance and the deposited Vault"
}
Expand Down
Loading
Loading