Skip to content

Commit e85b4bf

Browse files
committed
docs: add LookupDelegatedAddress usage, tests, and demo deployment instructions
1 parent 53c4a7a commit e85b4bf

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,47 @@ contract BigBrain {
6060
}
6161
```
6262

63+
### FVMActor - LookupDelegatedAddress
64+
Look up the delegated (f4 / f410) address associated with an actor ID on the FEVM.
65+
66+
```solidity
67+
import { FVMActor } from "fvm-solidity/FVMActor.sol";
68+
69+
contract BigBrain {
70+
using FVMActor for uint64;
71+
72+
// Try lookup without reverting
73+
function tryLookup(uint64 actorId) external view returns (bool exists, address addr) {
74+
return actorId.tryLookupDelegatedAddress();
75+
}
76+
77+
// Strict lookup (reverts if not found)
78+
function lookup(uint64 actorId) external view returns (address) {
79+
return actorId.lookupDelegatedAddress();
80+
}
81+
}
82+
```
83+
84+
#### Raw delegated address bytes
85+
86+
If you need the raw f4 / f410 encoded address:
87+
88+
```solidity
89+
import {FVMActor} from "fvm-solidity/FVMActor.sol";
90+
91+
contract BigBrain {
92+
using FVMActor for uint64;
93+
94+
function tryLookupBytes(uint64 actorId) external view returns (bool exists, bytes memory delegated) {
95+
return actorId.tryLookupDelegatedAddressBytes();
96+
}
97+
98+
function lookupBytes(uint64 actorId) external view returns (bytes memory delegated) {
99+
return actorId.lookupDelegatedAddressBytes();
100+
}
101+
}
102+
```
103+
63104
### Testing
64105
```solidity
65106
import {MockFVMTest} from "fvm-solidity/mocks/MockFVMTest.sol";
@@ -70,6 +111,7 @@ import {FVMAddress} from "fvm-solidity/FVMAddress.sol";
70111
contract BigBrainTest is MockFVMTest {
71112
using FVMAddress for uint64;
72113
using FVMActor for bytes;
114+
using FVMActor for uint64;
73115
74116
function setUp() public override {
75117
// Mock the FVM precompiles for forge test
@@ -80,12 +122,22 @@ contract BigBrainTest is MockFVMTest {
80122
function test_resolveAddress() public {
81123
uint64 actorId = 1234;
82124
bytes memory filAddress = actorId.f0();
83-
ACTOR_PRECOMPILE.mockResolveAddress(filAddress, actorId);
125+
RESOLVE_ADDRESS_PRECOMPILE.mockResolveAddress(filAddress, actorId);
84126
85127
(bool exists, uint64 resolved) = filAddress.tryGetActorId();
86128
assertTrue(exists);
87129
assertEq(resolved, actorId);
88130
}
131+
132+
function test_lookupDelegatedAddress() public {
133+
uint64 actorId = 1234;
134+
address ethAddr = address(0x1234567890123456789012345678901234567890);
135+
LOOKUP_DELEGATED_ADDRESS_PRECOMPILE.mockLookupDelegatedAddress(actorId, ethAddr);
136+
137+
(bool exists, address addr) = actorId.tryLookupDelegatedAddress();
138+
assertTrue(exists);
139+
assertEq(addr, ethAddr);
140+
}
89141
}
90142
```
91143

@@ -110,7 +162,7 @@ Additional FVM support can be found in the [filecoin-solidity library](https://g
110162
| Supported | Name | Address |
111163
| :-------: | :--- | :------ |
112164
|| ResolveAddress | `0xfe00000000000000000000000000000000000001` |
113-
| | LookupDelegatedAddress | `0xfe00000000000000000000000000000000000002` |
165+
| | LookupDelegatedAddress | `0xfe00000000000000000000000000000000000002` |
114166
|| CallActorByAddress | `0xfe00000000000000000000000000000000000003` |
115167
|| CallActorById | `0xfe00000000000000000000000000000000000005` |
116168
|| GetBeaconRandomness | `0xfe00000000000000000000000000000000000006` |
@@ -121,3 +173,11 @@ Additional FVM support can be found in the [filecoin-solidity library](https://g
121173
| :-------: | :--- | :----- |
122174
|| Send | 0 |
123175
|| Constructor | 1 |
176+
177+
### Demo Deployment
178+
179+
You can deploy the demo contract using the helper script:
180+
181+
```sh
182+
./tools/deploy-demo.sh
183+
```

0 commit comments

Comments
 (0)