Skip to content

Commit

Permalink
Merge pull request #51 from SocketDotTech/restructure
Browse files Browse the repository at this point in the history
Restructure
  • Loading branch information
shreykeny authored Sep 14, 2023
2 parents a2d450a + 2bafb06 commit 9ce1f9d
Show file tree
Hide file tree
Showing 64 changed files with 2,838 additions and 25,835 deletions.
61 changes: 0 additions & 61 deletions docs/Build/APIReference/Track.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/Build/Contract Setup/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Setup : Getting Started",
"position": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ id: configuring-plugs
title: Configuring Plugs
sidebar_position: 1
---
Connecting your cross-chain smart contracts (i.e. Plugs) is as easy as creating a Plug on chain A and chain B, connecting both to their chain's canonical Socket deployment, and configuring both Plugs to reference one another.
Connecting your cross-chain smart contracts (i.e. Plugs) is as easy as creating a Plug on chain A and chain B, connecting both Plugs to their chain's canonical Socket deployment, and configuring both Plugs to reference one another.

Before getting started on configuring your Plugs, here are a few things to keep in mind:
- Socket allows only Plugs to update this configuration/connection, and allows Plugs to do so at any point.
- Connection should be permissioned at the Plug level by either `owner keys`, protocol governance. Or, to make the connection immutable, you can block re-connection forever.
- Socket allows only Plugs to update this configuration/connection at any point
- Connection should be permissioned at the Plug level by either `owner keys`, protocol governance. Or, to make the connection immutable, you can block re-connection forever
- Malicious configuration while connecting to Socket could cause unintended actions.
- Connections are pair-wis, i.e you connect PlugA on ChainA to PlugB on ChainB. To extend your deployment to chain C, you would pair a PlugC on ChainC with one on both ChainsA and ChainB.
- Connections are pair-wise, i.e you connect PlugA on ChainA to PlugB on ChainB. To extend your deployment to chain C, you would pair a PlugC on ChainC with Plugs on ChainA and ChainB respectively

You can read more about Plugs [here](../../Learn/Components/Plugs.md). Once connected, you can use the Outbound and Inbound methods to send and receive messages.
You can read more about Plugs [here](../../Learn/Components/Plugs.md). Once connected, you can use the `Outbound` and `Inbound` methods to send and receive messages.

## Configuring your Plug's Parameters
## Configuring Plug Parameters

Plugs should be deployed first so you can then point them to each other and "connect". Once you are ready with Plugs deployed on the networks you want to work with, its time to get Plugged!
Plugs should be deployed on respective chains before they can be connected to their sibling Plugs deployed on other chains. Once you are ready with Plugs deployed on the networks you want to work with, its time to get Plugged!

**Here's the parameters required for connection**

| Parameters | Description |
| --- | --- |
| siblingChainSlug | ChainSlug of the network the sibling plug is deployed on, you can find all [chainSlugs here](../../Build/DeploymentsSection/Deployments.md) |
| siblingPlug | Address of your plug on the destination network |
| siblingChainSlug | ChainSlug of the network the sibling plug is deployed on, you can find all [chainSlugs here](../../Dev%20Resources/Deployments.mdx) |
| siblingPlug | Address of the plug deployed on the sibling chain |
| inboundSwitchboard | Switchboard address used for receiving messages from siblingPlug |
| outboundSwitchboard | Switchboard address used for sending messages to siblingPlug |

You can find addresses for all verified Switchboards and Socket contracts in [Deployments](../../Build/DeploymentsSection/Deployments.md)
You can find addresses for all verified Switchboards and Socket contracts in [Deployments](../../Dev%20Resources/Deployments.mdx)

## Connecting your Plugs

Expand All @@ -36,8 +36,9 @@ Below is a quick example for how your Plug can call the `connect` method on Sock

```javascript
ISocket socket = ISocket(socket_address);

function connectToSocket(
uint256 siblingChainSlug,
uint32 siblingChainSlug,
address siblingPlug,
address inboundSwitchboard,
address outboundSwitchboard
Expand All @@ -54,7 +55,6 @@ Below is a quick example for how your Plug can call the `connect` method on Sock
);
}
```
<!-- // TODO: Need to link alotta things below -->

