mirror of https://github.com/crytic/slither
parent
5a6ef0d5a6
commit
0165614270
Binary file not shown.
@ -0,0 +1,9 @@ |
||||
{ |
||||
"BalanceDeltaLibrary": { |
||||
"amount0(BalanceDelta)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n2->3;\n3[label=\"Node Type: END INLINE ASM 3\n\"];\n3->4;\n4[label=\"Node Type: RETURN 4\n\"];\n}\n", |
||||
"amount1(BalanceDelta)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: INLINE ASM 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n2->3;\n3[label=\"Node Type: END INLINE ASM 3\n\"];\n3->4;\n4[label=\"Node Type: RETURN 4\n\"];\n}\n" |
||||
}, |
||||
"X": { |
||||
"get(BalanceDelta)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: NEW VARIABLE 2\n\"];\n}\n" |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
// SPDX-License-Identifier: MIT |
||||
pragma solidity ^0.8.20; |
||||
|
||||
type BalanceDelta is int256; |
||||
|
||||
using {add as +, sub as -, eq as ==} for BalanceDelta global; |
||||
using BalanceDeltaLibrary for BalanceDelta global; |
||||
|
||||
function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) { |
||||
/// @solidity memory-safe-assembly |
||||
assembly { |
||||
balanceDelta := |
||||
or(shl(128, _amount0), and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, _amount1)) |
||||
} |
||||
} |
||||
|
||||
function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) { |
||||
return toBalanceDelta(a.amount0() + b.amount0(), a.amount1() + b.amount1()); |
||||
} |
||||
|
||||
function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) { |
||||
return toBalanceDelta(a.amount0() - b.amount0(), a.amount1() - b.amount1()); |
||||
} |
||||
|
||||
function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) { |
||||
return a.amount0() == b.amount0() && a.amount1() == b.amount1(); |
||||
} |
||||
|
||||
library BalanceDeltaLibrary { |
||||
function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) { |
||||
/// @solidity memory-safe-assembly |
||||
assembly { |
||||
_amount0 := shr(128, balanceDelta) |
||||
} |
||||
} |
||||
|
||||
function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) { |
||||
/// @solidity memory-safe-assembly |
||||
assembly { |
||||
_amount1 := balanceDelta |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
|
||||
import {BalanceDelta} from "./using_for_global_user_defined_operator.sol"; |
||||
contract X { |
||||
|
||||
function get(BalanceDelta delta) external { |
||||
int128 amount0 = delta.amount0(); |
||||
int128 amount1 = delta.amount1(); |
||||
} |
||||
} |
Loading…
Reference in new issue