Skip to content

Commit

Permalink
Merge branch 'main' into migration-spell
Browse files Browse the repository at this point in the history
  • Loading branch information
AStox committed Jul 30, 2024
2 parents ac67490 + 1f92ebd commit c88ff07
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 112 deletions.
36 changes: 18 additions & 18 deletions deployments/testnet/ethereum-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
"chainId": 11155111,
"rpcUrl": "https://sepolia.infura.io/v3/ed5e0e19bcbc427cbf8f661736d44516",
"config": {
"commitHash": "333cc86042891d25c72e9a66dc9068652c0e02e0",
"deployer": "0x423420Ae467df6e90291fd0252c0A8a637C1e03f",
"commitHash": "93c59a531c9529e92949bd50aaf2a346be8c9a0a",
"deployer": "0x7c0E0200c7451d16F667665B39E3C78669a24BC3",
"adapter": {
"name": "Axelar",
"axelarGateway": "0xe432150cce91c13a887f7D836923d5597adD8E31"
"name": "Passthrough"
},
"admin": "0x423420Ae467df6e90291fd0252c0A8a637C1e03f",
"etherscanUrl": "https://api.etherscan.io/api/"
},
"contracts": {
"root": "0x5efaE490cf5B54a614852b31540BF3F0B6011717",
"investmentManager": "0xE3C901F6756e40dca041Dc58A1742e515bf58924",
"poolManager": "0x5c8657b827a138D52a4e3f03683A28B1FaD86893",
"gateway": "0xa0eBf95b390F38a50f0F0d44149EDd74279fA374",
"escrow": "0x1AB6cD0c08120215E241a6108ae7458c995E1694",
"userEscrow": "0x80EFf9C87f48c50BF9c6c3998D26174410647621",
"adapter": "0x1724a512567Bb0FFc7a543C7033979852eDb084f",
"trancheFactory": "0xf4D51485313248b48237502403A86875707cC94D",
"liquidityPoolFactory": "0x8048eAFA883fA3CB5C27c5dcBE501877D106b21C",
"restrictionManagerFactory": "0x60F98D1DD5Fb1Bd35B3F501c5460C0392964D63E",
"pauseAdmin": "0x96B5CA2575393eBc1F534d808d86E602a2318d30",
"delayedAdmin": "0xc89c96956202798310502aE5C03bE6B11A2b0cd6",
"messages": "0xd6c9f5204037a054a1BB3768195bD52A38E84ccD"
"root": "0xd9789E8cd7aC7b2D05CF51f52A9C64541f411d97",
"investmentManager": "0xe4Ae602E4D488a6bb16e5d8A44C8184928C3E4B4",
"centrifugeRouter": "0xFd2bd7e938C461A208740507362d43E36021AF65",
"poolManager": "0xd5F5Bb94dCC8bD894C0A66C0a5Fe3d2503a3D013",
"gateway": "0xc002c4437e05E41B746e5F840041275dEed912ba",
"gasService": "0x3CEc80ba243C5627300E90FD611e17207CbBD206",
"escrow": "0x961Ea4bEED78F8460125b2EB4bD76760b39a93e8",
"routerEscrow": "0x679c1DdAD3DDE8a2e80cC87Fc7123090C1dB137f",
"adapter": "0x7857E1c9e02dE72ce6CD582A88e2e1d92c9Cf2E7",
"trancheFactory": "0xaA141F0E0e408f75CB706d51F1a7811c13E00CED",
"erc7540VaultFactory": "0xa329bf0A2286B3f5631b6d5679a52911681FF84F",
"transferProxyFactory": "0x7EE1B98b0D53D175b74799b41757BD589B766Dd4",
"restrictionManagerFactory": "0x3293C3Aa8C3dC892d035b4101175141Ed2C00f8A",
"guardian": "0x0Be897D63eC22E020B7eA05A606e9e9614768B22"
},
"deploymentBlock": 4922687,
"deploymentBlock": 6379316,
"isTestnet": true
}
4 changes: 3 additions & 1 deletion src/ERC7540Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,12 @@ contract ERC7540Vault is Auth, IERC7540Vault {
}

// --- Helpers ---
/// @notice Price of 1 unit of share, quoted in the decimals of the asset
/// @notice Price of 1 unit of share, quoted in the decimals of the asset.
function pricePerShare() external view returns (uint256) {
return convertToAssets(10 ** shareDecimals);
}

