Skip to content

Commit e2f5dc2

Browse files
alex-connollyAlex ConnollyCodeSchwert
authored
Migrating all Immutable X contracts and tests (#116)
* Migrating all IMX contracts and tests. * lint fix --------- Co-authored-by: Alex Connolly <[email protected]> Co-authored-by: Nik Ho <[email protected]>
1 parent 17986cd commit e2f5dc2

File tree

8 files changed

+621
-0
lines changed

8 files changed

+621
-0
lines changed

contracts/bridge/x/Core.sol

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.11;
3+
4+
interface Core {
5+
6+
function announceAvailabilityVerifierRemovalIntent(address) external;
7+
function announceVerifierRemovalIntent(address) external;
8+
function getRegisteredAvailabilityVerifiers() external;
9+
function getRegisteredVerifiers() external;
10+
function isAvailabilityVerifier(address) external;
11+
function isFrozen() external;
12+
function isVerifier(address) external;
13+
function mainAcceptGovernance() external;
14+
function mainCancelNomination() external;
15+
function mainIsGovernor(address) external;
16+
function mainNominateNewGovernor(address) external;
17+
function mainRemoveGovernor(address) external;
18+
function registerAvailabilityVerifier(address, string calldata) external;
19+
function registerVerifier(address, string calldata) external;
20+
function removeAvailabilityVerifier(address) external;
21+
function removeVerifier(address) external;
22+
function unFreeze() external;
23+
function getEthKey(uint256 starkKey) external view returns (address ethKey);
24+
function isOperator(address) external;
25+
function isTokenAdmin(address) external;
26+
function isUserAdmin(address) external;
27+
function onERC721Received(address, address, uint256, bytes calldata) external;
28+
function registerOperator(address) external;
29+
function registerToken(uint256, bytes calldata) external;
30+
function registerTokenAdmin(address) external;
31+
function registerUser(address, uint256, bytes calldata) external;
32+
function registerUserAdmin(address) external;
33+
function unregisterOperator(address) external;
34+
function unregisterTokenAdmin(address) external;
35+
function unregisterUserAdmin(address) external;
36+
function withdrawNftTo(uint256, uint256, uint256, address) external;
37+
function withdrawTo(uint256, uint256, address) external;
38+
39+
event LogDeposit(
40+
address depositorEthKey,
41+
uint256 starkKey,
42+
uint256 vaultId,
43+
uint256 assetType,
44+
uint256 nonQuantizedAmount,
45+
uint256 quantizedAmount
46+
);
47+
48+
event LogNftDeposit(
49+
address depositorEthKey,
50+
uint256 starkKey,
51+
uint256 vaultId,
52+
uint256 assetType,
53+
uint256 tokenId,
54+
uint256 assetId
55+
);
56+
57+
event LogDepositCancel(uint256 starkKey, uint256 vaultId, uint256 assetId);
58+
59+
event LogDepositCancelReclaimed(
60+
uint256 starkKey,
61+
uint256 vaultId,
62+
uint256 assetType,
63+
uint256 nonQuantizedAmount,
64+
uint256 quantizedAmount
65+
);
66+
67+
event LogDepositNftCancelReclaimed(
68+
uint256 starkKey,
69+
uint256 vaultId,
70+
uint256 assetType,
71+
uint256 tokenId,
72+
uint256 assetId
73+
);
74+
75+
function getDepositBalance(
76+
uint256 starkKey,
77+
uint256 assetId,
78+
uint256 vaultId
79+
) external view returns (uint256 balance);
80+
81+
function getQuantizedDepositBalance(
82+
uint256 starkKey,
83+
uint256 assetId,
84+
uint256 vaultId
85+
) external view returns (uint256 balance);
86+
87+
function depositNft(
88+
uint256 starkKey,
89+
uint256 assetType,
90+
uint256 vaultId,
91+
uint256 tokenId
92+
) external;
93+
94+
function getCancellationRequest(
95+
uint256 starkKey,
96+
uint256 assetId,
97+
uint256 vaultId
98+
) external view returns (uint256 request);
99+
100+
function depositERC20(
101+
uint256 starkKey,
102+
uint256 assetType,
103+
uint256 vaultId,
104+
uint256 quantizedAmount
105+
) external;
106+
107+
function depositEth(
108+
uint256 starkKey,
109+
uint256 assetType,
110+
uint256 vaultId
111+
) external payable;
112+
113+
function deposit(
114+
uint256 starkKey,
115+
uint256 assetType,
116+
uint256 vaultId,
117+
uint256 quantizedAmount
118+
) external;
119+
120+
function deposit(
121+
uint256 starkKey,
122+
uint256 assetType,
123+
uint256 vaultId
124+
) external payable;
125+
126+
function depositCancel(
127+
uint256 starkKey,
128+
uint256 assetId,
129+
uint256 vaultId
130+
) external;
131+
132+
function depositReclaim(
133+
uint256 starkKey,
134+
uint256 assetId,
135+
uint256 vaultId
136+
) external;
137+
138+
function depositNftReclaim(
139+
uint256 starkKey,
140+
uint256 assetType,
141+
uint256 vaultId,
142+
uint256 tokenId
143+
) external;
144+
145+
event LogWithdrawalPerformed(
146+
uint256 ownerKey,
147+
uint256 assetType,
148+
uint256 nonQuantizedAmount,
149+
uint256 quantizedAmount,
150+
address recipient
151+
);
152+
153+
event LogNftWithdrawalPerformed(
154+
uint256 ownerKey,
155+
uint256 assetType,
156+
uint256 tokenId,
157+
uint256 assetId,
158+
address recipient
159+
);
160+
161+
event LogMintWithdrawalPerformed(
162+
uint256 ownerKey,
163+
uint256 assetType,
164+
uint256 nonQuantizedAmount,
165+
uint256 quantizedAmount,
166+
uint256 assetId
167+
);
168+
169+
event LogWithdrawalAllowed(
170+
uint256 ownerKey,
171+
uint256 assetType,
172+
uint256 nonQuantizedAmount,
173+
uint256 quantizedAmount
174+
);
175+
176+
event LogNftWithdrawalAllowed(uint256 ownerKey, uint256 assetId);
177+
178+
event LogMintableWithdrawalAllowed(uint256 ownerKey, uint256 assetId, uint256 quantizedAmount);
179+
180+
function getWithdrawalBalance(uint256 ownerKey, uint256 assetId)
181+
external
182+
view
183+
returns (uint256 balance);
184+
185+
function withdraw(uint256 ownerKey, uint256 assetType) external;
186+
187+
function withdrawNft(
188+
uint256 ownerKey,
189+
uint256 assetType,
190+
uint256 tokenId
191+
) external ;
192+
193+
function withdrawAndMint(
194+
uint256 ownerKey,
195+
uint256 assetType,
196+
bytes calldata mintingBlob
197+
) external;
198+
199+
function getVaultRoot() external view returns (uint256 root);
200+
function getVaultTreeHeight() external view returns (uint256 height);
201+
function getOrderRoot() external view returns (uint256 root);
202+
function getOrderTreeHeight() external view returns (uint256 height);
203+
function getSequenceNumber() external view returns (uint256 seq);
204+
function getLastBatchId() external view returns (uint256 batchId);
205+
206+
function registerAndDepositERC20(
207+
address ethKey,
208+
uint256 starkKey,
209+
bytes calldata signature,
210+
uint256 assetType,
211+
uint256 vaultId,
212+
uint256 quantizedAmount
213+
) external;
214+
215+
function registerAndDepositEth(
216+
address ethKey,
217+
uint256 starkKey,
218+
bytes calldata signature,
219+
uint256 assetType,
220+
uint256 vaultId
221+
) external payable;
222+
223+
function getAssetInfo(uint256 assetType) external view returns (bytes memory assetInfo);
224+
225+
function getQuantum(uint256 presumedAssetType) external view returns (uint256 quantum);
226+
227+
function escape(
228+
uint256 starkKey,
229+
uint256 vaultId,
230+
uint256 assetId,
231+
uint256 quantizedAmount
232+
) external;
233+
234+
event LogFullWithdrawalRequest(uint256 starkKey, uint256 vaultId);
235+
236+
function fullWithdrawalRequest(uint256 starkKey, uint256 vaultId) external;
237+
238+
function freezeRequest(uint256 starkKey, uint256 vaultId) external;
239+
240+
event LogRootUpdate(
241+
uint256 sequenceNumber,
242+
uint256 batchId,
243+
uint256 vaultRoot,
244+
uint256 orderRoot
245+
);
246+
247+
event LogStateTransitionFact(bytes32 stateTransitionFact);
248+
249+
event LogVaultBalanceChangeApplied(
250+
address ethKey,
251+
uint256 assetId,
252+
uint256 vaultId,
253+
int256 quantizedAmountChange
254+
);
255+
256+
function updateState(uint256[] calldata publicInput, uint256[] calldata applicationData) external;
257+
258+
function getFullWithdrawalRequest(uint256 starkKey, uint256 vaultId)
259+
external
260+
view
261+
returns (uint256 res);
262+
}

contracts/bridge/x/Registration.sol

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.11;
3+
4+
import { Core } from "./Core.sol";
5+
6+
contract Registration {
7+
Core public imx;
8+
9+
constructor(Core _imx) {
10+
imx = _imx;
11+
}
12+
13+
function registerAndDepositNft(
14+
address ethKey,
15+
uint256 starkKey,
16+
bytes calldata signature,
17+
uint256 assetType,
18+
uint256 vaultId,
19+
uint256 tokenId
20+
) external {
21+
imx.registerUser(ethKey, starkKey, signature);
22+
imx.depositNft(starkKey, assetType, vaultId, tokenId);
23+
}
24+
25+
function registerAndWithdraw(
26+
address ethKey,
27+
uint256 starkKey,
28+
bytes calldata signature,
29+
uint256 assetType
30+
) external {
31+
imx.registerUser(ethKey, starkKey, signature);
32+
imx.withdraw(starkKey, assetType);
33+
}
34+
35+
function registerAndWithdrawTo(
36+
address ethKey,
37+
uint256 starkKey,
38+
bytes calldata signature,
39+
uint256 assetType,
40+
address recipient
41+
) external {
42+
imx.registerUser(ethKey, starkKey, signature);
43+
imx.withdrawTo(starkKey, assetType, recipient);
44+
}
45+
46+
function registerAndWithdrawNft(
47+
address ethKey,
48+
uint256 starkKey,
49+
bytes calldata signature,
50+
uint256 assetType,
51+
uint256 tokenId
52+
) external {
53+
imx.registerUser(ethKey, starkKey, signature);
54+
imx.withdrawNft(starkKey, assetType, tokenId);
55+
}
56+
57+
function registerAndWithdrawNftTo(
58+
address ethKey,
59+
uint256 starkKey,
60+
bytes calldata signature,
61+
uint256 assetType,
62+
uint256 tokenId,
63+
address recipient
64+
) external {
65+
imx.registerUser(ethKey, starkKey, signature);
66+
imx.withdrawNftTo(starkKey, assetType, tokenId, recipient);
67+
}
68+
69+
function regsiterAndWithdrawAndMint(
70+
address ethKey,
71+
uint256 starkKey,
72+
bytes calldata signature,
73+
uint256 assetType,
74+
bytes calldata mintingBlob
75+
) external {
76+
imx.registerUser(ethKey, starkKey, signature);
77+
imx.withdrawAndMint(starkKey, assetType, mintingBlob);
78+
}
79+
80+
function isRegistered(uint256 starkKey) public view returns (bool) {
81+
return imx.getEthKey(starkKey) != address(0);
82+
}
83+
}

contracts/token/erc721/x/Asset.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5+
import { Mintable } from "./Mintable.sol";
6+
7+
contract Asset is ERC721, Mintable {
8+
constructor(
9+
address _owner,
10+
string memory _name,
11+
string memory _symbol,
12+
address _imx
13+
) ERC721(_name, _symbol) Mintable(_owner, _imx) {}
14+
15+
function _mintFor(
16+
address user,
17+
uint256 id,
18+
bytes memory
19+
) internal override {
20+
_safeMint(user, id);
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
interface IMintable {
5+
function mintFor(
6+
address to,
7+
uint256 quantity,
8+
bytes calldata mintingBlob
9+
) external;
10+
}

0 commit comments

Comments
 (0)