This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
CORE-2033 Add RegistrationV4 contract #422
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
393bec1
update OpenAPI generated API client code
kaihirota 6d2fcda
add prepare withdrawal v2 workflow
kaihirota 03aa93d
fix typo
kaihirota 77f2585
update error message
kaihirota e189c16
rename vars
kaihirota 2a10b98
add v2 complete withdrawal
kaihirota 0be3a60
update
kaihirota 79a94e2
move location
kaihirota 6b95765
add v4 starkex contracts
kaihirota 74d649e
add v2 registration contract bindings
kaihirota 3d3dbd5
add readme
kaihirota ef48478
update
kaihirota 5a048fb
update
kaihirota 38787a3
add v4 stark contract
kaihirota 0edbfd1
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota 5c3e0e5
update
kaihirota b6878ab
add stark v4 factory
kaihirota bf1c424
rename core factory to stark v3
kaihirota 2a04508
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota ecca3ee
update
kaihirota 63c36b0
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota fe69113
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota 8d90fd7
update examples
kaihirota d41c00d
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota d191afa
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota 1a5143e
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota f568af7
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota 3f894e1
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota bee2cba
update
kaihirota 49530da
update
kaihirota f6494b9
fix bad refs
kaihirota 2a1bb38
add stark v4 factory
kaihirota d557a51
rename core factory to stark v3
kaihirota 6f7cb14
update
kaihirota 5d9b69b
add v2 complete withdrawal
kaihirota 3292610
update
kaihirota e796738
add v4 stark contract
kaihirota acb12b8
update
kaihirota 38daa61
update examples
kaihirota 4641e81
Merge branch 'main' into CORE-1952-add-v4-starkex-contract-bindings
kaihirota 5fab131
update changelog and version
kaihirota 13d0a14
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota 7b148cf
changelog
kaihirota a195a7e
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota 3a44e9d
Merge branch 'main' into CORE-2033-add-v2-registration-contract
kaihirota a081ec3
rename from v2 to v4
kaihirota af59db7
bump version
kaihirota 3cc6f5f
update readme
kaihirota 28eb96d
minor change
kaihirota 9bee302
update solidity contracts
kaihirota c5df8a4
update contract
kaihirota 7e0f437
Merge branch 'main' into CORE-2033-add-v2-registration-contract
kaihirota a81f4a0
bump version
kaihirota 8c7f8a0
regenerate
kaihirota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
File renamed without changes.
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,277 @@ | ||
// Copyright (c) Immutable Pty Ltd 2018 - 2024 | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This contract is an interface for the StarkEx Core contract v4 version. | ||
// It is used to interact with the StarkEx Core contract from the Registration contract. | ||
// The Core contract is used to register and withdraw users and assets from the StarkEx system. | ||
// | ||
// This file was generated using the abi-to-sol tool. | ||
// the StarkEx contract ABI that was provided by StarkWare via slack. | ||
pragma solidity ^0.8.19; | ||
|
||
interface CoreV4 { | ||
fallback() external payable; | ||
|
||
function VERSION() external view returns (string memory); | ||
|
||
function initialize(bytes memory data) external; | ||
|
||
receive() external payable; | ||
|
||
event LogFrozen(); | ||
event LogNewGovernorAccepted(address acceptedGovernor); | ||
event LogNominatedGovernor(address nominatedGovernor); | ||
event LogNominationCancelled(); | ||
event LogRegistered(address entry, string entryId); | ||
event LogRemovalIntent(address entry, string entryId); | ||
event LogRemoved(address entry, string entryId); | ||
event LogRemovedGovernor(address removedGovernor); | ||
event LogUnFrozen(); | ||
|
||
function DEPOSIT_CANCEL_DELAY() external view returns (uint256); | ||
|
||
function FREEZE_GRACE_PERIOD() external view returns (uint256); | ||
|
||
function MAIN_GOVERNANCE_INFO_TAG() external view returns (string memory); | ||
|
||
function MAX_FORCED_ACTIONS_REQS_PER_BLOCK() external view returns (uint256); | ||
|
||
function MAX_VERIFIER_COUNT() external view returns (uint256); | ||
|
||
function UNFREEZE_DELAY() external view returns (uint256); | ||
|
||
function VERIFIER_REMOVAL_DELAY() external view returns (uint256); | ||
|
||
function announceAvailabilityVerifierRemovalIntent(address verifier) external; | ||
|
||
function announceVerifierRemovalIntent(address verifier) external; | ||
|
||
function getRegisteredAvailabilityVerifiers() external view returns (address[] memory _verifers); | ||
|
||
function getRegisteredVerifiers() external view returns (address[] memory _verifers); | ||
|
||
function isAvailabilityVerifier(address verifierAddress) external view returns (bool); | ||
|
||
function isFrozen() external view returns (bool); | ||
|
||
function isVerifier(address verifierAddress) external view returns (bool); | ||
|
||
function mainAcceptGovernance() external; | ||
|
||
function mainCancelNomination() external; | ||
|
||
function mainIsGovernor(address testGovernor) external view returns (bool); | ||
|
||
function mainNominateNewGovernor(address newGovernor) external; | ||
|
||
function mainRemoveGovernor(address governorForRemoval) external; | ||
|
||
function registerAvailabilityVerifier(address verifier, string memory identifier) external; | ||
|
||
function registerVerifier(address verifier, string memory identifier) external; | ||
|
||
function removeAvailabilityVerifier(address verifier) external; | ||
|
||
function removeVerifier(address verifier) external; | ||
|
||
function unFreeze() external; | ||
|
||
event LogDeposit( | ||
address depositorEthKey, | ||
uint256 starkKey, | ||
uint256 vaultId, | ||
uint256 assetType, | ||
uint256 nonQuantizedAmount, | ||
uint256 quantizedAmount | ||
); | ||
event LogDepositCancel(uint256 starkKey, uint256 vaultId, uint256 assetId); | ||
event LogDepositCancelReclaimed( | ||
uint256 starkKey, uint256 vaultId, uint256 assetType, uint256 nonQuantizedAmount, uint256 quantizedAmount | ||
); | ||
event LogDepositNftCancelReclaimed( | ||
uint256 starkKey, uint256 vaultId, uint256 assetType, uint256 tokenId, uint256 assetId | ||
); | ||
event LogMintWithdrawalPerformed( | ||
uint256 ownerKey, uint256 assetType, uint256 nonQuantizedAmount, uint256 quantizedAmount, uint256 assetId | ||
); | ||
event LogMintableWithdrawalAllowed(uint256 ownerKey, uint256 assetId, uint256 quantizedAmount); | ||
event LogNftDeposit( | ||
address depositorEthKey, uint256 starkKey, uint256 vaultId, uint256 assetType, uint256 tokenId, uint256 assetId | ||
); | ||
event LogNftWithdrawalAllowed(uint256 ownerKey, uint256 assetId); | ||
event LogNftWithdrawalPerformed( | ||
uint256 ownerKey, uint256 assetType, uint256 tokenId, uint256 assetId, address recipient | ||
); | ||
event LogTokenAdminAdded(address tokenAdmin); | ||
event LogTokenAdminRemoved(address tokenAdmin); | ||
event LogTokenRegistered(uint256 assetType, bytes assetInfo, uint256 quantum); | ||
event LogUserRegistered(address ethKey, uint256 starkKey, address sender); | ||
event LogWithdrawalAllowed( | ||
uint256 ownerKey, uint256 assetType, uint256 nonQuantizedAmount, uint256 quantizedAmount | ||
); | ||
event LogWithdrawalPerformed( | ||
uint256 ownerKey, uint256 assetType, uint256 nonQuantizedAmount, uint256 quantizedAmount, address recipient | ||
); | ||
|
||
function defaultVaultWithdrawalLock() external view returns (uint256); | ||
|
||
function deposit(uint256 starkKey, uint256 assetType, uint256 vaultId) external payable; | ||
|
||
function deposit(uint256 starkKey, uint256 assetType, uint256 vaultId, uint256 quantizedAmount) external; | ||
|
||
function depositCancel(uint256 starkKey, uint256 assetId, uint256 vaultId) external; | ||
|
||
function depositERC20(uint256 starkKey, uint256 assetType, uint256 vaultId, uint256 quantizedAmount) external; | ||
|
||
function depositEth(uint256 starkKey, uint256 assetType, uint256 vaultId) external payable; | ||
|
||
function depositNft(uint256 starkKey, uint256 assetType, uint256 vaultId, uint256 tokenId) external; | ||
|
||
function depositNftReclaim(uint256 starkKey, uint256 assetType, uint256 vaultId, uint256 tokenId) external; | ||
|
||
function depositReclaim(uint256 starkKey, uint256 assetId, uint256 vaultId) external; | ||
|
||
function getActionCount() external view returns (uint256); | ||
|
||
function getActionHashByIndex(uint256 actionIndex) external view returns (bytes32); | ||
|
||
function getAssetInfo(uint256 assetType) external view returns (bytes memory assetInfo); | ||
|
||
function getCancellationRequest(uint256 starkKey, uint256 assetId, uint256 vaultId) | ||
external | ||
view | ||
returns (uint256 request); | ||
|
||
function getDepositBalance(uint256 starkKey, uint256 assetId, uint256 vaultId) | ||
external | ||
view | ||
returns (uint256 balance); | ||
|
||
function getEthKey(uint256 ownerKey) external view returns (address); | ||
|
||
function getFullWithdrawalRequest(uint256 starkKey, uint256 vaultId) external view returns (uint256 res); | ||
|
||
function getQuantizedDepositBalance(uint256 starkKey, uint256 assetId, uint256 vaultId) | ||
external | ||
view | ||
returns (uint256 balance); | ||
|
||
function getQuantum(uint256 presumedAssetType) external view returns (uint256 quantum); | ||
|
||
function getWithdrawalBalance(uint256 ownerKey, uint256 assetId) external view returns (uint256 balance); | ||
|
||
function isAssetRegistered(uint256 assetType) external view returns (bool); | ||
|
||
function isTokenAdmin(address testedAdmin) external view returns (bool); | ||
|
||
function onERC721Received(address, address, uint256, bytes memory) external returns (bytes4); | ||
|
||
function orderRegistryAddress() external view returns (address); | ||
|
||
function registerAndDepositERC20( | ||
address ethKey, | ||
uint256 starkKey, | ||
bytes memory signature, | ||
uint256 assetType, | ||
uint256 vaultId, | ||
uint256 quantizedAmount | ||
) external; | ||
|
||
function registerAndDepositEth( | ||
address ethKey, | ||
uint256 starkKey, | ||
bytes memory signature, | ||
uint256 assetType, | ||
uint256 vaultId | ||
) external payable; | ||
|
||
function registerEthAddress(address ethKey, uint256 starkKey, bytes memory starkSignature) external; | ||
|
||
function registerSender(uint256 starkKey, bytes memory starkSignature) external; | ||
|
||
function registerToken(uint256 assetType, bytes memory assetInfo) external; | ||
|
||
function registerToken(uint256 assetType, bytes memory assetInfo, uint256 quantum) external; | ||
|
||
function registerTokenAdmin(address newAdmin) external; | ||
|
||
function unregisterTokenAdmin(address oldAdmin) external; | ||
|
||
function withdraw(uint256 ownerKey, uint256 assetType) external; | ||
|
||
function withdrawAndMint(uint256 ownerKey, uint256 assetType, bytes memory mintingBlob) external; | ||
|
||
function withdrawNft(uint256 ownerKey, uint256 assetType, uint256 tokenId) external; | ||
|
||
event LogOperatorAdded(address operator); | ||
event LogOperatorRemoved(address operator); | ||
event LogRootUpdate(uint256 sequenceNumber, uint256 batchId, uint256 vaultRoot, uint256 orderRoot); | ||
event LogStateTransitionFact(bytes32 stateTransitionFact); | ||
event LogVaultBalanceChangeApplied(address ethKey, uint256 assetId, uint256 vaultId, int256 quantizedAmountChange); | ||
|
||
function STARKEX_MAX_DEFAULT_VAULT_LOCK() external view returns (uint256); | ||
|
||
function escape(uint256 starkKey, uint256 vaultId, uint256 assetId, uint256 quantizedAmount) external; | ||
|
||
function getLastBatchId() external view returns (uint256 batchId); | ||
|
||
function getOrderRoot() external view returns (uint256 root); | ||
|
||
function getOrderTreeHeight() external view returns (uint256 height); | ||
|
||
function getSequenceNumber() external view returns (uint256 seq); | ||
|
||
function getVaultRoot() external view returns (uint256 root); | ||
|
||
function getVaultTreeHeight() external view returns (uint256 height); | ||
|
||
function isOperator(address testedOperator) external view returns (bool); | ||
|
||
function registerOperator(address newOperator) external; | ||
|
||
function unregisterOperator(address removedOperator) external; | ||
|
||
function updateState(uint256[] memory publicInput, uint256[] memory applicationData) external; | ||
|
||
event LogFullWithdrawalRequest(uint256 starkKey, uint256 vaultId); | ||
|
||
function freezeRequest(uint256 starkKey, uint256 vaultId) external; | ||
|
||
function fullWithdrawalRequest(uint256 starkKey, uint256 vaultId) external; | ||
|
||
event LogDefaultVaultWithdrawalLockSet(uint256 newDefaultLockTime); | ||
event LogDepositToVault( | ||
address ethKey, uint256 assetId, uint256 vaultId, uint256 nonQuantizedAmount, uint256 quantizedAmount | ||
); | ||
event LogVaultWithdrawalLockSet(address ethKey, uint256 assetId, uint256 vaultId, uint256 timeRelease); | ||
event LogWithdrawalFromVault( | ||
address ethKey, uint256 assetId, uint256 vaultId, uint256 nonQuantizedAmount, uint256 quantizedAmount | ||
); | ||
|
||
function depositERC20ToVault(uint256 assetId, uint256 vaultId, uint256 quantizedAmount) external; | ||
|
||
function depositEthToVault(uint256 assetId, uint256 vaultId) external payable; | ||
|
||
function getQuantizedVaultBalance(address ethKey, uint256 assetId, uint256 vaultId) | ||
external | ||
view | ||
returns (uint256); | ||
|
||
function getVaultBalance(address ethKey, uint256 assetId, uint256 vaultId) external view returns (uint256); | ||
|
||
function getVaultWithdrawalLock(address ethKey, uint256 assetId, uint256 vaultId) external view returns (uint256); | ||
|
||
function isStrictVaultBalancePolicy() external view returns (bool); | ||
|
||
function isVaultLocked(address ethKey, uint256 assetId, uint256 vaultId) external view returns (bool); | ||
|
||
function lockVault(uint256 assetId, uint256 vaultId, uint256 lockTime) external; | ||
|
||
function setDefaultVaultWithdrawalLock(uint256 newDefaultTime) external; | ||
|
||
function withdrawFromVault(uint256 assetId, uint256 vaultId, uint256 quantizedAmount) external; | ||
|
||
event ImplementationActivationRescheduled(address indexed implementation, uint256 updatedActivationTime); | ||
|
||
function updateImplementationActivationTime(address implementation, bytes memory data, bool finalize) external; | ||
} | ||
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,6 @@ | ||
# About | ||
|
||
Contracts in this directory are for interacting with StarkEx contracts with version >= 4.0. | ||
|
||
- `Core.sol` - wrapper for StarkEx V4 contract. | ||
- `Registration.sol` - Version 2 of the registration wrapper contract, which adds helper functions like `withdrawAll` and `registerAndWithdrawAll`, which can be used in edge cases where a user has prepared withdrawals in StarkEx v3 and v4 contract, and wishes to withdraw both in one transaction. It is named RegistrationV4 because it is designed to interact with StarkEx V4 contract. |
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,81 @@ | ||||||||
// Copyright (c) Immutable Pty Ltd 2018 - 2024 | ||||||||
// SPDX-License-Identifier: MIT | ||||||||
pragma solidity ^0.8.19; | ||||||||
|
||||||||
import {CoreV4} from "./CoreV4.sol"; | ||||||||
|
||||||||
/** | ||||||||
* Emitted when there are no funds to withdraw when calling `withdrawAll`. | ||||||||
*/ | ||||||||
error NoFundsToWithdraw(uint256 ethKey, uint256 starkKey); | ||||||||
|
||||||||
/** | ||||||||
* RegistrationV4 is a wrapper around the StarkEx contract to provide a more user-friendly interface for executing multiple transactions on the StarkEx contract at once. | ||||||||
* This contract is not upgradeable. If an issue is found with this contract, a new version will be deployed. | ||||||||
*/ | ||||||||
contract RegistrationV4 { | ||||||||
CoreV4 public immutable imx; | ||||||||
|
||||||||
constructor(address payable _imx) { | ||||||||
imx = CoreV4(_imx); | ||||||||
} | ||||||||
|
||||||||
function registerAndWithdrawAll(address ethKey, uint256 starkKey, bytes calldata signature, uint256 assetType) | ||||||||
external | ||||||||
{ | ||||||||
if (!isRegistered(starkKey)) { | ||||||||
imx.registerEthAddress(ethKey, starkKey, signature); | ||||||||
} | ||||||||
withdrawAll(uint160(ethKey), starkKey, assetType); | ||||||||
} | ||||||||
|
||||||||
function withdrawAll(uint256 ethKey, uint256 starkKey, uint256 assetType) public { | ||||||||
uint256 ethKeyBalance = imx.getWithdrawalBalance(ethKey, assetType); | ||||||||
uint256 starkKeyBalance = imx.getWithdrawalBalance(starkKey, assetType); | ||||||||
if (ethKeyBalance == 0 && starkKeyBalance == 0) { | ||||||||
revert NoFundsToWithdraw(ethKey, starkKey); | ||||||||
} | ||||||||
|
||||||||
if (ethKeyBalance > 0) { | ||||||||
imx.withdraw(ethKey, assetType); | ||||||||
} | ||||||||
|
||||||||
if (starkKeyBalance > 0) { | ||||||||
imx.withdraw(starkKey, assetType); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
function registerAndWithdrawNft( | ||||||||
address ethKey, | ||||||||
uint256 starkKey, | ||||||||
bytes calldata signature, | ||||||||
uint256 assetType, | ||||||||
uint256 tokenId | ||||||||
) external { | ||||||||
if (!isRegistered(starkKey)) { | ||||||||
imx.registerEthAddress(ethKey, starkKey, signature); | ||||||||
} | ||||||||
imx.withdrawNft(starkKey, assetType, tokenId); | ||||||||
} | ||||||||
|
||||||||
function registerWithdrawAndMint( | ||||||||
address ethKey, | ||||||||
uint256 starkKey, | ||||||||
bytes calldata signature, | ||||||||
uint256 assetType, | ||||||||
bytes calldata mintingBlob | ||||||||
) external { | ||||||||
if (!isRegistered(starkKey)) { | ||||||||
imx.registerEthAddress(ethKey, starkKey, signature); | ||||||||
} | ||||||||
imx.withdrawAndMint(starkKey, assetType, mintingBlob); | ||||||||
} | ||||||||
|
||||||||
function getVersion() external view returns (string memory) { | ||||||||
return imx.VERSION(); | ||||||||
} | ||||||||
|
||||||||
function isRegistered(uint256 starkKey) public view returns (bool) { | ||||||||
return imx.getEthKey(starkKey) != address(0); | ||||||||
} | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.