Skip to content

Commit

Permalink
chore: streaming docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nftchance committed Mar 1, 2024
1 parent 2db0edf commit edc0be9
Showing 1 changed file with 36 additions and 53 deletions.
89 changes: 36 additions & 53 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ head:

# Getting Started

Plug is a `Solidity` protocol and `Typescript` interface for building and interacting with protocols that support declarative EVM transactions.

You can learn about the rationale behind the project in the [Why Plug](/introduction/why-plug) section.
Plug is a `Solidity` protocol and `Typescript` interface for building and interacting with protocols through intents. You can learn about the rationale behind the protocol in the [Why Plug](/introduction/why-plug) section.

## User Quickstart

[Plug](/) has been designed to serve the end-user first. If you're not a developer all you have to do is head to the [official application](https://onplug.io) and you can get off to the races. There you will find templates and guides to lead you on your journey.

## Developer Installation
## Developer Quickstart

To work with `Plug` at the protocol or application layer you'll need to install the core framework package by opening a terminal and running the following command with your package manager of your choice:
To work with `Plug` at the protocol layer you'll need to install the core framework package by opening a terminal and running the following command with your package manager of your choice:

::: code-group

Expand All @@ -41,35 +39,7 @@ bun i @nftchance/plug-core

:::

## Protocol Quickstart

Integrating `Plug` into your protocol is as simple as inheriting from the appropriate contract and passing in your protocol's name and version to declare the [domain](https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator) of your protocol's plugs:

::: code-group

```solidity 5,7,9,10,12 [PeerToPeerBridge.sol]
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import { PlugReceiver } from '@nftchance/plug-core/src/contracts/abstracts/Plug.Receiver.sol'
contract PeerToPeerBridge is PlugReceiver {
/// @dev Include the code of your primitive.
}
```

:::

By inheriting `PlugReceiver`, your protocol now has full support for plugs in just those few lines; **there is no need to write any additional code or fiddle with the internals of the protocol.**

::: tip

Notably, this step is optional to the extent that by not including this the value of `msg.sender` will be the address of the contract that validated and executed the [Plugs](generated/base-types/Plugs).

:::

## Application Quickstart
## Signing an Intent

With your target contract prepared, it is now time to configure the conditions under which the transaction can be executed and distribute the fuses. Let's go ahead and declare the fuse tree for our intent and allow execution to safely be by an account in the Executor pool:

Expand All @@ -79,29 +49,25 @@ With your target contract prepared, it is now time to configure the conditions u
// * Create a new instance of the Plug framework.
const framework = new Plug(name, version, chainId, constants.types, contract);

// * Declare the transaction that is going to be executed.
const data = encodeFunctionData({
abi: CONTRACT_ABI,
functionName: "echo",
args: ["Hello World"]
});

// * Append all the conditions of execution (fuses).
const fuses = [
// Enable revocation.
Plug.Revocation(SIGNER_ADDRESS),
// Only allow the transaction to be executed once.
Plug.LimitedCalls(1)
];

const plugs = await framework.sign(owner, "Plugs", {
plugs: [{
current: {
ground: CONTRACT_ADDRESS,
voltage: 0,
data
target: CONTRACT_ADDRESS,
value: 0,
data: encodeFunctionData({
abi: CONTRACT_ABI,
functionName: "echo",
args: ["Hello World"]
})
},
fuses
fuses: [
Plug.Revocation(SIGNER_ADDRESS),
Plug.LimitedCalls(1)
],
fee: 0,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
executor: Plug.Executor
}],
salt: Math.floor(Date.now() / 1000);
});
Expand All @@ -116,3 +82,20 @@ When you're ready, all you have to do is run a single line of code like:
```typescript [./example.ts]
plugs.submit();
```

## Streaming Intents

On the other side of things, Executors have the ability to listen for newly created intents that can be executed. With the same framework used to sign intents, you can open a WebSocket of distribution with:

```typescript
// * Create a new instance of the Plug framework.
const framework = new Plug(name, version, chainId, constants.types, contract);

framework.stream();
```

With this, you will receive all newly signed intents. If however, you would like to only receive orders that your Executor contract has permission to execute you can do so easily by opening your stream with:

```typescript [./example.ts]
framework.stream({ executors: [EXECUTOR_ADDRESS] });
```

0 comments on commit edc0be9

Please sign in to comment.