Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gildlab/ethgild into 2024-06-25-sflr
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Sep 19, 2024
2 parents fe34fa7 + 293ab5b commit 53f1377
Show file tree
Hide file tree
Showing 48 changed files with 5,289 additions and 5,313 deletions.
123 changes: 107 additions & 16 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .github/workflows/manual-sol-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- arbitrum_sepolia
- avalanche
- base
- base_sepolia
- bsc
- ethereum
- flare
Expand All @@ -19,6 +20,7 @@ on:
- polygon
- sepolia
- songbird
- amoy

suite:
description: 'Suite to deploy'
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
Expand Down
66 changes: 16 additions & 50 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ cache_path = 'forge-cache'
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

solc = "0.8.25"
optimizer = false
optimizer = true
optimizer_runs = 100000

fuzz.runs = 2056

remappings = [
"rain.factory/=lib/rain.factory/src/",
"rain.intorastring/=lib/rain.interpreter/lib/rain.intorastring/src/",
"forge-std/=lib/rain.interpreter/lib/forge-std/src/",
]
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from f73c73
2 changes: 1 addition & 1 deletion lib/rain.interpreter
Submodule rain.interpreter updated 77 files
+26 −0 .github/workflows/git-clean.yaml
+6 −0 .gitmodules
+20 −2 Cargo.lock
+2 −1 Cargo.toml
+1 −0 crates/eval/Cargo.toml
+5 −165 crates/eval/src/error.rs
+34 −3 crates/eval/src/fork.rs
+1 −0 foundry.toml
+1 −1 lib/rain.interpreter.interface
+1 −0 lib/rain.math.binary
+1 −1 lib/rain.math.fixedpoint
+1 −0 lib/rain.sol.codegen
+109 −0 script/BuildPointers.sol
+3 −1 src/abstract/BaseRainterpreterExternNPE2.sol
+18 −10 src/abstract/BaseRainterpreterSubParserNPE2.sol
+13 −13 src/concrete/RainterpreterExpressionDeployerNPE2.sol
+11 −11 src/concrete/RainterpreterNPE2.sol
+15 −42 src/concrete/RainterpreterParserNPE2.sol
+7 −6 src/concrete/RainterpreterStoreNPE2.sol
+24 −44 src/concrete/extern/RainterpreterReferenceExternNPE2.sol
+19 −0 src/generated/RainterpreterExpressionDeployerNPE2.pointers.sol
+19 −0 src/generated/RainterpreterNPE2.pointers.sol
+47 −0 src/generated/RainterpreterParserNPE2.pointers.sol
+65 −0 src/generated/RainterpreterReferenceExternNPE2.pointers.sol
+12 −0 src/generated/RainterpreterStoreNPE2.pointers.sol
+0 −58 src/lib/bitwise/LibCtPop.sol
+0 −0 src/lib/constants/ExpressionDeployerNPConstants.sol
+43 −3 src/lib/op/LibAllStandardOpsNP.sol
+1 −1 src/lib/op/bitwise/LibOpCtPopNP.sol
+69 −0 src/lib/op/erc20/LibOpERC20Allowance.sol
+70 −0 src/lib/op/erc20/LibOpERC20BalanceOf.sol
+64 −0 src/lib/op/erc20/LibOpERC20TotalSupply.sol
+35 −0 src/lib/op/math/LibOpE.sol
+4 −4 src/lib/parse/LibParse.sol
+0 −282 src/lib/parse/LibParseMeta.sol
+6 −6 src/lib/parse/LibSubParse.sol
+1 −1 src/lib/parse/literal/LibParseLiteralSubParseable.sol
+1 −1 test/abstract/OperandTest.sol
+6 −5 test/abstract/RainterpreterExpressionDeployerNPE2DeploymentTest.sol
+0 −63 test/lib/bloom/LibBloom.sol
+0 −45 test/lib/bloom/LibBloom.t.sol
+4 −3 test/lib/parse/LibMetaFixture.sol
+9 −1 test/src/abstract/BaseRainterpreterExternNPE2.ierc165.t.sol
+14 −2 test/src/abstract/BaseRainterpreterSubParserNPE2.compatibility.t.sol
+16 −4 test/src/abstract/BaseRainterpreterSubParserNPE2.ierc165.t.sol
+0 −1 test/src/concrete/RainterpreterExpressionDeployerNPE2.deployCheck.t.sol
+1 −1 test/src/concrete/RainterpreterExpressionDeployerNPE2.describedByMetaV1.t.sol
+1 −1 test/src/concrete/RainterpreterExpressionDeployerNPE2.meta.t.sol
+0 −1 test/src/concrete/RainterpreterExpressionDeployerNPE2.parse2.t.sol
+14 −0 test/src/concrete/RainterpreterNPE2.pointers.t.sol
+3 −3 test/src/concrete/RainterpreterParserNPE2.ierc165.t.sol
+5 −3 test/src/concrete/RainterpreterParserNPE2.pointers.t.sol
+3 −4 test/src/concrete/RainterpreterReferenceExternNPE2.ierc165.t.sol
+1 −1 test/src/concrete/RainterpreterReferenceExternNPE2.intInc.t.sol
+9 −8 test/src/concrete/RainterpreterReferenceExternNPE2.pointers.t.sol
+0 −51 test/src/lib/bitwise/LibCtPop.ctpop.t.sol
+1 −1 test/src/lib/op/bitwise/LibOpCtPopNP.t.sol
+98 −0 test/src/lib/op/erc20/LibOpERC20Allowance.t.sol
+111 −0 test/src/lib/op/erc20/LibOpERC20BalanceOf.t.sol
+92 −0 test/src/lib/op/erc20/LibOpERC20TotalSupply.t.sol
+0 −0 test/src/lib/op/erc20/uint256/LibOpUint256ERC20Allowance.t.sol
+0 −0 test/src/lib/op/erc20/uint256/LibOpUint256ERC20BalanceOf.t.sol
+0 −0 test/src/lib/op/erc20/uint256/LibOpUint256ERC20TotalSupply.t.sol
+0 −7 test/src/lib/op/evm/LibOpBlockNumberNP.t.sol
+47 −22 test/src/lib/op/evm/LibOpTimestampNP.t.sol
+72 −0 test/src/lib/op/math/LibOpE.t.sol
+5 −5 test/src/lib/parse/LibParse.empty.gas.t.sol
+10 −10 test/src/lib/parse/LibParse.inputsOnly.gas.t.sol
+1 −1 test/src/lib/parse/LibParse.literalString.t.sol
+4 −3 test/src/lib/parse/LibParse.namedLHS.t.sol
+10 −10 test/src/lib/parse/LibParse.singleIgnored.gas.t.sol
+31 −31 test/src/lib/parse/LibParse.singleLHSNamed.gas.t.sol
+35 −34 test/src/lib/parse/LibParse.singleRHSNamed.gas.t.sol
+0 −77 test/src/lib/parse/LibParseMeta.buildMeta.t.sol
+0 −32 test/src/lib/parse/LibParseMeta.findExpander.t.sol
+1 −1 test/src/lib/parse/LibParseState.constantValueBloom.t.sol
+3 −3 test/src/lib/parse/literal/LibParseLiteralSubParseable.parseSubParseable.t.sol
2 changes: 1 addition & 1 deletion script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract Deploy is Script {
factory: ICloneableFactoryV2(vm.envAddress("CLONE_FACTORY")),
receiptImplementation: receipt
});
// new OffchainAssetReceiptVault(receiptVaultConstructionConfig);
new OffchainAssetReceiptVault(receiptVaultConstructionConfig);
new ERC20PriceOracleReceiptVault(receiptVaultConstructionConfig);

