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

Feat/aip ampl #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions .ampl.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# in GWEI
# DEFAULT_GAS_PRICE= 50
TOKEN=0xd46ba6d942050d489dbd938a2c909a5d5039a161
ATOKEN=0x6fBC3BE5ee5273598d1491D41bB45F6d05a7541A
STABLE_DEBT_TOKEN=0x0e8f4fc4c261d454b13C74507Bce8C38AA990361
VARIABLE_DEBT_TOKEN=0x3A38bbc6438d2CE2a9e8F116F315a23433755947
INTEREST_STRATEGY=0x9A8CA7e1d64AFfF2664443B3803f280345F5336B
LTV=0
LIQUIDATION_THRESHOLD=0
LIQUIDATION_BONUS=0
RESERVE_FACTOR=2000
DECIMALS=9
ENABLE_BORROW=true
ENABLE_STABLE_BORROW=false
ENABLE_AS_COLLATERAL=false
IPFS_HASH=QmX24WkPm4WLurTq4R24Neo1KMV3hs9KCg2EkhAYcQvV1e

# By default executor and governance addresses set to mainnet addresses
# Uncomment the following for kovan
#AAVE_SHORT_EXECUTOR=0x2012b02574f32a96b9cfb8ba7fdfd589d5c70f50
#AAVE_GOVERNANCE_V2=0xc2ebab3bac8f2f5028f5c7317027a41ebfca31d2

69 changes: 69 additions & 0 deletions contracts/assetListing/AIP12AMPL.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import {IERC20} from './interfaces/IERC20.sol';
import {ILendingPoolConfiguratorV2} from './interfaces/ILendingPoolConfiguratorV2.sol';
import {IOverlyingAsset} from './interfaces/IOverlyingAsset.sol';
import {ILendingPoolAddressesProvider} from './interfaces/ILendingPoolAddressesProvider.sol';
import {IAAMPL} from './interfaces/IAAMPL.sol';
import {ILendingPool, DataTypes} from './interfaces/ILendingPool.sol';
/**
* @title AssetListingProposalGenericExecutor
* @notice Proposal payload to be executed by the Aave Governance contract via DELEGATECALL
* @author Aave
**/
contract AIP12AMPL {
event ProposalExecuted();

ILendingPoolAddressesProvider public constant LENDING_POOL_ADDRESSES_PROVIDER =
ILendingPoolAddressesProvider(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5);

address public constant token = 0xD46bA6D942050d489DBd938a2C909A5d5039A161;
address public constant aToken = 0x6fBC3BE5ee5273598d1491D41bB45F6d05a7541A;
address public constant stableDebtToken = 0x0e8f4fc4c261d454b13C74507Bce8C38AA990361;
address public constant variableDebtToken = 0x3A38bbc6438d2CE2a9e8F116F315a23433755947;
address public constant interestStrategy = 0x9A8CA7e1d64AFfF2664443B3803f280345F5336B;
uint256 public constant ltv = 0;
uint256 public constant liquidationThreshold = 0;
uint256 public constant liquidationBonus = 0;
uint256 public constant reserveFactor = 2000;
uint8 public constant decimals = 9;

/**
* @dev Payload execution function, called once a proposal passed in the Aave governance
*/
function execute() external {
ILendingPoolConfiguratorV2 LENDING_POOL_CONFIGURATOR_V2 =
ILendingPoolConfiguratorV2(LENDING_POOL_ADDRESSES_PROVIDER.getLendingPoolConfigurator());
require(
token == IOverlyingAsset(aToken).UNDERLYING_ASSET_ADDRESS(),
'ATOKEN: WRONG_UNDERLYING_TOKEN'
);
require(
token == IOverlyingAsset(stableDebtToken).UNDERLYING_ASSET_ADDRESS(),
'STABLE_DEBT: WRONG_UNDERLYING_TOKEN'
);
require(
token == IOverlyingAsset(variableDebtToken).UNDERLYING_ASSET_ADDRESS(),
'VARIABLE_DEBT: WRONG_UNDERLYING_TOKEN'
);
LENDING_POOL_CONFIGURATOR_V2.initReserve(
aToken,
stableDebtToken,
variableDebtToken,
decimals,
interestStrategy
);
LENDING_POOL_CONFIGURATOR_V2.enableBorrowingOnReserve(token, false);
LENDING_POOL_CONFIGURATOR_V2.setReserveFactor(token, reserveFactor);

ILendingPool pool = ILendingPool(LENDING_POOL_ADDRESSES_PROVIDER.getLendingPool());

DataTypes.ReserveData memory reserve = pool.getReserveData(token);

IAAMPL(reserve.aTokenAddress).initializeDebtTokens();

emit ProposalExecuted();
}
}
6 changes: 6 additions & 0 deletions contracts/assetListing/interfaces/IAAMPL.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;

