Skip to content

Commit

Permalink
Merge pull request #1 from SocketDotTech/feat/timeout
Browse files Browse the repository at this point in the history
feat: timeout
  • Loading branch information
arthcp authored Jan 3, 2025
2 parents e909481 + 6b39bad commit 10c1369
Show file tree
Hide file tree
Showing 37 changed files with 1,212 additions and 446 deletions.
149 changes: 149 additions & 0 deletions Errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Custom Error Codes

## AddressResolver.sol

| Error | Signature |
| ------------------------------------------------------------------------- | ------------ |
| `AppGatewayContractAlreadySetByDifferentSender(address contractAddress_)` | `0x4062307a` |

## AsyncPromise.sol

| Error | Signature |
| -------------------------- | ------------ |
| `PromiseAlreadyResolved()` | `0x56b63537` |

## apps/payload-delivery/FeesManager.sol

| Error | Signature |
| ------------------- | ------------ |
| `FeesAlreadyPaid()` | `0xd3b1ad69` |

## apps/payload-delivery/app-gateway/BatchAsync.sol

| Error | Signature |
| ------------------------------- | ------------ |
| `AllPayloadsExecuted()` | `0x6bc43bfe` |
| `NotFromForwarder()` | `0xe83aa6bd` |
| `CallFailed(bytes32 payloadId)` | `0xe6176664` |
| `DelayLimitReached()` | `0xaa2ddd8e` |
| `PayloadTooLarge()` | `0x492f620d` |

## apps/payload-delivery/app-gateway/QueueAsync.sol

| Error | Signature |
| ------------------ | ------------ |
| `InvalidPromise()` | `0x45f2d176` |

## apps/super-token/LimitHook.sol

| Error | Signature |
| --------------------- | ------------ |
| `BurnLimitExceeded()` | `0x85e72fd4` |
| `MintLimitExceeded()` | `0xb643bfa6` |

## apps/super-token/SuperToken.sol

| Error | Signature |
| ---------------------------- | ------------ |
| `InsufficientBalance()` | `0xf4d678b8` |
| `InsufficientLockedTokens()` | `0x4f6d2a3e` |
| `NotController()` | `0x23019e67` |

## base/AppGatewayBase.sol

| Error | Signature |
| ------------------ | ------------ |
| `InvalidPromise()` | `0x45f2d176` |
| `FeesDataNotSet()` | `0x2ec61400` |

## common/Errors.sol

| Error | Signature |
| ------------------------ | ------------ |
| `NotAuthorized()` | `0xea8e4eb5` |
| `NotBridge()` | `0x7fea9dc5` |
| `NotSocket()` | `0xc59f8f7c` |
| `ConnectorUnavailable()` | `0xb1efb84a` |
| `InvalidTokenContract()` | `0x29bdfb34` |
| `ZeroAddressReceiver()` | `0x96bbcf1e` |
| `ZeroAddress()` | `0xd92e233d` |
| `ZeroAmount()` | `0x1f2a2005` |
| `InsufficientFunds()` | `0x356680b7` |
| `InvalidSigner()` | `0x815e1d64` |
| `InvalidFunction()` | `0xdb2079c3` |

## libraries/ECDSA.sol

| Error | Signature |
| --------------------------------------------- | ------------ |
| `ECDSAInvalidSignature()` | `0xf645eedf` |
| `ECDSAInvalidSignatureLength(uint256 length)` | `0x367e2e27` |
| `ECDSAInvalidSignatureS(bytes32 s)` | `0x5fedc3a1` |

## libraries/RescueFundsLib.sol

| Error | Signature |
| ----------------------- | ------------ |
| `InvalidTokenAddress()` | `0x1eb00b06` |

## socket/Socket.sol

| Error | Signature |
| -------------------------- | ------------ |
| `PayloadAlreadyExecuted()` | `0xe17bd578` |
| `VerificationFailed()` | `0x439cc0cd` |
| `InvalidAppGateway()` | `0x82ded261` |
| `LowGasLimit()` | `0xd38edae0` |
| `InvalidSlug()` | `0x290a8315` |

## socket/SocketBase.sol

| Error | Signature |
| ---------------------- | ------------ |
| `InvalidTransmitter()` | `0x58a70a0a` |

## socket/SocketConfig.sol

| Error | Signature |
| ---------------------- | ------------ |
| `SwitchboardExists()` | `0x2dff8555` |
| `InvalidConnection()` | `0x63228f29` |
| `InvalidSwitchboard()` | `0xf63c9e4d` |

## socket/switchboard/FastSwitchboard.sol

| Error | Signature |
| ------------------- | ------------ |
| `AlreadyAttested()` | `0x35d90805` |
| `WatcherNotFound()` | `0xa278e4ad` |

## socket/switchboard/SwitchboardBase.sol

| Error | Signature |
| ---------------- | ------------ |
| `InvalidNonce()` | `0x756688fe` |

## socket/utils/AccessControl.sol

| Error | Signature |
| ------------------------ | ------------ |
| `NoPermit(bytes32 role)` | `0x3db46572` |

## socket/utils/SignatureVerifier.sol

| Error | Signature |
| -------------------- | ------------ |
| `InvalidSigLength()` | `0xd2453293` |

## utils/Ownable.sol

| Error | Signature |
| --------------- | ------------ |
| `OnlyOwner()` | `0x5fc483c5` |
| `OnlyNominee()` | `0x7c91ccdd` |

