Skip to content

Commit 096a0f2

Browse files
refactor ERC4626SinkConnectors to account for 0.0 deposits
1 parent a34c95b commit 096a0f2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

cadence/contracts/connectors/evm/ERC4626SinkConnectors.cdc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ access(all) contract ERC4626SinkConnectors {
8282
access(all) fun depositCapacity(from: auth(FungibleToken.Withdraw) &{FungibleToken.Vault}) {
8383
// check capacity & early return if none
8484
let capacity = self.minimumCapacity()
85-
if capacity == 0.0 {
86-
return
87-
}
85+
if capacity == 0.0 || from.balance == 0.0 { return; }
8886

8987
// withdraw the appropriate amount from the referenced vault & deposit to the EVMTokenConnectors Sink
9088
var amount = capacity <= from.balance ? capacity : from.balance
@@ -113,10 +111,10 @@ access(all) contract ERC4626SinkConnectors {
113111
signature: "approve(address,uint256)",
114112
args: [self.vault, uintAmount],
115113
gasLimit: 500_000
116-
)
117-
if approveRes?.status != EVM.Status.successful {
114+
)!
115+
if approveRes.status != EVM.Status.successful {
118116
// TODO: consider more graceful handling of this error
119-
panic(self._approveErrorMessage(ufixAmount: amount, uintAmount: uintAmount, approveRes: approveRes!))
117+
panic(self._approveErrorMessage(ufixAmount: amount, uintAmount: uintAmount, approveRes: approveRes))
120118
}
121119

122120
// deposit the assets to the ERC4626 vault
@@ -126,11 +124,11 @@ access(all) contract ERC4626SinkConnectors {
126124
signature: "deposit(uint256,address)",
127125
args: [uintAmount, self.coa.borrow()!.address()],
128126
gasLimit: 1_000_000
129-
)
130-
if depositRes?.status != EVM.Status.successful {
127+
)!
128+
if depositRes.status != EVM.Status.successful {
131129
// TODO: Consider unwinding the deposit & returning to the from vault
132130
// - would require {Sink, Source} instead of just Sink
133-
panic(self._depositErrorMessage(ufixAmount: amount, uintAmount: uintAmount, depositRes: depositRes!))
131+
panic(self._depositErrorMessage(ufixAmount: amount, uintAmount: uintAmount, depositRes: depositRes))
134132
}
135133
}
136134
/// Returns a ComponentInfo struct containing information about this component and a list of ComponentInfo for

0 commit comments

Comments
 (0)