Skip to content

Commit

Permalink
add LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailo-maksa committed May 29, 2024
1 parent ac0395d commit 5e8a64f
Show file tree
Hide file tree
Showing 7 changed files with 2,186 additions and 1 deletion.
99 changes: 99 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Business Source License 1.1

License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
"Business Source License" is a trademark of MariaDB Corporation Ab.

-----------------------------------------------------------------------------

Parameters

Licensor: Intuition Systems, Inc.

Licensed Work: Intuition Protocol Contracts
The Licensed Work is (c) 2024 Intuition Systems, Inc.

Additional Use Grant: None.

Change Date: The earlier of 2026-06-01 (June 1st, 2026) or a date
specified at https://

Change License: MIT

-----------------------------------------------------------------------------

Terms

The Licensor hereby grants you the right to copy, modify, create derivative
works, redistribute, and make non-production use of the Licensed Work. The
Licensor may make an Additional Use Grant, above, permitting limited
production use.

Effective on the Change Date, or the fourth anniversary of the first publicly
available distribution of a specific version of the Licensed Work under this
License, whichever comes first, the Licensor hereby grants you rights under
the terms of the Change License, and the rights granted in the paragraph
above terminate.

If your use of the Licensed Work does not comply with the requirements
currently in effect as described in this License, you must purchase a
commercial license from the Licensor, its affiliated entities, or authorized
resellers, or you must refrain from using the Licensed Work.

All copies of the original and modified Licensed Work, and derivative works
of the Licensed Work, are subject to this License. This License applies
separately for each version of the Licensed Work and the Change Date may vary
for each version of the Licensed Work released by Licensor.

You must conspicuously display this License on each original or modified copy
of the Licensed Work. If you receive the Licensed Work in original or
modified form from a third party, the terms and conditions set forth in this
License apply to your use of that work.

Any use of the Licensed Work in violation of this License will automatically
terminate your rights under this License for the current and all other
versions of the Licensed Work.

This License does not grant you any right in any trademark or logo of
Licensor or its affiliates (provided that you may use a trademark or logo of
Licensor as expressly required by this License).

TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
TITLE.

MariaDB hereby grants you permission to use this License’s text to license
your works, and to refer to it using the trademark "Business Source License",
as long as you comply with the Covenants of Licensor below.

-----------------------------------------------------------------------------

Covenants of Licensor

In consideration of the right to use this License’s text and the "Business
Source License" name and trademark, Licensor covenants to MariaDB, and to all
other recipients of the licensed work to be provided by Licensor:

1. To specify as the Change License the GPL Version 2.0 or any later version,
or a license that is compatible with GPL Version 2.0 or a later version,
where "compatible" means that software provided under the Change License can
be included in a program with software provided under GPL Version 2.0 or a
later version. Licensor may specify additional Change Licenses without
limitation.

2. To either: (a) specify an additional grant of rights to use that does not
impose any additional restriction on the right granted in this License, as
the Additional Use Grant; or (b) insert the text "None".

3. To specify a Change Date.

4. Not to modify this License in any other way.

-----------------------------------------------------------------------------

Notice

The Business Source License (this document, or the "License") is not an Open
Source license. However, the Licensed Work will eventually be made available
under an Open Source License, as stated in this License.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Intuition Protocol
# Intuition Protocol

The open source contracts of the Intuition protocol v1.
176 changes: 176 additions & 0 deletions src/AtomWallet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.21;

import {IEthMultiVault} from "src/interfaces/IEthMultiVault.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {BaseAccount, UserOperation} from "account-abstraction/contracts/core/BaseAccount.sol";
import {IEntryPoint} from "account-abstraction/contracts/interfaces/IEntryPoint.sol";
import {Errors} from "./libraries/Errors.sol";