## watcherPrecompile/WatcherPrecompile.sol

| Error | Signature |
| -------------------- | ------------ |
| `InvalidChainSlug()` | `0xbff6b106` |
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SOCKET Protocol
> The protocol is on alpha-stage and in active development.

> The protocol is on alpha-stage and in active development.
SOCKET Protocol is the first chain-abstraction protocol, enabling developers to build chain-abstracted applications to compose users, accounts and applications across 300+ rollups and chains. Chain-Abstraction is a new computing paradigm for developers, enabling developers to leverage chains as servers/databases, enabling them to reach all users and applications spread across networks while providing a consistent monolithic experience to end users and applications.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {DEPLOY, CONFIGURE, ETH_ADDRESS} from "../../common/Constants.sol";

import {PlugBase} from "../../base/PlugBase.sol";
import {Ownable} from "../../utils/Ownable.sol";
/// @title ContractFactory
/// @notice Abstract contract for deploying contracts
abstract contract ContractFactory {
contract ContractFactoryPlug is PlugBase, Ownable {
event Deployed(address addr, bytes32 salt);

/// @notice Handles the deployment of a contract
/// @param data The data
/// @return bytes memory The encoded deployed address
function _handleDeploy(bytes memory data) internal returns (bytes memory) {
address deployedAddress = deployContract(data);
return abi.encode(deployedAddress);
}
constructor(
address socket_,
uint32 chainSlug_,
address owner_
) PlugBase(socket_, chainSlug_) Ownable(owner_) {}

/// @notice Deploys a contract
/// @param data The data
/// @return address The deployed address
function deployContract(
bytes memory data
) public payable returns (address) {
(bytes memory creationCode, bytes32 salt) = abi.decode(
data,
(bytes, bytes32)
);

bytes memory creationCode,
bytes32 salt
) public returns (address) {
address addr;
assembly {
addr := create2(
Expand Down Expand Up @@ -62,4 +53,11 @@ abstract contract ContractFactory {

return address(uint160(uint256(hash)));
}

function connect(
address appGateway_,
address switchboard_
) external onlyOwner {
_connectSocket(appGateway_, switchboard_);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,51 @@
pragma solidity ^0.8.13;

import "solmate/utils/SafeTransferLib.sol";

import {PlugBase} from "../../base/PlugBase.sol";
import {Ownable} from "../../utils/Ownable.sol";
import {ETH_ADDRESS} from "../../common/Constants.sol";

/// @title FeesManager
/// @notice Abstract contract for managing fees
abstract contract FeesManager {
contract FeesPlug is PlugBase, Ownable {
mapping(address => mapping(address => uint256)) public balanceOf;
mapping(uint256 => bool) public feesRedeemed;
mapping(bytes32 => bool) public feesRedeemed;

error FeesAlreadyPaid();

constructor() {}

/// @notice Handles the distribution of fees
/// @param data The data
/// @return bytes memory The encoded return data
function _handleDistributeFee(
bytes memory data
) internal returns (bytes memory) {
(
address appGateway,
address feeToken,
uint256 fee,
address transmitter,
uint256 feesCounter
) = abi.decode(data, (address, address, uint256, address, uint256));
constructor(
address socket_,
uint32 chainSlug_,
address owner_
) PlugBase(socket_, chainSlug_) Ownable(owner_) {}

if (feesRedeemed[feesCounter]) revert FeesAlreadyPaid();
feesRedeemed[feesCounter] = true;
function distributeFee(
address appGateway,
address feeToken,
uint256 fee,
address transmitter,
bytes32 feesId
) external onlySocket returns (bytes memory) {
if (feesRedeemed[feesId]) revert FeesAlreadyPaid();
feesRedeemed[feesId] = true;

require(
balanceOf[appGateway][feeToken] >= fee,
"PayloadDeliveryPlug: insufficient balance"
"FeesPlug: Insufficient Balance for Fees"
);
balanceOf[appGateway][feeToken] -= fee;
_transferTokens(feeToken, fee, transmitter);
return bytes("");
}

/// @notice Handles the withdrawal of funds
/// @param data The data
/// @return bytes memory The encoded return data
function _handleWithdraw(
bytes memory data
) internal returns (bytes memory) {
(
address appGateway,
address token,
uint256 amount,
address receiver
) = abi.decode(data, (address, address, uint256, address));

function withdrawFees(
address appGateway,
address token,
uint256 amount,
address receiver
) external onlySocket returns (bytes memory) {
require(
balanceOf[appGateway][token] >= amount,
"PayloadDeliveryPlug: insufficient balance"
"FeesPlug: Insufficient Balance for Withdrawal"
);
balanceOf[appGateway][token] -= amount;
_transferTokens(token, amount, receiver);
Expand All @@ -73,7 +63,7 @@ abstract contract FeesManager {
address appGateway_
) external payable {
if (token == ETH_ADDRESS) {
require(msg.value == amount, "Fees Manager: invalid depositamount");
require(msg.value == amount, "FeesPlug: Invalid Deposit Amount");
} else {
SafeTransferLib.safeTransferFrom(
ERC20(token),
Expand All @@ -100,4 +90,11 @@ abstract contract FeesManager {
SafeTransferLib.safeTransfer(ERC20(token), receiver, amount);
}
}

function connect(
address appGateway_,
address switchboard_
) external onlyOwner {
_connectSocket(appGateway_, switchboard_);
}
}
Loading

0 comments on commit 10c1369

Please sign in to comment.