Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Open

hack #245

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
94293a4
Register mock tokens in json database
PabiGamito Dec 19, 2020
0f7a68a
(feat) run compile prior running tests at package.json script
kartojal Feb 2, 2021
10cc590
Update package.json
shoenseiwaso Feb 7, 2021
b7aed31
feat(IAToken): add UNDERLYING_ASSET_ADDRESS function
PierrickGT Mar 15, 2021
44f8b40
Fix two scripts in package.json
Mar 16, 2021
7777d1d
replace with Add flag for verify on aave.dev.ts
Mar 16, 2021
242826d
ParaSwap adapter for collateral swaps
ColonelJ Mar 18, 2021
bf635b6
Merge branch 'master' into paraswap
ColonelJ Mar 18, 2021
2977296
Simplify ASM for copying revert reason
ColonelJ Mar 19, 2021
f9cf541
Added incentives data to ui helper
sendra Mar 23, 2021
83a499f
added incentives emission for a / v /s tokens
sendra Mar 26, 2021
2028631
fixed not needed casting
sendra Mar 26, 2021
ab8c9a2
fix typo in incentives controller env
kyzia551 Mar 26, 2021
e81ddb4
Added incentives information to UI data provider contract
sendra Mar 29, 2021
18b4c70
merged conflicts
sendra Mar 29, 2021
14e2ab4
Add task to deploy ParaSwapLiquiditySwapAdapter
ColonelJ Mar 29, 2021
99a0d17
reused local vars to not fill stack
sendra Mar 30, 2021
9ed3576
added public to incentives controller and price oracle so we can remo…
sendra Mar 30, 2021
516cbc7
updated deployment scripts
sendra Mar 30, 2021
5ba17aa
naming changed to IncentivesUserData
sendra Mar 30, 2021
b84a486
removed extra external calls that are not needed
sendra Apr 6, 2021
94a8b01
Fix example import in README
jarednielsen Apr 6, 2021
dc2943f
removed incentives data, as it is hardcoded on client side
sendra Apr 7, 2021
e01de3e
Merge branch 'fix/npm-i' of github.com:aave/protocol-v2 into feat/upd…
kartojal Apr 8, 2021
15d5566
fix deploy new asset bug
wenzhenxiang Apr 8, 2021
717bb13
added unclaimed user rewards
sendra Apr 8, 2021
e5b5ed5
Merge branch 'master' of github.com:aave/protocol-v2 into feat/update…
sendra Apr 8, 2021
e42304f
Merge pull request #71 from wenzhenxiang/master
The-3D Apr 8, 2021
c15cd9f
Merge pull request #69 from jarednielsen/patch-1
The-3D Apr 8, 2021
d4c73f9
Merge pull request #51 from PierrickGT/feat/iatoken_underlying_asset_…
The-3D Apr 8, 2021
051e3ae
Merge pull request #53 from l3lackcurtains/master
The-3D Apr 8, 2021
baeb455
Merge pull request #28 from curvegrid/noissue-ropsten-bug
The-3D Apr 8, 2021
a5ab0a6
added mumbai addresses
sendra Apr 9, 2021
f7fde94
updated with latest addresses
sendra Apr 9, 2021
1849484
updated with new mumbai addresses
sendra Apr 12, 2021
47b3d8f
new mumbai addresses
sendra Apr 12, 2021
94790ec
Fixed interface update
The-3D Apr 12, 2021
d5899dd
Merge pull request #73 from aave/fix/interface-inheritance
eboadom Apr 12, 2021
b0caaee
updated for latest mumbai addresses
sendra Apr 12, 2021
5e59623
feature: added emission end timestamp. Return struct instead, to save…
sendra Apr 16, 2021
5f817c7
fix: removed unused hardhat console import
Zer0dot Apr 19, 2021
6f57232
Merge pull request #79 from aave/fix/remove-unused-console-import
The-3D Apr 19, 2021
21fc210
fix: updated interface to last version
sendra Apr 19, 2021
360d37f
fix: updated mainnet task to deploy ui helper
sendra Apr 19, 2021
16a9292
- Fix typo on whitepaper
eboadom Apr 20, 2021
8000d83
Updated to new asset struct interface
sendra Apr 21, 2021
2a19131
feat: Updated to new interface of Incentives Controller
kartojal Apr 21, 2021
9df1502
correct mainnet incentives controller
sendra Apr 21, 2021
7ffb0e5
fix: Change the order of return variables of incentives getAssetData
kartojal Apr 22, 2021
ac88973
Merge pull request #80 from aave/fix/whitepaper-typo
The-3D Apr 23, 2021
3a10205
config: updated the reference fork to berlin
The-3D Apr 23, 2021
c46b393
config: updated package.json
The-3D Apr 23, 2021
46b48f3
Merge pull request #85 from aave/feat/berlin-config
eboadom Apr 23, 2021
e6f6fce
feat: add github actions to run tests at master and pull requests
kartojal Apr 23, 2021
a25b794
Merge pull request #86 from aave/feat/github-actions
The-3D Apr 23, 2021
7f88120
Added license badge
The-3D Apr 23, 2021
50b1a5f
Added "build" badge from Github Actions
kartojal Apr 23, 2021
ba51b6a
rename: Workflow name set to "Build" for better badge naming
kartojal Apr 23, 2021
aeae16b
readme: link Build badge to Github Actions
kartojal Apr 23, 2021
3683ebc
Merge pull request #87 from aave/feat/badge-build-pass
The-3D Apr 23, 2021
60dc234
fix: added try catch for incentives controller interactions
sendra Apr 26, 2021
42dc916
merged conflicts
sendra Apr 26, 2021
60ee0c5
fix: added check if incentives contract is 0
sendra Apr 26, 2021
701c079
fix: merged with master
sendra Apr 26, 2021
8b8736d
Back to try catch, but with also 0 address catching
sendra Apr 26, 2021
acc2207
added kovan config
sendra Apr 26, 2021
f5f3ade
removed error from catch so it catches everything
sendra Apr 26, 2021
d36b9fd
added other catch
sendra Apr 26, 2021
c1c2cff
remove try catch as it doesnt catch the implementation exeption
sendra Apr 26, 2021
4b8fabf
Merge pull request #4 from PabiGamito/master
The-3D Apr 27, 2021
644350c
Merge pull request #61 from aave/feat/update-dataproviderhelper-incen…
kyzia551 Apr 29, 2021
9b78daa
fix: fix kovan deployment. Prevent to init tokens without address. Ad…
kartojal May 7, 2021
57cc657
feat: Remove debug logs
kartojal May 7, 2021
607d3c9
tasks: Full migration scripts now deploys independent markets. Added …
kartojal May 7, 2021
e41a18c
fix: fixed logic of address provider registration
kartojal May 10, 2021
a895986
fix: local dev deployment
kartojal May 10, 2021
2cdfbbb
feat: Added support to fork any chain. Added deployment scripts to Gi…
kartojal May 10, 2021
2117e2c
misc: remove logs
kartojal May 10, 2021
9a699d5
misc: remove logs
kartojal May 10, 2021
e6a5ea0
ci: add env var usage
kartojal May 10, 2021
bb729b5
misc: do not change LendingPoolConfigurator old style
kartojal May 11, 2021
5076628
misc: do not change LendingPoolConfigurator old style
kartojal May 11, 2021
6c0bbad
Merge branch 'master' into feat/add-compile-prior-tests
kartojal May 11, 2021
4f7ce7e
Merge branch 'master' into polygon-verifier
kartojal May 11, 2021
e45dff5
Merge pull request #18 from kartojal/feat/add-compile-prior-tests
The-3D May 11, 2021
51c0cca
Merge branch 'master' into fix/101-support-registry-config
kartojal May 11, 2021
009752d
fix: typo at console.log
kartojal May 12, 2021
6312f9a
logs: organize logs at tenderly-utils.ts
kartojal May 12, 2021
b7462c6
feat: update UiPoolDataProvider task to match other tasks code style.…
kartojal May 12, 2021
095d5bf
typo: rename getWrappedNativeTokenddress to getWrappedNativeTokenAddress
kartojal May 12, 2021
8072db2
logs: remove unneeded debug log
kartojal May 12, 2021
3870182
Merge pull request #112 from aave/feat/ui-pool-data-provider-task
The-3D May 12, 2021
b4ed523
Merge pull request #68 from aave/polygon-verifier
The-3D May 12, 2021
37ba476
fix: solve conflicts from master
kartojal May 14, 2021
e15bdec
feat: remove deprecated task initialize-tokens
kartojal May 14, 2021
9b06eb1
feat: Improve readability of fork configuration. Support FORK_BLOCK_N…
kartojal May 14, 2021
2aeb420
Merge pull request #104 from aave/fix/101-support-registry-config
The-3D May 14, 2021
d6f92a6
feat: Add defender-relay-client dependency
miguelmtzinf May 17, 2021
329a48c
feat: Add defender utils and use of signer
miguelmtzinf May 17, 2021
93f9e6f
feat: Add DEFENDER env variables to docker yml
miguelmtzinf May 17, 2021
e6684bf
fix: Fix package-lock json
miguelmtzinf May 17, 2021
1d78df4
fix: Fix ts issue with DRE object
miguelmtzinf May 17, 2021
64d37bc
fix: Fix @tenderly/hardhat-tenderly to 1.1.0-beta.5
miguelmtzinf May 18, 2021
34c9bf2
fix: Fix typo of tenderlyRPC for tenderlyNetwork
miguelmtzinf May 18, 2021
83d2989
fix: Fix grammar typos on commments
miguelmtzinf May 18, 2021
53b2723
Merge pull request #126 from aave/feat/defender-integration
The-3D May 18, 2021
fe05cec
Use safeTransfer for rescueTokens
ColonelJ May 20, 2021
b13a01d
Rename _pullAToken function
ColonelJ May 20, 2021
11d0367
Explain code to overwrite fromAmount in comment
ColonelJ May 20, 2021
d26b1be
Fix _getDecimals function
ColonelJ May 20, 2021
5b45be6
Don't ignore return value of withdraw
ColonelJ May 20, 2021
afeb5fb
Remove _usePermit function
ColonelJ May 20, 2021
38bec94
Check lengths of all the arrays
ColonelJ May 20, 2021
bf7b19a
Add comments to empty constructor bodies
ColonelJ May 20, 2021
d8b8d50
Use better types than address
ColonelJ May 20, 2021
9d1cb50
Add reentrancy guard to adapter
ColonelJ May 20, 2021
4fe36c8
Introduce registry of valid Augustus addresses
ColonelJ May 20, 2021
6319733
added 0 address check in case we dont have incentives controller
sendra Jun 7, 2021
07ea0e6
pulled from master, and solved conflicts
sendra Jun 7, 2021
a6978ed
fix on deployment task
sendra Jun 8, 2021
191e5b4
case for when there is no user
sendra Jun 8, 2021
3d3e53a
correct matic oracle
sendra Jun 8, 2021
59e5bf4
updated comments
sendra Jun 14, 2021
0ec5e21
Add AugustusRegistry address
ColonelJ Jun 15, 2021
258a9be
Merge branch 'master' into paraswap
ColonelJ Jun 15, 2021
5f34943
fix incentives order
sendra Jun 16, 2021
4e3701c
Merge pull request #77 from aave/feat/incentives-end-emission
kyzia551 Jun 17, 2021
12896ff
add more functions to the UI data provider
kyzia551 Jun 17, 2021
7849be1
fix params order in getAssetData
kyzia551 Jun 17, 2021
b34499c
feat: added possibility to discard bytecode max size
dhadrien Jun 21, 2021
ca74be8
Merge pull request #163 from aave/feat/hardhat-unlimited-codsize
The-3D Jul 5, 2021
d51ac1d
temp fix for UIPoolDataProvider on polygon
kyzia551 Jul 14, 2021
79294d0
feat: support custom quote currencies. Added base scripts for custom …
kartojal Jul 14, 2021
6319f22
tests: fixed tests to support latest changes
kartojal Jul 14, 2021
a0a6210
feat: Add Avalanche network configuration
miguelmtzinf Jul 16, 2021
14fe2ba
feat: Add Avalanche market config
miguelmtzinf Jul 16, 2021
95e9c35
feat: support custom quote currencies. Added base scripts for custom …
kartojal Jul 14, 2021
4b217ff
tests: fixed tests to support latest changes
kartojal Jul 14, 2021
d460ab4
Merge remote-tracking branch 'origin/feat/usd-quote' into feat/188-av…
miguelmtzinf Jul 16, 2021
0e7bc49
feat: Replace AaveOracle to the latest version. Fix dev deployment sc…
kartojal Jul 20, 2021
8d359e1
feat: Add fixes to the avalanche deployment
miguelmtzinf Jul 21, 2021
9982cdd
feat: Update latest addresses of Avalanche market
miguelmtzinf Jul 21, 2021
025a988
add poligon related temp hacks
kyzia551 Jul 26, 2021
9bca403
Merge branch 'feat/188-avalanche-usd-quote' into feat/188-avalanche-m…
miguelmtzinf Jul 30, 2021
9959589
feat: Add latest changes
miguelmtzinf Jul 30, 2021
3119882
fix: Disable USDT as collateral
miguelmtzinf Aug 17, 2021
19cc58f
fix: Fix harcoded gas limit value on helpers
miguelmtzinf Aug 17, 2021
a000ed9
fix: Fix comments and ts style warnings
miguelmtzinf Aug 17, 2021
d9f7caf
fix: Update avalanche market addreses
miguelmtzinf Aug 17, 2021
90d5133
fix: Fix package json script for market deployment
miguelmtzinf Aug 18, 2021
6d7be2f
fix: Fix Avalanche deployment params
miguelmtzinf Aug 24, 2021
e82ea5a
feat: Add AVAX token to Fuji deployment
miguelmtzinf Aug 24, 2021
8e3df61
feat: Add FUJI Incentives Controller Address
miguelmtzinf Aug 24, 2021
df64cbe
feat: Add latest FUJI deployment addresses
miguelmtzinf Aug 24, 2021
b27092b
Merge branch 'feat/split-ui-dataprovider-logic' of github.com:aave/pr…
kartojal Aug 24, 2021
26a296f
Merge branch 'feat/188-avalanche-market' of github.com:aave/protocol-…
kartojal Aug 24, 2021
2d3bcf2
feat: update uipooldataprovider task config
kartojal Aug 24, 2021
984e19c
config: revised risk config
kartojal Aug 27, 2021
a7a54b5
fix: fix RPC url for avalanche mainnet
kartojal Aug 27, 2021
ccb43f0
Merge pull request #55 from paraswap/paraswap
eboadom Sep 1, 2021
2428502
feat: Revised Avalanche configs. Add UiPoolDataProvider helper to dep…
kartojal Sep 20, 2021
dc65b0b
Merge branch 'master' into feat/188-avalanche-market
kartojal Sep 20, 2021
a733710
config: adjusted risk parameters for avalanche
kartojal Sep 20, 2021
7686954
Merge branch 'feat/188-avalanche-market' of github.com:aave/protocol-…
kartojal Sep 20, 2021
153f869
config: Added ReserveFactor address
kartojal Sep 20, 2021
c0caf65
feat: pause Pool at deployment scripts
kartojal Sep 20, 2021
1bbd0a8
Release Deployment#001
kartojal Sep 20, 2021
58556fc
config: Update risk parameters
kartojal Sep 28, 2021
03c5253
fix: Fix error at mumbai config
miguelmtzinf Sep 29, 2021
69c826b
fix: Add addresses to mumbai market config
miguelmtzinf Sep 29, 2021
8238da7
fix: Fix matic market config details
miguelmtzinf Sep 29, 2021
b026a93
fix: Fix mtic market config details
miguelmtzinf Sep 30, 2021
4bded30
Merge pull request #225 from aave/fix/fix-matic-market-config
The-3D Sep 30, 2021
4dea9b3
feat: fixed underlying symbol for avalanche
sendra Oct 4, 2021
9c4fef5
Merge branch 'feat/avalanche-fix-uiprovider' of github.com:aave/proto…
kartojal Oct 4, 2021
d33b3c5
fix: fixed incentive controller order
sendra Oct 4, 2021
52e03fc
feat: add config for ui pool data provider deployment
kartojal Oct 4, 2021
dab9f72
Merge branch 'fix/wrong-controller-order' of github.com:aave/protocol…
kartojal Oct 4, 2021
de1ab95
fix: fixed order
sendra Oct 4, 2021
c49bac2
fix: missing commas at UiPoolDataProvider.sol
kartojal Oct 4, 2021
de2e710
feat: new getter
sendra Oct 4, 2021
02016dc
fix: remove comments and indentation
kartojal Oct 4, 2021
41b300a
config: adjust gas price for Avalanche
kartojal Oct 5, 2021
59ed739
added underlying symbol
sendra Oct 5, 2021
1adbcde
Merge branch 'feat/188-avalanche-market' of github.com:aave/protocol-…
sendra Oct 5, 2021
a129c65
ci: remove kovan step due doesnt support tx type 2
kartojal Oct 6, 2021
7b88c4f
Merge pull request #228 from aave/ci/remove-kovan-step
The-3D Oct 6, 2021
60f0488
Merge branch 'master' of github.com:aave/protocol-v2 into feat/188-av…
kartojal Oct 6, 2021
fa1f134
fix: load the EmergencyAdmin before pausing the pool at 2_lending_poo…
kartojal Oct 6, 2021
c1ada1c
Merge pull request #220 from aave/feat/188-avalanche-market
The-3D Oct 7, 2021
2b883e4
fix: Adapt code to support >128 reserves
LHerskind Nov 24, 2021
68d5980
test: Add test with >128 reserves
LHerskind Nov 24, 2021
e558db4
Merge pull request #251 from aave/fix/249-markets-with-more-assets
kartojal Nov 29, 2021
67aefa8
feat: added UiPoolDataProvider V2 with eth markets oracle case
sendra Dec 6, 2021
0895e6f
feat: added all helper versions
sendra Dec 17, 2021
d998c2f
Merge pull request #254 from aave/feat/UiPoolDataProviderV2-ethbased
kartojal Dec 17, 2021
138446b
fix: Revert reserves cap change due breaking change at ILendingPool i…
kartojal Jan 10, 2022
61c2273
Merge pull request #264 from aave/revert/reserves-cap
LHerskind Jan 10, 2022
049c84e
feat: added new fields needed for client calculations
sendra Feb 3, 2022
3f9ab86
fix: added newline
sendra Feb 3, 2022
f0fe26e
feat: added new rates fields
sendra Feb 4, 2022
2bbccd4
Merge branch 'master' of github.com:aave/protocol-v2 into feat/UiPool…
kartojal Feb 10, 2022
84fa41e
fix: return name on uipooldataprovider
sakulstra Jul 15, 2022
5df59ec
Merge pull request #300 from sakulstra/fix/return-name
kartojal Jul 18, 2022
637cd80
Merge pull request #272 from aave/feat/UiPoolDataProvider-optimalUtil…
kartojal Aug 9, 2022
742a826
feat: improve deploy scripts
kartojal Aug 9, 2022
f907950
fix: support deploy of ui helpers in fork mode
kartojal Aug 9, 2022
b172dbe
Merge pull request #305 from aave/fix/deploy-fork-ci
kartojal Aug 9, 2022
c26d157
Merge branch 'master' into feat/deploy-improvement
kartojal Aug 9, 2022
75d75e4
feat: add goerli constants for ui helpers
kartojal Aug 9, 2022
0799fbf
chore: use same package-lock
kartojal Aug 9, 2022
a48933b
feat: remove npm cache, adapt tests
kartojal Aug 9, 2022
365b039
fix: uncommented dev deployment and fix typpings
kartojal Aug 10, 2022
228c0bb
fix: use emergency admin for unpausing in prod deployment
kartojal Aug 10, 2022
0829f97
Merge pull request #306 from aave/feat/deploy-improvement
kartojal Aug 10, 2022
005b171
feat: added flashLoanEnabled flag
sendra Dec 21, 2022
e705472
fix: return true by default
sendra Dec 22, 2022
495dcc3
fix: add missing property
grothem Jan 6, 2023
a2ccdb1
bump hardhat etherscan and mock aggregators
foodaka Jan 10, 2023
17843d9
resolve ethereumjs dependency
foodaka Jan 10, 2023
cdfe06a
remove resolution
foodaka Jan 10, 2023
87121b5
bump lock
foodaka Jan 10, 2023
ce53c4a
Merge pull request #324 from aave/feat/flashloanable-flag
grothem Jan 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Test
run: npm run ci:test
- name: Dev deployment
run: npm run aave:evm:dev:migration
- name: Mainnet deployment at Mainnet fork
run: npm run aave:fork:main
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
- name: Amm deployment at Mainnet fork
run: npm run amm:fork:main
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
# - name: Coverage
# run: npm run coverage
# - uses: codecov/codecov-action@v1
# with:
# fail_ci_if_error: true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Build pass](https://github.com/AAVE/protocol-v2/actions/workflows/node.js.yml/badge.svg)](https://github.com/aave/protocol-v2/actions/workflows/node.js.yml)
```
.///. .///. //. .// `/////////////-
`++:++` .++:++` :++` `++: `++:......---.`
Expand Down Expand Up @@ -53,8 +55,8 @@ import {ILendingPool} from "@aave/protocol-v2/contracts/interfaces/ILendingPool.

contract Misc {

function deposit(address pool, address token, address user, uint256 amount) {
ILendingPool(pool).deposit(token, amount, user, '0');
function deposit(address pool, address token, address user, uint256 amount) public {
ILendingPool(pool).deposit(token, amount, user, 0);
{...}
}
}
Expand Down
Binary file modified aave-v2-whitepaper.pdf
Binary file not shown.
122 changes: 122 additions & 0 deletions contracts/adapters/BaseParaSwapAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import {SafeMath} from '../dependencies/openzeppelin/contracts/SafeMath.sol';
import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol';
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {DataTypes} from '../protocol/libraries/types/DataTypes.sol';
import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';
import {IERC20WithPermit} from '../interfaces/IERC20WithPermit.sol';
import {FlashLoanReceiverBase} from '../flashloan/base/FlashLoanReceiverBase.sol';

/**
* @title BaseParaSwapAdapter
* @notice Utility functions for adapters using ParaSwap
* @author Jason Raymond Bell
*/
abstract contract BaseParaSwapAdapter is FlashLoanReceiverBase, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using SafeERC20 for IERC20Detailed;
using SafeERC20 for IERC20WithPermit;

struct PermitSignature {
uint256 amount;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}

// Max slippage percent allowed
uint256 public constant MAX_SLIPPAGE_PERCENT = 3000; // 30%

IPriceOracleGetter public immutable ORACLE;

event Swapped(address indexed fromAsset, address indexed toAsset, uint256 fromAmount, uint256 receivedAmount);

constructor(
ILendingPoolAddressesProvider addressesProvider
) public FlashLoanReceiverBase(addressesProvider) {
ORACLE = IPriceOracleGetter(addressesProvider.getPriceOracle());
}

/**
* @dev Get the price of the asset from the oracle denominated in eth
* @param asset address
* @return eth price for the asset
*/
function _getPrice(address asset) internal view returns (uint256) {
return ORACLE.getAssetPrice(asset);
}

/**
* @dev Get the decimals of an asset
* @return number of decimals of the asset
*/
function _getDecimals(IERC20Detailed asset) internal view returns (uint8) {
uint8 decimals = asset.decimals();
// Ensure 10**decimals won't overflow a uint256
require(decimals <= 77, 'TOO_MANY_DECIMALS_ON_TOKEN');
return decimals;
}

/**
* @dev Get the aToken associated to the asset
* @return address of the aToken
*/
function _getReserveData(address asset) internal view returns (DataTypes.ReserveData memory) {
return LENDING_POOL.getReserveData(asset);
}

/**
* @dev Pull the ATokens from the user
* @param reserve address of the asset
* @param reserveAToken address of the aToken of the reserve
* @param user address
* @param amount of tokens to be transferred to the contract
* @param permitSignature struct containing the permit signature
*/
function _pullATokenAndWithdraw(
address reserve,
IERC20WithPermit reserveAToken,
address user,
uint256 amount,
PermitSignature memory permitSignature
) internal {
// If deadline is set to zero, assume there is no signature for permit
if (permitSignature.deadline != 0) {
reserveAToken.permit(
user,
address(this),
permitSignature.amount,
permitSignature.deadline,
permitSignature.v,
permitSignature.r,
permitSignature.s
);
}

// transfer from user to adapter
reserveAToken.safeTransferFrom(user, address(this), amount);

// withdraw reserve
require(
LENDING_POOL.withdraw(reserve, amount, address(this)) == amount,
'UNEXPECTED_AMOUNT_WITHDRAWN'
);
}

/**
* @dev Emergency rescue for token stucked on this contract, as failsafe mechanism
* - Funds should never remain in this contract more time than during transactions
* - Only callable by the owner
*/
function rescueTokens(IERC20 token) external onlyOwner {
token.safeTransfer(owner(), token.balanceOf(address(this)));
}
}
109 changes: 109 additions & 0 deletions contracts/adapters/BaseParaSwapSellAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol';
import {PercentageMath} from '../protocol/libraries/math/PercentageMath.sol';
import {IParaSwapAugustus} from '../interfaces/IParaSwapAugustus.sol';
import {IParaSwapAugustusRegistry} from '../interfaces/IParaSwapAugustusRegistry.sol';
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';

/**
* @title BaseParaSwapSellAdapter
* @notice Implements the logic for selling tokens on ParaSwap
* @author Jason Raymond Bell
*/
abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
using PercentageMath for uint256;

IParaSwapAugustusRegistry public immutable AUGUSTUS_REGISTRY;

constructor(
ILendingPoolAddressesProvider addressesProvider,
IParaSwapAugustusRegistry augustusRegistry
) public BaseParaSwapAdapter(addressesProvider) {
// Do something on Augustus registry to check the right contract was passed
require(!augustusRegistry.isValidAugustus(address(0)));
AUGUSTUS_REGISTRY = augustusRegistry;
}

/**
* @dev Swaps a token for another using ParaSwap
* @param fromAmountOffset Offset of fromAmount in Augustus calldata if it should be overwritten, otherwise 0
* @param swapCalldata Calldata for ParaSwap's AugustusSwapper contract
* @param augustus Address of ParaSwap's AugustusSwapper contract
* @param assetToSwapFrom Address of the asset to be swapped from
* @param assetToSwapTo Address of the asset to be swapped to
* @param amountToSwap Amount to be swapped
* @param minAmountToReceive Minimum amount to be received from the swap
* @return amountReceived The amount received from the swap
*/
function _sellOnParaSwap(
uint256 fromAmountOffset,
bytes memory swapCalldata,
IParaSwapAugustus augustus,
IERC20Detailed assetToSwapFrom,
IERC20Detailed assetToSwapTo,
uint256 amountToSwap,
uint256 minAmountToReceive
) internal returns (uint256 amountReceived) {
require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS');

{
uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom);
uint256 toAssetDecimals = _getDecimals(assetToSwapTo);

uint256 fromAssetPrice = _getPrice(address(assetToSwapFrom));
uint256 toAssetPrice = _getPrice(address(assetToSwapTo));

uint256 expectedMinAmountOut =
amountToSwap
.mul(fromAssetPrice.mul(10**toAssetDecimals))
.div(toAssetPrice.mul(10**fromAssetDecimals))
.percentMul(PercentageMath.PERCENTAGE_FACTOR - MAX_SLIPPAGE_PERCENT);

require(expectedMinAmountOut <= minAmountToReceive, 'MIN_AMOUNT_EXCEEDS_MAX_SLIPPAGE');
}

uint256 balanceBeforeAssetFrom = assetToSwapFrom.balanceOf(address(this));
require(balanceBeforeAssetFrom >= amountToSwap, 'INSUFFICIENT_BALANCE_BEFORE_SWAP');
uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this));

address tokenTransferProxy = augustus.getTokenTransferProxy();
assetToSwapFrom.safeApprove(tokenTransferProxy, 0);
assetToSwapFrom.safeApprove(tokenTransferProxy, amountToSwap);

if (fromAmountOffset != 0) {
// Ensure 256 bit (32 bytes) fromAmount value is within bounds of the
// calldata, not overlapping with the first 4 bytes (function selector).
require(fromAmountOffset >= 4 &&
fromAmountOffset <= swapCalldata.length.sub(32),
'FROM_AMOUNT_OFFSET_OUT_OF_RANGE');
// Overwrite the fromAmount with the correct amount for the swap.
// In memory, swapCalldata consists of a 256 bit length field, followed by
// the actual bytes data, that is why 32 is added to the byte offset.
assembly {
mstore(add(swapCalldata, add(fromAmountOffset, 32)), amountToSwap)
}
}
(bool success,) = address(augustus).call(swapCalldata);
if (!success) {
// Copy revert reason from call
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
require(assetToSwapFrom.balanceOf(address(this)) == balanceBeforeAssetFrom - amountToSwap, 'WRONG_BALANCE_AFTER_SWAP');
amountReceived = assetToSwapTo.balanceOf(address(this)).sub(balanceBeforeAssetTo);
require(amountReceived >= minAmountToReceive, 'INSUFFICIENT_AMOUNT_RECEIVED');

emit Swapped(
address(assetToSwapFrom),
address(assetToSwapTo),
amountToSwap,
amountReceived
);
}
}
Loading
Loading