@@ -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
@@ -112,11 +110,11 @@ access(all) contract ERC4626SinkConnectors {
112110 to : self .assetEVMAddress,
113111 signature : " approve(address,uint256)" ,
114112 args : [self .vault, uintAmount],
115- gasLimit : 100_000
116- )
117- if approveRes? .status ! = EVM.Status.successful {
113+ gasLimit : 500_000
114+ )!
115+ if approveRes.status ! = EVM.Status.successful {
118116 // TODO: consider more graceful handling of this error
119- panic (" Failed to approve ERC4626 vault to spend assets " )
117+ panic (self . _approveErrorMessage ( ufixAmount : amount, uintAmount : uintAmount, approveRes : approveRes) )
120118 }
121119
122120 // deposit the assets to the ERC4626 vault
@@ -125,12 +123,12 @@ access(all) contract ERC4626SinkConnectors {
125123 to : self .vault,
126124 signature : " deposit(uint256,address)" ,
127125 args : [uintAmount, self .coa.borrow ()! .address ()],
128- gasLimit : 250_000
129- )
130- if depositRes? .status ! = EVM.Status.successful {
126+ gasLimit : 1_000_000
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 (" Failed to deposit \(amount) assets \( self.assetEVMAddress.toString()) to ERC4626 vault \(self.vault.toString()) " )
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
@@ -179,5 +177,34 @@ access(all) contract ERC4626SinkConnectors {
179177 }
180178 return nil
181179 }
180+ /// Returns an error message for a failed approve call
181+ ///
182+ /// @param ufixAmount: the amount of assets to approve
183+ /// @param uintAmount: the amount of assets to approve in uint256 format
184+ /// @param approveRes: the result of the approve call
185+ ///
186+ /// @return an error message for a failed approve call
187+ ///
188+ access (self )
189+ fun _approveErrorMessage (ufixAmount : UFix64 , uintAmount : UInt256 , approveRes : EVM .Result ): String {
190+ return " Failed to approve ERC4626 vault \(self.vault.toString()) to spend \(ufixAmount) assets \(self.assetEVMAddress.toString()). "
191+ .concat (" approvee: \(self.vault.toString()), amount: \(uintAmount). " )
192+ .concat (" Error code: \(approveRes.errorCode) Error message: \(approveRes.errorMessage)" )
193+ }
194+ /// Returns an error message for a failed deposit call
195+ ///
196+ /// @param ufixAmount: the amount of assets to deposit
197+ /// @param uintAmount: the amount of assets to deposit in uint256 format
198+ /// @param depositRes: the result of the deposit call
199+ ///
200+ /// @return an error message for a failed deposit call
201+ ///
202+ access (self )
203+ fun _depositErrorMessage (ufixAmount : UFix64 , uintAmount : UInt256 , depositRes : EVM .Result ): String {
204+ let coaHex = self .coa.borrow ()! .address ().toString ()
205+ return " Failed to deposit \(ufixAmount) assets \(self.assetEVMAddress.toString()) to ERC4626 vault \(self.vault.toString()). "
206+ .concat (" amount: \(uintAmount), to: \(coaHex). " )
207+ .concat (" Error code: \(depositRes.errorCode) Error message: \(depositRes.errorMessage)" )
208+ }
182209 }
183210}
0 commit comments