-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 77-test-coverage-for-…
…handler
- Loading branch information
Showing
30 changed files
with
2,925 additions
and
3,442 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
deleted from
f73c73
Submodule rain.interpreter
updated
77 files
117 changes: 117 additions & 0 deletions
117
test/foundry/abstract/ERC20PriceOracleReceiptVaultTest.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity =0.8.25; | ||
|
||
import {Test, Vm} from "forge-std/Test.sol"; | ||
import {ICloneableFactoryV2} from "rain.factory/interface/ICloneableFactoryV2.sol"; | ||
import {CloneFactory} from "rain.factory/concrete/CloneFactory.sol"; | ||
import { | ||
ERC20PriceOracleReceiptVault, | ||
ReceiptVaultConstructionConfig, | ||
ERC20PriceOracleReceiptVaultConfig | ||
} from "contracts/concrete/vault/ERC20PriceOracleReceiptVault.sol"; | ||
import {LibERC20PriceOracleReceiptVaultCreator} from "../lib/LibERC20PriceOracleReceiptVaultCreator.sol"; | ||
import {Receipt as ReceiptContract} from "contracts/concrete/receipt/Receipt.sol"; | ||
import {TwoPriceOracle, TwoPriceOracleConfig} from "contracts/oracle/price/TwoPriceOracle.sol"; | ||
import { | ||
ChainlinkFeedPriceOracle, | ||
ChainlinkFeedPriceOracleConfig | ||
} from "contracts/oracle/price/chainlink/ChainlinkFeedPriceOracle.sol"; | ||
import {MockChainlinkDataFeed, RoundData} from "contracts/test/MockChainlinkDataFeed.sol"; | ||
import {IERC20} from "forge-std/interfaces/IERC20.sol"; | ||
|
||
contract ERC20PriceOracleReceiptVaultTest is Test { | ||
event ERC20PriceOracleReceiptVaultInitialized(address sender, ERC20PriceOracleReceiptVaultConfig config); | ||
|
||
ICloneableFactoryV2 internal immutable iFactory; | ||
ERC20PriceOracleReceiptVault internal immutable iImplementation; | ||
ReceiptContract internal immutable iReceiptImplementation; | ||
IERC20 immutable iAsset; | ||
|
||
constructor() { | ||
iFactory = new CloneFactory(); | ||
iReceiptImplementation = new ReceiptContract(); | ||
iImplementation = new ERC20PriceOracleReceiptVault( | ||
ReceiptVaultConstructionConfig({factory: iFactory, receiptImplementation: iReceiptImplementation}) | ||
); | ||
iAsset = IERC20(address(uint160(uint256(keccak256("asset.test"))))); | ||
} | ||
|
||
function createVault(address priceOracle, string memory name, string memory symbol) | ||
internal | ||
returns (ERC20PriceOracleReceiptVault) | ||
{ | ||
ERC20PriceOracleReceiptVault vault = LibERC20PriceOracleReceiptVaultCreator.createVault( | ||
iFactory, iImplementation, priceOracle, address(iAsset), name, symbol | ||
); | ||
return vault; | ||
} | ||
|
||
function createTwoPriceOracle(uint8 usdDecimals, uint8 xauDecimals, uint256 timestamp, uint80 answeredInRound) | ||
internal | ||
returns (TwoPriceOracle twoPriceOracle) | ||
{ | ||
int256 basePrice = 1e8; // Example price for base | ||
int256 quotePrice = 1.8e8; // Example price for quote | ||
|
||
// Deploy base price oracle | ||
MockChainlinkDataFeed basePriceOracle = new MockChainlinkDataFeed(); | ||
basePriceOracle.setDecimals(usdDecimals); | ||
basePriceOracle.setRoundData( | ||
1, | ||
RoundData({answer: basePrice, startedAt: timestamp, updatedAt: timestamp, answeredInRound: answeredInRound}) | ||
); | ||
|
||
// Deploy quote price oracle | ||
MockChainlinkDataFeed quotePriceOracle = new MockChainlinkDataFeed(); | ||
quotePriceOracle.setDecimals(xauDecimals); | ||
quotePriceOracle.setRoundData( | ||
1, | ||
RoundData({answer: quotePrice, startedAt: timestamp, updatedAt: timestamp, answeredInRound: answeredInRound}) | ||
); | ||
// Set stale after times | ||
uint256 baseStaleAfter = 60 * 60; // 1 hour | ||
uint256 quoteStaleAfter = 48 * 60 * 60; // 48 hours | ||
|
||
// Deploy Chainlink Feed Price Oracle for base and quote | ||
address chainlinkFeedPriceOracleBase = address( | ||
new ChainlinkFeedPriceOracle( | ||
ChainlinkFeedPriceOracleConfig({feed: address(basePriceOracle), staleAfter: baseStaleAfter}) | ||
) | ||
); | ||
address chainlinkFeedPriceOracleQuote = address( | ||
new ChainlinkFeedPriceOracle( | ||
ChainlinkFeedPriceOracleConfig({feed: address(quotePriceOracle), staleAfter: quoteStaleAfter}) | ||
) | ||
); | ||
|
||
// Deploy TwoPriceOracle | ||
TwoPriceOracleConfig memory config = | ||
TwoPriceOracleConfig({base: chainlinkFeedPriceOracleBase, quote: chainlinkFeedPriceOracleQuote}); | ||
twoPriceOracle = new TwoPriceOracle(config); | ||
|
||
return twoPriceOracle; | ||
} | ||
|
||
/// Get Receipt from event | ||
function getReceipt() internal returns (ReceiptContract) { | ||
Vm.Log[] memory logs = vm.getRecordedLogs(); | ||
|
||
// Find the ERC20PriceOracleReceiptVaultInitialized event log | ||
address receiptAddress = address(0); | ||
bool eventFound = false; // Flag to indicate whether the event log was found | ||
for (uint256 i = 0; i < logs.length; i++) { | ||
if (logs[i].topics[0] == ERC20PriceOracleReceiptVaultInitialized.selector) { | ||
// Decode the event data | ||
(, ERC20PriceOracleReceiptVaultConfig memory config) = | ||
abi.decode(logs[i].data, (address, ERC20PriceOracleReceiptVaultConfig)); | ||
receiptAddress = config.receiptVaultConfig.receipt; | ||
eventFound = true; // Set the flag to true since event log was found | ||
break; | ||
} | ||
} | ||
// Assert that the event log was found | ||
assertTrue(eventFound, "ERC20PriceOracleReceiptVaultInitialized event log not found"); | ||
// Return an receipt contract | ||
return ReceiptContract(receiptAddress); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/foundry/lib/LibERC20PriceOracleReceiptVaultCreator.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity =0.8.25; | ||
|
||
import {ICloneableFactoryV2} from "rain.factory/interface/ICloneableFactoryV2.sol"; | ||
import { | ||
ERC20PriceOracleReceiptVault, | ||
ERC20PriceOracleVaultConfig | ||
} from "contracts/concrete/vault/ERC20PriceOracleReceiptVault.sol"; | ||
import {VaultConfig} from "contracts/abstract/ReceiptVault.sol"; | ||
|
||
library LibERC20PriceOracleReceiptVaultCreator { | ||
/// Helper to create child erc20PriceOracleVault. | ||
function createVault( | ||
ICloneableFactoryV2 factory, | ||
ERC20PriceOracleReceiptVault implementation, | ||
address priceOracle, | ||
address asset, | ||
string memory name, | ||
string memory symbol | ||
) internal returns (ERC20PriceOracleReceiptVault) { | ||
ERC20PriceOracleVaultConfig memory erc20PriceOracleVault = ERC20PriceOracleVaultConfig({ | ||
priceOracle: priceOracle, | ||
vaultConfig: VaultConfig({asset: asset, name: name, symbol: symbol}) | ||
}); | ||
|
||
// Use the factory to create the child contract | ||
return ERC20PriceOracleReceiptVault(factory.clone(address(implementation), abi.encode(erc20PriceOracleVault))); | ||
} | ||
} |
Oops, something went wrong.