Skip to content

Commit e53c3f2

Browse files
authored
Merge pull request #93 from AztecProtocol/lh/ace-of-zk
Lh/ace of zk
2 parents 90fa97f + 15989d9 commit e53c3f2

File tree

3 files changed

+145
-1
lines changed

3 files changed

+145
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"rootDir": "./src"
3939
},
4040
"name": "@aztec/bridge-clients",
41-
"version": "0.1.42",
41+
"version": "0.1.43",
4242
"description": "This repo contains the solidity files and typescript helper class for all of the Aztec Connect Bridge Contracts",
4343
"repository": "[email protected]:AztecProtocol/aztec-connect-bridges.git",
4444
"license": "MIT",

src/bridges/aceofzk/AceOfZkBridge.sol

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: GPLv2
2+
pragma solidity >=0.8.4;
3+
4+
import {IERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5+
import {IRollupProcessor} from "../../interfaces/IRollupProcessor.sol";
6+
import {IDefiBridge} from "../../interfaces/IDefiBridge.sol";
7+
import {AztecTypes} from "../../aztec/AztecTypes.sol";
8+
9+
contract AceOfZkBridge is IDefiBridge {
10+
error InvalidCaller();
11+
error AsyncDisabled();
12+
13+
address public constant ACE_OF_ZK_NFT = 0xE56B526E532804054411A470C49715c531CFd485;
14+
address public constant NFT_HOLDER = 0xE298a76986336686CC3566469e3520d23D1a8aaD;
15+
uint256 public constant NFT_ID = 16;
16+
17+
address public immutable ROLLUP_PROCESSOR;
18+
19+
constructor(address _rollupProcessor) {
20+
ROLLUP_PROCESSOR = _rollupProcessor;
21+
}
22+
23+
function convert(
24+
AztecTypes.AztecAsset calldata,
25+
AztecTypes.AztecAsset calldata,
26+
AztecTypes.AztecAsset calldata,
27+
AztecTypes.AztecAsset calldata,
28+
uint256,
29+
uint256,
30+
uint64,
31+
address
32+
)
33+
external
34+
payable
35+
returns (
36+
uint256,
37+
uint256,
38+
bool
39+
)
40+
{
41+
if (msg.sender != ROLLUP_PROCESSOR) {
42+
revert InvalidCaller();
43+
}
44+
45+
IERC721(ACE_OF_ZK_NFT).transferFrom(NFT_HOLDER, ROLLUP_PROCESSOR, NFT_ID);
46+
47+
return (0, 0, false);
48+
}
49+
50+
function finalise(
51+
AztecTypes.AztecAsset calldata,
52+
AztecTypes.AztecAsset calldata,
53+
AztecTypes.AztecAsset calldata,
54+
AztecTypes.AztecAsset calldata,
55+
uint256,
56+
uint64
57+
)
58+
external
59+
payable
60+
returns (
61+
uint256,
62+
uint256,
63+
bool
64+
)
65+
{
66+
revert AsyncDisabled();
67+
}
68+
}

src/test/aceofzk/AceOfZk.t.sol

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.4;
3+
4+
import {Test} from "forge-std/Test.sol";
5+
6+
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
7+
8+
import {DefiBridgeProxy} from "./../../aztec/DefiBridgeProxy.sol";
9+
import {RollupProcessor} from "./../../aztec/RollupProcessor.sol";
10+
import {AztecTypes} from "./../../aztec/AztecTypes.sol";
11+
12+
import {AceOfZkBridge} from "./../../bridges/aceofzk/AceOfZkBridge.sol";
13+
14+
contract AceOfZkTest is Test {
15+
error InvalidCaller();
16+
error AsyncDisabled();
17+
18+
IERC721 public constant ACE_OF_ZK_NFT = IERC721(0xE56B526E532804054411A470C49715c531CFd485);
19+
address public constant NFT_HOLDER = 0xE298a76986336686CC3566469e3520d23D1a8aaD;
20+
uint256 public constant NFT_ID = 16;
21+
22+
AceOfZkBridge internal bridge;
23+
DefiBridgeProxy internal defiBridgeProxy;
24+
RollupProcessor internal rollupProcessor;
25+
26+
AztecTypes.AztecAsset private empty;
27+
AztecTypes.AztecAsset private ethAsset =
28+
AztecTypes.AztecAsset({id: 1, erc20Address: address(0), assetType: AztecTypes.AztecAssetType.ETH});
29+
30+
function setUp() public {
31+
defiBridgeProxy = new DefiBridgeProxy();
32+
rollupProcessor = new RollupProcessor(address(defiBridgeProxy));
33+
34+
bridge = new AceOfZkBridge(address(rollupProcessor));
35+
36+
vm.prank(NFT_HOLDER);
37+
ACE_OF_ZK_NFT.approve(address(bridge), NFT_ID);
38+
}
39+
40+
function testHappyPath() public {
41+
// Fund rollup processor
42+
vm.deal(address(rollupProcessor), 1);
43+
44+
assertTrue(ACE_OF_ZK_NFT.ownerOf(NFT_ID) != address(rollupProcessor), "The rollup processor owns the nft");
45+
46+
(uint256 outputValueA, uint256 outputValueB, bool isAsync) = rollupProcessor.convert(
47+
address(bridge),
48+
ethAsset,
49+
empty,
50+
ethAsset,
51+
empty,
52+
1,
53+
0,
54+
0
55+
);
56+
57+
assertEq(outputValueA, 0, "Non zero return a");
58+
assertEq(outputValueB, 0, "Non zero return b");
59+
assertFalse(isAsync, "The convert was async");
60+
assertEq(ACE_OF_ZK_NFT.ownerOf(NFT_ID), address(rollupProcessor), "The rollup processor does not own the nft");
61+
}
62+
63+
function testWrongCaller(address _caller) public {
64+
vm.assume(_caller != address(rollupProcessor));
65+
66+
vm.prank(_caller);
67+
68+
vm.expectRevert(InvalidCaller.selector);
69+
bridge.convert(ethAsset, empty, ethAsset, empty, 0, 0, 0, _caller);
70+
}
71+
72+
function testAsyncDisabled() public {
73+
vm.expectRevert(AsyncDisabled.selector);
74+
bridge.finalise(ethAsset, empty, ethAsset, empty, 0, 0);
75+
}
76+
}

0 commit comments

Comments
 (0)