/// @notice Returns timestamp of the last share price update.
function priceLastUpdated() external view returns (uint64) {
return manager.priceLastUpdated(address(this));
}
Expand All @@ -418,6 +419,7 @@ contract ERC7540Vault is Auth, IERC7540Vault {
return ITranche(share).checkTransferRestriction(address(0), controller, 0);
}

/// @notice Ensures msg.sender can operate on behalf of controller.
function validateController(address controller) internal view {
require(controller == msg.sender || isOperator[controller][msg.sender], "ERC7540Vault/invalid-controller");
}
Expand Down
9 changes: 7 additions & 2 deletions src/InvestmentManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ contract InvestmentManager is Auth, IInvestmentManager {
}

// --- Helpers ---
/// @dev Calculates share amount based on asset amount and share price. Returned value is in share decimals.
function _calculateShares(uint128 assets, address vault, uint256 price) internal view returns (uint128 shares) {
if (price == 0 || assets == 0) {
shares = 0;
Expand All @@ -551,6 +552,7 @@ contract InvestmentManager is Auth, IInvestmentManager {
}
}

/// @dev Calculates asset amount based on share amount and share price. Returned value is in asset decimals.
function _calculateAssets(uint128 shares, address vault, uint256 price) internal view returns (uint128 assets) {
if (price == 0 || shares == 0) {
assets = 0;
Expand All @@ -564,6 +566,7 @@ contract InvestmentManager is Auth, IInvestmentManager {
}
}

/// @dev Calculates share price and returns the value in price decimals
function _calculatePrice(address vault, uint128 assets, uint128 shares) internal view returns (uint256) {
if (assets == 0 || shares == 0) {
return 0;
Expand All @@ -582,18 +585,20 @@ contract InvestmentManager is Auth, IInvestmentManager {
return uint256(_value) * 10 ** (PRICE_DECIMALS - decimals);
}

/// @dev Convert decimals of the value from the price decimals back to the intended decimals
/// @dev Converts decimals of the value from the price decimals back to the intended decimals
function _fromPriceDecimals(uint256 _value, uint8 decimals) internal pure returns (uint128) {
if (PRICE_DECIMALS == decimals) return _value.toUint128();
return (_value / 10 ** (PRICE_DECIMALS - decimals)).toUint128();
}

/// @dev Return the asset decimals and the share decimals for a given vault
/// @dev Returns the asset decimals and the share decimals for a given vault
function _getPoolDecimals(address vault) internal view returns (uint8 assetDecimals, uint8 shareDecimals) {
assetDecimals = IERC20Metadata(IERC7540Vault(vault).asset()).decimals();
shareDecimals = IERC20Metadata(IERC7540Vault(vault).share()).decimals();
}

/// @dev Checks transfer restrictions for the vault shares. Sender (from) and receiver (to) have both to pass the
/// restrictions for a successful share transfer.
function _canTransfer(address vault, address from, address to, uint256 value) internal view returns (bool) {
ITranche share = ITranche(IERC7540Vault(vault).share());
return share.checkTransferRestriction(from, to, value);
Expand Down
4 changes: 2 additions & 2 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ contract PoolManager is Auth, IPoolManager {
} else if (call == MessagesLib.Call.UpdateTrancheHook) {
updateTrancheHook(message.toUint64(1), message.toBytes16(9), message.toAddress(25));
} else if (call == MessagesLib.Call.TransferAssets) {
handleTransfer(message.toUint128(1), message.toAddress(49), message.toUint128(81));
handleTransfer(message.toUint128(1), message.toAddress(17), message.toUint128(49));
} else if (call == MessagesLib.Call.TransferTrancheTokens) {
handleTransferTrancheTokens(
message.toUint64(1), message.toBytes16(9), message.toAddress(66), message.toUint128(98)
message.toUint64(1), message.toBytes16(9), message.toAddress(34), message.toUint128(66)
);
} else if (call == MessagesLib.Call.UpdateRestriction) {
updateRestriction(message.toUint64(1), message.toBytes16(9), message.slice(25, message.length - 25));
Expand Down
Loading

0 comments on commit c88ff07

Please sign in to comment.