Skip to content

Commit

Permalink
Add pre & post conditions to the interface & remove the `senderAddres…
Browse files Browse the repository at this point in the history
…s` param from event (#138)

add pre & post conditions to the interface
  • Loading branch information
satyamakgec authored Aug 23, 2023
1 parent d806282 commit 81c6e7e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions application/20230522-pool-based-dex.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ pub resource interface ImmediateSwap {
recipient: Capability<&{FungibleToken.Receiver}>,
remainingSourceTokenRecipient: Capability<&{FungibleToken.Receiver}>
)
{
pre {
expiry >= getCurrentBlock().timestamp : "Expired swap request"
recipient.check() : "Provided recipient capability can not be borrowed"
sourceToTargetTokenPath.length >= 2 : "Incorrect source to target token path"
sourceVault.balance > 0.0 : "Swap is not permitted for zero source vault balance"
}
}
/// @notice It will Swap the source token for to target token and
Expand Down Expand Up @@ -121,8 +129,17 @@ pub resource interface ImmediateSwap {
sourceToTargetTokenPath: [Type],
sourceVault: @FungibleToken.Vault,
exactTargetAmount: UFix64,
expiry: UInt64
): @ExactSwapAndReturnValue
expiry: UFix64
): @ExactSwapAndReturnValue {
pre {
expiry >= getCurrentBlock().timestamp : "Expired swap request"
sourceToTargetTokenPath.length >= 2 : "Incorrect source to target token path"
sourceVault.balance > 0.0 : "Swap is not permitted for zero source vault balance"
}
post {
result.targetTokenVault.balance == exactTargetAmount : "Unable to perform exact swap"
}
}
}
Expand All @@ -134,7 +151,6 @@ Events play a pivotal role in enhancing discoverability within a system; thus, t
/// Below event get emitted during `swapExactSourceToTargetTokenUsingPath` & `swapExactSourceToTargetTokenUsingPathAndReturn`
/// function call.
///
/// @param senderAddress: Address who initiated the swap. // TODO: It is not possible to know as per the proposed interface.
/// @param receiverAddress: Address who receives target token, It is optional because in case of
/// `swapExactSourceToTargetTokenUsingPathAndReturn` function target token vault would be returned instead of movement of funds in
/// receiver capability.
Expand All @@ -143,7 +159,6 @@ Events play a pivotal role in enhancing discoverability within a system; thus, t
/// @param sourceToken: Type of sourceToken. eg. Type<FLOW>
/// @param targetToken: Type of targetToken. eg. Type<USDC>
pub event Swap(
senderAddress: Address,
receiverAddress: Address?,
sourceTokenAmount: UFix64,
receivedTargetTokenAmount: UFix64,
Expand Down

0 comments on commit 81c6e7e

Please sign in to comment.