Skip to content

Commit

Permalink
Merge pull request #13 from open-dollar/paraswap
Browse files Browse the repository at this point in the history
Paraswap
  • Loading branch information
daopunk authored Jul 9, 2024
2 parents e30c59f + b652a71 commit f309979
Show file tree
Hide file tree
Showing 26 changed files with 1,574 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
THIS_IS_AN_EXAMPLE_FILE=!!!

ARB_ETHERSCAN_API_KEY=
ARB_MAINNET_RPC=

Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ deployments/anvil/
docs/

# Dotenv file
.env

lib/
.env
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "lib/aave-debt-swap"]
path = lib/aave-debt-swap
url = https://github.com/aave/aave-debt-swap
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ auto_detect_solc = true
src = "src"
out = "out"
libs = ["lib"]
ffi = true

[rpc_endpoints]
mainnet = "${ARB_MAINNET_RPC}"
Expand Down
1 change: 1 addition & 0 deletions lib/aave-debt-swap
Submodule aave-debt-swap added at 7ae593
1 change: 1 addition & 0 deletions lib/ds-test
Submodule ds-test added at e28215
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 6e0572
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
"test:coverage": "forge coverage --report lcov && lcov --ignore-errors unused --remove lcov.info 'node_modules/*' 'script/*' 'test/*' 'src/contracts/for-test/*' 'src/libraries/*' -o lcov.info.pruned && mv lcov.info.pruned lcov.info && genhtml -o coverage-report lcov.info"
},
"dependencies": {
"@opendollar/contracts": "0.0.0-e31c2151",
"@opendollar/contracts": "0.0.0-984c17c2",
"@openzeppelin-contracts-3.4.2-solc-0.7": "yarn:@openzeppelin/contracts@^3.4.2",
"@openzeppelin/contracts": "4.9.6",
"@paraswap/sdk": "^6.7.0"
"@paraswap/sdk": "^6.7.0",
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"ethers": "^5.7.2",
"object-hash": "^3.0.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
7 changes: 7 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@aave-core-v3/=lib/aave-debt-swap/lib/aave-v3-core/
@aave-address-book/=lib/aave-debt-swap/lib/aave-address-book/src/
@aave-debt-swap/=lib/aave-debt-swap/src/contracts/
@aave-debt-swap-test/=lib/aave-debt-swap/src/tests/
@openzeppelin/=node_modules/@openzeppelin/contracts/
@openzeppelin-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/
@openzeppelin-sol7/=node_modules/@openzeppelin-contracts-3.4.2-solc-0.7/
@openzeppelin-upgradeable/=node_modules/@openzeppelin/
@defi-wonderland/solidity-utils/=node_modules/@defi-wonderland/solidity-utils/solidity/
solidity-utils/=lib/aave-debt-swap/lib/solidity-utils/src/

@opendollar/contracts/=node_modules/@opendollar/contracts/src/contracts/
@opendollar/interfaces/=node_modules/@opendollar/contracts/src/interfaces/
Expand Down
40 changes: 33 additions & 7 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;

// ParaSwap Limit Order Contract (Sol 0.8.1)
address constant PARASWAP_AUGUSTUS_RFQ = 0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D;

// ParaSwap On-Chain Aggregator (Sol 0.7.5)
address constant PARASWAP_AUGUSTUS_SWAPPER = 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57;
pragma solidity >=0.8.0;

// Open Dollar
address constant OD_ADDR = 0x221A0f68770658C15B525d0F89F5da2baAB5f321;
address constant VAULT721 = 0x0005AFE00fF7E7FF83667bFe4F2996720BAf0B36;

// Open Dollar Pool Pair
bytes32 constant WETH = bytes32('WETH');
address constant WETH_ADDR = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;

// Open Dollar Protocol Collateral
bytes32 constant WSTETH = bytes32('WSTETH');
address constant WSTETH_ADDR = 0x5979D7b546E38E414F7E9822514be443A4800529;
bytes32 constant RETH = bytes32('RETH');
address constant RETH_ADDR = 0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8;
bytes32 constant ARB = bytes32('ARB');
address constant ARB_ADDR = 0x912CE59144191C1204E64559FE8253a0e49E6548;

// Aave
address constant AAVE_POOL_ADDRESS_PROVIDER = 0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb;

// ParaSwap Limit Order Contract (Sol 0.8.1)
address constant PARASWAP_AUGUSTUS_RFQ = 0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D;

// ParaSwap On-Chain Aggregator (Sol 0.7.5)
address constant PARASWAP_AUGUSTUS_SWAPPER = 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57;

// Test Vars
address constant USER = 0x37c5B029f9c3691B3d47cb024f84E5E257aEb0BB;
uint256 constant SELL_AMOUNT = 1 ether;

// Token Kekkac256 Hashes for Aave
bytes32 constant RETH_HASH = bytes32(keccak256('RETH'));
bytes32 constant WETH_HASH = bytes32(keccak256('WETH'));
bytes32 constant WSTETH_HASH = bytes32(keccak256('WSTETH'));
bytes32 constant AAVE_RETH_HASH = bytes32(keccak256('AAVE_RETH'));
bytes32 constant AAVE_WETH_HASH = bytes32(keccak256('AAVE_WETH'));
bytes32 constant AAVE_WSTETH_HASH = bytes32(keccak256('AAVE_WSTETH'));

// Oracle Relayers
address constant MAINNET_CHAINLINK_ETH_USD_RELAYER = 0x3e6C1621f674da311E57646007fBfAd857084383;
address constant MAINNET_DENOMINATED_WSTETH_USD_ORACLE = 0xD0cf1FfFF3FB90c87210D76DFBc3AcfFd02D6B12;
address constant MAINNET_DENOMINATED_RETH_USD_ORACLE = 0x2b6b76D9854E9A7189c2F1b496c10043b373e453;
address constant MAINNET_CHAINLINK_ARB_USD_RELAYER = 0x2635f731BB6981E72F92A781578952450759F762;
32 changes: 32 additions & 0 deletions script/getDstAmount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const {constructSimpleSDK, SwapSide} = require('@paraswap/sdk');
const axios = require('axios');
const ethers = require('ethers');

const paraSwapMin = constructSimpleSDK({chainId: 42161, axios});

const args = process.argv.slice(2);

const FROM_TOKEN = args[0];
const FROM_DECIMALS = args[1];
const TO_TOKEN = args[2];
const TO_DECIMALS = args[3];
const SELL_AMOUNT = args[4];
const CALLER = args[5];

async function getDstRoute(_fromToken, _fromDecimals, _toToken, _toDecimals, _sellAmount, _caller) {
const _priceRoute = await paraSwapMin.swap.getRate({
srcToken: _fromToken,
srcDecimals: _fromDecimals,
destToken: _toToken,
destDecimals: _toDecimals,
amount: _sellAmount,
userAddress: _caller,
side: SwapSide.SELL,
});

const dstAmount = ethers.utils.defaultAbiCoder.encode(["(uint256)"],[[_priceRoute.destAmount]]);

process.stdout.write(dstAmount);
}

getDstRoute(FROM_TOKEN, FROM_DECIMALS, TO_TOKEN, TO_DECIMALS, SELL_AMOUNT, CALLER);
41 changes: 41 additions & 0 deletions script/getSwapRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const {constructSimpleSDK, SwapSide} = require('@paraswap/sdk');
const axios = require('axios');

const paraSwapMin = constructSimpleSDK({chainId: 42161, axios});

const args = process.argv.slice(2);

const FROM_TOKEN = args[0];
const FROM_DECIMALS = args[1];
const TO_TOKEN = args[2];
const TO_DECIMALS = args[3];
const SELL_AMOUNT = args[4];
const CALLER = args[5];

async function getSwapRoute(_fromToken, _fromDecimals, _toToken, _toDecimals, _sellAmount, _caller) {
const priceRoute = await paraSwapMin.swap.getRate({
srcToken: _fromToken,
srcDecimals: _fromDecimals,
destToken: _toToken,
destDecimals: _toDecimals,
amount: _sellAmount,
userAddress: _caller,
side: SwapSide.SELL,
});

const txParams = await paraSwapMin.swap.buildTx(
{
srcToken: priceRoute.srcToken,
destToken: priceRoute.destToken,
srcAmount: priceRoute.srcAmount,
destAmount: priceRoute.destAmount,
priceRoute,
userAddress: _caller,
ignoreChecks: true
}
);

process.stdout.write(txParams.data);
}

getSwapRoute(FROM_TOKEN, FROM_DECIMALS, TO_TOKEN, TO_DECIMALS, SELL_AMOUNT, CALLER);
10 changes: 6 additions & 4 deletions src/leverage/LeverageCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ contract LeverageCalculator {
// TODO: recalculate collateral or execute leverage swap
_debtIterator = calculateSingleLeverage(_safeId);
}

return _leverage;
}

/// @dev calculate max flashloan leverage based on initial locked collateral
function calculateFlashLeverage(uint256 _safeId) external view returns (uint256 _leverage) {
function calculateFlashLeverage(uint256 _safeId) external pure returns (uint256 _leverage) {
// TODO: calculate max leverage
return _safeId;
}
Expand All @@ -57,9 +59,9 @@ contract LeverageCalculator {

/// @dev get cType and safe handler of NFV
function getNFVIds(uint256 _safeId) public view returns (bytes32 _cType, address _safeHandler) {
IVault721.NFVState memory nftState = VAULT721.getNfvState(_safeId);
_cType = nftState.cType;
_safeHandler = nftState.safeHandler;
IVault721.NFVState memory _nftState = VAULT721.getNfvState(_safeId);
_cType = _nftState.cType;
_safeHandler = _nftState.safeHandler;
}

/// @dev get locked collateral and generated debt
Expand Down
6 changes: 0 additions & 6 deletions src/leverage/LeverageSwapper.sol

This file was deleted.

Loading

0 comments on commit f309979

Please sign in to comment.