Initial build for QIE Mainnet Hackathon 3.0 (DeFi & Financial Infrastructure track). Includes: - packages/contracts: constant-product AMM (factory/pair/router), over-collateralized lending vault, and an oracle adapter wrapping QIE's real deployed price-feed contracts. 25/25 Foundry tests pass locally. Clean-room: no existing DEX/lending protocol source was read or copied. - packages/core: TypeScript SDK (viem-based) for QIE's chain, the real (corrected) oracle ABI, a fail-closed QUSDC helper, a Blockscout explorer client, and QIE Wallet connection constants. Live-verified against real testnet (chain 1983) and mainnet (chain 1990) RPCs and the real oracle contracts. - packages/cli: a small CLI built on @qie-forge/core. Real findings from building this, documented in README.md and docs/STATUS.md: the previously-documented testnet RPC URL is dead (replacement found and verified live); QIE's own oracle docs describe a getPrice(string) function that reverts on the real deployed contracts, which actually implement a Chainlink AggregatorV3-style interface (verified live via raw eth_call); the oracle is deployed on Mainnet only, not Testnet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
145 lines
4.5 KiB
Solidity
145 lines
4.5 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.31;
|
|
|
|
import {Test} from "forge-std/Test.sol";
|
|
import {RLP} from "@openzeppelin/contracts/utils/RLP.sol";
|
|
import {Memory} from "@openzeppelin/contracts/utils/Memory.sol";
|
|
|
|
contract RLPTest is Test {
|
|
using RLP for *;
|
|
|
|
// Encode -> Decode
|
|
|
|
function testEncodeDecodeBool(bool input) external pure {
|
|
assertEq(input.encode().decodeBool(), input);
|
|
}
|
|
|
|
function testEncodeDecodeAddress(address input) external pure {
|
|
assertEq(input.encode().decodeAddress(), input);
|
|
}
|
|
|
|
function testEncodeDecodeUint256(uint256 input) external pure {
|
|
assertEq(input.encode().decodeUint256(), input);
|
|
}
|
|
|
|
function testEncodeDecodeBytes32(bytes32 input) external pure {
|
|
assertEq(input.encode().decodeBytes32(), input);
|
|
}
|
|
|
|
function testEncodeDecodeBytes(bytes memory input) external pure {
|
|
assertEq(input.encode().decodeBytes(), input);
|
|
}
|
|
|
|
function testEncodeDecodeString(string memory input) external pure {
|
|
assertEq(input.encode().decodeString(), input);
|
|
}
|
|
|
|
/// forge-config: default.fuzz.runs = 512
|
|
function testEncodeDecodeList(bytes[] memory input) external pure {
|
|
// max length for list decoding by default
|
|
vm.assume(input.length <= 32);
|
|
|
|
bytes[] memory encoded = new bytes[](input.length);
|
|
for (uint256 i = 0; i < input.length; ++i) {
|
|
encoded[i] = input[i].encode();
|
|
}
|
|
|
|
// encode list + decode as list of RLP items
|
|
Memory.Slice[] memory list = encoded.encode().decodeList();
|
|
|
|
assertEq(list.length, input.length);
|
|
for (uint256 i = 0; i < input.length; ++i) {
|
|
assertEq(list[i].readBytes(), input[i]);
|
|
}
|
|
}
|
|
|
|
// List encoder
|
|
|
|
function testEncodeEmpty() external pure {
|
|
assertEq(RLP.encoder().encode(), hex"c0");
|
|
}
|
|
|
|
function testEncodeBool(bool input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeAddress(address input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeUint256(uint256 input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeBytes32(bytes32 input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeBytes(bytes memory input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeString(string memory input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
/// forge-config: default.fuzz.runs = 512
|
|
function testEncodeBytesArray(bytes[] memory input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
|
|
assertEq(RLP.encoder().push(input).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeEncoder(bytes memory input) external pure {
|
|
bytes[] memory list = new bytes[](1);
|
|
list[0] = RLP.encode(input);
|
|
list[0] = RLP.encode(list);
|
|
|
|
assertEq(RLP.encoder().push(RLP.encoder().push(input)).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testEncodeMultiType(uint256 u, bytes memory b, address a) external pure {
|
|
bytes[] memory list = new bytes[](3);
|
|
list[0] = RLP.encode(u);
|
|
list[1] = RLP.encode(b);
|
|
list[2] = RLP.encode(a);
|
|
|
|
assertEq(RLP.encoder().push(u).push(b).push(a).encode(), RLP.encode(list));
|
|
|
|
list[0] = RLP.encode(b);
|
|
list[1] = RLP.encode(a);
|
|
list[2] = RLP.encode(u);
|
|
|
|
assertEq(RLP.encoder().push(b).push(a).push(u).encode(), RLP.encode(list));
|
|
}
|
|
|
|
function testComputeCreateAddress(address deployer, uint256 nonce) external pure {
|
|
nonce = bound(nonce, 0, type(uint64).max);
|
|
|
|
assertEq(
|
|
address(uint160(uint256(keccak256(RLP.encoder().push(deployer).push(nonce).encode())))),
|
|
vm.computeCreateAddress(deployer, nonce)
|
|
);
|
|
}
|
|
}
|