Skip to content

Commit

Permalink
feat: Add Deploy Aggregate Token
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasia committed Nov 13, 2024
1 parent ddd34f0 commit 372b1d8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 21 deletions.
57 changes: 57 additions & 0 deletions packages/contracts/script/DeployAggregateToken.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { TomlConfig } from "@script/TomlConfig.s.sol";

import { AggregateToken } from "@plume/contracts/nest/AggregateToken.sol";
import { AggregateTokenProxy } from "@plume/contracts/nest/proxy/AggregateTokenProxy.sol";
import { IComponentToken } from "@plume/contracts/nest/interfaces/IComponentToken.sol";

import { stdToml } from "forge-std/StdToml.sol";
import { console2 } from "forge-std/console2.sol";

contract DeployAggregateToken is TomlConfig {
using stdToml for string;

string private _tomlConfig;

constructor() {
_tomlConfig = loadTomlConfiguration();
}

function run() public returns (AggregateToken aggregateToken_) {
address contractOwner = _tomlConfig.readAddress(".evm.address.owner");
address usdcAddress = _tomlConfig.readAddress(".evm.address.usdc_token");

return run(contractOwner, usdcAddress);
}

function run(address contractOwner, address assetAddress) public virtual returns (AggregateToken aggregateToken_) {
vm.startBroadcast(contractOwner);

// Deploy AggregateToken with both component tokens
AggregateToken aggregateToken = new AggregateToken();
console2.log("AggregateTokenImpl deployed to:", address(aggregateToken));

AggregateTokenProxy aggregateTokenProxy = new AggregateTokenProxy(
address(aggregateToken),
abi.encodeCall(
AggregateToken.initialize,
(
contractOwner,
"Cranberry (Credbull Test Aggregate Token)",
"CRAN",
IComponentToken(assetAddress),
1e17, // ask price
1e17 // bid price
)
)
);
console2.log("AggregateTokenProxy deployed to:", address(aggregateTokenProxy));

vm.stopBroadcast();

return AggregateToken(address(aggregateTokenProxy));
}
}
30 changes: 9 additions & 21 deletions packages/contracts/test/src/plume/AggregateTokenTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,23 @@ pragma solidity ^0.8.25;

import { IComponentToken } from "@plume/contracts/nest/interfaces/IComponentToken.sol";
import { IERC7575 } from "@plume/contracts/nest/interfaces/IERC7575.sol";
import { IERC7540 } from "@plume/contracts/nest/interfaces/IERC7540.sol";
import { AggregateToken } from "@plume/contracts/nest/AggregateToken.sol";
import { LiquidContinuousMultiTokenVaultTestBase } from "@test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol";
import { AggregateTokenProxy } from "@plume/contracts/nest/proxy/AggregateTokenProxy.sol";
import { TestParamSet } from "@test/test/token/ERC1155/TestParamSet.t.sol";
import { console2 } from "forge-std/console2.sol";

import { IERC1155Receiver } from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import { DeployAggregateToken } from "@script/DeployAggregateToken.s.sol";

contract AggregateTokenTest is LiquidContinuousMultiTokenVaultTestBase {
AggregateToken internal aggregateToken;
address public NEST_ADMIN_ADDRESS = makeAddr("NEST_ADMIN_ADDRESS");
address public aggTokenOwner;

function setUp() public override {
super.setUp();

// Deploy implementation of AggregateToken
AggregateToken aggregateTokenImpl = new AggregateToken();

// Deploy proxy of AggregateToken
AggregateTokenProxy aggregateTokenProxy = new AggregateTokenProxy(
address(aggregateTokenImpl),
abi.encodeCall(
AggregateToken.initialize,
(NEST_ADMIN_ADDRESS, "Aggregate Token", "AGGT", IComponentToken(address(_asset)), 15e17, 12e17)
)
);

aggregateToken = AggregateToken(address(aggregateTokenProxy));
DeployAggregateToken deployAggToken = new DeployAggregateToken();
aggTokenOwner = _vaultAuth.owner;
aggregateToken = deployAggToken.run(aggTokenOwner, address(_asset));
}

function test__AggregateTokenTest__SupportsInterface() public view {
Expand All @@ -52,7 +40,7 @@ contract AggregateTokenTest is LiquidContinuousMultiTokenVaultTestBase {
);

// Call buyComponentToken
vm.startPrank(NEST_ADMIN_ADDRESS);
vm.startPrank(aggTokenOwner);
aggregateToken.approveComponentToken(IComponentToken(address(_liquidVault)), depositAmount);
aggregateToken.buyComponentToken(IComponentToken(address(_liquidVault)), depositAmount);
vm.stopPrank();
Expand Down Expand Up @@ -81,7 +69,7 @@ contract AggregateTokenTest is LiquidContinuousMultiTokenVaultTestBase {
);

// Call buyComponentToken
vm.startPrank(NEST_ADMIN_ADDRESS);
vm.startPrank(aggTokenOwner);
aggregateToken.approveComponentToken(IComponentToken(address(_liquidVault)), testParams.principal);
aggregateToken.buyComponentToken(IComponentToken(address(_liquidVault)), testParams.principal);
vm.stopPrank();
Expand All @@ -101,14 +89,14 @@ contract AggregateTokenTest is LiquidContinuousMultiTokenVaultTestBase {
_warpToPeriod(_liquidVault, testParams.redeemPeriod - _liquidVault.noticePeriod());

// Call requestSellComponentToken (newly added by us)
vm.prank(NEST_ADMIN_ADDRESS);
vm.prank(aggTokenOwner);
aggregateToken.requestSellComponentToken(IComponentToken(address(_liquidVault)), testParams.principal);

// Move the blocktime to redeemPeriod
_warpToPeriod(_liquidVault, testParams.redeemPeriod);

// Call sellComponentToken
vm.prank(NEST_ADMIN_ADDRESS);
vm.prank(aggTokenOwner);
aggregateToken.sellComponentToken(IComponentToken(address(_liquidVault)), testParams.principal);

uint256 expectedAmount = testParams.principal + _expectedReturns(0, _liquidVault, testParams);
Expand Down

0 comments on commit 372b1d8

Please sign in to comment.