Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Mar 11, 2024
2 parents 625ed9c + c54de60 commit 965558f
Show file tree
Hide file tree
Showing 14 changed files with 892 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: mkdir -p test/csvs
- run: nix run .#rainix-sol-prelude
- run: nix run .#rainix-sol-test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ docs/

# Dotenv file
.env
test/csvs/*
test/csvs/*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "lib/rain.math.fixedpoint"]
path = lib/rain.math.fixedpoint
url = https://github.com/rainprotocol/rain.math.fixedpoint
[submodule "lib/rain.math.saturating"]
path = lib/rain.math.saturating
url = https://github.com/rainprotocol/rain.math.saturating
14 changes: 13 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ libs = ['lib']
ffi = true

solc = "0.8.19"

# Try to make sure the optimizer doesn't touch the output in a way that can break
# source maps for debugging.
# via_ir = false
# optimizer = false
# optimizer_runs = 0
# optimizer_steps = 0

# These settings should be used for snapshots
optimizer = true
optimizer_runs = 100000
optimizer_runs = 1000000

bytecode_hash = "none"
cbor_metadata = false


# Build metadata used for testing rain meta aware contracts in this folder rather
# than expose ffi to forge.
fs_permissions = [
{ access = "read-write", path = "test/csvs"}
]
Expand Down
2 changes: 1 addition & 1 deletion lib/rain.interpreter.interface
Submodule rain.interpreter.interface updated 49 files
+15 −0 .gitmodules
+1 −0 lib/forge-std
+1 −0 lib/openzeppelin-contracts
+1 −0 lib/rain.lib.hash
+1 −0 lib/rain.lib.typecast
+1 −0 lib/rain.solmem
+2 −2 slither.config.json
+38 −0 src/error/ErrBytecode.sol
+0 −0 src/interface/IExpressionDeployerV3.sol
+3 −3 src/interface/IInterpreterCallerV2.sol
+1 −1 src/interface/IInterpreterExternV3.sol
+1 −1 src/interface/IInterpreterStoreV2.sol
+1 −1 src/interface/IInterpreterV2.sol
+1 −1 src/interface/ISubParserV2.sol
+1 −1 src/interface/deprecated/IDebugExpressionDeployerV1.sol
+1 −1 src/interface/deprecated/IDebugInterpreterV1.sol
+1 −1 src/interface/deprecated/IDebugInterpreterV2.sol
+1 −1 src/interface/deprecated/IExpressionDeployerV1.sol
+1 −1 src/interface/deprecated/IExpressionDeployerV2.sol
+1 −1 src/interface/deprecated/IInterpreterCallerV1.sol
+1 −1 src/interface/deprecated/IInterpreterStoreV1.sol
+1 −1 src/interface/deprecated/IInterpreterV1.sol
+6 −0 src/interface/unstable/IAnalyzerV1.sol
+17 −0 src/interface/unstable/IInterpreterV3.sol
+6 −0 src/interface/unstable/IParserV2.sol
+315 −0 src/lib/bytecode/LibBytecode.sol
+205 −0 src/lib/caller/LibContext.sol
+25 −0 src/lib/caller/LibDeployerDiscoverable.sol
+42 −0 src/lib/caller/LibEncodedDispatch.sol
+28 −0 src/lib/caller/LibEvaluable.sol
+30 −0 src/lib/ns/LibNamespace.sol
+110 −0 test/abstract/BytecodeTest.sol
+365 −0 test/src/lib/bytecode/LibBytecode.checkNoOOBPointers.t.sol
+25 −0 test/src/lib/bytecode/LibBytecode.sourceCount.t.sol
+49 −0 test/src/lib/bytecode/LibBytecode.sourceInputsOutputs.t.sol
+53 −0 test/src/lib/bytecode/LibBytecode.sourceOpsCount.t.sol
+61 −0 test/src/lib/bytecode/LibBytecode.sourcePointer.t.sol
+79 −0 test/src/lib/bytecode/LibBytecode.sourceRelativeOffset.t.sol
+48 −0 test/src/lib/bytecode/LibBytecode.sourceStackAllocation.t.sol
+63 −0 test/src/lib/bytecode/LibBytecodeSlow.sol
+62 −0 test/src/lib/caller/LibContext.hash.t.sol
+47 −0 test/src/lib/caller/LibContext.t.sol
+57 −0 test/src/lib/caller/LibContextSlow.sol
+28 −0 test/src/lib/caller/LibDeployerV3Discoverable.t.sol
+17 −0 test/src/lib/caller/LibEncodedDispatch.t.sol
+73 −0 test/src/lib/caller/LibEvaluable.t.sol
+16 −0 test/src/lib/caller/LibEvaluableSlow.sol
+24 −0 test/src/lib/ns/LibNamespace.t.sol
+18 −0 test/src/lib/ns/LibNamespaceSlow.sol
1 change: 1 addition & 0 deletions lib/rain.math.saturating
Submodule rain.math.saturating added at 8d8406
42 changes: 0 additions & 42 deletions src/lib/LibEncodedDispatch.sol

This file was deleted.

30 changes: 0 additions & 30 deletions src/lib/LibNamespace.sol

This file was deleted.

271 changes: 271 additions & 0 deletions src/lib/LibTrancheSpaceOrders.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import {Vm} from "forge-std/Vm.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";

// STRATEGY PARAMS
uint256 constant TRANCHE_SPACE_PER_SECOND = 0;
uint256 constant TRANCHE_SPACE_RECHARGE_DELAY = 0;
uint256 constant TRANCHE_SIZE_BASE = 5000e18;
uint256 constant TRANCHE_SIZE_GROWTH = 1e18;
uint256 constant IO_RATIO_BASE = 6e18;
uint256 constant IO_RATIO_GROWTH = 1e17;
uint256 constant MIN_TRANCHE_SPACE_DIFF = 1e17;
uint256 constant TRANCHE_SNAP_THRESHOLD = 1e16;
uint256 constant AMOUNT_IS_OUTPUT = 0;

library LibTrancheSpaceOrders {
using Strings for address;
using Strings for uint256;

struct TrancheSpaceOrder {
uint256 trancheSpacePerSecond;
uint256 trancheSpaceRechargeDelay;
uint256 trancheSizeBase;
uint256 trancheSizeGrowth;
uint256 ioRatioBase;
uint256 ioRatioGrowth;
uint256 minTrancheSpaceDiff;
uint256 trancheSpaceSnapThreshold;
uint256 amountIsOutput;
uint256 referenceStableDecimals;
uint256 referenceReserveDecimals;
address referenceStable;
address referenceReserve;
}

struct TestTrancheSpaceOrder {
uint256 trancheSpacePerSecond;
uint256 trancheSpaceRechargeDelay;
uint256 trancheSizeBase;
uint256 trancheSizeGrowth;
uint256 ioRatioBase;
uint256 ioRatioGrowth;
uint256 minTrancheSpaceDiff;
uint256 trancheSpaceSnapThreshold;
uint256 amountIsOutput;
uint256 referenceStableDecimals;
uint256 referenceReserveDecimals;
uint256 testTrancheSpaceBefore;
uint256 testLastTimeUpdate;
uint256 testNow;
address referenceStable;
address referenceReserve;
}

function getTrancheSpaceOrder(Vm vm, address orderBookSubparser, TrancheSpaceOrder memory trancheSpaceOrderConfig)
internal
returns (bytes memory trancheSpaceOrder)
{
string[] memory ffi = new string[](45);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/tranche-space.rain";
ffi[5] = "--entrypoint";
ffi[6] = "calculate-io";
ffi[7] = "--entrypoint";
ffi[8] = "handle-io";
ffi[9] = "--bind";
ffi[10] = string.concat("tranche-space-per-second=", trancheSpaceOrderConfig.trancheSpacePerSecond.toString());
ffi[11] = "--bind";
ffi[12] =
string.concat("tranche-space-recharge-delay=", trancheSpaceOrderConfig.trancheSpaceRechargeDelay.toString());
ffi[13] = "--bind";
ffi[14] = "tranche-size-expr='constant-growth";
ffi[15] = "--bind";
ffi[16] = string.concat("tranche-size-base=", trancheSpaceOrderConfig.trancheSizeBase.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("tranche-size-growth=", trancheSpaceOrderConfig.trancheSizeGrowth.toString());
ffi[19] = "--bind";
ffi[20] = "io-ratio-expr='linear-growth";
ffi[21] = "--bind";
ffi[22] = string.concat("io-ratio-base=", trancheSpaceOrderConfig.ioRatioBase.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("io-ratio-growth=", trancheSpaceOrderConfig.ioRatioGrowth.toString());
ffi[25] = "--bind";
ffi[26] = string.concat("reference-stable=", trancheSpaceOrderConfig.referenceStable.toHexString());
ffi[27] = "--bind";
ffi[28] =
string.concat("reference-stable-decimals=", trancheSpaceOrderConfig.referenceStableDecimals.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("reference-reserve=", trancheSpaceOrderConfig.referenceReserve.toHexString());
ffi[31] = "--bind";
ffi[32] =
string.concat("reference-reserve-decimals=", trancheSpaceOrderConfig.referenceReserveDecimals.toString());
ffi[33] = "--bind";
ffi[34] = string.concat("min-tranche-space-diff=", trancheSpaceOrderConfig.minTrancheSpaceDiff.toString());
ffi[35] = "--bind";
ffi[36] =
string.concat("tranche-space-snap-threshold=", trancheSpaceOrderConfig.trancheSpaceSnapThreshold.toString());
ffi[37] = "--bind";
ffi[38] = string.concat("amount-is-output=", trancheSpaceOrderConfig.amountIsOutput.toString());
ffi[39] = "--bind";
ffi[40] = "get-last-tranche='get-real-last-tranche";
ffi[41] = "--bind";
ffi[42] = "set-last-tranche='set-real-last-tranche";
ffi[43] = "--bind";
ffi[44] = "io-ratio-multiplier='io-ratio-multiplier-identity";

trancheSpaceOrder = bytes.concat(getSubparserPrelude(orderBookSubparser), vm.ffi(ffi));
}

function getTestTrancheSpaceOrder(
Vm vm,
address orderBookSubparser,
TestTrancheSpaceOrder memory testTrancheSpaceOrderConfig
) internal returns (bytes memory testTrancheSpaceOrder) {
string[] memory ffi = new string[](51);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/tranche-space.rain";
ffi[5] = "--entrypoint";
ffi[6] = "calculate-io";
ffi[7] = "--entrypoint";
ffi[8] = "handle-io";
ffi[9] = "--bind";
ffi[10] =
string.concat("tranche-space-per-second=", testTrancheSpaceOrderConfig.trancheSpacePerSecond.toString());
ffi[11] = "--bind";
ffi[12] = string.concat(
"tranche-space-recharge-delay=", testTrancheSpaceOrderConfig.trancheSpaceRechargeDelay.toString()
);
ffi[13] = "--bind";
ffi[14] = "tranche-size-expr='constant-growth";
ffi[15] = "--bind";
ffi[16] = string.concat("tranche-size-base=", testTrancheSpaceOrderConfig.trancheSizeBase.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("tranche-size-growth=", testTrancheSpaceOrderConfig.trancheSizeGrowth.toString());
ffi[19] = "--bind";
ffi[20] = "io-ratio-expr='linear-growth";
ffi[21] = "--bind";
ffi[22] = string.concat("io-ratio-base=", testTrancheSpaceOrderConfig.ioRatioBase.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("io-ratio-growth=", testTrancheSpaceOrderConfig.ioRatioGrowth.toString());
ffi[25] = "--bind";
ffi[26] = string.concat("reference-stable=", testTrancheSpaceOrderConfig.referenceStable.toHexString());
ffi[27] = "--bind";
ffi[28] =
string.concat("reference-stable-decimals=", testTrancheSpaceOrderConfig.referenceStableDecimals.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("reference-reserve=", testTrancheSpaceOrderConfig.referenceReserve.toHexString());
ffi[31] = "--bind";
ffi[32] = string.concat(
"reference-reserve-decimals=", testTrancheSpaceOrderConfig.referenceReserveDecimals.toString()
);
ffi[33] = "--bind";
ffi[34] = string.concat("min-tranche-space-diff=", testTrancheSpaceOrderConfig.minTrancheSpaceDiff.toString());
ffi[35] = "--bind";
ffi[36] = string.concat(
"tranche-space-snap-threshold=", testTrancheSpaceOrderConfig.trancheSpaceSnapThreshold.toString()
);
ffi[37] = "--bind";
ffi[38] = string.concat("amount-is-output=", testTrancheSpaceOrderConfig.amountIsOutput.toString());
ffi[39] = "--bind";
ffi[40] = "get-last-tranche='get-test-last-tranche";
ffi[41] = "--bind";
ffi[42] = "set-last-tranche='set-test-last-tranche";
ffi[43] = "--bind";
ffi[44] = "io-ratio-multiplier='io-ratio-multiplier-identity";
ffi[45] = "--bind";
ffi[46] =
string.concat("test-tranche-space-before=", testTrancheSpaceOrderConfig.testTrancheSpaceBefore.toString());
ffi[47] = "--bind";
ffi[48] = string.concat("test-last-update-time=", testTrancheSpaceOrderConfig.testLastTimeUpdate.toString());
ffi[49] = "--bind";
ffi[50] = string.concat("test-now=", testTrancheSpaceOrderConfig.testNow.toString());

testTrancheSpaceOrder = bytes.concat(getSubparserPrelude(orderBookSubparser), vm.ffi(ffi));
}

function getCalculateTranche(
Vm vm,
address orderBookSubparser,
uint256 testTrancheSpaceBefore,
uint256 testLastTimeUpdate,
uint256 testNow
) internal returns (bytes memory calculateTranche) {
string[] memory ffi = new string[](25);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/tranche-space.rain";
ffi[5] = "--entrypoint";
ffi[6] = "calculate-tranche";
ffi[7] = "--bind";
ffi[8] = string.concat("tranche-space-per-second=", TRANCHE_SPACE_PER_SECOND.toString());
ffi[9] = "--bind";
ffi[10] = string.concat("tranche-space-recharge-delay=", TRANCHE_SPACE_RECHARGE_DELAY.toString());
ffi[11] = "--bind";
ffi[12] = "tranche-size-expr='constant-growth";
ffi[13] = "--bind";
ffi[14] = string.concat("tranche-size-base=", TRANCHE_SIZE_BASE.toString());
ffi[15] = "--bind";
ffi[16] = string.concat("tranche-size-growth=", TRANCHE_SIZE_GROWTH.toString());
ffi[17] = "--bind";
ffi[18] = "get-last-tranche='get-test-last-tranche";
ffi[19] = "--bind";
ffi[20] = string.concat("test-tranche-space-before=", testTrancheSpaceBefore.toString());
ffi[21] = "--bind";
ffi[22] = string.concat("test-last-update-time=", testLastTimeUpdate.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("test-now=", testNow.toString());

calculateTranche = bytes.concat(getSubparserPrelude(orderBookSubparser), vm.ffi(ffi));
}

function getHandleIo(
Vm vm,
address orderBookSubparser,
uint256 testTrancheSpaceBefore,
uint256 testLastTimeUpdate,
uint256 testNow
) internal returns (bytes memory calculateTranche) {
string[] memory ffi = new string[](33);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/tranche-space.rain";
ffi[5] = "--entrypoint";
ffi[6] = "handle-io";
ffi[7] = "--bind";
ffi[8] = string.concat("tranche-space-per-second=", TRANCHE_SPACE_PER_SECOND.toString());
ffi[9] = "--bind";
ffi[10] = string.concat("tranche-space-recharge-delay=", TRANCHE_SPACE_RECHARGE_DELAY.toString());
ffi[11] = "--bind";
ffi[12] = "tranche-size-expr='constant-growth";
ffi[13] = "--bind";
ffi[14] = string.concat("tranche-size-base=", TRANCHE_SIZE_BASE.toString());
ffi[15] = "--bind";
ffi[16] = string.concat("tranche-size-growth=", TRANCHE_SIZE_GROWTH.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("min-tranche-space-diff=", MIN_TRANCHE_SPACE_DIFF.toString());
ffi[19] = "--bind";
ffi[20] = string.concat("tranche-space-snap-threshold=", TRANCHE_SNAP_THRESHOLD.toString());
ffi[21] = "--bind";
ffi[22] = "get-last-tranche='get-test-last-tranche";
ffi[23] = "--bind";
ffi[24] = "set-last-tranche='set-test-last-tranche";
ffi[25] = "--bind";
ffi[26] = string.concat("test-tranche-space-before=", testTrancheSpaceBefore.toString());
ffi[27] = "--bind";
ffi[28] = string.concat("test-last-update-time=", testLastTimeUpdate.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("test-now=", testNow.toString());
ffi[31] = "--bind";
ffi[32] = string.concat("amount-is-output=", AMOUNT_IS_OUTPUT.toString());

calculateTranche = bytes.concat(getSubparserPrelude(orderBookSubparser), vm.ffi(ffi));
}

function getSubparserPrelude(address obSubparser) internal pure returns (bytes memory) {
bytes memory RAINSTRING_OB_SUBPARSER = bytes(string.concat("using-words-from ", obSubparser.toHexString(), " "));
return RAINSTRING_OB_SUBPARSER;
}
}
Loading

0 comments on commit 965558f

Please sign in to comment.