feat: Add swap method (first attempt)
Will add tests and fullproof it in a future PR --- don't change below this line --- ENG-4041 Took 8 minutes Took 42 seconds Took 5 seconds
This commit is contained in:
40
foundry/src/Swap.sol
Normal file
40
foundry/src/Swap.sol
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
library Swap {
|
||||
/// Returns the InToken index into an array of tokens
|
||||
function tokenInIndex(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint8 res)
|
||||
{
|
||||
res = uint8(swap[0]);
|
||||
}
|
||||
|
||||
/// The OutToken index into an array of tokens
|
||||
function tokenOutIndex(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint8 res)
|
||||
{
|
||||
res = uint8(swap[1]);
|
||||
}
|
||||
|
||||
/// The relative amount of token quantity routed into this swap
|
||||
function splitPercentage(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint24 res)
|
||||
{
|
||||
res = uint24(bytes3(swap[2:5]));
|
||||
}
|
||||
|
||||
/// Remaining bytes are interpreted as protocol data
|
||||
function protocolData(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (bytes calldata res)
|
||||
{
|
||||
res = swap[5:];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user