withdraw method
Withdraws from a yield vault and returns the transaction hash.
Implementation
@override
Future<YieldTransactionResult> withdraw(String vaultId, String ownerAddress, String amount, [String? receiverAddress, bool? sponsored]) async {
Future<YieldTransactionResult> instrumentationOperation() async {
final operationScope = _state.flowScope.capture(replace: false);
await operationScope.ready();
operationScope.check();
final yieldVaultWithdrawBody = <String, dynamic>{"ownerAddress": ownerAddress, "amount": amount};
if (receiverAddress != null) yieldVaultWithdrawBody["receiverAddress"] = receiverAddress;
final response = await _api.post<YieldVaultActionResponse>(path: "/yield/vaults/${Uri.encodeComponent(vaultId)}/withdraw", body: yieldVaultWithdrawBody, token: null, sessionPublicKey: _state.sessionPublicKey, parse: YieldVaultActionResponse.fromJson);
operationScope.check();
operationScope.check();
final transactionHash = await _earnExecutionService.execute(response.signingPayload, ownerAddress, sponsored);
operationScope.check();
return YieldTransactionResult(transactionHash: transactionHash);
}
return await _api.instrumentation.runAsync("earn.withdraw", instrumentationOperation);
}