-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadAppGateway.sol
More file actions
118 lines (105 loc) · 4.74 KB
/
Copy pathUploadAppGateway.sol
File metadata and controls
118 lines (105 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol";
import "./ICounter.sol";
/**
* @title UploadAppGateway
* @dev Gateway contract for uploading and interacting with existing contracts across chains
* Unlike other example application gateways, this contract connects to pre-existing contracts
* Inherits from AppGatewayBase for SOCKET Protocol integration
*/
contract UploadAppGateway is AppGatewayBase {
/**
* @notice Address of the forwarder contract for the Counter
* @dev Used to interact with the Counter contract across chains
*/
address public counterForwarder;
/**
* @notice Event emitted when a value is read from an onchain contract
* @param forwarder The address of the forwarder contract
* @param value The value read from the onchain contract
*/
event ReadOnchain(address forwarder, uint256 value);
/**
* @notice Constructs the UploadAppGateway contract
* @dev Sets up fee overrides for the gateway
* @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract
* @param fees_ Fee configuration for multi-chain operations
*/
constructor(address addressResolver_, uint256 fees_) {
_initializeAppGateway(addressResolver_);
_setMaxFees(fees_);
}
/**
* @notice Empty deployment function as this gateway uses existing contracts
* @dev Required by AppGatewayBase but not used in this implementation
* @param chainSlug_ The identifier of the target chain (unused)
*/
function deployContracts(uint32 chainSlug_) external async {}
/**
* @notice Empty initialization function as no post-deployment setup is needed
* @dev Required by AppGatewayBase but not used in this implementation
* @param chainSlug_ The identifier of the chain (unused)
*/
function initializeOnChain(uint32 chainSlug_) public override {}
/**
* @notice Uploads an existing onchain contract to EVMx
* @dev Creates a forwarder contract that points to an existing onchain contract
* @param onchainContract The address of the existing contract on the source chain
* @param chainSlug_ The identifier of the chain where the contract exists
*/
function uploadToEVMx(address onchainContract, uint32 chainSlug_) public {
counterForwarder = asyncDeployer__().getOrDeployForwarderContract(onchainContract, chainSlug_);
}
/**
* @notice Reads the counter value from the onchain contract
* @dev Initiates an asynchronous read operation with parallel execution enabled
* Sets up a promise to handle the read result via the handleRead function
*/
function read() public async {
_setOverrides(Read.ON);
ICounter(counterForwarder).counter();
then(this.handleRead.selector, abi.encode(counterForwarder));
_setOverrides(Read.OFF);
}
/**
* @notice Handles the result of a read operation from the onchain contract
* @dev Callback function for promise resolution that emits a ReadOnchain event
* Can only be called by the promises system
* @param data The encoded forwarder address
* @param returnData The encoded counter value read from the onchain contract
*/
function handleRead(bytes memory data, bytes memory returnData) public onlyPromises {
address instance = abi.decode(data, (address));
uint256 value_ = abi.decode(returnData, (uint256));
emit ReadOnchain(instance, value_);
}
/**
* @notice Withdraws fee tokens from the SOCKET Protocol
* @dev Allows withdrawal of accumulated fees to a specified receiver
* @param chainSlug_ The chain from which to withdraw fees
* @param token_ The token address to withdraw
* @param amount_ The amount to withdraw
* @param receiver_ The address that will receive the withdrawn fees
*/
function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external {
_withdrawCredits(chainSlug_, token_, amount_, receiver_);
}
/**
* @notice Transfers fee credits from this contract to a specified address
* @dev Moves a specified amount of fee credits from the current contract to the given recipient
* @param to_ The address to transfer credits to
* @param amount_ The amount of credits to transfer
*/
function transferCredits(address to_, uint256 amount_) external {
feesManager__().transferCredits(address(this), to_, amount_);
}
/**
* @notice Updates the fee max value
* @dev Allows modification of fee settings for multi-chain operations
* @param fees_ New fee configuration
*/
function setMaxFees(uint256 fees_) public {
maxFees = fees_;
}
}