Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

CORE-2033 Add RegistrationV4 contract #422

Merged
merged 54 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
393bec1
update OpenAPI generated API client code
kaihirota Dec 5, 2023
6d2fcda
add prepare withdrawal v2 workflow
kaihirota Dec 5, 2023
03aa93d
fix typo
kaihirota Dec 14, 2023
77f2585
update error message
kaihirota Feb 5, 2024
e189c16
rename vars
kaihirota Feb 5, 2024
2a10b98
add v2 complete withdrawal
kaihirota Feb 5, 2024
0be3a60
update
kaihirota Feb 12, 2024
79a94e2
move location
kaihirota Feb 13, 2024
6b95765
add v4 starkex contracts
kaihirota Feb 13, 2024
74d649e
add v2 registration contract bindings
kaihirota Feb 13, 2024
3d3dbd5
add readme
kaihirota Feb 13, 2024
ef48478
update
kaihirota Feb 13, 2024
5a048fb
update
kaihirota Feb 13, 2024
38787a3
add v4 stark contract
kaihirota Feb 16, 2024
0edbfd1
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota Feb 16, 2024
5c3e0e5
update
kaihirota Feb 19, 2024
b6878ab
add stark v4 factory
kaihirota Feb 19, 2024
bf1c424
rename core factory to stark v3
kaihirota Feb 19, 2024
2a04508
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota Feb 19, 2024
ecca3ee
update
kaihirota Feb 19, 2024
63c36b0
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota Feb 19, 2024
fe69113
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota Feb 19, 2024
8d90fd7
update examples
kaihirota Feb 19, 2024
d41c00d
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota Feb 19, 2024
d191afa
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota Feb 22, 2024
1a5143e
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota Feb 22, 2024
f568af7
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota Feb 23, 2024
3f894e1
Merge branch 'main' into CORE-1942-create-withdrawal-v2
kaihirota Feb 25, 2024
bee2cba
update
kaihirota Feb 25, 2024
49530da
update
kaihirota Feb 25, 2024
f6494b9
fix bad refs
kaihirota Feb 25, 2024
2a1bb38
add stark v4 factory
kaihirota Feb 19, 2024
d557a51
rename core factory to stark v3
kaihirota Feb 19, 2024
6f7cb14
update
kaihirota Feb 19, 2024
5d9b69b
add v2 complete withdrawal
kaihirota Feb 5, 2024
3292610
update
kaihirota Feb 12, 2024
e796738
add v4 stark contract
kaihirota Feb 16, 2024
acb12b8
update
kaihirota Feb 19, 2024
38daa61
update examples
kaihirota Feb 19, 2024
4641e81
Merge branch 'main' into CORE-1952-add-v4-starkex-contract-bindings
kaihirota Feb 26, 2024
5fab131
update changelog and version
kaihirota Feb 26, 2024
13d0a14
Merge branch 'CORE-1952-add-v4-starkex-contract-bindings' into CORE-1…
kaihirota Feb 26, 2024
7b148cf
changelog
kaihirota Feb 26, 2024
a195a7e
Merge branch 'CORE-1952-add-v2-complete-withdrawal-flow' into CORE-20…
kaihirota Feb 26, 2024
3a44e9d
Merge branch 'main' into CORE-2033-add-v2-registration-contract
kaihirota Feb 27, 2024
a081ec3
rename from v2 to v4
kaihirota Feb 27, 2024
af59db7
bump version
kaihirota Feb 27, 2024
3cc6f5f
update readme
kaihirota Feb 27, 2024
28eb96d
minor change
kaihirota Feb 27, 2024
9bee302
update solidity contracts
kaihirota Feb 27, 2024
c5df8a4
update contract
kaihirota Feb 27, 2024
7e0f437
Merge branch 'main' into CORE-2033-add-v2-registration-contract
kaihirota Feb 27, 2024
a81f4a0
bump version
kaihirota Feb 27, 2024
8c7f8a0
regenerate
kaihirota Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.0] - 2024-02-27

### Added

- Add V4 registration contract bindings.

## [3.0.0] - 2024-02-26

### Added

- `completeWithdrawal` has been updated to use V2 withdrawal logic for StarkEx V4 contract.
- [BREAKING CHANGE] `completeWithdrawal` now requires `WalletConnection` instead of Eth Signer.


## [2.6.1] - 2024-02-26

### Added
Expand Down
File renamed without changes.
277 changes: 277 additions & 0 deletions contracts/v4/CoreV4.sol
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

6 changes: 6 additions & 0 deletions contracts/v4/README.md
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.
81 changes: 81 additions & 0 deletions contracts/v4/RegistrationV4.sol
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);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('@typechain/hardhat');
require('@nomiclabs/hardhat-ethers');

const config = {
solidity: '0.8.11',
solidity: '0.8.19',
typechain: {
outDir: 'src/contracts',
target: 'ethers-v5',
Expand Down
Loading