Update events

This commit is contained in:
Mubaris NK 2021-03-15 22:52:47 +05:30
parent 593069bddd
commit c2f4a1f119
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
4 changed files with 53 additions and 84 deletions

View File

@ -1,7 +1,5 @@
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
import { OneProtoData, OneProtoMultiData, OneInchData} from "./interface.sol";
contract Events { contract Events {
event LogSell( event LogSell(
address indexed buyToken, address indexed buyToken,
@ -12,21 +10,6 @@ contract Events {
uint256 setId uint256 setId
); );
function emitLogSell(
OneProtoData memory oneProtoData,
uint256 getId,
uint256 setId
) internal {
emit LogSell(
address(oneProtoData.buyToken),
address(oneProtoData.sellToken),
oneProtoData._buyAmt,
oneProtoData._sellAmt,
getId,
setId
);
}
event LogSellTwo( event LogSellTwo(
address indexed buyToken, address indexed buyToken,
address indexed sellToken, address indexed sellToken,
@ -36,21 +19,6 @@ contract Events {
uint256 setId uint256 setId
); );
function emitLogSellTwo(
OneProtoData memory oneProtoData,
uint256 getId,
uint256 setId
) internal {
emit LogSellTwo(
address(oneProtoData.buyToken),
address(oneProtoData.sellToken),
oneProtoData._buyAmt,
oneProtoData._sellAmt,
getId,
setId
);
}
event LogSellMulti( event LogSellMulti(
address[] tokens, address[] tokens,
address indexed buyToken, address indexed buyToken,
@ -61,22 +29,6 @@ contract Events {
uint256 setId uint256 setId
); );
function emitLogSellMulti(
OneProtoMultiData memory oneProtoData,
uint256 getId,
uint256 setId
) internal {
emit LogSellMulti(
oneProtoData.tokens,
address(oneProtoData.buyToken),
address(oneProtoData.sellToken),
oneProtoData._buyAmt,
oneProtoData._sellAmt,
getId,
setId
);
}
event LogSellThree( event LogSellThree(
address indexed buyToken, address indexed buyToken,
address indexed sellToken, address indexed sellToken,
@ -85,19 +37,4 @@ contract Events {
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
function emitLogSellThree(
OneInchData memory oneInchData,
uint256 setId
) internal {
emit LogSellThree(
address(oneInchData.buyToken),
address(oneInchData.sellToken),
oneInchData._buyAmt,
oneInchData._sellAmt,
0,
setId
);
}
} }

View File

@ -141,7 +141,7 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
OneProtoData memory oneProtoData, OneProtoData memory oneProtoData,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
) internal { ) internal returns (OneProtoData memory) {
uint _sellAmt = getUint(getId, oneProtoData._sellAmt); uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
oneProtoData._sellAmt = _sellAmt == uint(-1) ? oneProtoData._sellAmt = _sellAmt == uint(-1) ?
@ -165,7 +165,7 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
setUint(setId, oneProtoData._buyAmt); setUint(setId, oneProtoData._buyAmt);
emitLogSell(oneProtoData, getId, setId); return oneProtoData;
} }
/** /**
@ -178,7 +178,7 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
OneProtoData memory oneProtoData, OneProtoData memory oneProtoData,
uint getId, uint getId,
uint setId uint setId
) internal { ) internal returns (OneProtoData memory) {
uint _sellAmt = getUint(getId, oneProtoData._sellAmt); uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
oneProtoData._sellAmt = _sellAmt == uint(-1) ? oneProtoData._sellAmt = _sellAmt == uint(-1) ?
@ -191,7 +191,8 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
); );
setUint(setId, oneProtoData._buyAmt); setUint(setId, oneProtoData._buyAmt);
emitLogSellTwo(oneProtoData, getId, setId);
return oneProtoData;
} }
/** /**
@ -204,7 +205,7 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
OneProtoMultiData memory oneProtoData, OneProtoMultiData memory oneProtoData,
uint getId, uint getId,
uint setId uint setId
) internal { ) internal returns (OneProtoMultiData memory) {
uint _sellAmt = getUint(getId, oneProtoData._sellAmt); uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
oneProtoData._sellAmt = _sellAmt == uint(-1) ? oneProtoData._sellAmt = _sellAmt == uint(-1) ?
@ -214,7 +215,9 @@ abstract contract OneProtoResolverHelpers is OneInchResolver {
oneProtoData._buyAmt = oneProtoSwapMulti(oneProtoData); oneProtoData._buyAmt = oneProtoSwapMulti(oneProtoData);
setUint(setId, oneProtoData._buyAmt); setUint(setId, oneProtoData._buyAmt);
emitLogSellMulti(oneProtoData, getId, setId); // emitLogSellMulti(oneProtoData, getId, setId);
return oneProtoData;
} }
} }
@ -228,7 +231,7 @@ abstract contract OneInchResolverHelpers is OneProtoResolverHelpers {
function _sellThree( function _sellThree(
OneInchData memory oneInchData, OneInchData memory oneInchData,
uint setId uint setId
) internal { ) internal returns (OneInchData memory) {
TokenInterface _sellAddr = oneInchData.sellToken; TokenInterface _sellAddr = oneInchData.sellToken;
uint ethAmt; uint ethAmt;
@ -243,7 +246,9 @@ abstract contract OneInchResolverHelpers is OneProtoResolverHelpers {
oneInchData._buyAmt = oneInchSwap(oneInchData, ethAmt); oneInchData._buyAmt = oneInchSwap(oneInchData, ethAmt);
setUint(setId, oneInchData._buyAmt); setUint(setId, oneInchData._buyAmt);
emitLogSellThree(oneInchData, setId); return oneInchData;
// emitLogSellThree(oneInchData, setId);
} }
} }
@ -264,7 +269,7 @@ abstract contract OneProto is OneInchResolverHelpers {
uint unitAmt, uint unitAmt,
uint getId, uint getId,
uint setId uint setId
) external payable { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
OneProtoData memory oneProtoData = OneProtoData({ OneProtoData memory oneProtoData = OneProtoData({
buyToken: TokenInterface(buyAddr), buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr), sellToken: TokenInterface(sellAddr),
@ -275,7 +280,10 @@ abstract contract OneProto is OneInchResolverHelpers {
disableDexes: 0 disableDexes: 0
}); });
_sell(oneProtoData, getId, setId); oneProtoData = _sell(oneProtoData, getId, setId);
_eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(buyAddr, sellAddr, oneProtoData._buyAmt, oneProtoData._sellAmt, getId, setId);
} }
/** /**
@ -298,7 +306,7 @@ abstract contract OneProto is OneInchResolverHelpers {
uint disableDexes, uint disableDexes,
uint getId, uint getId,
uint setId uint setId
) external payable { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
OneProtoData memory oneProtoData = OneProtoData({ OneProtoData memory oneProtoData = OneProtoData({
buyToken: TokenInterface(buyAddr), buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr), sellToken: TokenInterface(sellAddr),
@ -309,7 +317,10 @@ abstract contract OneProto is OneInchResolverHelpers {
_buyAmt: 0 _buyAmt: 0
}); });
_sellTwo(oneProtoData, getId, setId); oneProtoData = _sellTwo(oneProtoData, getId, setId);
_eventName = "LogSellTwo(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(buyAddr, sellAddr, oneProtoData._buyAmt, oneProtoData._sellAmt, getId, setId);
} }
/** /**
@ -330,10 +341,11 @@ abstract contract OneProto is OneInchResolverHelpers {
uint[] calldata disableDexes, uint[] calldata disableDexes,
uint getId, uint getId,
uint setId uint setId
) external payable { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _length = tokens.length;
OneProtoMultiData memory oneProtoData = OneProtoMultiData({ OneProtoMultiData memory oneProtoData = OneProtoMultiData({
tokens: tokens, tokens: tokens,
buyToken: TokenInterface(address(tokens[tokens.length - 1])), buyToken: TokenInterface(address(tokens[_length - 1])),
sellToken: TokenInterface(address(tokens[0])), sellToken: TokenInterface(address(tokens[0])),
unitAmt: unitAmt, unitAmt: unitAmt,
distribution: distribution, distribution: distribution,
@ -342,7 +354,18 @@ abstract contract OneProto is OneInchResolverHelpers {
_buyAmt: 0 _buyAmt: 0
}); });
_sellMulti(oneProtoData, getId, setId); oneProtoData = _sellMulti(oneProtoData, getId, setId);
_eventName = "LogSellMulti(address[],address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
tokens,
address(oneProtoData.buyToken),
address(oneProtoData.sellToken),
oneProtoData._buyAmt,
oneProtoData._sellAmt,
getId,
setId
);
} }
} }
@ -363,7 +386,7 @@ abstract contract OneInch is OneProto {
uint unitAmt, uint unitAmt,
bytes calldata callData, bytes calldata callData,
uint setId uint setId
) external payable { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
OneInchData memory oneInchData = OneInchData({ OneInchData memory oneInchData = OneInchData({
buyToken: TokenInterface(buyAddr), buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr), sellToken: TokenInterface(sellAddr),
@ -373,7 +396,10 @@ abstract contract OneInch is OneProto {
_buyAmt: 0 _buyAmt: 0
}); });
_sellThree(oneInchData, setId); oneInchData = _sellThree(oneInchData, setId);
_eventName = "LogSellThree(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(buyAddr, sellAddr, oneInchData._buyAmt, oneInchData._sellAmt, 0, setId);
} }
} }

View File

@ -8,20 +8,26 @@ abstract contract ChiResolver is Events, Helpers {
* @dev Mint CHI token. * @dev Mint CHI token.
* @param amt token amount to mint. * @param amt token amount to mint.
*/ */
function mint(uint amt) public payable { function mint(uint amt) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = amt == uint(-1) ? 140 : amt; uint _amt = amt == uint(-1) ? 140 : amt;
require(_amt <= 140, "Max minting is 140 chi"); require(_amt <= 140, "Max minting is 140 chi");
chi.mint(_amt); chi.mint(_amt);
_eventName = "LogMint(uint256)";
_eventParam = abi.encode(_amt);
} }
/** /**
* @dev burn CHI token. * @dev burn CHI token.
* @param amt token amount to burn. * @param amt token amount to burn.
*/ */
function burn(uint amt) public payable { function burn(uint amt) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = amt == uint(-1) ? chi.balanceOf(address(this)) : amt; uint _amt = amt == uint(-1) ? chi.balanceOf(address(this)) : amt;
chi.approve(address(chi), _amt); chi.approve(address(chi), _amt);
chi.free(_amt); chi.free(_amt);
_eventName = "LogBurn(uint256)";
_eventParam = abi.encode(_amt);
} }
} }
contract ConnectV2CHI is ChiResolver { contract ConnectV2CHI is ChiResolver {

View File

@ -227,7 +227,7 @@ abstract contract MakerResolver is Helpers, Events {
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogBorrow(uint256,bytes32,uint256,uint256,uint256)"; _eventName = "LogPayback(uint256,bytes32,uint256,uint256,uint256)";
_eventParam = abi.encode(_vault, ilk, _amt, getId, setId); _eventParam = abi.encode(_vault, ilk, _amt, getId, setId);
} }
@ -272,7 +272,7 @@ abstract contract MakerResolver is Helpers, Events {
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogBorrow(uint256,bytes32,uint256,uint256,uint256)"; _eventName = "LogWithdrawLiquidated(uint256,bytes32,uint256,uint256,uint256)";
_eventParam = abi.encode(vault, ilk, _amt, getId, setId); _eventParam = abi.encode(vault, ilk, _amt, getId, setId);
} }