interface IAAMPL {
function initializeDebtTokens() external;
}
2 changes: 2 additions & 0 deletions contracts/assetListing/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ interface IERC20 {
uint256 amount
) external returns (bool);

function decimals() external view returns (uint8);

/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '@nomiclabs/hardhat-waffle';
if (process.env.SKIP_LOAD !== 'true') {
// eslint-disable-next-line global-require
require('./tasks/list-new-asset.ts');
require('./tasks/list-ampl.ts');
}

export const BUIDLEREVM_CHAIN_ID = 31337;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test:crv": "MAINNET_FORK=true FORKING_BLOCK=11538355 hardhat test ./test/test-listing-crv.spec.ts",
"test:bal": "MAINNET_FORK=true FORKING_BLOCK=11743368 hardhat test ./test/test-listing-bal.spec.ts",
"test:xsushi": "MAINNET_FORK=true FORKING_BLOCK=11829845 hardhat test ./test/test-listing-xsushi.spec.ts",
"test:ampl": "MAINNET_FORK=true FORKING_BLOCK=12406480 hardhat test ./test/test-listing-ampl.spec.ts",
"run-env": "npm i && tail -f /dev/null",
"propose-new-asset:kovan": "hardhat create:proposal-new-asset --network kovan",
"propose-new-asset:main": "hardhat create:proposal-new-asset --network main"
Expand Down
51 changes: 51 additions & 0 deletions tasks/list-ampl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';
import { getContractAt } from '@nomiclabs/hardhat-ethers/dist/src/helpers';
import { config } from 'dotenv';
import { IAaveGovernanceV2 } from '../types/IAaveGovernanceV2';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bs58 = require('bs58');
const AAVE_GOVERNANCE_V2 = '0xEC568fffba86c094cf06b22134B23074DFE2252c'; // mainnet
const AAVE_SHORT_EXECUTOR = '0xee56e2b3d491590b5b31738cc34d5232f378a8d5'; // mainnet

config();

task('list:ampl', 'Create some proposals and votes')
// eslint-disable-next-line no-empty-pattern
.setAction(async ({}, _DRE: HardhatRuntimeEnvironment) => {
const {
IPFS_HASH,
} = process.env;
if (
!IPFS_HASH
) {
throw new Error('please set `IPFS_HASH` as environment variable');
}
const proposer = (await _DRE.ethers.getSigners())[0];
const genericPayloadAddress = (
await _DRE.deployments.get('AIP12AMPL')
).address;
const executeCallData = new _DRE.ethers.utils.Interface(['function execute()']).encodeFunctionData('execute');
const gov = (await getContractAt(
_DRE,
'IAaveGovernanceV2',
AAVE_GOVERNANCE_V2 || ''
)) as IAaveGovernanceV2;
const ipfsEncoded = `0x${bs58.decode(IPFS_HASH).slice(2).toString('hex')}`;

await (
await gov
.connect(proposer)
.create(
AAVE_SHORT_EXECUTOR,
[genericPayloadAddress],
['0'],
[''],
[executeCallData],
[true],
ipfsEncoded
)
).wait();
console.log('Your Proposal has been submitted');
});
Loading