Skip to content
Closed
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
6 changes: 3 additions & 3 deletions cadence/contracts/connectors/FungibleTokenConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ access(all) contract FungibleTokenConnectors {
return self.withdrawVaultType
}
/// Returns an estimate of how much of the associated Vault can be provided by this Source
access(all) fun minimumAvailable(): UFix64 {
access(all) fun minimumAvailable(liquidate: Bool): UFix64 {
if let vault = self.withdrawVault.borrow() {
return self.minimumBalance < vault.balance ? vault.balance - self.minimumBalance : 0.0
}
Expand All @@ -170,7 +170,7 @@ access(all) contract FungibleTokenConnectors {
/// 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} {
let available = self.minimumAvailable()
let available = self.minimumAvailable(liquidate: true)
if !self.withdrawVault.check() || available == 0.0 || maxAmount == 0.0 {
return <- DeFiActionsUtils.getEmptyVault(self.withdrawVaultType)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ access(all) contract FungibleTokenConnectors {
return 0.0
}
/// Returns an estimate of how much of the associated Vault can be provided by this Source
access(all) fun minimumAvailable(): UFix64 {
access(all) fun minimumAvailable(liquidate: Bool): UFix64 {
if let vault = self.vault.borrow() {
return vault.balance < self.minimumBalance ? vault.balance - self.minimumBalance : 0.0
}
Expand Down
10 changes: 5 additions & 5 deletions cadence/contracts/connectors/SwapConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ access(all) contract SwapConnectors {
///
/// @return the minimum amount of currency available to withdraw from this Source
///
access(all) fun minimumAvailable(): UFix64 {
access(all) fun minimumAvailable(liquidate: Bool): UFix64 {
// estimate post-conversion currency based on the source's pre-conversion balance available
let availableIn = self.source.minimumAvailable()
let availableIn = self.source.minimumAvailable(liquidate: liquidate)
return availableIn > 0.0
? self.swapper.quoteOut(forProvided: availableIn, reverse: false).outAmount
: 0.0
Expand All @@ -393,14 +393,14 @@ access(all) contract SwapConnectors {
/// @return the Vault containing the withdrawn currency
///
access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} {
let minimumAvail = self.minimumAvailable()
let minimumAvail = self.minimumAvailable(liquidate: true)
if minimumAvail == 0.0 || maxAmount == 0.0 {
return <- DeFiActionsUtils.getEmptyVault(self.getSourceType())
}

// expect output amount as the lesser between the amount available and the maximum amount
var quote = minimumAvail < maxAmount
? self.swapper.quoteOut(forProvided: self.source.minimumAvailable(), reverse: false)
? self.swapper.quoteOut(forProvided: self.source.minimumAvailable(liquidate: true), reverse: false)
: self.swapper.quoteIn(forDesired: maxAmount, reverse: false)

let sourceLiquidity <- self.source.withdrawAvailable(maxAmount: quote.inAmount)
Expand All @@ -417,4 +417,4 @@ access(all) contract SwapConnectors {
return <- outVault
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ access(all) contract IncrementFiStakingConnectors {
///
/// @return the minimum amount of rewards available for claiming from this Source
///
access(all) fun minimumAvailable(): UFix64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np: my preference would be liquidate

access(all) fun minimumAvailable(liquidate: Bool): UFix64 {
if let address = self.userCertificate.borrow()?.owner?.address {
if let pool = IncrementFiStakingConnectors.borrowPool(pid: self.pid) {
// Stake an empty vault on behalf of the user to update the pool
Expand All @@ -238,7 +238,7 @@ access(all) contract IncrementFiStakingConnectors {
/// @return a Vault containing the claimed rewards
///
access(FungibleToken.Withdraw) fun withdrawAvailable(maxAmount: UFix64): @{FungibleToken.Vault} {
let minimumAvailable = self.minimumAvailable()
let minimumAvailable = self.minimumAvailable(liquidate: true)
if minimumAvailable == 0.0 {
return <- DeFiActionsUtils.getEmptyVault(self.getSourceType())
}
Expand Down Expand Up @@ -309,4 +309,4 @@ access(all) contract IncrementFiStakingConnectors {
access(all) fun tokenTypeIdentifierToVaultType(_ tokenType: String): Type {
return CompositeType(tokenType.concat(".Vault"))!
}
}
}
4 changes: 2 additions & 2 deletions cadence/contracts/interfaces/DeFiActions.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ access(all) contract DeFiActions {
/// Returns the Vault type provided by this Source
access(all) view fun getSourceType(): Type
/// Returns an estimate of how much of the associated Vault Type can be provided by this Source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns an estimate of how much of the associated Vault Type can be provided by this Source
/// Returns an estimate of how much of the associated Vault Type can be provided by this Source
/// with a flag that may be useful for denoting a caller wants the fully available balance the Source
/// can provide.

access(all) fun minimumAvailable(): UFix64
access(all) fun minimumAvailable(liquidate: Bool): 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 @@ -521,7 +521,7 @@ access(all) contract DeFiActions {
return self.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 minimumAvailable(liquidate: Bool): UFix64 {
if let ab = self.autoBalancer.borrow() {
return ab.vaultBalance()
}
Expand Down
4 changes: 2 additions & 2 deletions cadence/transactions/increment-fi/restake_rewards.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ transaction(

// Get the expected amount of LP tokens to be restaked
self.expectedStakeIncrease = zapper.quoteOut(
forProvided: poolRewardsSource.minimumAvailable(),
forProvided: poolRewardsSource.minimumAvailable(liquidate: true),
reverse: false
).outAmount
}
Expand Down Expand Up @@ -109,4 +109,4 @@ transaction(
assert(vault.balance == 0.0, message: "Vault should be empty after withdrawal - restaking may have failed")
destroy vault
}
}
}