Skip to content

Commit

Permalink
use returned value from legacy redemption for autoredemption event
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Dec 20, 2024
1 parent d72cdce commit 2c58fa5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contracts/AutoRedemption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ contract AutoRedemption is AutomationCompatibleInterface, FunctionsClient, Confi
mapping(address => address) hypervisorCollaterals;
mapping(address => bytes) swapPaths;

event AutoRedemption(address indexed vault, address indexed token, uint256 usdsRedeemed);

string private constant source =
"const { ethers } = await import('npm:[email protected]'); const apiResponse = await Functions.makeHttpRequest({ url: 'https://smart-vault-api.thestandard.io/redemption' }); if (apiResponse.error) { throw Error('Request failed'); } const { data } = apiResponse; const encoded = ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'address'], [data.tokenID, data.collateral]); return ethers.getBytes(encoded)";

Expand Down Expand Up @@ -122,7 +124,10 @@ contract AutoRedemption is AutomationCompatibleInterface, FunctionsClient, Confi
(uint256 _approxAmountInRequired,,,) =
IQuoter(quoter).quoteExactOutput(_collateralToUSDsPath, _USDsTargetAmount);
uint256 _amountIn = _approxAmountInRequired > _collateralBalance ? _collateralBalance : _approxAmountInRequired;
ISmartVaultManager(smartVaultManager).vaultAutoRedemption(_smartVault, _token, _collateralToUSDsPath, _amountIn);
uint256 _usdsRedeemed = ISmartVaultManager(smartVaultManager).vaultAutoRedemption(
_smartVault, _token, _collateralToUSDsPath, _amountIn
);
emit AutoRedemption(_smartVault, _token, _usdsRedeemed);
}

function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory err) internal override {
Expand Down

0 comments on commit 2c58fa5

Please sign in to comment.