Skip to content
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
13 changes: 13 additions & 0 deletions cadence/contracts/connectors/FungibleTokenConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ access(all) contract FungibleTokenConnectors {
}
return 0.0
}

/// Returns an estimate of how much of the associated Vault can be provided by this Source
/// regardless of the minimum balance
access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}

/// Withdraws the lesser of maxAmount or minimumAvailable(). If none is available, an empty Vault should be
/// returned
access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} {
Expand Down Expand Up @@ -268,6 +275,12 @@ access(all) contract FungibleTokenConnectors {
}
return 0.0
}
/// Returns an estimate of how much of the associated Vault can be provided by this Source
/// regardless of the minimum balance
access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}

/// Deposits up to the Sink's capacity from the provided Vault
access(all) fun depositCapacity(from: auth(FungibleToken.Withdraw) &{FungibleToken.Vault}) {
if let vault = self.vault.borrow() {
Expand Down
14 changes: 13 additions & 1 deletion cadence/contracts/connectors/SwapConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ access(all) contract SwapConnectors {
? self.swapper.quoteOut(forProvided: availableIn, reverse: false).outAmount
: 0.0
}
/// Returns the maximum amount of currency available to withdraw from this Source
///
/// @return the maximum amount of currency available to withdraw from this Source
///
access(all) fun maximumAvailable(): UFix64 {
// estimate post-conversion currency based on the source's pre-conversion balance available
let availableIn = self.source.maximumAvailable()
return availableIn > 0.0
? self.swapper.quoteOut(forProvided: availableIn, reverse: false).outAmount
: 0.0
}

/// Withdraws the provided amount of currency from this Source, swapping the provided amount to the required type if necessary
///
/// @param maxAmount: the maximum amount of currency to withdraw from this Source
Expand Down Expand Up @@ -417,4 +429,4 @@ access(all) contract SwapConnectors {
return <- outVault
}
}
}
}
7 changes: 7 additions & 0 deletions cadence/contracts/connectors/evm/EVMNativeFLOWConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ access(all) contract EVMNativeFLOWConnectors {
}
return 0.0
}
/// Returns the maximum available balance of this Source regardless of the minimumBalance
///
/// @return the maximum available balance of this Source
///
access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}
/// Withdraws the given amount of FLOW from the COA's EVM-native FLOW balance
///
/// @param maxAmount: the maximum amount of FLOW to withdraw
Expand Down
4 changes: 4 additions & 0 deletions cadence/contracts/connectors/evm/EVMTokenConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ access(all) contract EVMTokenConnectors {
}
return 0.0
}
/// Returns the maximum available balance for this Source regardless or the minimumBalance
access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}
/// Withdraws the given amount of tokens from the CadenceOwnedAccount's balance of ERC20 tokens
///
/// @param maxAmount: the maximum amount of tokens to withdraw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ access(all) contract IncrementFiStakingConnectors {
return 0.0 // no capacity if the staking pool is not available
}

access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}

/// Withdraws rewards from the staking pool up to the specified maximum amount
/// Overflow rewards are sent to the appropriate overflow sinks if provided
///
Expand Down Expand Up @@ -309,4 +313,4 @@ access(all) contract IncrementFiStakingConnectors {
access(all) fun tokenTypeIdentifierToVaultType(_ tokenType: String): Type {
return CompositeType(tokenType.concat(".Vault"))!
}
}
}
5 changes: 5 additions & 0 deletions cadence/contracts/interfaces/DeFiActions.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ access(all) contract DeFiActions {
access(all) view fun getSourceType(): Type
/// Returns an estimate of how much of the associated Vault Type can be provided by this Source
access(all) fun minimumAvailable(): UFix64
access(all) fun maximumAvailable(): UFix64
/// Withdraws the lesser of maxAmount or minimumAvailable(). If none is available, an empty Vault should be
/// returned
access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} {
Expand Down Expand Up @@ -527,6 +528,10 @@ access(all) contract DeFiActions {
}
return 0.0
}

access(all) fun maximumAvailable(): UFix64 {
return self.minimumAvailable()
}
/// Withdraws the lesser of maxAmount or minimumAvailable(). If none is available, an empty Vault should be
/// returned
access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} {
Expand Down