Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aave ParaSwap Adapters #27

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ node_modules

# ignore foundry deploy artifacts
broadcast/

237 changes: 214 additions & 23 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[profile.default]
src = 'src'
test = 'tests'
script = 'scripts'
src = 'src/contracts'
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
test = 'src/tests'
script = 'src/script'
out = 'out'
libs = ['lib']
remappings = [
Expand Down
2 changes: 1 addition & 1 deletion lib/aave-address-book
Submodule aave-address-book updated 218 files
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"prettier-plugin-solidity": "^1.0.0-beta.19"
},
"dependencies": {
"@paraswap/sdk": "^6.2.1",
"@paraswap/sdk": "^6.4.0",
"axios": "^1.1.3",
"ethers": "^5.7.2",
"object-hash": "^3.0.0"
Expand Down
24 changes: 13 additions & 11 deletions scripts/psp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const FROM_DECIMALS = Number(args[8]);
const TO_DECIMALS = Number(args[9]);
// param only needed for the hash
// const BLOCK_NUMBER = Number(args[10]);
const UPDATE_PSP_CACHE = args[11] !== "false";

// generate a hash for input parameters to cache response and not spam psp sdk
const hash = objectHash(args);
Expand Down Expand Up @@ -60,11 +61,11 @@ function augustusFromAmountOffsetFromCalldata(calldata) {
case "0x19fc5be0": // directBalancerV2GivenOutSwap
return 68; // 4 + 2 * 32
case "0x3865bde6": // directCurveV1Swap
return 68; // 4 + 2 * 32
return 132; // 4 + 4 * 32
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
case "0x58f15100": // directCurveV2Swap
return 68; // 4 + 2 * 32
case "0xa6866da9": // directUniV3Swap
return 68; // 4 + 2 * 32
case "0xa6886da9": // directUniV3Swap
return 132; // 4 + 4 * 32
default:
throw new Error("Unrecognized function selector for Augustus");
}
Expand All @@ -91,17 +92,17 @@ const augustusToAmountOffsetFromCalldata = (calldata) => {

async function main(from, to, method, amount, user) {
// check cache and return cache if available
const filePath = path.join(process.cwd(), "tests/pspcache", hash);
const filePath = path.join(process.cwd(), "src/tests/.pspcache", hash);
if (fs.existsSync(filePath)) {
const file = fs.readFileSync(filePath);
process.stdout.write(file);
return;
}
// distinguish between exactOut and exactInoutdMethod
const excludedMethod =
// distinguish between exactOut and exactInOutMethod
const preferredMethods =
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
method === "SELL"
? [ContractMethod.simpleSwap]
: [ContractMethod.simpleBuy, ContractMethod.directUniV3Buy];
? [ContractMethod.multiSwap, ContractMethod.megaSwap]
: [ContractMethod.buy];
const priceRoute = await paraSwapMin.swap.getRate({
srcToken: from,
srcDecimals: FROM_DECIMALS,
Expand All @@ -112,7 +113,7 @@ async function main(from, to, method, amount, user) {
...(MAX
? {
options: {
excludeContractMethods: [...excludedMethod],
includeContractMethods: [...preferredMethods],
},
}
: {}),
Expand Down Expand Up @@ -158,8 +159,9 @@ async function main(from, to, method, amount, user) {
["(address,bytes,uint256,uint256,uint256)"],
[[txParams.to, txParams.data, srcAmount, destAmount, offset]]
);

fs.writeFileSync(filePath, encodedData);
if (UPDATE_PSP_CACHE) {
fs.writeFileSync(filePath, encodedData);
}
process.stdout.write(encodedData);
}
main(FROM, TO, METHOD, AMOUNT, USER_ADDRESS);
104 changes: 0 additions & 104 deletions src/contracts/BaseParaSwapAdapter.sol

This file was deleted.

15 changes: 11 additions & 4 deletions src/contracts/ParaSwapDebtSwapAdapterV2.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {ParaSwapDebtSwapAdapter} from './ParaSwapDebtSwapAdapter.sol';
import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IParaSwapAugustusRegistry} from '../interfaces/IParaSwapAugustusRegistry.sol';
import {DataTypes, ILendingPool} from 'aave-address-book/AaveV2.sol';
import {IParaSwapAugustusRegistry} from './dependencies/paraswap/IParaSwapAugustusRegistry.sol';
import {BaseParaSwapAdapter} from './base/BaseParaSwapAdapter.sol';
import {ParaSwapDebtSwapAdapter} from './base/ParaSwapDebtSwapAdapter.sol';

/**
* @title ParaSwapDebtSwapAdapter
Expand All @@ -17,9 +18,14 @@ contract ParaSwapDebtSwapAdapterV2 is ParaSwapDebtSwapAdapter {
address pool,
IParaSwapAugustusRegistry augustusRegistry,
address owner
) ParaSwapDebtSwapAdapter(addressesProvider, pool, augustusRegistry, owner) {}
) ParaSwapDebtSwapAdapter(addressesProvider, pool, augustusRegistry, owner) {
// Intentionally left blank
}

function _getReserveData(address asset) internal view override returns (address, address, address) {
/// @inheritdoc BaseParaSwapAdapter
function _getReserveData(
address asset
) internal view override returns (address, address, address) {
DataTypes.ReserveData memory reserveData = ILendingPool(address(POOL)).getReserveData(asset);
return (
reserveData.variableDebtTokenAddress,
Expand All @@ -28,6 +34,7 @@ contract ParaSwapDebtSwapAdapterV2 is ParaSwapDebtSwapAdapter {
);
}

/// @inheritdoc BaseParaSwapAdapter
function _supply(
address asset,
uint256 amount,
Expand Down
11 changes: 8 additions & 3 deletions src/contracts/ParaSwapDebtSwapAdapterV3.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {ParaSwapDebtSwapAdapter} from './ParaSwapDebtSwapAdapter.sol';
import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IParaSwapAugustusRegistry} from '../interfaces/IParaSwapAugustusRegistry.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {IParaSwapAugustusRegistry} from './dependencies/paraswap/IParaSwapAugustusRegistry.sol';
import {BaseParaSwapAdapter} from './base/BaseParaSwapAdapter.sol';
import {ParaSwapDebtSwapAdapter} from './base/ParaSwapDebtSwapAdapter.sol';

/**
* @title ParaSwapDebtSwapAdapter
Expand All @@ -18,8 +19,11 @@ contract ParaSwapDebtSwapAdapterV3 is ParaSwapDebtSwapAdapter {
address pool,
IParaSwapAugustusRegistry augustusRegistry,
address owner
) ParaSwapDebtSwapAdapter(addressesProvider, pool, augustusRegistry, owner) {}
) ParaSwapDebtSwapAdapter(addressesProvider, pool, augustusRegistry, owner) {
// Intentionally left blank
}

/// @inheritdoc BaseParaSwapAdapter
function _getReserveData(
address asset
) internal view override returns (address, address, address) {
Expand All @@ -31,6 +35,7 @@ contract ParaSwapDebtSwapAdapterV3 is ParaSwapDebtSwapAdapter {
);
}

/// @inheritdoc BaseParaSwapAdapter
function _supply(
address asset,
uint256 amount,
Expand Down
9 changes: 5 additions & 4 deletions src/contracts/ParaSwapDebtSwapAdapterV3GHO.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {ParaSwapDebtSwapAdapterV3} from './ParaSwapDebtSwapAdapterV3.sol';
import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol';
import {IParaSwapAugustusRegistry} from '../interfaces/IParaSwapAugustusRegistry.sol';
import {IERC3156FlashBorrower} from '../interfaces/IERC3156FlashBorrower.sol';
import {IERC3156FlashLender} from '../interfaces/IERC3156FlashLender.sol';
import {IParaSwapAugustusRegistry} from './dependencies/paraswap/IParaSwapAugustusRegistry.sol';
import {IERC3156FlashBorrower} from './interfaces/IERC3156FlashBorrower.sol';
import {IERC3156FlashLender} from './interfaces/IERC3156FlashLender.sol';
import {BaseParaSwapAdapter} from './base/BaseParaSwapAdapter.sol';
import {ParaSwapDebtSwapAdapterV3} from './ParaSwapDebtSwapAdapterV3.sol';

// send collateral if needed via params
/**
Expand Down
54 changes: 54 additions & 0 deletions src/contracts/ParaSwapLiquiditySwapAdapterV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {DataTypes, ILendingPool} from 'aave-address-book/AaveV2.sol';
import {IParaSwapAugustusRegistry} from './dependencies/paraswap/IParaSwapAugustusRegistry.sol';
import {BaseParaSwapAdapter} from './base/BaseParaSwapAdapter.sol';
import {ParaSwapLiquiditySwapAdapter} from './base/ParaSwapLiquiditySwapAdapter.sol';

/**
* @title ParaSwapLiquiditySwapAdapterV2
* @notice ParaSwap Adapter to perform a swap of collateral from one asset to another.
* @dev It is specifically designed for Aave V2
* @author Aave Labs
**/
contract ParaSwapLiquiditySwapAdapterV2 is ParaSwapLiquiditySwapAdapter {
/**
* @dev Constructor
* @param addressesProvider The address of the Aave PoolAddressesProvider contract
* @param pool The address of the Aave Pool contract
* @param augustusRegistry The address of the Paraswap AugustusRegistry contract
* @param owner The address of the owner
*/
constructor(
IPoolAddressesProvider addressesProvider,
address pool,
IParaSwapAugustusRegistry augustusRegistry,
address owner
) ParaSwapLiquiditySwapAdapter(addressesProvider, pool, augustusRegistry, owner) {
// Intentionally left blank
}

/// @inheritdoc BaseParaSwapAdapter
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
function _getReserveData(
address asset
) internal view override returns (address, address, address) {
DataTypes.ReserveData memory reserveData = ILendingPool(address(POOL)).getReserveData(asset);
return (
reserveData.variableDebtTokenAddress,
reserveData.stableDebtTokenAddress,
reserveData.aTokenAddress
);
}

/// @inheritdoc BaseParaSwapAdapter
function _supply(
address asset,
uint256 amount,
address to,
uint16 referralCode
) internal override {
ILendingPool(address(POOL)).deposit(asset, amount, to, referralCode);
}
}
Loading