Skip to content

Commit

Permalink
refactor: cleaner seeding code (bgd-labs#28)
Browse files Browse the repository at this point in the history
* refactor: move amount to const var and reuse

* fix: make it internal

* fix: make it internal

* fix: cleaner array
  • Loading branch information
sakulstra authored and Rozengarden committed Nov 2, 2023
1 parent 0f3d8a5 commit c223665
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 9 additions & 6 deletions generator/features/__snapshots__/assetListing.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ contract AaveV3Ethereum_Test_20231023 is AaveV3PayloadEthereum {
using SafeERC20 for IERC20;
address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;
uint256 internal constant PSP_SEED_AMOUNT = 10 ** 18;
function _postExecute() internal override {
IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), 10 ** 18);
AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0);
IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), PSP_SEED_AMOUNT);
AaveV3Ethereum.POOL.supply(PSP, PSP_SEED_AMOUNT, address(AaveV3Ethereum.COLLECTOR), 0);
}
function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down Expand Up @@ -166,7 +167,7 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
AaveV3Ethereum_Test_20231023 internal proposal;
function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 18461057);
vm.createSelectFork(vm.rpcUrl('mainnet'), 18480118);
proposal = new AaveV3Ethereum_Test_20231023();
}
Expand Down Expand Up @@ -219,7 +220,7 @@ contract DeployEthereum is EthereumScript {
* command: make deploy-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:CreateProposal chain=mainnet
*/
contract CreateProposal is EthereumScript {
function run() external broadcast {
function run() external {
// create payloads
PayloadsControllerUtils.Payload[] memory payloads = new PayloadsControllerUtils.Payload[](1);
Expand All @@ -230,6 +231,7 @@ contract CreateProposal is EthereumScript {
payloads[0] = GovV3Helpers.buildMainnetPayload(vm, actionsEthereum);
// create proposal
vm.startBroadcast();
GovV3Helpers.createProposal2_5(
payloads,
GovV3Helpers.ipfsHashFile(vm, 'src/20231023_AaveV3Ethereum_Test/Test.md')
Expand All @@ -245,10 +247,11 @@ exports[`feature: assetListing > should return reasonable code 1`] = `
"code": {
"constants": [
"address public constant PSP = 0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5;",
"uint256 internal constant PSP_SEED_AMOUNT = 10 ** 18;",
],
"execute": [
"IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), 10 ** 18);
AaveV3Ethereum.POOL.supply(PSP, 10 ** 18, address(AaveV3Ethereum.COLLECTOR), 0);",
"IERC20(PSP).forceApprove(address(AaveV3Ethereum.POOL), PSP_SEED_AMOUNT);
AaveV3Ethereum.POOL.supply(PSP, PSP_SEED_AMOUNT, address(AaveV3Ethereum.COLLECTOR), 0);",
],
"fn": [
"function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down
11 changes: 8 additions & 3 deletions generator/features/assetListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ export const assetListing: FeatureModule<Listing[]> = {
build(opt, pool, cfg) {
const response: CodeArtifact = {
code: {
constants: cfg.map((cfg) => `address public constant ${cfg.assetSymbol} = ${cfg.asset};`),
constants: cfg
.map((cfg) => [
`address public constant ${cfg.assetSymbol} = ${cfg.asset};`,
`uint256 internal constant ${cfg.assetSymbol}_SEED_AMOUNT = 10 ** ${cfg.decimals};`,
])
.flat(),
execute: cfg.map(
(cfg) =>
`IERC20(${cfg.assetSymbol}).forceApprove(address(${pool}.POOL), 10 ** ${cfg.decimals});
${pool}.POOL.supply(${cfg.assetSymbol}, 10 ** ${cfg.decimals}, address(${pool}.COLLECTOR), 0);`
`IERC20(${cfg.assetSymbol}).forceApprove(address(${pool}.POOL), ${cfg.assetSymbol}_SEED_AMOUNT);
${pool}.POOL.supply(${cfg.assetSymbol}, ${cfg.assetSymbol}_SEED_AMOUNT, address(${pool}.COLLECTOR), 0);`
),
fn: [
`function newListings() public pure override returns (IAaveV3ConfigEngine.Listing[] memory) {
Expand Down

0 comments on commit c223665

Please sign in to comment.