Replies: 7 comments 8 replies
-
Based on Andrei's gas estimations here, it should be safe to increase the number of segments to 500 on all chains except Avalanche, where we will still use 300. Any thoughts @andreivladbrg, @smol-ninja? |
Beta Was this translation helpful? Give feedback.
-
Adding it here for future reference. LockupTranched-createWithDurations Logs:
2829527 gas when 100 tranches.
5400617 gas when 200 tranches.
8040963 gas when 300 tranches.
10689330 gas when 400 tranches.
13346889 gas when 500 tranches.
16014814 gas when 600 tranches.
18694276 gas when 700 tranches.
21386447 gas when 800 tranches.
24092599 gas when 900 tranches. LockupTranched-createWithTimestamps Logs:
2765497 gas when 100 tranches.
5269622 gas when 200 tranches.
7840076 gas when 300 tranches.
10415625 gas when 400 tranches.
12997440 gas when 500 tranches.
15586695 gas when 600 tranches.
18184562 gas when 700 tranches.
20792210 gas when 800 tranches.
23410911 gas when 900 tranches. LockupDynamic-createWithDurations Logs:
2969510 gas when 100 segments.
5686270 gas when 200 segments.
8479262 gas when 300 segments.
11288544 gas when 400 segments.
14116573 gas when 500 segments.
16965813 gas when 600 segments.
19838723 gas when 700 segments.
22737765 gas when 800 segments.
25665536 gas when 900 segments. LockupDynamic-createWithTimestamps Logs:
2893423 gas when 100 segments.
5528371 gas when 200 segments.
8233815 gas when 300 segments.
10949808 gas when 400 segments.
13678815 gas when 500 segments.
16423294 gas when 600 segments.
19185706 gas when 700 segments.
21968514 gas when 800 segments.
24774313 gas when 900 segments. LockupTranched Code// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;
import { ud } from "@prb/math/src/UD60x18.sol";
import { console2 } from "forge-std/src/console2.sol";
import { Broker, LockupTranched } from "src/types/DataTypes.sol";
import { Base_Test } from "./Base.t.sol";
contract CreateLockupTranched_Gas_Test is Base_Test {
uint128 private constant PER_TRANCHE_AMOUNT = 10e18;
uint40 private constant TRANCHE_DURATION = 10;
uint128[] private tranches_array = [100, 200, 300, 400, 500, 600, 700, 800, 900];
function setUp() public override {
super.setUp();
deal({ token: address(dai), to: users.sender, give: type(uint256).max });
resetPrank({ msgSender: users.sender });
}
function test_GasCreateWithTimestamps() public {
for (uint256 i; i < tranches_array.length; ++i) {
LockupTranched.CreateWithTimestamps memory params = LockupTranched.CreateWithTimestamps({
sender: users.sender,
recipient: users.recipient,
totalAmount: PER_TRANCHE_AMOUNT * tranches_array[i],
asset: dai,
cancelable: true,
transferable: true,
startTime: uint40(block.timestamp),
tranches: _prepareTranches(tranches_array[i]),
broker: Broker({ account: address(0), fee: ud(0) })
});
uint256 beforeGas = gasleft();
lockupTranched.createWithTimestamps(params);
uint256 afterGas = gasleft();
console2.log("%s gas when %s tranches.", beforeGas - afterGas, tranches_array[i]);
}
}
function test_GasCreateWithDurations() public {
for (uint256 i; i < tranches_array.length; ++i) {
LockupTranched.CreateWithDurations memory params = LockupTranched.CreateWithDurations({
sender: users.sender,
recipient: users.recipient,
totalAmount: PER_TRANCHE_AMOUNT * tranches_array[i],
asset: dai,
cancelable: true,
transferable: true,
tranches: _prepareTranchesWithDuration(tranches_array[i]),
broker: Broker({ account: address(0), fee: ud(0) })
});
uint256 beforeGas = gasleft();
lockupTranched.createWithDurations(params);
uint256 afterGas = gasleft();
console2.log("%s gas when %s tranches.", beforeGas - afterGas, tranches_array[i]);
}
}
function _prepareTranches(uint128 count) private view returns (LockupTranched.Tranche[] memory tranches) {
tranches = new LockupTranched.Tranche[](count);
// Populate tranches
for (uint256 i = 0; i < count; ++i) {
tranches[i] = LockupTranched.Tranche({
amount: PER_TRANCHE_AMOUNT,
timestamp: uint40(block.timestamp + TRANCHE_DURATION * (1 + i))
});
}
}
function _prepareTranchesWithDuration(uint128 count)
private
pure
returns (LockupTranched.TrancheWithDuration[] memory tranches)
{
tranches = new LockupTranched.TrancheWithDuration[](count);
// Populate tranches
for (uint256 i = 0; i < count; ++i) {
tranches[i] = LockupTranched.TrancheWithDuration({ amount: PER_TRANCHE_AMOUNT, duration: TRANCHE_DURATION });
}
}
} LockupDynamic Code// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;
import { UD2x18 } from "@prb/math/src/UD2x18.sol";
import { ud } from "@prb/math/src/UD60x18.sol";
import { console2 } from "forge-std/src/console2.sol";
import { Broker, LockupDynamic } from "src/types/DataTypes.sol";
import { Base_Test } from "./Base.t.sol";
contract CreateLockupDynamic_Gas_Test is Base_Test {
uint128 private constant PER_SEGMENT_AMOUNT = 10e18;
uint40 private constant SEGMENT_DURATION = 10;
uint128[] private segments_array = [100, 200, 300, 400, 500, 600, 700, 800, 900];
function setUp() public override {
super.setUp();
deal({ token: address(dai), to: users.sender, give: type(uint256).max });
resetPrank({ msgSender: users.sender });
}
function test_GasCreateWithTimestamps() public {
for (uint256 i; i < segments_array.length; ++i) {
LockupDynamic.CreateWithTimestamps memory params = LockupDynamic.CreateWithTimestamps({
sender: users.sender,
recipient: users.recipient,
totalAmount: PER_SEGMENT_AMOUNT * segments_array[i],
asset: dai,
cancelable: true,
transferable: true,
startTime: uint40(block.timestamp),
segments: _prepareSegments(segments_array[i]),
broker: Broker({ account: address(0), fee: ud(0) })
});
uint256 beforeGas = gasleft();
lockupDynamic.createWithTimestamps(params);
uint256 afterGas = gasleft();
console2.log("%s gas when %s segments.", beforeGas - afterGas, segments_array[i]);
}
}
function test_GasCreateWithDurations() public {
for (uint256 i; i < segments_array.length; ++i) {
LockupDynamic.CreateWithDurations memory params = LockupDynamic.CreateWithDurations({
sender: users.sender,
recipient: users.recipient,
totalAmount: PER_SEGMENT_AMOUNT * segments_array[i],
asset: dai,
cancelable: true,
transferable: true,
segments: _prepareSegmentsWithDuration(segments_array[i]),
broker: Broker({ account: address(0), fee: ud(0) })
});
uint256 beforeGas = gasleft();
lockupDynamic.createWithDurations(params);
uint256 afterGas = gasleft();
console2.log("%s gas when %s segments.", beforeGas - afterGas, segments_array[i]);
}
}
function _prepareSegments(uint128 count) private view returns (LockupDynamic.Segment[] memory segments) {
segments = new LockupDynamic.Segment[](count);
// Populate segments
for (uint256 i = 0; i < count; ++i) {
segments[i] = LockupDynamic.Segment({
amount: PER_SEGMENT_AMOUNT,
exponent: UD2x18.wrap(2.72e18),
timestamp: uint40(block.timestamp + SEGMENT_DURATION * (1 + i))
});
}
}
function _prepareSegmentsWithDuration(uint128 count)
private
pure
returns (LockupDynamic.SegmentWithDuration[] memory segments)
{
segments = new LockupDynamic.SegmentWithDuration[](count);
// Populate segments
for (uint256 i = 0; i < count; ++i) {
segments[i] = LockupDynamic.SegmentWithDuration({
amount: PER_SEGMENT_AMOUNT,
exponent: UD2x18.wrap(2.72e18),
duration: SEGMENT_DURATION
});
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks @smol-ninja, these gas tables are super helpful.
|
Beta Was this translation helpful? Give feedback.
-
Related: #872 |
Beta Was this translation helpful? Give feedback.
-
Let's keep this discussion open until we pin down the ideal maximum limits for each chain. |
Beta Was this translation helpful? Give feedback.
-
Arbitrum also has 32M block gas limit. The big number returned by the RPC endpoint is hardcoded. |
Beta Was this translation helpful? Give feedback.
-
Closing this as has been resolved in #908. |
Beta Was this translation helpful? Give feedback.
-
We've recently received this feature request from a user:
This is proof that users are interested in creating streams with a high number of segments.
During the first mainnet deployment of Lockup Dynamic, Andrei estimated the optimal number of segments to be 300. That's what we have used for all of our deployments - but I wonder if we can increase that now?
Cc @andreivladbrg, @smol-ninja.
Beta Was this translation helpful? Give feedback.
All reactions