vm.stopBroadcast();
Expand Down
39 changes: 0 additions & 39 deletions test/Fallback.test.ts

This file was deleted.

117 changes: 117 additions & 0 deletions test/foundry/abstract/ERC20PriceOracleReceiptVaultTest.sol
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/concrete/oracle/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);
}
}
21 changes: 21 additions & 0 deletions test/foundry/abstract/OffchainAssetReceiptVaultTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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 {
OffchainAssetReceiptVaultConfig,
OffchainAssetReceiptVault,
ReceiptVaultConstructionConfig
} from "contracts/concrete/vault/OffchainAssetReceiptVault.sol";
import {LibOffchainAssetVaultCreator} from "../lib/LibOffchainAssetVaultCreator.sol";
import {Receipt as ReceiptContract} from "contracts/concrete/receipt/Receipt.sol";

contract OffchainAssetReceiptVaultTest is Test {
event OffchainAssetReceiptVaultInitialized(address sender, OffchainAssetReceiptVaultConfig config);

ICloneableFactoryV2 internal immutable iFactory;
OffchainAssetReceiptVault internal immutable iImplementation;
ReceiptContract internal immutable receiptImplementation;
Expand All @@ -30,4 +33,22 @@ contract OffchainAssetReceiptVaultTest is Test {
{
return LibOffchainAssetVaultCreator.createVault(iFactory, iImplementation, admin, name, symbol);
}

function getReceipt(Vm.Log[] memory logs) internal pure returns (ReceiptContract) {
// Find the OffchainAssetReceiptVaultInitialized 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] == OffchainAssetReceiptVaultInitialized.selector) {
// Decode the event data
(, OffchainAssetReceiptVaultConfig memory config) =
abi.decode(logs[i].data, (address, OffchainAssetReceiptVaultConfig));
receiptAddress = config.receiptVaultConfig.receipt;
eventFound = true; // Set the flag to true since event log was found
break;
}
}
// Return an receipt contract
return ReceiptContract(receiptAddress);
}
}
Loading

0 comments on commit 53f1377

Please sign in to comment.