/**
* @title AtomWallet
* @notice This contract is an abstract account associated with a corresponding atom.
*/
contract AtomWallet is Initializable, BaseAccount, OwnableUpgradeable {
using ECDSA for bytes32;

/// @notice The storage slot for the AtomWallet contract ownable storage
/// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

/// @notice The EthMultiVault contract address
IEthMultiVault public ethMultiVault;

/// @notice The flag to indicate if the wallet's ownership has been claimed by the user
bool public isClaimed;

/// @notice The entry point contract address
IEntryPoint private _entryPoint;

// solhint-disable-next-line no-empty-blocks
receive() external payable {}

/**
* @notice Initialize the AtomWallet contract
* @param anEntryPoint the entry point contract address
* @param anOwner the owner of the contract (`walletConfig.atomWarden` is the initial owner of all atom wallets)
* @param _ethMultiVault the EthMultiVault contract address
*/
function init(IEntryPoint anEntryPoint, address anOwner, IEthMultiVault _ethMultiVault) external initializer {
__Ownable_init(anOwner);
_entryPoint = anEntryPoint;
ethMultiVault = _ethMultiVault;
}

/// @notice Get the entry point contract address
/// @return the entry point contract address
function entryPoint() public view virtual override returns (IEntryPoint) {
return _entryPoint;
}

/**
* @notice Execute a transaction (called directly from owner, or by entryPoint)
* @param dest the target address
* @param value the value to send
* @param func the function call data
*/
function execute(address dest, uint256 value, bytes calldata func) external onlyOwnerOrEntryPoint {
_call(dest, value, func);
}

/**
* @notice Execute a sequence (batch) of transactions
* @param dest the target addresses array
* @param func the function call data array
*/
function executeBatch(address[] calldata dest, bytes[] calldata func) external onlyOwnerOrEntryPoint {
if (dest.length != func.length) {
revert Errors.AtomWallet_WrongArrayLengths();
}

for (uint256 i = 0; i < dest.length; i++) {
_call(dest[i], 0, func[i]);
}
}

/// implement template method of BaseAccount
/**
* @notice Validate the signature of the user operation
* @param userOp the user operation
* @param userOpHash the hash of the user operation
* @return validationData the validation data (0 if successful)
*/
function _validateSignature(UserOperation calldata userOp, bytes32 userOpHash)
internal
virtual
override
returns (uint256 validationData)
{
bytes32 hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", userOpHash));

(address recovered,,) = ECDSA.tryRecover(hash, userOp.signature);

if (recovered != owner()) {
return SIG_VALIDATION_FAILED;
}

return 0;
}

/**
* @notice An internal method that calls a target address with value and data
* @param target the target address
* @param value the value to send
* @param data the function call data
*/
function _call(address target, uint256 value, bytes memory data) internal {
(bool success, bytes memory result) = target.call{value: value}(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}

/// @notice Returns the deposit of the account in the entry point contract
function getDeposit() public view returns (uint256) {
return entryPoint().balanceOf(address(this));
}

/// @notice Add deposit to the account in the entry point contract
function addDeposit() public payable {
entryPoint().depositTo{value: msg.value}(address(this));
}

/**
* @notice Withdraws value from the account's deposit
* @param withdrawAddress target to send to
* @param amount to withdraw
*/
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public {
if (!(msg.sender == owner() || msg.sender == address(this))) {
revert Errors.AtomWallet_OnlyOwner();
}
entryPoint().withdrawTo(withdrawAddress, amount);
}

/// @notice Transfer ownership of the wallet to a new owner. Ifn the wallet's ownership
/// is being transferred to the user, the wallet is considered claimed. Once claimed,
/// wallet is considered owned by the user and the action cannot be undone.
/// @param newOwner the new owner of the wallet
function transferOwnership(address newOwner) public override onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}

if (!isClaimed && newOwner != ethMultiVault.getAtomWarden()) {
isClaimed = true;
}

_transferOwnership(newOwner);
}

/// @notice Returns the owner of the wallet. If the wallet has been claimed, the owner
/// is the user. Otherwise, the owner is the atomWarden.
function owner() public view override returns (address) {
OwnableStorage storage $ = _getAtomWalletOwnableStorage();
return isClaimed ? $._owner : ethMultiVault.getAtomWarden();
}

/// @dev Get the storage slot for the AtomWallet contract ownable storage
function _getAtomWalletOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}

/// @dev Modifier to allow only the owner or entry point to call a function
modifier onlyOwnerOrEntryPoint() {
if (!(msg.sender == address(entryPoint()) || msg.sender == owner())) {
revert Errors.AtomWallet_OnlyOwnerOrEntryPoint();
}
_;
}
}
Loading

0 comments on commit 5e8a64f

Please sign in to comment.