mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
Add events
This commit is contained in:
parent
00ab0f7bff
commit
1d2725f36a
13
contracts/implementations/aave-v2-migrator/events.sol
Normal file
13
contracts/implementations/aave-v2-migrator/events.sol
Normal file
|
@ -0,0 +1,13 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Events {
|
||||
event LogMigrateAaveV2(
|
||||
address indexed owner,
|
||||
address[] supplyTokens,
|
||||
address[] borrowTokens,
|
||||
uint[] supplyAmts,
|
||||
uint[] variableBorrowAmts,
|
||||
uint[] stableBorrowAmts
|
||||
);
|
||||
}
|
|
@ -4,8 +4,9 @@ pragma experimental ABIEncoderV2;
|
|||
import { TokenInterface, AccountInterface } from "../../common/interfaces.sol";
|
||||
import { AaveInterface, ReceiverInterface, AaveData } from "./interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
contract AaveMigratorResolver is Helpers {
|
||||
contract AaveMigratorResolver is Helpers, Events {
|
||||
ReceiverInterface public immutable receiver;
|
||||
|
||||
constructor(address _receiver) {
|
||||
|
|
16
contracts/receivers/aave-v2-receiver/events.sol
Normal file
16
contracts/receivers/aave-v2-receiver/events.sol
Normal file
|
@ -0,0 +1,16 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(
|
||||
address owner,
|
||||
address[] tokens,
|
||||
uint[] amts
|
||||
);
|
||||
|
||||
event LogWithdraw(
|
||||
address owner,
|
||||
address[] tokens,
|
||||
uint[] amts
|
||||
);
|
||||
}
|
|
@ -6,8 +6,9 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { AccountInterface } from "./interfaces.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
contract MigrateResolver is DSMath {
|
||||
contract MigrateResolver is DSMath, Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
struct AaveData {
|
||||
|
@ -20,25 +21,15 @@ contract MigrateResolver is DSMath {
|
|||
address[] borrowTokens;
|
||||
}
|
||||
|
||||
uint private lastStateId;
|
||||
mapping (address => AaveData) public positions;
|
||||
mapping(address => mapping(address => uint)) deposits;
|
||||
|
||||
function _migratePosition(address owner) internal {
|
||||
AaveData storage data = positions[owner];
|
||||
|
||||
for (uint i = 0; i < data.supplyTokens.length; i++) {
|
||||
IERC20(data.supplyTokens[i]).safeTransfer(data.targetDsa, data.supplyAmts[i]);
|
||||
}
|
||||
|
||||
AccountInterface(data.targetDsa).migrateAave(owner);
|
||||
data.isFinal = true;
|
||||
}
|
||||
|
||||
function deposit(address[] calldata tokens, uint[] calldata amts) external {
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
address _token = tokens[i];
|
||||
|
||||
|
@ -47,13 +38,18 @@ contract MigrateResolver is DSMath {
|
|||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
|
||||
deposits[msg.sender][_token] = _amt;
|
||||
_amts[i] = _amt;
|
||||
}
|
||||
|
||||
emit LogDeposit(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
function withdraw(address[] calldata tokens, uint[] calldata amts) external {
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
uint _amt = amts[i];
|
||||
address _token = tokens[i];
|
||||
|
@ -66,6 +62,44 @@ contract MigrateResolver is DSMath {
|
|||
IERC20(_token).safeTransfer(msg.sender, _amt);
|
||||
|
||||
deposits[msg.sender][_token] = sub(maxAmt, _amt);
|
||||
|
||||
_amts[i] = _amt;
|
||||
}
|
||||
|
||||
emit LogWithdraw(msg.sender, tokens, _amts);
|
||||
}
|
||||
}
|
||||
|
||||
contract AaveV2Migrator is MigrateResolver {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
uint private lastStateId;
|
||||
|
||||
function _migratePosition(address owner) internal {
|
||||
AaveData storage data = positions[owner];
|
||||
|
||||
for (uint i = 0; i < data.supplyTokens.length; i++) {
|
||||
IERC20(data.supplyTokens[i]).safeTransfer(data.targetDsa, data.supplyAmts[i]);
|
||||
}
|
||||
|
||||
AccountInterface(data.targetDsa).migrateAave(owner);
|
||||
data.isFinal = true;
|
||||
}
|
||||
|
||||
function getPosition(address owner) public view returns (AaveData memory data) {
|
||||
data = positions[owner];
|
||||
}
|
||||
|
||||
function canMigrate(address owner) public view returns (bool can) {
|
||||
can = true;
|
||||
|
||||
AaveData memory data = getPosition(owner);
|
||||
|
||||
for (uint i = 0; i < data.supplyTokens.length; i++) {
|
||||
IERC20 token = IERC20(data.supplyTokens[i]);
|
||||
if (token.balanceOf(address(this)) < data.supplyAmts[i]) {
|
||||
can = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,21 +121,4 @@ contract MigrateResolver is DSMath {
|
|||
|
||||
_migratePosition(owner);
|
||||
}
|
||||
|
||||
function getPosition(address owner) public view returns (AaveData memory data) {
|
||||
data = positions[owner];
|
||||
}
|
||||
|
||||
function canMigrate(address owner) public view returns (bool can) {
|
||||
can = true;
|
||||
|
||||
AaveData memory data = getPosition(owner);
|
||||
|
||||
for (uint i = 0; i < data.supplyTokens.length; i++) {
|
||||
IERC20 token = IERC20(data.supplyTokens[i]);
|
||||
if (token.balanceOf(address(this)) < data.supplyAmts[i]) {
|
||||
can = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
contracts/senders/aave-v2-migrator/events.sol
Normal file
26
contracts/senders/aave-v2-migrator/events.sol
Normal file
|
@ -0,0 +1,26 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(
|
||||
address owner,
|
||||
address[] tokens,
|
||||
uint[] amts
|
||||
);
|
||||
|
||||
event LogWithdraw(
|
||||
address owner,
|
||||
address[] tokens,
|
||||
uint[] amts
|
||||
);
|
||||
|
||||
event LogAaveV2Migrate(
|
||||
address indexed user,
|
||||
address indexed targetDsa,
|
||||
address[] supplyTokens,
|
||||
address[] borrowTokens,
|
||||
uint[] supplyAmts,
|
||||
uint[] variableBorrowAmts,
|
||||
uint[] stableBorrowAmts
|
||||
);
|
||||
}
|
|
@ -7,8 +7,9 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { AaveInterface, ATokenInterface } from "./interfaces.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
contract LiquidityResolver is Helpers {
|
||||
contract LiquidityResolver is Helpers, Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
mapping(address => mapping(address => uint)) deposits;
|
||||
|
@ -17,6 +18,8 @@ contract LiquidityResolver is Helpers {
|
|||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
uint _amt;
|
||||
address _token = tokens[i];
|
||||
|
@ -31,14 +34,20 @@ contract LiquidityResolver is Helpers {
|
|||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
}
|
||||
|
||||
_amts[i] = _amt;
|
||||
|
||||
deposits[msg.sender][_token] = _amt;
|
||||
}
|
||||
|
||||
emit LogDeposit(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
function withdraw(address[] calldata tokens, uint[] calldata amts) external {
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
uint _amt = amts[i];
|
||||
address _token = tokens[i];
|
||||
|
@ -55,8 +64,12 @@ contract LiquidityResolver is Helpers {
|
|||
IERC20(_token).safeTransfer(msg.sender, _amt);
|
||||
}
|
||||
|
||||
_amts[i] = _amt;
|
||||
|
||||
deposits[msg.sender][_token] = sub(maxAmt, _amt);
|
||||
}
|
||||
|
||||
emit LogWithdraw(msg.sender, tokens, _amts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,5 +153,15 @@ contract MigrateResolver is LiquidityResolver {
|
|||
positions[owner] = data;
|
||||
bytes memory positionData = abi.encode(owner, data);
|
||||
stateSender.syncState(polygonReceiver, positionData);
|
||||
|
||||
emit LogAaveV2Migrate(
|
||||
msg.sender,
|
||||
targetDsa,
|
||||
supplyTokens,
|
||||
borrowTokens,
|
||||
data.supplyAmts,
|
||||
data.variableBorrowAmts,
|
||||
data.stableBorrowAmts
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user