## Testing your connection
Once you are done connecting, the transaction will emit a log called `PlugConnected`
Expand All @@ -64,6 +64,6 @@ For reference, checkout [this example tx](https://goerli.etherscan.io/tx/0x37040

Furthermore, you can do the following to check the connection is successful :
- Call the `getPlugConfig` function on the Socket contract that returns the config for your Plug for a given destination ChainSlug
- Use the [Check Connection API](../APIReference/CheckConnection.md) that reads the configs and aids you to make sure your connection is correct
- Use the [Check Connection API](../../Dev%20Resources/APIReference/CheckConnection.md) that reads the configs and aids you to make sure your connection is correct

<!-- // TODO: ADD GIF; ITs time to send it -->
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ interface IPlug {
* @param payload_ the data which is needed by plug at inbound call on destination
*/
function inbound(
uint256 siblingChainSlug_,
uint32 siblingChainSlug_,
bytes calldata payload_
) external;
}
```
Your Plug on the destination network can look something like below. In the below snippet we assume the payload is an integer.
:::note
Only [`Socket`](../../Dev%20Resources/Deployments.mdx) on a given chain should be allowed to call the `inbound` method on a Plug as seen in the example below.
:::
<br />
Your Plug on the destination network can look something like below. In the below snippet we assume the payload is a `uint256`.
```javascript
uint256 number;

function inbound(
uint256 siblingChainSlug_,
uint32 siblingChainSlug_,
bytes calldata payload_
) external payable {
// Make sure the caller is Socket contract only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ id: sending
title: Sending messages
sidebar_position: 2
---
<!-- // TODO: read more -->

`Outbound` method on the Socket contract deployed on all networks allows Plugs to send messages to other Plugs across chains. Checkout the below section to understand how to use it. If you want to read more on how sending messages in Socket works, [read more here](../../Learn/lifecycle.md#sending-a-message).

Expand All @@ -15,7 +14,6 @@ sidebar_position: 2
| payload | The message you want to send to the plug on remoteChainSlug |
| msgGasLimit | gasLimit required to execute the `payload` on remoteChainSlug |

<!-- // TODO: link here -->
In order to pay for cross-chain execution, you call the outbound function with the msg.value representing the amount of fees you want to pay. You can estimate the minimum amount of fees via the methods outlined here.


Expand All @@ -29,24 +27,21 @@ Equipped with the payload we want to send, we can now call the outbound on Socke
ISocket socket = ISocket(_address);

// THIS IS NOT AN ACTUAL SLUG, please get the right slug from the deployments page
uint256 remoteChainSlug = 1333;
uint256 defaultGasLimit = 1000000;
uint32 remoteChainSlug = 1333;
uint32 defaultGasLimit = 1000000;

// send hello world to the sibling Plug we configured on chainSlug:1333
function SendHelloWorld(
) external payable {
bytes memory payload = abi.encode("Hello World");
// msg.value should be equal to the minFees
socket.outbound{value: msg.value}(remoteChainSlug, defaultGasLimit, payload);
socket.outbound{value: msg.value}(remoteChainSlug, defaultGasLimit, bytes32(0), bytes32(0), payload);
}
```
<!-- // TODO: add API link -->

Once the tx is finalised:
- An event `MessageTransmitted` is emitted by Socket containing all relavent details.
- Your message will be allocated a unique ID called (`msgId`) you can look it up in the `MessageTransmitted` log
- An event `MessageOutbound` is emitted by Socket containing all relavent details.
- Your message will be allocated a unique ID called (`msgId`) you can look it up in the `MessageOutbound` log

You can use the tx-hash to track the delivery and execution on the destination chain via this API.

<!-- // TODO: LINK -->
You can check out some examples we built out here:
You can use the tx-hash to track the delivery and execution on the destination chain via [this API](../../Dev%20Resources/APIReference/Track.md).
4 changes: 0 additions & 4 deletions docs/Build/DeploymentsSection/_category_.json

This file was deleted.

Loading

0 comments on commit 9ce1f9d

Please sign in to comment.