-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockedCollateralAdapter.sol
More file actions
57 lines (51 loc) · 2.25 KB
/
Copy pathLockedCollateralAdapter.sol
File metadata and controls
57 lines (51 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import {IPledgeAdapter} from "../interfaces/IPledgeAdapter.sol";
import {EvmV1Decoder} from "../vendor/EvmV1Decoder.sol";
/**
* Reference adapter, for a protocol whose lifecycle events look like this:
*
* CollateralLocked (bytes32 indexed positionId, address indexed nftContract,
* address indexed owner, uint256 nftId, uint256 principal)
* ObligationCleared (same shape)
* CollateralUnlocked(same shape)
*
* Nothing about that schema matches the registry's native one: the instance id
* leads the topics, the token id lives in the data, and the amount trails it.
* The adapter is the whole integration, and the protocol is not touched.
*
* It is pure, it holds no state, and it is short on purpose. An adapter decides
* what a log means rather than merely which logs are read, which makes it the
* weakest link in the chain and the one worth keeping readable in one sitting.
* That is caveat 9.
*/
contract LockedCollateralAdapter is IPledgeAdapter {
bytes32 public constant LOCKED_SIG =
keccak256("CollateralLocked(bytes32,address,address,uint256,uint256)");
bytes32 public constant CLEARED_SIG =
keccak256("ObligationCleared(bytes32,address,address,uint256,uint256)");
bytes32 public constant UNLOCKED_SIG =
keccak256("CollateralUnlocked(bytes32,address,address,uint256,uint256)");
error UnexpectedTopics(uint256 count);
function signaturesFor(uint8 kind) external pure returns (bytes32[] memory signatures) {
signatures = new bytes32[](1);
signatures[0] = kind == 0 ? LOCKED_SIG : (kind == 1 ? CLEARED_SIG : UNLOCKED_SIG);
}
function translate(uint8, EvmV1Decoder.LogEntry calldata log)
external
pure
returns (
address collateralToken,
uint256 tokenId,
address borrower,
uint256 amount,
bytes32 instanceId
)
{
if (log.topics.length != 4) revert UnexpectedTopics(log.topics.length);
instanceId = log.topics[1];
collateralToken = address(uint160(uint256(log.topics[2])));
borrower = address(uint160(uint256(log.topics[3])));
(tokenId, amount) = abi.decode(log.data, (uint256, uint256));
}
}