-
Notifications
You must be signed in to change notification settings - Fork 8
Solana triggers - DO NOT MERGE #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cfc1708
WIP
gwalen efbe256
Add ForwarderSolana and solana gatway and call scripts
gwalen c543ef9
refactor: add creating Solana style digest; emit debug events; fix de…
gwalen 9fc61d3
refactor: WritePrecompile -> handlePayload() -> abi.decode for switch…
gwalen 3afb4c8
Borsh encoding and decoding works with tests; first iteration
gwalen d718485
Fix decoding and always wrapping types into uint256
gwalen ade46e5
Add test for decoding Socket config account from Solana
gwalen 38d756c
Simplify SolanaReadRequest - no need for keeping Generic shema inside…
gwalen 6fd707c
Fix naming for BorshDecoder; add handling of Solana READ in the AppGa…
gwalen 41e6f8a
Cleanup; Move Borsh encoder/decoder to borsh-serde directory
gwalen 7003cd1
Comment to remove the onChainAddress_ from initialize() in ForwarderS…
gwalen 549a766
fix: lost letter
gwalen 86b8a29
feat: invoke trigger and read return value final changes
gwalen a09b06a
remove comments
gwalen a9510bc
Merge branch 'dev-solana-v2' into solana-triggers
gwalen 701e866
CR fixes
gwalen baaf1fa
minor changes
gwalen ceb4cbd
Merge branch 'fees-deposit-hook' into solana-triggers
gwalen 613467d
Add comments and small rename in FeesPlug
gwalen 3b49f8e
Merge branch 'fees-deposit-hook' into solana-triggers
gwalen 95fe490
Minor fixes from CodeRabbit to: BorshEncoder.sol, EvmSolanaOnchainCal…
gwalen 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,94 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.21; | ||
|
||
import "solady/utils/Initializable.sol"; | ||
import "./AddressResolverUtil.sol"; | ||
import "../interfaces/IAddressResolver.sol"; | ||
import "../interfaces/IAppGateway.sol"; | ||
import "../interfaces/IForwarder.sol"; | ||
import {QueueParams, OverrideParams, Transaction} from "../../utils/common/Structs.sol"; | ||
import {AsyncModifierNotSet, WatcherNotSet, InvalidOnChainAddress} from "../../utils/common/Errors.sol"; | ||
import "../../utils/RescueFundsLib.sol"; | ||
import {toBytes32Format} from "../../utils/common/Converters.sol"; | ||
import {SolanaInstruction} from "../../utils/common/Structs.sol"; | ||
import {CHAIN_SLUG_SOLANA_MAINNET, CHAIN_SLUG_SOLANA_DEVNET} from "../../utils/common/Constants.sol"; | ||
import {ForwarderStorage} from "./Forwarder.sol"; | ||
|
||
/// @title Forwarder Contract | ||
/// @notice This contract acts as a forwarder for async calls to the on-chain contracts. | ||
contract ForwarderSolana is ForwarderStorage, Initializable, AddressResolverUtil { | ||
error InvalidSolanaChainSlug(); | ||
error AddressResolverNotSet(); | ||
|
||
constructor() { | ||
_disableInitializers(); // disable for implementation | ||
} | ||
|
||
/// @notice Initializer to replace constructor for upgradeable contracts | ||
/// @param chainSlug_ chain slug on which the contract is deployed | ||
//// @param onChainAddress_ on-chain address associated with this forwarder | ||
/// @param addressResolver_ address resolver contract | ||
function initialize( | ||
uint32 chainSlug_, | ||
bytes32 onChainAddress_, // TODO:GW: after demo remove this param, we take target as param in callSolana() | ||
address addressResolver_ | ||
) public initializer { | ||
if (chainSlug_ == CHAIN_SLUG_SOLANA_MAINNET || chainSlug_ == CHAIN_SLUG_SOLANA_DEVNET) { | ||
chainSlug = chainSlug_; | ||
} else { | ||
revert InvalidSolanaChainSlug(); | ||
} | ||
onChainAddress = onChainAddress_; | ||
_setAddressResolver(addressResolver_); | ||
} | ||
|
||
/// @notice Returns the on-chain address associated with this forwarder. | ||
/// @return The on-chain address. | ||
function getOnChainAddress() external view returns (bytes32) { | ||
return onChainAddress; | ||
} | ||
|
||
/// @notice Returns the chain slug on which the contract is deployed. | ||
/// @return chain slug | ||
function getChainSlug() external view returns (uint32) { | ||
return chainSlug; | ||
} | ||
|
||
/// @notice Fallback function to process the contract calls to onChainAddress | ||
/// @dev It queues the calls in the middleware and deploys the promise contract | ||
// function callSolana(SolanaInstruction memory solanaInstruction, bytes32 switchboardSolana) external { | ||
function callSolana(bytes memory solanaPayload, bytes32 target) external { | ||
if (address(addressResolver__) == address(0)) { | ||
revert AddressResolverNotSet(); | ||
} | ||
if (address(watcher__()) == address(0)) { | ||
revert WatcherNotSet(); | ||
} | ||
|
||
// validates if the async modifier is set | ||
address msgSender = msg.sender; | ||
bool isAsyncModifierSet = IAppGateway(msgSender).isAsyncModifierSet(); | ||
if (!isAsyncModifierSet) revert AsyncModifierNotSet(); | ||
|
||
// fetch the override params from app gateway | ||
(OverrideParams memory overrideParams, bytes32 sbType) = IAppGateway(msgSender) | ||
.getOverrideParams(); | ||
|
||
// TODO:GW: after POC make it work like below | ||
// get the switchboard address from the watcher precompile config | ||
// address switchboard = watcherPrecompileConfig().switchboards(chainSlug, sbType); | ||
gwalen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Queue the call in the middleware. | ||
QueueParams memory queueParams; | ||
queueParams.overrideParams = overrideParams; | ||
queueParams.transaction = Transaction({ | ||
chainSlug: chainSlug, | ||
// target: onChainAddress, // for Solana reads it should be accountToRead | ||
// TODO: Solana forwarder can be a singleton - does not need to store onChainAddress and can use target as param | ||
target: target, | ||
payload: solanaPayload | ||
}); | ||
queueParams.switchboardType = sbType; | ||
watcher__().queue(queueParams, msgSender); | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.