Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/err/ErrFtso.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ error InconsistentFtso();
/// Thrown when decimals are too large to handle safely.
/// @param decimals The decimals that were too large.
error DecimalsTooLarge(uint256 decimals);

/// Thrown when the sFLR contract returns a zero exchange rate.
error ZeroSFLRRate();
2 changes: 1 addition & 1 deletion src/generated/FlareFtsoWords.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pragma solidity ^0.8.25;
// file needs the contract to exist so that it can be compiled.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x96e4ec5ff213f69e32f76c5ce42fb5ae8a42af3ad080341ce1d1b74a0061723d);
bytes32 constant BYTECODE_HASH = bytes32(0xa6e08b45005271ce77af0810fef0a97d7bbbdda007793e4be428ba5737caf303);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x8717d07737e3cedcdddea6cd3337ae762d7089918bf8d818fb0afc5b63e3985a);
Expand Down
5 changes: 4 additions & 1 deletion src/lib/sflr/LibSceptreStakedFlare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity ^0.8.19;

import {IStakedFlr} from "../../interface/IStakedFlr.sol";
import {ZeroSFLRRate} from "../../err/ErrFtso.sol";

/// @dev Immutable upgradeable proxy contract to the sFLR contract.
IStakedFlr constant SFLR_CONTRACT = IStakedFlr(address(0x12e605bc104e93B45e1aD99F9e555f659051c2BB));
Expand All @@ -13,6 +14,8 @@ library LibSceptreStakedFlare {
/// according to the sFLR contract's current exchange rate.
//forge-lint: disable-next-line(mixed-case-function)
function getSFLRPerFLR18() internal view returns (uint256) {
return SFLR_CONTRACT.getSharesByPooledFlr(1e18);
uint256 rate = SFLR_CONTRACT.getSharesByPooledFlr(1e18);
if (rate == 0) revert ZeroSFLRRate();
return rate;
}
}
18 changes: 17 additions & 1 deletion test/src/lib/sflr/LibSceptreStakedFlare.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pragma solidity =0.8.25;

import {Test} from "forge-std-1.16.1/src/Test.sol";
import {LibFork} from "test/fork/LibFork.sol";
import {LibSceptreStakedFlare} from "src/lib/sflr/LibSceptreStakedFlare.sol";
import {LibSceptreStakedFlare, SFLR_CONTRACT} from "src/lib/sflr/LibSceptreStakedFlare.sol";
import {IStakedFlr} from "src/interface/IStakedFlr.sol";
import {ZeroSFLRRate} from "src/err/ErrFtso.sol";

uint256 constant BLOCK_NUMBER = 31843105;

Expand All @@ -13,8 +15,22 @@ contract LibSceptreStakedFlareTest is Test {
vm.createSelectFork(LibFork.rpcUrlFlare(vm), BLOCK_NUMBER);
}

function externalGetSFLRPerFLR18() external view returns (uint256) {
return LibSceptreStakedFlare.getSFLRPerFLR18();
}

function testGetSFLRPerFLR18() external view {
uint256 rate18 = LibSceptreStakedFlare.getSFLRPerFLR18();
assertEq(rate18, 0.877817288626455057e18);
}

function testGetSFLRPerFLR18ZeroReverts() external {
vm.mockCall(
address(SFLR_CONTRACT),
abi.encodeWithSelector(IStakedFlr.getSharesByPooledFlr.selector, uint256(1e18)),
abi.encode(uint256(0))
);
vm.expectRevert(abi.encodeWithSelector(ZeroSFLRRate.selector));
this.externalGetSFLRPerFLR18();
}
}
Loading