Skip to content

Commit

Permalink
pass in string directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dianakocsis committed Sep 23, 2024
1 parent 8506989 commit 4542c59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
2 changes: 1 addition & 1 deletion script/DeployPositionDescriptor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {PositionDescriptor} from "../src/PositionDescriptor.sol";
contract DeployPositionDescriptorTest is Script {
function setUp() public {}

function run(address poolManager, address weth, bytes32 nativeCurrencyLabel)
function run(address poolManager, address weth, string memory nativeCurrencyLabel)
public
returns (PositionDescriptor positionDescriptor)
{
Expand Down
25 changes: 5 additions & 20 deletions src/PositionDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,14 @@ contract PositionDescriptor is IPositionDescriptor {
address private constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;

address public immutable WETH9;
/// @dev A null-terminated string
bytes32 public immutable nativeCurrencyLabelBytes;
string public nativeCurrencyLabel;

IPoolManager public immutable poolManager;

constructor(IPoolManager _poolManager, address _WETH9, bytes32 _nativeCurrencyLabel) {
constructor(IPoolManager _poolManager, address _WETH9, string memory _nativeCurrencyLabel) {
poolManager = _poolManager;
WETH9 = _WETH9;
nativeCurrencyLabelBytes = _nativeCurrencyLabel;
}

/// @notice Takes the native currency label in bytes32 and returns it as a string
/// @return nativeCurrencyLabel The native currency label
function nativeCurrencyLabel() public view returns (string memory) {
uint256 len = 0;
while (len < 32 && nativeCurrencyLabelBytes[len] != 0) {
len++;
}
bytes memory b = new bytes(len);
for (uint256 i = 0; i < len; i++) {
b[i] = nativeCurrencyLabelBytes[i];
}
return string(b);
nativeCurrencyLabel = _nativeCurrencyLabel;
}

/// @inheritdoc IPositionDescriptor
Expand All @@ -80,10 +65,10 @@ contract PositionDescriptor is IPositionDescriptor {
quoteCurrency: quoteCurrency,
baseCurrency: baseCurrency,
quoteCurrencySymbol: quoteCurrency.isAddressZero()
? nativeCurrencyLabel()
? nativeCurrencyLabel
: SafeERC20Namer.tokenSymbol(Currency.unwrap(quoteCurrency)),
baseCurrencySymbol: baseCurrency.isAddressZero()
? nativeCurrencyLabel()
? nativeCurrencyLabel
: SafeERC20Namer.tokenSymbol(Currency.unwrap(baseCurrency)),
quoteCurrencyDecimals: quoteCurrency.isAddressZero()
? 18
Expand Down
8 changes: 2 additions & 6 deletions test/PositionDescriptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PositionDescriptorTest is Test, PosmTestSetup {
address public USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
address public TBTC = 0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa;
address public WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
bytes32 public nativeCurrencyLabel = "ETH";
string public nativeCurrencyLabel = "ETH";

struct Token {
string description;
Expand All @@ -39,11 +39,7 @@ contract PositionDescriptorTest is Test, PosmTestSetup {
function test_setup_succeeds() public view {
assertEq(address(positionDescriptor.poolManager()), address(manager));
assertEq(positionDescriptor.WETH9(), WETH9);
assertEq(positionDescriptor.nativeCurrencyLabelBytes(), nativeCurrencyLabel);
}

function test_nativeCurrencyLabel_succeeds() public view {
assertEq(positionDescriptor.nativeCurrencyLabel(), "ETH");
assertEq(positionDescriptor.nativeCurrencyLabel(), nativeCurrencyLabel);
}

function test_currencyRatioPriority_mainnet_succeeds() public {
Expand Down

0 comments on commit 4542c59

Please sign in to comment.