-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) A LockProxyProxy contract which limits access to the LockProxy…
… extension to nominated tokens.
- Loading branch information
1 parent
d251a5d
commit 7793dcb
Showing
13 changed files
with
252 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
smart-contracts/contracts/periphery/ILockProxyExtensionTransfer.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.20; | ||
|
||
// The part of the LockProxy extension interface that allows us to mint and burn | ||
// tokens. | ||
interface ILockProxyExtensionTransfer { | ||
function extensionTransfer( | ||
address _receivingAddress, | ||
address _assetHash, | ||
uint256 _amount | ||
) external returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.20; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; | ||
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
import { ILockProxyExtensionTransfer } from "contracts/periphery/ILockProxyExtensionTransfer.sol"; | ||
|
||
/// @dev This is a lock proxy proxy; it ensures that the extension is only called for a fixed set of tokens, | ||
/// decided at deployment time. | ||
contract LockProxyProxy is ILockProxyExtensionTransfer, Ownable2Step { | ||
using EnumerableSet for EnumerableSet.AddressSet; | ||
|
||
address public lockProxy; | ||
mapping(address => bool) legalTokens; | ||
EnumerableSet.AddressSet legalCallers; | ||
|
||
error UnauthorizedCaller(address caller); | ||
|
||
constructor(address[] memory _tokens, address _owner, address _lockProxy) Ownable(_owner) { | ||
lockProxy = _lockProxy; | ||
for (uint i; i < _tokens.length; ++i) { | ||
legalTokens[_tokens[i]] = true; | ||
} | ||
} | ||
|
||
function addCaller(address _caller) onlyOwner public { | ||
legalCallers.add(_caller); | ||
|
||
} | ||
|
||
function removeCaller(address _caller) onlyOwner public { | ||
legalCallers.remove(_caller); | ||
} | ||
|
||
function enumerateCallers() public view returns (address[] memory) { | ||
return legalCallers.values(); | ||
} | ||
|
||
modifier onlyValidCaller() { | ||
if (!legalCallers.contains(_msgSender())) { | ||
revert UnauthorizedCaller(_msgSender()); | ||
} | ||
_; | ||
} | ||
|
||
function extensionTransfer(address _receivingAddress, address _assetHash, uint256 _amount) external onlyValidCaller returns (bool) { | ||
require(legalTokens[_assetHash], "Bad asset hash"); | ||
return ILockProxyExtensionTransfer(lockProxy).extensionTransfer(_receivingAddress, _assetHash, _amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.20; | ||
|
||
import {Tester, Vm} from "test/Tester.sol"; | ||
import { LockProxyProxy } from "contracts/periphery/LockProxyProxy.sol"; | ||
import { ILockProxyExtensionTransfer } from "contracts/periphery/ILockProxyExtensionTransfer.sol"; | ||
import { TestToken } from "test/Helpers.sol"; | ||
|
||
contract TestLockProxyProxy is Tester, ILockProxyExtensionTransfer { | ||
Vm.Wallet validatorWallet = vm.createWallet("validator"); | ||
address validator = validatorWallet.addr; | ||
|
||
Vm.Wallet callerWallet = vm.createWallet("caller"); | ||
Vm.Wallet otherWallet = vm.createWallet("other"); | ||
|
||
Vm.Wallet transferorWallet = vm.createWallet("transferor"); | ||
|
||
LockProxyProxy theProxy; | ||
TestToken allowedToken; | ||
TestToken disallowedToken; | ||
uint tokenSupply = 1000 ether; | ||
uint tokensTransferred = 12 ether; | ||
|
||
function extensionTransfer(address _receivingAddress, address /* _assetHash */, uint256 _amount) external returns (bool) { | ||
assertEq(_receivingAddress, transferorWallet.addr); | ||
// Deliberately don't validate on the asset hash because we want the caller to do it. | ||
assertEq(_amount, tokensTransferred); | ||
return true; | ||
} | ||
|
||
|
||
function setUp() public { | ||
vm.startPrank(validator); | ||
// Deploy the test token | ||
allowedToken = new TestToken(tokenSupply); | ||
disallowedToken = new TestToken(tokenSupply); | ||
address[] memory allowedTokens = new address[](1); | ||
allowedTokens[0] = address(allowedToken); | ||
theProxy = new LockProxyProxy(allowedTokens, validator, address(this)); | ||
theProxy.addCaller(callerWallet.addr); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testTransfer() public { | ||
vm.startPrank(callerWallet.addr); | ||
ILockProxyExtensionTransfer(theProxy).extensionTransfer(transferorWallet.addr, address(allowedToken), | ||
tokensTransferred ); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testInvalidToken() public { | ||
vm.expectRevert("Bad asset hash"); | ||
vm.startPrank(callerWallet.addr); | ||
ILockProxyExtensionTransfer(theProxy).extensionTransfer(transferorWallet.addr, address(disallowedToken), tokensTransferred); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testInvalidCaller() public { | ||
vm.expectRevert(); | ||
vm.startPrank(otherWallet.addr); | ||
ILockProxyExtensionTransfer(theProxy).extensionTransfer(transferorWallet.addr, address(allowedToken), tokensTransferred); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testRemoveCaller() public { | ||
vm.startPrank(validator); | ||
theProxy.removeCaller(callerWallet.addr); | ||
vm.stopPrank(); | ||
vm.startPrank(callerWallet.addr); | ||
vm.expectRevert(); | ||
ILockProxyExtensionTransfer(theProxy).extensionTransfer(transferorWallet.addr, address(allowedToken), | ||
tokensTransferred ); | ||
vm.stopPrank(); | ||
vm.startPrank(validator); | ||
theProxy.addCaller(callerWallet.addr); | ||
vm.stopPrank(); | ||
vm.startPrank(callerWallet.addr); | ||
ILockProxyExtensionTransfer(theProxy).extensionTransfer(transferorWallet.addr, address(allowedToken), | ||
tokensTransferred ); | ||
vm.stopPrank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.