Last active
July 30, 2024 21:14
-
-
Save Turupawn/382567383afbde8ddae3954d3d00dc3c to your computer and use it in GitHub Desktop.
DeFi Ethereum Argentina
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
library DataTypes { | |
struct ReserveConfigurationMap { | |
uint256 data; | |
} | |
struct ReserveData { | |
ReserveConfigurationMap configuration; | |
uint128 liquidityIndex; | |
uint128 currentLiquidityRate; | |
uint128 variableBorrowIndex; | |
uint128 currentVariableBorrowRate; | |
uint128 currentStableBorrowRate; | |
uint40 lastUpdateTimestamp; | |
uint16 id; | |
address aTokenAddress; | |
address stableDebtTokenAddress; | |
address variableDebtTokenAddress; | |
address interestRateStrategyAddress; | |
uint128 accruedToTreasury; | |
uint128 unbacked; | |
uint128 isolationModeTotalDebt; | |
} | |
} | |
interface IPool { | |
function borrow( | |
address asset, | |
uint256 amount, | |
uint256 interestRateMode, // 1 for Stable, 2 for Variable | |
uint16 referralCode, | |
address onBehalfOf) external; | |
function supply( | |
address asset, | |
uint256 amount, | |
address onBehalfOf, | |
uint16 referralCode) external; | |
function withdraw( | |
address asset, | |
uint256 amount, | |
address to) external returns (uint256); | |
function getReserveData( | |
address asset) external view returns (DataTypes.ReserveData memory); | |
} | |
interface IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function approve(address spender, uint256 value) external returns (bool); | |
function transferFrom(address from, address to, uint256 value) external returns (bool); | |
} | |
contract AaveLender { | |
address public immutable AAVE_POOL_ADDRESS; | |
address public immutable STAKED_TOKEN_ADDRESS; | |
address public immutable ATOKEN_ADDRESS; | |
address public immutable OWNER; | |
mapping(address account => uint amount) public stakeByAccount; | |
uint public totalStake; | |
// Ejemplo en Scroll Sepolia | |
// Pool Address | |
// 0x48914C788295b5db23aF2b5F0B3BE775C4eA9440 | |
// DAI | |
// 0x7984E363c38b590bB4CA35aEd5133Ef2c6619C40 | |
// check at https://app.aave.com/ | |
constructor(address aavePoolAddress, address stakedTokenAddress) { | |
AAVE_POOL_ADDRESS = aavePoolAddress; | |
STAKED_TOKEN_ADDRESS = stakedTokenAddress; | |
OWNER = msg.sender; | |
ATOKEN_ADDRESS = IPool(aavePoolAddress).getReserveData(stakedTokenAddress).aTokenAddress; | |
} | |
function stake(uint amount) public { | |
totalStake += amount; | |
stakeByAccount[msg.sender] += amount; | |
IERC20(STAKED_TOKEN_ADDRESS).transferFrom(msg.sender, address(this), amount); | |
IERC20(STAKED_TOKEN_ADDRESS).approve(AAVE_POOL_ADDRESS, amount); | |
IPool(AAVE_POOL_ADDRESS).supply( | |
STAKED_TOKEN_ADDRESS, | |
amount, | |
address(this), | |
0); | |
} | |
function unstake(uint amount) public { | |
require(amount <= stakeByAccount[msg.sender], "Not enough stake"); | |
totalStake -= amount; | |
stakeByAccount[msg.sender] -= amount; | |
IPool(AAVE_POOL_ADDRESS).withdraw( | |
STAKED_TOKEN_ADDRESS, | |
amount, | |
msg.sender | |
); | |
} | |
function yieldEarned() public view returns(uint){ | |
return IERC20(ATOKEN_ADDRESS).balanceOf(address(this)) - totalStake; | |
} | |
function withdraw(uint amount) public { | |
require(msg.sender == OWNER, "Sender is not owner"); | |
require(amount <= yieldEarned(), "Maximum withdraw exceeded"); | |
IPool(AAVE_POOL_ADDRESS).withdraw( | |
STAKED_TOKEN_ADDRESS, | |
amount, | |
msg.sender | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | |
contract DataConsumerV3 { | |
AggregatorV3Interface internal dataFeed; | |
constructor() { | |
dataFeed = AggregatorV3Interface( | |
0x87dce67002e66C17BC0d723Fe20D736b80CAaFda | |
); | |
} | |
function getChainlinkDataFeedLatestAnswer() public view returns (int) { | |
// prettier-ignore | |
( | |
/* uint80 roundID */, | |
int answer, | |
/*uint startedAt*/, | |
/*uint timeStamp*/, | |
/*uint80 answeredInRound*/ | |
) = dataFeed.latestRoundData(); | |
return answer; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////// | |
//EAS | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.24; | |
import { IEAS, AttestationRequest, AttestationRequestData, RevocationRequest, RevocationRequestData } from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol"; | |
import { NO_EXPIRATION_TIME, EMPTY_UID } from "@ethereum-attestation-service/eas-contracts/contracts/Common.sol"; | |
contract EASDemo | |
{ | |
address easAddress = 0xaEF4103A04090071165F78D45D83A0C0782c2B2a; | |
bytes32 schema = 0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a; | |
// check at https://scroll-sepolia.easscan.org/schema/view/0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a | |
function sendIsFriend(address to, bool isFriend) public returns(bytes32) | |
{ | |
return IEAS(easAddress).attest( | |
AttestationRequest({ | |
schema: schema, | |
data: AttestationRequestData({ | |
recipient: to, | |
expirationTime: NO_EXPIRATION_TIME, | |
revocable: false, | |
refUID: EMPTY_UID, | |
data: abi.encode(isFriend), | |
value: 0 // No value/ETH | |
}) | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment